Last-minute GUI fixes to make music cross-fade when switching between tracks. Also made it switch back to the main theme on End Game.
This was SVN commit r1396.
This commit is contained in:
parent
caff02e8da
commit
314689a0bf
@ -15,12 +15,6 @@
|
||||
// Play main 0 A.D. theme when the main menu starts.
|
||||
curr_music = newRandomSound("music", "theme");
|
||||
curr_music.loop();
|
||||
// curr_session_playlist_1 = newRandomSound("music", "peace");
|
||||
// curr_session_playlist_1.play();
|
||||
// curr_session_playlist_1.free();
|
||||
// curr_session_playlist_2 = newRandomSound("music", "peace");
|
||||
// curr_session_playlist_2.play();
|
||||
// curr_session_playlist_2.free();
|
||||
]]></action>
|
||||
|
||||
<object type="image" name="pregame-mainmenu-background-image" sprite="pregame-mainmenu-background" size="0 0 100% 100%" z="100" hidden="false" />
|
||||
@ -32,9 +26,10 @@
|
||||
GUIObjectUnhide("End_Game_Button");
|
||||
GUIObjectHide("pregame_gui");
|
||||
FlipGUI(GUIType);
|
||||
curr_music.free(); // Close main theme when starting game session.
|
||||
// Select session peace track.
|
||||
curr_session_playlist_1 = newRandomSound("music", "peace");
|
||||
curr_session_playlist_1.play();
|
||||
// Fade out main theme and fade in session theme.
|
||||
CrossFade(curr_music, curr_session_playlist_1, 0.0001);
|
||||
]]></action>
|
||||
<action on="MouseEnter"><![CDATA[
|
||||
tooltipObject = getGUIObjectByName("pregame-mainmenu-tooltip");
|
||||
|
@ -18,7 +18,7 @@
|
||||
<object type="button" name="exit_button" sprite="exit_sprite" sprite-over="exit_sprite-over" size="100%-18 2 100%-2 18" z="1000" hidden="false">
|
||||
<action on="Press"><![CDATA[
|
||||
btCaptions = new Array("Yes, let me out!", "Nooooo!");
|
||||
btCode = new Array("curr_music.free();\nexit();", "");
|
||||
btCode = new Array("exit();", "");
|
||||
messageBox(400, 200, "Do you really want to quit [icon=0ad_icon] A.D.? This will cause a sudden return to reality.", "Confirmation", 0, btCaptions, btCode);
|
||||
]]></action>
|
||||
|
||||
@ -39,9 +39,9 @@
|
||||
|
||||
<object type="button" name="End_Game_Button" sprite="message_box-button-normal" sprite-over="message_box-button-over" hotkey="endgame" text-align="center" text-valign="center" size="100%-200 2 100%-100 36" z="105" hidden="true">
|
||||
<action on="Press"><![CDATA[
|
||||
btCaptions = new Array("Yepp, work's done!", "No, more slaughter!");
|
||||
btCaptions = new Array("Yep, work's done!", "No, more slaughter!");
|
||||
//btCode = new Array("endGame();", "GUIObjectHide('mb_main');");
|
||||
btCode = new Array("endGame();\nGUIObjectHide('session_gui');\nGUIObjectUnhide('pregame_gui');\nGUIObjectHide('End_Game_Button');", "");
|
||||
btCode = new Array("endGame();\ncurr_music = newRandomSound('music', 'theme');\nCrossFade(curr_session_playlist_1, curr_music, 0.0001);\nGUIObjectHide('session_gui');\nGUIObjectUnhide('pregame_gui');\nGUIObjectHide('End_Game_Button');", "");
|
||||
messageBox(600, 200, "Do you want to leave the current game? There might be more dudes to slaughter.", "Confirmation", 0, btCaptions, btCode);
|
||||
]]></action>
|
||||
End Game
|
||||
|
@ -13,8 +13,15 @@
|
||||
// Close "s" and free it from memory (use in conjunction with loop()):
|
||||
// s.free();
|
||||
|
||||
// Adjust the gain (volume) of a sound (floating point range between 0 (silent) and 1 (max volume)).
|
||||
// s.SetGain(value);
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function newRandomSound(soundType, soundSubType, soundPrePath)
|
||||
{
|
||||
// Return a random audio file by category, to be assigned to a handle.
|
||||
|
||||
switch (soundType)
|
||||
{
|
||||
case "music":
|
||||
@ -229,4 +236,49 @@ function newRandomSound(soundType, soundSubType, soundPrePath)
|
||||
console.write("Playing " + randomSoundPath + " ...");
|
||||
|
||||
return new Sound(randomSoundPath);
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function FadeOut (soundHandle, Rate)
|
||||
{
|
||||
// Adjust the gain of a sound until it is zero.
|
||||
|
||||
for (fadeLoop = 1; fadeLoop > 0; fadeLoop = fadeLoop - Rate)
|
||||
{
|
||||
soundHandle.setGain(fadeLoop);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function FadeIn (soundHandle, Gain, Rate)
|
||||
{
|
||||
// Adjust the gain of a sound from zero up to the given value.
|
||||
|
||||
for (fadeLoop = 0; fadeLoop < Gain; fadeLoop = fadeLoop + Rate)
|
||||
{
|
||||
soundHandle.setGain(fadeLoop);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
function CrossFade (outHandle, inHandle, Rate)
|
||||
{
|
||||
// Accepts two sound handles. Fades out the first and fades in the second at the specified rate.
|
||||
// Note that it plays the in and frees the out while it's at it.
|
||||
|
||||
FadeOut(outHandle, Rate);
|
||||
inHandle.play();
|
||||
FadeIn(inHandle, 1, Rate);
|
||||
outHandle.free();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ====================================================================
|
Loading…
Reference in New Issue
Block a user