Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/unit_commands.js
// The number of currently visible buttons (used to optimise showing/hiding) | // The number of currently visible buttons (used to optimise showing/hiding) | ||||
var g_unitPanelButtons = { | var g_unitPanelButtons = { | ||||
"Selection": 0, | "Selection": 0, | ||||
"Queue": 0, | "Queue": 0, | ||||
"Formation": 0, | "Formation": 0, | ||||
"Garrison": 0, | "Garrison": 0, | ||||
"Training": 0, | "Training": 0, | ||||
"Research": 0, | "Research": 0, | ||||
"Alert": 0, | "Alert": 0, | ||||
"Barter": 0, | "Barter": 0, | ||||
"Construction": 0, | "Construction": 0, | ||||
"Command": 0, | "Command": 0, | ||||
"AllyCommand": 0, | |||||
"Stance": 0, | "Stance": 0, | ||||
"Gate": 0, | "Gate": 0, | ||||
"Pack": 0, | "Pack": 0, | ||||
"Upgrade": 0 | "Upgrade": 0 | ||||
}; | }; | ||||
/** | /** | ||||
* Set the position of a panel object according to the index, | * Set the position of a panel object according to the index, | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
* "supplementalSelectionDetails" GUI Object | * "supplementalSelectionDetails" GUI Object | ||||
* @param commandsPanel Reference to the "commandsPanel" GUI Object | * @param commandsPanel Reference to the "commandsPanel" GUI Object | ||||
*/ | */ | ||||
function updateUnitCommands(entStates, supplementalDetailsPanel, commandsPanel) | function updateUnitCommands(entStates, supplementalDetailsPanel, commandsPanel) | ||||
{ | { | ||||
for (let panel in g_SelectionPanels) | for (let panel in g_SelectionPanels) | ||||
g_SelectionPanels[panel].used = false; | g_SelectionPanels[panel].used = false; | ||||
// If the selection is friendly units, add the command panels | |||||
// Get player state to check some constraints | // Get player state to check some constraints | ||||
// e.g. presence of a hero or build limits | // e.g. presence of a hero or build limits. | ||||
let playerStates = GetSimState().players; | let playerStates = GetSimState().players; | ||||
let playerState = playerStates[Engine.GetPlayerID()]; | let playerState = playerStates[Engine.GetPlayerID()]; | ||||
// Always show selection. | // Always show selection. | ||||
setupUnitPanel("Selection", entStates, playerStates[entStates[0].player]); | setupUnitPanel("Selection", entStates, playerStates[entStates[0].player]); | ||||
// Command panel always shown for it can contain commands | |||||
// for which the entity does not need to be owned. | |||||
setupUnitPanel("Command", entStates, playerState); | |||||
if (g_IsObserver || entStates.every(entState => | if (g_IsObserver || entStates.every(entState => | ||||
controlsPlayer(entState.player) && | controlsPlayer(entState.player) && | ||||
(!entState.identity || entState.identity.controllable)) || | (!entState.identity || entState.identity.controllable)) || | ||||
playerState.controlsAll) | playerState.controlsAll) | ||||
{ | { | ||||
for (let guiName of g_PanelsOrder) | for (let guiName of g_PanelsOrder) | ||||
{ | { | ||||
if (g_SelectionPanels[guiName].conflictsWith && | if (g_SelectionPanels[guiName].conflictsWith && | ||||
g_SelectionPanels[guiName].conflictsWith.some(p => g_SelectionPanels[p].used)) | g_SelectionPanels[guiName].conflictsWith.some(p => g_SelectionPanels[p].used)) | ||||
continue; | continue; | ||||
setupUnitPanel(guiName, entStates, playerStates[entStates[0].player]); | setupUnitPanel(guiName, entStates, playerStates[entStates[0].player]); | ||||
} | } | ||||
supplementalDetailsPanel.hidden = false; | supplementalDetailsPanel.hidden = false; | ||||
commandsPanel.hidden = false; | commandsPanel.hidden = false; | ||||
} | } | ||||
else if (playerState.isMutualAlly[entStates[0].player]) // owned by allied player | else if (playerState.isMutualAlly[entStates[0].player]) | ||||
{ | { | ||||
// TODO if there's a second panel needed for a different player | // TODO if there's a second panel needed for a different player | ||||
// we should consider adding the players list to g_SelectionPanels | // we should consider adding the players list to g_SelectionPanels | ||||
setupUnitPanel("Garrison", entStates, playerState); | setupUnitPanel("Garrison", entStates, playerState); | ||||
setupUnitPanel("AllyCommand", entStates, playerState); | |||||
supplementalDetailsPanel.hidden = !g_SelectionPanels.Garrison.used; | supplementalDetailsPanel.hidden = !g_SelectionPanels.Garrison.used; | ||||
commandsPanel.hidden = true; | commandsPanel.hidden = true; | ||||
} | } | ||||
else // owned by another player | else | ||||
{ | { | ||||
supplementalDetailsPanel.hidden = true; | supplementalDetailsPanel.hidden = true; | ||||
commandsPanel.hidden = true; | commandsPanel.hidden = true; | ||||
} | } | ||||
// Hides / unhides Unit Panels (panels should be grouped by type, not by order, but we will leave that for another time) | // Hides / unhides Unit Panels (panels should be grouped by type, not by order, but we will leave that for another time) | ||||
for (let panelName in g_SelectionPanels) | for (let panelName in g_SelectionPanels) | ||||
Engine.GetGUIObjectByName("unit" + panelName + "Panel").hidden = !g_SelectionPanels[panelName].used; | Engine.GetGUIObjectByName("unit" + panelName + "Panel").hidden = !g_SelectionPanels[panelName].used; | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator