From 29495f77f78e69a8c36dc32e62907cc0b21f4989 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 24 Mar 2024 19:39:36 -0400 Subject: [PATCH] runtime toggle of ENHANCED_SYMBOLS customsymbols --- include/decl.h | 3 ++- include/extern.h | 6 ++++-- include/flag.h | 1 + include/optlist.h | 3 +++ include/sym.h | 6 ++++++ src/decl.c | 3 ++- src/glyphs.c | 28 +++++++++++++++++----------- src/options.c | 38 +++++++++++++++++++++++++------------- src/symbols.c | 6 ++++-- src/utf8map.c | 8 ++++++++ 10 files changed, 72 insertions(+), 30 deletions(-) diff --git a/include/decl.h b/include/decl.h index 9a9fcc099..c1bc4cd3f 100644 --- a/include/decl.h +++ b/include/decl.h @@ -752,7 +752,8 @@ struct instance_globals_o { boolean opt_need_redraw; /* for doset() */ boolean opt_need_glyph_reset; boolean opt_need_promptstyle; - boolean opt_reset_customizations; + boolean opt_reset_customcolors; + boolean opt_reset_customsymbols; /* pickup.c */ int oldcap; /* last encumbrance */ diff --git a/include/extern.h b/include/extern.h index 67620e010..acef12e9d 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1106,12 +1106,13 @@ extern void dump_all_glyphids(FILE *fp) NONNULLARG1; extern void fill_glyphid_cache(void); extern void free_glyphid_cache(void); extern boolean glyphid_cache_status(void); -extern void apply_customizations(enum graphics_sets which_set); +extern void apply_customizations(enum graphics_sets which_set, + enum do_customizations docustomize); extern void purge_custom_entries(enum graphics_sets which_set); extern void purge_all_custom_entries(void); extern void dump_glyphids(void); extern void clear_all_glyphmap_colors(void); -extern void reset_customizations(void); +extern void reset_customcolors(void); /* ### hack.c ### */ @@ -3383,6 +3384,7 @@ extern char *mixed_to_utf8(char *buf, size_t bufsz, const char *str, void free_all_glyphmap_u(void); int set_map_u(glyph_map *gm, uint32 utf32ch, const uint8 *utf8str) NONNULLPTRS; #endif /* ENHANCED_SYMBOLS */ +extern void reset_customsymbols(void); /* ### vault.c ### */ diff --git a/include/flag.h b/include/flag.h index 0bff96054..c998b540b 100644 --- a/include/flag.h +++ b/include/flag.h @@ -376,6 +376,7 @@ struct instance_flags { boolean wizweight; /* display weight of everything in wizard mode */ boolean wizmgender; /* test gender info from core in window port */ boolean customcolors; /* support customcolors defined in glyphmap */ + boolean customsymbols; /* support customsymbols defined in glyphmap */ /* * Window capability support. */ diff --git a/include/optlist.h b/include/optlist.h index 81d2b626a..a0c1a9cb6 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -253,6 +253,9 @@ static int optfn_##a(int, int, boolean, char *, char *); NHOPTB(customcolors, Map, 0, opt_out, set_in_game, On, Yes, No, No, "customcolours", &iflags.customcolors, Term_False, "use custom colors in map") + NHOPTB(customsymbols, Map, 0, opt_out, set_in_game, + On, Yes, No, No, "customsymbols", &iflags.customsymbols, + Term_False, "use custom utf8 symbols in map") NHOPTB(dark_room, Advanced, 0, opt_out, set_in_game, On, Yes, No, No, NoAlias, &flags.dark_room, Term_False, "show floor outside line of sight differently") diff --git a/include/sym.h b/include/sym.h index 9808de0b5..05d566b07 100644 --- a/include/sym.h +++ b/include/sym.h @@ -129,6 +129,12 @@ enum graphics_sets { UNICODESET = NUM_GRAPHICS }; +enum do_customizations { + do_custom_none, + do_custom_colors, + do_custom_symbols +}; + enum customization_types { custom_none, custom_symbols, custom_ureps, custom_nhcolor, custom_count }; diff --git a/src/decl.c b/src/decl.c index a90d140a7..7d74dbc50 100644 --- a/src/decl.c +++ b/src/decl.c @@ -655,7 +655,8 @@ static const struct instance_globals_o g_init_o = { FALSE, /* opt_need_redraw */ FALSE, /* opt_need_glyph_reset */ FALSE, /* opt_need_promptstyle */ - FALSE, /* opt_reset_customizations */ + FALSE, /* opt_reset_customcolors */ + FALSE, /* opt_reset_customsymbols */ /* pickup.c */ 0, /* oldcap */ /* restore.c */ diff --git a/src/glyphs.c b/src/glyphs.c index e8e741db0..58d467b27 100644 --- a/src/glyphs.c +++ b/src/glyphs.c @@ -449,12 +449,16 @@ add_custom_nhcolor_entry( } void -apply_customizations(enum graphics_sets which_set) +apply_customizations( + enum graphics_sets which_set, + enum do_customizations docustomize) { glyph_map *gmap; struct customization_detail *details; struct symset_customization *sc; - boolean at_least_one = FALSE; + boolean at_least_one = FALSE, + do_colors = ((docustomize & do_custom_colors) != 0), + do_symbols = ((docustomize & do_custom_symbols) != 0); int custs; for (custs = 0; custs < (int) custom_count; ++custs) { @@ -466,15 +470,17 @@ apply_customizations(enum graphics_sets which_set) details = sc->details; while (details) { #ifdef ENHANCED_SYMBOLS - if (sc->custtype == custom_ureps) { - gmap = &glyphmap[details->content.urep.glyphidx]; - if (gs.symset[which_set].handling == H_UTF8) - (void) set_map_u(gmap, - details->content.urep.u.utf32ch, - details->content.urep.u.utf8str); + if (iflags.customsymbols && do_symbols) { + if (sc->custtype == custom_ureps) { + gmap = &glyphmap[details->content.urep.glyphidx]; + if (gs.symset[which_set].handling == H_UTF8) + (void) set_map_u(gmap, + details->content.urep.u.utf32ch, + details->content.urep.u.utf8str); + } } #endif - if (iflags.customcolors) { + if (iflags.customcolors && do_colors) { if (sc->custtype == custom_nhcolor) { gmap = &glyphmap[details->content.ccolor.glyphidx]; (void) set_map_nhcolor(gmap, @@ -1048,10 +1054,10 @@ clear_all_glyphmap_colors(void) } } -void reset_customizations(void) +void reset_customcolors(void) { clear_all_glyphmap_colors(); - apply_customizations(gc.currentgraphics); + apply_customizations(gc.currentgraphics, do_custom_colors); } /* not used yet */ diff --git a/src/options.c b/src/options.c index 839486a40..e45f45c2d 100644 --- a/src/options.c +++ b/src/options.c @@ -4078,7 +4078,8 @@ optfn_symset( reslt = handler_symset(optidx); if (glyphid_cache_status()) free_glyphid_cache(); - /* apply_customizations(gc.currentgraphics); */ + /* apply_customizations(gc.currentgraphics, + (do_custom_colors | do_custom_symbols)); */ return reslt; } return optn_ok; @@ -5230,7 +5231,10 @@ optfn_boolean( go.opt_need_glyph_reset = TRUE; break; case opt_customcolors: - go.opt_reset_customizations = TRUE; + go.opt_reset_customcolors = TRUE; + break; + case opt_customsymbols: + go.opt_reset_customsymbols = TRUE; break; case opt_menucolors: case opt_guicolor: @@ -7193,7 +7197,8 @@ initoptions_finish(void) if (glyphid_cache_status()) free_glyphid_cache(); - apply_customizations(gc.currentgraphics); + apply_customizations(gc.currentgraphics, + (do_custom_colors | do_custom_symbols)); go.opt_initial = FALSE; /* @@ -8392,7 +8397,8 @@ doset_simple_menu(void) go.opt_need_redraw = FALSE; go.opt_need_glyph_reset = FALSE; - go.opt_reset_customizations = FALSE; + go.opt_reset_customcolors = FALSE; + go.opt_reset_customsymbols = FALSE; pick_cnt = select_menu(tmpwin, PICK_ONE, &pick_list); /* note: without the complication of a preselected entry, a PICK_ONE menu returning pick_cnt > 0 implies exactly 1 */ @@ -8483,8 +8489,11 @@ doset_simple(void) } if (go.opt_need_promptstyle) adjust_menu_promptstyle(WIN_INVEN, &iflags.menu_headings); - if (go.opt_reset_customizations) { - reset_customizations(); + if (go.opt_reset_customcolors || go.opt_reset_customsymbols) { + if (go.opt_reset_customcolors) + reset_customcolors(); + if (go.opt_reset_customsymbols) + reset_customsymbols(); docrt_flags(opt_crt_flags); } @@ -8738,13 +8747,16 @@ doset(void) /* changing options via menu by Per Liboriussen */ if (go.opt_need_glyph_reset) { reset_glyphmap(gm_optionchange); } - if (go.opt_reset_customizations) { - reset_customizations(); - docrt(); - } - if (go.opt_need_redraw) { - check_gold_symbol(); - reglyph_darkroom(); + if (go.opt_reset_customcolors + || go.opt_reset_customsymbols || go.opt_need_redraw) { + if (go.opt_reset_customcolors) + reset_customcolors(); + if (go.opt_reset_customsymbols) + reset_customsymbols(); + if (go.opt_need_redraw) { + check_gold_symbol(); + reglyph_darkroom(); + } docrt(); } if (go.opt_need_promptstyle) { diff --git a/src/symbols.c b/src/symbols.c index 2e9a0650a..23e618a72 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -680,7 +680,8 @@ load_symset(const char *s, int which_set) if (read_sym_file(which_set)) { switch_symbols(TRUE); - apply_customizations(gc.currentgraphics); + apply_customizations(gc.currentgraphics, + do_custom_symbols | do_custom_colors); } else { clear_symsetentry(which_set, TRUE); return 0; @@ -1089,7 +1090,8 @@ do_symset(boolean rogueflag) assign_graphics(ROGUESET); } else if (!rogueflag) assign_graphics(PRIMARYSET); - apply_customizations(rogueflag ? ROGUESET : PRIMARYSET); + apply_customizations(rogueflag ? ROGUESET : PRIMARYSET, + (do_custom_symbols | do_custom_colors)); preference_update("symset"); return TRUE; } diff --git a/src/utf8map.c b/src/utf8map.c index d918078bb..310b7f549 100644 --- a/src/utf8map.c +++ b/src/utf8map.c @@ -208,6 +208,14 @@ add_custom_urep_entry( } #endif /* ENHANCED_SYMBOLS */ +void reset_customsymbols(void) +{ +#ifdef ENHANCED_SYMBOLS + free_all_glyphmap_u(); + apply_customizations(gc.currentgraphics, do_custom_symbols); +#endif +} + /* utf8map.c */