rnd-20140430-1-src
[rocksndiamonds.git] / src / screens.c
index c2fd03149e4875fde322426f4f3ab5c3c8e95485..95b6706f5f0c8beb3257fcf833781def1a44b4af 100644 (file)
 #define SETUP_MODE_SOUND               4
 #define SETUP_MODE_ARTWORK             5
 #define SETUP_MODE_INPUT               6
-#define SETUP_MODE_SHORTCUTS           7
-#define SETUP_MODE_SHORTCUTS_1         8
-#define SETUP_MODE_SHORTCUTS_2         9
-#define SETUP_MODE_SHORTCUTS_3         10
-#define SETUP_MODE_SHORTCUTS_4         11
-#define SETUP_MODE_SHORTCUTS_5         12
+#define SETUP_MODE_TOUCH               7
+#define SETUP_MODE_SHORTCUTS           8
+#define SETUP_MODE_SHORTCUTS_1         9
+#define SETUP_MODE_SHORTCUTS_2         10
+#define SETUP_MODE_SHORTCUTS_3         11
+#define SETUP_MODE_SHORTCUTS_4         12
+#define SETUP_MODE_SHORTCUTS_5         13
 
 /* sub-screens on the setup screen (generic) */
-#define SETUP_MODE_CHOOSE_ARTWORK      13
-#define SETUP_MODE_CHOOSE_OTHER                14
+#define SETUP_MODE_CHOOSE_ARTWORK      14
+#define SETUP_MODE_CHOOSE_OTHER                15
 
 /* sub-screens on the setup screen (specific) */
-#define SETUP_MODE_CHOOSE_GAME_SPEED   15
-#define SETUP_MODE_CHOOSE_SCROLL_DELAY 16
-#define SETUP_MODE_CHOOSE_SCREEN_MODE  17
-#define SETUP_MODE_CHOOSE_WINDOW_SIZE  18
-#define SETUP_MODE_CHOOSE_SCALING_TYPE 19
-#define SETUP_MODE_CHOOSE_GRAPHICS     20
-#define SETUP_MODE_CHOOSE_SOUNDS       21
-#define SETUP_MODE_CHOOSE_MUSIC                22
-#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE        23
-#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 24
-#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 25
-
-#define MAX_SETUP_MODES                        26
+#define SETUP_MODE_CHOOSE_GAME_SPEED   16
+#define SETUP_MODE_CHOOSE_SCROLL_DELAY 17
+#define SETUP_MODE_CHOOSE_SCREEN_MODE  18
+#define SETUP_MODE_CHOOSE_WINDOW_SIZE  19
+#define SETUP_MODE_CHOOSE_SCALING_TYPE 20
+#define SETUP_MODE_CHOOSE_GRAPHICS     21
+#define SETUP_MODE_CHOOSE_SOUNDS       22
+#define SETUP_MODE_CHOOSE_MUSIC                23
+#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE        24
+#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 25
+#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 26
+#define SETUP_MODE_CHOOSE_TOUCH_CONTROL        27
+#define SETUP_MODE_CHOOSE_MOVE_DISTANCE        28
+#define SETUP_MODE_CHOOSE_DROP_DISTANCE        29
+
+#define MAX_SETUP_MODES                        30
 
 /* for input setup functions */
 #define SETUPINPUT_SCREEN_POS_START    0
 #define NUM_INFO_ELEMENTS_ON_SCREEN    10
 #endif
 #define MAX_MENU_ENTRIES_ON_SCREEN     (SCR_FIELDY - MENU_SCREEN_START_YPOS)
-#if 0
+#if 1
+#define MAX_MENU_TEXT_LENGTH_BIG       13
+#define MAX_MENU_TEXT_LENGTH_MEDIUM    (MAX_MENU_TEXT_LENGTH_BIG * 2)
+#else
 #define MAX_MENU_TEXT_LENGTH_BIG       (MENU_SCREEN_VALUE_XPOS -       \
                                         MENU_SCREEN_START_XPOS)
 #define MAX_MENU_TEXT_LENGTH_MEDIUM    (MAX_MENU_TEXT_LENGTH_BIG * 2)
@@ -168,6 +175,7 @@ static void CalibrateJoystick(int);
 static void execSetupGame(void);
 static void execSetupGraphics(void);
 static void execSetupSound(void);
+static void execSetupTouch(void);
 static void execSetupArtwork(void);
 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
 
@@ -222,6 +230,15 @@ static TreeInfo *volume_loops_current = NULL;
 static TreeInfo *volumes_music = NULL;
 static TreeInfo *volume_music_current = NULL;
 
+static TreeInfo *touch_controls = NULL;
+static TreeInfo *touch_control_current = NULL;
+
+static TreeInfo *move_distances = NULL;
+static TreeInfo *move_distance_current = NULL;
+
+static TreeInfo *drop_distances = NULL;
+static TreeInfo *drop_distance_current = NULL;
+
 static TreeInfo *level_number = NULL;
 static TreeInfo *level_number_current = NULL;
 
@@ -331,6 +348,37 @@ static struct
   {    -1,     NULL                            },
 };
 
+static struct
+{
+  char *value;
+  char *text;
+} touch_controls_list[] =
+{
+  {    TOUCH_CONTROL_VIRTUAL_BUTTONS,  "Virtual Buttons"       },
+  {    TOUCH_CONTROL_WIPE_GESTURES,    "Wipe Gestures"         },
+
+  {    NULL,                           NULL                    },
+};
+
+static struct
+{
+  int value;
+  char *text;
+} distances_list[] =
+{
+  {    1,      "1 %"                           },
+  {    2,      "2 %"                           },
+  {    3,      "3 %"                           },
+  {    4,      "4 %"                           },
+  {    5,      "5 %"                           },
+  {    10,     "10 %"                          },
+  {    15,     "15 %"                          },
+  {    20,     "20 %"                          },
+  {    25,     "25 %"                          },
+
+  {    -1,     NULL                            },
+};
+
 #define DRAW_MODE(s)           ((s) >= GAME_MODE_MAIN &&               \
                                 (s) <= GAME_MODE_SETUP ? (s) :         \
                                 (s) == GAME_MODE_PSEUDO_TYPENAME ?     \
@@ -1495,7 +1543,8 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading)
 #endif
 
 #if 1
-  if (fade_mask == REDRAW_ALL)
+  // if (fade_mask == REDRAW_ALL)
+  // (always redraw current door state)
   {
     int door_state = GetDoorState();
 
@@ -1505,6 +1554,12 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading)
   }
 #endif
 
+#if 0
+  redraw_mask |= REDRAW_ALL;
+  BackToFront();
+  Delay(3000);
+#endif
+
   DrawMaskedBorder(REDRAW_ALL);
 
   FadeIn(fade_mask);
@@ -3724,6 +3779,10 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
               setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
               setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
        execSetupSound();
+      else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
+              setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
+              setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+       execSetupTouch();
       else
        execSetupArtwork();
     }
@@ -3965,6 +4024,10 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
                   setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
                   setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
            execSetupSound();
+         else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
+                  setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
+                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+           execSetupTouch();
          else
            execSetupArtwork();
        }
@@ -4252,6 +4315,9 @@ static char *music_set_name;
 static char *volume_simple_text;
 static char *volume_loops_text;
 static char *volume_music_text;
+static char *touch_controls_text;
+static char *move_distance_text;
+static char *drop_distance_text;
 
 static void execSetupMain()
 {
@@ -4815,6 +4881,173 @@ static void execSetupSound()
   DrawSetupScreen();
 }
 
+static void execSetupChooseTouchControls()
+{
+  setup_mode = SETUP_MODE_CHOOSE_TOUCH_CONTROL;
+
+  DrawSetupScreen();
+}
+
+static void execSetupChooseMoveDistance()
+{
+  setup_mode = SETUP_MODE_CHOOSE_MOVE_DISTANCE;
+
+  DrawSetupScreen();
+}
+
+static void execSetupChooseDropDistance()
+{
+  setup_mode = SETUP_MODE_CHOOSE_DROP_DISTANCE;
+
+  DrawSetupScreen();
+}
+
+static void execSetupTouch()
+{
+#if 1
+  if (touch_controls == NULL)
+  {
+    int i;
+
+    for (i = 0; touch_controls_list[i].value != NULL; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      char *value = touch_controls_list[i].value;
+      char *text = touch_controls_list[i].text;
+
+      ti->node_top = &touch_controls;
+      ti->sort_priority = i;
+
+      sprintf(identifier, "%s", value);
+      sprintf(name, "%s", text);
+
+      setString(&ti->identifier, identifier);
+      setString(&ti->name, name);
+      setString(&ti->name_sorting, name);
+      setString(&ti->infotext, "Control Type");
+
+      pushTreeInfo(&touch_controls, ti);
+    }
+
+    /* sort touch control values to start with lowest touch control value */
+    sortTreeInfo(&touch_controls);
+
+    /* set current touch control value to configured touch control value */
+    touch_control_current =
+      getTreeInfoFromIdentifier(touch_controls, setup.touch.control_type);
+
+    /* if that fails, set current touch control to reliable default value */
+    if (touch_control_current == NULL)
+      touch_control_current =
+       getTreeInfoFromIdentifier(touch_controls, TOUCH_CONTROL_DEFAULT);
+
+    /* if that also fails, set current touch control to first available value */
+    if (touch_control_current == NULL)
+      touch_control_current = touch_controls;
+  }
+
+  if (move_distances == NULL)
+  {
+    int i;
+
+    for (i = 0; distances_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = distances_list[i].value;
+      char *text = distances_list[i].text;
+
+      ti->node_top = &move_distances;
+      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, "Move Distance");
+
+      pushTreeInfo(&move_distances, ti);
+    }
+
+    /* sort distance values to start with lowest distance value */
+    sortTreeInfo(&move_distances);
+
+    /* set current distance value to configured distance value */
+    move_distance_current =
+      getTreeInfoFromIdentifier(move_distances,
+                               i_to_a(setup.touch.move_distance));
+
+    /* 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));
+
+    /* if that also fails, set current distance to first available value */
+    if (move_distance_current == NULL)
+      move_distance_current = move_distances;
+  }
+
+  if (drop_distances == NULL)
+  {
+    int i;
+
+    for (i = 0; distances_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = distances_list[i].value;
+      char *text = distances_list[i].text;
+
+      ti->node_top = &drop_distances;
+      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, "Drop Distance");
+
+      pushTreeInfo(&drop_distances, ti);
+    }
+
+    /* sort distance values to start with lowest distance value */
+    sortTreeInfo(&drop_distances);
+
+    /* set current distance value to configured distance value */
+    drop_distance_current =
+      getTreeInfoFromIdentifier(drop_distances,
+                               i_to_a(setup.touch.drop_distance));
+
+    /* 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));
+
+    /* if that also fails, set current distance to first available value */
+    if (drop_distance_current == NULL)
+      drop_distance_current = drop_distances;
+  }
+
+  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);
+
+  /* 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;
+#endif
+
+  setup_mode = SETUP_MODE_TOUCH;
+
+  DrawSetupScreen();
+}
+
 static void execSetupArtwork()
 {
 #if 0
@@ -4931,7 +5164,12 @@ static struct TokenInfo setup_info_main[] =
   { TYPE_ENTER_MENU,   execSetupGraphics,      "Graphics"              },
   { TYPE_ENTER_MENU,   execSetupSound,         "Sound & Music"         },
   { TYPE_ENTER_MENU,   execSetupArtwork,       "Custom Artwork"        },
+#if !defined(PLATFORM_ANDROID)
   { TYPE_ENTER_MENU,   execSetupInput,         "Input Devices"         },
+  { TYPE_ENTER_MENU,   execSetupTouch,         "Touch Controls"        },
+#else
+  { TYPE_ENTER_MENU,   execSetupTouch,         "Touch Controls"        },
+#endif
   { TYPE_ENTER_MENU,   execSetupShortcuts,     "Key Shortcuts"         },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_LEAVE_MENU,   execExitSetup,          "Exit"                  },
@@ -5013,7 +5251,7 @@ static struct TokenInfo setup_info_graphics[] =
   { TYPE_SWITCH,       &setup.scroll_delay,    "Scroll Delay:"         },
 #endif
 #if 0
-  { TYPE_ENTER_LIST,   execSetupChooseScrollDelay, "Scroll Delay Value:" },
+  { TYPE_ENTER_LIST,   execSetupChooseScrollDelay, "Scroll Delay:"     },
   { TYPE_STRING,       &scroll_delay_text,     ""                      },
 #endif
 #if 0
@@ -5103,6 +5341,21 @@ static struct TokenInfo setup_info_input[] =
   { 0,                 NULL,                   NULL                    }
 };
 
+static struct TokenInfo setup_info_touch[] =
+{
+  { TYPE_ENTER_LIST,   execSetupChooseTouchControls, "Touch Control Type:" },
+  { TYPE_STRING,       &touch_controls_text,   ""                      },
+  { TYPE_EMPTY,                NULL,                   ""                      },
+  { TYPE_ENTER_LIST,   execSetupChooseMoveDistance, "Move Trigger Distance:" },
+  { TYPE_STRING,       &move_distance_text,    ""                      },
+  { TYPE_ENTER_LIST,   execSetupChooseDropDistance, "Drop Trigger Distance:" },
+  { TYPE_STRING,       &drop_distance_text,    ""                      },
+  { TYPE_EMPTY,                NULL,                   ""                      },
+  { TYPE_LEAVE_MENU,   execSetupMain,          "Back"                  },
+
+  { 0,                 NULL,                   NULL                    }
+};
+
 static struct TokenInfo setup_info_shortcuts[] =
 {
   { TYPE_ENTER_MENU,   execSetupShortcuts1,    "Various Keys"          },
@@ -5286,7 +5539,7 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
   struct TokenInfo *si = &setup_info[si_pos];
   boolean font_draw_xoffset_modified = FALSE;
   int font_draw_xoffset_old = -1;
-  int xoffset = (num_setup_info < max_setup_info ? -1 * 1 : 0);
+  int xoffset = (num_setup_info < max_setup_info ? -1 : 0);
   int menu_screen_value_xpos = MENU_SCREEN_VALUE_XPOS + xoffset;
   int menu_screen_max_xpos = MENU_SCREEN_MAX_XPOS + xoffset;
   int xpos = menu_screen_value_xpos;
@@ -5336,8 +5589,13 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw)
   font_height = getFontHeight(font_nr);
 #endif
 
+#if 0
+  if (menu_screen_value_xpos < 1 + MAX_MENU_TEXT_LENGTH_BIG)
+    font_nr = ...;
+#endif
+
   /* downward compatibility correction for Juergen Bonhagen's menu settings */
-  if (1 && setup_mode != SETUP_MODE_INPUT)
+  if (setup_mode != SETUP_MODE_INPUT)
   {
     int max_menu_text_length_big = (menu_screen_value_xpos -
                                    MENU_SCREEN_START_XPOS);
@@ -5723,6 +5981,11 @@ static void DrawSetupScreen_Generic()
     setup_info = setup_info_artwork;
     title_string = "Custom Artwork";
   }
+  else if (setup_mode == SETUP_MODE_TOUCH)
+  {
+    setup_info = setup_info_touch;
+    title_string = "Setup Touch Ctrls";
+  }
   else if (setup_mode == SETUP_MODE_SHORTCUTS)
   {
     setup_info = setup_info_shortcuts;
@@ -5878,10 +6141,20 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
 
 #if 1
     if (choice < first_entry)
+    {
       choice = first_entry;
+
+      if (setup_info[choice].type & TYPE_SKIP_ENTRY)
+       choice++;
+    }
     else if (choice > first_entry + num_page_entries - 1)
+    {
       choice = first_entry + num_page_entries - 1;
 
+      if (setup_info[choice].type & TYPE_SKIP_ENTRY)
+       choice--;
+    }
+
     choice_store[setup_mode] = choice;
 
     DrawCursorAndText_Setup(choice - first_entry, choice, TRUE);
@@ -5966,13 +6239,34 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
       {
        choice += first_entry - first_entry_store[setup_mode];
 
-       first_entry_store[setup_mode] = first_entry;
-
        if (choice < first_entry)
+       {
          choice = first_entry;
+
+         if (setup_info[choice].type & TYPE_SKIP_ENTRY)
+           choice++;
+       }
        else if (choice > first_entry + num_page_entries - 1)
+       {
          choice = first_entry + num_page_entries - 1;
 
+         if (setup_info[choice].type & TYPE_SKIP_ENTRY)
+           choice--;
+       }
+#if 1
+       else if (setup_info[choice].type & TYPE_SKIP_ENTRY)
+       {
+         choice += SIGN(dy);
+
+         if (choice < first_entry ||
+             choice > first_entry + num_page_entries - 1)
+         first_entry += SIGN(dy);
+       }
+#endif
+
+       // printf("::: MARK 1: %d\n", first_entry);
+
+       first_entry_store[setup_mode] = first_entry;
        choice_store[setup_mode] = choice;
 
        drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN);
@@ -6004,13 +6298,28 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button)
 #endif
 
     /* jump to next non-empty menu entry (up or down) */
+#if 1
+    while (first_entry + y > 0 &&
+          first_entry + y < max_setup_info - 1 &&
+          setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
+      y += dy;
+#else
     while (y > 0 && y < num_setup_info - 1 &&
           setup_info[first_entry + y].type & TYPE_SKIP_ENTRY)
       y += dy;
+#endif
 
     if (!IN_VIS_FIELD(x, y))
     {
+      choice += y - y_old;
+#if 1
+      if (choice < first_entry)
+       first_entry = choice;
+      else if (choice > first_entry + num_page_entries - 1)
+       first_entry = choice - num_page_entries + 1;
+#else
       first_entry += y - y_old;
+#endif
 
       if (first_entry >= 0 &&
          first_entry + num_page_entries <= max_setup_info)
@@ -6840,6 +7149,12 @@ void DrawSetupScreen()
     DrawChooseTree(&volume_loops_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
     DrawChooseTree(&volume_music_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
+    DrawChooseTree(&touch_control_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
+    DrawChooseTree(&move_distance_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+    DrawChooseTree(&drop_distance_current);
   else
     DrawSetupScreen_Generic();
 
@@ -6890,6 +7205,12 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
     HandleChooseTree(mx, my, dx, dy, button, &volume_loops_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
     HandleChooseTree(mx, my, dx, dy, button, &volume_music_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL)
+    HandleChooseTree(mx, my, dx, dy, button, &touch_control_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE)
+    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
     HandleSetupScreen_Generic(mx, my, dx, dy, button);