#ClientMenu

This commit is contained in:
Applevangelist 2023-07-17 16:26:06 +02:00
parent e8ad649770
commit e8432db26e
4 changed files with 431 additions and 409 deletions

View File

@ -3,12 +3,14 @@
-- **Main Features:** -- **Main Features:**
-- --
-- * For complex, non-static menu structures -- * For complex, non-static menu structures
-- * Separation of menu tree creation from pushing it to clients -- * Lightweigt implementation as alternative to MENU
-- * Separation of menu tree creation from menu on the clients's side
-- * Works with a SET_CLIENT set of clients -- * Works with a SET_CLIENT set of clients
-- * Allow manipulation of the shadow tree in various ways -- * Allow manipulation of the shadow tree in various ways
-- * Push to all or only one client -- * Push to all or only one client
-- * Change entries' menu text, even if they have a sub-structure -- * Change entries' menu text
-- * Option to make an entry usable once -- * Option to make an entry usable once only across all clients
-- * Auto appends GROUP and CLIENT objects to menu calls
-- --
-- === -- ===
-- --
@ -55,7 +57,7 @@
CLIENTMENU = { CLIENTMENU = {
ClassName = "CLIENTMENUE", ClassName = "CLIENTMENUE",
lid = "", lid = "",
version = "0.0.2", version = "0.1.0",
name = nil, name = nil,
path = nil, path = nil,
group = nil, group = nil,
@ -94,16 +96,20 @@ function CLIENTMENU:NewEntry(Client,Text,Parent,Function,...)
end end
self.name = Text or "unknown entry" self.name = Text or "unknown entry"
if Parent then if Parent then
if Parent:IsInstanceOf("MENU_BASE") then
self.parentpath = Parent.MenuPath
else
self.parentpath = Parent:GetPath() self.parentpath = Parent:GetPath()
Parent:AddChild(self) Parent:AddChild(self)
end end
end
self.Parent = Parent self.Parent = Parent
self.Function = Function self.Function = Function
self.Functionargs = arg or {} self.Functionargs = arg or {}
table.insert(self.Functionargs,self.group) table.insert(self.Functionargs,self.group)
table.insert(self.Functionargs,self.client) table.insert(self.Functionargs,self.client)
if self.Functionargs and self.debug then if self.Functionargs and self.debug then
self:I({"Functionargs",self.Functionargs}) self:T({"Functionargs",self.Functionargs})
end end
if not self.Generic then if not self.Generic then
if Function ~= nil then if Function ~= nil then
@ -136,7 +142,7 @@ function CLIENTMENU:NewEntry(Client,Text,Parent,Function,...)
self.path[#self.path+1] = Text self.path[#self.path+1] = Text
end end
self.UUID = table.concat(self.path,";") self.UUID = table.concat(self.path,";")
self:I({self.UUID}) self:T({self.UUID})
self.Once = false self.Once = false
-- Log id. -- Log id.
self.lid=string.format("CLIENTMENU %s | %s | ", self.ID, self.name) self.lid=string.format("CLIENTMENU %s | %s | ", self.ID, self.name)
@ -144,6 +150,21 @@ function CLIENTMENU:NewEntry(Client,Text,Parent,Function,...)
return self return self
end end
--- Create a UUID
-- @param #CLIENTMENU self
-- @param #CLIENTMENU Parent The parent object if any
-- @param #string Text The menu entry text
-- @return #string UUID
function CLIENTMENU:CreateUUID(Parent,Text)
local path = {}
if Parent and Parent.path then
path = Parent.path
end
path[#path+1] = Text
local UUID = table.concat(path,";")
return UUID
end
--- Set the CLIENTMENUMANAGER for this entry. --- Set the CLIENTMENUMANAGER for this entry.
-- @param #CLIENTMENU self -- @param #CLIENTMENU self
-- @param #CLIENTMENUMANAGER Controller The controlling object. -- @param #CLIENTMENUMANAGER Controller The controlling object.
@ -166,9 +187,9 @@ end
-- @param #CLIENTMENU self -- @param #CLIENTMENU self
-- @return #CLIENTMENU self -- @return #CLIENTMENU self
function CLIENTMENU:RemoveF10() function CLIENTMENU:RemoveF10()
self:I(self.lid.."RemoveF10") self:T(self.lid.."RemoveF10")
if not self.Generic then if self.GroupID then
self:I(self.lid.."Removing") --self:I(self.lid.."Removing "..table.concat(self.path,";"))
missionCommands.removeItemForGroup(self.GroupID , self.path ) missionCommands.removeItemForGroup(self.GroupID , self.path )
end end
return self return self
@ -214,10 +235,10 @@ end
-- @param #CLIENTMENU self -- @param #CLIENTMENU self
-- @return #CLIENTMENU self -- @return #CLIENTMENU self
function CLIENTMENU:RemoveSubEntries() function CLIENTMENU:RemoveSubEntries()
self:I(self.lid.."RemoveSubEntries") self:T(self.lid.."RemoveSubEntries")
self:I({self.Children}) self:T({self.Children})
for _id,_entry in pairs(self.Children) do for _id,_entry in pairs(self.Children) do
self:I("Removing ".._id) self:T("Removing ".._id)
if _entry then if _entry then
_entry:RemoveSubEntries() _entry:RemoveSubEntries()
_entry:RemoveF10() _entry:RemoveF10()
@ -328,8 +349,22 @@ end
-- ## Add a single entry -- ## Add a single entry
-- --
-- local baimenu = menumgr:NewEntry("BAI",mymenu_lv1b) -- local baimenu = menumgr:NewEntry("BAI",mymenu_lv1b)
--
-- menumgr:AddEntry(baimenu) -- menumgr:AddEntry(baimenu)
-- --
-- ## Add an entry with a function
--
-- local baimenu = menumgr:NewEntry("Task Action", mymenu_lv1b, TestFunction, Argument1, Argument1)
--
-- Now, the class will **automatically append the call with GROUP and CLIENT objects**, as this is can only be done when pushing the entry to the clients. So, the actual function implementation needs to look like this:
--
-- function TestFunction( Argument1, Argument2, Group, Client)
--
-- **Caveat is**, that you need to ensure your arguments are not **nil** or **false**, as LUA will optimize those away. You would end up having Group and Client in wrong places in the function call. Hence,
-- if you need/ want to send **nil** or **false**, send a place holder instead and ensure your function can handle this, e.g.
--
-- local baimenu = menumgr:NewEntry("Task Action", mymenu_lv1b, TestFunction, "nil", Argument1)
--
-- ## Change the text of a leaf entry in the menu tree -- ## Change the text of a leaf entry in the menu tree
-- --
-- menumgr:ChangeEntryTextForAll(mymenu_lv1b,"Attack") -- menumgr:ChangeEntryTextForAll(mymenu_lv1b,"Attack")
@ -346,7 +381,7 @@ end
CLIENTMENUMANAGER = { CLIENTMENUMANAGER = {
ClassName = "CLIENTMENUMANAGER", ClassName = "CLIENTMENUMANAGER",
lid = "", lid = "",
version = "0.0.4", version = "0.1.0",
name = nil, name = nil,
clientset = nil, clientset = nil,
menutree = {}, menutree = {},
@ -370,7 +405,7 @@ function CLIENTMENUMANAGER:New(ClientSet, Alias)
-- Log id. -- Log id.
self.lid=string.format("CLIENTMENUMANAGER %s | %s | ", self.version, self.name) self.lid=string.format("CLIENTMENUMANAGER %s | %s | ", self.version, self.name)
if self.debug then if self.debug then
self:I(self.lid.."Created") self:T(self.lid.."Created")
end end
return self return self
end end
@ -396,12 +431,21 @@ function CLIENTMENUMANAGER:NewEntry(Text,Parent,Function,...)
return entry return entry
end end
--- Check matching entry in the generic structure by UUID.
-- @param #CLIENTMENUMANAGER self
-- @param #string UUID UUID of the menu entry.
-- @return #boolean Exists
function CLIENTMENUMANAGER:EntryUUIDExists(UUID)
local exists = self.flattree[UUID] and true or false
return exists
end
--- Find matching entry in the generic structure by UUID. --- Find matching entry in the generic structure by UUID.
-- @param #CLIENTMENUMANAGER self -- @param #CLIENTMENUMANAGER self
-- @param #string UUID UUID of the menu entry. -- @param #string UUID UUID of the menu entry.
-- @return #CLIENTMENU Entry The #CLIENTMENU object found or nil. -- @return #CLIENTMENU Entry The #CLIENTMENU object found or nil.
function CLIENTMENUMANAGER:FindEntryByUUID(UUID) function CLIENTMENUMANAGER:FindEntryByUUID(UUID)
self:I(self.lid.."FindEntryByUUID "..UUID or "None") self:T(self.lid.."FindEntryByUUID "..UUID or "None")
local entry = nil local entry = nil
for _gid,_entry in pairs(self.flattree) do for _gid,_entry in pairs(self.flattree) do
local Entry = _entry -- #CLIENTMENU local Entry = _entry -- #CLIENTMENU
@ -412,33 +456,82 @@ function CLIENTMENUMANAGER:FindEntryByUUID(UUID)
return entry return entry
end end
--- Find matching entry by text in the generic structure by UUID. --- Find matching entries by text in the generic structure by UUID.
-- @param #CLIENTMENUMANAGER self -- @param #CLIENTMENUMANAGER self
-- @param #string Text Text or partial text of the menu entry to find -- @param #string Text Text or partial text of the menu entry to find.
-- @param #CLIENTMENU Parent (Optional) Only find entries under this parent entry.
-- @return #table Table of matching UUIDs of #CLIENTMENU objects -- @return #table Table of matching UUIDs of #CLIENTMENU objects
-- @return #table Table of matching #CLIENTMENU objects -- @return #table Table of matching #CLIENTMENU objects
function CLIENTMENUMANAGER:FindUUIDsByText(Text) -- @return #number Number of matches
self:I(self.lid.."FindUUIDsByText "..Text or "None") function CLIENTMENUMANAGER:FindUUIDsByText(Text,Parent)
self:T(self.lid.."FindUUIDsByText "..Text or "None")
local matches = {} local matches = {}
local entries = {} local entries = {}
local n = 0
for _uuid,_entry in pairs(self.flattree) do for _uuid,_entry in pairs(self.flattree) do
local Entry = _entry -- #CLIENTMENU local Entry = _entry -- #CLIENTMENU
if Parent then
if Entry and string.find(Entry.name,Text) and string.find(Entry.UUID,Parent.UUID) then
table.insert(matches,_uuid)
table.insert(entries,Entry )
n=n+1
end
else
if Entry and string.find(Entry.name,Text) then if Entry and string.find(Entry.name,Text) then
table.insert(matches,_uuid) table.insert(matches,_uuid)
table.insert(entries,Entry ) table.insert(entries,Entry )
n=n+1
end end
end end
return matches, entries end
return matches, entries, n
end end
--- Find matching entries in the generic structure by the menu text. --- Find matching entries in the generic structure by the menu text.
-- @param #CLIENTMENUMANAGER self -- @param #CLIENTMENUMANAGER self
-- @param #string Text Text or partial text of the F10 menu entry. -- @param #string Text Text or partial text of the F10 menu entry.
-- @param #CLIENTMENU Parent (Optional) Only find entries under this parent entry.
-- @return #table Table of matching #CLIENTMENU objects. -- @return #table Table of matching #CLIENTMENU objects.
function CLIENTMENUMANAGER:FindEntriesByText(Text) -- @return #number Number of matches
self:I(self.lid.."FindEntriesByText "..Text or "None") function CLIENTMENUMANAGER:FindEntriesByText(Text,Parent)
local matches, objects = self:FindUUIDsByText(Text) self:T(self.lid.."FindEntriesByText "..Text or "None")
return objects local matches, objects, number = self:FindUUIDsByText(Text, Parent)
return objects, number
end
--- Find matching entries under a parent in the generic structure by UUID.
-- @param #CLIENTMENUMANAGER self
-- @param #CLIENTMENU Parent Find entries under this parent entry.
-- @return #table Table of matching UUIDs of #CLIENTMENU objects
-- @return #table Table of matching #CLIENTMENU objects
-- @return #number Number of matches
function CLIENTMENUMANAGER:FindUUIDsByParent(Parent)
self:T(self.lid.."FindUUIDsByParent")
local matches = {}
local entries = {}
local n = 0
for _uuid,_entry in pairs(self.flattree) do
local Entry = _entry -- #CLIENTMENU
if Parent then
if Entry and string.find(Entry.UUID,Parent.UUID) then
table.insert(matches,_uuid)
table.insert(entries,Entry )
n=n+1
end
end
end
return matches, entries, n
end
--- Find matching entries in the generic structure under a parent.
-- @param #CLIENTMENUMANAGER self
-- @param #CLIENTMENU Parent Find entries under this parent entry.
-- @return #table Table of matching #CLIENTMENU objects.
-- @return #number Number of matches
function CLIENTMENUMANAGER:FindEntriesByParent(Parent)
self:T(self.lid.."FindEntriesByParent")
local matches, objects, number = self:FindUUIDsByParent(Parent)
return objects, number
end end
--- Alter the text of a leaf entry in the generic structure and push to one specific client's F10 menu. --- Alter the text of a leaf entry in the generic structure and push to one specific client's F10 menu.
@ -468,8 +561,8 @@ end
-- @param Wrapper.Client#CLIENT Client (optional) If given, propagate only for this client. -- @param Wrapper.Client#CLIENT Client (optional) If given, propagate only for this client.
-- @return #CLIENTMENU Entry -- @return #CLIENTMENU Entry
function CLIENTMENUMANAGER:Propagate(Client) function CLIENTMENUMANAGER:Propagate(Client)
self:I(self.lid.."Propagate") self:T(self.lid.."Propagate")
self:I(Client) self:T(Client)
local Set = self.clientset.Set local Set = self.clientset.Set
if Client then if Client then
Set = {Client} Set = {Client}
@ -483,12 +576,12 @@ function CLIENTMENUMANAGER:Propagate(Client)
self.playertree[playername] = {} self.playertree[playername] = {}
end end
for level,branch in pairs (self.menutree) do for level,branch in pairs (self.menutree) do
self:I("Building branch:" .. level) self:T("Building branch:" .. level)
for _,leaf in pairs(branch) do for _,leaf in pairs(branch) do
self:I("Building leaf:" .. leaf) self:T("Building leaf:" .. leaf)
local entry = self:FindEntryByUUID(leaf) local entry = self:FindEntryByUUID(leaf)
if entry then if entry then
self:I("Found generic entry:" .. entry.UUID) self:T("Found generic entry:" .. entry.UUID)
local parent = nil local parent = nil
if entry.Parent and entry.Parent.UUID then if entry.Parent and entry.Parent.UUID then
parent = self.playertree[playername][entry.Parent.UUID] or self:FindEntryByUUID(entry.Parent.UUID) parent = self.playertree[playername][entry.Parent.UUID] or self:FindEntryByUUID(entry.Parent.UUID)
@ -496,7 +589,7 @@ function CLIENTMENUMANAGER:Propagate(Client)
self.playertree[playername][entry.UUID] = CLIENTMENU:NewEntry(client,entry.name,parent,entry.Function,unpack(entry.Functionargs)) self.playertree[playername][entry.UUID] = CLIENTMENU:NewEntry(client,entry.name,parent,entry.Function,unpack(entry.Functionargs))
self.playertree[playername][entry.UUID].Once = entry.Once self.playertree[playername][entry.UUID].Once = entry.Once
else else
self:I("NO generic entry for:" .. leaf) self:T("NO generic entry for:" .. leaf)
end end
end end
end end
@ -521,15 +614,18 @@ function CLIENTMENUMANAGER:AddEntry(Entry,Client)
if client and client:IsAlive() then if client and client:IsAlive() then
local playername = client:GetPlayerName() local playername = client:GetPlayerName()
if Entry then if Entry then
self:I("Adding generic entry:" .. Entry.UUID) self:T("Adding generic entry:" .. Entry.UUID)
local parent = nil local parent = nil
if not self.playertree[playername] then
self.playertree[playername] = {}
end
if Entry.Parent and Entry.Parent.UUID then if Entry.Parent and Entry.Parent.UUID then
parent = self.playertree[playername][Entry.Parent.UUID] or self:FindEntryByUUID(Entry.Parent.UUID) parent = self.playertree[playername][Entry.Parent.UUID] or self:FindEntryByUUID(Entry.Parent.UUID)
end end
self.playertree[playername][Entry.UUID] = CLIENTMENU:NewEntry(client,Entry.name,parent,Entry.Function,unpack(Entry.Functionargs)) self.playertree[playername][Entry.UUID] = CLIENTMENU:NewEntry(client,Entry.name,parent,Entry.Function,unpack(Entry.Functionargs))
self.playertree[playername][Entry.UUID].Once = Entry.Once self.playertree[playername][Entry.UUID].Once = Entry.Once
else else
self:I("NO generic entry given") self:T("NO generic entry given")
end end
end end
end end
@ -577,7 +673,7 @@ end
-- @param Wrapper.Client#CLIENT Client (optional) If given, make this change only for this client. In this case the generic structure will not be touched. -- @param Wrapper.Client#CLIENT Client (optional) If given, make this change only for this client. In this case the generic structure will not be touched.
-- @return #CLIENTMENUMANAGER self -- @return #CLIENTMENUMANAGER self
function CLIENTMENUMANAGER:DeleteF10Entry(Entry,Client) function CLIENTMENUMANAGER:DeleteF10Entry(Entry,Client)
self:I(self.lid.."DeleteF10Entry") self:T(self.lid.."DeleteF10Entry")
local Set = self.clientset.Set local Set = self.clientset.Set
if Client then if Client then
Set = {Client} Set = {Client}
@ -588,6 +684,7 @@ function CLIENTMENUMANAGER:DeleteF10Entry(Entry,Client)
if self.playertree[playername] then if self.playertree[playername] then
local centry = self.playertree[playername][Entry.UUID] -- #CLIENTMENU local centry = self.playertree[playername][Entry.UUID] -- #CLIENTMENU
if centry then if centry then
--self:I("Match for "..Entry.UUID)
centry:Clear() centry:Clear()
end end
end end
@ -601,7 +698,7 @@ end
-- @param #CLIENTMENU Entry The entry to remove -- @param #CLIENTMENU Entry The entry to remove
-- @return #CLIENTMENUMANAGER self -- @return #CLIENTMENUMANAGER self
function CLIENTMENUMANAGER:DeleteGenericEntry(Entry) function CLIENTMENUMANAGER:DeleteGenericEntry(Entry)
self:I(self.lid.."DeleteGenericEntry") self:T(self.lid.."DeleteGenericEntry")
if Entry.Children and #Entry.Children > 0 then if Entry.Children and #Entry.Children > 0 then
self:RemoveGenericSubEntries(Entry) self:RemoveGenericSubEntries(Entry)
@ -614,11 +711,11 @@ function CLIENTMENUMANAGER:DeleteGenericEntry(Entry)
if tbl[depth] then if tbl[depth] then
for i=depth,#tbl do for i=depth,#tbl do
self:I("Level = "..i) --self:I("Level = "..i)
for _id,_uuid in pairs(tbl[i]) do for _id,_uuid in pairs(tbl[i]) do
self:I(_uuid) self:T(_uuid)
if string.find(_uuid,uuid) then if string.find(_uuid,uuid) or _uuid == uuid then
self:I("Match for ".._uuid) --self:I("Match for ".._uuid)
self.menutree[i][_id] = nil self.menutree[i][_id] = nil
self.flattree[_uuid] = nil self.flattree[_uuid] = nil
end end
@ -634,7 +731,7 @@ end
-- @param #CLIENTMENU Entry The entry where to start. This entry stays. -- @param #CLIENTMENU Entry The entry where to start. This entry stays.
-- @return #CLIENTMENUMANAGER self -- @return #CLIENTMENUMANAGER self
function CLIENTMENUMANAGER:RemoveGenericSubEntries(Entry) function CLIENTMENUMANAGER:RemoveGenericSubEntries(Entry)
self:I(self.lid.."RemoveGenericSubEntries") self:T(self.lid.."RemoveGenericSubEntries")
local depth = #Entry.path + 1 local depth = #Entry.path + 1
local uuid = Entry.UUID local uuid = Entry.UUID
@ -643,11 +740,11 @@ function CLIENTMENUMANAGER:RemoveGenericSubEntries(Entry)
if tbl[depth] then if tbl[depth] then
for i=depth,#tbl do for i=depth,#tbl do
self:I("Level = "..i) self:T("Level = "..i)
for _id,_uuid in pairs(tbl[i]) do for _id,_uuid in pairs(tbl[i]) do
self:I(_uuid) self:T(_uuid)
if string.find(_uuid,uuid) then if string.find(_uuid,uuid) then
self:I("Match for ".._uuid) self:T("Match for ".._uuid)
self.menutree[i][_id] = nil self.menutree[i][_id] = nil
self.flattree[_uuid] = nil self.flattree[_uuid] = nil
end end
@ -664,7 +761,7 @@ end
-- @param Wrapper.Client#CLIENT Client (optional) If given, make this change only for this client. In this case the generic structure will not be touched. -- @param Wrapper.Client#CLIENT Client (optional) If given, make this change only for this client. In this case the generic structure will not be touched.
-- @return #CLIENTMENUMANAGER self -- @return #CLIENTMENUMANAGER self
function CLIENTMENUMANAGER:RemoveF10SubEntries(Entry,Client) function CLIENTMENUMANAGER:RemoveF10SubEntries(Entry,Client)
self:I(self.lid.."RemoveSubEntries") self:T(self.lid.."RemoveSubEntries")
local Set = self.clientset.Set local Set = self.clientset.Set
if Client then if Client then
Set = {Client} Set = {Client}

View File

@ -278,7 +278,9 @@ do -- MENU_BASE
end end
end end
do -- MENU_COMMAND_BASE do
---
-- MENU_COMMAND_BASE
-- @type MENU_COMMAND_BASE -- @type MENU_COMMAND_BASE
-- @field #function MenuCallHandler -- @field #function MenuCallHandler
-- @extends Core.Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
@ -344,7 +346,9 @@ do -- MENU_COMMAND_BASE
end end
end end
do -- MENU_MISSION do
---
-- MENU_MISSION
-- @type MENU_MISSION -- @type MENU_MISSION
-- @extends Core.Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
--- Manages the main menus for a complete mission. --- Manages the main menus for a complete mission.
@ -432,8 +436,9 @@ do -- MENU_MISSION
end end
end end
do -- MENU_MISSION_COMMAND do
--- MENU_MISSION_COMMAND
-- @type MENU_MISSION_COMMAND -- @type MENU_MISSION_COMMAND
-- @extends Core.Menu#MENU_COMMAND_BASE -- @extends Core.Menu#MENU_COMMAND_BASE
@ -510,7 +515,8 @@ do -- MENU_MISSION_COMMAND
return self return self
end end
end end
do -- MENU_COALITION do
--- MENU_COALITION
-- @type MENU_COALITION -- @type MENU_COALITION
-- @extends Core.Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
@ -636,8 +642,9 @@ do -- MENU_COALITION
return self return self
end end
end end
do -- MENU_COALITION_COMMAND do
--- MENU_COALITION_COMMAND
-- @type MENU_COALITION_COMMAND -- @type MENU_COALITION_COMMAND
-- @extends Core.Menu#MENU_COMMAND_BASE -- @extends Core.Menu#MENU_COMMAND_BASE
@ -726,7 +733,10 @@ do
-- So every menu for a client created must be tracked so that program logic accidentally does not create. -- So every menu for a client created must be tracked so that program logic accidentally does not create.
-- the same menus twice during initialization logic. -- the same menus twice during initialization logic.
-- These menu classes are handling this logic with this variable. -- These menu classes are handling this logic with this variable.
local _MENUGROUPS = {} local _MENUGROUPS = {}
---
-- @type MENU_GROUP -- @type MENU_GROUP
-- @extends Core.Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
@ -900,7 +910,7 @@ do
return self return self
end end
---
-- @type MENU_GROUP_COMMAND -- @type MENU_GROUP_COMMAND
-- @extends Core.Menu#MENU_COMMAND_BASE -- @extends Core.Menu#MENU_COMMAND_BASE
@ -984,6 +994,7 @@ do
end end
--- MENU_GROUP_DELAYED --- MENU_GROUP_DELAYED
do do
---
-- @type MENU_GROUP_DELAYED -- @type MENU_GROUP_DELAYED
-- @extends Core.Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
@ -1107,7 +1118,7 @@ do
return self return self
end end
---
-- @type MENU_GROUP_COMMAND_DELAYED -- @type MENU_GROUP_COMMAND_DELAYED
-- @extends Core.Menu#MENU_COMMAND_BASE -- @extends Core.Menu#MENU_COMMAND_BASE

View File

@ -3946,6 +3946,7 @@ end
do -- SET_CLIENT do -- SET_CLIENT
---
-- @type SET_CLIENT -- @type SET_CLIENT
-- @field Core.Timer#TIMER ZoneTimer -- @field Core.Timer#TIMER ZoneTimer
-- @field #number ZoneTimerInterval -- @field #number ZoneTimerInterval
@ -4059,7 +4060,7 @@ do -- SET_CLIENT
--- Remove CLIENT(s) from SET_CLIENT. --- Remove CLIENT(s) from SET_CLIENT.
-- @param Core.Set#SET_CLIENT self -- @param Core.Set#SET_CLIENT self
-- @param Wrapper.Client#CLIENT RemoveClientNames A single name or an array of CLIENT names. -- @param Wrapper.Client#CLIENT RemoveClientNames A single object or an array of CLIENT objects.
-- @return self -- @return self
function SET_CLIENT:RemoveClientsByName( RemoveClientNames ) function SET_CLIENT:RemoveClientsByName( RemoveClientNames )

View File

@ -954,6 +954,7 @@ do
-- @field Utilities.FiFo#FIFO TasksPerPlayer -- @field Utilities.FiFo#FIFO TasksPerPlayer
-- @field Utilities.FiFo#FIFO PrecisionTasks -- @field Utilities.FiFo#FIFO PrecisionTasks
-- @field Core.Set#SET_CLIENT ClientSet -- @field Core.Set#SET_CLIENT ClientSet
-- @field Core.Set#SET_CLIENT ActiveClientSet
-- @field #string ClientFilter -- @field #string ClientFilter
-- @field #string Name -- @field #string Name
-- @field #string Type -- @field #string Type
@ -1610,20 +1611,22 @@ function PLAYERTASKCONTROLLER:New(Name, Coalition, Type, ClientFilter)
self.UseTypeNames = false self.UseTypeNames = false
local IsClientSet = false self.IsClientSet = false
if ClientFilter and type(ClientFilter) == "table" and ClientFilter.ClassName and ClientFilter.ClassName == "SET_CLIENT" then if ClientFilter and type(ClientFilter) == "table" and ClientFilter.ClassName and ClientFilter.ClassName == "SET_CLIENT" then
-- we have a predefined SET_CLIENT -- we have a predefined SET_CLIENT
self.ClientSet = ClientFilter self.ClientSet = ClientFilter
IsClientSet = true self.IsClientSet = true
end end
if ClientFilter and not IsClientSet then if ClientFilter and not self.IsClientSet then
self.ClientSet = SET_CLIENT:New():FilterCoalitions(string.lower(self.CoalitionName)):FilterActive(true):FilterPrefixes(ClientFilter):FilterStart() self.ClientSet = SET_CLIENT:New():FilterCoalitions(string.lower(self.CoalitionName)):FilterActive(true):FilterPrefixes(ClientFilter):FilterStart()
elseif not IsClientSet then elseif not self.IsClientSet then
self.ClientSet = SET_CLIENT:New():FilterCoalitions(string.lower(self.CoalitionName)):FilterActive(true):FilterStart() self.ClientSet = SET_CLIENT:New():FilterCoalitions(string.lower(self.CoalitionName)):FilterActive(true):FilterStart()
end end
self.ActiveClientSet = SET_CLIENT:New()
self.lid=string.format("PlayerTaskController %s %s | ", self.Name, tostring(self.Type)) self.lid=string.format("PlayerTaskController %s %s | ", self.Name, tostring(self.Type))
self:_InitLocalization() self:_InitLocalization()
@ -2171,7 +2174,8 @@ end
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
-- @return #PLAYERTASKCONTROLLER self -- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_EventHandler(EventData) function PLAYERTASKCONTROLLER:_EventHandler(EventData)
self:I(self.lid.."_EventHandler: "..EventData.id) self:T(self.lid.."_EventHandler: "..EventData.id)
self:T(self.lid.."_EventHandler: "..EventData.IniPlayerName)
if EventData.id == EVENTS.PlayerLeaveUnit or EventData.id == EVENTS.Ejection or EventData.id == EVENTS.Crash or EventData.id == EVENTS.PilotDead then if EventData.id == EVENTS.PlayerLeaveUnit or EventData.id == EVENTS.Ejection or EventData.id == EVENTS.Crash or EventData.id == EVENTS.PilotDead then
if EventData.IniPlayerName then if EventData.IniPlayerName then
self:T(self.lid.."Event for player: "..EventData.IniPlayerName) self:T(self.lid.."Event for player: "..EventData.IniPlayerName)
@ -2195,11 +2199,14 @@ function PLAYERTASKCONTROLLER:_EventHandler(EventData)
self:T(self.lid..text) self:T(self.lid..text)
end end
elseif EventData.id == EVENTS.PlayerEnterAircraft and EventData.IniCoalition == self.Coalition then elseif EventData.id == EVENTS.PlayerEnterAircraft and EventData.IniCoalition == self.Coalition then
if EventData.IniPlayerName and EventData.IniGroup and self.UseSRS then if EventData.IniPlayerName and EventData.IniGroup then
if self.ClientSet:IsNotInSet(CLIENT:FindByName(EventData.IniUnitName)) then if self.IsClientSet and self.ClientSet:IsNotInSet(CLIENT:FindByName(EventData.IniUnitName)) then
self:T(self.lid.."Client not in SET: "..EventData.IniPlayerName)
return self return self
end end
self:I(self.lid.."Event for player: "..EventData.IniPlayerName) self:T(self.lid.."Event for player: "..EventData.IniPlayerName)
if self.UseSRS then
local frequency = self.Frequency local frequency = self.Frequency
local freqtext = "" local freqtext = ""
if type(frequency) == "table" then if type(frequency) == "table" then
@ -2226,14 +2233,11 @@ function PLAYERTASKCONTROLLER:_EventHandler(EventData)
--local text = string.format("%s, %s, switch to %s for task assignment!",EventData.IniPlayerName,self.MenuName or self.Name,freqtext) --local text = string.format("%s, %s, switch to %s for task assignment!",EventData.IniPlayerName,self.MenuName or self.Name,freqtext)
local text = string.format(switchtext,playername,self.MenuName or self.Name,freqtext) local text = string.format(switchtext,playername,self.MenuName or self.Name,freqtext)
self.SRSQueue:NewTransmission(text,nil,self.SRS,timer.getAbsTime()+60,2,{EventData.IniGroup},text,30,self.BCFrequency,self.BCModulation) self.SRSQueue:NewTransmission(text,nil,self.SRS,timer.getAbsTime()+60,2,{EventData.IniGroup},text,30,self.BCFrequency,self.BCModulation)
end
if EventData.IniPlayerName then if EventData.IniPlayerName then
self.PlayerMenu[EventData.IniPlayerName] = nil self.PlayerMenu[EventData.IniPlayerName] = nil
--self:_BuildMenus(CLIENT:FindByName(EventData.IniUnitName))
--self:_BuildMenus(CLIENT:FindByPlayerName(EventData.IniPlayerName))
local player = CLIENT:FindByName(EventData.IniUnitName) local player = CLIENT:FindByName(EventData.IniUnitName)
self:I({player}) self:_SwitchMenuForClient(player,"Info")
local controller = self.JoinTaskMenuTemplate
controller:Propagate(player)
end end
end end
end end
@ -2362,11 +2366,23 @@ function PLAYERTASKCONTROLLER:_GetTasksPerType()
local threat=_data.threat local threat=_data.threat
local task = _data.task -- Ops.PlayerTask#PLAYERTASK local task = _data.task -- Ops.PlayerTask#PLAYERTASK
local type = task.Type local type = task.Type
local name = task.Target:GetName()
--self:I(name)
if not task:IsDone() then if not task:IsDone() then
--self:I(name)
table.insert(tasktypes[type],task) table.insert(tasktypes[type],task)
end end
end end
--[[
for _type,_data in pairs(tasktypes) do
self:I("Task Type: ".._type)
for _id,_task in pairs(_data) do
self:I("Task Name: ".._task.Target:GetName())
end
end
--]]
return tasktypes return tasktypes
end end
@ -2478,7 +2494,7 @@ function PLAYERTASKCONTROLLER:_CheckTaskQueue()
local client = _client --Wrapper.Client#CLIENT local client = _client --Wrapper.Client#CLIENT
local group = client:GetGroup() local group = client:GetGroup()
for _,task in pairs(nexttasks) do for _,task in pairs(nexttasks) do
self:_JoinTask(group,client,task,true) self:_JoinTask(task,true,group,client)
end end
end end
end end
@ -2497,7 +2513,7 @@ end
-- @param #PLAYERTASKCONTROLLER self -- @param #PLAYERTASKCONTROLLER self
-- @return #PLAYERTASKCONTROLLER self -- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_CheckPrecisionTasks() function PLAYERTASKCONTROLLER:_CheckPrecisionTasks()
self:T(self.lid.."_CheckTaskQueue") self:T(self.lid.."_CheckPrecisionTasks")
if self.PrecisionTasks:Count() > 0 and self.precisionbombing then if self.PrecisionTasks:Count() > 0 and self.precisionbombing then
if not self.LasingDrone or self.LasingDrone:IsDead() then if not self.LasingDrone or self.LasingDrone:IsDead() then
-- we need a new drone -- we need a new drone
@ -3006,9 +3022,14 @@ end
-- @param Wrapper.Client#CLIENT Client -- @param Wrapper.Client#CLIENT Client
-- @return #PLAYERTASKCONTROLLER self -- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_JoinTask(Task, Force, Group, Client) function PLAYERTASKCONTROLLER:_JoinTask(Task, Force, Group, Client)
self:T({Force, Group, Client})
self:T(self.lid.."_JoinTask") self:T(self.lid.."_JoinTask")
local force = false
if type(Force) == "boolean" then
force = Force
end
local playername, ttsplayername = self:_GetPlayerName(Client) local playername, ttsplayername = self:_GetPlayerName(Client)
if self.TasksPerPlayer:HasUniqueID(playername) and not Force then if self.TasksPerPlayer:HasUniqueID(playername) and not force then
-- Player already has a task -- Player already has a task
if not self.NoScreenOutput then if not self.NoScreenOutput then
local text = self.gettext:GetEntry("HAVEACTIVETASK",self.locale) local text = self.gettext:GetEntry("HAVEACTIVETASK",self.locale)
@ -3039,7 +3060,7 @@ function PLAYERTASKCONTROLLER:_JoinTask(Task, Force, Group, Client)
self.TasksPerPlayer:Push(Task,playername) self.TasksPerPlayer:Push(Task,playername)
self:__PlayerJoinedTask(1, Group, Client, Task) self:__PlayerJoinedTask(1, Group, Client, Task)
-- clear menu -- clear menu
--self:_BuildMenus(Client,true) self:_SwitchMenuForClient(Client,"Active",1)
end end
if Task.Type == AUFTRAG.Type.PRECISIONBOMBING then if Task.Type == AUFTRAG.Type.PRECISIONBOMBING then
if not self.PrecisionTasks:HasUniqueID(Task.PlayerTaskNr) then if not self.PrecisionTasks:HasUniqueID(Task.PlayerTaskNr) then
@ -3109,10 +3130,14 @@ function PLAYERTASKCONTROLLER:_ActiveTaskInfo(Task, Group, Client)
local playername, ttsplayername = self:_GetPlayerName(Client) local playername, ttsplayername = self:_GetPlayerName(Client)
local text = "" local text = ""
local textTTS = "" local textTTS = ""
if self.TasksPerPlayer:HasUniqueID(playername) or Task then local task = nil
if type(Task) ~= "string" then
task = Task
end
if self.TasksPerPlayer:HasUniqueID(playername) or task then
-- NODO: Show multiple? -- NODO: Show multiple?
-- Details -- Details
local task = Task or self.TasksPerPlayer:ReadByID(playername) -- Ops.PlayerTask#PLAYERTASK local task = task or self.TasksPerPlayer:ReadByID(playername) -- Ops.PlayerTask#PLAYERTASK
local tname = self.gettext:GetEntry("TASKNAME",self.locale) local tname = self.gettext:GetEntry("TASKNAME",self.locale)
local ttsname = self.gettext:GetEntry("TASKNAMETTS",self.locale) local ttsname = self.gettext:GetEntry("TASKNAMETTS",self.locale)
local taskname = string.format(tname,task.Type,task.PlayerTaskNr) local taskname = string.format(tname,task.Type,task.PlayerTaskNr)
@ -3424,119 +3449,173 @@ function PLAYERTASKCONTROLLER:_AbortTask(Group, Client)
if not self.NoScreenOutput then if not self.NoScreenOutput then
local m=MESSAGE:New(text,15,"Tasking"):ToClient(Client) local m=MESSAGE:New(text,15,"Tasking"):ToClient(Client)
end end
--self:_BuildMenus(Client,true) self:_SwitchMenuForClient(Client,"Info",1)
return self return self
end end
--- [Internal] Build Task Info Menu
-- @param #PLAYERTASKCONTROLLER self
-- @param Wrapper.Group#GROUP group
-- @param Wrapper.Client#CLIENT client
-- @param #string playername
-- @param Core.Menu#MENU_BASE topmenu
-- @param #table tasktypes
-- @param #table taskpertype
-- @param #string newtag
-- @return #table taskinfomenu
function PLAYERTASKCONTROLLER:_BuildTaskInfoMenu(group,client,playername,topmenu,tasktypes,taskpertype,newtag)
self:T(self.lid.."_BuildTaskInfoMenu")
local taskinfomenu = nil
if self.taskinfomenu then
local menutaskinfo = self.gettext:GetEntry("MENUTASKINFO",self.locale)
local taskinfomenu = MENU_GROUP:New(group,menutaskinfo,topmenu):SetTag(newtag)
local ittypes = {}
local itaskmenu = {}
local tnow = timer.getTime()
for _tasktype,_data in pairs(tasktypes) do
ittypes[_tasktype] = MENU_GROUP:New(group,_tasktype,taskinfomenu):SetTag(newtag)
local tasks = taskpertype[_tasktype] or {}
local n = 0
for _,_task in pairs(tasks) do
_task = _task -- Ops.PlayerTask#PLAYERTASK
local pilotcount = _task:CountClients()
local newtext = "]"
-- marker for new tasks
if tnow - _task.timestamp < 60 then
newtext = "*]"
end
local menutaskno = self.gettext:GetEntry("MENUTASKNO",self.locale)
local text = string.format("%s %03d [%d%s",menutaskno,_task.PlayerTaskNr,pilotcount,newtext)
if self.UseGroupNames then
local name = _task.Target:GetName()
if name ~= "Unknown" then
text = string.format("%s (%03d) [%d%s",name,_task.PlayerTaskNr,pilotcount,newtext)
end
end
if self.UseTypeNames then
if _task.TypeName then
--local name = self.gettext:GetEntry(_task.TypeName,self.locale)
text = string.format("%s (%03d) [%d%s",_task.TypeName,_task.PlayerTaskNr,pilotcount,newtext)
--self:T(self.lid.."Menu text = "..text)
end
end
local taskentry = MENU_GROUP_COMMAND:New(group,text,ittypes[_tasktype],self._ActiveTaskInfo,self,group,client,_task):SetTag(newtag)
--taskentry:SetTag(playername)
itaskmenu[#itaskmenu+1] = taskentry
-- keep max items limit
n = n + 1
if n >= self.menuitemlimit then
break
end
end
end
end
return taskinfomenu
end
-- TODO - New Menu Manager -- TODO - New Menu Manager
--- [Internal] _UpdateJoinMenuTemplate
-- @param #PLAYERTASKCONTROLLER self
-- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_UpdateJoinMenuTemplate() function PLAYERTASKCONTROLLER:_UpdateJoinMenuTemplate()
self:I("_UpdateJoinMenuTemplate") self:T("_UpdateJoinMenuTemplate")
if self.TaskQueue:Count() > 0 then if self.TaskQueue:Count() > 0 then
local taskpertype = self:_GetTasksPerType() local taskpertype = self:_GetTasksPerType()
local JoinMenu = self.JoinMenu -- Core.ClientMenu#CLIENTMENU local JoinMenu = self.JoinMenu -- Core.ClientMenu#CLIENTMENU
self:I(JoinMenu.path) --self:I(JoinMenu.UUID)
local controller = self.JoinTaskMenuTemplate -- Core.ClientMenu#CLIENTMENUMANAGER local controller = self.JoinTaskMenuTemplate -- Core.ClientMenu#CLIENTMENUMANAGER
local actcontroller = self.ActiveTaskMenuTemplate -- Core.ClientMenu#CLIENTMENUMANAGER local actcontroller = self.ActiveTaskMenuTemplate -- Core.ClientMenu#CLIENTMENUMANAGER
local entrynumbers = {} local actinfomenu = self.ActiveInfoMenu
local existingentries = {} --local entrynumbers = {}
--local existingentries = {}
local maxn = self.menuitemlimit local maxn = self.menuitemlimit
-- Generate task type menu items -- Generate task type menu items
for _type,_ in pairs(taskpertype) do for _type,_ in pairs(taskpertype) do
--local found = controller:FindEntryByText(_type) local found = controller:FindEntriesByText(_type)
local found, text = controller:FindEntryUnderParentByText(JoinMenu,_type) --self:I({found})
self:I(text) if #found == 0 then
if not found then
local newentry = controller:NewEntry(_type,JoinMenu) local newentry = controller:NewEntry(_type,JoinMenu)
controller:AddEntry(newentry) controller:AddEntry(newentry)
if self.JoinInfoMenu then if self.JoinInfoMenu then
local newentry = controller:NewEntry(_type,self.JoinInfoMenu) local newentry = controller:NewEntry(_type,self.JoinInfoMenu)
controller:AddEntry(newentry) controller:AddEntry(newentry)
end end
entrynumbers[_type] = 0 if actinfomenu then
existingentries[_type] = {} local newentry = actcontroller:NewEntry(_type,self.ActiveInfoMenu)
actcontroller:AddEntry(newentry)
end
end
end
local typelist = self:_GetAvailableTaskTypes()
-- Slot in Tasks
for _tasktype,_data in pairs(typelist) do
self:T("**** Building for TaskType: ".._tasktype)
--local tasks = taskpertype[_tasktype] or {}
for _,_task in pairs(taskpertype[_tasktype]) do
_task = _task -- Ops.PlayerTask#PLAYERTASK
self:T("**** Building for Task: ".._task.Target:GetName())
if _task.InMenu then
self:T("**** Task already in Menu ".._task.Target:GetName())
else else
--local pilotcount = _task:CountClients()
--local newtext = "]"
--local tnow = timer.getTime()
-- marker for new tasks
--if tnow - _task.timestamp < 60 then
--newtext = "*]"
--end
local menutaskno = self.gettext:GetEntry("MENUTASKNO",self.locale)
--local text = string.format("%s %03d [%d%s",menutaskno,_task.PlayerTaskNr,pilotcount,newtext)
local text = string.format("%s %03d",menutaskno,_task.PlayerTaskNr)
if self.UseGroupNames then
local name = _task.Target:GetName()
if name ~= "Unknown" then
--text = string.format("%s (%03d) [%d%s",name,_task.PlayerTaskNr,pilotcount,newtext)
text = string.format("%s (%03d)",name,_task.PlayerTaskNr)
end
end
--local taskentry = MENU_GROUP_COMMAND:New(group,text,ttypes[_tasktype],self._JoinTask,self,group,client,_task):SetTag(newtag)
local parenttable, number = controller:FindEntriesByText(_tasktype,JoinMenu)
if number > 0 then
local Parent = parenttable[1]
local matches, count = controller:FindEntriesByParent(Parent)
self:T("***** Join Menu ".._tasktype.. " # of entries: "..count)
if count < self.menuitemlimit then
local taskentry = controller:NewEntry(text,Parent,self._JoinTask,self,_task,"false")
controller:AddEntry(taskentry)
_task.InMenu = true
if not _task.UUIDS then _task.UUIDS = {} end
table.insert(_task.UUIDS,taskentry.UUID)
end
end
if self.JoinInfoMenu then
local parenttable, number = controller:FindEntriesByText(_tasktype,self.JoinInfoMenu)
if number > 0 then
local Parent = parenttable[1]
local matches, count = controller:FindEntriesByParent(Parent)
self:T("***** Join Info Menu ".._tasktype.. " # of entries: "..count)
if count < self.menuitemlimit then
local taskentry = controller:NewEntry(text,Parent,self._ActiveTaskInfo,self,_task)
controller:AddEntry(taskentry)
_task.InMenu = true
if not _task.UUIDS then _task.UUIDS = {} end
table.insert(_task.UUIDS,taskentry.UUID)
end
end
end
if actinfomenu then
local parenttable, number = actcontroller:FindEntriesByText(_tasktype,self.ActiveInfoMenu)
if number > 0 then
local Parent = parenttable[1]
local matches, count = actcontroller:FindEntriesByParent(Parent)
self:T("***** Active Info Menu ".._tasktype.. " # of entries: "..count)
if count < self.menuitemlimit then
local taskentry = actcontroller:NewEntry(text,Parent,self._ActiveTaskInfo,self,_task)
actcontroller:AddEntry(taskentry)
_task.InMenu = true
if not _task.AUUIDS then _task.AUUIDS = {} end
table.insert(_task.AUUIDS,taskentry.UUID)
end
end end
end end
local function FindInList(List,Text)
local found = false
for _,_name in pairs(List) do
if string.match(_name,Text) then
found = true
break
end end
end end
return found
end end
end end
return self return self
end end
--- [Internal] _RemoveMenuEntriesForTask
-- @param #PLAYERTASKCONTROLLER self
-- @param #PLAYERTASK Task
-- @param Wrapper.Client#CLIENT Client
-- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_RemoveMenuEntriesForTask(Task,Client)
self:T("_RemoveMenuEntriesForTask")
--self:I("Task name: "..Task.Target:GetName())
--self:I("Client: "..Client:GetPlayerName())
if Task then
if Task.UUIDS and self.JoinTaskMenuTemplate then
--self:I("***** JoinTaskMenuTemplate")
UTILS.PrintTableToLog(Task.UUIDS)
local controller = self.JoinTaskMenuTemplate
for _,_uuid in pairs(Task.UUIDS) do
local Entry = controller:FindEntryByUUID(_uuid)
if Entry then
controller:DeleteF10Entry(Entry,Client)
controller:DeleteGenericEntry(Entry)
UTILS.PrintTableToLog(controller.menutree)
end
end
end
if Task.AUUIDS and self.ActiveTaskMenuTemplate then
--self:I("***** ActiveTaskMenuTemplate")
UTILS.PrintTableToLog(Task.AUUIDS)
for _,_uuid in pairs(Task.AUUIDS) do
local controller = self.ActiveTaskMenuTemplate
local Entry = controller:FindEntryByUUID(_uuid)
if Entry then
controller:DeleteF10Entry(Entry,Client)
controller:DeleteGenericEntry(Entry)
UTILS.PrintTableToLog(controller.menutree)
end
end
end
Task.UUIDS = nil
Task.AUUIDS = nil
end
return self
end
--- [Internal] _CreateJoinMenuTemplate
-- @param #PLAYERTASKCONTROLLER self
-- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_CreateJoinMenuTemplate() function PLAYERTASKCONTROLLER:_CreateJoinMenuTemplate()
self:I("_CreateActiveTaskMenuTemplate") self:T("_CreateActiveTaskMenuTemplate")
local menujoin = self.gettext:GetEntry("MENUJOIN",self.locale) local menujoin = self.gettext:GetEntry("MENUJOIN",self.locale)
local menunotasks = self.gettext:GetEntry("MENUNOTASKS",self.locale) local menunotasks = self.gettext:GetEntry("MENUNOTASKS",self.locale)
@ -3552,7 +3631,7 @@ function PLAYERTASKCONTROLLER:_CreateJoinMenuTemplate()
end end
if self.AllowFlash then if self.AllowFlash then
JoinTaskMenuTemplate:NewEntry(flashtext,self.JoinTopMenu,self._SwitchFlashing,self,group,client) JoinTaskMenuTemplate:NewEntry(flashtext,self.JoinTopMenu,self._SwitchFlashing,self)
end end
self.JoinMenu = JoinTaskMenuTemplate:NewEntry(menujoin,self.JoinTopMenu) self.JoinMenu = JoinTaskMenuTemplate:NewEntry(menujoin,self.JoinTopMenu)
@ -3571,9 +3650,11 @@ function PLAYERTASKCONTROLLER:_CreateJoinMenuTemplate()
return self return self
end end
--- [Internal] _CreateActiveTaskMenuTemplate
-- @param #PLAYERTASKCONTROLLER self
-- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate() function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate()
self:I("_CreateActiveTaskMenuTemplate") self:T("_CreateActiveTaskMenuTemplate")
local menuactive = self.gettext:GetEntry("MENUACTIVE",self.locale) local menuactive = self.gettext:GetEntry("MENUACTIVE",self.locale)
local menuinfo = self.gettext:GetEntry("MENUINFO",self.locale) local menuinfo = self.gettext:GetEntry("MENUINFO",self.locale)
@ -3583,7 +3664,7 @@ function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate()
local menuillu = self.gettext:GetEntry("MENUILLU",self.locale) local menuillu = self.gettext:GetEntry("MENUILLU",self.locale)
local menuabort = self.gettext:GetEntry("MENUABORT",self.locale) local menuabort = self.gettext:GetEntry("MENUABORT",self.locale)
local ActiveTaskMenuTemplate = CLIENTMENUMANAGER:New(self.ClientSet,"ActiveTask") local ActiveTaskMenuTemplate = CLIENTMENUMANAGER:New(self.ActiveClientSet,"ActiveTask")
if not self.ActiveTopMenu then if not self.ActiveTopMenu then
local taskings = self.gettext:GetEntry("MENUTASKING",self.locale) local taskings = self.gettext:GetEntry("MENUTASKING",self.locale)
@ -3594,24 +3675,24 @@ function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate()
if self.AllowFlash then if self.AllowFlash then
local flashtext = self.gettext:GetEntry("FLASHMENU",self.locale) local flashtext = self.gettext:GetEntry("FLASHMENU",self.locale)
ActiveTaskMenuTemplate:NewEntry(flashtext,self.ActiveTopMenu,self._SwitchFlashing,self,group,client) ActiveTaskMenuTemplate:NewEntry(flashtext,self.ActiveTopMenu,self._SwitchFlashing,self)
end end
local active = ActiveTaskMenuTemplate:NewEntry(menuactive,self.ActiveTopMenu) local active = ActiveTaskMenuTemplate:NewEntry(menuactive,self.ActiveTopMenu)
ActiveTaskMenuTemplate:NewEntry(menuinfo,active,self._ActiveTaskInfo,self,nil) ActiveTaskMenuTemplate:NewEntry(menuinfo,active,self._ActiveTaskInfo,self,"NONE")
ActiveTaskMenuTemplate:NewEntry(menumark,active,self._MarkTask,self,nil) ActiveTaskMenuTemplate:NewEntry(menumark,active,self._MarkTask,self)
if self.Type ~= PLAYERTASKCONTROLLER.Type.A2A and self.noflaresmokemenu ~= true then if self.Type ~= PLAYERTASKCONTROLLER.Type.A2A and self.noflaresmokemenu ~= true then
ActiveTaskMenuTemplate:NewEntry(menusmoke,active,self._SmokeTask,self,group,client) ActiveTaskMenuTemplate:NewEntry(menusmoke,active,self._SmokeTask,self)
ActiveTaskMenuTemplate:NewEntry(menuflare,active,self._FlareTask,self,group,client) ActiveTaskMenuTemplate:NewEntry(menuflare,active,self._FlareTask,self)
if self.illumenu then if self.illumenu then
ActiveTaskMenuTemplate:NewEntry(menuillu,active,self._IlluminateTask,self,group,client) ActiveTaskMenuTemplate:NewEntry(menuillu,active,self._IlluminateTask,self)
end end
end end
ActiveTaskMenuTemplate:NewEntry(menuabort,active,self._AbortTask,self,group,client) ActiveTaskMenuTemplate:NewEntry(menuabort,active,self._AbortTask,self)
self.ActiveTaskMenuTemplate = ActiveTaskMenuTemplate self.ActiveTaskMenuTemplate = ActiveTaskMenuTemplate
if self.taskinfomenu and self.activehasinfomenu then if self.taskinfomenu and self.activehasinfomenu then
@ -3622,215 +3703,33 @@ function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate()
return self return self
end end
--- [Internal] Build client menus --- [Internal] _SwitchMenuForClient
-- @param #PLAYERTASKCONTROLLER self -- @param #PLAYERTASKCONTROLLER self
-- @param Wrapper.Client#CLIENT Client (optional) build for this client name only -- @param Wrapper.Client#CLIENT Client The client
-- @param #boolean enforced -- @param #string MenuType
-- @param #boolean fromsuccess -- @param #number Delay
-- @return #PLAYERTASKCONTROLLER self -- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:_BuildMenus(Client,enforced,fromsuccess) function PLAYERTASKCONTROLLER:_SwitchMenuForClient(Client,MenuType,Delay)
self:T(self.lid.."_BuildMenus") self:T(self.lid.."_SwitchMenuForClient")
if Delay then
if self.MenuBuildLocked and (timer.getAbsTime() - self.MenuBuildLocked < 2) then self:ScheduleOnce(Delay,self._SwitchMenuForClient,self,Client,MenuType)
self:ScheduleOnce(2,self._BuildMenus,self,Client,enforced,fromsuccess)
return self return self
end
if MenuType == "Info" then
self.ClientSet:AddClientsByName(Client:GetName())
self.ActiveClientSet:Remove(Client:GetName(),true)
self.ActiveTaskMenuTemplate:ResetMenu(Client)
self.JoinTaskMenuTemplate:ResetMenu(Client)
self.JoinTaskMenuTemplate:Propagate(Client)
elseif MenuType == "Active" then
self.ActiveClientSet:AddClientsByName(Client:GetName())
self.ClientSet:Remove(Client:GetName(),true)
self.ActiveTaskMenuTemplate:ResetMenu(Client)
self.JoinTaskMenuTemplate:ResetMenu(Client)
self.ActiveTaskMenuTemplate:Propagate(Client)
else else
self.MenuBuildLocked = timer.getAbsTime() self:E(self.lid .."Unknown menu type in _SwitchMenuForClient:"..tostring(MenuType))
end end
local clients = self.ClientSet:GetAliveSet()
local joinorabort = false
local timedbuild = false
if Client then
-- client + enforced -- join task or abort
clients = {Client}
enforced = true
joinorabort = true
end
local tasktypes = self:_GetAvailableTaskTypes()
local taskpertype = self:_GetTasksPerType()
for _,_client in pairs(clients) do
if _client and _client:IsAlive() then
local client = _client -- Wrapper.Client#CLIENT
local group = client:GetGroup()
local unknown = self.gettext:GetEntry("UNKNOWN",self.locale)
local playername = client:GetPlayerName() or unknown
local oldtag = self.PlayerMenuTag[playername]
local newtag = playername..timer.getAbsTime()
self.PlayerMenuTag[playername] = newtag
if group and client then
---
-- TOPMENU
---
local taskings = self.gettext:GetEntry("MENUTASKING",self.locale)
local longname = self.Name..taskings..self.Type
local menuname = self.MenuName or longname
local playerhastask = false
if self:_CheckPlayerHasTask(playername) and not fromsuccess then playerhastask = true end
local topmenu = nil
--local oldmenu = nil
local rebuilddone = false
self:T("Playerhastask = "..tostring(playerhastask).." Enforced = "..tostring(enforced).." Join or Abort = "..tostring(joinorabort))
-- Cases to rebuild menu
-- 1) new player
-- 2) player joined a task, joinorabort = true
-- 3) player left a task, joinorabort = true
-- 4) player has no task, but number of tasks changed, and last build > 30 secs ago
if self.PlayerMenu[playername] then
-- NOT a new player
-- 2)+3) Join or abort?
if joinorabort then
self.PlayerMenu[playername]:RemoveSubMenus()
self.PlayerMenu[playername] = MENU_GROUP:New(group,menuname,self.MenuParent)
self.PlayerMenu[playername]:SetTag(newtag)
topmenu = self.PlayerMenu[playername]
elseif (not playerhastask) or enforced then
-- 4) last build > 30 secs?
local T0 = timer.getAbsTime()
local TDiff = T0-self.PlayerMenu[playername].PTTimeStamp
self:T("TDiff = "..string.format("%.2d",TDiff))
if TDiff >= self.holdmenutime then
--self.PlayerMenu[playername]:RemoveSubMenus()
--oldmenu = self.PlayerMenu[playername]
--self.PlayerMenu[playername] = nil
--self.PlayerMenu[playername]:RemoveSubMenus()
--self.PlayerMenu[playername] = MENU_GROUP:New(group,menuname,self.MenuParent)
--self.PlayerMenu[playername]:SetTag(newtag)
--self.PlayerMenu[playername].PTTimeStamp = timer.getAbsTime()
--timedbuild = true
end
topmenu = self.PlayerMenu[playername]
end
else
-- 1) new player#
topmenu = MENU_GROUP:New(group,menuname,self.MenuParent)
self.PlayerMenu[playername] = topmenu
self.PlayerMenu[playername]:SetTag(newtag)
self.PlayerMenu[playername].PTTimeStamp = timer.getAbsTime()
enforced = true
end
---
-- ACTIVE TASK MENU
---
if playerhastask and enforced then
self:T("Building Active Task Menus for "..playername)
rebuilddone = true
local menuactive = self.gettext:GetEntry("MENUACTIVE",self.locale)
local menuinfo = self.gettext:GetEntry("MENUINFO",self.locale)
local menumark = self.gettext:GetEntry("MENUMARK",self.locale)
local menusmoke = self.gettext:GetEntry("MENUSMOKE",self.locale)
local menuflare = self.gettext:GetEntry("MENUFLARE",self.locale)
local menuabort = self.gettext:GetEntry("MENUABORT",self.locale)
local active = MENU_GROUP:New(group,menuactive,topmenu):SetTag(newtag)
local info = MENU_GROUP_COMMAND:New(group,menuinfo,active,self._ActiveTaskInfo,self,group,client):SetTag(newtag)
local mark = MENU_GROUP_COMMAND:New(group,menumark,active,self._MarkTask,self,group,client):SetTag(newtag)
if self.Type ~= PLAYERTASKCONTROLLER.Type.A2A then
if self.noflaresmokemenu ~= true then
-- no smoking/flaring here if A2A or designer has set noflaresmokemenu to true
local smoke = MENU_GROUP_COMMAND:New(group,menusmoke,active,self._SmokeTask,self,group,client):SetTag(newtag)
local flare = MENU_GROUP_COMMAND:New(group,menuflare,active,self._FlareTask,self,group,client):SetTag(newtag)
local IsNight = client:GetCoordinate():IsNight()
if IsNight then
local light = MENU_GROUP_COMMAND:New(group,menuflare,active,self._IlluminateTask,self,group,client):SetTag(newtag)
end
end
end
local abort = MENU_GROUP_COMMAND:New(group,menuabort,active,self._AbortTask,self,group,client):SetTag(newtag)
if self.activehasinfomenu and self.taskinfomenu then
self:T("Building Active-Info Menus for "..playername)
if self.PlayerInfoMenu[playername] then
self.PlayerInfoMenu[playername]:RemoveSubMenus(nil,oldtag)
end
self.PlayerInfoMenu[playername] = self:_BuildTaskInfoMenu(group,client,playername,topmenu,tasktypes,taskpertype,newtag)
end
elseif (self.TaskQueue:Count() > 0 and enforced) or (not playerhastask and (timedbuild or joinorabort)) then
self:T("Building Join Menus for "..playername)
rebuilddone = true
---
-- JOIN TASK MENU
---
local menujoin = self.gettext:GetEntry("MENUJOIN",self.locale)
if self.PlayerJoinMenu[playername] then
self.PlayerJoinMenu[playername]:RemoveSubMenus(nil,oldtag)
end
local joinmenu = MENU_GROUP:New(group,menujoin,topmenu):SetTag(newtag)
self.PlayerJoinMenu[playername] = joinmenu
local ttypes = {}
local taskmenu = {}
for _tasktype,_data in pairs(tasktypes) do
ttypes[_tasktype] = MENU_GROUP:New(group,_tasktype,joinmenu):SetTag(newtag)
local tasks = taskpertype[_tasktype] or {}
local n = 0
for _,_task in pairs(tasks) do
_task = _task -- Ops.PlayerTask#PLAYERTASK
local pilotcount = _task:CountClients()
local newtext = "]"
local tnow = timer.getTime()
-- marker for new tasks
if tnow - _task.timestamp < 60 then
newtext = "*]"
end
local menutaskno = self.gettext:GetEntry("MENUTASKNO",self.locale)
local text = string.format("%s %03d [%d%s",menutaskno,_task.PlayerTaskNr,pilotcount,newtext)
if self.UseGroupNames then
local name = _task.Target:GetName()
if name ~= "Unknown" then
text = string.format("%s (%03d) [%d%s",name,_task.PlayerTaskNr,pilotcount,newtext)
end
end
local taskentry = MENU_GROUP_COMMAND:New(group,text,ttypes[_tasktype],self._JoinTask,self,group,client,_task):SetTag(newtag)
--taskentry:SetTag(playername)
taskmenu[#taskmenu+1] = taskentry
n = n + 1
if n >= self.menuitemlimit then
break
end
end
end
if self.taskinfomenu then
self:T("Building Join-Info Menus for "..playername)
if self.PlayerInfoMenu[playername] then
self.PlayerInfoMenu[playername]:RemoveSubMenus(nil,oldtag)
end
self.PlayerInfoMenu[playername] = self:_BuildTaskInfoMenu(group,client,playername,topmenu,tasktypes,taskpertype,newtag)
end
end
if self.AllowFlash and topmenu ~= nil then
local flashtext = self.gettext:GetEntry("FLASHMENU",self.locale)
local flashmenu = MENU_GROUP_COMMAND:New(group,flashtext,topmenu,self._SwitchFlashing,self,group,client):SetTag(newtag)
end
if self.TaskQueue:Count() == 0 then
self:T("No open tasks info")
local menunotasks = self.gettext:GetEntry("MENUNOTASKS",self.locale)
local joinmenu = MENU_GROUP:New(group,menunotasks,self.PlayerMenu[playername]):SetTag(newtag)
rebuilddone = true
end
---
-- REFRESH MENU
---
if rebuilddone then
--self.PlayerMenu[playername]:RemoveSubMenus(nil,oldtag)
--self.PlayerMenu[playername]:Set()
self.PlayerMenu[playername]:Refresh()
end
end
end
end
self.MenuBuildLocked = false
return self return self
end end
@ -3978,8 +3877,8 @@ end
-- @param Core.Menu#MENU_MISSION Menu -- @param Core.Menu#MENU_MISSION Menu
-- @return #PLAYERTASKCONTROLLER self -- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:SetParentMenu(Menu) function PLAYERTASKCONTROLLER:SetParentMenu(Menu)
self:T(self.lid.."SetParentName") self:T(self.lid.."SetParentMenu")
self.MenuParent = Menu --self.MenuParent = Menu
return self return self
end end
@ -4140,8 +4039,8 @@ end
-- @param #string To -- @param #string To
-- @return #PLAYERTASKCONTROLLER self -- @return #PLAYERTASKCONTROLLER self
function PLAYERTASKCONTROLLER:onafterStart(From, Event, To) function PLAYERTASKCONTROLLER:onafterStart(From, Event, To)
self:I({From, Event, To}) self:T({From, Event, To})
self:I(self.lid.."onafterStart") self:T(self.lid.."onafterStart")
self:_CreateJoinMenuTemplate() self:_CreateJoinMenuTemplate()
self:_CreateActiveTaskMenuTemplate() self:_CreateActiveTaskMenuTemplate()
return self return self
@ -4176,8 +4075,6 @@ function PLAYERTASKCONTROLLER:onafterStatus(From, Event, To)
end end
end end
--self:_BuildMenus(nil,enforcedmenu)
self:_UpdateJoinMenuTemplate() self:_UpdateJoinMenuTemplate()
if self.verbose then if self.verbose then
@ -4225,6 +4122,16 @@ function PLAYERTASKCONTROLLER:onafterTaskCancelled(From, Event, To, Task)
taskname = string.format(canceltxttts, self.MenuName or self.Name, Task.PlayerTaskNr, tostring(Task.TTSType)) taskname = string.format(canceltxttts, self.MenuName or self.Name, Task.PlayerTaskNr, tostring(Task.TTSType))
self.SRSQueue:NewTransmission(taskname,nil,self.SRS,nil,2) self.SRSQueue:NewTransmission(taskname,nil,self.SRS,nil,2)
end end
local clients=Task:GetClientObjects()
for _,client in pairs(clients) do
self:_RemoveMenuEntriesForTask(Task,client)
--self:_SwitchMenuForClient(client,"Info")
end
for _,client in pairs(clients) do
--self:_RemoveMenuEntriesForTask(Task,client)
self:_SwitchMenuForClient(client,"Info",5)
end
return self return self
end end
@ -4249,9 +4156,15 @@ function PLAYERTASKCONTROLLER:onafterTaskSuccess(From, Event, To, Task)
taskname = string.format(succtxttts, self.MenuName or self.Name, Task.PlayerTaskNr, tostring(Task.TTSType)) taskname = string.format(succtxttts, self.MenuName or self.Name, Task.PlayerTaskNr, tostring(Task.TTSType))
self.SRSQueue:NewTransmission(taskname,nil,self.SRS,nil,2) self.SRSQueue:NewTransmission(taskname,nil,self.SRS,nil,2)
end end
local clients=Task:GetClientObjects() local clients=Task:GetClientObjects()
for _,client in pairs(clients) do for _,client in pairs(clients) do
--self:_BuildMenus(client,true,true) self:_RemoveMenuEntriesForTask(Task,client)
--self:_SwitchMenuForClient(client,"Info")
end
for _,client in pairs(clients) do
-- self:_RemoveMenuEntriesForTask(Task,client)
self:_SwitchMenuForClient(client,"Info",5)
end end
return self return self
end end