X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fscreens.c;h=eba14f7ad58b447a601b9c97db3728c3f73a31ad;hp=16a3fc1b77b8e2e57758487aa5bd2258935eaba5;hb=522a0df5c166bfcb34156f044cdcc9d194ed56e9;hpb=02a095de0eb40735cb15b3f043c1639dbd883ce1 diff --git a/src/screens.c b/src/screens.c index 16a3fc1b..eba14f7a 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 @@ -248,6 +252,7 @@ static void execSetupTouch(void); static void execSetupArtwork(void); static void HandleChooseTree(int, int, int, int, int, TreeInfo **); +static void DrawChoosePlayerName(void); static void DrawChooseLevelSet(void); static void DrawChooseLevelNr(void); static void DrawInfoScreen(void); @@ -327,6 +332,9 @@ static TreeInfo *transparency_current = NULL; static TreeInfo *grid_sizes[2][2] = { { NULL, NULL }, { NULL, NULL } }; static TreeInfo *grid_size_current[2][2] = { { NULL, NULL }, { NULL, NULL } }; +static TreeInfo *player_name = NULL; +static TreeInfo *player_name_current = NULL; + static TreeInfo *level_number = NULL; static TreeInfo *level_number_current = NULL; @@ -541,7 +549,9 @@ static int align_yoffset = 0; #define DRAW_MODE(s) ((s) >= GAME_MODE_MAIN && \ (s) <= GAME_MODE_SETUP ? (s) : \ (s) == GAME_MODE_PSEUDO_TYPENAME ? \ - GAME_MODE_MAIN : GAME_MODE_DEFAULT) + GAME_MODE_MAIN : \ + (s) == GAME_MODE_PSEUDO_TYPENAMES ? \ + GAME_MODE_NAMES : GAME_MODE_DEFAULT) // (there are no draw offset definitions needed for INFO_MODE_TITLE) #define DRAW_MODE_INFO(i) ((i) >= INFO_MODE_TITLE && \ @@ -1424,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); @@ -2079,9 +2123,20 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) } else { - SetGameStatus(GAME_MODE_PSEUDO_TYPENAME); + if (setup.multiple_users) + { + CloseDoor(DOOR_CLOSE_2); + + SetGameStatus(GAME_MODE_NAMES); - DrawTypeName(); + DrawChoosePlayerName(); + } + else + { + SetGameStatus(GAME_MODE_PSEUDO_TYPENAME); + + DrawTypeName(); + } } } else if (pos == MAIN_CONTROL_LEVELS) @@ -3961,14 +4016,124 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button) // type name functions // ============================================================================ -static void HandleTypeNameExt(boolean initialize, Key key) +static TreeInfo *type_name_node = NULL; +static char type_name_last[MAX_PLAYER_NAME_LEN + 1] = { 0 }; + +static void getTypeNameValues(char *name, struct TextPosInfo *pos, int *xpos) { - static char last_player_name[MAX_PLAYER_NAME_LEN + 1]; struct MainControlInfo *mci = getMainControlInfo(MAIN_CONTROL_NAME); - struct TextPosInfo *pos = mci->pos_input; - int startx = mSX + ALIGNED_TEXT_XPOS(pos); - int starty = mSY + ALIGNED_TEXT_YPOS(pos); + + *pos = *mci->pos_input; + + if (setup.multiple_users) + { + TreeInfo *ti = player_name_current; + int first_entry = ti->cl_first; + int entry_pos = first_entry + ti->cl_cursor; + 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 * font_width; + pos->y = ypos * font_width; + pos->width = MAX_PLAYER_NAME_LEN * font_width; + } + else + { + strcpy(name, setup.player_name); + } + + strcpy(type_name_last, name); + + if (strEqual(name, EMPTY_PLAYER_NAME)) + strcpy(name, ""); + + *xpos = strlen(name); +} + +static void setTypeNameValues(char *name, int *font, boolean success) +{ + if (!success) + strcpy(name, type_name_last); + + if (strEqual(name, "")) + strcpy(name, EMPTY_PLAYER_NAME); + + if (setup.multiple_users) + { + if (type_name_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; + } + + *font = FONT_TEXT_1 + type_name_node->color; + } + + if (!success) + return; + + int last_user_nr = user.nr; + + if (setup.multiple_users) + { + int edit_user_nr = posTreeInfo(type_name_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); + + // save setup of currently active user (may differ from edited user) + SaveSetup(); + + // temporarily change active user to edited user + user.nr = edit_user_nr; + + // load setup of edited user + LoadSetup(); + } + + // change name of edited user in setup structure + strcpy(setup.player_name, name); + + // save setup of edited user + SaveSetup(); + + if (setup.multiple_users) + { + // restore currently active user + user.nr = last_user_nr; + + // restore setup of currently active user + LoadSetup(); + } +} + +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); @@ -3976,20 +4141,16 @@ static void HandleTypeNameExt(boolean initialize, Key key) boolean is_valid_key_char = (key_char != 0 && (key_char != ' ' || xpos > 0)); boolean is_active = TRUE; - DrawBackgroundForFont(startx,starty, pos->width, pos->height, font_active_nr); + DrawBackgroundForFont(sx, sy, pos->width, pos->height, font_active_nr); if (initialize) { - strcpy(last_player_name, setup.player_name); - - xpos = strlen(setup.player_name); - - StartTextInput(startx, starty, pos->width, pos->height); + StartTextInput(sx, sy, pos->width, pos->height); } else if (is_valid_key_char && xpos < MAX_PLAYER_NAME_LEN) { - setup.player_name[xpos] = key_char; - setup.player_name[xpos + 1] = 0; + name[xpos] = key_char; + name[xpos + 1] = 0; xpos++; } @@ -3997,39 +4158,37 @@ static void HandleTypeNameExt(boolean initialize, Key key) { xpos--; - setup.player_name[xpos] = 0; + name[xpos] = 0; } - else if (key == KSYM_Return && xpos > 0) + else if (key == KSYM_Return) { - SaveSetup(); + setTypeNameValues(name, &font_nr, TRUE); is_active = FALSE; - - SetGameStatus(GAME_MODE_MAIN); } else if (key == KSYM_Escape) { - strcpy(setup.player_name, last_player_name); + setTypeNameValues(name, &font_nr, FALSE); is_active = FALSE; - - SetGameStatus(GAME_MODE_MAIN); } if (is_active) { - pos->width = (strlen(setup.player_name) + 1) * font_width; - startx = mSX + ALIGNED_TEXT_XPOS(pos); + pos->width = (strlen(name) + 1) * font_width; + sx = mSX + ALIGNED_TEXT_XPOS(pos); - DrawText(startx, starty, setup.player_name, font_active_nr); - DrawText(startx + xpos * font_width, starty, "_", font_active_nr); + DrawText(sx, sy, name, font_active_nr); + DrawText(sx + xpos * font_width, sy, "_", font_active_nr); } else { - pos->width = strlen(setup.player_name) * font_width; - startx = mSX + ALIGNED_TEXT_XPOS(pos); + SetGameStatus(game_status_last_screen); - DrawText(startx, starty, setup.player_name, font_nr); + pos->width = strlen(name) * font_width; + sx = mSX + ALIGNED_TEXT_XPOS(pos); + + DrawText(sx, sy, name, font_nr); StopTextInput(); } @@ -4121,7 +4280,9 @@ static void DrawChooseTree(TreeInfo **ti_ptr) // needed if different viewport properties defined for choosing level (set) ChangeViewportPropertiesIfNeeded(); - if (game_status == GAME_MODE_LEVELNR) + if (game_status == GAME_MODE_NAMES) + SetMainBackgroundImage(IMG_BACKGROUND_NAMES); + else if (game_status == GAME_MODE_LEVELNR) SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR); else if (game_status == GAME_MODE_LEVELS) SetMainBackgroundImage(IMG_BACKGROUND_LEVELS); @@ -4130,8 +4291,8 @@ static void DrawChooseTree(TreeInfo **ti_ptr) OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW); - HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr); MapScreenTreeGadgets(*ti_ptr); + HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr); DrawMaskedBorder(fade_mask); @@ -4188,6 +4349,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; @@ -4235,6 +4399,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); @@ -4336,6 +4502,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 { @@ -4434,6 +4603,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); @@ -4553,6 +4728,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_TYPENAME); + + 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); @@ -4563,6 +4771,65 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, } } +void DrawChoosePlayerName(void) +{ + int i; + + FadeMenuSoundsAndMusic(); + + if (player_name != NULL) + { + freeTreeInfo(player_name); + + player_name = NULL; + } + + 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); + 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; + + snprintf(identifier, sizeof(identifier), "%d", value); + snprintf(name, sizeof(name), "%s", global.user_names[i]); + + setString(&ti->identifier, identifier); + setString(&ti->name, name); + setString(&ti->name_sorting, name); + + pushTreeInfo(&player_name, ti); + } + + // sort player entries by player number + sortTreeInfo(&player_name); + + // set current player entry to selected player entry + player_name_current = + getTreeInfoFromIdentifier(player_name, i_to_a(user.nr)); + + // if that fails, set current player name to first available name + if (player_name_current == NULL) + player_name_current = player_name; + + DrawChooseTree(&player_name_current); + + PlayMenuSoundsAndMusic(); +} + +void HandleChoosePlayerName(int mx, int my, int dx, int dy, int button) +{ + HandleChooseTree(mx, my, dx, dy, button, &player_name_current); +} + void DrawChooseLevelSet(void) { FadeMenuSoundsAndMusic(); @@ -6307,6 +6574,7 @@ static struct TokenInfo setup_info_game[] = { TYPE_PLAYER, &setup.network_player_nr,"Preferred Network Player:" }, { TYPE_TEXT_INPUT, execGadgetNetworkServer, "Network Server Hostname:" }, { TYPE_STRING, &network_server_text, "" }, + { TYPE_SWITCH, &setup.multiple_users, "Multiple Users/Teams:" }, { TYPE_YES_NO, &setup.input_on_focus, "Only Move Focussed Player:" }, { TYPE_SWITCH, &setup.time_limit, "Time Limit:" }, { TYPE_SWITCH, &setup.handicap, "Handicap:" }, @@ -9071,7 +9339,9 @@ static void HandleScreenGadgets(struct GadgetInfo *gi) break; case SCREEN_CTRL_ID_SCROLL_UP: - if (game_status == GAME_MODE_LEVELS) + if (game_status == GAME_MODE_NAMES) + HandleChoosePlayerName(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK); + else if (game_status == GAME_MODE_LEVELS) HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK); else if (game_status == GAME_MODE_LEVELNR) HandleChooseLevelNr(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK); @@ -9082,7 +9352,9 @@ static void HandleScreenGadgets(struct GadgetInfo *gi) break; case SCREEN_CTRL_ID_SCROLL_DOWN: - if (game_status == GAME_MODE_LEVELS) + if (game_status == GAME_MODE_NAMES) + HandleChoosePlayerName(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK); + else if (game_status == GAME_MODE_LEVELS) HandleChooseLevelSet(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK); else if (game_status == GAME_MODE_LEVELNR) HandleChooseLevelNr(0,0, 0, +1 * SCROLL_LINE, MB_MENU_MARK); @@ -9093,7 +9365,9 @@ static void HandleScreenGadgets(struct GadgetInfo *gi) break; case SCREEN_CTRL_ID_SCROLL_VERTICAL: - if (game_status == GAME_MODE_LEVELS) + if (game_status == GAME_MODE_NAMES) + HandleChoosePlayerName(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE); + else if (game_status == GAME_MODE_LEVELS) HandleChooseLevelSet(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE); else if (game_status == GAME_MODE_LEVELNR) HandleChooseLevelNr(0,0,999,gi->event.item_position,MB_MENU_INITIALIZE);