Some win32 updates from <Someone>;
also corrects a cut-and-paste error that I made in options.c The following options can be set in the game now: WC_HILITE_PET WC_ALIGN_MESSAGE WC_ALIGN_STATUS WC_SCROLL_MARGIN WC_MAP_MODE WC_FONT_MESSAGE WC_FONT_STATUS WC_FONT_MENU WC_FONT_TEXT WC_FONTSIZ_MESSAGE WC_FONTSIZ_STATUS WC_FONTSIZ_MENU WC_FONTSIZ_TEXT
This commit is contained in:
@@ -2362,7 +2362,7 @@ doset()
|
||||
parseoptions(buf, setinitial, fromfile);
|
||||
}
|
||||
if (wc_supported(compopt[opt_indx].name))
|
||||
preference_update(boolopt[opt_indx].name);
|
||||
preference_update(compopt[opt_indx].name);
|
||||
}
|
||||
}
|
||||
free((genericptr_t)pick_list);
|
||||
|
||||
@@ -26,7 +26,6 @@ LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||
static LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
|
||||
static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
|
||||
static void register_main_window_class(void);
|
||||
static void select_map_mode(int map_mode);
|
||||
static int menuid2mapmode(int menuid);
|
||||
static int mapmode2menuid(int map_mode);
|
||||
|
||||
@@ -290,7 +289,7 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
HWND child;
|
||||
|
||||
if( GetNHApp()->windowlist[msg_param->wid].type == NHW_MAP )
|
||||
select_map_mode(iflags.wc_map_mode);
|
||||
mswin_select_map_mode(iflags.wc_map_mode);
|
||||
|
||||
child = GetNHApp()->windowlist[msg_param->wid].win;
|
||||
if( child ) mswin_layout_main_window(child);
|
||||
@@ -502,7 +501,7 @@ LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_MAP_ASCII16X12:
|
||||
case IDM_MAP_ASCII10X18:
|
||||
case IDM_MAP_FIT_TO_SCREEN:
|
||||
select_map_mode(menuid2mapmode(wmId));
|
||||
mswin_select_map_mode(menuid2mapmode(wmId));
|
||||
break;
|
||||
|
||||
case IDM_HELP_LONG:
|
||||
@@ -601,7 +600,7 @@ LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void select_map_mode(int mode)
|
||||
void mswin_select_map_mode(int mode)
|
||||
{
|
||||
CheckMenuRadioItem(
|
||||
GetMenu(GetNHApp()->hMainWnd),
|
||||
|
||||
@@ -10,5 +10,6 @@
|
||||
|
||||
HWND mswin_init_main_window (void);
|
||||
void mswin_layout_main_window(HWND changed_child);
|
||||
void mswin_select_map_mode(int map_mode);
|
||||
|
||||
#endif /* MSWINMainWindow_h */
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "mhaskyn.h"
|
||||
#include "mhdlg.h"
|
||||
#include "mhrip.h"
|
||||
#include "mhmain.h"
|
||||
#include "mhfont.h"
|
||||
|
||||
#define LLEN 128
|
||||
|
||||
@@ -29,6 +31,7 @@ void logDebug(const char *fmt, ...) { }
|
||||
#endif
|
||||
|
||||
static void mswin_main_loop(void);
|
||||
static BOOL initMapTiles(void);
|
||||
|
||||
/* Interface definition, for windows.c */
|
||||
struct window_procs mswin_procs = {
|
||||
@@ -86,7 +89,7 @@ struct window_procs mswin_procs = {
|
||||
mswin_start_screen,
|
||||
mswin_end_screen,
|
||||
mswin_outrip,
|
||||
genl_preference_update,
|
||||
mswin_preference_update,
|
||||
};
|
||||
|
||||
|
||||
@@ -117,6 +120,58 @@ void mswin_init_nhwindows(int* argc, char** argv)
|
||||
#endif
|
||||
mswin_nh_input_init();
|
||||
|
||||
/* check default values */
|
||||
if( iflags.wc_fontsiz_status<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_status>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
if( iflags.wc_fontsiz_message<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_message>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
if( iflags.wc_fontsiz_text<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_text>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
if( iflags.wc_fontsiz_menu<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_menu>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
if( iflags.wc_align_message==0 ) iflags.wc_align_message = ALIGN_TOP;
|
||||
if( iflags.wc_align_status==0 ) iflags.wc_align_status = ALIGN_BOTTOM;
|
||||
if( iflags.wc_scroll_margin==0 ) iflags.wc_scroll_margin = DEF_CLIPAROUND_MARGIN;
|
||||
if( iflags.wc_tile_width==0 ) iflags.wc_tile_width = TILE_X;
|
||||
if( iflags.wc_tile_height==0 ) iflags.wc_tile_height = TILE_Y;
|
||||
|
||||
/* force tabs in menus */
|
||||
iflags.menu_tab_sep = 1;
|
||||
|
||||
/* initialize map tiles bitmap */
|
||||
initMapTiles();
|
||||
|
||||
/* set tile-related options to readonly */
|
||||
set_wc_option_mod_status(
|
||||
WC_TILE_WIDTH|WC_TILE_HEIGHT|WC_TILE_FILE,
|
||||
DISP_IN_GAME);
|
||||
|
||||
/* set font-related options to change in the game */
|
||||
set_wc_option_mod_status(
|
||||
WC_HILITE_PET |
|
||||
WC_ALIGN_MESSAGE |
|
||||
WC_ALIGN_STATUS |
|
||||
WC_SCROLL_MARGIN |
|
||||
WC_MAP_MODE |
|
||||
WC_FONT_MESSAGE |
|
||||
WC_FONT_STATUS |
|
||||
WC_FONT_MENU |
|
||||
WC_FONT_TEXT |
|
||||
WC_FONTSIZ_MESSAGE |
|
||||
WC_FONTSIZ_STATUS |
|
||||
WC_FONTSIZ_MENU |
|
||||
WC_FONTSIZ_TEXT,
|
||||
SET_IN_GAME
|
||||
);
|
||||
|
||||
iflags.window_inited = TRUE;
|
||||
}
|
||||
|
||||
@@ -1022,6 +1077,112 @@ void mswin_outrip(winid wid, int how)
|
||||
genl_outrip(wid, how);
|
||||
}
|
||||
|
||||
/* handle options updates here */
|
||||
void mswin_preference_update(const char *pref)
|
||||
{
|
||||
HDC hdc;
|
||||
|
||||
if( stricmp( pref, "font_menu")==0 ||
|
||||
stricmp( pref, "font_size_menu")==0 ) {
|
||||
if( iflags.wc_fontsiz_menu<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_menu>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_menu = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
hdc = GetDC(GetNHApp()->hMainWnd);
|
||||
mswin_get_font(NHW_MENU, ATR_NONE, hdc, TRUE);
|
||||
mswin_get_font(NHW_MENU, ATR_BOLD, hdc, TRUE);
|
||||
mswin_get_font(NHW_MENU, ATR_DIM, hdc, TRUE);
|
||||
mswin_get_font(NHW_MENU, ATR_ULINE, hdc, TRUE);
|
||||
mswin_get_font(NHW_MENU, ATR_BLINK, hdc, TRUE);
|
||||
mswin_get_font(NHW_MENU, ATR_INVERSE, hdc, TRUE);
|
||||
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
||||
|
||||
mswin_layout_main_window(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if( stricmp( pref, "font_status")==0 ||
|
||||
stricmp( pref, "font_size_status")==0 ) {
|
||||
|
||||
if( iflags.wc_fontsiz_status<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_status>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
hdc = GetDC(GetNHApp()->hMainWnd);
|
||||
mswin_get_font(NHW_STATUS, ATR_NONE, hdc, TRUE);
|
||||
mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, TRUE);
|
||||
mswin_get_font(NHW_STATUS, ATR_DIM, hdc, TRUE);
|
||||
mswin_get_font(NHW_STATUS, ATR_ULINE, hdc, TRUE);
|
||||
mswin_get_font(NHW_STATUS, ATR_BLINK, hdc, TRUE);
|
||||
mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE);
|
||||
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
||||
|
||||
mswin_layout_main_window(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if( stricmp( pref, "font_message")==0 ||
|
||||
stricmp( pref, "font_size_message")==0 ) {
|
||||
|
||||
if( iflags.wc_fontsiz_message<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_message>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_message = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
hdc = GetDC(GetNHApp()->hMainWnd);
|
||||
mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, TRUE);
|
||||
mswin_get_font(NHW_MESSAGE, ATR_BOLD, hdc, TRUE);
|
||||
mswin_get_font(NHW_MESSAGE, ATR_DIM, hdc, TRUE);
|
||||
mswin_get_font(NHW_MESSAGE, ATR_ULINE, hdc, TRUE);
|
||||
mswin_get_font(NHW_MESSAGE, ATR_BLINK, hdc, TRUE);
|
||||
mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE);
|
||||
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
||||
|
||||
mswin_layout_main_window(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if( stricmp( pref, "font_text")==0 ||
|
||||
stricmp( pref, "font_size_text")==0 ) {
|
||||
|
||||
if( iflags.wc_fontsiz_text<NHFONT_SIZE_MIN ||
|
||||
iflags.wc_fontsiz_text>NHFONT_SIZE_MAX )
|
||||
iflags.wc_fontsiz_text = NHFONT_DEFAULT_SIZE;
|
||||
|
||||
hdc = GetDC(GetNHApp()->hMainWnd);
|
||||
mswin_get_font(NHW_TEXT, ATR_NONE, hdc, TRUE);
|
||||
mswin_get_font(NHW_TEXT, ATR_BOLD, hdc, TRUE);
|
||||
mswin_get_font(NHW_TEXT, ATR_DIM, hdc, TRUE);
|
||||
mswin_get_font(NHW_TEXT, ATR_ULINE, hdc, TRUE);
|
||||
mswin_get_font(NHW_TEXT, ATR_BLINK, hdc, TRUE);
|
||||
mswin_get_font(NHW_TEXT, ATR_INVERSE, hdc, TRUE);
|
||||
ReleaseDC(GetNHApp()->hMainWnd, hdc);
|
||||
|
||||
mswin_layout_main_window(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if( stricmp( pref, "scroll_margin")==0 ) {
|
||||
mswin_cliparound(u.ux, u.uy);
|
||||
return;
|
||||
}
|
||||
|
||||
if( stricmp( pref, "map_mode")==0 ) {
|
||||
mswin_select_map_mode( iflags.wc_map_mode );
|
||||
return;
|
||||
}
|
||||
|
||||
if( stricmp( pref, "hilite_pet")==0 ) {
|
||||
InvalidateRect(mswin_hwnd_from_winid(WIN_MAP), NULL, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
if( stricmp( pref, "align_message")==0 ||
|
||||
stricmp( pref, "align_status")==0 ) {
|
||||
mswin_layout_main_window(NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mswin_main_loop()
|
||||
{
|
||||
@@ -1045,6 +1206,70 @@ void bail(const char *mesg)
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
BOOL initMapTiles(void)
|
||||
{
|
||||
HBITMAP hBmp;
|
||||
BITMAP bm;
|
||||
TCHAR wbuf[MAX_PATH];
|
||||
int tl_num;
|
||||
SIZE map_size;
|
||||
extern int total_tiles_used;
|
||||
|
||||
/* no file - no tile */
|
||||
if( !(iflags.wc_tile_file && *iflags.wc_tile_file) )
|
||||
return TRUE;
|
||||
|
||||
/* load bitmap */
|
||||
hBmp = LoadImage(
|
||||
GetNHApp()->hApp,
|
||||
NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH),
|
||||
IMAGE_BITMAP,
|
||||
0,
|
||||
0,
|
||||
LR_LOADFROMFILE | LR_DEFAULTSIZE
|
||||
);
|
||||
if( hBmp==NULL ) {
|
||||
raw_print("Cannot load tiles from the file. Reverting back to default.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* calculate tile dimensions */
|
||||
GetObject(hBmp, sizeof(BITMAP), (LPVOID)&bm);
|
||||
if( bm.bmWidth%iflags.wc_tile_width ||
|
||||
bm.bmHeight%iflags.wc_tile_height ) {
|
||||
DeleteObject(hBmp);
|
||||
raw_print("Tiles bitmap does not match tile_width and tile_height options. Reverting back to default.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
tl_num = (bm.bmWidth/iflags.wc_tile_width)*
|
||||
(bm.bmHeight/iflags.wc_tile_height);
|
||||
if( tl_num<total_tiles_used ) {
|
||||
DeleteObject(hBmp);
|
||||
raw_print("Number of tiles in the bitmap is less than required by the game. Reverting back to default.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set the tile information */
|
||||
if( GetNHApp()->bmpMapTiles!=GetNHApp()->bmpTiles ) {
|
||||
DeleteObject(GetNHApp()->bmpMapTiles);
|
||||
}
|
||||
|
||||
GetNHApp()->bmpMapTiles = hBmp;
|
||||
GetNHApp()->mapTile_X = iflags.wc_tile_width;
|
||||
GetNHApp()->mapTile_Y = iflags.wc_tile_height;
|
||||
GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width;
|
||||
|
||||
map_size.cx = GetNHApp()->mapTile_X * COLNO;
|
||||
map_size.cy = GetNHApp()->mapTile_Y * ROWNO;
|
||||
mswin_map_stretch(
|
||||
mswin_hwnd_from_winid(WIN_MAP),
|
||||
&map_size,
|
||||
TRUE
|
||||
);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ char *mswin_get_color_string(void);
|
||||
void mswin_start_screen(void);
|
||||
void mswin_end_screen(void);
|
||||
void mswin_outrip(winid wid, int how);
|
||||
void mswin_preference_update(const char *pref);
|
||||
|
||||
/* helper function */
|
||||
HWND mswin_hwnd_from_winid(winid wid);
|
||||
|
||||
@@ -31,7 +31,6 @@ BOOL InitInstance(HINSTANCE, int);
|
||||
|
||||
extern void FDECL(pcmain, (int,char **));
|
||||
static void __cdecl mswin_moveloop(void *);
|
||||
static BOOL initMapTiles(void);
|
||||
|
||||
#define MAX_CMDLINE_PARAM 255
|
||||
|
||||
@@ -101,9 +100,6 @@ int APIENTRY WinMain(HINSTANCE hInstance,
|
||||
|
||||
pcmain(argc,argv);
|
||||
|
||||
/* initialize map tiles bitmap */
|
||||
initMapTiles();
|
||||
|
||||
moveloop();
|
||||
|
||||
return 0;
|
||||
@@ -143,66 +139,3 @@ PNHWinApp GetNHApp()
|
||||
return &_nethack_app;
|
||||
}
|
||||
|
||||
BOOL initMapTiles(void)
|
||||
{
|
||||
HBITMAP hBmp;
|
||||
BITMAP bm;
|
||||
TCHAR wbuf[MAX_PATH];
|
||||
int tl_num;
|
||||
SIZE map_size;
|
||||
extern int total_tiles_used;
|
||||
|
||||
/* no file - no tile */
|
||||
if( !(iflags.wc_tile_file && *iflags.wc_tile_file) )
|
||||
return TRUE;
|
||||
|
||||
/* load bitmap */
|
||||
hBmp = LoadImage(
|
||||
GetNHApp()->hApp,
|
||||
NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH),
|
||||
IMAGE_BITMAP,
|
||||
0,
|
||||
0,
|
||||
LR_LOADFROMFILE | LR_DEFAULTSIZE
|
||||
);
|
||||
if( hBmp==NULL ) {
|
||||
raw_print("Cannot load tiles from the file. Reverting back to default.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* calculate tile dimensions */
|
||||
GetObject(hBmp, sizeof(BITMAP), (LPVOID)&bm);
|
||||
if( bm.bmWidth%iflags.wc_tile_width ||
|
||||
bm.bmHeight%iflags.wc_tile_height ) {
|
||||
DeleteObject(hBmp);
|
||||
raw_print("Tiles bitmap does not match tile_width and tile_height options. Reverting back to default.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
tl_num = (bm.bmWidth/iflags.wc_tile_width)*
|
||||
(bm.bmHeight/iflags.wc_tile_height);
|
||||
if( tl_num<total_tiles_used ) {
|
||||
DeleteObject(hBmp);
|
||||
raw_print("Number of tiles in the bitmap is less than required by the game. Reverting back to default.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set the tile information */
|
||||
if( GetNHApp()->bmpMapTiles!=GetNHApp()->bmpTiles ) {
|
||||
DeleteObject(GetNHApp()->bmpMapTiles);
|
||||
}
|
||||
|
||||
GetNHApp()->bmpMapTiles = hBmp;
|
||||
GetNHApp()->mapTile_X = iflags.wc_tile_width;
|
||||
GetNHApp()->mapTile_Y = iflags.wc_tile_height;
|
||||
GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width;
|
||||
|
||||
map_size.cx = GetNHApp()->mapTile_X * COLNO;
|
||||
map_size.cy = GetNHApp()->mapTile_Y * ROWNO;
|
||||
mswin_map_stretch(
|
||||
mswin_hwnd_from_winid(WIN_MAP),
|
||||
&map_size,
|
||||
TRUE
|
||||
);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user