fixed playfield graphics for BD runtime elements in level editor
[rocksndiamonds.git] / src / tools.c
index 39976f9d9522949cc221b0234f69950c968b4e08..ac3d31bf9405b406391c255b3f5f9cf8ffbcfc91 100644 (file)
@@ -2818,12 +2818,14 @@ static void DrawSizedElementExt(int x, int y, int element, int tilesize,
   }
   else
   {
-    int graphic = el2edimg(element);
+    int graphic, frame;
+
+    el2edimg_with_frame(element, &graphic, &frame);
 
     if (masked)
-      DrawSizedGraphicThruMask(x, y, graphic, 0, tilesize);
+      DrawSizedGraphicThruMask(x, y, graphic, frame, tilesize);
     else
-      DrawSizedGraphic(x, y, graphic, 0, tilesize);
+      DrawSizedGraphic(x, y, graphic, frame, tilesize);
   }
 }
 
@@ -10163,6 +10165,31 @@ int el2edimg(int element)
   return element_info[element].special_graphic[GFX_SPECIAL_ARG_EDITOR];
 }
 
+int el2edimg_with_frame(int element, int *graphic, int *frame)
+{
+  element = GFX_ELEMENT(element);
+
+  *graphic = element_info[element].special_graphic[GFX_SPECIAL_ARG_EDITOR];
+  *frame = 0;
+
+  if (*graphic == IMG_UNKNOWN)
+  {
+    // no graphic defined -- if BD style, try to get runtime ("effect") element graphics
+    // (normal BD style elements have graphics, but runtime ("effects") elements do not)
+    int element_bd = map_element_RND_to_BD_cave(element);
+
+    if (element_bd != O_UNKNOWN)
+    {
+      struct GraphicInfo_BD *g_bd = &graphic_info_bd_object[element_bd][0];
+
+      *graphic = g_bd->graphic;
+      *frame   = g_bd->frame;
+    }
+  }
+
+  return *graphic;
+}
+
 int el2preimg(int element)
 {
   element = GFX_ELEMENT(element);
@@ -11431,6 +11458,27 @@ void PlaySoundSelecting(void)
 #endif
 }
 
+void ToggleAudioSampleRateIfNeeded(void)
+{
+  int setup_audio_sample_rate = (setup.audio_sample_rate_44100 ? 44100 : 22050);
+
+  // if setup and audio sample rate are already matching, nothing do do
+  if ((setup_audio_sample_rate == audio.sample_rate) ||
+      !audio.sound_available)
+    return;
+
+#if 1
+  // apparently changing the audio output sample rate does not work at runtime,
+  // so currently the program has to be restarted to apply the new sample rate
+  Request("Please restart the program to change audio sample rate!", REQ_CONFIRM);
+#else
+  SDLReopenAudio();
+
+  // set setup value according to successfully changed audio sample rate
+  setup.audio_sample_rate_44100 = (audio.sample_rate == 44100);
+#endif
+}
+
 void ToggleFullscreenIfNeeded(void)
 {
   // if setup and video fullscreen state are already matching, nothing do do