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
Open
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
84 changes: 54 additions & 30 deletions scripts/menus/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,34 @@ function RunPreferencesMenu()
SetFogOfWarType(fogOfWarTypes[fogOfWarType:getSelected() + 1])
end)
fogOfWarType:setSize(120, 16)

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(maxSelectableUnitsList[maxSelectableUnitsListDD:getSelected() + 1])
end
)
maxSelectableUnitsListDD:setSize(40, 16)

local fowBilinear = menu:addImageCheckBox(_("Bilinear fog"), 225, 28 + 19 * 8 + 10, offi, offi2, oni, oni2, function()end)
local fowBilinear = menu:addImageCheckBox(_("Bilinear fog"), 225, 28 + 19 * 10 + 10, offi, offi2, oni, oni2, function()end)
fowBilinear:setMarked(GetIsFogOfWarBilinear())
fowBilinear:setActionCallback(
function()
SetFogOfWarBilinear(fowBilinear:isMarked())
end)

local hwCursor = menu:addImageCheckBox(_("Hardware cursor"), 225, 28 + 19 * 9 + 10, offi, offi2, oni, oni2, function()end)
local hwCursor = menu:addImageCheckBox(_("Hardware cursor"), 225, 28 + 19 * 11 + 10, offi, offi2, oni, oni2, function()end)
hwCursor:setMarked(wc2.preferences.HardwareCursor)
hwCursor:setActionCallback(
function()
Expand All @@ -411,34 +430,39 @@ function RunPreferencesMenu()
menu:addLabel(_("~!* - requires restart"), 10, 10 + 18 * 16, Fonts["game"], false)

menu:addHalfButton("~!OK", "o", 206, 352 - 40,
function()
wc2.preferences.GrabMouse = GetGrabMouse()
wc2.preferences.ShowCommandKey = UI.ButtonPanel.ShowCommandKey
wc2.preferences.MineNotifications = Preference.MineNotifications
wc2.preferences.ShowDamage = showDamage:isMarked()
wc2.preferences.ShowButtonPopups = showButtonPopups:isMarked()
wc2.preferences.UseFancyBuildings = useFancyBuildings:isMarked()
wc2.preferences.ShowMessages = Preference.ShowMessages
wc2.preferences.PauseOnLeave = Preference.PauseOnLeave
wc2.preferences.EnhancedEffects = enhancedEffects:isMarked()
wc2.preferences.DeselectInMine = Preference.DeselectInMine
wc2.preferences.SimplifiedAutoTargeting = Preference.SimplifiedAutoTargeting
wc2.preferences.FogOfWarType = fogOfWarTypes[fogOfWarType:getSelected() + 1]
wc2.preferences.FogOfWarBilinear = fowBilinear:isMarked()

if (not IsNetworkGame()) then
wc2.preferences.FogOfWar = fogOfWar:isMarked()
end
if Preference.ShowOrders > 0 then
wc2.preferences.ShowOrders = true
else
wc2.preferences.ShowOrders = false
end
wc2.preferences.SelectionStyle = selectionStyleList[selectionStyle:getSelected() + 1]
wc2.preferences.ViewportMode = viewportMode:getSelected()
SavePreferences()
menu:stop(1)
end)
function()
wc2.preferences.GrabMouse = GetGrabMouse()
wc2.preferences.ShowCommandKey = UI.ButtonPanel.ShowCommandKey
wc2.preferences.MineNotifications = Preference.MineNotifications
wc2.preferences.ShowDamage = showDamage:isMarked()
wc2.preferences.ShowButtonPopups = showButtonPopups:isMarked()
wc2.preferences.UseFancyBuildings = useFancyBuildings:isMarked()
wc2.preferences.ShowMessages = Preference.ShowMessages
wc2.preferences.PauseOnLeave = Preference.PauseOnLeave
wc2.preferences.EnhancedEffects = enhancedEffects:isMarked()
wc2.preferences.DeselectInMine = Preference.DeselectInMine
wc2.preferences.SimplifiedAutoTargeting = Preference.SimplifiedAutoTargeting
wc2.preferences.FogOfWarType = fogOfWarTypes[fogOfWarType:getSelected() + 1]
wc2.preferences.FogOfWarBilinear = fowBilinear:isMarked()
if (Preference.MaxSelectableUnits ~= nil) then
wc2.preferences.MaxSelectableUnits = Preference.MaxSelectableUnits
end
if (not IsNetworkGame()) then
wc2.preferences.FogOfWar = fogOfWar:isMarked()
end
if Preference.ShowOrders > 0 then
wc2.preferences.ShowOrders = true
else
wc2.preferences.ShowOrders = false
end
wc2.preferences.SelectionStyle = selectionStyleList[selectionStyle:getSelected() + 1]
wc2.preferences.ViewportMode = viewportMode:getSelected()
SavePreferences()
-- Apply the changes
SetMaxSelectable(wc2.preferences.MaxSelectableUnits)
menu:stop(1)
end
)

menu:addHalfButton(_("Cancel (~<Esc~>)"), "escape", 40, 352 - 40,
function()
Expand Down
9 changes: 5 additions & 4 deletions scripts/stratagus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,6 @@ AStar("fixed-unit-cost", 1000, "moving-unit-cost", 20, "know-unseen-terrain", "u

-------------------------------------------------------------------------------

-- Maximum number of selectable units
SetMaxSelectable(18)

-- All player food unit limit
SetAllPlayersUnitLimit(200)
-- All player building limit
Expand Down Expand Up @@ -441,7 +438,8 @@ local defaultPreferences = {
SimplifiedAutoTargeting = true,
FogOfWarType = "fast", -- "enhanced", "tiled", "fast". Tiled and fast types of FOW don't work with shadow casting FOV.
FogOfWarBilinear = false, -- Enable/Disable bilinear filtration for fog of war
MapGrid = false
MapGrid = false,
MaxSelectableUnits = 18 -- Possible values: 9, 12, 18, 50, 100, 200
}

--- Skirmish Setup --------------
Expand All @@ -464,6 +462,9 @@ end
CompleteMissingValues(wc2.preferences, defaultPreferences)
SavePreferences()

-- Maximum number of selectable units
SetMaxSelectable(wc2.preferences.MaxSelectableUnits)

SetTitleScreens(
{Image = "ui/black_title.png", Timeout = 1},
{Image = "videos/logo.ogv"},
Expand Down