// other screen text constants
#define STR_CHOOSE_TREE_EDIT "Edit"
+#define MENU_CHOOSE_TREE_FONT(x) (FONT_TEXT_1 + (x))
// for input setup functions
#define SETUPINPUT_SCREEN_POS_START 0
static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
static int type_name_nr = 0;
+static int getPlayerNameColor(char *name)
+{
+ return (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
+}
+
static void drawTypeNameText(char *name, struct TextPosInfo *pos,
boolean active)
{
char text[MAX_PLAYER_NAME_LEN + 2] = { 0 };
- int sx = mSX + ALIGNED_TEXT_XPOS(pos);
- int sy = mSY + ALIGNED_TEXT_YPOS(pos);
+ boolean multiple_users = (game_status == GAME_MODE_PSEUDO_TYPENAMES);
+ int sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
+ int sy = (multiple_users ? amSY + pos->y : mSY + ALIGNED_TEXT_YPOS(pos));
int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
int font_width = getFontWidth(font_nr);
sprintf(text, "%s%c", name, (active ? '_' : '\0'));
pos->width = strlen(text) * font_width;
- sx = mSX + ALIGNED_TEXT_XPOS(pos);
+ sx = (multiple_users ? amSX + pos->x : mSX + ALIGNED_TEXT_XPOS(pos));
DrawText(sx, sy, text, font_nr);
}
*pos = *mci->pos_input;
- if (setup.multiple_users)
+ if (game_status == GAME_MODE_PSEUDO_TYPENAMES)
{
TreeInfo *ti = player_name_current;
int first_entry = ti->cl_first;
TreeInfo *node_first = getTreeInfoFirstGroupEntry(ti);
int xpos = MENU_SCREEN_START_XPOS;
int ypos = MENU_SCREEN_START_YPOS + ti->cl_cursor;
- int font_width = getFontWidth(pos->font);
type_name_node = getTreeInfoFromPos(node_first, entry_pos);
type_name_nr = entry_pos;
strcpy(name, type_name_node->name);
- pos->x = xpos * font_width;
- pos->y = ypos * font_width;
- pos->width = MAX_PLAYER_NAME_LEN * font_width;
+ pos->x = xpos * 32;
+ pos->y = ypos * 32;
+ pos->width = MAX_PLAYER_NAME_LEN * 32;
}
else
{
*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 = getPlayerNameColor(name);
+ pos->font = MENU_CHOOSE_TREE_FONT(node->color);
+ }
+}
+
static void setTypeNameValues(char *name, struct TextPosInfo *pos,
boolean changed)
{
- TreeInfo *node = type_name_node;
+ 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);
- if (setup.multiple_users)
- {
- if (node == NULL) // should not happen
- return;
-
- if (changed)
- node->color = (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
-
- pos->font = (node->color == FC_RED ? FONT_INPUT_1 : FONT_VALUE_OLD);
- }
+ setTypeNameValues_Name(name, pos);
// if player name not changed, no further action required
if (strEqual(name, type_name_last))
return;
- int last_user_nr = user.nr;
+ // redraw player name before (possibly) opening request dialogs
+ drawTypeNameText(name, pos, FALSE);
- // 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 (setup.multiple_users)
+ 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();
// temporarily change active user to edited user
user.nr = type_name_nr;
- // load setup of edited user
- LoadSetup();
+ // 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 (setup.multiple_users)
+ 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();
}
}
int num_entries = numTreeInfoInGroup(ti);
boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
- int text_width = max_text_size * getFontWidth(FONT_TEXT_1);
+ int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
+ int text_width = max_text_size * getFontWidth(font_nr);
int button_width = SC_MENUBUTTON_XSIZE;
int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
int num_entries = numTreeInfoInGroup(ti);
int num_page_entries = MIN(num_entries, NUM_MENU_ENTRIES_ON_SCREEN);
- int font_height = getFontHeight(FONT_TEXT_1);
+ int font_nr = MENU_CHOOSE_TREE_FONT(FC_RED);
+ int font_height = getFontHeight(font_nr);
int text_height = font_height * num_page_entries;
int page_height = font_height * NUM_MENU_ENTRIES_ON_SCREEN;
int align = menu.list_setup[SETUP_MODE_CHOOSE_OTHER].valign;
boolean scrollbar_needed = (num_entries > NUM_MENU_ENTRIES_ON_SCREEN);
int scrollbar_xpos = SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset;
int screen_width = (scrollbar_needed ? scrollbar_xpos : SXSIZE);
- int font_nr = FONT_TEXT_1;
- int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
int i;
char *title_string = NULL;
int yoffset_sets = MENU_TITLE1_YPOS;
{
TreeInfo *node, *node_first;
int entry_pos = first_entry + i;
+
+ node_first = getTreeInfoFirstGroupEntry(ti);
+ node = getTreeInfoFromPos(node_first, entry_pos);
+
+ int font_nr = MENU_CHOOSE_TREE_FONT(node->color);
+ int font_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset;
int xpos = MENU_SCREEN_START_XPOS;
int ypos = MENU_SCREEN_START_YPOS + i;
int startx = amSX + xpos * 32;
int max_buffer_len = max_text_size / getFontWidth(font_nr);
char buffer[max_buffer_len + 1];
- node_first = getTreeInfoFirstGroupEntry(ti);
- node = getTreeInfoFromPos(node_first, entry_pos);
-
strncpy(buffer, node->name, max_buffer_len);
buffer[max_buffer_len] = '\0';
- DrawText(startx, starty, buffer, font_nr + node->color);
+ DrawText(startx, starty, buffer, font_nr);
if (node->parent_link)
initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU);
for (i = 0; i < MAX_PLAYER_NAMES; i++)
{
- boolean team_mode = (!network.enabled && setup.team_mode);
- int tree_type = (team_mode ? TREE_TYPE_PLAYER_TEAM : TREE_TYPE_PLAYER_NAME);
- TreeInfo *ti = newTreeInfo_setDefaults(tree_type);
+ TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_PLAYER_NAME);
char identifier[32], name[MAX_PLAYER_NAME_LEN + 1];
int value = i;
ti->node_top = &player_name;
ti->sort_priority = 10000 + value;
- ti->color = FC_RED;
-
- if (strEqual(global.user_names[i], EMPTY_PLAYER_NAME))
- ti->color = FC_BLUE;
+ ti->color = getPlayerNameColor(global.user_names[i]);
snprintf(identifier, sizeof(identifier), "%d", value);
snprintf(name, sizeof(name), "%s", global.user_names[i]);