diff --git a/binaries/data/mods/public/gui/common/functions_utility_music.js b/binaries/data/mods/public/gui/common/functions_utility_music.js index 5b76265041..97636b8c23 100644 --- a/binaries/data/mods/public/gui/common/functions_utility_music.js +++ b/binaries/data/mods/public/gui/common/functions_utility_music.js @@ -17,6 +17,8 @@ const MAIN_MENU = "main_menu"; const DEFEAT_CUE = "gen_loss_cue"; const DEFEAT_MUSIC = "gen_loss_track"; const VICTORY_MUSIC = "win_1"; +//const AMBIENT_SOUND = "audio/ambient/dayscape/day_temperate_gen_03.ogg"; +const BUTTON_SOUND = "audio/interface/ui/ui_button_longclick.ogg"; // ==================================================================== @@ -42,11 +44,15 @@ const VICTORY_MUSIC = "win_1"; function newRandomSound(soundType, soundSubType, soundPrePath) { // Return a random audio file by category, to be assigned to a handle. + var randomSoundPath; switch (soundType) { case "music": - var randomSoundPath = "audio/music/" + randomSoundPath = "audio/music/" + break; + case "ambient": + randomSoundPath = "audio/ambient/" + soundPrePath + "/"; break; case "effect": randomSoundPath = soundPrePath + "/"; @@ -161,12 +167,18 @@ function getRandomBattleTrack() function playMainMenuMusic() { - if (global.curr_music) + if (global.curr_music) switchMusic(MAIN_MENU, 0.0, true); else playMusic(MAIN_MENU, 0.0, true); } +function playButtonSound() +{ + var buttonSound = new Sound(BUTTON_SOUND); + buttonSound.play(); +} + function stopMainMenuMusic() { if (global.main_menu_music) @@ -192,6 +204,16 @@ function startSessionSounds(civMusic) playRandomCivMusic(); } +function startMusic() +{ + console.write(getRandomPeaceTrack()); + + + console.write(global.curr_music); + playRandomCivMusic(); + console.write(global.curr_music); +} + function playRandomCivMusic() { global.curr_music = new Sound(getRandomPeaceTrack()); @@ -204,7 +226,10 @@ function playRandomCivMusic() function playAmbientSounds() { - global.curr_ambient = new Sound("audio/ambient/dayscape/day_temperate_gen_03.ogg"); + // Seem to need the underscore at the end of "temperate" to avoid crash + // (Might be caused by trying to randomly load day_temperate.xml) + global.curr_ambient = newRandomSound("ambient", "temperate_", "dayscape"); + console.write(global.curr_ambient); if (global.curr_ambient) { global.curr_ambient.loop(); diff --git a/binaries/data/mods/public/gui/pregame/mainmenu.js b/binaries/data/mods/public/gui/pregame/mainmenu.js index 2c8b7ef820..29b56984de 100644 --- a/binaries/data/mods/public/gui/pregame/mainmenu.js +++ b/binaries/data/mods/public/gui/pregame/mainmenu.js @@ -8,8 +8,8 @@ function init() userReportEnabledText = getGUIObjectByName("userReportEnabledText").caption; - // initialize currentSubmenuType with placeholder to avoid null when switching - currentSubmenuType = "submenuSinglePlayer"; + // initialize currentSubmenuType with placeholder to avoid null when switching + currentSubmenuType = "submenuSinglePlayer"; } var t0 = new Date; @@ -82,11 +82,11 @@ function formatUserReportStatus(status) function onTick() { - // Animate backgrounds + // Animate backgrounds scrollBackgrounds(); - // Animate submenu - updateMenuPosition(); + // Animate submenu + updateMenuPosition(); if (Engine.IsUserReportEnabled()) { @@ -112,81 +112,77 @@ function onTick() // Slide menu function updateMenuPosition() { - var submenu = getGUIObjectByName("submenu"); + var submenu = getGUIObjectByName("submenu"); - if (submenu.hidden == false) - { - // The offset is the increment or number of units/pixels to move - // the menu. An offset of one is always accurate, but it is too - // slow. The offset must divide into the travel distance evenly - // in order for the menu to end up at the right spot. The travel - // distance is the max-initial. The travel distance in this - // example is 300-60 = 240. We choose an offset of 5 because it - // divides into 240 evenly and provided the speed we wanted. - var OFFSET = 10; + if (submenu.hidden == false) + { + // The offset is the increment or number of units/pixels to move + // the menu. An offset of one is always accurate, but it is too + // slow. The offset must divide into the travel distance evenly + // in order for the menu to end up at the right spot. The travel + // distance is the max-initial. The travel distance in this + // example is 300-60 = 240. We choose an offset of 5 because it + // divides into 240 evenly and provided the speed we wanted. + const OFFSET = 10; - if (submenu.size.left < getGUIObjectByName("mainMenu").size.right) - { - submenu.size = (submenu.size.left + OFFSET) + " " + submenu.size.top + " " + (submenu.size.right + OFFSET) + " " + submenu.size.bottom; - } - } + if (submenu.size.left < getGUIObjectByName("mainMenu").size.right) + { + submenu.size = (submenu.size.left + OFFSET) + " " + submenu.size.top + " " + (submenu.size.right + OFFSET) + " " + submenu.size.bottom; + } + } } // Opens the menu by revealing the screen which contains the menu function openMenu(newSubmenu, position, buttonHeight, numButtons) { - var menuSound = new newRandomSound("effect", "arrowfly_", "audio/attack/weapon"); - if (menuSound) - { - menuSound.play(0); - } + // switch to new submenu type + currentSubmenuType = newSubmenu; + getGUIObjectByName(currentSubmenuType).hidden = false; - // switch to new submenu type - currentSubmenuType = newSubmenu; - getGUIObjectByName(currentSubmenuType).hidden = false; + // set position of new submenu + var submenu = getGUIObjectByName("submenu"); + var top = position - MARGIN; + var bottom = position + ((buttonHeight + MARGIN) * numButtons); + submenu.size = submenu.size.left + " " + top + " " + submenu.size.right + " " + bottom; - // set position of new submenu - var submenu = getGUIObjectByName("submenu"); - var top = position - MARGIN; - var bottom = position + ((buttonHeight + MARGIN) * numButtons); - submenu.size = submenu.size.left + " " + top + " " + submenu.size.right + " " + bottom; + // Blend in right border of main menu into the left border of the submenu + blendSubmenuIntoMain(top, bottom); - // Blend in right border of main menu into the left border of the submenu - blendSubmenuIntoMain(top, bottom); + // Reveal submenu + getGUIObjectByName("submenu").hidden = false; - // Reveal submenu - getGUIObjectByName("submenu").hidden = false; - - // prepare to hide the submenu when the user clicks on the background - getGUIObjectByName("submenuScreen").hidden = false; + // prepare to hide the submenu when the user clicks on the background + getGUIObjectByName("submenuScreen").hidden = false; } // Closes the menu and resets position function closeMenu() { - // remove old submenu type - getGUIObjectByName(currentSubmenuType).hidden = true; + playButtonSound(); - // hide submenu and reset position - var submenu = getGUIObjectByName("submenu"); - submenu.hidden = true; - submenu.size = getGUIObjectByName("mainMenu").size; + // remove old submenu type + getGUIObjectByName(currentSubmenuType).hidden = true; - // reset main menu panel right border - getGUIObjectByName("MainMenuPanelRightBorderTop").size = "100%-2 0 100% 100%"; + // hide submenu and reset position + var submenu = getGUIObjectByName("submenu"); + submenu.hidden = true; + submenu.size = getGUIObjectByName("mainMenu").size; - // hide submenu screen - getGUIObjectByName("submenuScreen").hidden = false; + // reset main menu panel right border + getGUIObjectByName("MainMenuPanelRightBorderTop").size = "100%-2 0 100% 100%"; + + // hide submenu screen + getGUIObjectByName("submenuScreen").hidden = false; } // Sizes right border on main menu panel to match the submenu function blendSubmenuIntoMain(topPosition, bottomPosition) { - var topSprite = getGUIObjectByName("MainMenuPanelRightBorderTop"); - topSprite.size = "100%-2 0 100% " + (topPosition + MARGIN); + var topSprite = getGUIObjectByName("MainMenuPanelRightBorderTop"); + topSprite.size = "100%-2 0 100% " + (topPosition + MARGIN); - var bottomSprite = getGUIObjectByName("MainMenuPanelRightBorderBottom"); - bottomSprite.size = "100%-2 " + (bottomPosition) + " 100% 100%"; + var bottomSprite = getGUIObjectByName("MainMenuPanelRightBorderBottom"); + bottomSprite.size = "100%-2 " + (bottomPosition) + " 100% 100%"; } // Reveals submenu @@ -209,54 +205,54 @@ function closeMainMenuSubWindow (windowName) * FUNCTIONS BELOW DO NOT WORK YET */ -// Switch to a given options tab window. -function openOptionsTab(tabName) -{ - // Hide the other tabs. - for (i = 1; i <= 3; i++) - { - switch (i) - { - case 1: - var tmpName = "pgOptionsAudio"; - break; - case 2: - var tmpName = "pgOptionsVideo"; - break; - case 3: - var tmpName = "pgOptionsGame"; - break; - default: - break; - } - - if (tmpName != tabName) - { - getGUIObjectByName (tmpName + "Window").hidden = true; - getGUIObjectByName (tmpName + "Button").enabled = true; - } - } - - // Make given tab visible. - getGUIObjectByName (tabName + "Window").hidden = false; - getGUIObjectByName (tabName + "Button").enabled = false; -} - -// Move the credits up the screen. -function updateCredits() -{ - // If there are still credit lines to remove, remove them. - if (getNumItems("pgCredits") > 0) - removeItem ("pgCredits", 0); - else - { - // When we've run out of credit, - - // Stop the increment timer if it's still active. - cancelInterval(); - - // Close the credits screen and return. - closeMainMenuSubWindow ("pgCredits"); - guiUnHide ("pg"); - } -} +//// Switch to a given options tab window. +//function openOptionsTab(tabName) +//{ +// // Hide the other tabs. +// for (i = 1; i <= 3; i++) +// { +// switch (i) +// { +// case 1: +// var tmpName = "pgOptionsAudio"; +// break; +// case 2: +// var tmpName = "pgOptionsVideo"; +// break; +// case 3: +// var tmpName = "pgOptionsGame"; +// break; +// default: +// break; +// } +// +// if (tmpName != tabName) +// { +// getGUIObjectByName (tmpName + "Window").hidden = true; +// getGUIObjectByName (tmpName + "Button").enabled = true; +// } +// } +// +// // Make given tab visible. +// getGUIObjectByName (tabName + "Window").hidden = false; +// getGUIObjectByName (tabName + "Button").enabled = false; +//} +// +//// Move the credits up the screen. +//function updateCredits() +//{ +// // If there are still credit lines to remove, remove them. +// if (getNumItems("pgCredits") > 0) +// removeItem ("pgCredits", 0); +// else +// { +// // When we've run out of credit, +// +// // Stop the increment timer if it's still active. +// cancelInterval(); +// +// // Close the credits screen and return. +// closeMainMenuSubWindow ("pgCredits"); +// guiUnHide ("pg"); +// } +//} diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index 5fbfbc4560..b8c939574f 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -1094,22 +1094,8 @@ function performCommand(entity, commandName) { case "delete": var selection = g_Selection.toList(); - if (selection.length > 0) - { - closeMenu(); - closeOpenDialogs(); - - var deleteFunction = function () - { - Engine.PostNetworkCommand({"type": "delete-entities", "entities": selection}); - }; - - var btCaptions = ["Yes", "No"]; - var btCode = [deleteFunction, null]; - - messageBox(400, 200, "Destroy everything currently selected?", "Delete", 0, btCaptions, btCode); - } + openDeleteDialog(selection); break; case "garrison": inputState = INPUT_PRESELECTEDACTION; diff --git a/binaries/data/mods/public/gui/session/menu.js b/binaries/data/mods/public/gui/session/menu.js index 8ec9771731..2665e6aa81 100644 --- a/binaries/data/mods/public/gui/session/menu.js +++ b/binaries/data/mods/public/gui/session/menu.js @@ -1,3 +1,6 @@ +const PAUSE = "Pause"; +const RESUME = "Resume"; + /* * MENU POSITION CONSTANTS */ @@ -6,7 +9,7 @@ const MARGIN = 4; // Includes the main menu button -const NUM_BUTTONS = 6; +const NUM_BUTTONS = 5; // Regular menu buttons const BUTTON_HEIGHT = 32; @@ -14,74 +17,145 @@ const BUTTON_HEIGHT = 32; // The position where the bottom of the menu will end up (currently 164) const END_MENU_POSITION = (BUTTON_HEIGHT * NUM_BUTTONS) + MARGIN; -// Menu starting position - bottom +// Menu starting position: bottom const MENU_BOTTOM = 36; -// Menu starting position - top +// Menu starting position: top const MENU_TOP = MENU_BOTTOM - END_MENU_POSITION; -// Menu starting position - overall +// Menu starting position: overall const INITIAL_MENU_POSITION = "100%-164 " + MENU_TOP + " 100% " + MENU_BOTTOM; +// The offset is the increment or number of units/pixels to move +// the menu. An offset of one is always accurate, but it is too +// slow. The offset must divide into the travel distance evenly +// in order for the menu to end up at the right spot. The travel +// distance is the max-initial. The travel distance in this +// example is 164-36 = 128. We choose an offset of 16 because it +// divides into 128 evenly and provided the speed we wanted. +const OFFSET = 8; +var isMenuOpen = false; +var menu; + +// Ignore size defined in XML and set the actual menu size here +function initMenuPosition() +{ + menu = getGUIObjectByName("menu"); + menu.size = INITIAL_MENU_POSITION; +} + +// ============================================================================= +// Overall Menu +// ============================================================================= +// // Slide menu function updateMenuPosition() { - if (getGUIObjectByName("menu").hidden == false) - { - var menu = getGUIObjectByName("menu"); - - // The offset is the increment or number of units/pixels to move - // the menu. An offset of one is always accurate, but it is too - // slow. The offset must divide into the travel distance evenly - // in order for the menu to end up at the right spot. The travel - // distance is the max-initial. The travel distance in this - // example is 196-36 = 160. We choose an offset of 16 because it - // divides into 160 evenly and provided the speed we wanted. - var OFFSET = 16; - - if (menu.size.bottom < END_MENU_POSITION) - { - menu.size = "100%-164 " + (menu.size.top + OFFSET) + " 100% " + (menu.size.bottom + OFFSET); - } - } + if (isMenuOpen) + { + if (menu.size.bottom < END_MENU_POSITION) + { + menu.size = "100%-164 " + (menu.size.top + OFFSET) + " 100% " + (menu.size.bottom + OFFSET); + } + } + else + { + if (menu.size.top > MENU_TOP) + { + menu.size = "100%-164 " + (menu.size.top - OFFSET) + " 100% " + (menu.size.bottom - OFFSET); + } + } } // Opens the menu by revealing the screen which contains the menu function openMenu() { - var menuSound = new Sound("audio/interface/ui/ui_button_longclick.ogg"); - if (menuSound) - { - menuSound.play(0); - } - - getGUIObjectByName("menu").hidden = false; + playButtonSound(); + isMenuOpen = true; } // Closes the menu and resets position function closeMenu() { - getGUIObjectByName("menu").hidden = true; - getGUIObjectByName("menu").size = INITIAL_MENU_POSITION; + playButtonSound(); + isMenuOpen = false; } -function openSettings() +function toggleMenu() { - closeMenu(); - closeChat(); - getGUIObjectByName("settingsDialogPanel").hidden = false; + if (isMenuOpen == true) + closeMenu(); + else + openMenu(); } -function closeSettings() +// Menu buttons +// ============================================================================= +function settingsMenuButton() +{ + closeMenu(); + closeOpenDialogs(); + openSettings(true); +} + +function chatMenuButton() +{ + closeMenu(); + closeOpenDialogs(); + openChat(); +} + +function pauseMenuButton() +{ + togglePause(); +} + +function exitMenuButton() +{ + closeMenu(); + closeOpenDialogs(); + pauseGame(); + var btCaptions = ["Yes", "No"]; + var btCode = [leaveGame, resumeGame]; + messageBox(400, 200, "Are you sure you want to quit?", "Confirmation", 0, btCaptions, btCode); +} + +function openDeleteDialog(selection) +{ + closeMenu(); + closeOpenDialogs(); + + var deleteSelectedEntities = function () + { + Engine.PostNetworkCommand({"type": "delete-entities", "entities": selection}); + }; + + var btCaptions = ["Yes", "No"]; + var btCode = [deleteSelectedEntities, resumeGame]; + + messageBox(400, 200, "Destroy everything currently selected?", "Delete", 0, btCaptions, btCode); +} + +// Menu functions +// ============================================================================= + +function openSettings(pause) +{ + getGUIObjectByName("settingsDialogPanel").hidden = false; + if (pause) + pauseGame(); +} + +function closeSettings(resume) { getGUIObjectByName("settingsDialogPanel").hidden = true; + if (resume) + resumeGame(); } function openChat() { - closeMenu(); - closeSettings(); getGUIObjectByName("chatInput").focus(); // Grant focus to the input area getGUIObjectByName("chatDialogPanel").hidden = false; @@ -95,7 +169,7 @@ function closeChat() function toggleChatWindow() { - closeSettings(); + closeSettings(); var chatWindow = getGUIObjectByName("chatDialogPanel"); var chatInput = getGUIObjectByName("chatInput"); @@ -108,23 +182,37 @@ function toggleChatWindow() chatWindow.hidden = !chatWindow.hidden; } +function pauseGame() +{ + getGUIObjectByName("pauseButtonText").caption = RESUME; + getGUIObjectByName("pauseOverlay").hidden = false; + setPaused(true); +} + +function resumeGame() +{ + getGUIObjectByName("pauseButtonText").caption = PAUSE; + getGUIObjectByName("pauseOverlay").hidden = true; + setPaused(false); +} + function togglePause() { - closeMenu(); - closeChat(); - closeSettings(); + closeMenu(); + closeOpenDialogs(); var pauseOverlay = getGUIObjectByName("pauseOverlay"); if (pauseOverlay.hidden) { + getGUIObjectByName("pauseButtonText").caption = RESUME; setPaused(true); - getGUIObjectByName("pauseButtonText").caption = "Unpause"; + } else { setPaused(false); - getGUIObjectByName("pauseButtonText").caption = "Pause"; + getGUIObjectByName("pauseButtonText").caption = PAUSE; } pauseOverlay.hidden = !pauseOverlay.hidden; @@ -140,7 +228,7 @@ function toggleDeveloperOverlay() function closeOpenDialogs() { - closeMenu(); - closeChat(); - closeSettings(); + closeMenu(); + closeChat(); + closeSettings(false); } \ No newline at end of file diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 957ec87898..2cdbc359c3 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -71,6 +71,7 @@ function init(initData, hotloadData) g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" }; getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem; + initMenuPosition(); // set initial position if (hotloadData) { diff --git a/binaries/data/mods/public/gui/session/session.xml b/binaries/data/mods/public/gui/session/session.xml index 62a5a16b00..e95b5f1f52 100644 --- a/binaries/data/mods/public/gui/session/session.xml +++ b/binaries/data/mods/public/gui/session/session.xml @@ -157,7 +157,8 @@ z="0" > - Game Paused + Game Paused + Click to Resume Game togglePause(); @@ -197,552 +198,553 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - + + + + - - - - + + + + - - - + + + - - - ALPHA VI : Fortuna + + + ALPHA VI : Fortuna - - - - - + + + + + - - - - - - + + + + + + - MENU - - openMenu(); - - - + MENU + + toggleMenu(); + + + - + -