added using configurable virtual buttons while playing
authorHolger Schemel <info@artsoft.org>
Wed, 9 May 2018 19:51:23 +0000 (21:51 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 5 Jun 2018 18:58:42 +0000 (20:58 +0200)
Note: Virtual buttons can be configured (for both screen orientations)
and are also used when playing the game now, but are not saved yet.

src/events.c
src/libgame/sdl.c
src/libgame/system.c
src/libgame/system.h

index 5a4023ec36b3e621d0d22fa5e8dc1b3765dfc293..4fcbd19981885ce1074cb310c08aae18cb6c2490 100644 (file)
@@ -683,6 +683,18 @@ static struct
 
 void HandleFingerEvent_VirtualButtons(FingerEvent *event)
 {
+#if 1
+  int x = event->x * overlay.grid_xsize;
+  int y = event->y * overlay.grid_ysize;
+  int grid_button = overlay.grid_button[x][y];
+  Key key = (grid_button == CHAR_GRID_BUTTON_LEFT  ? setup.input[0].key.left :
+            grid_button == CHAR_GRID_BUTTON_RIGHT ? setup.input[0].key.right :
+            grid_button == CHAR_GRID_BUTTON_UP    ? setup.input[0].key.up :
+            grid_button == CHAR_GRID_BUTTON_DOWN  ? setup.input[0].key.down :
+            grid_button == CHAR_GRID_BUTTON_SNAP  ? setup.input[0].key.snap :
+            grid_button == CHAR_GRID_BUTTON_DROP  ? setup.input[0].key.drop :
+            KSYM_UNDEFINED);
+#else
   float ypos = 1.0 - 1.0 / 3.0 * video.display_width / video.display_height;
   float event_x = (event->x);
   float event_y = (event->y - ypos) / (1 - ypos);
@@ -705,6 +717,7 @@ void HandleFingerEvent_VirtualButtons(FingerEvent *event)
             event_y > 2.0 / 3.0 && event_y < 1 ?
             setup.input[0].key.down :
             KSYM_UNDEFINED);
+#endif
   int key_status = (event->type == EVENT_FINGERRELEASE ? KEY_RELEASED :
                    KEY_PRESSED);
   char *key_status_name = (key_status == KEY_RELEASED ? "KEY_RELEASED" :
index d1d14a825bc525c7e35fae31c03f0b3fb9267d6b..877bb16eb3bdd35d0dff071a389a1cdbb95b2746 100644 (file)
@@ -3077,7 +3077,6 @@ static void DrawTouchInputOverlay()
   static boolean initialized = FALSE;
   static boolean deactivated = TRUE;
   static boolean show_grid = FALSE;
-  static boolean show_grid_buttons = FALSE;
   static int width = 0, height = 0;
   static int alpha_max = SDL_ALPHA_OPAQUE / 2;
   static int alpha_step = 5;
@@ -3108,19 +3107,15 @@ static void DrawTouchInputOverlay()
   else if (deactivated)
     show_grid = FALSE;
 
-  if (overlay.show_grid_buttons)
-    show_grid_buttons = TRUE;
-  else if (deactivated)
-    show_grid_buttons = FALSE;
-
   if (show_grid)
     DrawTouchInputOverlay_ShowGrid(alpha);
 
-  if (show_grid_buttons)
-    DrawTouchInputOverlay_ShowGridButtons(alpha);
+  DrawTouchInputOverlay_ShowGridButtons(alpha);
 
-  if (show_grid || show_grid_buttons)
-    return;
+  return;
+
+
+  // !!! VIRTUAL BUTTONS FROM IMAGE FILE NOT USED ANYMORE !!!
 
   if (!initialized)
   {
index 5b7cede45da7a2932ca770d4bc9722b85eac13ed..3363ac2b94c7cbfe976ba25c2806b403b75595f6 100644 (file)
@@ -341,7 +341,6 @@ void InitOverlayInfo()
   overlay.active = FALSE;
 
   overlay.show_grid = FALSE;
-  overlay.show_grid_buttons = FALSE;
 
   for (i = 0; i < 2; i++)
   {
@@ -439,7 +438,6 @@ void SetOverlayActive(boolean active)
 void SetOverlayShowGrid(boolean show_grid)
 {
   overlay.show_grid = show_grid;
-  overlay.show_grid_buttons = show_grid;
 
   SetOverlayActive(show_grid);
 
index b5c5fcee6771397befef3e9f6710bf32f26f2e1b..480ef0d426820e4719effd45d914d909fa171c49 100644 (file)
@@ -1016,7 +1016,6 @@ struct OverlayInfo
   boolean active;              /* overlay activated (depending on game mode) */
 
   boolean show_grid;
-  boolean show_grid_buttons;
 
   int grid_xsize_all[2];
   int grid_ysize_all[2];