-
Notifications
You must be signed in to change notification settings - Fork 57
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 option to specify the amount of selectable units in preference menu #479
base: master
Are you sure you want to change the base?
Add option to specify the amount of selectable units in preference menu #479
Conversation
Add dropdown menu for specify the number of units that can be selected.
A new variable is added to let players change the amount of selectable units
Now the option to select the amount of unit works with the changes applied only if the Ok button is pressed.
scripts/menus/options.lua
Outdated
local maxSelectableUnits = {9, 12, 18, 50, 100, 200} | ||
local maxSelectableUnitsList = {"9", "12", "18", "50", "100", "200"} |
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.
Sad to duplicate list.
int<->string conversion can be done on the fly IMO.
Textfield/spinbox is another option. Not sure we have validator though.
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.
The conversion from int to string and vice versa is easy, that's true.
I was thinking this change
local maxSelectableUnitsList = {"9", "12", "18", "50", "100", "200"}
menu:addLabel(_("Selectable units:"), 225, 28 + 19 * 8 + 5, Fonts["game"], false)
local maxSelectableUnitsListDD = menu:addDropDown(maxSelectableUnitsList, 225, 28 + 19 * 9 + 5, function(dd) end)
-- Get the index of the MaxSelectableUnits from list
local idx_msu = 0
for i,v in ipairs(maxSelectableUnitsList) do
if tonumber(v) == wc2.preferences.MaxSelectableUnits then
idx_msu = i - 1
break
end
end
maxSelectableUnitsListDD:setSelected(idx_msu)
maxSelectableUnitsListDD:setActionCallback(
function()
Preference.MaxSelectableUnits = tonumber(maxSelectableUnitsListDD:getSelected())
end
)
maxSelectableUnitsListDD:setSize(40, 16)
The problem I have is the dropDown function getSelected()
doesn't return the value from the list but the index of it. For example if I select 18 the function will return 2 and not 18.
I cannot find the function that actually returns the value I want and not the index from it.
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.
ImageDropDownWidget
has std::string getSelectedItem()
(in trunk, not in 3.3.2).
Else capture the table maxSelectableUnitsList
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.
I forgot to mention that I did already test that
maxSelectableUnitsListDD:setActionCallback(
function()
Preference.MaxSelectableUnits = maxSelectableUnitsListDD:getSelectedItem()
end
)
But I got this error
[string "/home/not_important/.stratagus/data.Wargus/scripts..."]:410: attempt to call method 'getSelectedItem' (a nil value)
Is this function added recently?
Because I'm testing the changes on the stable version (3.3.2)
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.
Indeed, not present in 3.3.2
Was added by Wargus/stratagus@425fa26
so 1 year and some days.
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.
By the way I have solved with this code:
maxSelectableUnitsListDD:setActionCallback(
function()
Preference.MaxSelectableUnits = tonumber(maxSelectableUnitsList[maxSelectableUnitsListDD:getSelected() + 1])
end
)
Since war1gus has this option I found weird that wargus doesn't have this option.
Basically I have added a new variable in the table of default preferences and in the option menu a new drop down menu has been added to specify the number of possible selectable units.
Here are the screenshots for the changes