moved code to set changed player name to separate function
authorHolger Schemel <info@artsoft.org>
Wed, 21 Oct 2020 00:36:00 +0000 (02:36 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 13 Dec 2020 23:58:00 +0000 (00:58 +0100)
src/screens.c

index 1a906f5a329fcf7b6482533372b47482cf4c7e63..4fd0a412b739d075818aa479029704f098f9d658 100644 (file)
@@ -4079,43 +4079,43 @@ static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
   *xpos = strlen(name);
 }
 
-static void setTypeNameValues(char *name, struct TextPosInfo *pos,
-                             boolean changed)
+static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
 {
-  TreeInfo *node = type_name_node;
-
-  if (!changed)
-    strcpy(name, type_name_last);
-
-  if (strEqual(name, ""))
-    strcpy(name, EMPTY_PLAYER_NAME);
+  // change name of edited user in global list of user names
+  setString(&global.user_names[type_name_nr], name);
 
   if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
   {
-    if (node == NULL)          // should not happen
-      return;
+    TreeInfo *node = type_name_node;
 
-    if (changed)
-      node->color = (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
+    // change name of edited user in local menu tree structure
+    setString(&node->name, name);
+    setString(&node->name_sorting, name);
 
+    node->color = (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
     pos->font = (node->color == FC_RED ? FONT_INPUT_1 : FONT_VALUE_OLD);
   }
+}
+
+static void setTypeNameValues(char *name, struct TextPosInfo *pos,
+                             boolean changed)
+{
+  if (!changed)
+    strcpy(name, type_name_last);
+
+  if (strEqual(name, ""))
+    strcpy(name, EMPTY_PLAYER_NAME);
 
   // if player name not changed, no further action required
   if (strEqual(name, type_name_last))
     return;
 
-  int last_user_nr = user.nr;
+  setTypeNameValues_Name(name, pos);
 
-  // change name of edited user in global list of user names
-  setString(&global.user_names[type_name_nr], name);
+  int last_user_nr = user.nr;
 
   if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
   {
-    // change name of edited user in local menu tree structure
-    setString(&node->name, name);
-    setString(&node->name_sorting, name);
-
     // save setup of currently active user (may differ from edited user)
     SaveSetup();