mirror of
https://gitlab.cs.fau.de/ik15ydit/latexandmore.git
synced 2024-11-22 11:49:32 +01:00
added alt override
cleaned up code
This commit is contained in:
parent
8fe2eb0dc6
commit
e383773ad3
@ -2,21 +2,77 @@
|
||||
local ref_low
|
||||
--medium (construction)
|
||||
local ref_medium
|
||||
local trigger = true
|
||||
|
||||
--header
|
||||
function widget:GetInfo()
|
||||
return {
|
||||
name = "Selection Priority",
|
||||
desc = "Sorts Units by Priority (atackunit>builder/commander>buildings)",
|
||||
author = "Sheppy",
|
||||
date = "2015",
|
||||
license = "PD", -- should be compatible with Spring
|
||||
license = "GPL",
|
||||
layer = 0,
|
||||
enabled = true
|
||||
}
|
||||
end
|
||||
|
||||
function widget:CommandNotify(cmdID, cmdParams, cmdOptions)
|
||||
if trigger then
|
||||
local selected = Spring.GetSelectedUnits()
|
||||
local low = {}
|
||||
local medium = {}
|
||||
local high = {}
|
||||
local deselect = 0
|
||||
local a = Spring.GetModKeyState() --alt ctrl ? shift , discard all but alt
|
||||
--do nothing if CTRL is pressed
|
||||
Spring.Echo(Spring.GetModKeyState())
|
||||
if a then return end
|
||||
--iterate Selection
|
||||
for i=1,200 do
|
||||
if selected[i] == nil then break end
|
||||
--get name to match
|
||||
defID = UnitDefs[Spring.GetUnitDefID(selected[i])].name
|
||||
--Check what we got in out selection
|
||||
if inTable(ref_low,defID) then
|
||||
table.insert(low,selected[i])
|
||||
elseif inTable(ref_medium,defID) then
|
||||
table.insert(medium,selected[i])
|
||||
if deselect == 0 then deselect = 1 end
|
||||
else
|
||||
table.insert(high,selected[i])
|
||||
if deselect < 2 then deselect = 2 end
|
||||
end
|
||||
end
|
||||
--discard selections
|
||||
if deselect == 1 then
|
||||
Spring.SelectUnitArray(medium,false)
|
||||
Spring.SelectUnitArray(high,true)
|
||||
elseif deselect == 2 then
|
||||
Spring.SelectUnitArray(high,false)
|
||||
end
|
||||
end
|
||||
|
||||
function inTable(tbl,item)
|
||||
for key, value in pairs(tbl) do
|
||||
if value == item then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--for debugging purpose only
|
||||
function debug()
|
||||
for key, value in pairs(medium) do
|
||||
Spring.Echo("val_med: " .. value)
|
||||
end
|
||||
for key, value in pairs(low) do
|
||||
Spring.Echo("val_low: " .. value)
|
||||
end
|
||||
for key, value in pairs(low) do
|
||||
Spring.Echo("val_high: " .. value)
|
||||
end
|
||||
end
|
||||
|
||||
--loading unit-names to match against
|
||||
function widget:Initialize()
|
||||
ref_medium = {
|
||||
--arm
|
||||
"armcom",
|
||||
@ -139,62 +195,5 @@ ref_low = {
|
||||
"corhlt",
|
||||
"corjamt"
|
||||
}
|
||||
Spring.Echo("Done.")
|
||||
trigger = false
|
||||
Spring.Echo("Namelist init done.")
|
||||
end
|
||||
local selected = Spring.GetSelectedUnits()
|
||||
local low = {}
|
||||
local medium = {}
|
||||
local high = {}
|
||||
local deselect = 0
|
||||
--if teamID ~= Spring.GetMyTeamID() then return end
|
||||
for i=1,200 do
|
||||
if selected[i] == nil then break end
|
||||
--get name to match
|
||||
defID = UnitDefs[Spring.GetUnitDefID(selected[i])].name
|
||||
--Spring.Echo(selected[i])
|
||||
--Check what we got in out selection
|
||||
if inTable(ref_low,defID) then
|
||||
table.insert(low,selected[i])
|
||||
--Spring.Echo("reflow")
|
||||
elseif inTable(ref_medium,defID) then
|
||||
--Spring.Echo("refmed")
|
||||
table.insert(medium,selected[i])
|
||||
if deselect == 0 then deselect = 1 end
|
||||
else
|
||||
--Spring.Echo("refhigh")
|
||||
table.insert(high,selected[i])
|
||||
if deselect < 2 then deselect = 2 end
|
||||
end
|
||||
end
|
||||
--debug()
|
||||
--discard selections
|
||||
if deselect == 1 then
|
||||
Spring.SelectUnitArray(medium,false)
|
||||
Spring.SelectUnitArray(high,true)
|
||||
elseif deselect == 2 then
|
||||
Spring.SelectUnitArray(high,false)
|
||||
end
|
||||
--Spring.Echo("Dis was: " .. deselect)
|
||||
end
|
||||
|
||||
function inTable(tbl,item)
|
||||
for key, value in pairs(tbl) do
|
||||
--Spring.Echo(key .. "val: " .. value)
|
||||
if value == item then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function debug()
|
||||
for key, value in pairs(medium) do
|
||||
Spring.Echo("val_med: " .. value)
|
||||
end
|
||||
for key, value in pairs(low) do
|
||||
Spring.Echo("val_low: " .. value)
|
||||
end
|
||||
for key, value in pairs(low) do
|
||||
Spring.Echo("val_high: " .. value)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user