+
+ *pos = *mci->pos_input;
+
+ if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
+ {
+ TreeInfo *ti = player_name_current;
+ int first_entry = ti->cl_first;
+ int entry_pos = first_entry + ti->cl_cursor;
+ TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
+ int xpos = MENU_SCREEN_START_XPOS;
+ int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
+
+ type_name_node = getTreeInfoFromPos(node_first, entry_pos);
+ type_name_nr = entry_pos;
+
+ strcpy(name, type_name_node->name);
+
+ pos->x = xpos * 32;
+ pos->y = ypos * 32;
+ pos->width = MAX_PLAYER_NAME_LEN * 32;
+ }
+ else
+ {
+ type_name_nr = user.nr;
+
+ strcpy(name, setup.player_name);
+ }
+
+ strcpy(type_name_last, name);
+
+ if (strEqual(name, EMPTY_PLAYER_NAME))
+ strcpy(name, "");
+
+ *xpos = strlen(name);
+}
+
+static void setTypeNameValues_Name(char *name, struct TextPosInfo *pos)
+{
+ // 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)
+ {
+ TreeInfo *node = type_name_node;
+
+ // 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 = FONT_TEXT_1 + node->color;
+ }
+}
+
+static void setTypeNameValues(char *name, struct TextPosInfo *pos,
+ boolean changed)
+{
+ boolean reset_setup = strEqual(name, "");
+ boolean remove_user = strEqual(name, EMPTY_PLAYER_NAME);
+ boolean create_user = strEqual(type_name_last, EMPTY_PLAYER_NAME);
+
+ if (!changed)
+ strcpy(name, type_name_last);
+
+ if (strEqual(name, ""))
+ strcpy(name, EMPTY_PLAYER_NAME);
+
+ setTypeNameValues_Name(name, pos);
+
+ // if player name not changed, no further action required
+ if (strEqual(name, type_name_last))
+ return;
+
+ // redraw player name before (possibly) opening request dialogs
+ drawTypeNameText(name, pos, FALSE);
+
+ int last_user_nr = user.nr;
+
+ if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
+ {
+ // save setup of currently active user (may differ from edited user)
+ SaveSetup();
+
+ // temporarily change active user to edited user
+ user.nr = type_name_nr;
+
+ // load setup of edited user (unless creating user with current setup)
+ if (!create_user ||
+ !Request("Use current setup values for the new player?", REQ_ASK))
+ LoadSetup();
+ }
+
+ char *setup_filename = getSetupFilename();
+ boolean setup_exists = fileExists(setup_filename);
+
+ // change name of edited user in setup structure
+ strcpy(setup.player_name, name);
+
+ // save setup of edited user
+ SaveSetup();
+
+ if (game_status == GAME_MODE_PSEUDO_TYPENAMES || reset_setup)
+ {
+ if (reset_setup)
+ {
+ if (Request("Reset setup values for this player?", REQ_ASK))
+ {
+ // remove setup config file
+ unlink(setup_filename);
+
+ // set player name to default player name
+ LoadSetup();
+
+ // update player name used by name typing functions
+ strcpy(name, setup.player_name);
+
+ setTypeNameValues_Name(name, pos);
+ }
+ }
+ else if (remove_user && type_name_nr != 0)
+ {
+ if (Request("Remove settings and tapes for deleted player?", REQ_ASK))
+ {
+ char *user_dir = getUserGameDataDir();
+ char *user_dir_removed =
+ getStringCat3WithSeparator(user_dir, "REMOVED",
+ getCurrentTimestamp(), ".");
+
+ if (rename(user_dir, user_dir_removed) != 0)
+ Request("Removing settings and tapes failed!", REQ_CONFIRM);
+
+ checked_free(user_dir_removed);
+ }
+ }
+ else if (create_user && type_name_nr != 0 && !setup_exists)
+ {
+ if (Request("Create empty level set for the new player?", REQ_ASK))
+ {
+ char *levelset_subdir = getNewUserLevelSubdir();
+
+ if (CreateUserLevelSet(levelset_subdir, name, name, 100, FALSE))
+ {
+ AddUserLevelSetToLevelInfo(levelset_subdir);
+
+ LevelDirTree *leveldir_current_last = leveldir_current;
+
+ leveldir_current = getTreeInfoFromIdentifier(leveldir_first,
+ levelset_subdir);
+
+ // set level number of newly created level set to default value
+ LoadLevelSetup_SeriesInfo();
+
+ // set newly created level set as current level set for new user
+ SaveLevelSetup_LastSeries();
+ SaveLevelSetup_SeriesInfo();
+
+ leveldir_current = leveldir_current_last;
+ }
+ else
+ {
+ Request("Creating new level set failed!", REQ_CONFIRM);
+ }
+ }
+ }
+
+ // restore currently active user
+ user.nr = last_user_nr;
+
+ // restore setup of currently active user
+ LoadSetup();
+
+ // restore last level set of currently active user
+ LoadLevelSetup_LastSeries();
+ LoadLevelSetup_SeriesInfo();
+ }
+}
+
+static void HandleTypeNameExt(boolean initialize, Key key)
+{
+ static struct TextPosInfo pos_name = { 0 };
+ static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };