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

Add option to specify the amount of selectable units in preference menu #479

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

SimoneStarace
Copy link
Contributor

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
Screenshot from 2024-11-28 15-33-58
Screenshot from 2024-11-28 15-34-03

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 Show resolved Hide resolved
scripts/stratagus.lua Outdated Show resolved Hide resolved
Comment on lines 395 to 396
local maxSelectableUnits = {9, 12, 18, 50, 100, 200}
local maxSelectableUnitsList = {"9", "12", "18", "50", "100", "200"}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@Jarod42 Jarod42 Nov 28, 2024

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

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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
   )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants