From: Pasi Kallinen Date: Thu, 6 Oct 2016 17:55:30 +0000 (+0300) Subject: win32: Save and load map colors from registry X-Git-Tag: NetHack-3.6.1_RC01~585 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f95747e3ef57fcabd2e785299b1f5426a39e575d;p=nethack win32: Save and load map colors from registry --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 0a6acdfd9..3cb943939 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -516,6 +516,7 @@ X11: status display split into three columns to accomodate Stone/Deaf/Lev/&c; NetHack*status_condition.foreground, .background, and .showGrip resources replaced by status_condition[1-3].* X11: more terminal-like default resources +win32gui: save and load map colors from registry NetHack Community Patches (or Variation) Included diff --git a/win/win32/mhmap.c b/win/win32/mhmap.c index 821c91802..8b301da66 100644 --- a/win/win32/mhmap.c +++ b/win/win32/mhmap.c @@ -9,6 +9,7 @@ #include "mhinput.h" #include "mhfont.h" +#include "color.h" #include "patchlevel.h" #define NHMAP_FONT_NAME TEXT("Terminal") @@ -1025,41 +1026,8 @@ nhglyph2charcolor(short g, uchar *ch, int *color) COLORREF nhcolor_to_RGB(int c) { - switch (c) { - case CLR_BLACK: - return RGB(0x55, 0x55, 0x55); - case CLR_RED: - return RGB(0xFF, 0x00, 0x00); - case CLR_GREEN: - return RGB(0x00, 0x80, 0x00); - case CLR_BROWN: - return RGB(0xA5, 0x2A, 0x2A); - case CLR_BLUE: - return RGB(0x00, 0x00, 0xFF); - case CLR_MAGENTA: - return RGB(0xFF, 0x00, 0xFF); - case CLR_CYAN: - return RGB(0x00, 0xFF, 0xFF); - case CLR_GRAY: - return RGB(0xC0, 0xC0, 0xC0); - case NO_COLOR: - return RGB(0xFF, 0xFF, 0xFF); - case CLR_ORANGE: - return RGB(0xFF, 0xA5, 0x00); - case CLR_BRIGHT_GREEN: - return RGB(0x00, 0xFF, 0x00); - case CLR_YELLOW: - return RGB(0xFF, 0xFF, 0x00); - case CLR_BRIGHT_BLUE: - return RGB(0x00, 0xC0, 0xFF); - case CLR_BRIGHT_MAGENTA: - return RGB(0xFF, 0x80, 0xFF); - case CLR_BRIGHT_CYAN: - return RGB(0x80, 0xFF, 0xFF); /* something close to aquamarine */ - case CLR_WHITE: - return RGB(0xFF, 0xFF, 0xFF); - default: - return RGB(0x00, 0x00, 0x00); /* black */ - } + if (c >= 0 && c < CLR_MAX) + return GetNHApp()->regMapColors[c]; + return RGB(0x00, 0x00, 0x00); } diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index df53f7a88..fe3ce07b5 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -8,6 +8,7 @@ */ #include "hack.h" +#include "color.h" #include "dlb.h" #include "func_tab.h" /* for extended commands */ #include "winMS.h" @@ -2278,6 +2279,25 @@ mswin_read_reg() DWORD size; DWORD safe_buf; char keystring[MAX_PATH]; + int i; + COLORREF default_mapcolors[CLR_MAX] = { + RGB(0x55, 0x55, 0x55), /* CLR_BLACK */ + RGB(0xFF, 0x00, 0x00), /* CLR_RED */ + RGB(0x00, 0x80, 0x00), /* CLR_GREEN */ + RGB(0xA5, 0x2A, 0x2A), /* CLR_BROWN */ + RGB(0x00, 0x00, 0xFF), /* CLR_BLUE */ + RGB(0xFF, 0x00, 0xFF), /* CLR_MAGENTA */ + RGB(0x00, 0xFF, 0xFF), /* CLR_CYAN */ + RGB(0xC0, 0xC0, 0xC0), /* CLR_GRAY */ + RGB(0xFF, 0xFF, 0xFF), /* NO_COLOR */ + RGB(0xFF, 0xA5, 0x00), /* CLR_ORANGE */ + RGB(0x00, 0xFF, 0x00), /* CLR_BRIGHT_GREEN */ + RGB(0xFF, 0xFF, 0x00), /* CLR_YELLOW */ + RGB(0x00, 0xC0, 0xFF), /* CLR_BRIGHT_BLUE */ + RGB(0xFF, 0x80, 0xFF), /* CLR_BRIGHT_MAGENTA */ + RGB(0x80, 0xFF, 0xFF), /* CLR_BRIGHT_CYAN */ + RGB(0xFF, 0xFF, 0xFF) /* CLR_WHITE */ + }; sprintf(keystring, "%s\\%s\\%s\\%s", CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY); @@ -2288,6 +2308,9 @@ mswin_read_reg() GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */ GetNHApp()->regNetHackMode = TRUE; + for (i = 0; i < CLR_MAX; i++) + GetNHApp()->regMapColors[i] = default_mapcolors[i]; + if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key) != ERROR_SUCCESS) return; @@ -2340,6 +2363,14 @@ mswin_read_reg() NHGETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); #undef NHGETREG_DWORD + for (i = 0; i < CLR_MAX; i++) { + COLORREF cl; + char mapcolorkey[64]; + sprintf(mapcolorkey, "MapColor%02d", i); + if (RegQueryValueEx(key, mapcolorkey, NULL, NULL, (BYTE *)&cl, &size) == ERROR_SUCCESS) + GetNHApp()->regMapColors[i] = cl; + } + RegCloseKey(key); /* check the data for validity */ @@ -2358,6 +2389,7 @@ mswin_write_reg() { HKEY key; DWORD disposition; + int i; if (GetNHApp()->saveRegistrySettings) { char keystring[MAX_PATH]; @@ -2419,6 +2451,13 @@ mswin_write_reg() NHSETREG_DWORD(INVENTBOTTOM, GetNHApp()->rtInvenWindow.bottom); #undef NHSETREG_DWORD + for (i = 0; i < CLR_MAX; i++) { + COLORREF cl = GetNHApp()->regMapColors[i]; + char mapcolorkey[64]; + sprintf(mapcolorkey, "MapColor%02d", i); + RegSetValueEx(key, mapcolorkey, 0, REG_DWORD, (BYTE *)&cl, sizeof(DWORD)); + } + RegCloseKey(key); } } diff --git a/win/win32/winMS.h b/win/win32/winMS.h index 7938d83d1..f35e601c9 100644 --- a/win/win32/winMS.h +++ b/win/win32/winMS.h @@ -25,6 +25,7 @@ #include #include #include "hack.h" +#include "color.h" /* Create an array to keep track of the various windows */ @@ -94,6 +95,8 @@ typedef struct mswin_nhwindow_app { regNetHackMode; /* NetHack mode means no Windows keys in some places */ + COLORREF regMapColors[CLR_MAX]; + LONG regMainMinX; LONG regMainMinY; LONG regMainMaxX;