Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions language/en/interface.json
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,12 @@
"smartselect_includebuildings_descr": "When rectangle-drag-selecting an area, include building units too?\n\nDisabled: non-mobile units will be excluded (hold Shift to override)\nNote: Construction Turrets will always be selected",
"smartselect_includebuilders": "include builders (if above is off)",
"smartselect_includebuilders_descr": "When rectangle-drag-selecting an area, exclude builder units (hold Shift to override)",
"smartselect_includeantinuke": "include antinuke units (if above is off)",
"smartselect_includeantinuke_descr": "When rectangle-drag-selecting an area, exclude antinuke units (hold Shift to override)",
"smartselect_includeradar": "include radar units (if above is off)",
"smartselect_includeradar_descr": "When rectangle-drag-selecting an area, exclude radar units (hold Shift to override)",
"smartselect_includejammer": "include jammer units (if above is off)",
"smartselect_includejammer_descr": "When rectangle-drag-selecting an area, exclude jammer units (hold Shift to override)",
"onlyfighterspatrol": "Only fighters patrol",
"onlyfighterspatrol_descr": "Only fighters obey a factory's patrol route after leaving airlab.",
"fightersfly": "Set fighters on Fly mode",
Expand Down
28 changes: 27 additions & 1 deletion luaui/Widgets/gui_options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4605,7 +4605,27 @@ function init()
saveOptionValue('SmartSelect', 'smartselect', 'setIncludeBuilders', { 'includeBuilders' }, value)
end,
},

{ id = "smartselect_includeantinuke", group = "game", category = types.basic, name = widgetOptionColor .. " " .. Spring.I18N('ui.settings.option.smartselect_includeantinuke'), type = "bool", value = false, description = Spring.I18N('ui.settings.option.smartselect_includeantinuke_descr'),
onload = function(i)
end,
onchange = function(i, value)
saveOptionValue('SmartSelect', 'smartselect', 'setIncludeAntinuke', { 'includeAntinuke' }, value)
end,
},
{ id = "smartselect_includeradar", group = "game", category = types.basic, name = widgetOptionColor .. " " .. Spring.I18N('ui.settings.option.smartselect_includeradar'), type = "bool", value = false, description = Spring.I18N('ui.settings.option.smartselect_includeradar_descr'),
onload = function(i)
end,
onchange = function(i, value)
saveOptionValue('SmartSelect', 'smartselect', 'setIncludeRadar', { 'includeRadar' }, value)
end,
},
{ id = "smartselect_includejammer", group = "game", category = types.basic, name = widgetOptionColor .. " " .. Spring.I18N('ui.settings.option.smartselect_includejammer'), type = "bool", value = false, description = Spring.I18N('ui.settings.option.smartselect_includejammer_descr'),
onload = function(i)
end,
onchange = function(i, value)
saveOptionValue('SmartSelect', 'smartselect', 'setIncludeJammer', { 'includeJammer' }, value)
end,
},

{ id = "prioconturrets", group = "game", category = types.basic, widget = "Priority Construction Turrets", name = Spring.I18N('ui.settings.option.prioconturrets'), type = "bool", value = GetWidgetToggleValue("Priority Construction Turrets"), description = Spring.I18N('ui.settings.option.prioconturrets_descr') },

Expand Down Expand Up @@ -6425,9 +6445,15 @@ function init()
if WG['smartselect'] == nil then
options[getOptionByID('smartselect_includebuildings')] = nil
options[getOptionByID('smartselect_includebuilders')] = nil
options[getOptionByID('smartselect_includeantinuke')] = nil
options[getOptionByID('smartselect_includeradar')] = nil
options[getOptionByID('smartselect_includejammer')] = nil
else
options[getOptionByID('smartselect_includebuildings')].value = WG['smartselect'].getIncludeBuildings()
options[getOptionByID('smartselect_includebuilders')].value = WG['smartselect'].getIncludeBuilders()
options[getOptionByID('smartselect_includeantinuke')].value = WG['smartselect'].getIncludeAntinuke()
options[getOptionByID('smartselect_includeradar')].value = WG['smartselect'].getIncludeRadar()
options[getOptionByID('smartselect_includejammer')].value = WG['smartselect'].getIncludeJammer()
end

if WG['snow'] ~= nil and WG['snow'].getSnowMap ~= nil then
Expand Down
94 changes: 77 additions & 17 deletions luaui/Widgets/unit_smart_select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ local referenceX, referenceY
local selectBuildingsWithMobile = false -- whether to select buildings when mobile units are inside selection rectangle
local includeNanosAsMobile = true
local includeBuilders = false
local includeAntinuke = false
local includeRadar = false
local includeJammer = false

-- selection modifiers
local mods = {
Expand Down Expand Up @@ -78,6 +81,10 @@ local combatFilter = {}
local builderFilter = {}
local buildingFilter = {}
local mobileFilter = {}
local utilFilter = {}
local antinukeFilter = {}
local radarFilter = {}
local jammerFilter = {}
local customFilter = {}

for udid, udef in pairs(UnitDefs) do
Expand All @@ -89,6 +96,10 @@ for udid, udef in pairs(UnitDefs) do
local builder = (udef.canReclaim and udef.reclaimSpeed > 0) or (udef.canResurrect and udef.resurrectSpeed > 0) or (udef.canRepair and udef.repairSpeed > 0) or (udef.buildOptions and udef.buildOptions[1])
local building = (isMobile == false)
local combat = (not builder) and isMobile and (#udef.weapons > 0)
local isUtil = udef.customParams and udef.customParams.unitgroup == "util"
local antinuke = udef.customParams and udef.customParams.unitgroup == "antinuke"
local radar = isMobile and isUtil and udef.radarDistance > 0
local jammer = isMobile and isUtil and udef.radarDistanceJam > 0

if string.find(udef.name, 'armspid') or string.find(udef.name, 'leginfestor') then
builder = false
Expand All @@ -97,6 +108,25 @@ for udid, udef in pairs(UnitDefs) do
builderFilter[udid] = builder
buildingFilter[udid] = building
mobileFilter[udid] = isMobile
utilFilter[udid] = isUtil
antinukeFilter[udid] = antinuke
radarFilter[udid] = radar
jammerFilter[udid] = jammer
end

local function smartSelectIncludeFilter(udid)
local smartSelectFilters = {
{include = includeBuilders, filter = builderFilter},
{include = includeAntinuke, filter = antinukeFilter},
{include = includeRadar, filter = radarFilter},
{include = includeJammer, filter = jammerFilter}
}
for _, unit in ipairs(smartSelectFilters) do
if not unit.include and unit.filter[udid] then
return false
end
end
return true
end

local dualScreen
Expand Down Expand Up @@ -369,23 +399,23 @@ function widget:Update(dt)
end

if mobiles then
tmp = {}
local tmp2 = {}
local included = {}
local excluded = {}
for i = 1, #mouseSelection do
uid = mouseSelection[i]
udid = spGetUnitDefID(uid)
if buildingFilter[udid] == false then
if includeBuilders or not builderFilter[udid] then
tmp[#tmp + 1] = uid
if smartSelectIncludeFilter(udid) then
included[#included + 1] = uid
else
tmp2[#tmp2 + 1] = uid
excluded[#excluded + 1] = uid
end
end
end
if #tmp == 0 then
tmp = tmp2
if #included == 0 then
included = excluded
end
mouseSelection = tmp
mouseSelection = included
end
end

Expand Down Expand Up @@ -586,23 +616,23 @@ function widget:Initialize()
end

if mobiles then
tmp = {}
local tmp2 = {}
local included = {}
local excluded = {}
for i = 1, #mouseSelection do
uid = mouseSelection[i]
udid = spGetUnitDefID(uid)
if buildingFilter[udid] == false then
if includeBuilders or not builderFilter[udid] then
tmp[#tmp + 1] = uid
if smartSelectIncludeFilter(udid) then
included[#included + 1] = uid
else
tmp2[#tmp2 + 1] = uid
excluded[#excluded + 1] = uid
end
end
end
if #tmp == 0 then
tmp = tmp2
if #included == 0 then
included = excluded
end
mouseSelection = tmp
mouseSelection = included
end
end

Expand Down Expand Up @@ -656,6 +686,24 @@ function widget:Initialize()
WG['smartselect'].setIncludeBuilders = function(value)
includeBuilders = value
end
WG['smartselect'].getIncludeAntinuke = function()
return includeAntinuke
end
WG['smartselect'].setIncludeAntinuke = function(value)
includeAntinuke = value
end
WG['smartselect'].getIncludeRadar = function()
return includeRadar
end
WG['smartselect'].setIncludeRadar = function(value)
includeRadar = value
end
WG['smartselect'].getIncludeJammer = function()
return includeJammer
end
WG['smartselect'].setIncludeJammer = function(value)
includeJammer = value
end

widget:ViewResize()
end
Expand All @@ -664,7 +712,10 @@ function widget:GetConfigData()
return {
selectBuildingsWithMobile = selectBuildingsWithMobile,
includeNanosAsMobile = includeNanosAsMobile,
includeBuilders = includeBuilders
includeBuilders = includeBuilders,
includeAntinuke = includeAntinuke,
includeRadar = includeRadar,
includeJammer = includeJammer
}
end

Expand All @@ -678,4 +729,13 @@ function widget:SetConfigData(data)
if data.includeBuilders ~= nil then
includeBuilders = data.includeBuilders
end
if data.includeAntinuke ~= nil then
includeAntinuke = data.includeAntinuke
end
if data.includeRadar ~= nil then
includeRadar = data.includeRadar
end
if data.includeJammer ~= nil then
includeJammer = data.includeJammer
end
end