X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fscreens.c;h=f859a632d65229720f6706c9d861e432ad02af54;hb=7365879552fa4ca715de55f648c0cc93cb8f1f8c;hp=5bbe467ef211387f4651ea1647b7b05ea69fbd02;hpb=46117e2d3c0ed234252e1e39a62617e6e77c09b5;p=rocksndiamonds.git diff --git a/src/screens.c b/src/screens.c index 5bbe467e..f859a632 100644 --- a/src/screens.c +++ b/src/screens.c @@ -4019,6 +4019,25 @@ 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 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); @@ -4075,7 +4094,7 @@ static void setTypeNameValues(char *name, struct TextPosInfo *pos, if (success) node->color = (strEqual(name, EMPTY_PLAYER_NAME) ? FC_BLUE : FC_RED); - pos->font = FONT_TEXT_1 + node->color; + pos->font = (node->color == FC_RED ? FONT_INPUT_1 : FONT_VALUE_OLD); } if (!success) @@ -4128,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); - 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) @@ -4174,24 +4187,13 @@ static void HandleTypeNameExt(boolean initialize, Key key) 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, pos->font); - StopTextInput(); + + SetGameStatus(game_status_last_screen); } }