From 80fb1b5f542b4167fffe4fcccd2bcbbdab42d7bb Mon Sep 17 00:00:00 2001 From: nhmall Date: Mon, 25 Mar 2024 20:42:48 -0400 Subject: [PATCH] provide way for developer to verify custom colors and symbols in effect ' #wizcustom --- include/extern.h | 3 ++ src/cmd.c | 2 + src/glyphs.c | 55 +++++++++++++++++++----- src/wizcmds.c | 90 ++++++++++++++++++++++++++++++++++++++++ sys/windows/consoletty.c | 11 ++++- 5 files changed, 148 insertions(+), 13 deletions(-) diff --git a/include/extern.h b/include/extern.h index 1f69f8940..5d404f0a0 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1103,6 +1103,7 @@ extern int unicode_val(const char *); extern int glyphrep(const char *) NONNULLARG1; extern int match_glyph(char *) NONNULLARG1; extern void dump_all_glyphids(FILE *fp) NONNULLARG1; +extern void wizcustom_glyphids(winid win); extern void fill_glyphid_cache(void); extern void free_glyphid_cache(void); extern boolean glyphid_cache_status(void); @@ -3690,6 +3691,7 @@ extern void cuss(struct monst *) NONNULLARG1; /* ### wizcmds.c ### */ +extern int wiz_custom(void); extern int wiz_detect(void); extern int wiz_flip_level(void); extern int wiz_fuzzer(void); @@ -3718,6 +3720,7 @@ extern int wiz_wish(void); extern void makemap_remove_mons(void); extern void wiz_levltyp_legend(void); extern void wiz_map_levltyp(void); +extern void wizcustom_callback(winid win, int glyphnum, char *id); #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG) extern int wiz_display_macros(void); extern int wiz_mon_diff(void); diff --git a/src/cmd.c b/src/cmd.c index e04624226..548883815 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1898,6 +1898,8 @@ struct ext_func_tab extcmdlist[] = { #endif { '\0', "wizcast", "cast any spell", dowizcast, IFBURIED | WIZMODECMD, NULL }, + { '\0', "wizcustom", "show customized glyphs", + wiz_custom, IFBURIED | WIZMODECMD | NOFUZZERCMD, NULL }, { C('e'), "wizdetect", "reveal hidden things within a small radius", wiz_detect, IFBURIED | WIZMODECMD, NULL }, #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG) diff --git a/src/glyphs.c b/src/glyphs.c index 80d353126..14cf57e3f 100644 --- a/src/glyphs.c +++ b/src/glyphs.c @@ -39,6 +39,7 @@ static const long nonzero_black = CLR_BLACK | NH_BASIC_COLOR; staticfn void init_glyph_cache(void); staticfn void add_glyph_to_cache(int glyphnum, const char *id); staticfn int find_glyph_in_cache(const char *id); +staticfn char *find_glyphid_in_cache_by_glyphnum(int glyphnum); staticfn uint32 glyph_hash(const char *id); staticfn void to_custom_symset_entry_callback(int glyph, struct find_struct *findwhat); @@ -341,6 +342,23 @@ find_glyph_in_cache(const char *id) return -1; } +staticfn char * +find_glyphid_in_cache_by_glyphnum(int glyphnum) +{ + size_t idx; + + if (!glyphid_cache) + return (char *) 0; + for (idx = 0; idx < glyphid_cache_size; ++idx) { + if (glyphid_cache[idx].glyphnum == glyphnum + && glyphid_cache[idx].id != 0) { + /* Match found */ + return glyphid_cache[idx].id; + } + } + return (char *) 0; +} + staticfn uint32 glyph_hash(const char *id) { @@ -364,17 +382,6 @@ glyphid_cache_status(void) return (glyphid_cache != 0); } -void -dump_all_glyphids(FILE *fp) -{ - struct find_struct dump_glyphid_find = zero_find; - - dump_glyphid_find.findtype = find_nothing; - dump_glyphid_find.reserved = (genericptr_t) fp; - dump_glyphid_find.restype = res_dump_glyphids; - (void) parse_id((char *) 0, &dump_glyphid_find); -} - int match_glyph(char *buf) { @@ -703,6 +710,32 @@ purge_custom_entries(enum graphics_sets which_set) gdc->count = 0; } } +void +dump_all_glyphids(FILE *fp) +{ + struct find_struct dump_glyphid_find = zero_find; + + dump_glyphid_find.findtype = find_nothing; + dump_glyphid_find.reserved = (genericptr_t) fp; + dump_glyphid_find.restype = res_dump_glyphids; + (void) parse_id((char *) 0, &dump_glyphid_find); +} + +void +wizcustom_glyphids(winid win) +{ + int glyphnum; + char *id; + + if (!glyphid_cache) + return; + for (glyphnum = 0; glyphnum < MAX_GLYPH; ++glyphnum) { + id = find_glyphid_in_cache_by_glyphnum(glyphnum); + if (id) { + wizcustom_callback(win, glyphnum, id); + } + } + } staticfn int parse_id(const char *id, struct find_struct *findwhat) diff --git a/src/wizcmds.c b/src/wizcmds.c index edb7d6be0..c3b11501d 100644 --- a/src/wizcmds.c +++ b/src/wizcmds.c @@ -1818,4 +1818,94 @@ wiz_migrate_mons(void) return ECMD_OK; } +/* #wizcustom command to see glyphmap customizations */ +int +wiz_custom(void) +{ + extern const char *const known_handling[]; /* symbols.c */ + + if (wizard) { + static const char wizcustom[] = "#wizcustom"; + winid win; + char buf[BUFSZ], bufa[BUFSZ]; + int n; +#if 0 + int j, glyph; +#endif + menu_item *pick_list = (menu_item *) 0; + + if (!glyphid_cache_status()) + fill_glyphid_cache(); + + win = create_nhwindow(NHW_MENU); + start_menu(win, MENU_BEHAVE_STANDARD); + add_menu_heading(win, + " glyph glyph identifier " + " sym clr customcolor unicode utf8"); + Sprintf(bufa, "%s: colorcount=%d %s", wizcustom, iflags.colorcount, + gs.symset[PRIMARYSET].name ? gs.symset[PRIMARYSET].name + : "default"); + if (gc.currentgraphics == PRIMARYSET && gs.symset[PRIMARYSET].name) + Strcat(bufa, ", active"); + if (gs.symset[PRIMARYSET].handling) { + Sprintf(eos(bufa), ", handler=%s", + known_handling[gs.symset[PRIMARYSET].handling]); + } + Sprintf(buf, "%s", bufa); + wizcustom_glyphids(win); + end_menu(win, bufa); + n = select_menu(win, PICK_NONE, &pick_list); + destroy_nhwindow(win); +#if 0 + for (j = 0; j < n; ++j) { + glyph = pick_list[j].item.a_int - 1; /* -1: reverse +1 above */ + } +#endif + if (n >= 1) + free((genericptr_t) pick_list); + if (glyphid_cache_status()) + free_glyphid_cache(); + docrt(); + } else + pline(unavailcmd, ecname_from_fn(wiz_custom)); + return ECMD_OK; +} + +void +wizcustom_callback(winid win, int glyphnum, char *id) +{ + extern glyph_map glyphmap[MAX_GLYPH]; + glyph_map *cgm; + int clr = NO_COLOR; + char buf[BUFSZ], bufa[BUFSZ], bufb[BUFSZ], bufc[BUFSZ], bufd[BUFSZ], + bufu[BUFSZ]; + anything any; + uint8 *cp; + + if (win && id) { + cgm = &glyphmap[glyphnum]; + if (cgm->u || cgm->customcolor != 0) { + Sprintf(bufa, "[%04d] %-44s", glyphnum, id); + Sprintf(bufb, "'\\%03d' %02d", + gs.showsyms[cgm->sym.symidx], cgm->sym.color); + Sprintf(bufc, "%011x", cgm->customcolor); + bufu[0] = '\0'; + if (cgm->u && cgm->u->utf8str) { + Sprintf(bufu, "U+%04x", cgm->u->utf32ch); + cp = cgm->u->utf8str; + while (*cp) { + Sprintf(bufd, " <%d>", (int) *cp); + Strcat(bufu, bufd); + cp++; + } + } + any.a_int = glyphnum + 1; /* avoid 0 */ + Sprintf(buf, "%s %s %s %s", bufa, bufb, bufc, bufu); + add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, buf, + MENU_ITEMFLAGS_NONE); + } + } + return; +} + /*wizcmds.c*/ diff --git a/sys/windows/consoletty.c b/sys/windows/consoletty.c index 5ea736fce..749d24ca7 100644 --- a/sys/windows/consoletty.c +++ b/sys/windows/consoletty.c @@ -997,8 +997,10 @@ tty_startup(int *wid, int *hgt) *wid = console.width; *hgt = console.height; set_option_mod_status("mouse_support", set_in_game); - iflags.colorcount = 16777216; -// iflags.colorcount = 256; + if (iflags.colorcount == 0) { + iflags.colorcount = 16777216; + // iflags.colorcount = 256; + } } void @@ -2404,6 +2406,11 @@ void nethack_enter_consoletty(void) #ifdef VIRTUAL_TERMINAL_SEQUENCES char buf[BUFSZ], *bp, *localestr; BOOL success; + + if (iflags.colorcount == 0) { + iflags.colorcount = 16777216; + // iflags.colorcount = 256; + } #endif /* VIRTUAL_TERMINAL_SEQUENCES */ #if 0 /* set up state needed by early_raw_print() */