From: Holger Schemel Date: Wed, 13 Jun 2018 22:57:40 +0000 (+0200) Subject: added (optional) main menu buttons to insert or play solution tape X-Git-Tag: 4.1.1.0~127 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=bd9eb07192105e183db44f03d675332ffb2b767a added (optional) main menu buttons to insert or play solution tape There is a difference to the already existing tape buttons to insert or play a solution tape in that the main menu buttons are only drawn if the current level really has a solution tape, while the tape buttons are always drawn, regardless if the level has a solution tape or not. --- diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 785b2e2a..20bb6830 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -6088,6 +6088,11 @@ struct ConfigInfo image_config[] = { "menu.button_level_number", UNDEFINED_FILENAME }, { "menu.button_level_number.active", UNDEFINED_FILENAME }, + { "menu.button_insert_solution", UNDEFINED_FILENAME }, + { "menu.button_insert_solution.active", UNDEFINED_FILENAME }, + { "menu.button_play_solution", UNDEFINED_FILENAME }, + { "menu.button_play_solution.active", UNDEFINED_FILENAME }, + { "menu.scrollbar", "RocksDC.png" }, { "menu.scrollbar.xpos", "8" }, { "menu.scrollbar.ypos", "10" }, @@ -7908,6 +7913,11 @@ struct ConfigInfo image_config[] = { "main.button.next_level.x", "448" }, { "main.button.next_level.y", "96" }, + { "main.button.insert_solution.x", "-1" }, + { "main.button.insert_solution.y", "-1" }, + { "main.button.play_solution.x", "-1" }, + { "main.button.play_solution.y", "-1" }, + { "main.text.name.x", "-1" }, { "main.text.name.y", "-1" }, { "main.text.name.width", "-1" }, diff --git a/src/main.h b/src/main.h index 6e4c5060..b71bb3ce 100644 --- a/src/main.h +++ b/src/main.h @@ -2642,6 +2642,9 @@ struct MenuMainButtonInfo struct MenuPosInfo first_level; struct MenuPosInfo last_level; struct MenuPosInfo level_number; + + struct MenuPosInfo insert_solution; + struct MenuPosInfo play_solution; }; struct MenuMainTextInfo diff --git a/src/screens.c b/src/screens.c index 067f630a..200f725c 100644 --- a/src/screens.c +++ b/src/screens.c @@ -172,18 +172,21 @@ #define SCREEN_CTRL_ID_NEXT_LEVEL 1 #define SCREEN_CTRL_ID_PREV_PLAYER 2 #define SCREEN_CTRL_ID_NEXT_PLAYER 3 -#define SCREEN_CTRL_ID_SCROLL_UP 4 -#define SCREEN_CTRL_ID_SCROLL_DOWN 5 -#define SCREEN_CTRL_ID_SCROLL_VERTICAL 6 +#define SCREEN_CTRL_ID_INSERT_SOLUTION 4 +#define SCREEN_CTRL_ID_PLAY_SOLUTION 5 +#define SCREEN_CTRL_ID_SCROLL_UP 6 +#define SCREEN_CTRL_ID_SCROLL_DOWN 7 +#define SCREEN_CTRL_ID_SCROLL_VERTICAL 8 -#define NUM_SCREEN_GADGETS 7 +#define NUM_SCREEN_GADGETS 9 -#define NUM_SCREEN_MENUBUTTONS 4 +#define NUM_SCREEN_MENUBUTTONS 6 #define NUM_SCREEN_SCROLLBUTTONS 2 #define NUM_SCREEN_SCROLLBARS 1 #define SCREEN_MASK_MAIN (1 << 0) -#define SCREEN_MASK_INPUT (1 << 1) +#define SCREEN_MASK_MAIN_HAS_SOLUTION (1 << 1) +#define SCREEN_MASK_INPUT (1 << 2) /* graphic position and size values for buttons and scrollbars */ #define SC_MENUBUTTON_XSIZE TILEX @@ -246,6 +249,8 @@ static void MapScreenMenuGadgets(int); static void MapScreenGadgets(int); static void MapScreenTreeGadgets(TreeInfo *); +static void UpdateScreenMenuGadgets(int, boolean); + static struct GadgetInfo *screen_gadget[NUM_SCREEN_GADGETS]; static int info_mode = INFO_MODE_MAIN; @@ -1658,6 +1663,7 @@ void DrawMainMenu() /* map gadgets for main menu screen */ MapTapeButtons(); MapScreenMenuGadgets(SCREEN_MASK_MAIN); + UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape()); /* copy actual game door content to door double buffer for OpenDoor() */ BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0); @@ -1929,6 +1935,8 @@ void HandleMainMenu_SelectLevel(int step, int direction, int selected_level_nr) SaveLevelSetup_SeriesInfo(); + UpdateScreenMenuGadgets(SCREEN_MASK_MAIN_HAS_SOLUTION, hasSolutionTape()); + /* needed because DrawPreviewLevelInitial() takes some time */ BackToFront(); /* SyncDisplay(); */ @@ -7914,6 +7922,16 @@ static void getScreenMenuButtonPos(int *x, int *y, int gadget_id) *y = mSY + TILEY * MENU_SCREEN_START_YPOS; break; + case SCREEN_CTRL_ID_INSERT_SOLUTION: + *x = mSX + GDI_ACTIVE_POS(menu.main.button.insert_solution.x); + *y = mSY + GDI_ACTIVE_POS(menu.main.button.insert_solution.y); + break; + + case SCREEN_CTRL_ID_PLAY_SOLUTION: + *x = mSX + GDI_ACTIVE_POS(menu.main.button.play_solution.x); + *y = mSY + GDI_ACTIVE_POS(menu.main.button.play_solution.y); + break; + default: Error(ERR_EXIT, "unknown gadget ID %d", gadget_id); } @@ -7956,6 +7974,20 @@ static struct SCREEN_MASK_INPUT, "next player" }, + { + IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE, + getScreenMenuButtonPos, + SCREEN_CTRL_ID_INSERT_SOLUTION, + SCREEN_MASK_MAIN_HAS_SOLUTION, + "insert solution tape" + }, + { + IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE, + getScreenMenuButtonPos, + SCREEN_CTRL_ID_PLAY_SOLUTION, + SCREEN_MASK_MAIN_HAS_SOLUTION, + "play solution tape" + }, }; static struct @@ -8014,12 +8046,23 @@ static void CreateScreenMenubuttons() int gd_x1, gd_x2, gd_y1, gd_y2; int id = menubutton_info[i].gadget_id; - event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED; + if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION) + event_mask = GD_EVENT_RELEASED; + else + event_mask = GD_EVENT_PRESSED | GD_EVENT_REPEATED; menubutton_info[i].get_gadget_position(&x, &y, id); - width = SC_MENUBUTTON_XSIZE; - height = SC_MENUBUTTON_YSIZE; + if (menubutton_info[i].screen_mask == SCREEN_MASK_MAIN_HAS_SOLUTION) + { + width = graphic_info[menubutton_info[i].gfx_pressed].width; + height = graphic_info[menubutton_info[i].gfx_pressed].height; + } + else + { + width = SC_MENUBUTTON_XSIZE; + height = SC_MENUBUTTON_YSIZE; + } gfx_unpressed = menubutton_info[i].gfx_unpressed; gfx_pressed = menubutton_info[i].gfx_pressed; @@ -8228,6 +8271,33 @@ void MapScreenMenuGadgets(int screen_mask) MapGadget(screen_gadget[menubutton_info[i].gadget_id]); } +void UnmapScreenMenuGadgets(int screen_mask) +{ + int i; + + for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++) + { + if (screen_mask & menubutton_info[i].screen_mask) + { + UnmapGadget(screen_gadget[menubutton_info[i].gadget_id]); + + if (screen_mask & SCREEN_MASK_MAIN_HAS_SOLUTION) + DrawBackground(screen_gadget[menubutton_info[i].gadget_id]->x, + screen_gadget[menubutton_info[i].gadget_id]->y, + screen_gadget[menubutton_info[i].gadget_id]->width, + screen_gadget[menubutton_info[i].gadget_id]->height); + } + } +} + +void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets) +{ + if (map_gadgets) + MapScreenMenuGadgets(screen_mask); + else + UnmapScreenMenuGadgets(screen_mask); +} + void MapScreenGadgets(int num_entries) { int i; @@ -8273,6 +8343,14 @@ static void HandleScreenGadgets(struct GadgetInfo *gi) HandleSetupScreen_Input_Player(step, +1); break; + case SCREEN_CTRL_ID_INSERT_SOLUTION: + InsertSolutionTape(); + break; + + case SCREEN_CTRL_ID_PLAY_SOLUTION: + PlaySolutionTape(); + break; + case SCREEN_CTRL_ID_SCROLL_UP: if (game_status == GAME_MODE_LEVELS) HandleChooseLevelSet(0,0, 0, -1 * SCROLL_LINE, MB_MENU_MARK); diff --git a/src/tape.c b/src/tape.c index f75bc897..1e072cd4 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1079,12 +1079,18 @@ void TapeQuickLoad() } } -boolean InsertSolutionTape() +boolean hasSolutionTape() { + boolean tape_file_exists = fileExists(getSolutionTapeFilename(level_nr)); boolean level_has_tape = (level.game_engine_type == GAME_ENGINE_TYPE_SP && level.native_sp_level->demo.is_available); - if (!fileExists(getSolutionTapeFilename(level_nr)) && !level_has_tape) + return (tape_file_exists || level_has_tape); +} + +boolean InsertSolutionTape() +{ + if (!hasSolutionTape()) { Request("No solution tape for this level!", REQ_CONFIRM); diff --git a/src/tape.h b/src/tape.h index 0924395c..e7f4da6e 100644 --- a/src/tape.h +++ b/src/tape.h @@ -233,6 +233,8 @@ unsigned int GetTapeLengthFrames(void); unsigned int GetTapeLengthSeconds(void); void TapeQuickSave(void); void TapeQuickLoad(void); + +boolean hasSolutionTape(); boolean InsertSolutionTape(void); boolean PlaySolutionTape(void);