X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fscreens.c;h=3638840e82b711166e725178f9d8be2fa8e02a48;hb=dfe5aa4b462c9507926f1c7a1b8c30911bfacef1;hp=3b9504bc0d23682859a96ededc5c76c6c9205e2a;hpb=2a0aa9698a999f688e326d74810f3a365e64ee8f;p=rocksndiamonds.git diff --git a/src/screens.c b/src/screens.c index 3b9504bc..3638840e 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1745,7 +1745,7 @@ static void gotoTopLevelDir(void) if (leveldir_current->node_parent->node_group->cl_first == -1) { int num_leveldirs = numTreeInfoInGroup(leveldir_current); - int leveldir_pos = posTreeInfo(leveldir_current); + int leveldir_pos = getPosFromTreeInfo(leveldir_current); int num_page_entries = MIN(num_leveldirs, NUM_MENU_ENTRIES_ON_SCREEN); int cl_first, cl_cursor; @@ -4018,6 +4018,26 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button) static TreeInfo *type_name_node = NULL; static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 }; +static int type_name_nr = 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) { @@ -4036,6 +4056,7 @@ static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos) 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); @@ -4045,6 +4066,8 @@ static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos) } else { + type_name_nr = user.nr; + strcpy(name, setup.player_name); } @@ -4056,11 +4079,12 @@ static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos) *xpos = strlen(name); } -static void setTypeNameValues(char *name, int *font, boolean success) +static void setTypeNameValues(char *name, struct TextPosInfo *pos, + boolean changed) { TreeInfo *node = type_name_node; - if (!success) + if (!changed) strcpy(name, type_name_last); if (strEqual(name, "")) @@ -4071,32 +4095,23 @@ static void setTypeNameValues(char *name, int *font, boolean success) if (node == NULL) // should not happen return; - if (success) - { - node->color = FC_RED; - - if (strEqual(name, EMPTY_PLAYER_NAME)) - node->color = FC_BLUE; - } + if (changed) + node->color = (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED); - *font = FONT_TEXT_1 + node->color; + pos->font = (node->color == FC_RED ? FONT_INPUT_1 : FONT_VALUE_OLD); } - if (!success) - return; - + // if player name not changed, no further action required if (strEqual(name, type_name_last)) return; int last_user_nr = user.nr; + // change name of edited user in global list of user names + setString(&global.user_names[type_name_nr], name); + if (setup.multiple_users) { - 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(&node->name, name); setString(&node->name_sorting, name); @@ -4105,7 +4120,7 @@ static void setTypeNameValues(char *name, int *font, boolean success) SaveSetup(); // temporarily change active user to edited user - user.nr = edit_user_nr; + user.nr = type_name_nr; // load setup of edited user LoadSetup(); @@ -4132,24 +4147,18 @@ static void HandleTypeNameExt(boolean initialize, Key key) 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); + boolean active = TRUE; 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) @@ -4167,35 +4176,27 @@ static void HandleTypeNameExt(boolean initialize, Key key) } else if (key == KSYM_Return) { - setTypeNameValues(name, &font_nr, TRUE); + setTypeNameValues(name, pos, TRUE); - is_active = FALSE; + active = FALSE; } else if (key == KSYM_Escape) { - setTypeNameValues(name, &font_nr, FALSE); + setTypeNameValues(name, pos, FALSE); - is_active = FALSE; + active = FALSE; } - if (is_active) - { - pos->width = (strlen(name) + 1) * font_width; - sx = mSX + ALIGNED_TEXT_XPOS(pos); + drawTypeNameText(name, pos, active); - DrawText(sx, sy, name, font_active_nr); - DrawText(sx + xpos * font_width, sy, "_", font_active_nr); - } - else + if (!active) { - SetGameStatus(game_status_last_screen); - - pos->width = strlen(name) * font_width; - sx = mSX + ALIGNED_TEXT_XPOS(pos); + StopTextInput(); - DrawText(sx, sy, name, font_nr); + SetGameStatus(game_status_last_screen); - StopTextInput(); + if (game_status == GAME_MODE_MAIN) + InitializeMainControls(); } } @@ -4416,7 +4417,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, if (button == MB_MENU_INITIALIZE) { int num_entries = numTreeInfoInGroup(ti); - int entry_pos = posTreeInfo(ti); + int entry_pos = getPosFromTreeInfo(ti); align_xoffset = getAlignXOffsetFromTreeInfo(ti); align_yoffset = getAlignYOffsetFromTreeInfo(ti);