added separate grid buttons for landscape and portrait screen orientation
[rocksndiamonds.git] / src / screens.c
index dc28e237a19db3810867bf82440545bb782c1c41..3dd571fe857cb912493d9dc0105a0a559103d2fe 100644 (file)
@@ -207,6 +207,7 @@ static void HandleSetupScreen_Generic(int, int, int, int, int);
 static void HandleSetupScreen_Input(int, int, int, int, int);
 static void CustomizeKeyboard(int);
 static void ConfigureJoystick(int);
+static void ConfigureVirtualButtons();
 static void execSetupGame(void);
 static void execSetupGraphics(void);
 static void execSetupSound(void);
@@ -5257,6 +5258,13 @@ static void execSetupChooseDropDistance()
   DrawSetupScreen();
 }
 
+static void execSetupConfigureVirtualButtons()
+{
+  ConfigureVirtualButtons();
+
+  DrawSetupScreen();
+}
+
 static void execSetupTouch()
 {
   if (touch_controls == NULL)
@@ -5743,6 +5751,18 @@ static struct TokenInfo setup_info_touch[] =
   { 0,                 NULL,                   NULL                    }
 };
 
+static struct TokenInfo setup_info_touch_virtual_buttons[] =
+{
+  { TYPE_ENTER_LIST,   execSetupChooseTouchControls, "Touch Control Type:" },
+  { TYPE_STRING,       &touch_controls_text,   ""                      },
+  { TYPE_EMPTY,                NULL,                   ""                      },
+  { TYPE_ENTER_LIST,   execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
+  { TYPE_EMPTY,                NULL,                   ""                      },
+  { TYPE_LEAVE_MENU,   execSetupMain,          "Back"                  },
+
+  { 0,                 NULL,                   NULL                    }
+};
+
 static struct TokenInfo setup_info_touch_wipe_gestures[] =
 {
   { TYPE_ENTER_LIST,   execSetupChooseTouchControls, "Touch Control Type:" },
@@ -6176,7 +6196,9 @@ static void DrawSetupScreen_Generic()
     setup_info = setup_info_touch;
     title_string = STR_SETUP_TOUCH;
 
-    if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
+    if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
+      setup_info = setup_info_touch_virtual_buttons;
+    else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_WIPE_GESTURES))
       setup_info = setup_info_touch_wipe_gestures;
   }
   else if (setup_mode == SETUP_MODE_SHORTCUTS)
@@ -6570,7 +6592,7 @@ static boolean CustomizeKeyboardMain(int player_nr)
   };
   int font_nr_old = FONT_VALUE_OLD;
   int font_nr_new = FONT_VALUE_1;
-  int success = FALSE;
+  boolean success = FALSE;
 
   if (SCR_FIELDX < SCR_FIELDX_DEFAULT)
   {
@@ -6898,6 +6920,7 @@ static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
                       controller->width, controller->height,
                       controller_x, controller_y);
 
+      SDL_SetSurfaceBlendMode(marker->surface_masked, SDL_BLENDMODE_BLEND);
       SDL_SetSurfaceAlphaMod(marker->surface_masked, alpha);
 
       BlitBitmapMasked(marker, drawto, 0, 0,
@@ -7002,6 +7025,8 @@ static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
                /* leave screen */
                success = FALSE;
                done = TRUE;
+
+               break;
              }
 
              /* undo this step */
@@ -7150,6 +7175,239 @@ void ConfigureJoystick(int player_nr)
   DrawSetupScreen_Input();
 }
 
+boolean ConfigureVirtualButtonsMain()
+{
+  static char *customize_step_text[] =
+  {
+    "Move Left",
+    "Move Right",
+    "Move Up",
+    "Move Down",
+    "Snap Field",
+    "Drop Element"
+  };
+  char grid_button[] =
+  {
+    CHAR_GRID_BUTTON_LEFT,
+    CHAR_GRID_BUTTON_RIGHT,
+    CHAR_GRID_BUTTON_UP,
+    CHAR_GRID_BUTTON_DOWN,
+    CHAR_GRID_BUTTON_SNAP,
+    CHAR_GRID_BUTTON_DROP
+  };
+  int font_nr = FONT_INPUT_1_ACTIVE;
+  int font_height = getFontHeight(font_nr);
+  int ypos1 = SYSIZE / 2 - font_height * 2;
+  int ypos2 = SYSIZE / 2 - font_height * 1;
+  boolean success = FALSE;
+  boolean finished = FALSE;
+  int step_nr = 0;
+  char grid_button_draw = CHAR_GRID_BUTTON_NONE;
+  char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
+  char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
+  boolean set_grid_button = FALSE;
+  int nr = GRID_ACTIVE_NR();
+  int x, y;
+
+  for (x = 0; x < MAX_GRID_XSIZE; x++)
+    for (y = 0; y < MAX_GRID_YSIZE; y++)
+      grid_button_old[x][y] = grid_button_tmp[x][y] = overlay.grid_button[x][y];
+
+  overlay.grid_button_highlight = grid_button[step_nr];
+
+  FadeSetEnterMenu();
+  FadeOut(REDRAW_FIELD);
+
+  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]);
+
+  FadeIn(REDRAW_FIELD);
+
+  SetOverlayShowGrid(TRUE);
+
+  while (!finished)
+  {
+    Event event;
+
+    while (NextValidEvent(&event))
+    {
+      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]);
+         }
+         break;
+
+        case EVENT_KEYRELEASE:
+         key_joystick_mapping = 0;
+         break;
+
+       case EVENT_BUTTONPRESS:
+       case EVENT_BUTTONRELEASE:
+         {
+           ButtonEvent *button = (ButtonEvent *)&event;
+
+           button->x += video.screen_xoffset;
+           button->y += video.screen_yoffset;
+
+           x = button->x * overlay.grid_xsize / video.screen_width;
+           y = button->y * overlay.grid_ysize / video.screen_height;
+
+           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;
+
+       case EVENT_MOTIONNOTIFY:
+         {
+           MotionEvent *motion = (MotionEvent *)&event;
+
+           motion->x += video.screen_xoffset;
+           motion->y += video.screen_yoffset;
+
+           x = motion->x * overlay.grid_xsize / video.screen_width;
+           y = motion->y * overlay.grid_ysize / video.screen_height;
+
+           set_grid_button = TRUE;
+         }
+         break;
+
+        default:
+         HandleOtherEvents(&event);
+         break;
+      }
+
+      if (set_grid_button)
+      {
+       overlay.grid_button[x][y] =
+         (grid_button_draw != CHAR_GRID_BUTTON_NONE ? grid_button_draw :
+          grid_button_tmp[x][y] == grid_button[step_nr] ? CHAR_GRID_BUTTON_NONE :
+          grid_button_tmp[x][y]);
+
+       set_grid_button = FALSE;
+      }
+    }
+
+    BackToFront();
+  }
+
+  for (x = 0; x < MAX_GRID_XSIZE; x++)
+    for (y = 0; y < MAX_GRID_YSIZE; y++)
+      overlay.grid_button_all[nr][x][y] = overlay.grid_button[x][y];
+
+  overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
+
+  SetOverlayShowGrid(FALSE);
+
+  return success;
+}
+
+void ConfigureVirtualButtons()
+{
+  boolean success = ConfigureVirtualButtonsMain();
+
+  if (success)
+  {
+    int font_nr = FONT_TITLE_1;
+    int font_height = getFontHeight(font_nr);
+    int ypos1 = SYSIZE / 2 - font_height * 2;
+    int ypos2 = SYSIZE / 2 - font_height * 1;
+    unsigned int wait_frame_delay = 0;
+    unsigned int wait_frame_delay_value = 2000;
+
+    ResetDelayCounter(&wait_frame_delay);
+
+    ClearField();
+
+    DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
+    DrawTextSCentered(ypos2, font_nr, "configured!");
+
+    while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
+      BackToFront();
+
+    ClearEventQueue();
+  }
+}
+
 void DrawSetupScreen()
 {
   if (setup_mode == SETUP_MODE_INPUT)