AUTOLASE - less menu builds

This commit is contained in:
Applevangelist 2024-05-27 18:31:14 +02:00
parent 7c0605e82f
commit 09372df86d

View File

@ -325,46 +325,51 @@ end
function AUTOLASE:SetPilotMenu() function AUTOLASE:SetPilotMenu()
if self.usepilotset then if self.usepilotset then
local pilottable = self.pilotset:GetSetObjects() or {} local pilottable = self.pilotset:GetSetObjects() or {}
local grouptable = {}
for _,_unit in pairs (pilottable) do for _,_unit in pairs (pilottable) do
local Unit = _unit -- Wrapper.Unit#UNIT local Unit = _unit -- Wrapper.Unit#UNIT
if Unit and Unit:IsAlive() then if Unit and Unit:IsAlive() then
local Group = Unit:GetGroup() local Group = Unit:GetGroup()
local GroupName = Group:GetName() or "none"
local unitname = Unit:GetName() local unitname = Unit:GetName()
if self.playermenus[unitname] then self.playermenus[unitname]:Remove() end if not grouptable[GroupName] == true then
local lasetopm = MENU_GROUP:New(Group,"Autolase",nil) if self.playermenus[unitname] then self.playermenus[unitname]:Remove() end -- menus
self.playermenus[unitname] = lasetopm local lasetopm = MENU_GROUP:New(Group,"Autolase",nil)
local lasemenu = MENU_GROUP_COMMAND:New(Group,"Status",lasetopm,self.ShowStatus,self,Group,Unit) self.playermenus[unitname] = lasetopm
if self.smokemenu then local lasemenu = MENU_GROUP_COMMAND:New(Group,"Status",lasetopm,self.ShowStatus,self,Group,Unit)
local smoke = (self.smoketargets == true) and "off" or "on" if self.smokemenu then
local smoketext = string.format("Switch smoke targets to %s",smoke) local smoke = (self.smoketargets == true) and "off" or "on"
local smokemenu = MENU_GROUP_COMMAND:New(Group,smoketext,lasetopm,self.SetSmokeTargets,self,(not self.smoketargets)) local smoketext = string.format("Switch smoke targets to %s",smoke)
end local smokemenu = MENU_GROUP_COMMAND:New(Group,smoketext,lasetopm,self.SetSmokeTargets,self,(not self.smoketargets))
if self.threatmenu then end -- smokement
local threatmenutop = MENU_GROUP:New(Group,"Set min lasing threat",lasetopm) if self.threatmenu then
for i=0,10,2 do local threatmenutop = MENU_GROUP:New(Group,"Set min lasing threat",lasetopm)
local text = "Threatlevel "..tostring(i) for i=0,10,2 do
local threatmenu = MENU_GROUP_COMMAND:New(Group,text,threatmenutop,self.SetMinThreatLevel,self,i) local text = "Threatlevel "..tostring(i)
end local threatmenu = MENU_GROUP_COMMAND:New(Group,text,threatmenutop,self.SetMinThreatLevel,self,i)
end end -- threatlevel
for _,_grp in pairs(self.RecceSet.Set) do end -- threatmenu
local grp = _grp -- Wrapper.Group#GROUP for _,_grp in pairs(self.RecceSet.Set) do
local unit = grp:GetUnit(1) local grp = _grp -- Wrapper.Group#GROUP
--local name = grp:GetName() local unit = grp:GetUnit(1)
if unit and unit:IsAlive() then --local name = grp:GetName()
local name = unit:GetName() if unit and unit:IsAlive() then
local mname = string.gsub(name,".%d+.%d+$","") local name = unit:GetName()
local code = self:GetLaserCode(name) local mname = string.gsub(name,".%d+.%d+$","")
local unittop = MENU_GROUP:New(Group,"Change laser code for "..mname,lasetopm) local code = self:GetLaserCode(name)
for _,_code in pairs(self.LaserCodes) do local unittop = MENU_GROUP:New(Group,"Change laser code for "..mname,lasetopm)
local text = tostring(_code) for _,_code in pairs(self.LaserCodes) do
if _code == code then text = text.."(*)" end local text = tostring(_code)
local changemenu = MENU_GROUP_COMMAND:New(Group,text,unittop,self.SetRecceLaserCode,self,name,_code,true) if _code == code then text = text.."(*)" end
end local changemenu = MENU_GROUP_COMMAND:New(Group,text,unittop,self.SetRecceLaserCode,self,name,_code,true)
end end -- Codes
end end -- unit alive
end -- Recceset
grouptable[GroupName] = true
end -- grouptable[GroupName]
--lasemenu:Refresh() --lasemenu:Refresh()
end end -- unit alive
end end -- pilot loop
else else
if not self.NoMenus then if not self.NoMenus then
self.Menu = MENU_COALITION_COMMAND:New(self.coalition,"Autolase",nil,self.ShowStatus,self) self.Menu = MENU_COALITION_COMMAND:New(self.coalition,"Autolase",nil,self.ShowStatus,self)