fixed default values for move/drop distances for wipe gestures
[rocksndiamonds.git] / src / screens.c
index 6d23dc804edd6e71a7133f436d212bc7bb277e75..458f9422473217ee0fd210ba6b3c189fbea08da3 100644 (file)
@@ -77,8 +77,9 @@
 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL        28
 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE        29
 #define SETUP_MODE_CHOOSE_DROP_DISTANCE        30
+#define SETUP_MODE_CHOOSE_TRANSPARENCY 31
 
-#define MAX_SETUP_MODES                        31
+#define MAX_SETUP_MODES                        32
 
 #define MAX_MENU_MODES                 MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
 
 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
+#define STR_SETUP_CHOOSE_TRANSPARENCY  "Transparency"
 
 /* for input setup functions */
 #define SETUPINPUT_SCREEN_POS_START    0
@@ -276,6 +278,9 @@ static TreeInfo *move_distance_current = NULL;
 static TreeInfo *drop_distances = NULL;
 static TreeInfo *drop_distance_current = NULL;
 
+static TreeInfo *transparencies = NULL;
+static TreeInfo *transparency_current = NULL;
+
 static TreeInfo *level_number = NULL;
 static TreeInfo *level_number_current = NULL;
 
@@ -452,6 +457,27 @@ static struct
   {    -1,     NULL                            },
 };
 
+static struct
+{
+  int value;
+  char *text;
+} transparencies_list[] =
+{
+  {    0,      "0 % (Opaque)"                  },
+  {    10,     "10 %"                          },
+  {    20,     "20 %"                          },
+  {    30,     "30 %"                          },
+  {    40,     "40 %"                          },
+  {    50,     "50 %"                          },
+  {    60,     "60 %"                          },
+  {    70,     "70 %"                          },
+  {    80,     "80 %"                          },
+  {    90,     "90 %"                          },
+  {    100,    "100 % (Invisible)"             },
+
+  {    -1,     NULL                            },
+};
+
 #define DRAW_MODE(s)           ((s) >= GAME_MODE_MAIN &&               \
                                 (s) <= GAME_MODE_SETUP ? (s) :         \
                                 (s) == GAME_MODE_PSEUDO_TYPENAME ?     \
@@ -4076,7 +4102,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
        execSetupSound();
       else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
               setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
-              setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+              setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
+              setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
        execSetupTouch();
       else
        execSetupArtwork();
@@ -4228,7 +4255,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
            execSetupSound();
          else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
                   setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
-                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
+                  setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
            execSetupTouch();
          else
            execSetupArtwork();
@@ -4294,7 +4322,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
            execSetupSound();
          else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
                   setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
-                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
+                  setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
            execSetupTouch();
          else
            execSetupArtwork();
@@ -4561,6 +4590,7 @@ static char *volume_music_text;
 static char *touch_controls_text;
 static char *move_distance_text;
 static char *drop_distance_text;
+static char *transparency_text;
 
 static void execSetupMain()
 {
@@ -5258,6 +5288,13 @@ static void execSetupChooseDropDistance()
   DrawSetupScreen();
 }
 
+static void execSetupChooseTransparency()
+{
+  setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
+
+  DrawSetupScreen();
+}
+
 static void execSetupConfigureVirtualButtons()
 {
   ConfigureVirtualButtons();
@@ -5345,7 +5382,8 @@ static void execSetupTouch()
     /* if that fails, set current distance to reliable default value */
     if (move_distance_current == NULL)
       move_distance_current =
-       getTreeInfoFromIdentifier(move_distances, i_to_a(1));
+       getTreeInfoFromIdentifier(move_distances,
+                                 i_to_a(TOUCH_MOVE_DISTANCE_DEFAULT));
 
     /* if that also fails, set current distance to first available value */
     if (move_distance_current == NULL)
@@ -5388,21 +5426,68 @@ static void execSetupTouch()
     /* if that fails, set current distance to reliable default value */
     if (drop_distance_current == NULL)
       drop_distance_current =
-       getTreeInfoFromIdentifier(drop_distances, i_to_a(1));
+       getTreeInfoFromIdentifier(drop_distances,
+                                 i_to_a(TOUCH_DROP_DISTANCE_DEFAULT));
 
     /* if that also fails, set current distance to first available value */
     if (drop_distance_current == NULL)
       drop_distance_current = drop_distances;
   }
 
+  if (transparencies == NULL)
+  {
+    int i;
+
+    for (i = 0; transparencies_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = transparencies_list[i].value;
+      char *text = transparencies_list[i].text;
+
+      ti->node_top = &transparencies;
+      ti->sort_priority = value;
+
+      sprintf(identifier, "%d", value);
+      sprintf(name, "%s", text);
+
+      setString(&ti->identifier, identifier);
+      setString(&ti->name, name);
+      setString(&ti->name_sorting, name);
+      setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
+
+      pushTreeInfo(&transparencies, ti);
+    }
+
+    /* sort transparency values to start with lowest transparency value */
+    sortTreeInfo(&transparencies);
+
+    /* set current transparency value to configured transparency value */
+    transparency_current =
+      getTreeInfoFromIdentifier(transparencies,
+                               i_to_a(setup.touch.transparency));
+
+    /* if that fails, set current transparency to reliable default value */
+    if (transparency_current == NULL)
+      transparency_current =
+       getTreeInfoFromIdentifier(transparencies,
+                                 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
+
+    /* if that also fails, set current transparency to first available value */
+    if (transparency_current == NULL)
+      transparency_current = transparencies;
+  }
+
   setup.touch.control_type = touch_control_current->identifier;
   setup.touch.move_distance = atoi(move_distance_current->identifier);
   setup.touch.drop_distance = atoi(drop_distance_current->identifier);
+  setup.touch.transparency = atoi(transparency_current->identifier);
 
   /* needed for displaying volume text instead of identifier */
   touch_controls_text = touch_control_current->name;
   move_distance_text = move_distance_current->name;
   drop_distance_text = drop_distance_current->name;
+  transparency_text = transparency_current->name;
 
   setup_mode = SETUP_MODE_TOUCH;
 
@@ -5569,6 +5654,9 @@ static struct
   { &setup.touch.drop_distance,                execSetupChooseDropDistance     },
   { &setup.touch.drop_distance,                &drop_distance_text             },
 
+  { &setup.touch.transparency,         execSetupChooseTransparency     },
+  { &setup.touch.transparency,         &transparency_text              },
+
   { NULL,                              NULL                            }
 };
 
@@ -5756,6 +5844,9 @@ 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,   execSetupChooseTransparency, "Transparency:"    },
+  { TYPE_STRING,       &transparency_text,     ""                      },
+  { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_ENTER_LIST,   execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_LEAVE_MENU,   execSetupMain,          "Back"                  },
@@ -7186,6 +7277,15 @@ boolean ConfigureVirtualButtonsMain()
     "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;
@@ -7193,6 +7293,18 @@ boolean ConfigureVirtualButtonsMain()
   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);
@@ -7205,11 +7317,13 @@ boolean ConfigureVirtualButtonsMain()
 
   FadeIn(REDRAW_FIELD);
 
+  SetOverlayShowGrid(TRUE);
+
   while (!finished)
   {
     Event event;
 
-    if (NextValidEvent(&event))
+    while (NextValidEvent(&event))
     {
       switch (event.type)
       {
@@ -7220,6 +7334,10 @@ boolean ConfigureVirtualButtonsMain()
            /* 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;
@@ -7262,6 +7380,12 @@ boolean ConfigureVirtualButtonsMain()
              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();
@@ -7276,15 +7400,100 @@ boolean ConfigureVirtualButtonsMain()
          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;
+
+#if defined(TARGET_SDL2)
+       case SDL_WINDOWEVENT:
+         HandleWindowEvent((WindowEvent *) &event);
+
+         // check if device has been rotated
+         if (nr != GRID_ACTIVE_NR())
+         {
+           nr = GRID_ACTIVE_NR();
+
+           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];
+         }
+
+         break;
+
+       case SDL_APP_WILLENTERBACKGROUND:
+       case SDL_APP_DIDENTERBACKGROUND:
+       case SDL_APP_WILLENTERFOREGROUND:
+       case SDL_APP_DIDENTERFOREGROUND:
+         HandlePauseResumeEvent((PauseResumeEvent *) &event);
+         break;
+#endif
+
         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++)
+      setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
+
+  overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
+
+  SetOverlayShowGrid(FALSE);
+
   return success;
 }
 
@@ -7349,6 +7558,8 @@ void DrawSetupScreen()
     DrawChooseTree(&move_distance_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
     DrawChooseTree(&drop_distance_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
+    DrawChooseTree(&transparency_current);
   else
     DrawSetupScreen_Generic();
 
@@ -7401,6 +7612,8 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
     HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
     HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
+    HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
   else
     HandleSetupScreen_Generic(mx, my, dx, dy, button);
 }