-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- include("keysym.h.lua") function widget:GetInfo() return { name = "Auto group", desc = "Assigns new units to predefined groups. Ctrl+alt+0-9 setups auto group.", author = "Licho", date = "Mar 23, 2007", license = "GNU GPL, v2 or later", layer = 0, enabled = true -- loaded by default? } end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- local unit2group = {} --function widget:GetConfigData() -- return unit2group --end --function widget:SetConfigData(data) -- unit2group = data --end function widget:UnitFinished(unitID, unitDefID, unitTeam) if (unitTeam ~= Spring.GetMyTeamID() or unitID == nil) then return -- not my unit end local group = unit2group[unitDefID] if (group ~= nil) then Spring.SetUnitGroup(unitID, group) end end function GetNumFromGroupId(groupId) if groupId == 0 then return 10 else return groupId end end function widget:GroupChanged(id) local a,c,m,s = Spring.GetModKeyState() local gr if (c and a) then for id, group in ipairs(unit2group) do if (group == gr) then unit2group[id] = -1 unit2group[id] = nil table.remove(unit2group,id) end end for _, uid in ipairs(Spring.GetSelectedUnits()) do unit2group[Spring.GetUnitDefID(uid)] = id end end end -- function widget:KeyPress(key, modifier, isRepeat) -- if (modifier.ctrl and modifier.alt) then -- local gr -- if (key == KEYSYMS.N_0) then gr = 0 end -- if (key == KEYSYMS.N_1) then gr = 1 end -- if (key == KEYSYMS.N_2) then gr = 2 end -- if (key == KEYSYMS.N_3) then gr = 3 end -- if (key == KEYSYMS.N_4) then gr = 4 end -- if (key == KEYSYMS.N_5) then gr = 5 end -- if (key == KEYSYMS.N_6) then gr = 6 end -- if (key == KEYSYMS.N_7) then gr = 7 end -- if (key == KEYSYMS.N_8) then gr = 8 end -- if (key == KEYSYMS.N_9) then gr = 9 end -- if (gr ~= nil) then -- for id, group in ipairs(unit2group) do -- if (group == gr) then -- unit2group[id] = -1 -- unit2group[id] = nil -- table.remove(unit2group,id) -- end -- end -- for _, uid in ipairs(Spring.GetSelectedUnits()) do -- unit2group[Spring.GetUnitDefID(uid)] = gr -- end -- end -- end -- end --------------------------------------------------------------------------------