- 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
parent deb233677e
commit d39a624942
6 changed files with 25 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -460,8 +460,7 @@ class SaveMenu : LoadSaveMenu
//
//
//=============================================================================
const SAVESTRINGSIZE = 32;
override bool MenuEvent (int mkey, bool fromcontroller)
{
if (Super.MenuEvent(mkey, fromcontroller))
@ -476,7 +475,7 @@ class SaveMenu : LoadSaveMenu
if (mkey == MKEY_Enter)
{
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();
mEntering = true;
}

View File

@ -92,7 +92,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable
{
if (i == 0)
{
mPlayerName = s.Mid(0, MAXPLAYERNAME);
mPlayerName = s;
return true;
}
return false;
@ -164,7 +164,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable
// Draw player name box
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)
{
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)
{
Menu.MenuSound ("menu/choose");
mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), mPlayerName, MAXPLAYERNAME, 2, fromcontroller);
mEnter = TextEnterMenu.Open(Menu.GetCurrentMenu(), mPlayerName, -1, 2, fromcontroller);
mEnter.ActivateMenu();
return true;
}