Skip to content

Commit

Permalink
Commander Transport Search Hotkey Upgrade (FAForever#6534)
Browse files Browse the repository at this point in the history
Modifies the existing select/zoom to commander keyactions to use a new
SelectCommander function, which searches possible transports and
selects/zooms to them if it doesn't find a commander on the ground.

For cases of multiple commanders:
- Prioritizes the nearest commander not in a transport (like the stock
implementation)
- If there's no grounded commanders, it finds one in a transport at
random. There's unfortunately no method for the UI to search by both
attached units and distance

In case of no commander it clears the selection

---------

Co-authored-by: FAForever Machine User <[email protected]>
  • Loading branch information
clyfordv and FAForeverBot authored Nov 19, 2024
1 parent e59dacf commit 012e944
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog/snippets/features.6534.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6534) Select/go to commander hotkeys will now search for commanders in transports if it doesn't find any on the ground
4 changes: 2 additions & 2 deletions loc/CZ/strings_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4723,8 +4723,8 @@ key_desc_0216="One-key zoom-pop"
key_desc_0217="Select onscreen idle mass extractors."
key_desc_0218="Select all mass extractors."
key_desc_0219="Select nearest onscreen lowest tech idle mass extractor."
key_desc_0220="Select ACU (control group)"
key_desc_0221="Append ACU to selection (control group)"
key_desc_0220="Select ACU (double tap to zoom)"
key_desc_0221="Append ACU to selection (double tap to zoom)"
key_desc_0222="Select nearest idle engineer (not ACU)"
key_desc_0223="Select/Add nearest idle engineers"
key_desc_0224="Cycle through idle factories"
Expand Down
4 changes: 2 additions & 2 deletions loc/PL/strings_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4722,8 +4722,8 @@ key_desc_0216="One-key zoom-pop"
key_desc_0217="Select onscreen idle mass extractors."
key_desc_0218="Select all mass extractors."
key_desc_0219="Select nearest onscreen lowest tech idle mass extractor."
key_desc_0220="Select ACU (control group)"
key_desc_0221="Append ACU to selection (control group)"
key_desc_0220="Select ACU (double tap to zoom)"
key_desc_0221="Append ACU to selection (double tap to zoom)"
key_desc_0222="Select nearest idle engineer (not ACU)"
key_desc_0223="Select/Add nearest idle engineers"
key_desc_0224="Cycle through idle factories"
Expand Down
4 changes: 2 additions & 2 deletions loc/US/strings_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4267,8 +4267,8 @@ key_desc_0216="One-key zoom-pop"
key_desc_0217="Select onscreen idle mass extractors."
key_desc_0218="Select all mass extractors."
key_desc_0219="Select nearest onscreen lowest tech idle mass extractor."
key_desc_0220="Select ACU (control group)"
key_desc_0221="Append ACU to selection (control group)"
key_desc_0220="Select ACU (double tap to zoom)"
key_desc_0221="Append ACU to selection (double tap to zoom)"
key_desc_0222="Select nearest idle engineer (not ACU)"
key_desc_0223="Select/Add nearest idle engineers"
key_desc_0224="Cycle through idle factories"
Expand Down
4 changes: 2 additions & 2 deletions lua/keymap/keyactions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ local keyActionsSelectionQuickSelect = {
category = 'selection',
},
['goto_commander'] = {
action = 'UI_SelectByCategory +nearest +goto COMMAND',
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").SelectCommander(true)',
category = 'selection',
},
['select_commander'] = {
action = 'UI_SelectByCategory +nearest COMMAND',
action = 'UI_Lua import("/lua/keymap/misckeyactions.lua").SelectCommander(false)',
category = 'selection',
},
['select_all'] = {
Expand Down
4 changes: 2 additions & 2 deletions lua/keymap/keydescriptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ keyDescriptions = {
['select_all_mex'] = '<LOC key_desc_0218>Select all mass extractors.',
['select_nearest_idle_lt_mex'] = '<LOC key_desc_0219>Select nearest onscreen lowest tech idle mass extractor.',

['acu_select_cg'] = '<LOC key_desc_0220>Select ACU (control group)',
['acu_append_cg'] = '<LOC key_desc_0221>Append ACU to selection (control group)',
['acu_select_cg'] = '<LOC key_desc_0220>Select ACU (double tap to zoom)',
['acu_append_cg'] = '<LOC key_desc_0221>Append ACU to selection (double tap to zoom)',
['select_nearest_idle_eng_not_acu'] = '<LOC key_desc_0222>Select nearest idle engineer (not ACU)',
['add_nearest_idle_engineers_seq'] = '<LOC key_desc_0223>Select/Add nearest idle engineers',
['cycle_idle_factories'] = '<LOC key_desc_0224>Cycle through idle factories',
Expand Down
32 changes: 30 additions & 2 deletions lua/keymap/misckeyactions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local Prefs = import("/lua/user/prefs.lua")
local SelectionUtils = import("/lua/ui/game/selection.lua")
local SetIgnoreSelection = import("/lua/ui/game/gamemain.lua").SetIgnoreSelection

local lockZoomEnable = false
function lockZoom()
Expand Down Expand Up @@ -200,9 +201,9 @@ function ACUSelectCG()
local curTime = GetSystemTimeSeconds()
local diffTime = curTime - lastACUSelectionTime
if diffTime > 1.0 then
ConExecute('UI_SelectByCategory +nearest COMMAND')
SelectCommander(false)
else
ConExecute('UI_SelectByCategory +nearest +goto COMMAND')
SelectCommander(true)
end

lastACUSelectionTime = curTime
Expand Down Expand Up @@ -662,3 +663,30 @@ SelectAllResourceConsumers = function(onscreen)

SelectUnits(units)
end

--- Select the commander with an option to zoom to. Will search for commanders in transports if none are found otherwise.
---@param zoomTo boolean
SelectCommander = function(zoomTo)
UISelectionByCategory("COMMAND", false, false, true, false)
local selectedUnits = GetSelectedUnits()
if not selectedUnits then
SetIgnoreSelection(true)
UISelectionByCategory("CANTRANSPORTCOMMANDER", false, false, false, false)
local transports = GetSelectedUnits()
SelectUnits(nil)
SetIgnoreSelection(false)
for _, transport in transports do
local attachedCommanders = EntityCategoryFilterDown(categories.COMMAND, GetAttachedUnitsList({transport}))
if attachedCommanders and table.getn(attachedCommanders) > 0 then
if zoomTo then
UISelectAndZoomTo(transport, 0)
else
SelectUnits({transport})
end
break
end
end
elseif zoomTo then
UIZoomTo(selectedUnits, 0)
end
end

0 comments on commit 012e944

Please sign in to comment.