Add theme fallback music settings
authorWuzzy <Wuzzy2@mail.ru>
Wed, 07 Feb 2018 07:38:37 +0100
changeset 12920 4d3b52f1ba18
parent 12919 0de553fb7e89
child 12921 6fede49bc103
Add theme fallback music settings theme.cfg: * fallback-music * fallback-sd-music
ChangeLog.txt
hedgewars/uLandObjects.pas
hedgewars/uSound.pas
--- a/ChangeLog.txt	Wed Feb 07 05:36:32 2018 +0100
+++ b/ChangeLog.txt	Wed Feb 07 07:38:37 2018 +0100
@@ -14,6 +14,9 @@
  + Mission 3: Display number of turns left at timed parcours
  * Fix incorrect storytelling in mission descriptions
 
+Theme customization:
+ + Add fallback music with fallback-music and fallback-sd-music
+
 Lua API:
  + New call: WriteLnToChat(string): Add a line in the chat
  * Fix call: SetWeapon(amNothing) now unselects weapon
--- a/hedgewars/uLandObjects.pas	Wed Feb 07 05:36:32 2018 +0100
+++ b/hedgewars/uLandObjects.pas	Wed Feb 07 07:38:37 2018 +0100
@@ -672,6 +672,10 @@
         MusicFN:= Trim(s)
     else if key = 'sd-music' then
         SDMusicFN:= Trim(s)
+    else if key = 'fallback-music' then
+        FallbackMusicFN:= Trim(s)
+    else if key = 'fallback-sd-music' then
+        FallbackSDMusicFN:= Trim(s)
     else if key = 'clouds' then
         begin
         cCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div 4096;
--- a/hedgewars/uSound.pas	Wed Feb 07 05:36:32 2018 +0100
+++ b/hedgewars/uSound.pas	Wed Feb 07 07:38:37 2018 +0100
@@ -106,6 +106,8 @@
 
 var MusicFN: shortstring; // music file name
     SDMusicFN: shortstring; // SD music file name
+    FallbackMusicFN: shortstring; // fallback music file name
+    FallbackSDMusicFN: shortstring; // fallback SD music fille name
 
 var Volume: LongInt;
     SoundTimerTicks: Longword;
@@ -632,9 +634,35 @@
     else s:= '/Music/' + MusicFN;
     WriteToConsole(msgLoading + s + ' ');
 
+    // Load normal music
     Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
     SDLCheck(Mus <> nil, 'Mix_LoadMUS_RW', false);
-    WriteLnToConsole(msgOK);
+    if Mus <> nil then
+        WriteLnToConsole(msgOK);
+
+    // If normal music failed, try to get fallback music
+    if Mus = nil then
+       begin
+       WriteLnToConsole('Music not found. Trying fallback music.');
+       if SuddenDeath and (FallbackSDMusicFN <> '') then
+           s:= '/Music/' + FallbackSDMusicFN
+       else if (not SuddenDeath) and (FallbackMusicFN <> '') then
+           s:= '/Music/' + FallbackMusicFN
+       else
+           begin
+           WriteLnToConsole('No fallback music configured!');
+           s:= ''
+           end;
+
+       if (s <> '') then
+           begin
+           WriteLnToConsole(msgLoading + s + ' ');
+           Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
+           SDLCheck(Mus <> nil, 'Mix_LoadMUS_RW', false);
+           if Mus <> nil then
+               WriteLnToConsole(msgOK)
+           end;
+       end;
 
     SDLCheck(Mix_FadeInMusic(Mus, -1, 3000) <> -1, 'Mix_FadeInMusic', false)
 end;