changed variable handling when typing name in main menu
authorHolger Schemel <info@artsoft.org>
Sun, 18 Oct 2020 12:21:58 +0000 (14:21 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 13 Dec 2020 23:57:57 +0000 (00:57 +0100)
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.

src/screens.c

index 403e4247a0b33e878a9d956b36ad938238dc817f..24d440c7bb71e9c724be6a7282c61d8bb2a9711e 100644 (file)
@@ -3980,6 +3980,7 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button)
 
 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;
@@ -3997,16 +3998,17 @@ static void HandleTypeNameExt(boolean initialize, Key key)
 
   if (initialize)
   {
-    strcpy(last_player_name, setup.player_name);
+    strcpy(name, setup.player_name);
+    strcpy(last_player_name, name);
 
-    xpos = strlen(setup.player_name);
+    xpos = strlen(name);
 
     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;
 
     xpos++;
   }
@@ -4014,37 +4016,39 @@ static void HandleTypeNameExt(boolean initialize, Key key)
   {
     xpos--;
 
-    setup.player_name[xpos] = 0;
+    name[xpos] = 0;
   }
   else if (key == KSYM_Return && xpos > 0)
   {
+    strcpy(setup.player_name, name);
+
     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)
   {
-    pos->width = (strlen(setup.player_name) + 1) * font_width;
+    pos->width = (strlen(name) + 1) * font_width;
     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);
 
-    pos->width = strlen(setup.player_name) * font_width;
+    pos->width = strlen(name) * font_width;
     sx = mSX + ALIGNED_TEXT_XPOS(pos);
 
-    DrawText(sx, sy, setup.player_name, font_nr);
+    DrawText(sx, sy, name, font_nr);
 
     StopTextInput();
   }