Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/session.js
Show All 12 Lines | |||||
var g_Chat; | var g_Chat; | ||||
var g_DeveloperOverlay; | var g_DeveloperOverlay; | ||||
var g_DiplomacyColors; | var g_DiplomacyColors; | ||||
var g_DiplomacyDialog; | var g_DiplomacyDialog; | ||||
var g_GameSpeedControl; | var g_GameSpeedControl; | ||||
var g_Menu; | var g_Menu; | ||||
var g_MiniMapPanel; | var g_MiniMapPanel; | ||||
var g_ObjectivesDialog; | var g_ObjectivesDialog; | ||||
var g_OutOfSyncNetwork; | |||||
var g_OutOfSyncReplay; | |||||
var g_PanelEntityManager; | var g_PanelEntityManager; | ||||
var g_PauseControl; | var g_PauseControl; | ||||
var g_PauseOverlay; | var g_PauseOverlay; | ||||
var g_PlayerViewControl; | var g_PlayerViewControl; | ||||
var g_QuitConfirmationDefeat; | |||||
var g_QuitConfirmationReplay; | |||||
var g_RangeOverlayManager; | var g_RangeOverlayManager; | ||||
var g_ResearchProgress; | var g_ResearchProgress; | ||||
var g_TradeDialog; | var g_TradeDialog; | ||||
var g_TopPanel; | var g_TopPanel; | ||||
/** | /** | ||||
* A random file will be played. TODO: more variety | * A random file will be played. TODO: more variety | ||||
*/ | */ | ||||
Show All 31 Lines | |||||
var g_IsObserver = false; | var g_IsObserver = false; | ||||
/** | /** | ||||
* True if the current user has rejoined (or joined the game after it started). | * True if the current user has rejoined (or joined the game after it started). | ||||
*/ | */ | ||||
var g_HasRejoined = false; | var g_HasRejoined = false; | ||||
/** | /** | ||||
* Shows a message box asking the user to leave if "won" or "defeated". | |||||
*/ | |||||
var g_ConfirmExit = false; | |||||
/** | |||||
* The playerID selected in the change perspective tool. | * The playerID selected in the change perspective tool. | ||||
*/ | */ | ||||
var g_ViewedPlayer = Engine.GetPlayerID(); | var g_ViewedPlayer = Engine.GetPlayerID(); | ||||
/** | /** | ||||
* True if the camera should focus on attacks and player commands | * True if the camera should focus on attacks and player commands | ||||
* and select the affected units. | * and select the affected units. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | if (initData) | ||||
g_ReplaySelectionData = initData.replaySelectionData; | g_ReplaySelectionData = initData.replaySelectionData; | ||||
g_HasRejoined = initData.isRejoining; | g_HasRejoined = initData.isRejoining; | ||||
if (initData.savedGUIData) | if (initData.savedGUIData) | ||||
restoreSavedGameData(initData.savedGUIData); | restoreSavedGameData(initData.savedGUIData); | ||||
} | } | ||||
g_DiplomacyColors = new DiplomacyColors(); | g_DiplomacyColors = new DiplomacyColors(); | ||||
g_PlayerViewControl = new PlayerViewControl(); | g_PlayerViewControl = new PlayerViewControl(); | ||||
g_PlayerViewControl.registerViewedPlayerChangeHandler(g_DiplomacyColors.updateDisplayedPlayerColors.bind(g_DiplomacyColors)); | g_PlayerViewControl.registerViewedPlayerChangeHandler(g_DiplomacyColors.updateDisplayedPlayerColors.bind(g_DiplomacyColors)); | ||||
g_DiplomacyColors.registerDiplomacyColorsChangeHandler(g_PlayerViewControl.rebuild.bind(g_PlayerViewControl)); | g_DiplomacyColors.registerDiplomacyColorsChangeHandler(g_PlayerViewControl.rebuild.bind(g_PlayerViewControl)); | ||||
g_DiplomacyColors.registerDiplomacyColorsChangeHandler(updateGUIObjects); | g_DiplomacyColors.registerDiplomacyColorsChangeHandler(updateGUIObjects); | ||||
g_PauseControl = new PauseControl(); | |||||
g_PlayerViewControl.registerPreViewedPlayerChangeHandler(removeStatusBarDisplay); | g_PlayerViewControl.registerPreViewedPlayerChangeHandler(removeStatusBarDisplay); | ||||
g_PlayerViewControl.registerViewedPlayerChangeHandler(resetTemplates); | g_PlayerViewControl.registerViewedPlayerChangeHandler(resetTemplates); | ||||
g_Chat = new Chat(g_PlayerViewControl); | g_Chat = new Chat(g_PlayerViewControl); | ||||
g_DeveloperOverlay = new DeveloperOverlay(g_PlayerViewControl, g_Selection); | g_DeveloperOverlay = new DeveloperOverlay(g_PlayerViewControl, g_Selection); | ||||
g_DiplomacyDialog = new DiplomacyDialog(g_PlayerViewControl, g_DiplomacyColors); | g_DiplomacyDialog = new DiplomacyDialog(g_PlayerViewControl, g_DiplomacyColors); | ||||
g_GameSpeedControl = new GameSpeedControl(g_PlayerViewControl); | g_GameSpeedControl = new GameSpeedControl(g_PlayerViewControl); | ||||
g_Menu = new Menu(g_PauseControl, g_PlayerViewControl, g_Chat); | |||||
g_MiniMapPanel = new MiniMapPanel(g_PlayerViewControl, g_DiplomacyColors, g_WorkerTypes); | g_MiniMapPanel = new MiniMapPanel(g_PlayerViewControl, g_DiplomacyColors, g_WorkerTypes); | ||||
g_ObjectivesDialog = new ObjectivesDialog(g_PlayerViewControl); | g_ObjectivesDialog = new ObjectivesDialog(g_PlayerViewControl); | ||||
g_OutOfSyncNetwork = new OutOfSyncNetwork(); | |||||
g_OutOfSyncReplay = new OutOfSyncReplay(); | |||||
g_PanelEntityManager = new PanelEntityManager(g_PlayerViewControl, g_Selection, g_PanelEntityOrder); | g_PanelEntityManager = new PanelEntityManager(g_PlayerViewControl, g_Selection, g_PanelEntityOrder); | ||||
g_PauseControl = new PauseControl(); | |||||
g_PauseOverlay = new PauseOverlay(g_PauseControl); | g_PauseOverlay = new PauseOverlay(g_PauseControl); | ||||
g_Menu = new Menu(g_PauseControl, g_PlayerViewControl, g_Chat); | g_QuitConfirmationDefeat = new QuitConfirmationDefeat(); | ||||
g_QuitConfirmationReplay = new QuitConfirmationReplay(); | |||||
g_RangeOverlayManager = new RangeOverlayManager(g_Selection); | g_RangeOverlayManager = new RangeOverlayManager(g_Selection); | ||||
g_ResearchProgress = new ResearchProgress(g_PlayerViewControl, g_Selection); | g_ResearchProgress = new ResearchProgress(g_PlayerViewControl, g_Selection); | ||||
g_TradeDialog = new TradeDialog(g_PlayerViewControl); | g_TradeDialog = new TradeDialog(g_PlayerViewControl); | ||||
g_TopPanel = new TopPanel(g_PlayerViewControl, g_DiplomacyDialog, g_TradeDialog, g_ObjectivesDialog, g_GameSpeedControl); | g_TopPanel = new TopPanel(g_PlayerViewControl, g_DiplomacyDialog, g_TradeDialog, g_ObjectivesDialog, g_GameSpeedControl); | ||||
initBatchTrain(); | initBatchTrain(); | ||||
initSelectionPanels(); | initSelectionPanels(); | ||||
LoadModificationTemplates(); | LoadModificationTemplates(); | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | function playersFinished(players, victoryString, won) | ||||
if (players.indexOf(Engine.GetPlayerID()) == -1 || Engine.IsAtlasRunning()) | if (players.indexOf(Engine.GetPlayerID()) == -1 || Engine.IsAtlasRunning()) | ||||
return; | return; | ||||
global.music.setState( | global.music.setState( | ||||
won ? | won ? | ||||
global.music.states.VICTORY : | global.music.states.VICTORY : | ||||
global.music.states.DEFEAT | global.music.states.DEFEAT | ||||
); | ); | ||||
g_ConfirmExit = won ? "won" : "defeated"; | |||||
} | } | ||||
function resumeGame() | function resumeGame() | ||||
{ | { | ||||
g_PauseControl.implicitResume(); | g_PauseControl.implicitResume(); | ||||
} | } | ||||
function closeOpenDialogs() | function closeOpenDialogs() | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | function onSimulationUpdate() | ||||
for (let handler of g_SimulationUpdateHandlers) | for (let handler of g_SimulationUpdateHandlers) | ||||
handler(); | handler(); | ||||
// TODO: Move to handlers | // TODO: Move to handlers | ||||
updateCinemaPath(); | updateCinemaPath(); | ||||
handleNotifications(); | handleNotifications(); | ||||
updateGUIObjects(); | updateGUIObjects(); | ||||
if (g_ConfirmExit) | |||||
confirmExit(); | |||||
} | |||||
/** | |||||
* Don't show the message box before all playerstate changes are processed. | |||||
*/ | |||||
function confirmExit() | |||||
{ | |||||
if (g_IsNetworked && !g_IsNetworkedActive) | |||||
return; | |||||
closeOpenDialogs(); | |||||
g_PauseControl.implicitPause(); | |||||
// Don't ask for exit if other humans are still playing | |||||
let askExit = !Engine.HasNetServer() || g_Players.every((player, i) => | |||||
i == 0 || | |||||
player.state != "active" || | |||||
g_GameAttributes.settings.PlayerData[i].AI != ""); | |||||
let subject = g_PlayerStateMessages[g_ConfirmExit]; | |||||
if (askExit) | |||||
subject += "\n" + translate("Do you want to quit?"); | |||||
messageBox( | |||||
400, 200, | |||||
subject, | |||||
g_ConfirmExit == "won" ? | |||||
translate("VICTORIOUS!") : | |||||
translate("DEFEATED!"), | |||||
askExit ? [translate("No"), translate("Yes")] : [translate("OK")], | |||||
askExit ? [resumeGame, endGame] : [resumeGame]); | |||||
g_ConfirmExit = false; | |||||
} | } | ||||
function toggleGUI() | function toggleGUI() | ||||
{ | { | ||||
g_ShowGUI = !g_ShowGUI; | g_ShowGUI = !g_ShowGUI; | ||||
updateCinemaPath(); | updateCinemaPath(); | ||||
} | } | ||||
Show All 25 Lines | function updateGUIObjects() | ||||
{ | { | ||||
// Update music state on basis of battle state. | // Update music state on basis of battle state. | ||||
let battleState = Engine.GuiInterfaceCall("GetBattleState", g_ViewedPlayer); | let battleState = Engine.GuiInterfaceCall("GetBattleState", g_ViewedPlayer); | ||||
if (battleState) | if (battleState) | ||||
global.music.setState(global.music.states[battleState]); | global.music.setState(global.music.states[battleState]); | ||||
} | } | ||||
} | } | ||||
function onReplayFinished() | |||||
{ | |||||
closeOpenDialogs(); | |||||
g_PauseControl.implicitPause(); | |||||
messageBox(400, 200, | |||||
translateWithContext("replayFinished", "The replay has finished. Do you want to quit?"), | |||||
translateWithContext("replayFinished", "Confirmation"), | |||||
[translateWithContext("replayFinished", "No"), translateWithContext("replayFinished", "Yes")], | |||||
[resumeGame, endGame]); | |||||
} | |||||
function updateGroups() | function updateGroups() | ||||
{ | { | ||||
g_Groups.update(); | g_Groups.update(); | ||||
// Determine the sum of the costs of a given template | // Determine the sum of the costs of a given template | ||||
let getCostSum = (ent) => { | let getCostSum = (ent) => { | ||||
let cost = GetTemplateData(GetEntityState(ent).template).cost; | let cost = GetTemplateData(GetEntityState(ent).template).cost; | ||||
return cost ? Object.keys(cost).map(key => cost[key]).reduce((sum, cur) => sum + cur) : 0; | return cost ? Object.keys(cost).map(key => cost[key]).reduce((sum, cur) => sum + cur) : 0; | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator