CHANGE_COLOR palette option adjustments

It was too early to call the windowport change_color() routine
while processing the config file. The windowport was not yet
fully operational.

Now the palette option processing will just place the rgb
value into the appropriate ga.altpalette[CLR_MAX] entry.

init_sound_disp_gamewindows(void) [allmain.c] calls
change_palette() [coloratt.c] and it will call the windowport
change_color() function for each ga.altpalette[] entry that
has been set.

Notes:
The rgb values stored in ga.altpalette[] have the NH_ALTPALETTE bit set
so that the rgb value of 0 can be stored and be distinguishable from
a "not set" entry.

The NH_ALTPALETTE bit is cleared from the rgb value in change_palette()
prior to calling the windowport change_color() function.

The syntax for palette is colorname/r-g-b.
For example: palette:black/12-12-12

colorname must be one of the NH_BASIC_COLOR names or a suitable
alias for one of those 16 entries.

Some of the windowport CHANGE_COLOR functions had the wrong parameters,
perhaps due to bitrot. Those have been corrected to match the prototype.
This commit is contained in:
nhmall
2024-04-12 21:57:27 -04:00
parent 749f2ffb0e
commit 15db874f71
13 changed files with 239 additions and 62 deletions
+7
View File
@@ -667,6 +667,13 @@ init_sound_disp_gamewindows(void)
SoundAchievement(0, sa2_newgame_nosplash, 0);
}
#ifdef CHANGE_COLOR
/* init_nhwindows() has already been called, so before
creating the windows, check to see if there are any
palette entries to alter */
change_palette();
#endif
WIN_MESSAGE = create_nhwindow(NHW_MESSAGE);
if (VIA_WINDOWPORT()) {
status_initialize(0);
+76
View File
@@ -1016,4 +1016,80 @@ get_nhcolor_from_256_index(int idx)
retcolor = color_256_definitions[idx].value;
return retcolor;
}
#ifdef CHANGE_COLOR
int
count_alt_palette(void)
{
int clr, clrcount = 0;
for (clr = 0; clr < CLR_MAX; ++clr) {
if (ga.altpalette[clr] != 0U)
clrcount++;
}
return clrcount;
}
int
alternative_palette(char *op)
{
char buf[BUFSZ], *c_colorid, *c_colorval, *cp;
int reslt = 0, coloridx = CLR_MAX;
long rgb = 0L;
boolean slash = FALSE;
if (!op)
return 0;
Snprintf(buf, sizeof buf, "%s", op);
c_colorval = (char *) 0;
c_colorid = cp = buf;
while (*cp) {
if (*cp == ':' || *cp == '/') {
if (*cp == '/') {
slash = TRUE;
*cp = '\0';
}
}
cp++;
if (slash) {
c_colorval = cp;
slash = FALSE;
}
}
/* some sanity checks */
if (c_colorid && *c_colorid == ' ')
c_colorid++;
if (c_colorval && *c_colorval == ' ')
c_colorval++;
if (c_colorid)
coloridx = match_str2clr(c_colorid, TRUE);
if (c_colorval && coloridx >= 0 && coloridx < CLR_MAX) {
rgb = rgbstr_to_int32(c_colorval);
if (rgb != -1) {
ga.altpalette[coloridx] = (uint32) rgb | NH_ALTPALETTE;
/* use COLORVAL(ga.altpalette[coloridx]) to get
the actual rgb value out of ga.altpalette[] */
reslt = 1;
}
}
return reslt;
}
void
change_palette(void)
{
int clridx;
for (clridx = 0; clridx < CLR_MAX; ++clridx) {
if (ga.altpalette[clridx] != 0) {
long rgb = (long) (ga.altpalette[clridx] & ~NH_ALTPALETTE);
(*windowprocs.win_change_color)(clridx, rgb, 0);
}
}
}
#endif /* CHANGE_COLOR */
/*coloratt.c*/
+6
View File
@@ -210,6 +210,11 @@ static const struct instance_globals_a g_init_a = {
/* mon.c */
UNDEFINED_PTR, /* animal_list */
UNDEFINED_VALUE, /* animal_list_count */
#ifdef CHANGE_COLOR
/* options.c */
{ 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U,
0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U }, /* altpalette[CLR_MAX] */
#endif
/* pickup.c */
0, /* A_first_hint */
0, /* A_second_hint */
@@ -661,6 +666,7 @@ static const struct instance_globals_o g_init_o = {
FALSE, /* opt_need_promptstyle */
FALSE, /* opt_reset_customcolors */
FALSE, /* opt_reset_customsymbols */
FALSE, /* opt_update_basic_palette */
/* pickup.c */
0, /* oldcap */
/* restore.c */
+79 -51
View File
@@ -315,6 +315,8 @@ static const menu_cmd_t default_menu_cmd_info[] = {
{ (char *) 0, '\0', (char *) 0 }
};
static const char n_currently_set[] = "(%d currently set)";
staticfn void nmcpy(char *, const char *, int);
staticfn void escapes(const char *, char *);
staticfn void rejectoption(const char *);
@@ -2575,57 +2577,78 @@ optfn_packorder(
}
#ifdef CHANGE_COLOR
DISABLE_WARNING_FORMAT_NONLITERAL
staticfn int
optfn_palette(
int optidx UNUSED, int req, boolean negated UNUSED,
char *opts, char *op)
{
#ifndef WIN32
int cnt, tmp, reverse;
char *pt = op;
long rgb;
#endif
if (req == do_init) {
return optn_ok;
}
if (req == do_set) {
if (op == empty_optstr)
return optn_err;
/*
Non-WIN32 variant
palette (00c/880/-fff is blue/yellow/reverse white)
WIN32 variant
palette (adjust an RGB color in palette (color-R-G-B)
*/
if (match_optname(opts, "palette", 3, TRUE)
#ifdef MAC
|| match_optname(opts, "hicolor", 3, TRUE)
#endif
) {
int color_number, color_incr;
#ifndef WIN32
if (duplicate)
complain_about_duplicate(optidx);
#endif
#ifdef MAC
if (match_optname(opts, "hicolor", 3, TRUE)) {
color_number = CLR_MAX + 4; /* HARDCODED inverse number */
color_incr = -1;
} else
#endif
{
color_number = 0;
color_incr = 1;
}
#ifdef WIN32
if (match_optname(opts, "palette", 3, TRUE)) {
/*
* palette (adjust an RGB color in palette (color/R-G-B)
*/
if (!alternative_palette(op)) {
config_error_add("Error in palette parameter '%s'", op);
return optn_err;
}
#else
if (!go.opt_initial)
go.opt_update_basic_palette = TRUE;
}
return optn_ok;
}
if (req == get_val || req == get_cnf_val) {
if (!opts)
return optn_err;
Sprintf(opts, n_currently_set, count_alt_palette());
return optn_ok;
}
return optn_ok;
}
#if 0
/* old MAC OS9 code */
staticfn int
optfn_palette(
int optidx UNUSED, int req, boolean negated UNUSED,
char *opts, char *op)
{
int cnt, tmp, reverse;
char *pt = op;
long rgb;
* Mac OS9 variant
* palette (00c/880/-fff is blue/yellow/reverse white)
*/
if (req == do_init) {
return optn_ok;
}
if (req == do_set) {
if (op == empty_optstr)
return optn_err;
if (match_optname(opts, "palette", 3, TRUE)
|| match_optname(opts, "hicolor", 3, TRUE)) {
int color_number, color_incr;
if (duplicate)
complain_about_duplicate(optidx);
if (match_optname(opts, "hicolor", 3, TRUE)) {
color_number = CLR_MAX + 4; /* HARDCODED inverse number */
color_incr = -1;
} else {
color_number = 0;
color_incr = 1;
}
/* ----------- Mac OS 9 code -------------------------*/
while (*pt && color_number >= 0) {
cnt = 3;
rgb = 0L;
@@ -2637,21 +2660,15 @@ optfn_palette(
}
while (cnt-- > 0) {
if (*pt && *pt != '/') {
#ifdef AMIGA
rgb <<= 4;
#else
rgb <<= 8;
#endif
tmp = *pt++;
if (isalpha((uchar) tmp)) {
tmp = (tmp + 9) & 0xf; /* Assumes ASCII... */
} else {
tmp &= 0xf; /* Digits in ASCII too... */
}
#ifndef AMIGA
/* Add an extra so we fill f -> ff and 0 -> 00 */
rgb += tmp << 4;
#endif
rgb += tmp;
}
}
@@ -2660,20 +2677,25 @@ optfn_palette(
change_color(color_number, rgb, reverse);
color_number += color_incr;
}
#endif /* !WIN32 */
if (!go.opt_initial) {
go.opt_need_redraw = TRUE;
}
if (!go.opt_initial)
go.opt_update_basic_palette = TRUE;
}
return optn_ok;
}
if (req == get_val || req == get_cnf_val) {
opts[0] = '\0';
Sprintf(opts, "%s", get_color_string());
if (!opts)
return optn_err;
Sprintf(opts, n_currently_set, count_alt_palette());
return optn_ok;
}
return optn_ok;
}
#endif /* 0 */
RESTORE_WARNING_FORMAT_NONLITERAL
#endif /* CHANGE_COLOR */
/* for "paranoid_confirmation:foo" and alias "[!]prayconfirm" */
@@ -6333,7 +6355,6 @@ handler_msgtype(void)
return optn_ok;
}
staticfn int
handler_versinfo(void)
{
@@ -8071,8 +8092,6 @@ fruitadd(char *str, struct fruit *replace_fruit)
*/
static const char n_currently_set[] = "(%d currently set)";
DISABLE_WARNING_FORMAT_NONLITERAL /* RESTORE is after show_menucontrols() */
staticfn int
@@ -8400,6 +8419,7 @@ doset_simple_menu(void)
go.opt_need_glyph_reset = FALSE;
go.opt_reset_customcolors = FALSE;
go.opt_reset_customsymbols = FALSE;
go.opt_update_basic_palette = 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 */
@@ -8490,6 +8510,10 @@ doset_simple(void)
}
if (go.opt_need_promptstyle)
adjust_menu_promptstyle(WIN_INVEN, &iflags.menu_headings);
if (go.opt_update_basic_palette) {
change_palette();
go.opt_update_basic_palette = FALSE;
}
if (go.opt_reset_customcolors || go.opt_reset_customsymbols) {
if (go.opt_reset_customcolors)
reset_customcolors();
@@ -8745,8 +8769,12 @@ doset(void) /* changing options via menu by Per Liboriussen */
if (go.opt_need_glyph_reset) {
reset_glyphmap(gm_optionchange);
}
if (go.opt_reset_customcolors
if (go.opt_reset_customcolors || go.opt_update_basic_palette
|| go.opt_reset_customsymbols || go.opt_need_redraw) {
if (go.opt_update_basic_palette) {
change_palette();
go.opt_update_basic_palette = FALSE;
}
if (go.opt_reset_customcolors)
reset_customcolors();
if (go.opt_reset_customsymbols)
+1 -1
View File
@@ -790,7 +790,7 @@ hup_cliparound(int x UNUSED, int y UNUSED)
#ifdef CHANGE_COLOR
/*ARGSUSED*/
staticfn void
hup_change_color(int color, int reverse, long rgb)
hup_change_color(int color, long rgb, int reverse)
{
return;
}