Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commander Transport Search Hotkey Upgrade #6534

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading