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,12 +325,15 @@ 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
if self.playermenus[unitname] then self.playermenus[unitname]:Remove() end -- menus
local lasetopm = MENU_GROUP:New(Group,"Autolase",nil) local lasetopm = MENU_GROUP:New(Group,"Autolase",nil)
self.playermenus[unitname] = lasetopm self.playermenus[unitname] = lasetopm
local lasemenu = MENU_GROUP_COMMAND:New(Group,"Status",lasetopm,self.ShowStatus,self,Group,Unit) local lasemenu = MENU_GROUP_COMMAND:New(Group,"Status",lasetopm,self.ShowStatus,self,Group,Unit)
@ -338,14 +341,14 @@ function AUTOLASE:SetPilotMenu()
local smoke = (self.smoketargets == true) and "off" or "on" local smoke = (self.smoketargets == true) and "off" or "on"
local smoketext = string.format("Switch smoke targets to %s",smoke) local smoketext = string.format("Switch smoke targets to %s",smoke)
local smokemenu = MENU_GROUP_COMMAND:New(Group,smoketext,lasetopm,self.SetSmokeTargets,self,(not self.smoketargets)) local smokemenu = MENU_GROUP_COMMAND:New(Group,smoketext,lasetopm,self.SetSmokeTargets,self,(not self.smoketargets))
end end -- smokement
if self.threatmenu then if self.threatmenu then
local threatmenutop = MENU_GROUP:New(Group,"Set min lasing threat",lasetopm) local threatmenutop = MENU_GROUP:New(Group,"Set min lasing threat",lasetopm)
for i=0,10,2 do for i=0,10,2 do
local text = "Threatlevel "..tostring(i) local text = "Threatlevel "..tostring(i)
local threatmenu = MENU_GROUP_COMMAND:New(Group,text,threatmenutop,self.SetMinThreatLevel,self,i) local threatmenu = MENU_GROUP_COMMAND:New(Group,text,threatmenutop,self.SetMinThreatLevel,self,i)
end end -- threatlevel
end end -- threatmenu
for _,_grp in pairs(self.RecceSet.Set) do for _,_grp in pairs(self.RecceSet.Set) do
local grp = _grp -- Wrapper.Group#GROUP local grp = _grp -- Wrapper.Group#GROUP
local unit = grp:GetUnit(1) local unit = grp:GetUnit(1)
@ -359,12 +362,14 @@ function AUTOLASE:SetPilotMenu()
local text = tostring(_code) local text = tostring(_code)
if _code == code then text = text.."(*)" end if _code == code then text = text.."(*)" end
local changemenu = MENU_GROUP_COMMAND:New(Group,text,unittop,self.SetRecceLaserCode,self,name,_code,true) local changemenu = MENU_GROUP_COMMAND:New(Group,text,unittop,self.SetRecceLaserCode,self,name,_code,true)
end end -- Codes
end end -- unit alive
end 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)