rnd-20031122-1-src
[rocksndiamonds.git] / src / screens.c
index 8e66c8c9ed7831cc55f2c2b163dab62f8d2a1812..328f6893317dc40b33d415870aa333ac140633d5 100644 (file)
@@ -139,20 +139,40 @@ static void drawChooseTreeCursor(int ypos, int color)
   game_status = last_game_status;      /* restore current game status */
 }
 
-static void PlaySound_Menu_Start(int sound)
+static void PlayMenuSound()
 {
+  int sound = menu.sound[game_status];
+
+  if (sound == SND_UNDEFINED)
+    return;
+
   if (sound_info[sound].loop)
     PlaySoundLoop(sound);
   else
     PlaySound(sound);
 }
 
-static void PlaySound_Menu_Continue(int sound)
+static void PlayMenuSoundIfLoop()
 {
+  int sound = menu.sound[game_status];
+
+  if (sound == SND_UNDEFINED)
+    return;
+
   if (sound_info[sound].loop)
     PlaySoundLoop(sound);
 }
 
+static void PlayMenuMusic()
+{
+  int music = menu.music[game_status];
+
+  if (music == MUS_UNDEFINED)
+    return;
+
+  PlayMusic(music);
+}
+
 void DrawHeadline()
 {
   int text1_width = getTextWidth(PROGRAM_TITLE_STRING,     FONT_TITLE_1);
@@ -197,7 +217,7 @@ void DrawMainMenu()
   int i;
 
   UnmapAllGadgets();
-  FadeSounds();
+  FadeSoundsAndMusic();
 
   KeyboardAutoRepeatOn();
   ActivateJoystick();
@@ -294,6 +314,9 @@ void DrawMainMenu()
     LoadTape(level_nr);
   DrawCompleteVideoDisplay();
 
+  PlayMenuSound();
+  PlayMenuMusic();
+
   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
 
 #if 0
@@ -493,6 +516,7 @@ static long helpscreen_state;
 static int helpscreen_step[MAX_HELPSCREEN_ELS];
 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
 
+#if 0
 static int helpscreen_action[] =
 {
   IMG_PLAYER_1_MOVING_DOWN,            16,
@@ -702,6 +726,8 @@ static int helpscreen_action[] =
 
   HA_END
 };
+#endif
+
 static char *helpscreen_eltext[][2] =
 {
  {"THE HERO:",                         "(Is _this_ guy good old Rockford?)"},
@@ -769,6 +795,7 @@ static char *helpscreen_eltext[][2] =
 };
 static int num_helpscreen_els = sizeof(helpscreen_eltext) / (2*sizeof(char *));
 
+#if 0
 static char *helpscreen_music[][3] =
 {
   { "Alchemy",                 "Ian Boddy",            "Drive" },
@@ -779,73 +806,98 @@ static char *helpscreen_music[][3] =
   { "Voyager",                 "The Alan Parsons Project","Pyramid" },
   { "Twilight Painter",                "Tangerine Dream",      "Heartbreakers" }
 };
+#endif
+
 static int num_helpscreen_music = 7;
 static int helpscreen_musicpos;
 
-#if 0
-void OLD_DrawHelpScreenElAction(int start)
+#if 1
+void DrawHelpScreenElAction(int start)
 {
   int i = 0, j = 0;
-  int frame, graphic;
-  int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
+  int xstart = mSX + 16;
+  int ystart = mSY + 64 + 2 * 32;
+  int ystep = TILEY + 4;
+  int element, action, direction;
+  int graphic;
+  int delay;
+  int sync_frame;
 
-  while(helpscreen_action[j] != HA_END)
+  while (info_animation_info[j].element != -999)
   {
-    if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
+    if (i >= start + MAX_HELPSCREEN_ELS || i >= num_helpscreen_els)
       break;
-    else if (i<start || helpscreen_delay[i-start])
+    else if (i < start)
     {
-      if (i>=start && helpscreen_delay[i-start])
-       helpscreen_delay[i-start]--;
-
-      while(helpscreen_action[j] != HA_NEXT)
+      while (info_animation_info[j].element != -1)
        j++;
+
       j++;
       i++;
+
       continue;
     }
 
-    j += 3*helpscreen_step[i-start];
-    graphic = helpscreen_action[j++];
+    j += helpscreen_step[i - start];
+
+    element = info_animation_info[j].element;
+    action = info_animation_info[j].action;
+    direction = info_animation_info[j].direction;
+
+    if (action != -1 && direction != -1)
+      graphic = el_act_dir2img(element, action, direction);
+    else if (action != -1)
+      graphic = el_act2img(element, action);
+    else if (direction != -1)
+      graphic = el_act2img(element, direction);
+    else
+      graphic = el2img(element);
+
+    delay = info_animation_info[j++].delay;
+
+    if (delay == -1)
+      delay = 1000000;
 
-    if (helpscreen_frame[i-start])
+    if (helpscreen_frame[i - start] == 0)
     {
-      frame = helpscreen_action[j++] - helpscreen_frame[i-start];
-      helpscreen_frame[i-start]--;
+      sync_frame = 0;
+      helpscreen_frame[i - start] = delay - 1;
     }
     else
     {
-      frame = 0;
-      helpscreen_frame[i-start] = helpscreen_action[j++]-1;
+      sync_frame = delay - helpscreen_frame[i - start];
+      helpscreen_frame[i - start]--;
     }
 
-    helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
-
-    if (helpscreen_action[j] == HA_NEXT)
+    if (info_animation_info[j].element == -1)
     {
-      if (!helpscreen_frame[i-start])
-       helpscreen_step[i-start] = 0;
+      if (!helpscreen_frame[i - start])
+       helpscreen_step[i - start] = 0;
     }
     else
     {
-      if (!helpscreen_frame[i-start])
-       helpscreen_step[i-start]++;
-      while(helpscreen_action[j] != HA_NEXT)
+      if (!helpscreen_frame[i - start])
+       helpscreen_step[i - start]++;
+      while(info_animation_info[j].element != -1)
        j++;
     }
+
     j++;
 
-    DrawOldGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame);
+    ClearRectangleOnBackground(drawto, xstart, ystart + (i - start) * ystep,
+                              TILEX, TILEY);
+    DrawGraphicAnimationExt(drawto, xstart, ystart + (i - start) * ystep,
+                           graphic, sync_frame, USE_MASKING);
+
     i++;
   }
 
-  for(i=2;i<16;i++)
-  {
-    MarkTileDirty(0,i);
-    MarkTileDirty(1,i);
-  }
+  redraw_mask |= REDRAW_FIELD;
+
+  FrameCounter++;
 }
-#endif
+
+#else
 
 void DrawHelpScreenElAction(int start)
 {
@@ -930,6 +982,7 @@ void DrawHelpScreenElAction(int start)
 
   FrameCounter++;
 }
+#endif
 
 void DrawHelpScreenElText(int start)
 {
@@ -958,15 +1011,28 @@ void DrawHelpScreenElText(int start)
 
 void DrawHelpScreenMusicText(int num)
 {
+  struct MusicFileInfo *list = music_file_info;
   int ystart = 150, ystep = 30;
   int ybottom = SYSIZE - 20;
+  int i;
 
-  FadeSounds();
+  for (i=0; i < num && list; i++)
+    list = list->next;
+
+  FadeSoundsAndMusic();
   ClearWindow();
   DrawHeadline();
 
   DrawTextFCentered(100, FONT_TEXT_1, "The game background music loops:");
 
+#if 1
+  DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
+  DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3, "\"%s\"", list->title);
+  DrawTextFCentered(ystart + 2 * ystep, FONT_TEXT_2, "by");
+  DrawTextFCentered(ystart + 3 * ystep, FONT_TEXT_3, "%s", list->artist);
+  DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
+  DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3, "\"%s\"", list->album);
+#else
   DrawTextFCentered(ystart + 0 * ystep, FONT_TEXT_2, "Excerpt from");
   DrawTextFCentered(ystart + 1 * ystep, FONT_TEXT_3,
                    "\"%s\"", helpscreen_music[num][0]);
@@ -976,6 +1042,7 @@ void DrawHelpScreenMusicText(int num)
   DrawTextFCentered(ystart + 4 * ystep, FONT_TEXT_2, "from the album");
   DrawTextFCentered(ystart + 5 * ystep, FONT_TEXT_3,
                    "\"%s\"", helpscreen_music[num][2]);
+#endif
 
   DrawTextFCentered(ybottom, FONT_TEXT_4,
                    "Press any key or button for next page");
@@ -990,7 +1057,7 @@ void DrawHelpScreenCreditsText()
   int ystart = 150, ystep = 30;
   int ybottom = SYSIZE - 20;
 
-  FadeSounds();
+  FadeSoundsAndMusic();
   ClearWindow();
   DrawHeadline();
 
@@ -1047,6 +1114,7 @@ void DrawHelpScreenContactText()
 
 void DrawHelpScreen()
 {
+  struct MusicFileInfo *list;
   int i;
 
   UnmapAllGadgets();
@@ -1057,17 +1125,26 @@ void DrawHelpScreen()
   helpscreen_musicpos = 0;
   helpscreen_state = 0;
 
+  LoadInfoAnimations();
+  LoadMusicInfo();
+
+  num_helpscreen_els = 0;
+  for (i=0; info_animation_info[i].element != -999; i++)
+    if (info_animation_info[i].element == -1)
+      num_helpscreen_els++;
+
+  num_helpscreen_music = 0;
+  for (list = music_file_info; list != NULL; list = list->next)
+    num_helpscreen_music++;
+
   DrawHelpScreenElText(0);
   DrawHelpScreenElAction(0);
 
   FadeToFront();
   InitAnimation();
 
-#if 0
-  PlaySoundLoop(SND_BACKGROUND_INFO);
-#else
-  PlaySound_Menu_Start(SND_BACKGROUND_INFO);
-#endif
+  PlayMenuSound();
+  PlayMenuMusic();
 }
 
 void HandleHelpScreen(int button)
@@ -1110,7 +1187,7 @@ void HandleHelpScreen(int button)
     }
     else
     {
-      FadeSounds();
+      FadeSoundsAndMusic();
 
       game_status = GAME_MODE_MAIN;
       DrawMainMenu();
@@ -1124,14 +1201,7 @@ void HandleHelpScreen(int button)
        DrawHelpScreenElAction(helpscreen_state * MAX_HELPSCREEN_ELS);
     }
 
-    /* !!! workaround for playing "music" that is really a sound loop (and
-       must therefore periodically be reactivated with the current sound
-       engine !!! */
-#if 0
-    PlaySoundLoop(SND_BACKGROUND_INFO);
-#else
-    PlaySound_Menu_Continue(SND_BACKGROUND_INFO);
-#endif
+    PlayMenuSoundIfLoop();
   }
 
   DoAnimation();
@@ -1549,6 +1619,9 @@ void DrawChooseLevel()
   SetMainBackgroundImage(IMG_BACKGROUND_LEVELS);
 
   DrawChooseTree(&leveldir_current);
+
+  PlayMenuSound();
+  PlayMenuMusic();
 }
 
 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
@@ -1562,7 +1635,7 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
 void DrawHallOfFame(int highlight_position)
 {
   UnmapAllGadgets();
-  FadeSounds();
+  FadeSoundsAndMusic();
   CloseDoor(DOOR_CLOSE_2);
 
   if (highlight_position < 0) 
@@ -1573,11 +1646,8 @@ void DrawHallOfFame(int highlight_position)
 
   HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
 
-#if 0
-  PlaySound(SND_BACKGROUND_SCORES);
-#else
-  PlaySound_Menu_Start(SND_BACKGROUND_SCORES);
-#endif
+  PlayMenuSound();
+  PlayMenuMusic();
 }
 
 static void drawHallOfFameList(int first_entry, int highlight_position)
@@ -1662,10 +1732,8 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
     DrawMainMenu();
   }
 
-#if 1
   if (game_status == GAME_MODE_SCORES)
-    PlaySound_Menu_Continue(SND_BACKGROUND_SCORES);
-#endif
+    PlayMenuSoundIfLoop();
 
   DoAnimation();
   BackToFront();
@@ -1813,6 +1881,7 @@ static struct TokenInfo setup_info_editor[] =
   { TYPE_SWITCH,       &setup.editor.el_custom,        "Custom:"       },
   { TYPE_SWITCH,       &setup.editor.el_custom_more,   "More Custom:"  },
   { TYPE_SWITCH,       &setup.editor.el_headlines,     "Headlines:"    },
+  { TYPE_SWITCH,       &setup.editor.el_user_defined,  "User defined:" },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_LEAVE_MENU,   execSetupMain,          "Back"                  },
   { 0,                 NULL,                   NULL                    }
@@ -2766,6 +2835,9 @@ void DrawSetupScreen()
     DrawChooseTree(&artwork.mus_current);
   else
     DrawSetupScreen_Generic();
+
+  PlayMenuSound();
+  PlayMenuMusic();
 }
 
 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)