- fixed the player name display.

This was broken by several small unicode-incompatible code fragments.
This commit also removes the input limit for the player name and the savegame description. With multibyte encoding, limiting them to a fixed length did not work right.
Currently these will just overflow the fields if the text becomes too long, this needs some additional work.
This commit is contained in:
Christoph Oelckers 2019-02-16 22:57:02 +01:00 committed by drfrag
parent f790d48041
commit 1e9a65e673
6 changed files with 25 additions and 29 deletions

View file

@ -623,15 +623,15 @@ void FConfigFile::LoadConfigFile ()
bool FConfigFile::ReadConfig (void *file) bool FConfigFile::ReadConfig (void *file)
{ {
char readbuf[READBUFFERSIZE]; uint8_t readbuf[READBUFFERSIZE];
FConfigSection *section = NULL; FConfigSection *section = NULL;
ClearConfig (); ClearConfig ();
while (ReadLine (readbuf, READBUFFERSIZE, file) != NULL) while (ReadLine ((char*)readbuf, READBUFFERSIZE, file) != NULL)
{ {
char *start = readbuf; uint8_t *start = readbuf;
char *equalpt; uint8_t *equalpt;
char *endpt; uint8_t *endpt;
// Remove white space at start of line // Remove white space at start of line
while (*start && *start <= ' ') while (*start && *start <= ' ')
@ -644,7 +644,7 @@ bool FConfigFile::ReadConfig (void *file)
continue; continue;
} }
// Do not process tail of long line // Do not process tail of long line
const bool longline = (READBUFFERSIZE - 1) == strlen(readbuf) && '\n' != readbuf[READBUFFERSIZE - 2]; const bool longline = (READBUFFERSIZE - 1) == strlen((char*)readbuf) && '\n' != readbuf[READBUFFERSIZE - 2];
if (longline) if (longline)
{ {
endpt = start + READBUFFERSIZE - 2; endpt = start + READBUFFERSIZE - 2;
@ -652,7 +652,7 @@ bool FConfigFile::ReadConfig (void *file)
else else
{ {
// Remove white space at end of line // Remove white space at end of line
endpt = start + strlen (start) - 1; endpt = start + strlen ((char*)start) - 1;
while (endpt > start && *endpt <= ' ') while (endpt > start && *endpt <= ' ')
{ {
endpt--; endpt--;
@ -667,7 +667,7 @@ bool FConfigFile::ReadConfig (void *file)
{ // Section header { // Section header
if (*endpt == ']') if (*endpt == ']')
*endpt = 0; *endpt = 0;
section = NewConfigSection (start+1); section = NewConfigSection ((char*)start+1);
} }
else if (section == NULL) else if (section == NULL)
{ {
@ -675,11 +675,11 @@ bool FConfigFile::ReadConfig (void *file)
} }
else else
{ // Should be key=value { // Should be key=value
equalpt = strchr (start, '='); equalpt = (uint8_t*)strchr ((char*)start, '=');
if (equalpt != NULL && equalpt > start) if (equalpt != NULL && equalpt > start)
{ {
// Remove white space in front of = // Remove white space in front of =
char *whiteprobe = equalpt - 1; uint8_t *whiteprobe = equalpt - 1;
while (whiteprobe > start && isspace(*whiteprobe)) while (whiteprobe > start && isspace(*whiteprobe))
{ {
whiteprobe--; whiteprobe--;
@ -695,16 +695,16 @@ bool FConfigFile::ReadConfig (void *file)
// Check for multi-line value // Check for multi-line value
if (whiteprobe[0] == '<' && whiteprobe[1] == '<' && whiteprobe[2] == '<' && whiteprobe[3] != '\0') if (whiteprobe[0] == '<' && whiteprobe[1] == '<' && whiteprobe[2] == '<' && whiteprobe[3] != '\0')
{ {
ReadMultiLineValue (file, section, start, whiteprobe + 3); ReadMultiLineValue (file, section, (char*)start, (char*)whiteprobe + 3);
} }
else if (longline) else if (longline)
{ {
const FString key = start; const FString key = (char*)start;
FString value = whiteprobe; FString value = (char*)whiteprobe;
while (ReadLine (readbuf, READBUFFERSIZE, file) != NULL) while (ReadLine ((char*)readbuf, READBUFFERSIZE, file) != NULL)
{ {
const size_t endpos = (0 == readbuf[0]) ? 0 : (strlen(readbuf) - 1); const size_t endpos = (0 == readbuf[0]) ? 0 : (strlen((char*)readbuf) - 1);
const bool endofline = '\n' == readbuf[endpos]; const bool endofline = '\n' == readbuf[endpos];
if (endofline) if (endofline)
@ -712,7 +712,7 @@ bool FConfigFile::ReadConfig (void *file)
readbuf[endpos] = 0; readbuf[endpos] = 0;
} }
value += readbuf; value += (char*)readbuf;
if (endofline) if (endofline)
{ {
@ -724,7 +724,7 @@ bool FConfigFile::ReadConfig (void *file)
} }
else else
{ {
NewConfigEntry (section, start, whiteprobe); NewConfigEntry (section, (char*)start, (char*)whiteprobe);
} }
} }
} }

View file

@ -151,8 +151,6 @@ enum
extern AActor *WP_NOCHANGE; extern AActor *WP_NOCHANGE;
#define MAXPLAYERNAME 15
// [GRB] Custom player classes // [GRB] Custom player classes
enum enum
{ {

View file

@ -94,7 +94,7 @@ int utf8_decode(const uint8_t *src, int *size)
return c; return c;
} }
int c1 = src[1]; int c1 = src[1] & 0x3f;
if ((c & 0xE0) == 0xC0) if ((c & 0xE0) == 0xC0)
{ {
@ -107,7 +107,7 @@ int utf8_decode(const uint8_t *src, int *size)
return -1; return -1;
} }
int c2 = src[2]; int c2 = src[2] & 0x3f;
if ((c & 0xF0) == 0xE0) if ((c & 0xF0) == 0xE0)
{ {
@ -120,7 +120,7 @@ int utf8_decode(const uint8_t *src, int *size)
return -1; return -1;
} }
int c3 = src[3]; int c3 = src[3] & 0x3f;
if ((c & 0xF8) == 0xF0) if ((c & 0xF8) == 0xF0)
{ {

View file

@ -1,7 +1,6 @@
// for flag changer functions. // for flag changer functions.
const FLAG_NO_CHANGE = -1; const FLAG_NO_CHANGE = -1;
const MAXPLAYERS = 8; const MAXPLAYERS = 8;
const MAXPLAYERNAME = 15;
enum EStateUseFlags enum EStateUseFlags
{ {

View file

@ -460,7 +460,6 @@ class SaveMenu : LoadSaveMenu
// //
// //
//============================================================================= //=============================================================================
const SAVESTRINGSIZE = 32;
override bool MenuEvent (int mkey, bool fromcontroller) override bool MenuEvent (int mkey, bool fromcontroller)
{ {
@ -476,7 +475,7 @@ class SaveMenu : LoadSaveMenu
if (mkey == MKEY_Enter) if (mkey == MKEY_Enter)
{ {
String SavegameString = (Selected != 0)? manager.GetSavegame(Selected).SaveTitle : ""; String SavegameString = (Selected != 0)? manager.GetSavegame(Selected).SaveTitle : "";
mInput = TextEnterMenu.Open(self, SavegameString, SAVESTRINGSIZE, 1, fromcontroller); mInput = TextEnterMenu.Open(self, SavegameString, -1, 1, fromcontroller);
mInput.ActivateMenu(); mInput.ActivateMenu();
mEntering = true; mEntering = true;
} }

View file

@ -92,7 +92,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable
{ {
if (i == 0) if (i == 0)
{ {
mPlayerName = s.Mid(0, MAXPLAYERNAME); mPlayerName = s;
return true; return true;
} }
return false; return false;
@ -164,7 +164,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable
// Draw player name box // Draw player name box
double x = mXpos + mFont.StringWidth(text) + 16 + mFrameSize; double x = mXpos + mFont.StringWidth(text) + 16 + mFrameSize;
DrawBorder (x, mYpos - mFrameSize, MAXPLAYERNAME+1); DrawBorder (x, mYpos - mFrameSize, 16); // This creates a 128 pixel wide text box.
if (!mEnter) if (!mEnter)
{ {
screen.DrawText (SmallFont, Font.CR_UNTRANSLATED, x + mFrameSize, mYpos, mPlayerName, DTA_Clean, true); screen.DrawText (SmallFont, Font.CR_UNTRANSLATED, x + mFrameSize, mYpos, mPlayerName, DTA_Clean, true);
@ -187,7 +187,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable
if (mkey == Menu.MKEY_Enter) if (mkey == Menu.MKEY_Enter)
{ {
Menu.MenuSound ("menu/choose"); Menu.MenuSound ("menu/choose");
mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), mPlayerName, MAXPLAYERNAME, 2, fromcontroller); mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), mPlayerName, -1, 2, fromcontroller);
mEnter.ActivateMenu(); mEnter.ActivateMenu();
return true; return true;
} }