-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add widgetHandler:GetSelectedUnits. #4660
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function widget:GetInfo() | ||
return { | ||
name = "Unhandled Commands", | ||
desc = "handles unhandled commands.", | ||
author = "Amnykon", | ||
date = "March 22, 2022", | ||
license = "GNU GPL, v2 or later", | ||
layer = math.huge, | ||
handler = true, | ||
enabled = true -- loaded by default? | ||
} | ||
end | ||
|
||
-------------------------------------------------------------------------------- | ||
-------------------------------------------------------------------------------- | ||
|
||
function widget:CommandNotify(id, params, options) | ||
local units = widgetHandler:GetSelectedUnits(id, params, options) | ||
for i=1,#units do | ||
widgetHandler:UnitCommandNotify(units[i], id, params, options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default behavior does not call widgetHandler:UnitCommandNotify, preventing widgets from using this hook. |
||
end | ||
return true | ||
end | ||
|
||
function widget:UnitCommandNotify(unitID, id, params, options) | ||
Spring.GiveOrderToUnit (unitID, id, params, options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. calls that use this check for unhanded events and call this anyway. This makes that calls easier as they don't need to check if it is unhanded. |
||
return true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,6 +268,7 @@ local callInLists = { | |
'Shutdown', | ||
'Update', | ||
'TextCommand', | ||
'GetSelectedUnits', | ||
'CommandNotify', | ||
'UnitCommandNotify', | ||
'AddConsoleLine', | ||
|
@@ -1388,6 +1389,20 @@ function widgetHandler:ConfigureLayout(command) | |
return false | ||
end | ||
|
||
function widgetHandler:GetSelectedUnits(id, params, options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This callin seems misnamed. Spring.GetSelectedUnits already exists but widget:GetSelectedUnits seems to be doing something different. Also why is a callin a getter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would widgetHandler:filterSelectedUnits(selected, id, params, options) be better. and make callers call Spring.GetSelectedUnits() for selected argument? should widgetHandler call Spring.GetSelectedUnits() if selected is nil, as Spring.GetSelectedUnits() is the expected value for this argument? |
||
local selected = Spring.GetSelectedUnits() | ||
|
||
for _, w in r_ipairs(self.CommandNotifyList) do | ||
if w.GetSelectedUnits then | ||
local modified = w:GetSelectedUnits(selected, id, params, options) | ||
if modified then | ||
selected = modified | ||
end | ||
end | ||
end | ||
return selected | ||
end | ||
|
||
function widgetHandler:CommandNotify(id, params, options) | ||
for _, w in r_ipairs(self.CommandNotifyList) do | ||
if (w:CommandNotify(id, params, options)) then | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unhanded behavior does not call widgetHandler:GetSelectedUnits, which does not allow widgets to modify the selection units.