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
+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*/