static TreeInfo *type_name_node = NULL;
static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 };
+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);
+ int font_nr = (active ? FONT_ACTIVE(pos->font) : pos->font);
+ int font_width = getFontWidth(font_nr);
+
+ DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_nr);
+
+ sprintf(text, "%s%c", name, (active ? '_' : '\0'));
+
+ pos->width = strlen(text) * font_width;
+ sx = mSX + ALIGNED_TEXT_XPOS(pos);
+
+ DrawText(sx, sy, text, font_nr);
+}
+
static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos)
{
struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME);
*xpos = strlen(name);
}
-static void setTypeNameValues(char *name, int *font, boolean success)
+static void setTypeNameValues(char *name, struct TextPosInfo *pos,
+ boolean success)
{
+ TreeInfo *node = type_name_node;
+
if (!success)
strcpy(name, type_name_last);
if (setup.multiple_users)
{
- if (type_name_node == NULL) // should not happen
+ if (node == NULL) // should not happen
return;
if (success)
- {
- type_name_node->color = FC_RED;
-
- if (strEqual(name, EMPTY_PLAYER_NAME))
- type_name_node->color = FC_BLUE;
- }
+ node->color = (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED);
- *font = FONT_TEXT_1 + type_name_node->color;
+ pos->font = (node->color == FC_RED ? FONT_INPUT_1 : FONT_VALUE_OLD);
}
if (!success)
return;
+ if (strEqual(name, type_name_last))
+ return;
+
int last_user_nr = user.nr;
if (setup.multiple_users)
{
- int edit_user_nr = posTreeInfo(type_name_node);
+ int edit_user_nr = posTreeInfo(node);
// change name of edited user in global list of user names
setString(&global.user_names[edit_user_nr], name);
// change name of edited user in local menu tree structure
- setString(&type_name_node->name, name);
- setString(&type_name_node->name_sorting, name);
+ setString(&node->name, name);
+ setString(&node->name_sorting, name);
// save setup of currently active user (may differ from edited user)
SaveSetup();
static struct TextPosInfo pos_name = { 0 };
static char name[MAX_PLAYER_NAME_LEN + 1] = { 0 };
static int xpos = 0;
-
- if (initialize)
- getTypeNameValues(name, &pos_name, &xpos);
-
struct TextPosInfo *pos = &pos_name;
- int sx = mSX + ALIGNED_TEXT_XPOS(pos);
- int sy = mSY + ALIGNED_TEXT_YPOS(pos);
- int font_nr = pos->font;
- int font_active_nr = FONT_ACTIVE(font_nr);
- int font_width = getFontWidth(font_active_nr);
char key_char = getValidConfigValueChar(getCharFromKey(key));
boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0));
boolean is_active = TRUE;
- DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_active_nr);
-
if (initialize)
{
+ getTypeNameValues(name, pos, &xpos);
+
+ int sx = mSX + ALIGNED_TEXT_XPOS(pos);
+ int sy = mSY + ALIGNED_TEXT_YPOS(pos);
+
StartTextInput(sx, sy, pos->width, pos->height);
}
else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN)
}
else if (key == KSYM_Return)
{
- setTypeNameValues(name, &font_nr, TRUE);
+ setTypeNameValues(name, pos, TRUE);
is_active = FALSE;
}
else if (key == KSYM_Escape)
{
- setTypeNameValues(name, &font_nr, FALSE);
+ setTypeNameValues(name, pos, FALSE);
is_active = FALSE;
}
- if (is_active)
- {
- pos->width = (strlen(name) + 1) * font_width;
- sx = mSX + ALIGNED_TEXT_XPOS(pos);
+ drawTypeNameText(name, pos, is_active);
- DrawText(sx, sy, name, font_active_nr);
- DrawText(sx + xpos * font_width, sy, "_", font_active_nr);
- }
- else
+ if (!is_active)
{
- SetGameStatus(game_status_last_screen);
-
- pos->width = strlen(name) * font_width;
- sx = mSX + ALIGNED_TEXT_XPOS(pos);
-
- DrawText(sx, sy, name, font_nr);
-
StopTextInput();
+
+ SetGameStatus(game_status_last_screen);
}
}
{
if (mx >= sx1_edit_name && mx <= sx2_edit_name)
{
- SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
+ SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES);
DrawTypeName();