mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#ClientMenu
This commit is contained in:
parent
e8ad649770
commit
e8432db26e
@ -3,12 +3,14 @@
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * 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
|
||||
-- * Allow manipulation of the shadow tree in various ways
|
||||
-- * Push to all or only one client
|
||||
-- * Change entries' menu text, even if they have a sub-structure
|
||||
-- * Option to make an entry usable once
|
||||
-- * Change entries' menu text
|
||||
-- * 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 = {
|
||||
ClassName = "CLIENTMENUE",
|
||||
lid = "",
|
||||
version = "0.0.2",
|
||||
version = "0.1.0",
|
||||
name = nil,
|
||||
path = nil,
|
||||
group = nil,
|
||||
@ -94,16 +96,20 @@ function CLIENTMENU:NewEntry(Client,Text,Parent,Function,...)
|
||||
end
|
||||
self.name = Text or "unknown entry"
|
||||
if Parent then
|
||||
if Parent:IsInstanceOf("MENU_BASE") then
|
||||
self.parentpath = Parent.MenuPath
|
||||
else
|
||||
self.parentpath = Parent:GetPath()
|
||||
Parent:AddChild(self)
|
||||
end
|
||||
end
|
||||
self.Parent = Parent
|
||||
self.Function = Function
|
||||
self.Functionargs = arg or {}
|
||||
table.insert(self.Functionargs,self.group)
|
||||
table.insert(self.Functionargs,self.client)
|
||||
if self.Functionargs and self.debug then
|
||||
self:I({"Functionargs",self.Functionargs})
|
||||
self:T({"Functionargs",self.Functionargs})
|
||||
end
|
||||
if not self.Generic then
|
||||
if Function ~= nil then
|
||||
@ -136,7 +142,7 @@ function CLIENTMENU:NewEntry(Client,Text,Parent,Function,...)
|
||||
self.path[#self.path+1] = Text
|
||||
end
|
||||
self.UUID = table.concat(self.path,";")
|
||||
self:I({self.UUID})
|
||||
self:T({self.UUID})
|
||||
self.Once = false
|
||||
-- Log id.
|
||||
self.lid=string.format("CLIENTMENU %s | %s | ", self.ID, self.name)
|
||||
@ -144,6 +150,21 @@ function CLIENTMENU:NewEntry(Client,Text,Parent,Function,...)
|
||||
return self
|
||||
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.
|
||||
-- @param #CLIENTMENU self
|
||||
-- @param #CLIENTMENUMANAGER Controller The controlling object.
|
||||
@ -166,9 +187,9 @@ end
|
||||
-- @param #CLIENTMENU self
|
||||
-- @return #CLIENTMENU self
|
||||
function CLIENTMENU:RemoveF10()
|
||||
self:I(self.lid.."RemoveF10")
|
||||
if not self.Generic then
|
||||
self:I(self.lid.."Removing")
|
||||
self:T(self.lid.."RemoveF10")
|
||||
if self.GroupID then
|
||||
--self:I(self.lid.."Removing "..table.concat(self.path,";"))
|
||||
missionCommands.removeItemForGroup(self.GroupID , self.path )
|
||||
end
|
||||
return self
|
||||
@ -214,10 +235,10 @@ end
|
||||
-- @param #CLIENTMENU self
|
||||
-- @return #CLIENTMENU self
|
||||
function CLIENTMENU:RemoveSubEntries()
|
||||
self:I(self.lid.."RemoveSubEntries")
|
||||
self:I({self.Children})
|
||||
self:T(self.lid.."RemoveSubEntries")
|
||||
self:T({self.Children})
|
||||
for _id,_entry in pairs(self.Children) do
|
||||
self:I("Removing ".._id)
|
||||
self:T("Removing ".._id)
|
||||
if _entry then
|
||||
_entry:RemoveSubEntries()
|
||||
_entry:RemoveF10()
|
||||
@ -328,8 +349,22 @@ end
|
||||
-- ## Add a single entry
|
||||
--
|
||||
-- local baimenu = menumgr:NewEntry("BAI",mymenu_lv1b)
|
||||
--
|
||||
-- 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
|
||||
--
|
||||
-- menumgr:ChangeEntryTextForAll(mymenu_lv1b,"Attack")
|
||||
@ -346,7 +381,7 @@ end
|
||||
CLIENTMENUMANAGER = {
|
||||
ClassName = "CLIENTMENUMANAGER",
|
||||
lid = "",
|
||||
version = "0.0.4",
|
||||
version = "0.1.0",
|
||||
name = nil,
|
||||
clientset = nil,
|
||||
menutree = {},
|
||||
@ -370,7 +405,7 @@ function CLIENTMENUMANAGER:New(ClientSet, Alias)
|
||||
-- Log id.
|
||||
self.lid=string.format("CLIENTMENUMANAGER %s | %s | ", self.version, self.name)
|
||||
if self.debug then
|
||||
self:I(self.lid.."Created")
|
||||
self:T(self.lid.."Created")
|
||||
end
|
||||
return self
|
||||
end
|
||||
@ -396,12 +431,21 @@ function CLIENTMENUMANAGER:NewEntry(Text,Parent,Function,...)
|
||||
return entry
|
||||
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.
|
||||
-- @param #CLIENTMENUMANAGER self
|
||||
-- @param #string UUID UUID of the menu entry.
|
||||
-- @return #CLIENTMENU Entry The #CLIENTMENU object found or nil.
|
||||
function CLIENTMENUMANAGER:FindEntryByUUID(UUID)
|
||||
self:I(self.lid.."FindEntryByUUID "..UUID or "None")
|
||||
self:T(self.lid.."FindEntryByUUID "..UUID or "None")
|
||||
local entry = nil
|
||||
for _gid,_entry in pairs(self.flattree) do
|
||||
local Entry = _entry -- #CLIENTMENU
|
||||
@ -412,33 +456,82 @@ function CLIENTMENUMANAGER:FindEntryByUUID(UUID)
|
||||
return entry
|
||||
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 #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 #CLIENTMENU objects
|
||||
function CLIENTMENUMANAGER:FindUUIDsByText(Text)
|
||||
self:I(self.lid.."FindUUIDsByText "..Text or "None")
|
||||
-- @return #number Number of matches
|
||||
function CLIENTMENUMANAGER:FindUUIDsByText(Text,Parent)
|
||||
self:T(self.lid.."FindUUIDsByText "..Text or "None")
|
||||
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.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
|
||||
table.insert(matches,_uuid)
|
||||
table.insert(entries,Entry )
|
||||
n=n+1
|
||||
end
|
||||
end
|
||||
return matches, entries
|
||||
end
|
||||
return matches, entries, n
|
||||
end
|
||||
|
||||
--- Find matching entries in the generic structure by the menu text.
|
||||
-- @param #CLIENTMENUMANAGER self
|
||||
-- @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.
|
||||
function CLIENTMENUMANAGER:FindEntriesByText(Text)
|
||||
self:I(self.lid.."FindEntriesByText "..Text or "None")
|
||||
local matches, objects = self:FindUUIDsByText(Text)
|
||||
return objects
|
||||
-- @return #number Number of matches
|
||||
function CLIENTMENUMANAGER:FindEntriesByText(Text,Parent)
|
||||
self:T(self.lid.."FindEntriesByText "..Text or "None")
|
||||
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
|
||||
|
||||
--- 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.
|
||||
-- @return #CLIENTMENU Entry
|
||||
function CLIENTMENUMANAGER:Propagate(Client)
|
||||
self:I(self.lid.."Propagate")
|
||||
self:I(Client)
|
||||
self:T(self.lid.."Propagate")
|
||||
self:T(Client)
|
||||
local Set = self.clientset.Set
|
||||
if Client then
|
||||
Set = {Client}
|
||||
@ -483,12 +576,12 @@ function CLIENTMENUMANAGER:Propagate(Client)
|
||||
self.playertree[playername] = {}
|
||||
end
|
||||
for level,branch in pairs (self.menutree) do
|
||||
self:I("Building branch:" .. level)
|
||||
self:T("Building branch:" .. level)
|
||||
for _,leaf in pairs(branch) do
|
||||
self:I("Building leaf:" .. leaf)
|
||||
self:T("Building leaf:" .. leaf)
|
||||
local entry = self:FindEntryByUUID(leaf)
|
||||
if entry then
|
||||
self:I("Found generic entry:" .. entry.UUID)
|
||||
self:T("Found generic entry:" .. entry.UUID)
|
||||
local parent = nil
|
||||
if entry.Parent and entry.Parent.UUID then
|
||||
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].Once = entry.Once
|
||||
else
|
||||
self:I("NO generic entry for:" .. leaf)
|
||||
self:T("NO generic entry for:" .. leaf)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -521,15 +614,18 @@ function CLIENTMENUMANAGER:AddEntry(Entry,Client)
|
||||
if client and client:IsAlive() then
|
||||
local playername = client:GetPlayerName()
|
||||
if Entry then
|
||||
self:I("Adding generic entry:" .. Entry.UUID)
|
||||
self:T("Adding generic entry:" .. Entry.UUID)
|
||||
local parent = nil
|
||||
if not self.playertree[playername] then
|
||||
self.playertree[playername] = {}
|
||||
end
|
||||
if Entry.Parent and Entry.Parent.UUID then
|
||||
parent = self.playertree[playername][Entry.Parent.UUID] or self:FindEntryByUUID(Entry.Parent.UUID)
|
||||
end
|
||||
self.playertree[playername][Entry.UUID] = CLIENTMENU:NewEntry(client,Entry.name,parent,Entry.Function,unpack(Entry.Functionargs))
|
||||
self.playertree[playername][Entry.UUID].Once = Entry.Once
|
||||
else
|
||||
self:I("NO generic entry given")
|
||||
self:T("NO generic entry given")
|
||||
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.
|
||||
-- @return #CLIENTMENUMANAGER self
|
||||
function CLIENTMENUMANAGER:DeleteF10Entry(Entry,Client)
|
||||
self:I(self.lid.."DeleteF10Entry")
|
||||
self:T(self.lid.."DeleteF10Entry")
|
||||
local Set = self.clientset.Set
|
||||
if Client then
|
||||
Set = {Client}
|
||||
@ -588,6 +684,7 @@ function CLIENTMENUMANAGER:DeleteF10Entry(Entry,Client)
|
||||
if self.playertree[playername] then
|
||||
local centry = self.playertree[playername][Entry.UUID] -- #CLIENTMENU
|
||||
if centry then
|
||||
--self:I("Match for "..Entry.UUID)
|
||||
centry:Clear()
|
||||
end
|
||||
end
|
||||
@ -601,7 +698,7 @@ end
|
||||
-- @param #CLIENTMENU Entry The entry to remove
|
||||
-- @return #CLIENTMENUMANAGER self
|
||||
function CLIENTMENUMANAGER:DeleteGenericEntry(Entry)
|
||||
self:I(self.lid.."DeleteGenericEntry")
|
||||
self:T(self.lid.."DeleteGenericEntry")
|
||||
|
||||
if Entry.Children and #Entry.Children > 0 then
|
||||
self:RemoveGenericSubEntries(Entry)
|
||||
@ -614,11 +711,11 @@ function CLIENTMENUMANAGER:DeleteGenericEntry(Entry)
|
||||
|
||||
if tbl[depth] then
|
||||
for i=depth,#tbl do
|
||||
self:I("Level = "..i)
|
||||
--self:I("Level = "..i)
|
||||
for _id,_uuid in pairs(tbl[i]) do
|
||||
self:I(_uuid)
|
||||
if string.find(_uuid,uuid) then
|
||||
self:I("Match for ".._uuid)
|
||||
self:T(_uuid)
|
||||
if string.find(_uuid,uuid) or _uuid == uuid then
|
||||
--self:I("Match for ".._uuid)
|
||||
self.menutree[i][_id] = nil
|
||||
self.flattree[_uuid] = nil
|
||||
end
|
||||
@ -634,7 +731,7 @@ end
|
||||
-- @param #CLIENTMENU Entry The entry where to start. This entry stays.
|
||||
-- @return #CLIENTMENUMANAGER self
|
||||
function CLIENTMENUMANAGER:RemoveGenericSubEntries(Entry)
|
||||
self:I(self.lid.."RemoveGenericSubEntries")
|
||||
self:T(self.lid.."RemoveGenericSubEntries")
|
||||
|
||||
local depth = #Entry.path + 1
|
||||
local uuid = Entry.UUID
|
||||
@ -643,11 +740,11 @@ function CLIENTMENUMANAGER:RemoveGenericSubEntries(Entry)
|
||||
|
||||
if tbl[depth] then
|
||||
for i=depth,#tbl do
|
||||
self:I("Level = "..i)
|
||||
self:T("Level = "..i)
|
||||
for _id,_uuid in pairs(tbl[i]) do
|
||||
self:I(_uuid)
|
||||
self:T(_uuid)
|
||||
if string.find(_uuid,uuid) then
|
||||
self:I("Match for ".._uuid)
|
||||
self:T("Match for ".._uuid)
|
||||
self.menutree[i][_id] = nil
|
||||
self.flattree[_uuid] = nil
|
||||
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.
|
||||
-- @return #CLIENTMENUMANAGER self
|
||||
function CLIENTMENUMANAGER:RemoveF10SubEntries(Entry,Client)
|
||||
self:I(self.lid.."RemoveSubEntries")
|
||||
self:T(self.lid.."RemoveSubEntries")
|
||||
local Set = self.clientset.Set
|
||||
if Client then
|
||||
Set = {Client}
|
||||
|
||||
@ -278,7 +278,9 @@ do -- MENU_BASE
|
||||
end
|
||||
|
||||
end
|
||||
do -- MENU_COMMAND_BASE
|
||||
do
|
||||
---
|
||||
-- MENU_COMMAND_BASE
|
||||
-- @type MENU_COMMAND_BASE
|
||||
-- @field #function MenuCallHandler
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
@ -344,7 +346,9 @@ do -- MENU_COMMAND_BASE
|
||||
end
|
||||
end
|
||||
|
||||
do -- MENU_MISSION
|
||||
do
|
||||
---
|
||||
-- MENU_MISSION
|
||||
-- @type MENU_MISSION
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
--- Manages the main menus for a complete mission.
|
||||
@ -432,8 +436,9 @@ do -- MENU_MISSION
|
||||
end
|
||||
|
||||
end
|
||||
do -- MENU_MISSION_COMMAND
|
||||
do
|
||||
|
||||
--- MENU_MISSION_COMMAND
|
||||
-- @type MENU_MISSION_COMMAND
|
||||
-- @extends Core.Menu#MENU_COMMAND_BASE
|
||||
|
||||
@ -510,7 +515,8 @@ do -- MENU_MISSION_COMMAND
|
||||
return self
|
||||
end
|
||||
end
|
||||
do -- MENU_COALITION
|
||||
do
|
||||
--- MENU_COALITION
|
||||
-- @type MENU_COALITION
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
|
||||
@ -636,8 +642,9 @@ do -- MENU_COALITION
|
||||
return self
|
||||
end
|
||||
end
|
||||
do -- MENU_COALITION_COMMAND
|
||||
do
|
||||
|
||||
--- MENU_COALITION_COMMAND
|
||||
-- @type MENU_COALITION_COMMAND
|
||||
-- @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.
|
||||
-- the same menus twice during initialization logic.
|
||||
-- These menu classes are handling this logic with this variable.
|
||||
|
||||
local _MENUGROUPS = {}
|
||||
|
||||
---
|
||||
-- @type MENU_GROUP
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
|
||||
@ -900,7 +910,7 @@ do
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- @type MENU_GROUP_COMMAND
|
||||
-- @extends Core.Menu#MENU_COMMAND_BASE
|
||||
|
||||
@ -984,6 +994,7 @@ do
|
||||
end
|
||||
--- MENU_GROUP_DELAYED
|
||||
do
|
||||
---
|
||||
-- @type MENU_GROUP_DELAYED
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
|
||||
@ -1107,7 +1118,7 @@ do
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- @type MENU_GROUP_COMMAND_DELAYED
|
||||
-- @extends Core.Menu#MENU_COMMAND_BASE
|
||||
|
||||
|
||||
@ -3946,6 +3946,7 @@ end
|
||||
|
||||
do -- SET_CLIENT
|
||||
|
||||
---
|
||||
-- @type SET_CLIENT
|
||||
-- @field Core.Timer#TIMER ZoneTimer
|
||||
-- @field #number ZoneTimerInterval
|
||||
@ -4059,7 +4060,7 @@ do -- SET_CLIENT
|
||||
|
||||
--- Remove CLIENT(s) from SET_CLIENT.
|
||||
-- @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
|
||||
function SET_CLIENT:RemoveClientsByName( RemoveClientNames )
|
||||
|
||||
|
||||
@ -954,6 +954,7 @@ do
|
||||
-- @field Utilities.FiFo#FIFO TasksPerPlayer
|
||||
-- @field Utilities.FiFo#FIFO PrecisionTasks
|
||||
-- @field Core.Set#SET_CLIENT ClientSet
|
||||
-- @field Core.Set#SET_CLIENT ActiveClientSet
|
||||
-- @field #string ClientFilter
|
||||
-- @field #string Name
|
||||
-- @field #string Type
|
||||
@ -1610,20 +1611,22 @@ function PLAYERTASKCONTROLLER:New(Name, Coalition, Type, ClientFilter)
|
||||
|
||||
self.UseTypeNames = false
|
||||
|
||||
local IsClientSet = false
|
||||
self.IsClientSet = false
|
||||
|
||||
if ClientFilter and type(ClientFilter) == "table" and ClientFilter.ClassName and ClientFilter.ClassName == "SET_CLIENT" then
|
||||
-- we have a predefined SET_CLIENT
|
||||
self.ClientSet = ClientFilter
|
||||
IsClientSet = true
|
||||
self.IsClientSet = true
|
||||
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()
|
||||
elseif not IsClientSet then
|
||||
elseif not self.IsClientSet then
|
||||
self.ClientSet = SET_CLIENT:New():FilterCoalitions(string.lower(self.CoalitionName)):FilterActive(true):FilterStart()
|
||||
end
|
||||
|
||||
self.ActiveClientSet = SET_CLIENT:New()
|
||||
|
||||
self.lid=string.format("PlayerTaskController %s %s | ", self.Name, tostring(self.Type))
|
||||
|
||||
self:_InitLocalization()
|
||||
@ -2171,7 +2174,8 @@ end
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
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.IniPlayerName then
|
||||
self:T(self.lid.."Event for player: "..EventData.IniPlayerName)
|
||||
@ -2195,11 +2199,14 @@ function PLAYERTASKCONTROLLER:_EventHandler(EventData)
|
||||
self:T(self.lid..text)
|
||||
end
|
||||
elseif EventData.id == EVENTS.PlayerEnterAircraft and EventData.IniCoalition == self.Coalition then
|
||||
if EventData.IniPlayerName and EventData.IniGroup and self.UseSRS then
|
||||
if self.ClientSet:IsNotInSet(CLIENT:FindByName(EventData.IniUnitName)) then
|
||||
if EventData.IniPlayerName and EventData.IniGroup 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
|
||||
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 freqtext = ""
|
||||
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(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)
|
||||
end
|
||||
if EventData.IniPlayerName then
|
||||
self.PlayerMenu[EventData.IniPlayerName] = nil
|
||||
--self:_BuildMenus(CLIENT:FindByName(EventData.IniUnitName))
|
||||
--self:_BuildMenus(CLIENT:FindByPlayerName(EventData.IniPlayerName))
|
||||
local player = CLIENT:FindByName(EventData.IniUnitName)
|
||||
self:I({player})
|
||||
local controller = self.JoinTaskMenuTemplate
|
||||
controller:Propagate(player)
|
||||
self:_SwitchMenuForClient(player,"Info")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -2362,11 +2366,23 @@ function PLAYERTASKCONTROLLER:_GetTasksPerType()
|
||||
local threat=_data.threat
|
||||
local task = _data.task -- Ops.PlayerTask#PLAYERTASK
|
||||
local type = task.Type
|
||||
local name = task.Target:GetName()
|
||||
--self:I(name)
|
||||
if not task:IsDone() then
|
||||
--self:I(name)
|
||||
table.insert(tasktypes[type],task)
|
||||
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
|
||||
end
|
||||
|
||||
@ -2478,7 +2494,7 @@ function PLAYERTASKCONTROLLER:_CheckTaskQueue()
|
||||
local client = _client --Wrapper.Client#CLIENT
|
||||
local group = client:GetGroup()
|
||||
for _,task in pairs(nexttasks) do
|
||||
self:_JoinTask(group,client,task,true)
|
||||
self:_JoinTask(task,true,group,client)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -2497,7 +2513,7 @@ end
|
||||
-- @param #PLAYERTASKCONTROLLER self
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
function PLAYERTASKCONTROLLER:_CheckPrecisionTasks()
|
||||
self:T(self.lid.."_CheckTaskQueue")
|
||||
self:T(self.lid.."_CheckPrecisionTasks")
|
||||
if self.PrecisionTasks:Count() > 0 and self.precisionbombing then
|
||||
if not self.LasingDrone or self.LasingDrone:IsDead() then
|
||||
-- we need a new drone
|
||||
@ -3006,9 +3022,14 @@ end
|
||||
-- @param Wrapper.Client#CLIENT Client
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
function PLAYERTASKCONTROLLER:_JoinTask(Task, Force, Group, Client)
|
||||
self:T({Force, Group, Client})
|
||||
self:T(self.lid.."_JoinTask")
|
||||
local force = false
|
||||
if type(Force) == "boolean" then
|
||||
force = Force
|
||||
end
|
||||
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
|
||||
if not self.NoScreenOutput then
|
||||
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:__PlayerJoinedTask(1, Group, Client, Task)
|
||||
-- clear menu
|
||||
--self:_BuildMenus(Client,true)
|
||||
self:_SwitchMenuForClient(Client,"Active",1)
|
||||
end
|
||||
if Task.Type == AUFTRAG.Type.PRECISIONBOMBING 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 text = ""
|
||||
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?
|
||||
-- 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 ttsname = self.gettext:GetEntry("TASKNAMETTS",self.locale)
|
||||
local taskname = string.format(tname,task.Type,task.PlayerTaskNr)
|
||||
@ -3424,119 +3449,173 @@ function PLAYERTASKCONTROLLER:_AbortTask(Group, Client)
|
||||
if not self.NoScreenOutput then
|
||||
local m=MESSAGE:New(text,15,"Tasking"):ToClient(Client)
|
||||
end
|
||||
--self:_BuildMenus(Client,true)
|
||||
self:_SwitchMenuForClient(Client,"Info",1)
|
||||
return self
|
||||
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
|
||||
|
||||
--- [Internal] _UpdateJoinMenuTemplate
|
||||
-- @param #PLAYERTASKCONTROLLER self
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
function PLAYERTASKCONTROLLER:_UpdateJoinMenuTemplate()
|
||||
self:I("_UpdateJoinMenuTemplate")
|
||||
self:T("_UpdateJoinMenuTemplate")
|
||||
if self.TaskQueue:Count() > 0 then
|
||||
local taskpertype = self:_GetTasksPerType()
|
||||
local JoinMenu = self.JoinMenu -- Core.ClientMenu#CLIENTMENU
|
||||
self:I(JoinMenu.path)
|
||||
--self:I(JoinMenu.UUID)
|
||||
local controller = self.JoinTaskMenuTemplate -- Core.ClientMenu#CLIENTMENUMANAGER
|
||||
local actcontroller = self.ActiveTaskMenuTemplate -- Core.ClientMenu#CLIENTMENUMANAGER
|
||||
local entrynumbers = {}
|
||||
local existingentries = {}
|
||||
local actinfomenu = self.ActiveInfoMenu
|
||||
--local entrynumbers = {}
|
||||
--local existingentries = {}
|
||||
local maxn = self.menuitemlimit
|
||||
-- Generate task type menu items
|
||||
for _type,_ in pairs(taskpertype) do
|
||||
--local found = controller:FindEntryByText(_type)
|
||||
local found, text = controller:FindEntryUnderParentByText(JoinMenu,_type)
|
||||
self:I(text)
|
||||
if not found then
|
||||
local found = controller:FindEntriesByText(_type)
|
||||
--self:I({found})
|
||||
if #found == 0 then
|
||||
local newentry = controller:NewEntry(_type,JoinMenu)
|
||||
controller:AddEntry(newentry)
|
||||
if self.JoinInfoMenu then
|
||||
local newentry = controller:NewEntry(_type,self.JoinInfoMenu)
|
||||
controller:AddEntry(newentry)
|
||||
end
|
||||
entrynumbers[_type] = 0
|
||||
existingentries[_type] = {}
|
||||
if actinfomenu then
|
||||
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
|
||||
--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
|
||||
|
||||
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
|
||||
return found
|
||||
end
|
||||
|
||||
end
|
||||
return self
|
||||
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()
|
||||
self:I("_CreateActiveTaskMenuTemplate")
|
||||
self:T("_CreateActiveTaskMenuTemplate")
|
||||
|
||||
local menujoin = self.gettext:GetEntry("MENUJOIN",self.locale)
|
||||
local menunotasks = self.gettext:GetEntry("MENUNOTASKS",self.locale)
|
||||
@ -3552,7 +3631,7 @@ function PLAYERTASKCONTROLLER:_CreateJoinMenuTemplate()
|
||||
end
|
||||
|
||||
if self.AllowFlash then
|
||||
JoinTaskMenuTemplate:NewEntry(flashtext,self.JoinTopMenu,self._SwitchFlashing,self,group,client)
|
||||
JoinTaskMenuTemplate:NewEntry(flashtext,self.JoinTopMenu,self._SwitchFlashing,self)
|
||||
end
|
||||
|
||||
self.JoinMenu = JoinTaskMenuTemplate:NewEntry(menujoin,self.JoinTopMenu)
|
||||
@ -3571,9 +3650,11 @@ function PLAYERTASKCONTROLLER:_CreateJoinMenuTemplate()
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- [Internal] _CreateActiveTaskMenuTemplate
|
||||
-- @param #PLAYERTASKCONTROLLER self
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate()
|
||||
self:I("_CreateActiveTaskMenuTemplate")
|
||||
self:T("_CreateActiveTaskMenuTemplate")
|
||||
|
||||
local menuactive = self.gettext:GetEntry("MENUACTIVE",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 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
|
||||
local taskings = self.gettext:GetEntry("MENUTASKING",self.locale)
|
||||
@ -3594,24 +3675,24 @@ function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate()
|
||||
|
||||
if self.AllowFlash then
|
||||
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
|
||||
|
||||
local active = ActiveTaskMenuTemplate:NewEntry(menuactive,self.ActiveTopMenu)
|
||||
ActiveTaskMenuTemplate:NewEntry(menuinfo,active,self._ActiveTaskInfo,self,nil)
|
||||
ActiveTaskMenuTemplate:NewEntry(menumark,active,self._MarkTask,self,nil)
|
||||
ActiveTaskMenuTemplate:NewEntry(menuinfo,active,self._ActiveTaskInfo,self,"NONE")
|
||||
ActiveTaskMenuTemplate:NewEntry(menumark,active,self._MarkTask,self)
|
||||
|
||||
if self.Type ~= PLAYERTASKCONTROLLER.Type.A2A and self.noflaresmokemenu ~= true then
|
||||
ActiveTaskMenuTemplate:NewEntry(menusmoke,active,self._SmokeTask,self,group,client)
|
||||
ActiveTaskMenuTemplate:NewEntry(menuflare,active,self._FlareTask,self,group,client)
|
||||
ActiveTaskMenuTemplate:NewEntry(menusmoke,active,self._SmokeTask,self)
|
||||
ActiveTaskMenuTemplate:NewEntry(menuflare,active,self._FlareTask,self)
|
||||
|
||||
if self.illumenu then
|
||||
ActiveTaskMenuTemplate:NewEntry(menuillu,active,self._IlluminateTask,self,group,client)
|
||||
ActiveTaskMenuTemplate:NewEntry(menuillu,active,self._IlluminateTask,self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ActiveTaskMenuTemplate:NewEntry(menuabort,active,self._AbortTask,self,group,client)
|
||||
ActiveTaskMenuTemplate:NewEntry(menuabort,active,self._AbortTask,self)
|
||||
self.ActiveTaskMenuTemplate = ActiveTaskMenuTemplate
|
||||
|
||||
if self.taskinfomenu and self.activehasinfomenu then
|
||||
@ -3622,215 +3703,33 @@ function PLAYERTASKCONTROLLER:_CreateActiveTaskMenuTemplate()
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Build client menus
|
||||
--- [Internal] _SwitchMenuForClient
|
||||
-- @param #PLAYERTASKCONTROLLER self
|
||||
-- @param Wrapper.Client#CLIENT Client (optional) build for this client name only
|
||||
-- @param #boolean enforced
|
||||
-- @param #boolean fromsuccess
|
||||
-- @param Wrapper.Client#CLIENT Client The client
|
||||
-- @param #string MenuType
|
||||
-- @param #number Delay
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
function PLAYERTASKCONTROLLER:_BuildMenus(Client,enforced,fromsuccess)
|
||||
self:T(self.lid.."_BuildMenus")
|
||||
|
||||
if self.MenuBuildLocked and (timer.getAbsTime() - self.MenuBuildLocked < 2) then
|
||||
self:ScheduleOnce(2,self._BuildMenus,self,Client,enforced,fromsuccess)
|
||||
function PLAYERTASKCONTROLLER:_SwitchMenuForClient(Client,MenuType,Delay)
|
||||
self:T(self.lid.."_SwitchMenuForClient")
|
||||
if Delay then
|
||||
self:ScheduleOnce(Delay,self._SwitchMenuForClient,self,Client,MenuType)
|
||||
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
|
||||
self.MenuBuildLocked = timer.getAbsTime()
|
||||
self:E(self.lid .."Unknown menu type in _SwitchMenuForClient:"..tostring(MenuType))
|
||||
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
|
||||
end
|
||||
|
||||
@ -3978,8 +3877,8 @@ end
|
||||
-- @param Core.Menu#MENU_MISSION Menu
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
function PLAYERTASKCONTROLLER:SetParentMenu(Menu)
|
||||
self:T(self.lid.."SetParentName")
|
||||
self.MenuParent = Menu
|
||||
self:T(self.lid.."SetParentMenu")
|
||||
--self.MenuParent = Menu
|
||||
return self
|
||||
end
|
||||
|
||||
@ -4140,8 +4039,8 @@ end
|
||||
-- @param #string To
|
||||
-- @return #PLAYERTASKCONTROLLER self
|
||||
function PLAYERTASKCONTROLLER:onafterStart(From, Event, To)
|
||||
self:I({From, Event, To})
|
||||
self:I(self.lid.."onafterStart")
|
||||
self:T({From, Event, To})
|
||||
self:T(self.lid.."onafterStart")
|
||||
self:_CreateJoinMenuTemplate()
|
||||
self:_CreateActiveTaskMenuTemplate()
|
||||
return self
|
||||
@ -4176,8 +4075,6 @@ function PLAYERTASKCONTROLLER:onafterStatus(From, Event, To)
|
||||
end
|
||||
end
|
||||
|
||||
--self:_BuildMenus(nil,enforcedmenu)
|
||||
|
||||
self:_UpdateJoinMenuTemplate()
|
||||
|
||||
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))
|
||||
self.SRSQueue:NewTransmission(taskname,nil,self.SRS,nil,2)
|
||||
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
|
||||
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))
|
||||
self.SRSQueue:NewTransmission(taskname,nil,self.SRS,nil,2)
|
||||
end
|
||||
|
||||
local clients=Task:GetClientObjects()
|
||||
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
|
||||
return self
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user