* Implement fixes/tweaks as written on the gitlab.

* `SPR2_NTAG` last vestiges removal.
    * Removed need for `getskinfromdescription()` by calculating it once, at Menu load, and storing in `description_t`.
    * Fixed nametag colour issues.
    * Support widescreen with nametags.

* Fix a metric SHITTON of compiler errors.
    * Redefining `x` and `y` within scope of previous `x` and `y` (`M_DrawSetupChoosePlayerMenu`)
    * GCC straight up will not let you cast a `const char*` to a `char` (`V_DrawNameTag`)
    * Redefining `lines` within the scope of the global.
    * Redefining `string` within the function-specific `string`.
    * It would be recommended for y'alls to turn ERRORMODE on!
This commit is contained in:
toaster 2019-10-19 18:15:54 +01:00
parent 28607a81b5
commit bf761a26d6
4 changed files with 121 additions and 160 deletions

View File

@ -702,7 +702,6 @@ playersprite_t spr2defaults[NUMPLAYERSPRITES] = {
0, // SPR2_LIFE, 0, // SPR2_LIFE,
0, // SPR2_XTRA (should never be referenced) 0, // SPR2_XTRA (should never be referenced)
0, // SPR2_NTAG
}; };
// Doesn't work with g++, needs actionf_p1 (don't modify this comment) // Doesn't work with g++, needs actionf_p1 (don't modify this comment)

View File

@ -7894,7 +7894,7 @@ static void M_SetupChoosePlayer(INT32 choice)
UINT8 firstvalid = 255; UINT8 firstvalid = 255;
UINT8 lastvalid = 0; UINT8 lastvalid = 0;
boolean allowed = false; boolean allowed = false;
char *name; char *and;
(void)choice; (void)choice;
SP_PlayerMenu[0].status &= ~IT_DYBIGSPACE; // Correcting a hack that may be made below. SP_PlayerMenu[0].status &= ~IT_DYBIGSPACE; // Correcting a hack that may be made below.
@ -7903,8 +7903,21 @@ static void M_SetupChoosePlayer(INT32 choice)
{ {
if (description[i].used) // If the character's disabled through SOC, there's nothing we can do for it. if (description[i].used) // If the character's disabled through SOC, there's nothing we can do for it.
{ {
name = strtok(Z_StrDup(description[i].skinname), "&"); and = strchr(description[i].skinname, '&');
skinnum = R_SkinAvailable(name); if (and)
{
char firstskin[SKINNAMESIZE+1];
strncpy(firstskin, description[i].skinname, (and - description[i].skinname));
firstskin[(and - description[i].skinname)] = '\0';
description[i].skinnum[0] = R_SkinAvailable(firstskin);
description[i].skinnum[1] = R_SkinAvailable(and+1);
}
else
{
description[i].skinnum[0] = R_SkinAvailable(description[i].skinname);
description[i].skinnum[1] = -1;
}
skinnum = description[i].skinnum[0];
if ((skinnum != -1) && (R_SkinUsable(-1, skinnum))) if ((skinnum != -1) && (R_SkinUsable(-1, skinnum)))
{ {
// Handling order. // Handling order.
@ -7943,7 +7956,6 @@ static void M_SetupChoosePlayer(INT32 choice)
} }
} }
// else -- Technically, character select icons without corresponding skins get bundled away behind this too. Sucks to be them. // else -- Technically, character select icons without corresponding skins get bundled away behind this too. Sucks to be them.
Z_Free(name);
} }
} }
@ -8060,18 +8072,6 @@ static void M_HandleChoosePlayerMenu(INT32 choice)
// Draw the choose player setup menu, had some fun with player anim // Draw the choose player setup menu, had some fun with player anim
//define CHOOSEPLAYER_DRAWHEADER //define CHOOSEPLAYER_DRAWHEADER
static INT32 getskinfromdescription(INT32 desc)
{
char *and = strchr(description[desc].skinname, '&');
if (and)
{
char firstskin[SKINNAMESIZE];
strncpy(firstskin, description[desc].skinname, and - (description[desc].skinname));
return R_SkinAvailable(firstskin);
}
return R_SkinAvailable(description[desc].skinname);
}
static void M_DrawSetupChoosePlayerMenu(void) static void M_DrawSetupChoosePlayerMenu(void)
{ {
const INT32 my = 16; const INT32 my = 16;
@ -8088,7 +8088,8 @@ static void M_DrawSetupChoosePlayerMenu(void)
INT16 fgheight = SHORT(charfg->height); INT16 fgheight = SHORT(charfg->height);
INT16 bgwidth = SHORT(charbg->width); INT16 bgwidth = SHORT(charbg->width);
INT16 fgwidth = SHORT(charfg->width); INT16 fgwidth = SHORT(charfg->width);
INT32 y; INT32 x, y;
INT32 w = (vid.width/vid.dupx);
if (abs(char_scroll) > FRACUNIT) if (abs(char_scroll) > FRACUNIT)
char_scroll -= (char_scroll>>2); char_scroll -= (char_scroll>>2);
@ -8106,9 +8107,8 @@ static void M_DrawSetupChoosePlayerMenu(void)
prev = -1; prev = -1;
// Find skin number from description[] // Find skin number from description[]
skinnum = getskinfromdescription(char_on); skinnum = description[char_on].skinnum[0];
if (skinnum != -1) charskin = &skins[skinnum];
charskin = &skins[skinnum];
// Use the opposite of the character's skincolor // Use the opposite of the character's skincolor
col = description[char_on].oppositecolor; col = description[char_on].oppositecolor;
@ -8116,7 +8116,7 @@ static void M_DrawSetupChoosePlayerMenu(void)
col = Color_Opposite[charskin->prefcolor - 1][0]; col = Color_Opposite[charskin->prefcolor - 1][0];
// Make the translation colormap // Make the translation colormap
colormap = R_GetTranslationColormap(skinnum, col, 0); colormap = R_GetTranslationColormap(TC_DEFAULT, col, 0);
// Don't render the title map // Don't render the title map
hidetitlemap = true; hidetitlemap = true;
@ -8142,8 +8142,8 @@ static void M_DrawSetupChoosePlayerMenu(void)
// Character pictures // Character pictures
{ {
INT32 x = 8; x = 8;
INT32 y = (my+16) - FixedInt(char_scroll); y = (my+16) - FixedInt(char_scroll);
V_DrawScaledPatch(x, y, 0, description[char_on].charpic); V_DrawScaledPatch(x, y, 0, description[char_on].charpic);
if (prev != -1) if (prev != -1)
V_DrawScaledPatch(x, y - 144, 0, description[prev].charpic); V_DrawScaledPatch(x, y - 144, 0, description[prev].charpic);
@ -8153,16 +8153,15 @@ static void M_DrawSetupChoosePlayerMenu(void)
// Character description // Character description
{ {
INT32 x = 146;
INT32 y = my + 9;
INT32 flags = V_ALLOWLOWERCASE|V_RETURN8; INT32 flags = V_ALLOWLOWERCASE|V_RETURN8;
x = 146;
y = my + 9;
V_DrawString(x, y, flags, char_notes); V_DrawString(x, y, flags, char_notes);
} }
// Name tags // Name tags
{ {
INT32 ox, x, y; INT32 ox, oxsh = FixedInt(FixedMul(BASEVIDWIDTH*FRACUNIT, FixedDiv(char_scroll, 128*FRACUNIT))), txsh;
INT32 oxsh = FixedInt(FixedMul(BASEVIDWIDTH*FRACUNIT, FixedDiv(char_scroll, 128*FRACUNIT))), txsh;
patch_t *curpatch = NULL, *prevpatch = NULL, *nextpatch = NULL; patch_t *curpatch = NULL, *prevpatch = NULL, *nextpatch = NULL;
const char *curtext = NULL, *prevtext = NULL, *nexttext = NULL; const char *curtext = NULL, *prevtext = NULL, *nexttext = NULL;
UINT8 curtextcolor = 0, prevtextcolor = 0, nexttextcolor = 0; UINT8 curtextcolor = 0, prevtextcolor = 0, nexttextcolor = 0;
@ -8174,75 +8173,60 @@ static void M_DrawSetupChoosePlayerMenu(void)
curoutlinecolor = description[char_on].tagoutlinecolor; curoutlinecolor = description[char_on].tagoutlinecolor;
if (curtext[0] == '\0') if (curtext[0] == '\0')
curpatch = description[char_on].namepic; curpatch = description[char_on].namepic;
if (skinnum != -1) if (!curtextcolor)
{ curtextcolor = charskin->prefcolor;
if (!curtextcolor) if (!curoutlinecolor)
curtextcolor = charskin->prefcolor; curoutlinecolor = Color_Opposite[charskin->prefcolor - 1][0];
if (!curoutlinecolor)
curoutlinecolor = Color_Opposite[charskin->prefcolor - 1][0];
}
// previous character
if (prev != -1)
{
prevtext = description[prev].displayname;
prevtextcolor = description[prev].tagtextcolor;
prevoutlinecolor = description[prev].tagoutlinecolor;
if (prevtext[0] == '\0')
prevpatch = description[prev].namepic;
// Find skin number from description[]
skinnum = getskinfromdescription(prev);
if (skinnum != -1)
{
charskin = &skins[skinnum];
if (!prevtextcolor)
prevtextcolor = charskin->prefcolor;
if (!prevoutlinecolor)
prevoutlinecolor = Color_Opposite[charskin->prefcolor - 1][0];
}
}
// next character
if (next != -1)
{
nexttext = description[next].displayname;
nexttextcolor = description[next].tagtextcolor;
nextoutlinecolor = description[next].tagoutlinecolor;
if (nexttext[0] == '\0')
nextpatch = description[next].namepic;
// Find skin number from description[]
skinnum = getskinfromdescription(next);
if (skinnum != -1)
{
charskin = &skins[skinnum];
if (!nexttextcolor)
nexttextcolor = charskin->prefcolor;
if (!nextoutlinecolor)
nextoutlinecolor = Color_Opposite[charskin->prefcolor - 1][0];
}
}
txsh = oxsh; txsh = oxsh;
ox = 8 + SHORT((description[char_on].charpic)->width)/2; ox = 8 + SHORT((description[char_on].charpic)->width)/2;
y = my + 144; y = my + 144;
// cur
{
x = ox - txsh;
if (curpatch)
x -= (SHORT(curpatch->width)/2);
if (curtext[0] != '\0')
{
V_DrawNameTag(
x, y, V_CENTERNAMETAG, FRACUNIT,
R_GetTranslationColormap(TC_DEFAULT, curtextcolor, 0),
R_GetTranslationColormap(TC_DEFAULT, curoutlinecolor, 0),
curtext
);
}
else if (curpatch)
V_DrawScaledPatch(x, y, 0, curpatch);
}
if (char_scroll) if (char_scroll)
{ {
// prev // prev
if ((prev != -1) && char_scroll < 0) if ((prev != -1) && char_scroll < 0)
{ {
INT32 ox2 = ox; prevtext = description[prev].displayname;
prevtextcolor = description[prev].tagtextcolor;
prevoutlinecolor = description[prev].tagoutlinecolor;
if (prevtext[0] == '\0')
prevpatch = description[prev].namepic;
charskin = &skins[description[prev].skinnum[0]];
if (!prevtextcolor)
prevtextcolor = charskin->prefcolor;
if (!prevoutlinecolor)
prevoutlinecolor = Color_Opposite[charskin->prefcolor - 1][0];
x = (ox - txsh) - w;
if (prevpatch) if (prevpatch)
ox2 -= (SHORT(prevpatch->width)/2); x -= (SHORT(prevpatch->width)/2);
// Why does this work?
x = (ox2 - txsh) - BASEVIDWIDTH;
if (prevtext[0] != '\0') if (prevtext[0] != '\0')
{ {
skinnum = getskinfromdescription(prev);
V_DrawNameTag( V_DrawNameTag(
x, y, V_CENTERNAMETAG, FRACUNIT, x, y, V_CENTERNAMETAG, FRACUNIT,
R_GetTranslationColormap(skinnum, prevtextcolor, 0), R_GetTranslationColormap(TC_DEFAULT, prevtextcolor, 0),
R_GetTranslationColormap(skinnum, prevoutlinecolor, 0), R_GetTranslationColormap(TC_DEFAULT, prevoutlinecolor, 0),
prevtext prevtext
); );
} }
@ -8252,47 +8236,33 @@ static void M_DrawSetupChoosePlayerMenu(void)
// next // next
else if ((next != -1) && char_scroll > 0) else if ((next != -1) && char_scroll > 0)
{ {
INT32 ox2 = ox; nexttext = description[next].displayname;
if (nextpatch) nexttextcolor = description[next].tagtextcolor;
ox2 -= (SHORT(nextpatch->width)/2); nextoutlinecolor = description[next].tagoutlinecolor;
x = (ox2 - txsh) + BASEVIDWIDTH; if (nexttext[0] == '\0')
if (x < BASEVIDWIDTH) nextpatch = description[next].namepic;
{ charskin = &skins[description[next].skinnum[0]];
if (nexttext[0] != '\0') if (!nexttextcolor)
{ nexttextcolor = charskin->prefcolor;
skinnum = getskinfromdescription(next); if (!nextoutlinecolor)
V_DrawNameTag( nextoutlinecolor = Color_Opposite[charskin->prefcolor - 1][0];
x, y, V_CENTERNAMETAG, FRACUNIT,
R_GetTranslationColormap(skinnum, nexttextcolor, 0),
R_GetTranslationColormap(skinnum, nextoutlinecolor, 0),
nexttext
);
}
else if (nextpatch)
V_DrawScaledPatch(x, y, 0, nextpatch);
}
}
}
// cur x = (ox - txsh) + w;
skinnum = getskinfromdescription(next); if (nextpatch)
if (skinnum != -1) x -= (SHORT(nextpatch->width)/2);
{
INT32 ox2 = ox; if (nexttext[0] != '\0')
if (curpatch) {
ox2 -= (SHORT(curpatch->width)/2); V_DrawNameTag(
x = ox2 - txsh; x, y, V_CENTERNAMETAG, FRACUNIT,
if (curtext[0] != '\0') R_GetTranslationColormap(TC_DEFAULT, nexttextcolor, 0),
{ R_GetTranslationColormap(TC_DEFAULT, nextoutlinecolor, 0),
V_DrawNameTag( nexttext
x, y, V_CENTERNAMETAG, FRACUNIT, );
R_GetTranslationColormap(skinnum, curtextcolor, 0), }
R_GetTranslationColormap(skinnum, curoutlinecolor, 0), else if (nextpatch)
curtext V_DrawScaledPatch(x, y, 0, nextpatch);
);
} }
else if (curpatch)
V_DrawScaledPatch(x, y, 0, curpatch);
} }
} }
@ -8312,8 +8282,6 @@ static void M_DrawSetupChoosePlayerMenu(void)
// Chose the player you want to use Tails 03-02-2002 // Chose the player you want to use Tails 03-02-2002
static void M_ChoosePlayer(INT32 choice) static void M_ChoosePlayer(INT32 choice)
{ {
char *skin1,*skin2;
INT32 skinnum;
boolean ultmode = (ultimate_selectable && SP_PlayerDef.prevMenu == &SP_LoadDef && saveSlotSelected == NOSAVESLOT); boolean ultmode = (ultimate_selectable && SP_PlayerDef.prevMenu == &SP_LoadDef && saveSlotSelected == NOSAVESLOT);
// skip this if forcecharacter or no characters available // skip this if forcecharacter or no characters available
@ -8327,21 +8295,14 @@ static void M_ChoosePlayer(INT32 choice)
} }
M_ClearMenus(true); M_ClearMenus(true);
skin1 = strtok(description[choice].skinname, "&"); if (description[choice].skinnum[1] != -1) {
skin2 = strtok(NULL, "&");
if (skin2) {
// this character has a second skin // this character has a second skin
skinnum = R_SkinAvailable(skin1);
botskin = (UINT8)(R_SkinAvailable(skin2)+1);
botingame = true; botingame = true;
botskin = (UINT8)(description[choice].skinnum[1]+1);
botcolor = skins[botskin-1].prefcolor; botcolor = skins[description[choice].skinnum[1]].prefcolor;
}
// undo the strtok else
description[choice].skinname[strlen(skin1)] = '&'; {
} else {
skinnum = R_SkinAvailable(description[choice].skinname);
botingame = false; botingame = false;
botskin = 0; botskin = 0;
botcolor = 0; botcolor = 0;
@ -8353,7 +8314,7 @@ static void M_ChoosePlayer(INT32 choice)
//lastmapsaved = 0; //lastmapsaved = 0;
gamecomplete = false; gamecomplete = false;
G_DeferedInitNew(ultmode, G_BuildMapName(startmap), (UINT8)skinnum, false, fromlevelselect); G_DeferedInitNew(ultmode, G_BuildMapName(startmap), (UINT8)description[choice].skinnum[0], false, fromlevelselect);
COM_BufAddText("dummyconsvar 1\n"); // G_DeferedInitNew doesn't do this COM_BufAddText("dummyconsvar 1\n"); // G_DeferedInitNew doesn't do this
if (levelselect.rows) if (levelselect.rows)

View File

@ -329,6 +329,7 @@ typedef struct
// new character select // new character select
char displayname[SKINNAMESIZE+1]; char displayname[SKINNAMESIZE+1];
SINT8 skinnum[2];
UINT8 oppositecolor; UINT8 oppositecolor;
char nametag[8]; char nametag[8];
patch_t *namepic; patch_t *namepic;

View File

@ -2698,16 +2698,16 @@ static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UIN
// Looks familiar. // Looks familiar.
void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecolormap, UINT8 *outlinecolormap, const char *string) void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecolormap, UINT8 *outlinecolormap, const char *string)
{ {
char *text = (char *)string; const char *text = string;
char *first_token = text; const char *first_token = text;
char *last_token = strchr(text, '\n'); char *last_token = strchr(text, '\n');
const INT32 lbreakheight = 21; const INT32 lbreakheight = 21;
INT32 lines; INT32 ntlines;
if (option & V_CENTERNAMETAG) if (option & V_CENTERNAMETAG)
{ {
lines = V_CountNameTagLines(string); ntlines = V_CountNameTagLines(string);
y -= FixedInt(FixedMul(((lbreakheight/2) * (lines-1))*FRACUNIT, scale)); y -= FixedInt(FixedMul(((lbreakheight/2) * (ntlines-1))*FRACUNIT, scale));
} }
// No line breaks? // No line breaks?
@ -2717,7 +2717,7 @@ void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecol
// Split string by the line break character // Split string by the line break character
else else
{ {
char *string = NULL; char *str = NULL;
INT32 len; INT32 len;
while (true) while (true)
{ {
@ -2726,20 +2726,20 @@ void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecol
{ {
size_t shift = 0; size_t shift = 0;
// Free this line // Free this line
if (string) if (str)
Z_Free(string); Z_Free(str);
// Find string length, do a malloc... // Find string length, do a malloc...
len = (last_token-first_token)+1; len = (last_token-first_token)+1;
string = ZZ_Alloc(len); str = ZZ_Alloc(len);
// Copy the line // Copy the line
strncpy(string, first_token, len-1); strncpy(str, first_token, len-1);
string[len-1] = '\0'; str[len-1] = '\0';
// Don't leave a line break character // Don't leave a line break character
// at the start of the string! // at the start of the string!
if ((strlen(string) >= 2) && (string[0] == '\n') && (string[1] != '\n')) if ((strlen(str) >= 2) && (string[0] == '\n') && (string[1] != '\n'))
shift++; shift++;
// Then draw it // Then draw it
V_DrawNameTagLine(x, y, option, scale, basecolormap, outlinecolormap, string+shift); V_DrawNameTagLine(x, y, option, scale, basecolormap, outlinecolormap, str+shift);
} }
// No line break character was found // No line break character was found
else else
@ -2755,7 +2755,7 @@ void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecol
// Next line // Next line
y += FixedInt(FixedMul(lbreakheight*FRACUNIT, scale)); y += FixedInt(FixedMul(lbreakheight*FRACUNIT, scale));
if ((last_token-text)+1 >= strlen(text)) if ((last_token-text)+1 >= (signed)strlen(text))
last_token = NULL; last_token = NULL;
else else
{ {
@ -2764,35 +2764,35 @@ void V_DrawNameTag(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecol
} }
} }
// Free this line // Free this line
if (string) if (str)
Z_Free(string); Z_Free(str);
} }
} }
// Count the amount of lines in name tag string // Count the amount of lines in name tag string
INT32 V_CountNameTagLines(const char *string) INT32 V_CountNameTagLines(const char *string)
{ {
INT32 lines = 1; INT32 ntlines = 1;
char *text = (char *)string; const char *text = string;
char *first_token = text; const char *first_token = text;
char *last_token = strchr(text, '\n'); char *last_token = strchr(text, '\n');
// No line breaks? // No line breaks?
if (!last_token) if (!last_token)
return lines; return ntlines;
// Split string by the line break character // Split string by the line break character
else else
{ {
while (true) while (true)
{ {
if (last_token) if (last_token)
lines++; ntlines++;
// No line break character was found // No line break character was found
else else
break; break;
// Next line // Next line
if ((last_token-text)+1 >= strlen(text)) if ((last_token-text)+1 >= (signed)strlen(text))
last_token = NULL; last_token = NULL;
else else
{ {
@ -2801,7 +2801,7 @@ INT32 V_CountNameTagLines(const char *string)
} }
} }
} }
return lines; return ntlines;
} }
INT32 V_NameTagWidth(const char *string) INT32 V_NameTagWidth(const char *string)