Instead of immediately modifying setup player name when typing (and
restoring it when aborting by pressing Escape key), use internal
string buffer instead and only update setup player name after typing
name was successfully finished.
static void HandleTypeNameExt(boolean initialize, Key key)
{
static void HandleTypeNameExt(boolean initialize, Key key)
{
+ static char name[MAX_PLAYER_NAME_LEN + 1];
static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
struct TextPosInfo *pos = mci->pos_input;
static char last_player_name[MAX_PLAYER_NAME_LEN + 1];
struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
struct TextPosInfo *pos = mci->pos_input;
- strcpy(last_player_name, setup.player_name);
+ strcpy(name, setup.player_name);
+ strcpy(last_player_name, name);
- xpos = strlen(setup.player_name);
StartTextInput(sx, sy, pos->width, pos->height);
}
else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
{
StartTextInput(sx, sy, pos->width, pos->height);
}
else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
{
- setup.player_name[xpos] = key_char;
- setup.player_name[xpos + 1] = 0;
+ name[xpos] = key_char;
+ name[xpos + 1] = 0;
- setup.player_name[xpos] = 0;
}
else if (key == KSYM_Return && xpos > 0)
{
}
else if (key == KSYM_Return && xpos > 0)
{
+ strcpy(setup.player_name, name);
+
SaveSetup();
is_active = FALSE;
}
else if (key == KSYM_Escape)
{
SaveSetup();
is_active = FALSE;
}
else if (key == KSYM_Escape)
{
- strcpy(setup.player_name, last_player_name);
+ strcpy(name, last_player_name);
is_active = FALSE;
}
if (is_active)
{
is_active = FALSE;
}
if (is_active)
{
- pos->width = (strlen(setup.player_name) + 1) * font_width;
+ pos->width = (strlen(name) + 1) * font_width;
sx = mSX + ALIGNED_TEXT_XPOS(pos);
sx = mSX + ALIGNED_TEXT_XPOS(pos);
- DrawText(sx, sy, setup.player_name, font_active_nr);
+ DrawText(sx, sy, name, font_active_nr);
DrawText(sx + xpos * font_width, sy, "_", font_active_nr);
}
else
{
SetGameStatus(GAME_MODE_MAIN);
DrawText(sx + xpos * font_width, sy, "_", font_active_nr);
}
else
{
SetGameStatus(GAME_MODE_MAIN);
- pos->width = strlen(setup.player_name) * font_width;
+ pos->width = strlen(name) * font_width;
sx = mSX + ALIGNED_TEXT_XPOS(pos);
sx = mSX + ALIGNED_TEXT_XPOS(pos);
- DrawText(sx, sy, setup.player_name, font_nr);
+ DrawText(sx, sy, name, font_nr);