Index: binaries/data/mods/public/gui/session/selection_panels.js =================================================================== --- binaries/data/mods/public/gui/session/selection_panels.js +++ binaries/data/mods/public/gui/session/selection_panels.js @@ -134,6 +134,7 @@ data.countDisplay.caption = data.item.count || ""; + // This needs some thought. data.button.enabled = g_IsObserver && data.item.name == "focus-rally" || controlsPlayer(data.player) && (data.item.name != "delete" || @@ -153,59 +154,6 @@ } }; -g_SelectionPanels.AllyCommand = { - "getMaxNumberOfItems": function() - { - return 2; - }, - "conflictsWith": ["Command"], - "getItems": function(unitEntStates) - { - let commands = []; - for (let command in g_AllyEntityCommands) - for (let state of unitEntStates) - { - let info = g_AllyEntityCommands[command].getInfo(state); - if (info) - { - info.name = command; - commands.push(info); - break; - } - } - return commands; - }, - "setupButton": function(data) - { - data.button.tooltip = data.item.tooltip; - - data.button.onPress = function() { - if (data.item.callback) - data.item.callback(data.item); - else - performAllyCommand(data.unitEntStates[0].id, data.item.name); - }; - - data.countDisplay.caption = data.item.count || ""; - - data.button.enabled = !!data.item.count; - - let grayscale = data.button.enabled ? "" : "grayscale:"; - data.icon.sprite = "stretched:" + grayscale + "session/icons/" + data.item.icon; - - let size = data.button.size; - // relative to the center ( = 50%) - size.rleft = 50; - size.rright = 50; - // offset from the center calculation, count on square buttons, so size.bottom is the width too - size.left = (data.i - data.numberOfItems / 2) * (size.bottom + 1); - size.right = size.left + size.bottom; - data.button.size = size; - - return true; - } -}; - g_SelectionPanels.Construction = { "getMaxNumberOfItems": function() { @@ -1182,7 +1130,6 @@ // UNIQUE PANES (importance doesn't matter) "Command", - "AllyCommand", "Queue", "Selection", ]; Index: binaries/data/mods/public/gui/session/selection_panels_helpers.js =================================================================== --- binaries/data/mods/public/gui/session/selection_panels_helpers.js +++ binaries/data/mods/public/gui/session/selection_panels_helpers.js @@ -239,28 +239,13 @@ // Don't check all entities, because we assume a player cannot // select entities from more than one player - if (!controlsPlayer(entStates[0].player) && - !(g_IsObserver && commandName == "focus-rally")) + if (g_IsObserver && commandName != "focus-rally") return; - if (g_EntityCommands[commandName]) + if (g_EntityCommands[commandName] && g_EntityCommands[commandName].getInfo(entStates)) g_EntityCommands[commandName].execute(entStates); } -function performAllyCommand(entity, commandName) -{ - if (!entity) - return; - - let entState = GetEntityState(entity); - let playerState = GetSimState().players[Engine.GetPlayerID()]; - if (!playerState.isMutualAlly[entState.player] || g_IsObserver) - return; - - if (g_AllyEntityCommands[commandName]) - g_AllyEntityCommands[commandName].execute(entState); -} - function performFormation(entities, formationTemplate) { if (!entities) Index: binaries/data/mods/public/gui/session/unit_actions.js =================================================================== --- binaries/data/mods/public/gui/session/unit_actions.js +++ binaries/data/mods/public/gui/session/unit_actions.js @@ -1019,8 +1019,20 @@ { let count = 0; for (let entState of entStates) - if (entState.garrisonHolder) + { + if (!entState.garrisonHolder) + continue; + + if (controlsPlayer(entState.player)) count += entState.garrisonHolder.entities.length; + else + for (let entity of entState.garrisonHolder.entities) + { + let state = GetEntityState(entity); + if (controlsPlayer(state.player)) + ++count; + } + } if (!count) return false; @@ -1041,6 +1053,9 @@ "delete": { "getInfo": function(entStates) { + if (entStates.some(entState => !controlsPlayer(entState.player))) + return false; + return entStates.some(entState => !isUndeletable(entState)) ? { "tooltip": @@ -1104,7 +1119,7 @@ "stop": { "getInfo": function(entStates) { - if (entStates.every(entState => !entState.unitAI)) + if (entStates.every(entState => !entState.unitAI || !controlsPlayer(entState.player))) return false; return { @@ -1123,7 +1138,7 @@ "garrison": { "getInfo": function(entStates) { - if (entStates.every(entState => !entState.unitAI || entState.turretParent || false)) + if (entStates.every(entState => !entState.unitAI || entState.turretParent || !controlsPlayer(entState.player))) return false; return { @@ -1164,7 +1179,7 @@ "repair": { "getInfo": function(entStates) { - if (entStates.every(entState => !entState.builder)) + if (entStates.every(entState => !entState.builder || !controlsPlayer(entState.player))) return false; return { @@ -1183,7 +1198,7 @@ "focus-rally": { "getInfo": function(entStates) { - if (entStates.every(entState => !entState.rallyPoint)) + if (entStates.every(entState => !entState.rallyPoint || !controlsPlayer(entState.player))) return false; return { @@ -1218,7 +1233,7 @@ "back-to-work": { "getInfo": function(entStates) { - if (entStates.every(entState => !entState.unitAI || !entState.unitAI.hasWorkOrders)) + if (entStates.every(entState => !entState.unitAI || !entState.unitAI.hasWorkOrders || !controlsPlayer(entState.player))) return false; return { @@ -1237,7 +1252,7 @@ "getInfo": function(entStates) { if (entStates.every(entState => - !entState.unitAI || !entState.unitAI.canGuard || entState.unitAI.isGuarding)) + !entState.unitAI || !entState.unitAI.canGuard || entState.unitAI.isGuarding || !controlsPlayer(entState.player))) return false; return { @@ -1256,7 +1271,7 @@ "remove-guard": { "getInfo": function(entStates) { - if (entStates.every(entState => !entState.unitAI || !entState.unitAI.isGuarding)) + if (entStates.every(entState => !entState.unitAI || !entState.unitAI.isGuarding || !controlsPlayer(entState.player))) return false; return { @@ -1273,7 +1288,7 @@ "select-trading-goods": { "getInfo": function(entStates) { - if (entStates.every(entState => !entState.market)) + if (entStates.every(entState => !entState.market || !controlsPlayer(entState.player))) return false; return { @@ -1290,7 +1305,7 @@ "patrol": { "getInfo": function(entStates) { - if (!entStates.some(entState => entState.unitAI && entState.unitAI.canPatrol)) + if (!entStates.some(entState => entState.unitAI && entState.unitAI.canPatrol && controlsPlayer(entState.player))) return false; return { @@ -1315,81 +1330,31 @@ if (!sharableEntities.length) return false; - // Returns if none of the entities belong to a player with a mutual ally - if (entStates.every(entState => !GetSimState().players[entState.player].isMutualAlly.some( - (isAlly, playerId) => isAlly && playerId != entState.player))) - return false; - - return sharableEntities.some(entState => !entState.resourceDropsite.shared) ? - { - "tooltip": translate("Press to allow allies to use this dropsite"), - "icon": "locked_small.png" - } : - { - "tooltip": translate("Press to prevent allies from using this dropsite"), - "icon": "unlocked_small.png" - }; - }, - "execute": function(entStates) - { - let sharableEntities = entStates.filter( - entState => entState.resourceDropsite && entState.resourceDropsite.sharable); - Engine.PostNetworkCommand({ - "type": "set-dropsite-sharing", - "entities": sharableEntities.map(entState => entState.id), - "shared": sharableEntities.some(entState => !entState.resourceDropsite.shared) - }); - }, - } -}; - -var g_AllyEntityCommands = -{ - "unload-all": { - "getInfo": function(entState) - { - if (!entState.garrisonHolder) - return false; - - let player = Engine.GetPlayerID(); - - let count = 0; - for (let ent in g_Selection.selected) + if (sharableEntities.every(entState => controlsPlayer(entState.player))) { - let selectedEntState = GetEntityState(+ent); - if (!selectedEntState.garrisonHolder) - continue; + // Returns if none of the entities belong to a player with a mutual ally. + if (entStates.every(entState => !GetSimState().players[entState.player].isMutualAlly.some( + (isAlly, playerId) => isAlly && playerId != entState.player))) + return false; - for (let entity of selectedEntState.garrisonHolder.entities) - { - let state = GetEntityState(entity); - if (state.player == player) - ++count; - } + return sharableEntities.some(entState => !entState.resourceDropsite.shared) ? + { + "tooltip": translate("Press to allow allies to use this dropsite"), + "icon": "locked_small.png" + } : + { + "tooltip": translate("Press to prevent allies from using this dropsite"), + "icon": "unlocked_small.png" + }; } - return { - "tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.unload") + - translate("Unload All."), - "icon": "garrison-out.png", - "count": count, - }; - }, - "execute": function(entState) - { - unloadAll(); - }, - }, - - "share-dropsite": { - "getInfo": function(entState) - { - if (Engine.GetPlayerID() == -1 || - !GetSimState().players[Engine.GetPlayerID()].hasSharedDropsites || - !entState.resourceDropsite || !entState.resourceDropsite.sharable) + let player = Engine.GetPlayerID() + if (player == -1 || entStates.every(entState => + !GetSimState().players[player].hasSharedDropsites || + !entState.resourceDropsite || !entState.resourceDropsite.sharable)) return false; - if (entState.resourceDropsite.shared) + if (entStates.every(entState => entState.resourceDropsite.shared)) return { "tooltip": translate("You are allowed to use this dropsite"), "icon": "unlocked_small.png" @@ -1400,9 +1365,16 @@ "icon": "locked_small.png" }; }, - "execute": function(entState) + "execute": function(entStates) { - // This command button is always disabled + let sharableEntities = entStates.filter( + entState => entState.resourceDropsite && entState.resourceDropsite.sharable && controlsPlayer(entState.player)); + if (sharableEntities) + Engine.PostNetworkCommand({ + "type": "set-dropsite-sharing", + "entities": sharableEntities.map(entState => entState.id), + "shared": sharableEntities.some(entState => !entState.resourceDropsite.shared) + }); }, } }; Index: binaries/data/mods/public/gui/session/unit_commands.js =================================================================== --- binaries/data/mods/public/gui/session/unit_commands.js +++ binaries/data/mods/public/gui/session/unit_commands.js @@ -10,7 +10,6 @@ "Barter": 0, "Construction": 0, "Command": 0, - "AllyCommand": 0, "Stance": 0, "Gate": 0, "Pack": 0, @@ -135,6 +134,9 @@ let playerStates = GetSimState().players; let playerState = playerStates[Engine.GetPlayerID()]; + // Command panel always shown for it can contain non-owned commands. + setupUnitPanel("Command", entStates, playerState); + if (g_IsObserver || entStates.every(entState => controlsPlayer(entState.player))) { for (let guiName of g_PanelsOrder) @@ -155,7 +157,6 @@ // TODO if there's a second panel needed for a different player // we should consider adding the players list to g_SelectionPanels setupUnitPanel("Garrison", entStates, playerState); - setupUnitPanel("AllyCommand", entStates, playerState); supplementalDetailsPanel.hidden = !g_SelectionPanels.Garrison.used;