X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fscreens.c;h=f9815ee33678683db95065ffcd5aeae30be29df8;hb=44da8ca05994d2dcbaea2ad2e1d945bfa0005575;hp=6aa7f3fa97be4bb102330d94206c6e33e7b9bbd1;hpb=36c5a2903c6e5da5bfa88f707d3cf639b9d2ee7c;p=rocksndiamonds.git diff --git a/src/screens.c b/src/screens.c index 6aa7f3fa..f9815ee3 100644 --- a/src/screens.c +++ b/src/screens.c @@ -123,6 +123,9 @@ #define STR_SETUP_CHOOSE_GRID_XSIZE_1 "Horiz. Buttons" #define STR_SETUP_CHOOSE_GRID_YSIZE_1 "Vert. Buttons" +// other screen text constants +#define STR_CHOOSE_TREE_EDIT "Edit" + // for input setup functions #define SETUPINPUT_SCREEN_POS_START 0 #define SETUPINPUT_SCREEN_POS_EMPTY1 3 @@ -138,6 +141,7 @@ #define MENU_SCREEN_START_XPOS 1 #define MENU_SCREEN_START_YPOS 2 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3) +#define MENU_SCREEN_TEXT2_XPOS (SCR_FIELDX - 2) #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1) #define MENU_TITLE1_YPOS 8 #define MENU_TITLE2_YPOS 46 @@ -1430,6 +1434,40 @@ static void drawChooseTreeCursor(int ypos, boolean active) drawCursorExt(0, ypos, active, -1); } +static int getChooseTreeEditFont(boolean active) +{ + return (active ? FONT_MENU_2_ACTIVE : FONT_MENU_2); +} + +static int getChooseTreeEditXPos(int pos) +{ + boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped; + int xoffset = (has_scrollbar ? -1 : 0); + int xpos = MENU_SCREEN_TEXT2_XPOS + xoffset; + int sx = amSX + xpos * TILEX; + int font_nr = getChooseTreeEditFont(FALSE); + int width = getTextWidth(STR_CHOOSE_TREE_EDIT, font_nr); + + return (pos == POS_RIGHT ? sx + width - 1 : sx); +} + +static int getChooseTreeEditYPos(int ypos_raw) +{ + int ypos = MENU_SCREEN_START_YPOS + ypos_raw; + int sy = amSY + ypos * TILEY; + + return sy; +} + +static void drawChooseTreeEdit(int ypos_raw, boolean active) +{ + int sx = getChooseTreeEditXPos(POS_LEFT); + int sy = getChooseTreeEditYPos(ypos_raw); + int font_nr = getChooseTreeEditFont(active); + + DrawText(sx, sy, STR_CHOOSE_TREE_EDIT, font_nr); +} + static void DrawHeadline(void) { DrawTextSCentered(MENU_TITLE1_YPOS, FONT_TITLE_1, main_text_title_1); @@ -2085,7 +2123,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) } else { - if (0 && setup.multiple_users) // (not used yet) + if (setup.multiple_users) { CloseDoor(DOOR_CLOSE_2); @@ -3981,13 +4019,32 @@ 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); *pos = *mci->pos_input; - if (0 && setup.multiple_users) // (not used yet) + if (setup.multiple_users) { TreeInfo *ti = player_name_current; int first_entry = ti->cl_first; @@ -3995,13 +4052,15 @@ static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos) 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); strcpy(name, type_name_node->name); - pos->x = xpos * 32; - pos->y = ypos * 32; + pos->x = xpos * font_width; + pos->y = ypos * font_width; + pos->width = MAX_PLAYER_NAME_LEN * font_width; } else { @@ -4016,45 +4075,44 @@ 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) { - if (!success) + TreeInfo *node = type_name_node; + + if (!changed) strcpy(name, type_name_last); if (strEqual(name, "")) strcpy(name, EMPTY_PLAYER_NAME); - if (0 && setup.multiple_users) // (not used yet) + 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; - } + if (changed) + 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) + // if player name not changed, no further action required + if (strEqual(name, type_name_last)) return; int last_user_nr = user.nr; - if (0 && setup.multiple_users) // (not used yet) + 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(); @@ -4072,7 +4130,7 @@ static void setTypeNameValues(char *name, int *font, boolean success) // save setup of edited user SaveSetup(); - if (0 && setup.multiple_users) // (not used yet) + if (setup.multiple_users) { // restore currently active user user.nr = last_user_nr; @@ -4087,24 +4145,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) @@ -4122,35 +4174,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(); } } @@ -4309,6 +4353,9 @@ static void drawChooseTreeList(int first_entry, int num_page_entries, initCursor(i, IMG_MENU_BUTTON_ENTER_MENU); else initCursor(i, IMG_MENU_BUTTON); + + if (game_status == GAME_MODE_NAMES) + drawChooseTreeEdit(i, FALSE); } redraw_mask |= REDRAW_FIELD; @@ -4356,6 +4403,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, boolean has_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->mapped; int mx_scrollbar = screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x; int mx_right_border = (has_scrollbar ? mx_scrollbar : SX + SXSIZE); + int sx1_edit_name = getChooseTreeEditXPos(POS_LEFT); + int sx2_edit_name = getChooseTreeEditXPos(POS_RIGHT); int x = 0; int y = ti->cl_cursor; int step = (button == 1 ? 1 : button == 2 ? 5 : 10); @@ -4457,6 +4506,9 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, { x = (mx - amSX) / 32; y = (my - amSY) / 32 - MENU_SCREEN_START_YPOS; + + if (game_status == GAME_MODE_NAMES) + drawChooseTreeEdit(ti->cl_cursor, FALSE); } else if (dx || dy) // keyboard or scrollbar/scrollbutton input { @@ -4555,6 +4607,12 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, { if (button) { + if (game_status == GAME_MODE_NAMES) + { + if (mx >= sx1_edit_name && mx <= sx2_edit_name) + drawChooseTreeEdit(y, TRUE); + } + if (y != ti->cl_cursor) { PlaySound(SND_MENU_ITEM_ACTIVATING); @@ -4674,6 +4732,39 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, HandleMainMenu_SelectLevel(0, 0, new_level_nr); } + else if (game_status == GAME_MODE_NAMES) + { + if (mx >= sx1_edit_name && mx <= sx2_edit_name) + { + SetGameStatus(GAME_MODE_PSEUDO_TYPENAMES); + + DrawTypeName(); + + return; + } + + // change active user to selected user + user.nr = entry_pos; + + // save number of new active user + SaveUserSetup(); + + // load setup of new active user + LoadSetup(); + + // load last level set of new active user + LoadLevelSetup_LastSeries(); + LoadLevelSetup_SeriesInfo(); + + TapeErase(); + + ToggleFullscreenIfNeeded(); + ChangeWindowScalingIfNeeded(); + + ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_GRAPHICS); + ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_SOUNDS); + ChangeCurrentArtworkIfNeeded(ARTWORK_TYPE_MUSIC); + } SetGameStatus(GAME_MODE_MAIN);