From 012e94447e9f41a1523cf8b56e3499424cf103b3 Mon Sep 17 00:00:00 2001 From: clyf Date: Tue, 19 Nov 2024 16:37:01 -0500 Subject: [PATCH] Commander Transport Search Hotkey Upgrade (#6534) 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 --- changelog/snippets/features.6534.md | 1 + loc/CZ/strings_db.lua | 4 ++-- loc/PL/strings_db.lua | 4 ++-- loc/US/strings_db.lua | 4 ++-- lua/keymap/keyactions.lua | 4 ++-- lua/keymap/keydescriptions.lua | 4 ++-- lua/keymap/misckeyactions.lua | 32 +++++++++++++++++++++++++++-- 7 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 changelog/snippets/features.6534.md diff --git a/changelog/snippets/features.6534.md b/changelog/snippets/features.6534.md new file mode 100644 index 0000000000..3dbed32689 --- /dev/null +++ b/changelog/snippets/features.6534.md @@ -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 \ No newline at end of file diff --git a/loc/CZ/strings_db.lua b/loc/CZ/strings_db.lua index f7145683fa..bdd4b20586 100644 --- a/loc/CZ/strings_db.lua +++ b/loc/CZ/strings_db.lua @@ -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" diff --git a/loc/PL/strings_db.lua b/loc/PL/strings_db.lua index 355e703fe3..accaef2e45 100644 --- a/loc/PL/strings_db.lua +++ b/loc/PL/strings_db.lua @@ -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" diff --git a/loc/US/strings_db.lua b/loc/US/strings_db.lua index f19efe6f6e..9110ab2628 100644 --- a/loc/US/strings_db.lua +++ b/loc/US/strings_db.lua @@ -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" diff --git a/lua/keymap/keyactions.lua b/lua/keymap/keyactions.lua index 0bb395a03b..4a4d52d8f1 100755 --- a/lua/keymap/keyactions.lua +++ b/lua/keymap/keyactions.lua @@ -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'] = { diff --git a/lua/keymap/keydescriptions.lua b/lua/keymap/keydescriptions.lua index 586fb6263d..0038d15413 100755 --- a/lua/keymap/keydescriptions.lua +++ b/lua/keymap/keydescriptions.lua @@ -312,8 +312,8 @@ keyDescriptions = { ['select_all_mex'] = 'Select all mass extractors.', ['select_nearest_idle_lt_mex'] = 'Select nearest onscreen lowest tech idle mass extractor.', - ['acu_select_cg'] = 'Select ACU (control group)', - ['acu_append_cg'] = 'Append ACU to selection (control group)', + ['acu_select_cg'] = 'Select ACU (double tap to zoom)', + ['acu_append_cg'] = 'Append ACU to selection (double tap to zoom)', ['select_nearest_idle_eng_not_acu'] = 'Select nearest idle engineer (not ACU)', ['add_nearest_idle_engineers_seq'] = 'Select/Add nearest idle engineers', ['cycle_idle_factories'] = 'Cycle through idle factories', diff --git a/lua/keymap/misckeyactions.lua b/lua/keymap/misckeyactions.lua index 7ab142d2bc..97a2ee300c 100644 --- a/lua/keymap/misckeyactions.lua +++ b/lua/keymap/misckeyactions.lua @@ -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() @@ -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 @@ -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 \ No newline at end of file