mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Allow ingame menu to reverse, add sounds to all menu buttons, and some organizing and cleanup
This was SVN commit r10194.
This commit is contained in:
parent
1a76c3b848
commit
7a7ebaa983
8 changed files with 862 additions and 745 deletions
|
|
@ -17,6 +17,8 @@ const MAIN_MENU = "main_menu";
|
||||||
const DEFEAT_CUE = "gen_loss_cue";
|
const DEFEAT_CUE = "gen_loss_cue";
|
||||||
const DEFEAT_MUSIC = "gen_loss_track";
|
const DEFEAT_MUSIC = "gen_loss_track";
|
||||||
const VICTORY_MUSIC = "win_1";
|
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)
|
function newRandomSound(soundType, soundSubType, soundPrePath)
|
||||||
{
|
{
|
||||||
// Return a random audio file by category, to be assigned to a handle.
|
// Return a random audio file by category, to be assigned to a handle.
|
||||||
|
var randomSoundPath;
|
||||||
|
|
||||||
switch (soundType)
|
switch (soundType)
|
||||||
{
|
{
|
||||||
case "music":
|
case "music":
|
||||||
var randomSoundPath = "audio/music/"
|
randomSoundPath = "audio/music/"
|
||||||
|
break;
|
||||||
|
case "ambient":
|
||||||
|
randomSoundPath = "audio/ambient/" + soundPrePath + "/";
|
||||||
break;
|
break;
|
||||||
case "effect":
|
case "effect":
|
||||||
randomSoundPath = soundPrePath + "/";
|
randomSoundPath = soundPrePath + "/";
|
||||||
|
|
@ -161,12 +167,18 @@ function getRandomBattleTrack()
|
||||||
|
|
||||||
function playMainMenuMusic()
|
function playMainMenuMusic()
|
||||||
{
|
{
|
||||||
if (global.curr_music)
|
if (global.curr_music)
|
||||||
switchMusic(MAIN_MENU, 0.0, true);
|
switchMusic(MAIN_MENU, 0.0, true);
|
||||||
else
|
else
|
||||||
playMusic(MAIN_MENU, 0.0, true);
|
playMusic(MAIN_MENU, 0.0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function playButtonSound()
|
||||||
|
{
|
||||||
|
var buttonSound = new Sound(BUTTON_SOUND);
|
||||||
|
buttonSound.play();
|
||||||
|
}
|
||||||
|
|
||||||
function stopMainMenuMusic()
|
function stopMainMenuMusic()
|
||||||
{
|
{
|
||||||
if (global.main_menu_music)
|
if (global.main_menu_music)
|
||||||
|
|
@ -192,6 +204,16 @@ function startSessionSounds(civMusic)
|
||||||
playRandomCivMusic();
|
playRandomCivMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startMusic()
|
||||||
|
{
|
||||||
|
console.write(getRandomPeaceTrack());
|
||||||
|
|
||||||
|
|
||||||
|
console.write(global.curr_music);
|
||||||
|
playRandomCivMusic();
|
||||||
|
console.write(global.curr_music);
|
||||||
|
}
|
||||||
|
|
||||||
function playRandomCivMusic()
|
function playRandomCivMusic()
|
||||||
{
|
{
|
||||||
global.curr_music = new Sound(getRandomPeaceTrack());
|
global.curr_music = new Sound(getRandomPeaceTrack());
|
||||||
|
|
@ -204,7 +226,10 @@ function playRandomCivMusic()
|
||||||
|
|
||||||
function playAmbientSounds()
|
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)
|
if (global.curr_ambient)
|
||||||
{
|
{
|
||||||
global.curr_ambient.loop();
|
global.curr_ambient.loop();
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ function init()
|
||||||
|
|
||||||
userReportEnabledText = getGUIObjectByName("userReportEnabledText").caption;
|
userReportEnabledText = getGUIObjectByName("userReportEnabledText").caption;
|
||||||
|
|
||||||
// initialize currentSubmenuType with placeholder to avoid null when switching
|
// initialize currentSubmenuType with placeholder to avoid null when switching
|
||||||
currentSubmenuType = "submenuSinglePlayer";
|
currentSubmenuType = "submenuSinglePlayer";
|
||||||
}
|
}
|
||||||
|
|
||||||
var t0 = new Date;
|
var t0 = new Date;
|
||||||
|
|
@ -82,11 +82,11 @@ function formatUserReportStatus(status)
|
||||||
|
|
||||||
function onTick()
|
function onTick()
|
||||||
{
|
{
|
||||||
// Animate backgrounds
|
// Animate backgrounds
|
||||||
scrollBackgrounds();
|
scrollBackgrounds();
|
||||||
|
|
||||||
// Animate submenu
|
// Animate submenu
|
||||||
updateMenuPosition();
|
updateMenuPosition();
|
||||||
|
|
||||||
if (Engine.IsUserReportEnabled())
|
if (Engine.IsUserReportEnabled())
|
||||||
{
|
{
|
||||||
|
|
@ -112,81 +112,77 @@ function onTick()
|
||||||
// Slide menu
|
// Slide menu
|
||||||
function updateMenuPosition()
|
function updateMenuPosition()
|
||||||
{
|
{
|
||||||
var submenu = getGUIObjectByName("submenu");
|
var submenu = getGUIObjectByName("submenu");
|
||||||
|
|
||||||
if (submenu.hidden == false)
|
if (submenu.hidden == false)
|
||||||
{
|
{
|
||||||
// The offset is the increment or number of units/pixels to move
|
// 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
|
// the menu. An offset of one is always accurate, but it is too
|
||||||
// slow. The offset must divide into the travel distance evenly
|
// slow. The offset must divide into the travel distance evenly
|
||||||
// in order for the menu to end up at the right spot. The travel
|
// in order for the menu to end up at the right spot. The travel
|
||||||
// distance is the max-initial. The travel distance in this
|
// distance is the max-initial. The travel distance in this
|
||||||
// example is 300-60 = 240. We choose an offset of 5 because it
|
// example is 300-60 = 240. We choose an offset of 5 because it
|
||||||
// divides into 240 evenly and provided the speed we wanted.
|
// divides into 240 evenly and provided the speed we wanted.
|
||||||
var OFFSET = 10;
|
const OFFSET = 10;
|
||||||
|
|
||||||
if (submenu.size.left < getGUIObjectByName("mainMenu").size.right)
|
if (submenu.size.left < getGUIObjectByName("mainMenu").size.right)
|
||||||
{
|
{
|
||||||
submenu.size = (submenu.size.left + OFFSET) + " " + submenu.size.top + " " + (submenu.size.right + OFFSET) + " " + submenu.size.bottom;
|
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
|
// Opens the menu by revealing the screen which contains the menu
|
||||||
function openMenu(newSubmenu, position, buttonHeight, numButtons)
|
function openMenu(newSubmenu, position, buttonHeight, numButtons)
|
||||||
{
|
{
|
||||||
var menuSound = new newRandomSound("effect", "arrowfly_", "audio/attack/weapon");
|
// switch to new submenu type
|
||||||
if (menuSound)
|
currentSubmenuType = newSubmenu;
|
||||||
{
|
getGUIObjectByName(currentSubmenuType).hidden = false;
|
||||||
menuSound.play(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// switch to new submenu type
|
// set position of new submenu
|
||||||
currentSubmenuType = newSubmenu;
|
var submenu = getGUIObjectByName("submenu");
|
||||||
getGUIObjectByName(currentSubmenuType).hidden = false;
|
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
|
// Blend in right border of main menu into the left border of the submenu
|
||||||
var submenu = getGUIObjectByName("submenu");
|
blendSubmenuIntoMain(top, bottom);
|
||||||
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
|
// Reveal submenu
|
||||||
blendSubmenuIntoMain(top, bottom);
|
getGUIObjectByName("submenu").hidden = false;
|
||||||
|
|
||||||
// Reveal submenu
|
// prepare to hide the submenu when the user clicks on the background
|
||||||
getGUIObjectByName("submenu").hidden = false;
|
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
|
// Closes the menu and resets position
|
||||||
function closeMenu()
|
function closeMenu()
|
||||||
{
|
{
|
||||||
// remove old submenu type
|
playButtonSound();
|
||||||
getGUIObjectByName(currentSubmenuType).hidden = true;
|
|
||||||
|
|
||||||
// hide submenu and reset position
|
// remove old submenu type
|
||||||
var submenu = getGUIObjectByName("submenu");
|
getGUIObjectByName(currentSubmenuType).hidden = true;
|
||||||
submenu.hidden = true;
|
|
||||||
submenu.size = getGUIObjectByName("mainMenu").size;
|
|
||||||
|
|
||||||
// reset main menu panel right border
|
// hide submenu and reset position
|
||||||
getGUIObjectByName("MainMenuPanelRightBorderTop").size = "100%-2 0 100% 100%";
|
var submenu = getGUIObjectByName("submenu");
|
||||||
|
submenu.hidden = true;
|
||||||
|
submenu.size = getGUIObjectByName("mainMenu").size;
|
||||||
|
|
||||||
// hide submenu screen
|
// reset main menu panel right border
|
||||||
getGUIObjectByName("submenuScreen").hidden = false;
|
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
|
// Sizes right border on main menu panel to match the submenu
|
||||||
function blendSubmenuIntoMain(topPosition, bottomPosition)
|
function blendSubmenuIntoMain(topPosition, bottomPosition)
|
||||||
{
|
{
|
||||||
var topSprite = getGUIObjectByName("MainMenuPanelRightBorderTop");
|
var topSprite = getGUIObjectByName("MainMenuPanelRightBorderTop");
|
||||||
topSprite.size = "100%-2 0 100% " + (topPosition + MARGIN);
|
topSprite.size = "100%-2 0 100% " + (topPosition + MARGIN);
|
||||||
|
|
||||||
var bottomSprite = getGUIObjectByName("MainMenuPanelRightBorderBottom");
|
var bottomSprite = getGUIObjectByName("MainMenuPanelRightBorderBottom");
|
||||||
bottomSprite.size = "100%-2 " + (bottomPosition) + " 100% 100%";
|
bottomSprite.size = "100%-2 " + (bottomPosition) + " 100% 100%";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reveals submenu
|
// Reveals submenu
|
||||||
|
|
@ -209,54 +205,54 @@ function closeMainMenuSubWindow (windowName)
|
||||||
* FUNCTIONS BELOW DO NOT WORK YET
|
* FUNCTIONS BELOW DO NOT WORK YET
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Switch to a given options tab window.
|
//// Switch to a given options tab window.
|
||||||
function openOptionsTab(tabName)
|
//function openOptionsTab(tabName)
|
||||||
{
|
//{
|
||||||
// Hide the other tabs.
|
// // Hide the other tabs.
|
||||||
for (i = 1; i <= 3; i++)
|
// for (i = 1; i <= 3; i++)
|
||||||
{
|
// {
|
||||||
switch (i)
|
// switch (i)
|
||||||
{
|
// {
|
||||||
case 1:
|
// case 1:
|
||||||
var tmpName = "pgOptionsAudio";
|
// var tmpName = "pgOptionsAudio";
|
||||||
break;
|
// break;
|
||||||
case 2:
|
// case 2:
|
||||||
var tmpName = "pgOptionsVideo";
|
// var tmpName = "pgOptionsVideo";
|
||||||
break;
|
// break;
|
||||||
case 3:
|
// case 3:
|
||||||
var tmpName = "pgOptionsGame";
|
// var tmpName = "pgOptionsGame";
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (tmpName != tabName)
|
// if (tmpName != tabName)
|
||||||
{
|
// {
|
||||||
getGUIObjectByName (tmpName + "Window").hidden = true;
|
// getGUIObjectByName (tmpName + "Window").hidden = true;
|
||||||
getGUIObjectByName (tmpName + "Button").enabled = true;
|
// getGUIObjectByName (tmpName + "Button").enabled = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Make given tab visible.
|
// // Make given tab visible.
|
||||||
getGUIObjectByName (tabName + "Window").hidden = false;
|
// getGUIObjectByName (tabName + "Window").hidden = false;
|
||||||
getGUIObjectByName (tabName + "Button").enabled = false;
|
// getGUIObjectByName (tabName + "Button").enabled = false;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
// Move the credits up the screen.
|
//// Move the credits up the screen.
|
||||||
function updateCredits()
|
//function updateCredits()
|
||||||
{
|
//{
|
||||||
// If there are still credit lines to remove, remove them.
|
// // If there are still credit lines to remove, remove them.
|
||||||
if (getNumItems("pgCredits") > 0)
|
// if (getNumItems("pgCredits") > 0)
|
||||||
removeItem ("pgCredits", 0);
|
// removeItem ("pgCredits", 0);
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
// When we've run out of credit,
|
// // When we've run out of credit,
|
||||||
|
//
|
||||||
// Stop the increment timer if it's still active.
|
// // Stop the increment timer if it's still active.
|
||||||
cancelInterval();
|
// cancelInterval();
|
||||||
|
//
|
||||||
// Close the credits screen and return.
|
// // Close the credits screen and return.
|
||||||
closeMainMenuSubWindow ("pgCredits");
|
// closeMainMenuSubWindow ("pgCredits");
|
||||||
guiUnHide ("pg");
|
// guiUnHide ("pg");
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
|
||||||
|
|
@ -1094,22 +1094,8 @@ function performCommand(entity, commandName)
|
||||||
{
|
{
|
||||||
case "delete":
|
case "delete":
|
||||||
var selection = g_Selection.toList();
|
var selection = g_Selection.toList();
|
||||||
|
|
||||||
if (selection.length > 0)
|
if (selection.length > 0)
|
||||||
{
|
openDeleteDialog(selection);
|
||||||
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);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "garrison":
|
case "garrison":
|
||||||
inputState = INPUT_PRESELECTEDACTION;
|
inputState = INPUT_PRESELECTEDACTION;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
const PAUSE = "Pause";
|
||||||
|
const RESUME = "Resume";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MENU POSITION CONSTANTS
|
* MENU POSITION CONSTANTS
|
||||||
*/
|
*/
|
||||||
|
|
@ -6,7 +9,7 @@
|
||||||
const MARGIN = 4;
|
const MARGIN = 4;
|
||||||
|
|
||||||
// Includes the main menu button
|
// Includes the main menu button
|
||||||
const NUM_BUTTONS = 6;
|
const NUM_BUTTONS = 5;
|
||||||
|
|
||||||
// Regular menu buttons
|
// Regular menu buttons
|
||||||
const BUTTON_HEIGHT = 32;
|
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)
|
// The position where the bottom of the menu will end up (currently 164)
|
||||||
const END_MENU_POSITION = (BUTTON_HEIGHT * NUM_BUTTONS) + MARGIN;
|
const END_MENU_POSITION = (BUTTON_HEIGHT * NUM_BUTTONS) + MARGIN;
|
||||||
|
|
||||||
// Menu starting position - bottom
|
// Menu starting position: bottom
|
||||||
const MENU_BOTTOM = 36;
|
const MENU_BOTTOM = 36;
|
||||||
|
|
||||||
// Menu starting position - top
|
// Menu starting position: top
|
||||||
const MENU_TOP = MENU_BOTTOM - END_MENU_POSITION;
|
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;
|
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
|
// Slide menu
|
||||||
function updateMenuPosition()
|
function updateMenuPosition()
|
||||||
{
|
{
|
||||||
if (getGUIObjectByName("menu").hidden == false)
|
if (isMenuOpen)
|
||||||
{
|
{
|
||||||
var menu = getGUIObjectByName("menu");
|
if (menu.size.bottom < END_MENU_POSITION)
|
||||||
|
{
|
||||||
// The offset is the increment or number of units/pixels to move
|
menu.size = "100%-164 " + (menu.size.top + OFFSET) + " 100% " + (menu.size.bottom + OFFSET);
|
||||||
// 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
|
else
|
||||||
// distance is the max-initial. The travel distance in this
|
{
|
||||||
// example is 196-36 = 160. We choose an offset of 16 because it
|
if (menu.size.top > MENU_TOP)
|
||||||
// divides into 160 evenly and provided the speed we wanted.
|
{
|
||||||
var OFFSET = 16;
|
menu.size = "100%-164 " + (menu.size.top - OFFSET) + " 100% " + (menu.size.bottom - OFFSET);
|
||||||
|
}
|
||||||
if (menu.size.bottom < END_MENU_POSITION)
|
}
|
||||||
{
|
|
||||||
menu.size = "100%-164 " + (menu.size.top + OFFSET) + " 100% " + (menu.size.bottom + OFFSET);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opens the menu by revealing the screen which contains the menu
|
// Opens the menu by revealing the screen which contains the menu
|
||||||
function openMenu()
|
function openMenu()
|
||||||
{
|
{
|
||||||
var menuSound = new Sound("audio/interface/ui/ui_button_longclick.ogg");
|
playButtonSound();
|
||||||
if (menuSound)
|
isMenuOpen = true;
|
||||||
{
|
|
||||||
menuSound.play(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
getGUIObjectByName("menu").hidden = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closes the menu and resets position
|
// Closes the menu and resets position
|
||||||
function closeMenu()
|
function closeMenu()
|
||||||
{
|
{
|
||||||
getGUIObjectByName("menu").hidden = true;
|
playButtonSound();
|
||||||
getGUIObjectByName("menu").size = INITIAL_MENU_POSITION;
|
isMenuOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function openSettings()
|
function toggleMenu()
|
||||||
{
|
{
|
||||||
closeMenu();
|
if (isMenuOpen == true)
|
||||||
closeChat();
|
closeMenu();
|
||||||
getGUIObjectByName("settingsDialogPanel").hidden = false;
|
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;
|
getGUIObjectByName("settingsDialogPanel").hidden = true;
|
||||||
|
if (resume)
|
||||||
|
resumeGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
function openChat()
|
function openChat()
|
||||||
{
|
{
|
||||||
closeMenu();
|
|
||||||
closeSettings();
|
|
||||||
getGUIObjectByName("chatInput").focus(); // Grant focus to the input area
|
getGUIObjectByName("chatInput").focus(); // Grant focus to the input area
|
||||||
getGUIObjectByName("chatDialogPanel").hidden = false;
|
getGUIObjectByName("chatDialogPanel").hidden = false;
|
||||||
|
|
||||||
|
|
@ -95,7 +169,7 @@ function closeChat()
|
||||||
|
|
||||||
function toggleChatWindow()
|
function toggleChatWindow()
|
||||||
{
|
{
|
||||||
closeSettings();
|
closeSettings();
|
||||||
|
|
||||||
var chatWindow = getGUIObjectByName("chatDialogPanel");
|
var chatWindow = getGUIObjectByName("chatDialogPanel");
|
||||||
var chatInput = getGUIObjectByName("chatInput");
|
var chatInput = getGUIObjectByName("chatInput");
|
||||||
|
|
@ -108,23 +182,37 @@ function toggleChatWindow()
|
||||||
chatWindow.hidden = !chatWindow.hidden;
|
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()
|
function togglePause()
|
||||||
{
|
{
|
||||||
closeMenu();
|
closeMenu();
|
||||||
closeChat();
|
closeOpenDialogs();
|
||||||
closeSettings();
|
|
||||||
|
|
||||||
var pauseOverlay = getGUIObjectByName("pauseOverlay");
|
var pauseOverlay = getGUIObjectByName("pauseOverlay");
|
||||||
|
|
||||||
if (pauseOverlay.hidden)
|
if (pauseOverlay.hidden)
|
||||||
{
|
{
|
||||||
|
getGUIObjectByName("pauseButtonText").caption = RESUME;
|
||||||
setPaused(true);
|
setPaused(true);
|
||||||
getGUIObjectByName("pauseButtonText").caption = "Unpause";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setPaused(false);
|
setPaused(false);
|
||||||
getGUIObjectByName("pauseButtonText").caption = "Pause";
|
getGUIObjectByName("pauseButtonText").caption = PAUSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
pauseOverlay.hidden = !pauseOverlay.hidden;
|
pauseOverlay.hidden = !pauseOverlay.hidden;
|
||||||
|
|
@ -140,7 +228,7 @@ function toggleDeveloperOverlay()
|
||||||
|
|
||||||
function closeOpenDialogs()
|
function closeOpenDialogs()
|
||||||
{
|
{
|
||||||
closeMenu();
|
closeMenu();
|
||||||
closeChat();
|
closeChat();
|
||||||
closeSettings();
|
closeSettings(false);
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +71,7 @@ function init(initData, hotloadData)
|
||||||
g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" };
|
g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" };
|
||||||
|
|
||||||
getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem;
|
getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem;
|
||||||
|
initMenuPosition(); // set initial position
|
||||||
|
|
||||||
if (hotloadData)
|
if (hotloadData)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -12,6 +12,14 @@
|
||||||
text_valign="center"
|
text_valign="center"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<style name="PauseMessageText"
|
||||||
|
font="serif-bold-12"
|
||||||
|
textcolor="white"
|
||||||
|
text_align="center"
|
||||||
|
text_valign="center"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
<style name="leftAlignedText"
|
<style name="leftAlignedText"
|
||||||
textcolor="white"
|
textcolor="white"
|
||||||
text_align="left"
|
text_align="left"
|
||||||
|
|
|
||||||
|
|
@ -96,12 +96,12 @@ function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, sta
|
||||||
if (button)
|
if (button)
|
||||||
{
|
{
|
||||||
var size = button.size;
|
var size = button.size;
|
||||||
|
|
||||||
size.left = buttonSpacer*colNumber;
|
size.left = buttonSpacer*colNumber;
|
||||||
size.right = buttonSpacer*colNumber + buttonSideLength;
|
size.right = buttonSpacer*colNumber + buttonSideLength;
|
||||||
size.top = buttonSpacer*rowNumber;
|
size.top = buttonSpacer*rowNumber;
|
||||||
size.bottom = buttonSpacer*rowNumber + buttonSideLength;
|
size.bottom = buttonSpacer*rowNumber + buttonSideLength;
|
||||||
|
|
||||||
button.size = size;
|
button.size = size;
|
||||||
colNumber++;
|
colNumber++;
|
||||||
}
|
}
|
||||||
|
|
@ -109,50 +109,61 @@ function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, sta
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets up "unit panels" - the panels with rows of icons (Helper function for updateUnitDisplay)
|
// Sets up "unit panels" - the panels with rows of icons (Helper function for updateUnitDisplay)
|
||||||
|
|
||||||
function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||||
{
|
{
|
||||||
usedPanels[guiName] = 1;
|
usedPanels[guiName] = 1;
|
||||||
var numberOfItems = items.length;
|
var numberOfItems = items.length;
|
||||||
var selection = g_Selection.toList();
|
var selection = g_Selection.toList();
|
||||||
var garrisonGroups = new EntityGroups();
|
var garrisonGroups = new EntityGroups();
|
||||||
if (guiName == "Selection")
|
|
||||||
|
// Determine how many buttons there should be
|
||||||
|
switch (guiName)
|
||||||
{
|
{
|
||||||
if (numberOfItems > 16)
|
case SELECTION:
|
||||||
|
if (numberOfItems > 16)
|
||||||
numberOfItems = 16;
|
numberOfItems = 16;
|
||||||
}
|
break;
|
||||||
else if (guiName == "Formation")
|
|
||||||
{
|
case QUEUE:
|
||||||
if (numberOfItems > 16)
|
if (numberOfItems > 16)
|
||||||
numberOfItems = 16;
|
numberOfItems = 16;
|
||||||
}
|
break;
|
||||||
else if (guiName == "Stance")
|
|
||||||
{
|
case GARRISON:
|
||||||
if (numberOfItems > 5)
|
if (numberOfItems > 16)
|
||||||
|
numberOfItems = 16;
|
||||||
|
//Group garrisoned units based on class
|
||||||
|
garrisonGroups.add(unitEntState.garrisonHolder.entities);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STANCE:
|
||||||
|
if (numberOfItems > 5)
|
||||||
numberOfItems = 5;
|
numberOfItems = 5;
|
||||||
}
|
case FORMATION:
|
||||||
else if (guiName == "Queue")
|
if (numberOfItems > 16)
|
||||||
{
|
numberOfItems = 16;
|
||||||
if (numberOfItems > 16)
|
break;
|
||||||
numberOfItems = 16;
|
|
||||||
}
|
case TRAINING:
|
||||||
else if (guiName == "Garrison")
|
if (numberOfItems > 24)
|
||||||
{
|
numberOfItems = 24;
|
||||||
if (numberOfItems > 16)
|
break;
|
||||||
numberOfItems = 16;
|
|
||||||
//Group garrisoned units based on class
|
case CONSTRUCTION:
|
||||||
garrisonGroups.add(unitEntState.garrisonHolder.entities);
|
if (numberOfItems > 24)
|
||||||
}
|
numberOfItems = 24;
|
||||||
else if (guiName == "Command")
|
break;
|
||||||
{
|
|
||||||
if (numberOfItems > 6)
|
case COMMAND:
|
||||||
numberOfItems = 6;
|
if (numberOfItems > 6)
|
||||||
}
|
numberOfItems = 6;
|
||||||
else if (numberOfItems > 24)
|
break;
|
||||||
{
|
|
||||||
numberOfItems = 24;
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make buttons
|
||||||
var i;
|
var i;
|
||||||
for (i = 0; i < numberOfItems; i++)
|
for (i = 0; i < numberOfItems; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -168,78 +179,78 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||||
|
|
||||||
switch (guiName)
|
switch (guiName)
|
||||||
{
|
{
|
||||||
case SELECTION:
|
case SELECTION:
|
||||||
var name = getEntityName(template);
|
var name = getEntityName(template);
|
||||||
var tooltip = name;
|
var tooltip = name;
|
||||||
var count = g_Selection.groups.getCount(item);
|
var count = g_Selection.groups.getCount(item);
|
||||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : "");
|
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : "");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QUEUE:
|
case QUEUE:
|
||||||
var tooltip = getEntityName(template);
|
var tooltip = getEntityName(template);
|
||||||
var progress = Math.round(item.progress*100) + "%";
|
var progress = Math.round(item.progress*100) + "%";
|
||||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (item.count > 1 ? item.count : "");
|
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (item.count > 1 ? item.count : "");
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
getGUIObjectByName("queueProgress").caption = (item.progress ? progress : "");
|
|
||||||
var size = getGUIObjectByName("unit"+guiName+"ProgressSlider["+i+"]").size;
|
|
||||||
size.top = Math.round(item.progress*40);
|
|
||||||
getGUIObjectByName("unit"+guiName+"ProgressSlider["+i+"]").size = size;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GARRISON:
|
if (i == 0)
|
||||||
var name = getEntityName(template);
|
{
|
||||||
var tooltip = "Unload " + getEntityName(template);
|
getGUIObjectByName("queueProgress").caption = (item.progress ? progress : "");
|
||||||
var count = garrisonGroups.getCount(item);
|
var size = getGUIObjectByName("unit"+guiName+"ProgressSlider["+i+"]").size;
|
||||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : "");
|
size.top = Math.round(item.progress*40);
|
||||||
break;
|
getGUIObjectByName("unit"+guiName+"ProgressSlider["+i+"]").size = size;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case STANCE:
|
case GARRISON:
|
||||||
case FORMATION:
|
var name = getEntityName(template);
|
||||||
var tooltip = toTitleCase(item);
|
var tooltip = "Unload " + getEntityName(template);
|
||||||
break;
|
var count = garrisonGroups.getCount(item);
|
||||||
|
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 1 ? count : "");
|
||||||
|
break;
|
||||||
|
|
||||||
case TRAINING:
|
case STANCE:
|
||||||
var tooltip = getEntityNameWithGenericType(template);
|
case FORMATION:
|
||||||
if (template.tooltip)
|
var tooltip = toTitleCase(item);
|
||||||
tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]";
|
break;
|
||||||
|
|
||||||
tooltip += "\n" + getEntityCost(template);
|
case TRAINING:
|
||||||
|
var tooltip = getEntityNameWithGenericType(template);
|
||||||
|
if (template.tooltip)
|
||||||
|
tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]";
|
||||||
|
|
||||||
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType);
|
tooltip += "\n" + getEntityCost(template);
|
||||||
if (batchSize)
|
|
||||||
{
|
|
||||||
tooltip += "\n[font=\"serif-13\"]Training [font=\"serif-bold-13\"]" + batchSize + "[font=\"serif-13\"] units; " +
|
|
||||||
"Shift-click to train [font=\"serif-bold-13\"]"+ (batchSize+batchIncrement) + "[font=\"serif-13\"] units[/font]";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CONSTRUCTION:
|
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType);
|
||||||
var tooltip = getEntityNameWithGenericType(template);
|
if (batchSize)
|
||||||
if (template.tooltip)
|
{
|
||||||
tooltip += "\n[font=\"serif-13\"]" + template.tooltip + getPopulationBonus(template) + "[/font]";
|
tooltip += "\n[font=\"serif-13\"]Training [font=\"serif-bold-13\"]" + batchSize + "[font=\"serif-13\"] units; " +
|
||||||
|
"Shift-click to train [font=\"serif-bold-13\"]"+ (batchSize+batchIncrement) + "[font=\"serif-13\"] units[/font]";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
tooltip += "\n" + getEntityCost(template);
|
case CONSTRUCTION:
|
||||||
break;
|
var tooltip = getEntityNameWithGenericType(template);
|
||||||
|
if (template.tooltip)
|
||||||
|
tooltip += "\n[font=\"serif-13\"]" + template.tooltip + getPopulationBonus(template) + "[/font]";
|
||||||
|
|
||||||
case COMMAND:
|
tooltip += "\n" + getEntityCost(template);
|
||||||
if (item == "unload-all")
|
break;
|
||||||
{
|
|
||||||
var count = unitEntState.garrisonHolder.entities.length;
|
|
||||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 0 ? count : "");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
tooltip = toTitleCase(item);
|
case COMMAND:
|
||||||
break;
|
if (item == "unload-all")
|
||||||
|
{
|
||||||
|
var count = unitEntState.garrisonHolder.entities.length;
|
||||||
|
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (count > 0 ? count : "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = "";
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
tooltip = toTitleCase(item);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Button
|
// Button
|
||||||
|
|
@ -248,8 +259,8 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||||
button.hidden = false;
|
button.hidden = false;
|
||||||
button.tooltip = tooltip;
|
button.tooltip = tooltip;
|
||||||
|
|
||||||
// Button Function
|
// Button Function (need nested functions to get the closure right)
|
||||||
button.onpress = (function(e) { return function() { callback(e) } })(item); // (need nested functions to get the closure right)
|
button.onpress = (function(e){ return function() { callback(e) } })(item);
|
||||||
|
|
||||||
// Get icon image
|
// Get icon image
|
||||||
if (guiName == "Formation")
|
if (guiName == "Formation")
|
||||||
|
|
@ -290,7 +301,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||||
//icon.cell_id = i;
|
//icon.cell_id = i;
|
||||||
//icon.cell_id = getCommandCellId(item);
|
//icon.cell_id = getCommandCellId(item);
|
||||||
icon.sprite = "stretched:session/icons/single/" + getCommandImage(item);
|
icon.sprite = "stretched:session/icons/single/" + getCommandImage(item);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (template.icon)
|
else if (template.icon)
|
||||||
{
|
{
|
||||||
|
|
@ -326,7 +337,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||||
for (var i = 0; i < numRows; i++)
|
for (var i = 0; i < numRows; i++)
|
||||||
layoutButtonRow(i, guiName, buttonSideLength, buttonSpacer, rowLength*i, rowLength*(i+1) );
|
layoutButtonRow(i, guiName, buttonSideLength, buttonSpacer, rowLength*i, rowLength*(i+1) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize Queue panel if needed
|
// Resize Queue panel if needed
|
||||||
if (guiName == "Queue") // or garrison
|
if (guiName == "Queue") // or garrison
|
||||||
{
|
{
|
||||||
|
|
@ -347,7 +358,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
|
||||||
function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, selection)
|
function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, selection)
|
||||||
{
|
{
|
||||||
//var isInvisible = true;
|
//var isInvisible = true;
|
||||||
|
|
||||||
// Panels that are active
|
// Panels that are active
|
||||||
var usedPanels = {};
|
var usedPanels = {};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue