rocksndiamonds-3.3.1.1
[rocksndiamonds.git] / src / screens.c
index 37ccbe8e193e77c51880710bded1760114043ff5..8c38785210b777bfdcb744723d2b1faf4a1d25a4 100644 (file)
 #define SETUP_MODE_CHOOSE_GRAPHICS     18
 #define SETUP_MODE_CHOOSE_SOUNDS       19
 #define SETUP_MODE_CHOOSE_MUSIC                20
+#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE        21
+#define SETUP_MODE_CHOOSE_VOLUME_LOOPS 22
+#define SETUP_MODE_CHOOSE_VOLUME_MUSIC 23
 
-#define MAX_SETUP_MODES                        21
+#define MAX_SETUP_MODES                        24
 
 /* for input setup functions */
 #define SETUPINPUT_SCREEN_POS_START    0
@@ -138,6 +141,7 @@ static void CustomizeKeyboard(int);
 static void CalibrateJoystick(int);
 static void execSetupGame(void);
 static void execSetupGraphics(void);
+static void execSetupSound(void);
 static void execSetupArtwork(void);
 static void HandleChooseTree(int, int, int, int, int, TreeInfo **);
 
@@ -176,6 +180,15 @@ static TreeInfo *scroll_delay_current = NULL;
 static TreeInfo *game_speeds = NULL;
 static TreeInfo *game_speed_current = NULL;
 
+static TreeInfo *volumes_simple = NULL;
+static TreeInfo *volume_simple_current = NULL;
+
+static TreeInfo *volumes_loops = NULL;
+static TreeInfo *volume_loops_current = NULL;
+
+static TreeInfo *volumes_music = NULL;
+static TreeInfo *volume_music_current = NULL;
+
 static TreeInfo *level_number = NULL;
 static TreeInfo *level_number_current = NULL;
 
@@ -229,6 +242,27 @@ static struct
   {    -1,     NULL                            },
 };
 
+static struct
+{
+  int value;
+  char *text;
+} volumes_list[] =
+{
+  {    0,      "0 %"                           },
+  {    10,     "10 %"                          },
+  {    20,     "20 %"                          },
+  {    30,     "30 %"                          },
+  {    40,     "40 %"                          },
+  {    50,     "50 %"                          },
+  {    60,     "60 %"                          },
+  {    70,     "70 %"                          },
+  {    80,     "80 %"                          },
+  {    90,     "90 %"                          },
+  {    100,    "100 %"                         },
+
+  {    -1,     NULL                            },
+};
+
 #define DRAW_MODE(s)           ((s) >= GAME_MODE_MAIN &&               \
                                 (s) <= GAME_MODE_SETUP ? (s) :         \
                                 (s) == GAME_MODE_PSEUDO_TYPENAME ?     \
@@ -1448,7 +1482,7 @@ static void gotoTopLevelDir()
 
 void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 {
-  static unsigned long title_delay = 0;
+  static unsigned int title_delay = 0;
   static int title_screen_nr = 0;
   static int last_sound = -1, last_music = -1;
   boolean return_to_main_menu = FALSE;
@@ -2335,7 +2369,7 @@ void DrawInfoScreen_Elements()
 
 void HandleInfoScreen_Elements(int button)
 {
-  static unsigned long info_delay = 0;
+  static unsigned int info_delay = 0;
   static int num_anims;
   static int num_pages;
   static int page;
@@ -2849,6 +2883,18 @@ void DrawInfoScreen_Program()
                    "If you like it, send e-mail to:");
   DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3,
                    PROGRAM_EMAIL_STRING);
+#if 1
+  DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2,
+                   "More information and levels:");
+  DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3,
+                   PROGRAM_WEBSITE_STRING);
+  DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2,
+                   "If you have created new levels,");
+  DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_2,
+                   "send them to me to include them!");
+  DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2,
+                   ":-)");
+#else
   DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2,
                    "or SnailMail to:");
   DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3,
@@ -2869,6 +2915,7 @@ void DrawInfoScreen_Program()
                    "send them to me to include them!");
   DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2,
                    ":-)");
+#endif
 
   DrawTextSCentered(ybottom, FONT_TEXT_4,
                    "Press any key or button for info menu");
@@ -3525,6 +3572,10 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
       else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
               setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
        execSetupGraphics();
+      else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
+              setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
+              setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
+       execSetupSound();
       else
        execSetupArtwork();
     }
@@ -3711,6 +3762,10 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
          else if (setup_mode == SETUP_MODE_CHOOSE_SCREEN_MODE ||
                   setup_mode == SETUP_MODE_CHOOSE_SCROLL_DELAY)
            execSetupGraphics();
+         else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE ||
+                  setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS ||
+                  setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
+           execSetupSound();
          else
            execSetupArtwork();
        }
@@ -3767,9 +3822,13 @@ void DrawChooseLevelNr()
 
     ti->node_top = &level_number;
     ti->sort_priority = 10000 + value;
+    ti->color = (level.no_valid_file ? FC_BLUE :
+                LevelStats_getSolved(i) ? FC_GREEN :
+                LevelStats_getPlayed(i) ? FC_YELLOW : FC_RED);
 
     sprintf(identifier, "%d", value);
-    sprintf(name, "%03d: %s", value, level.name);
+    sprintf(name, "%03d: %s", value,
+           (level.no_valid_file ? "(no file)" : level.name));
 
     setString(&ti->identifier, identifier);
     setString(&ti->name, name);
@@ -3972,6 +4031,9 @@ static char *game_speed_text;
 static char *graphics_set_name;
 static char *sounds_set_name;
 static char *music_set_name;
+static char *volume_simple_text;
+static char *volume_loops_text;
+static char *volume_music_text;
 
 static void execSetupMain()
 {
@@ -4156,6 +4218,7 @@ static void execSetupGraphics()
 #endif
 
   setup_mode = SETUP_MODE_GRAPHICS;
+
   DrawSetupScreen();
 }
 
@@ -4176,8 +4239,166 @@ static void execSetupChooseScrollDelay()
   DrawSetupScreen();
 }
 
+static void execSetupChooseVolumeSimple()
+{
+  setup_mode = SETUP_MODE_CHOOSE_VOLUME_SIMPLE;
+
+  DrawSetupScreen();
+}
+
+static void execSetupChooseVolumeLoops()
+{
+  setup_mode = SETUP_MODE_CHOOSE_VOLUME_LOOPS;
+
+  DrawSetupScreen();
+}
+
+static void execSetupChooseVolumeMusic()
+{
+  setup_mode = SETUP_MODE_CHOOSE_VOLUME_MUSIC;
+
+  DrawSetupScreen();
+}
+
 static void execSetupSound()
 {
+#if 1
+  if (volumes_simple == NULL)
+  {
+    int i;
+
+    for (i = 0; volumes_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = volumes_list[i].value;
+      char *text = volumes_list[i].text;
+
+      ti->node_top = &volumes_simple;
+      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, "Sound Volume");
+
+      pushTreeInfo(&volumes_simple, ti);
+    }
+
+    /* sort volume values to start with lowest volume value */
+    sortTreeInfo(&volumes_simple);
+
+    /* set current volume value to configured volume value */
+    volume_simple_current =
+      getTreeInfoFromIdentifier(volumes_simple,i_to_a(setup.volume_simple));
+
+    /* if that fails, set current volume to reliable default value */
+    if (volume_simple_current == NULL)
+      volume_simple_current =
+       getTreeInfoFromIdentifier(volumes_simple, i_to_a(100));
+
+    /* if that also fails, set current volume to first available value */
+    if (volume_simple_current == NULL)
+      volume_simple_current = volumes_simple;
+  }
+
+  if (volumes_loops == NULL)
+  {
+    int i;
+
+    for (i = 0; volumes_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = volumes_list[i].value;
+      char *text = volumes_list[i].text;
+
+      ti->node_top = &volumes_loops;
+      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, "Loops Volume");
+
+      pushTreeInfo(&volumes_loops, ti);
+    }
+
+    /* sort volume values to start with lowest volume value */
+    sortTreeInfo(&volumes_loops);
+
+    /* set current volume value to configured volume value */
+    volume_loops_current =
+      getTreeInfoFromIdentifier(volumes_loops,i_to_a(setup.volume_loops));
+
+    /* if that fails, set current volume to reliable default value */
+    if (volume_loops_current == NULL)
+      volume_loops_current =
+       getTreeInfoFromIdentifier(volumes_loops, i_to_a(100));
+
+    /* if that also fails, set current volume to first available value */
+    if (volume_loops_current == NULL)
+      volume_loops_current = volumes_loops;
+  }
+
+  if (volumes_music == NULL)
+  {
+    int i;
+
+    for (i = 0; volumes_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = volumes_list[i].value;
+      char *text = volumes_list[i].text;
+
+      ti->node_top = &volumes_music;
+      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, "Music Volume");
+
+      pushTreeInfo(&volumes_music, ti);
+    }
+
+    /* sort volume values to start with lowest volume value */
+    sortTreeInfo(&volumes_music);
+
+    /* set current volume value to configured volume value */
+    volume_music_current =
+      getTreeInfoFromIdentifier(volumes_music,i_to_a(setup.volume_music));
+
+    /* if that fails, set current volume to reliable default value */
+    if (volume_music_current == NULL)
+      volume_music_current =
+       getTreeInfoFromIdentifier(volumes_music, i_to_a(100));
+
+    /* if that also fails, set current volume to first available value */
+    if (volume_music_current == NULL)
+      volume_music_current = volumes_music;
+  }
+
+  setup.volume_simple = atoi(volume_simple_current->identifier);
+  setup.volume_loops  = atoi(volume_loops_current->identifier);
+  setup.volume_music  = atoi(volume_music_current->identifier);
+
+  /* needed for displaying volume text instead of identifier */
+  volume_simple_text = volume_simple_current->name;
+  volume_loops_text = volume_loops_current->name;
+  volume_music_text = volume_music_current->name;
+#endif
+
   setup_mode = SETUP_MODE_SOUND;
 
   DrawSetupScreen();
@@ -4390,6 +4611,13 @@ static struct TokenInfo setup_info_sound[] =
   { TYPE_SWITCH,       &setup.sound_loops,     "Sound Effects (Looping):" },
   { TYPE_SWITCH,       &setup.sound_music,     "Music:"                },
   { TYPE_EMPTY,                NULL,                   ""                      },
+  { TYPE_ENTER_LIST,   execSetupChooseVolumeSimple, "Sound Volume (Normal):" },
+  { TYPE_STRING,       &volume_simple_text,    ""                      },
+  { TYPE_ENTER_LIST,   execSetupChooseVolumeLoops, "Sound Volume (Looping):" },
+  { TYPE_STRING,       &volume_loops_text,     ""                      },
+  { TYPE_ENTER_LIST,   execSetupChooseVolumeMusic, "Music Volume:"     },
+  { TYPE_STRING,       &volume_music_text,     ""                      },
+  { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_LEAVE_MENU,   execSetupMain,          "Back"                  },
 
   { 0,                 NULL,                   NULL                    }
@@ -4631,7 +4859,10 @@ static void drawSetupValue(int pos)
   int ypos = MENU_SCREEN_START_YPOS + pos;
   int startx = mSX + xpos * 32;
   int starty = mSY + ypos * 32;
-  int font_nr, font_width, font_height;
+  int font_nr, font_width;
+#if 0
+  int font_height;
+#endif
   int type = setup_info[pos].type;
   void *value = setup_info[pos].value;
   char *value_string = getSetupValue(type, value);
@@ -4667,7 +4898,9 @@ static void drawSetupValue(int pos)
   starty = mSY + ypos * 32;
   font_nr = getSetupValueFont(type, value);
   font_width = getFontWidth(font_nr);
+#if 0
   font_height = getFontHeight(font_nr);
+#endif
 
   /* downward compatibility correction for Juergen Bonhagen's menu settings */
   if (setup_mode != SETUP_MODE_INPUT)
@@ -5714,6 +5947,12 @@ void DrawSetupScreen()
     DrawChooseTree(&artwork.snd_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
     DrawChooseTree(&artwork.mus_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
+    DrawChooseTree(&volume_simple_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
+    DrawChooseTree(&volume_loops_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_MUSIC)
+    DrawChooseTree(&volume_music_current);
   else
     DrawSetupScreen_Generic();
 
@@ -5743,6 +5982,12 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
     HandleChooseTree(mx, my, dx, dy, button, &artwork.snd_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_MUSIC)
     HandleChooseTree(mx, my, dx, dy, button, &artwork.mus_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_SIMPLE)
+    HandleChooseTree(mx, my, dx, dy, button, &volume_simple_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_VOLUME_LOOPS)
+    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
     HandleSetupScreen_Generic(mx, my, dx, dy, button);
 
@@ -5909,7 +6154,7 @@ static struct
 static void CreateScreenMenubuttons()
 {
   struct GadgetInfo *gi;
-  unsigned long event_mask;
+  unsigned int event_mask;
   int i;
 
   for (i = 0; i < NUM_SCREEN_MENUBUTTONS; i++)
@@ -5962,7 +6207,7 @@ static void CreateScreenMenubuttons()
 static void CreateScreenScrollbuttons()
 {
   struct GadgetInfo *gi;
-  unsigned long event_mask;
+  unsigned int event_mask;
   int i;
 
   /* these values are not constant, but can change at runtime */
@@ -6042,7 +6287,7 @@ static void CreateScreenScrollbars()
     int gd_x1, gd_x2, gd_y1, gd_y2;
     struct GadgetInfo *gi;
     int items_max, items_visible, item_position;
-    unsigned long event_mask;
+    unsigned int event_mask;
     int num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
     int id = scrollbar_info[i].gadget_id;