X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fscreens.c;h=3a90c9571dd8aba39f387d6951a7989deb02d351;hb=67a6bf41eb5b913335c2f89ea1405c0dfb54360b;hp=9e55d79699d2eabd1731d00378d6e3b6496098ff;hpb=914d869445048466ef00954109a15286938521c6;p=rocksndiamonds.git diff --git a/src/screens.c b/src/screens.c index 9e55d796..3a90c957 100644 --- a/src/screens.c +++ b/src/screens.c @@ -258,6 +258,7 @@ static void ModifyGameSpeedIfNeeded(void); static void DisableVsyncIfNeeded(void); static void MapScreenMenuGadgets(int); +static void UnmapScreenMenuGadgets(int); static void MapScreenGadgets(int); static void MapScreenTreeGadgets(TreeInfo *); @@ -7905,6 +7906,13 @@ static boolean ConfigureVirtualButtonsMain(void) CHAR_GRID_BUTTON_SNAP, CHAR_GRID_BUTTON_DROP }; + enum + { + ACTION_NONE, + ACTION_ESCAPE, + ACTION_BACK, + ACTION_NEXT + }; int font_nr = FONT_INPUT_1_ACTIVE; int font_height = getFontHeight(font_nr); int ypos1 = SYSIZE / 2 - font_height * 2; @@ -7944,74 +7952,23 @@ static boolean ConfigureVirtualButtonsMain(void) while (NextValidEvent(&event)) { + int action = ACTION_NONE; + + // ---------- handle events and set the resulting action ---------- + switch (event.type) { case EVENT_KEYPRESS: { Key key = GetEventKey((KeyEvent *)&event, FALSE); - // press 'Escape' to abort and keep the old key bindings - if (key == KSYM_Escape) - { - for (x = 0; x < MAX_GRID_XSIZE; x++) - for (y = 0; y < MAX_GRID_YSIZE; y++) - overlay.grid_button[x][y] = grid_button_old[x][y]; - - FadeSkipNextFadeIn(); - - finished = TRUE; - - break; - } - - // press 'Enter' to keep the existing key binding - if (key == KSYM_Return || - key == KSYM_Menu || - key == KSYM_space) - { - step_nr++; - } - else if (key == KSYM_BackSpace || - key == KSYM_Back) - { - if (step_nr == 0) - { - FadeSkipNextFadeIn(); - - finished = TRUE; - - break; - } - - step_nr--; - } - else - { - break; - } - - // all virtual buttons configured - if (step_nr == 6) - { - finished = TRUE; - success = TRUE; - - break; - } - - for (x = 0; x < MAX_GRID_XSIZE; x++) - for (y = 0; y < MAX_GRID_YSIZE; y++) - grid_button_tmp[x][y] = overlay.grid_button[x][y]; - - overlay.grid_button_highlight = grid_button[step_nr]; - - // query next virtual button - - ClearField(); - - DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons"); - DrawTextSCentered(ypos1, font_nr, "Select tiles to"); - DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]); + action = (key == KSYM_Escape ? ACTION_ESCAPE : + key == KSYM_BackSpace || + key == KSYM_Back ? ACTION_BACK : + key == KSYM_Return || + key == KSYM_Menu || + key == KSYM_space ? ACTION_NEXT : + ACTION_NONE); } break; @@ -8024,6 +7981,13 @@ static boolean ConfigureVirtualButtonsMain(void) { ButtonEvent *button = (ButtonEvent *)&event; + motion_status = FALSE; + + if (button->type == EVENT_BUTTONPRESS) + button_status = button->button; + else + button_status = MB_RELEASED; + button->x += video.screen_xoffset; button->y += video.screen_yoffset; @@ -8032,18 +7996,12 @@ static boolean ConfigureVirtualButtonsMain(void) if (button->type == EVENT_BUTTONPRESS) { - button_status = button->button; - grid_button_draw = (overlay.grid_button[x][y] != grid_button[step_nr] ? grid_button[step_nr] : CHAR_GRID_BUTTON_NONE); set_grid_button = TRUE; } - else - { - button_status = MB_RELEASED; - } } break; @@ -8051,6 +8009,8 @@ static boolean ConfigureVirtualButtonsMain(void) { MotionEvent *motion = (MotionEvent *)&event; + motion_status = TRUE; + motion->x += video.screen_xoffset; motion->y += video.screen_yoffset; @@ -8089,6 +8049,64 @@ static boolean ConfigureVirtualButtonsMain(void) break; } + // ---------- perform action set by handling events ---------- + + if (action == ACTION_ESCAPE) + { + // abort and restore the old key bindings + + for (x = 0; x < MAX_GRID_XSIZE; x++) + for (y = 0; y < MAX_GRID_YSIZE; y++) + overlay.grid_button[x][y] = grid_button_old[x][y]; + + FadeSkipNextFadeIn(); + + finished = TRUE; + } + else if (action == ACTION_BACK) + { + // keep the configured key bindings and go to previous page + + step_nr--; + + if (step_nr < 0) + { + FadeSkipNextFadeIn(); + + finished = TRUE; + } + } + else if (action == ACTION_NEXT) + { + // keep the configured key bindings and go to next page + + step_nr++; + + // all virtual buttons configured + if (step_nr == 6) + { + finished = TRUE; + success = TRUE; + } + } + + if (action != ACTION_NONE && !finished) + { + for (x = 0; x < MAX_GRID_XSIZE; x++) + for (y = 0; y < MAX_GRID_YSIZE; y++) + grid_button_tmp[x][y] = overlay.grid_button[x][y]; + + overlay.grid_button_highlight = grid_button[step_nr]; + + // configure next virtual button + + ClearField(); + + DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Virtual Buttons"); + DrawTextSCentered(ypos1, font_nr, "Select tiles to"); + DrawTextSCentered(ypos2, font_nr, customize_step_text[step_nr]); + } + if (set_grid_button) { overlay.grid_button[x][y] = @@ -8300,64 +8318,10 @@ void HandleGameActions(void) // ---------- new screen button stuff -------------------------------------- -static void getScreenMenuButtonPos(int *x, int *y, int gadget_id) -{ - switch (gadget_id) - { - case SCREEN_CTRL_ID_PREV_LEVEL: - *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x); - *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y); - break; - - case SCREEN_CTRL_ID_NEXT_LEVEL: - *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x); - *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y); - break; - - case SCREEN_CTRL_ID_FIRST_LEVEL: - *x = mSX + GDI_ACTIVE_POS(menu.main.button.first_level.x); - *y = mSY + GDI_ACTIVE_POS(menu.main.button.first_level.y); - break; - - case SCREEN_CTRL_ID_LAST_LEVEL: - *x = mSX + GDI_ACTIVE_POS(menu.main.button.last_level.x); - *y = mSY + GDI_ACTIVE_POS(menu.main.button.last_level.y); - break; - - case SCREEN_CTRL_ID_LEVEL_NUMBER: - *x = mSX + GDI_ACTIVE_POS(menu.main.button.level_number.x); - *y = mSY + GDI_ACTIVE_POS(menu.main.button.level_number.y); - break; - - case SCREEN_CTRL_ID_PREV_PLAYER: - *x = mSX + GDI_ACTIVE_POS(menu.setup.button.prev_player.x); - *y = mSY + GDI_ACTIVE_POS(menu.setup.button.prev_player.y); - break; - - case SCREEN_CTRL_ID_NEXT_PLAYER: - *x = mSX + GDI_ACTIVE_POS(menu.setup.button.next_player.x); - *y = mSY + GDI_ACTIVE_POS(menu.setup.button.next_player.y); - 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); - } -} - static struct { int gfx_unpressed, gfx_pressed; - void (*get_gadget_position)(int *, int *, int); + struct MenuPosInfo *pos; int gadget_id; int screen_mask; unsigned int event_mask; @@ -8366,7 +8330,7 @@ static struct { { IMG_MENU_BUTTON_PREV_LEVEL, IMG_MENU_BUTTON_PREV_LEVEL_ACTIVE, - getScreenMenuButtonPos, + &menu.main.button.prev_level, SCREEN_CTRL_ID_PREV_LEVEL, SCREEN_MASK_MAIN, GD_EVENT_PRESSED | GD_EVENT_REPEATED, @@ -8374,7 +8338,7 @@ static struct }, { IMG_MENU_BUTTON_NEXT_LEVEL, IMG_MENU_BUTTON_NEXT_LEVEL_ACTIVE, - getScreenMenuButtonPos, + &menu.main.button.next_level, SCREEN_CTRL_ID_NEXT_LEVEL, SCREEN_MASK_MAIN, GD_EVENT_PRESSED | GD_EVENT_REPEATED, @@ -8382,7 +8346,7 @@ static struct }, { IMG_MENU_BUTTON_FIRST_LEVEL, IMG_MENU_BUTTON_FIRST_LEVEL_ACTIVE, - getScreenMenuButtonPos, + &menu.main.button.first_level, SCREEN_CTRL_ID_FIRST_LEVEL, SCREEN_MASK_MAIN, GD_EVENT_RELEASED, @@ -8390,7 +8354,7 @@ static struct }, { IMG_MENU_BUTTON_LAST_LEVEL, IMG_MENU_BUTTON_LAST_LEVEL_ACTIVE, - getScreenMenuButtonPos, + &menu.main.button.last_level, SCREEN_CTRL_ID_LAST_LEVEL, SCREEN_MASK_MAIN, GD_EVENT_RELEASED, @@ -8398,7 +8362,7 @@ static struct }, { IMG_MENU_BUTTON_LEVEL_NUMBER, IMG_MENU_BUTTON_LEVEL_NUMBER_ACTIVE, - getScreenMenuButtonPos, + &menu.main.button.level_number, SCREEN_CTRL_ID_LEVEL_NUMBER, SCREEN_MASK_MAIN, GD_EVENT_RELEASED, @@ -8406,7 +8370,7 @@ static struct }, { IMG_MENU_BUTTON_LEFT, IMG_MENU_BUTTON_LEFT_ACTIVE, - getScreenMenuButtonPos, + &menu.setup.button.prev_player, SCREEN_CTRL_ID_PREV_PLAYER, SCREEN_MASK_INPUT, GD_EVENT_PRESSED | GD_EVENT_REPEATED, @@ -8414,7 +8378,7 @@ static struct }, { IMG_MENU_BUTTON_RIGHT, IMG_MENU_BUTTON_RIGHT_ACTIVE, - getScreenMenuButtonPos, + &menu.setup.button.next_player, SCREEN_CTRL_ID_NEXT_PLAYER, SCREEN_MASK_INPUT, GD_EVENT_PRESSED | GD_EVENT_REPEATED, @@ -8422,7 +8386,7 @@ static struct }, { IMG_MENU_BUTTON_INSERT_SOLUTION, IMG_MENU_BUTTON_INSERT_SOLUTION_ACTIVE, - getScreenMenuButtonPos, + &menu.main.button.insert_solution, SCREEN_CTRL_ID_INSERT_SOLUTION, SCREEN_MASK_MAIN_HAS_SOLUTION, GD_EVENT_RELEASED, @@ -8430,7 +8394,7 @@ static struct }, { IMG_MENU_BUTTON_PLAY_SOLUTION, IMG_MENU_BUTTON_PLAY_SOLUTION_ACTIVE, - getScreenMenuButtonPos, + &menu.main.button.play_solution, SCREEN_CTRL_ID_PLAY_SOLUTION, SCREEN_MASK_MAIN_HAS_SOLUTION, GD_EVENT_RELEASED, @@ -8508,6 +8472,7 @@ static void CreateScreenMenubuttons(void) for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++) { + struct MenuPosInfo *pos = menubutton_info[i].pos; Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed; int gfx_unpressed, gfx_pressed; int x, y, width, height; @@ -8516,7 +8481,8 @@ static void CreateScreenMenubuttons(void) event_mask = menubutton_info[i].event_mask; - menubutton_info[i].get_gadget_position(&x, &y, id); + x = mSX + GDI_ACTIVE_POS(pos->x); + y = mSY + GDI_ACTIVE_POS(pos->y); width = graphic_info[menubutton_info[i].gfx_pressed].width; height = graphic_info[menubutton_info[i].gfx_pressed].height; @@ -8767,7 +8733,7 @@ void FreeScreenGadgets(void) FreeGadget(screen_gadget[i]); } -void MapScreenMenuGadgets(int screen_mask) +static void MapScreenMenuGadgets(int screen_mask) { int i; @@ -8795,7 +8761,7 @@ static void UnmapScreenMenuGadgets(int screen_mask) } } -void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets) +static void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets) { if (map_gadgets) MapScreenMenuGadgets(screen_mask); @@ -8803,7 +8769,7 @@ void UpdateScreenMenuGadgets(int screen_mask, boolean map_gadgets) UnmapScreenMenuGadgets(screen_mask); } -void MapScreenGadgets(int num_entries) +static void MapScreenGadgets(int num_entries) { int i; @@ -8817,7 +8783,7 @@ void MapScreenGadgets(int num_entries) MapGadget(screen_gadget[scrollbar_info[i].gadget_id]); } -void MapScreenTreeGadgets(TreeInfo *ti) +static void MapScreenTreeGadgets(TreeInfo *ti) { MapScreenGadgets(numTreeInfoInGroup(ti)); }