From faa049fe4b8a7a8d5724439deb6f81a8b641d0fc Mon Sep 17 00:00:00 2001 From: Vantha Date: Tue, 21 Oct 2025 21:41:42 +0200 Subject: [PATCH] Don't set up command and selection panels twice In the (common) case that the player controls all selected units or is an observer, the 'Selection' and 'Command' panels were set up ahead and then in the for loop again, which was wasteful. --- .../mods/public/gui/session/unit_commands.js | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/binaries/data/mods/public/gui/session/unit_commands.js b/binaries/data/mods/public/gui/session/unit_commands.js index 80787cef13..fa3511a20b 100644 --- a/binaries/data/mods/public/gui/session/unit_commands.js +++ b/binaries/data/mods/public/gui/session/unit_commands.js @@ -133,12 +133,6 @@ function updateUnitCommands(entStates, supplementalDetailsPanel, commandsPanel) const playerStates = GetSimState().players; const playerState = playerStates[Engine.GetPlayerID()]; - 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 => controlsPlayer(entState.player) && (!entState.identity || entState.identity.controllable)) || @@ -156,20 +150,29 @@ function updateUnitCommands(entStates, supplementalDetailsPanel, commandsPanel) supplementalDetailsPanel.hidden = false; commandsPanel.hidden = false; } - else if (playerState.isMutualAlly[entStates[0].player]) - { - // 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); - - supplementalDetailsPanel.hidden = !g_SelectionPanels.Garrison.used; - - commandsPanel.hidden = true; - } else { - supplementalDetailsPanel.hidden = true; - commandsPanel.hidden = true; + // Always show what entities are selected, no matter if they can be controlled. + setupUnitPanel("Selection", entStates, playerStates[entStates[0].player]); + // Always show the commands since they might not require the entities to be owned. + // TODO: This panel here is NOT related to the commandsPanel GUI object. The naming should be improved. + setupUnitPanel("Command", entStates, playerState); + + if (playerState.isMutualAlly[entStates[0].player]) + { + // 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); + + supplementalDetailsPanel.hidden = !g_SelectionPanels.Garrison.used; + + commandsPanel.hidden = true; + } + else + { + supplementalDetailsPanel.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)