core support for status field highlighting (trunk only)

This provides the core support needed for status field highlighting.
This patch doesn't actually perform status field highlighting for any port,
but provides the core hooks for doing so.

The syntax is:
OPTIONS=hilite_status:{fieldname}/{threshold}/{below}/{above}
where {fieldname} is the name of a status field.
           {threshold} is the value used as the threshold to trigger a display
                             change.  It can also be set to "updown" to trigger
                             a display change whenever it rises or whenever it falls.
                             If you end the threshold value with %, then it signifies
                             that you want to trigger the display change based on the
                             percentage of maximum.
         {below}, {above}
                        are the color or display attribute that you want to use when
                        the field value is underneath the threshold. Supported display
                        fields are:  normal, inverse, bold, black, red, green,
                                         brown, blue, magenta, cyan, gray, orange,
                                         bright-green, yellow, bright-blue, bright-magenta,
                                         bright-cyan, or white.
Valid field names are:
        alignment, armor-class, carrying-capacity,
        charisma, condition, constitution, dexterity,
        dungeon-level, experience-level, experience,
        gold, HD, hitpoints-max, hitpoints, hunger,
        intelligence, power-max, power, score,
        strength, time, title, wisdom

Refer to window.doc for details. Guidebook updates to come later.
This commit is contained in:
nethack.allison
2003-11-30 05:51:53 +00:00
parent c1c4ba99d9
commit 10480f4397
21 changed files with 997 additions and 195 deletions

View File

@@ -386,6 +386,43 @@ status_update(int fldindex, genericptr_t ptr, int chg, int percentage)
status_finish() -- called when it is time for the window port to tear down
the status display and free allocated memory, etc.
status_threshold(int fldidx, int threshholdtype, anything threshold,
int behavior, int under, int over)
-- called when a hiliting preference is added, changed, or
removed.
-- the fldindex identifies which field is having its hiliting
preference set. It is an integer index value from botl.h
-- fldindex could be any one of the following from botl.h:
BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX,
BL_LEVELDESC, BL_EXP, BL_CONDITION
-- datatype is P_INT, P_UINT, P_LONG, or P_MASK.
-- threshold is an "anything" union which can contain the
datatype value.
-- behavior is used to define how threshold is used and can
be BL_TH_NONE, BL_TH_VAL_PERCENTAGE, BL_TH_VAL_ABSOLUTE,
or BL_TH_UPDOWN. BL_TH_NONE means don't do anything above
or below the threshold. BL_TH_VAL_PERCENTAGE treats the
threshold value as a precentage of the maximum possible
value. BL_TH_VAL_ABSOLUTE means that the threshold is an
actual value. BL_TH_UPDOWN means that threshold is not
used, and the two below/above hilite values indicate how
to display something going down (under) or rising (over).
-- under is the hilite attribute used if value is below the
threshold. The attribute can be BL_HILITE_NONE,
BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
-- over is the hilite attribute used if value is at or above
the threshold. The attribute can be BL_HILITE_NONE,
BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
E. Misc. Routines

View File

@@ -5,6 +5,8 @@
#ifndef BOTL_H
#define BOTL_H
#ifdef STATUS_VIA_WINDOWPORT
#define BL_FLUSH -1
#define BL_TITLE 0
#define BL_STR 1
@@ -43,4 +45,20 @@
#define REASSESS_ONLY TRUE
#ifdef STATUS_HILITES
/* hilite status field behavior - coloridx values */
#define BL_HILITE_NONE -1 /* no hilite of this field */
#define BL_HILITE_INVERSE -2 /* inverse hilite */
#define BL_HILITE_BOLD -3 /* bold hilite */
/* or any CLR_ index (0 - 15) */
#define BL_TH_NONE 0
#define BL_TH_VAL_PERCENTAGE 100 /* threshold is percentage */
#define BL_TH_VAL_ABSOLUTE 101 /* threshold is particular value */
#define BL_TH_UPDOWN 102 /* threshold is up or down change */
#define BL_TH_CONDITION 103 /* threshold is bitmask of conditions */
#endif
extern const char *status_fieldnames[]; /* in botl.c */
#endif
#endif /* BOTL_H */

View File

@@ -355,6 +355,7 @@ typedef unsigned char uchar;
/*#define GOLDOBJ */ /* Gold is kept on obj chains - Helge Hafting */
#define AUTOPICKUP_EXCEPTIONS /* exceptions to autopickup */
#define STATUS_VIA_WINDOWPORT /* re-work of the status line updating process */
#define STATUS_HILITES /* support hilites of status fields */
/* End of Section 5 */

View File

@@ -152,6 +152,10 @@ E NEARDATA struct sinfo {
int panicking; /* `panic' is in progress */
#if defined(VMS) || defined(WIN32)
int exiting; /* an exit handler is executing */
#endif
int in_impossible;
#ifdef PANICLOG
int in_paniclog;
#endif
} program_state;

View File

@@ -140,6 +140,13 @@ E void NDECL(genl_status_init);
E void NDECL(genl_status_finish);
E void FDECL(genl_status_update, (int, genericptr_t, int, int));
E void FDECL(genl_status_enablefield, (int, const char *, const char *,BOOLEAN_P));
# ifdef STATUS_HILITES
E void FDECL(genl_status_threshold, (int,int,anything,int,int,int));
E boolean FDECL(set_status_hilites, (char *op));
E void NDECL(clear_status_hilites);
E char *FDECL(get_status_hilites, (char *, int));
E boolean NDECL(status_hilite_menu);
# endif
#endif
/* ### cmd.c ### */

View File

@@ -259,7 +259,6 @@ struct instance_flags {
boolean wc2_fullscreen; /* run fullscreen */
boolean wc2_softkeyboard; /* use software keyboard */
boolean wc2_wraptext; /* wrap text */
boolean cmdassist; /* provide detailed assistance for some commands */
boolean clicklook; /* allow right-clicking for look */
boolean obsolete; /* obsolete options can point at this, it isn't used */

View File

@@ -74,6 +74,9 @@ struct window_procs {
void NDECL((*win_status_finish));
void FDECL((*win_status_enablefield), (int,const char *,const char *,BOOLEAN_P));
void FDECL((*win_status_update), (int,genericptr_t,int,int));
# ifdef STATUS_HILITES
void FDECL((*win_status_threshold), (int,int,anything,int,int,int));
# endif
#endif
};
@@ -152,6 +155,9 @@ extern NEARDATA struct window_procs windowprocs;
*/
#define status_enablefield (*windowprocs.win_status_enablefield)
#define status_update (*windowprocs.win_status_update)
#ifdef STATUS_HILITES
#define status_threshold (*windowprocs.win_status_threshold)
#endif
#endif
/*
@@ -195,8 +201,9 @@ extern NEARDATA struct window_procs windowprocs;
#define WC2_FULLSCREEN 0x01L /* 01 display full screen */
#define WC2_SOFTKEYBOARD 0x02L /* 02 software keyboard */
#define WC2_WRAPTEXT 0x04L /* 04 wrap long lines of text */
/* 29 free bits */
#define WC2_WRAPTEXT 0x04L /* 03 wrap long lines of text */
#define WC2_HILITE_STATUS 0x08L /* 04 hilite fields in status */
/* 28 free bits */
#define ALIGN_LEFT 1
#define ALIGN_RIGHT 2

View File

@@ -15,14 +15,35 @@ typedef union any {
char a_char;
schar a_schar;
unsigned int a_uint;
long a_long;
unsigned long a_ulong;
int *a_iptr;
long *a_lptr;
unsigned long *a_ulptr;
unsigned *a_uptr;
/* add types as needed */
} anything;
#define ANY_P union any /* avoid typedef in prototypes */
/* (buggy old Ultrix compiler) */
/* symbolic names for the data types housed in anything */
#define ANY_VOID 1
#define ANY_OBJ 2 /* struct obj */
#define ANY_MONST 3 /* struct monst (not used) */
#define ANY_INT 4 /* int */
#define ANY_CHAR 5 /* char */
#define ANY_UCHAR 6 /* unsigned char */
#define ANY_SCHAR 7 /* signed char */
#define ANY_UINT 8 /* unsigned int */
#define ANY_LONG 9 /* long */
#define ANY_ULONG 10 /* unsigned long */
#define ANY_IPTR 11 /* pointer to int */
#define ANY_UPTR 12 /* pointer to unsigned int */
#define ANY_LPTR 13 /* pointer to long */
#define ANY_ULPTR 14 /* pointer to unsigned long */
#define ANY_STR 15 /* pointer to null-terminated char string */
#define ANY_MASK32 16 /* mask of 32 bits (stored as unsigned long) */
/* menu return list */
typedef struct mi {
anything item; /* identifier */

File diff suppressed because it is too large Load Diff

View File

@@ -2275,12 +2275,16 @@ const char *reason; /* explanation */
FILE *lfile;
char buf[BUFSZ];
lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX);
if (lfile) {
(void) fprintf(lfile, "%s %08ld: %s %s\n",
version_string(buf), yyyymmdd((time_t)0L),
type, reason);
(void) fclose(lfile);
if (!program_state.in_paniclog) {
program_state.in_paniclog = 1;
lfile = fopen_datafile(PANICLOG, "a", TROUBLEPREFIX);
if (lfile) {
(void) fprintf(lfile, "%s %08ld: %s %s\n",
version_string(buf), yyyymmdd((time_t)0L),
type, reason);
(void) fclose(lfile);
}
program_state.in_paniclog = 0;
}
#endif /* PANICLOG */
return;

View File

@@ -2138,7 +2138,23 @@ goodfruit:
return;
}
}
#if defined(STATUS_VIA_WINDOWPORT) && defined(STATUS_HILITES)
/* hilite fields in status prompt */
if (match_optname(opts, "hilite_status", 13, TRUE)) {
op = string_for_opt(opts, TRUE);
if (op && negated) {
clear_status_hilites();
return;
} else if (!op) {
/* a value is mandatory */
badoption(opts);
return;
}
if (!set_status_hilites(op))
badoption(opts);
return;
}
#endif
/* OK, if we still haven't recognized the option, check the boolean
* options list
*/
@@ -2474,12 +2490,23 @@ doset()
doset_add_menu(tmpwin, compopt[i].name,
(pass == DISP_IN_GAME) ? 0 : indexoffset);
}
#ifdef STATUS_VIA_WINDOWPORT
# ifdef STATUS_HILITES
any.a_int = -2;
get_status_hilites(buf2, 60);
if (!iflags.menu_tab_sep)
Sprintf(buf, fmtstr_doset_add_menu, any.a_int ? "" : " ",
"status_hilites", buf2);
else
Sprintf(buf, fmtstr_doset_add_menu_tab, "status_hilites", buf2);
add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED);
# endif
#endif
#ifdef AUTOPICKUP_EXCEPTIONS
any.a_int = -1;
Sprintf(buf, "autopickup exceptions (%d currently set)",
count_ape_maps((int *)0, (int *)0));
add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, MENU_UNSELECTED);
#endif /* AUTOPICKUP_EXCEPTIONS */
#ifdef PREFIXES_IN_USE
any.a_void = 0;
@@ -2501,10 +2528,22 @@ doset()
for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
opt_indx = pick_list[pick_idx].item.a_int - 1;
#ifdef AUTOPICKUP_EXCEPTIONS
if (opt_indx == -2) {
if (opt_indx == -2) { /* -3 due to -1 offset for select_menu() */
special_handling("autopickup_exception",
setinitial, fromfile);
} else
#endif
#ifdef STATUS_VIA_WINDOWPORT
# ifdef STATUS_HILITES
if (opt_indx == -3) { /* -3 due to -1 offset for select_menu() */
if (!status_hilite_menu())
pline("Bad status hilite(s) specified.");
else {
if (wc2_supported("status_hilites"))
preference_update("status_hilites");
}
} else
# endif
#endif
if (opt_indx < boolcount) {
/* boolean option */
@@ -3605,6 +3644,9 @@ struct wc_Opt wc2_options[] = {
{"fullscreen", WC2_FULLSCREEN},
{"softkeyboard", WC2_SOFTKEYBOARD},
{"wraptext", WC2_WRAPTEXT},
#ifdef STATUS_VIA_WINDOWPORT
{"hilite_status", WC2_HILITE_STATUS},
#endif
{(char *)0, 0L}
};

View File

@@ -252,6 +252,9 @@ void
impossible VA_DECL(const char *, s)
VA_START(s);
VA_INIT(s, const char *);
if (program_state.in_impossible)
panic("impossible called impossible");
program_state.in_impossible = 1;
{
char pbuf[BUFSZ];
Vsprintf(pbuf,s,VA_ARGS);
@@ -259,6 +262,7 @@ impossible VA_DECL(const char *, s)
}
vpline(s,VA_ARGS);
pline("Program in disorder - perhaps you'd better #quit.");
program_state.in_impossible = 0;
VA_END();
}

View File

@@ -87,6 +87,9 @@ struct window_procs amii_procs =
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};
@@ -154,6 +157,9 @@ struct window_procs amiv_procs =
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -2648,10 +2648,13 @@ struct window_procs mac_procs = {
genl_getmsghistory,
genl_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
genl_status_init,
genl_status_finish,
genl_status_enablefield,
genl_status_update,
genl_status_init,
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -102,6 +102,9 @@ struct window_procs mswin_procs = {
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -5286,6 +5286,9 @@ struct window_procs Qt_procs = {
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -167,6 +167,9 @@ struct window_procs X11_procs = {
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -105,6 +105,9 @@ struct window_procs Gem_procs = {
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -84,6 +84,9 @@ struct window_procs Gnome_procs = {
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -119,6 +119,9 @@ struct window_procs tty_procs = {
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};

View File

@@ -128,6 +128,9 @@ struct window_procs mswin_procs = {
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
};