Menu optimization

This commit is contained in:
FlightControl
2017-03-17 06:57:32 +01:00
parent 4c64548bea
commit af55214c52
10 changed files with 257 additions and 70165 deletions
@@ -108,7 +108,7 @@ do -- ACT_ASSIST
function ACT_ASSIST:onafterStart( ProcessUnit, From, Event, To ) function ACT_ASSIST:onafterStart( ProcessUnit, From, Event, To )
local ProcessGroup = ProcessUnit:GetGroup() local ProcessGroup = ProcessUnit:GetGroup()
local MissionMenu = self:GetMission():GetMissionMenu( ProcessGroup ) local MissionMenu = self:GetMission():GetMenu( ProcessGroup )
local function MenuSmoke( MenuParam ) local function MenuSmoke( MenuParam )
self:E( MenuParam ) self:E( MenuParam )
+104 -46
View File
@@ -138,6 +138,8 @@ do -- MENU_BASE
} }
--- Consructor --- Consructor
-- @param #MENU_BASE
-- @return #MENU_BASE
function MENU_BASE:New( MenuText, ParentMenu ) function MENU_BASE:New( MenuText, ParentMenu )
local MenuParentPath = {} local MenuParentPath = {}
@@ -150,10 +152,32 @@ do -- MENU_BASE
self.MenuPath = nil self.MenuPath = nil
self.MenuText = MenuText self.MenuText = MenuText
self.MenuParentPath = MenuParentPath self.MenuParentPath = MenuParentPath
self.Menus = {}
self.MenuTime = timer.getTime()
return self return self
end end
--- Gets a @{Menu} from a parent @{Menu}
-- @param #MENU_BASE self
-- @param #string MenuText The text of the child menu.
-- @return #MENU_BASE
function MENU_BASE:GetMenu( MenuText )
self:F( { self.Menus, MenuText } )
return self.Menus[MenuText]
end
--- Sets a time stamp for later prevention of menu removal.
-- @param #MENU_BASE self
-- @param MenuTime
-- @return #MENU_BASE
function MENU_BASE:SetTime( MenuTime )
self.MenuTime = MenuTime
return self
end
end end
do -- MENU_COMMAND_BASE do -- MENU_COMMAND_BASE
@@ -161,7 +185,7 @@ do -- MENU_COMMAND_BASE
--- The MENU_COMMAND_BASE class --- The MENU_COMMAND_BASE class
-- @type MENU_COMMAND_BASE -- @type MENU_COMMAND_BASE
-- @field #function MenuCallHandler -- @field #function MenuCallHandler
-- @extends Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
MENU_COMMAND_BASE = { MENU_COMMAND_BASE = {
ClassName = "MENU_COMMAND_BASE", ClassName = "MENU_COMMAND_BASE",
CommandMenuFunction = nil, CommandMenuFunction = nil,
@@ -170,6 +194,8 @@ do -- MENU_COMMAND_BASE
} }
--- Constructor --- Constructor
-- @param #MENU_COMMAND_BASE
-- @return #MENU_COMMAND_BASE
function MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, CommandMenuArguments ) function MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, CommandMenuArguments )
local self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) ) local self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
@@ -189,7 +215,7 @@ do -- MENU_MISSION
--- The MENU_MISSION class --- The MENU_MISSION class
-- @type MENU_MISSION -- @type MENU_MISSION
-- @extends Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
MENU_MISSION = { MENU_MISSION = {
ClassName = "MENU_MISSION" ClassName = "MENU_MISSION"
} }
@@ -198,7 +224,7 @@ do -- MENU_MISSION
-- @param #MENU_MISSION self -- @param #MENU_MISSION self
-- @param #string MenuText The text for the menu. -- @param #string MenuText The text for the menu.
-- @param #table ParentMenu The parent menu. This parameter can be ignored if you want the menu to be located at the perent menu of DCS world (under F10 other). -- @param #table ParentMenu The parent menu. This parameter can be ignored if you want the menu to be located at the perent menu of DCS world (under F10 other).
-- @return #MENU_MISSION self -- @return #MENU_MISSION
function MENU_MISSION:New( MenuText, ParentMenu ) function MENU_MISSION:New( MenuText, ParentMenu )
local self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) ) local self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
@@ -225,7 +251,7 @@ do -- MENU_MISSION
--- Removes the sub menus recursively of this MENU_MISSION. Note that the main menu is kept! --- Removes the sub menus recursively of this MENU_MISSION. Note that the main menu is kept!
-- @param #MENU_MISSION self -- @param #MENU_MISSION self
-- @return #MENU_MISSION self -- @return #MENU_MISSION
function MENU_MISSION:RemoveSubMenus() function MENU_MISSION:RemoveSubMenus()
self:F( self.MenuPath ) self:F( self.MenuPath )
@@ -256,7 +282,7 @@ do -- MENU_MISSION_COMMAND
--- The MENU_MISSION_COMMAND class --- The MENU_MISSION_COMMAND class
-- @type MENU_MISSION_COMMAND -- @type MENU_MISSION_COMMAND
-- @extends Menu#MENU_COMMAND_BASE -- @extends Core.Menu#MENU_COMMAND_BASE
MENU_MISSION_COMMAND = { MENU_MISSION_COMMAND = {
ClassName = "MENU_MISSION_COMMAND" ClassName = "MENU_MISSION_COMMAND"
} }
@@ -306,7 +332,7 @@ do -- MENU_COALITION
--- The MENU_COALITION class --- The MENU_COALITION class
-- @type MENU_COALITION -- @type MENU_COALITION
-- @extends Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
-- @usage -- @usage
-- -- This demo creates a menu structure for the planes within the red coalition. -- -- This demo creates a menu structure for the planes within the red coalition.
-- -- To test, join the planes, then look at the other radio menus (Option F10). -- -- To test, join the planes, then look at the other radio menus (Option F10).
@@ -380,7 +406,7 @@ do -- MENU_COALITION
--- Removes the sub menus recursively of this MENU_COALITION. Note that the main menu is kept! --- Removes the sub menus recursively of this MENU_COALITION. Note that the main menu is kept!
-- @param #MENU_COALITION self -- @param #MENU_COALITION self
-- @return #MENU_COALITION self -- @return #MENU_COALITION
function MENU_COALITION:RemoveSubMenus() function MENU_COALITION:RemoveSubMenus()
self:F( self.MenuPath ) self:F( self.MenuPath )
@@ -411,7 +437,7 @@ do -- MENU_COALITION_COMMAND
--- The MENU_COALITION_COMMAND class --- The MENU_COALITION_COMMAND class
-- @type MENU_COALITION_COMMAND -- @type MENU_COALITION_COMMAND
-- @extends Menu#MENU_COMMAND_BASE -- @extends Core.Menu#MENU_COMMAND_BASE
MENU_COALITION_COMMAND = { MENU_COALITION_COMMAND = {
ClassName = "MENU_COALITION_COMMAND" ClassName = "MENU_COALITION_COMMAND"
} }
@@ -423,7 +449,7 @@ do -- MENU_COALITION_COMMAND
-- @param Menu#MENU_COALITION ParentMenu The parent menu. -- @param Menu#MENU_COALITION ParentMenu The parent menu.
-- @param CommandMenuFunction A function that is called when the menu key is pressed. -- @param CommandMenuFunction A function that is called when the menu key is pressed.
-- @param CommandMenuArgument An argument for the function. There can only be ONE argument given. So multiple arguments must be wrapped into a table. See the below example how to do this. -- @param CommandMenuArgument An argument for the function. There can only be ONE argument given. So multiple arguments must be wrapped into a table. See the below example how to do this.
-- @return #MENU_COALITION_COMMAND self -- @return #MENU_COALITION_COMMAND
function MENU_COALITION_COMMAND:New( Coalition, MenuText, ParentMenu, CommandMenuFunction, ... ) function MENU_COALITION_COMMAND:New( Coalition, MenuText, ParentMenu, CommandMenuFunction, ... )
local self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) ) local self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) )
@@ -468,7 +494,7 @@ do -- MENU_CLIENT
--- MENU_COALITION constructor. Creates a new radio command item for a coalition, which can invoke a function with parameters. --- MENU_COALITION constructor. Creates a new radio command item for a coalition, which can invoke a function with parameters.
-- @type MENU_CLIENT -- @type MENU_CLIENT
-- @extends Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
-- @usage -- @usage
-- -- This demo creates a menu structure for the two clients of planes. -- -- This demo creates a menu structure for the two clients of planes.
-- -- Each client will receive a different menu structure. -- -- Each client will receive a different menu structure.
@@ -609,7 +635,7 @@ do -- MENU_CLIENT
--- The MENU_CLIENT_COMMAND class --- The MENU_CLIENT_COMMAND class
-- @type MENU_CLIENT_COMMAND -- @type MENU_CLIENT_COMMAND
-- @extends Menu#MENU_COMMAND -- @extends Core.Menu#MENU_COMMAND
MENU_CLIENT_COMMAND = { MENU_CLIENT_COMMAND = {
ClassName = "MENU_CLIENT_COMMAND" ClassName = "MENU_CLIENT_COMMAND"
} }
@@ -695,7 +721,7 @@ do
--- The MENU_GROUP class --- The MENU_GROUP class
-- @type MENU_GROUP -- @type MENU_GROUP
-- @extends Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
-- @usage -- @usage
-- -- This demo creates a menu structure for the two groups of planes. -- -- This demo creates a menu structure for the two groups of planes.
-- -- Each group will receive a different menu structure. -- -- Each group will receive a different menu structure.
@@ -769,8 +795,6 @@ do
self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) ) self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
MenuGroup._Menus[Path] = self MenuGroup._Menus[Path] = self
self.Menus = {}
self.MenuGroup = MenuGroup self.MenuGroup = MenuGroup
self.Path = Path self.Path = Path
self.MenuGroupID = MenuGroup:GetID() self.MenuGroupID = MenuGroup:GetID()
@@ -781,7 +805,8 @@ do
self.MenuPath = missionCommands.addSubMenuForGroup( self.MenuGroupID, MenuText, self.MenuParentPath ) self.MenuPath = missionCommands.addSubMenuForGroup( self.MenuGroupID, MenuText, self.MenuParentPath )
if ParentMenu and ParentMenu.Menus then if ParentMenu and ParentMenu.Menus then
ParentMenu.Menus[self.MenuPath] = self ParentMenu.Menus[MenuText] = self
self:F( { ParentMenu.Menus, MenuText } )
end end
end end
@@ -792,43 +817,59 @@ do
--- Removes the sub menus recursively of this MENU_GROUP. --- Removes the sub menus recursively of this MENU_GROUP.
-- @param #MENU_GROUP self -- @param #MENU_GROUP self
-- @param MenuTime
-- @return #MENU_GROUP self -- @return #MENU_GROUP self
function MENU_GROUP:RemoveSubMenus() function MENU_GROUP:RemoveSubMenus( MenuTime )
self:F2( self.MenuPath ) self:F2( { self.MenuPath, MenuTime, self.MenuTime } )
self:T( { "Removing Group SubMenus:", self.MenuGroup:GetName(), self.MenuPath } ) self:T( { "Removing Group SubMenus:", self.MenuGroup:GetName(), self.MenuPath } )
for MenuID, Menu in pairs( self.Menus ) do for MenuText, Menu in pairs( self.Menus ) do
Menu:Remove() Menu:Remove( MenuTime )
end end
end end
--- Removes the main menu of this MENU_GROUP.
-- @param #MENU_GROUP self
-- @param MenuTime
-- @return #nil
function MENU_GROUP:RemoveTop( MenuTime )
self:F( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
if not MenuTime or self.MenuTime ~= MenuTime then
if self.MenuGroup._Menus[self.Path] then
self = self.MenuGroup._Menus[self.Path]
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
if self.ParentMenu then
self.ParentMenu.Menus[self.MenuText] = nil
end
self:T( { "Removing Group Menu:", self.MenuGroup:GetName(), self.MenuGroup._Menus[self.Path].Path } )
self.MenuGroup._Menus[self.Path] = nil
self = nil
end
end
return nil
end
--- Removes the main menu and sub menus recursively of this MENU_GROUP. --- Removes the main menu and sub menus recursively of this MENU_GROUP.
-- @param #MENU_GROUP self -- @param #MENU_GROUP self
-- @param MenuTime
-- @return #nil -- @return #nil
function MENU_GROUP:Remove() function MENU_GROUP:Remove( MenuTime )
self:F2( { self.MenuGroupID, self.MenuPath } ) self:F( { self.MenuGroupID, self.MenuPath } )
self:RemoveSubMenus() self:RemoveSubMenus( MenuTime )
if self.MenuGroup._Menus[self.Path] then
self = self.MenuGroup._Menus[self.Path]
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath ) self:RemoveTop( MenuTime )
if self.ParentMenu then
self.ParentMenu.Menus[self.MenuPath] = nil
end
self:T( { "Removing Group Menu:", self.MenuGroup:GetName(), self.MenuGroup._Menus[self.Path].Path } )
self.MenuGroup._Menus[self.Path] = nil
self = nil
end
return nil return nil
end end
--- The MENU_GROUP_COMMAND class --- The MENU_GROUP_COMMAND class
-- @type MENU_GROUP_COMMAND -- @type MENU_GROUP_COMMAND
-- @extends Menu#MENU_BASE -- @extends Core.Menu#MENU_BASE
MENU_GROUP_COMMAND = { MENU_GROUP_COMMAND = {
ClassName = "MENU_GROUP_COMMAND" ClassName = "MENU_GROUP_COMMAND"
} }
@@ -840,13 +881,14 @@ do
-- @param ParentMenu The parent menu. -- @param ParentMenu The parent menu.
-- @param CommandMenuFunction A function that is called when the menu key is pressed. -- @param CommandMenuFunction A function that is called when the menu key is pressed.
-- @param CommandMenuArgument An argument for the function. -- @param CommandMenuArgument An argument for the function.
-- @return Menu#MENU_GROUP_COMMAND self -- @return #MENU_GROUP_COMMAND
function MENU_GROUP_COMMAND:New( MenuGroup, MenuText, ParentMenu, CommandMenuFunction, ... ) function MENU_GROUP_COMMAND:New( MenuGroup, MenuText, ParentMenu, CommandMenuFunction, ... )
MenuGroup._Menus = MenuGroup._Menus or {} MenuGroup._Menus = MenuGroup._Menus or {}
local Path = ( ParentMenu and ( table.concat( ParentMenu.MenuPath or {}, "@" ) .. "@" .. MenuText ) ) or MenuText local Path = ( ParentMenu and ( table.concat( ParentMenu.MenuPath or {}, "@" ) .. "@" .. MenuText ) ) or MenuText
if MenuGroup._Menus[Path] then if MenuGroup._Menus[Path] then
self = MenuGroup._Menus[Path] self = MenuGroup._Menus[Path]
self:T( { "Re-using Group Command Menu:", MenuGroup:GetName(), MenuText } )
else else
self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) ) self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) )
MenuGroup._Menus[Path] = self MenuGroup._Menus[Path] = self
@@ -861,7 +903,8 @@ do
self.MenuPath = missionCommands.addCommandForGroup( self.MenuGroupID, MenuText, self.MenuParentPath, self.MenuCallHandler, arg ) self.MenuPath = missionCommands.addCommandForGroup( self.MenuGroupID, MenuText, self.MenuParentPath, self.MenuCallHandler, arg )
if ParentMenu and ParentMenu.Menus then if ParentMenu and ParentMenu.Menus then
ParentMenu.Menus[self.MenuPath] = self ParentMenu.Menus[MenuText] = self
self:F( { ParentMenu.Menus, MenuText } )
end end
end end
@@ -872,22 +915,37 @@ do
--- Removes a menu structure for a group. --- Removes a menu structure for a group.
-- @param #MENU_GROUP_COMMAND self -- @param #MENU_GROUP_COMMAND self
-- @param MenuTime
-- @return #nil -- @return #nil
function MENU_GROUP_COMMAND:Remove() function MENU_GROUP_COMMAND:Remove( MenuTime )
self:F2( { self.MenuGroupID, self.MenuPath } ) self:F( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
if self.MenuGroup._Menus[self.Path] then if not MenuTime or self.MenuTime ~= MenuTime then
self = self.MenuGroup._Menus[self.Path] if self.MenuGroup._Menus[self.Path] then
self = self.MenuGroup._Menus[self.Path]
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
self.ParentMenu.Menus[self.MenuPath] = nil missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
self:T( { "Removing Group Command Menu:", self.MenuGroup:GetName(), self.MenuGroup._Menus[self.Path].Path } ) self:T( { "Removing Group Command Menu:", self.MenuGroup:GetName(), self.MenuText, self.Path, self.MenuGroup._Menus[self.Path].Path } )
self.MenuGroup._Menus[self.Path] = nil self.ParentMenu.Menus[self.MenuText] = nil
self = nil self.MenuGroup._Menus[self.Path] = nil
self = nil
end
end end
return nil return nil
end end
--- Removes a menu for a group.
-- @param #MENU_GROUP_COMMAND self
-- @param MenuTime
-- @return #nil
function MENU_GROUP_COMMAND:RemoveTop( MenuTime )
self:F( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
self:Remove( MenuTime )
return nil
end
end end
@@ -1298,10 +1298,11 @@ do -- DETECTION_UNITS
local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT
local DetectedTypeName = DetectedItem.Type local DetectedTypeName = DetectedItem.Type
for DetectedUnitName, DetectedUnitData in pairs( DetectedItemSet ) do for DetectedUnitName, DetectedUnitData in pairs( DetectedItemSet:GetSet() ) do
local DetectedUnit = DetectedUnitData -- Wrapper.Unit#UNIT local DetectedUnit = DetectedUnitData -- Wrapper.Unit#UNIT
local DetectedObject = nil local DetectedObject = nil
self:E( DetectedUnit )
if DetectedUnit:IsAlive() then if DetectedUnit:IsAlive() then
--self:E(DetectedUnit:GetName()) --self:E(DetectedUnit:GetName())
DetectedObject = self:GetDetectedObject( DetectedUnit:GetName() ) DetectedObject = self:GetDetectedObject( DetectedUnit:GetName() )
@@ -194,17 +194,26 @@ function COMMANDCENTER:SetMenu()
self.CommandCenterMenu = self.CommandCenterMenu or MENU_COALITION:New( self.CommandCenterCoalition, "Command Center (" .. self:GetName() .. ")" ) self.CommandCenterMenu = self.CommandCenterMenu or MENU_COALITION:New( self.CommandCenterCoalition, "Command Center (" .. self:GetName() .. ")" )
local MenuTime = timer.getTime()
for MissionID, Mission in pairs( self:GetMissions() ) do for MissionID, Mission in pairs( self:GetMissions() ) do
local Mission = Mission -- Tasking.Mission#MISSION local Mission = Mission -- Tasking.Mission#MISSION
Mission:RemoveMenu() Mission:SetMenu( MenuTime )
end
for MissionID, Mission in pairs( self:GetMissions() ) do
local Mission = Mission -- Tasking.Mission#MISSION
Mission:RemoveMenu( MenuTime )
end end
for MissionID, Mission in pairs( self:GetMissions() ) do
local Mission = Mission -- Tasking.Mission#MISSION
Mission:SetMenu()
end
end end
--- Gets the commandcenter menu structure governed by the HQ command center.
-- @param #COMMANDCENTER self
-- @return Core.Menu#MENU_COALITION
function COMMANDCENTER:GetMenu()
self:F()
return self.CommandCenterMenu
end
--- Checks of the COMMANDCENTER has a GROUP. --- Checks of the COMMANDCENTER has a GROUP.
-- @param #COMMANDCENTER self -- @param #COMMANDCENTER self
+11 -33
View File
@@ -363,23 +363,25 @@ end
--- Sets the Planned Task menu. --- Sets the Planned Task menu.
-- @param #MISSION self -- @param #MISSION self
function MISSION:SetMenu() -- @param #number MenuTime
function MISSION:SetMenu( MenuTime )
self:F() self:F()
for _, Task in pairs( self:GetTasks() ) do for _, TaskData in pairs( self:GetTasks() ) do
local Task = Task -- Tasking.Task#TASK local Task = TaskData -- Tasking.Task#TASK
Task:SetMenu() Task:SetMenu( MenuTime )
end end
end end
--- Removes the Planned Task menu. --- Removes the Planned Task menu.
-- @param #MISSION self -- @param #MISSION self
function MISSION:RemoveMenu() -- @param #number MenuTime
function MISSION:RemoveMenu( MenuTime )
self:F() self:F()
for _, Task in pairs( self:GetTasks() ) do for _, Task in pairs( self:GetTasks() ) do
local Task = Task -- Tasking.Task#TASK local Task = Task -- Tasking.Task#TASK
Task:RemoveMenu() Task:RemoveMenu( MenuTime )
end end
end end
@@ -391,20 +393,6 @@ function MISSION:GetCommandCenter()
return self.CommandCenter return self.CommandCenter
end end
--- Sets the Assigned Task menu.
-- @param #MISSION self
-- @param Tasking.Task#TASK Task
-- @param #string MenuText The menu text.
-- @return #MISSION self
function MISSION:SetAssignedMenu( Task )
for _, Task in pairs( self.Tasks ) do
local Task = Task -- Tasking.Task#TASK
Task:RemoveMenu()
Task:SetAssignedMenu()
end
end
--- Removes a Task menu. --- Removes a Task menu.
-- @param #MISSION self -- @param #MISSION self
@@ -420,28 +408,18 @@ end
-- @param #MISSION self -- @param #MISSION self
-- @param Wrapper.Group#GROUP TaskGroup -- @param Wrapper.Group#GROUP TaskGroup
-- @return Core.Menu#MENU_COALITION self -- @return Core.Menu#MENU_COALITION self
function MISSION:GetMissionMenu( TaskGroup ) function MISSION:GetMenu( TaskGroup )
local CommandCenter = self:GetCommandCenter() local CommandCenter = self:GetCommandCenter()
local CommandCenterMenu = CommandCenter.CommandCenterMenu local CommandCenterMenu = CommandCenter:GetMenu()
local MissionName = self:GetName() local MissionName = self:GetName()
local MissionMenu = CommandCenterMenu:GetMenu( MissionName )
local TaskGroupName = TaskGroup:GetName()
local MissionMenu = MENU_GROUP:New( TaskGroup, MissionName, CommandCenterMenu )
return MissionMenu return MissionMenu
end end
--- Clears the mission menu for the coalition.
-- @param #MISSION self
-- @return #MISSION self
function MISSION:ClearMissionMenu()
self.MissionMenu:Remove()
self.MissionMenu = nil
end
--- Get the TASK identified by the TaskNumber from the Mission. This function is useful in GoalFunctions. --- Get the TASK identified by the TaskNumber from the Mission. This function is useful in GoalFunctions.
-- @param #string TaskName The Name of the @{Task} within the @{Mission}. -- @param #string TaskName The Name of the @{Task} within the @{Mission}.
-- @return Tasking.Task#TASK The Task -- @return Tasking.Task#TASK The Task
+65 -29
View File
@@ -354,8 +354,13 @@ function TASK:AssignToGroup( TaskGroup )
TaskGroup:SetState( TaskGroup, "Assigned", self ) TaskGroup:SetState( TaskGroup, "Assigned", self )
self:RemoveMenuForGroup( TaskGroup ) local Mission = self:GetMission()
self:SetAssignedMenuForGroup( TaskGroup ) local CommandCenter = Mission:GetCommandCenter()
CommandCenter:SetMenu()
--self:RemoveMenuForGroup( TaskGroup )
--self:SetAssignedMenuForGroup( TaskGroup )
local TaskUnits = TaskGroup:GetUnits() local TaskUnits = TaskGroup:GetUnits()
for UnitID, UnitData in pairs( TaskUnits ) do for UnitID, UnitData in pairs( TaskUnits ) do
@@ -527,13 +532,18 @@ end
--- Set the menu options of the @{Task} to all the groups in the SetGroup. --- Set the menu options of the @{Task} to all the groups in the SetGroup.
-- @param #TASK self -- @param #TASK self
function TASK:SetMenu() -- @param #number MenuTime
-- @return #TASK
function TASK:SetMenu( MenuTime )
self:F() self:F()
self.SetGroup:Flush() self.SetGroup:Flush()
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do for TaskGroupID, TaskGroupData in pairs( self.SetGroup:GetSet() ) do
if self:IsStatePlanned() or self:IsStateReplanned() then local TaskGroup = TaskGroupData -- Wrapper.Group#GROUP
self:SetMenuForGroup( TaskGroup ) if TaskGroup:IsAlive() and TaskGroup:GetPlayerNames() then
if self:IsStatePlanned() or self:IsStateReplanned() then
self:SetMenuForGroup( TaskGroup, MenuTime )
end
end end
end end
end end
@@ -541,17 +551,15 @@ end
--- Remove the menu options of the @{Task} to all the groups in the SetGroup. --- Remove the menu options of the @{Task} to all the groups in the SetGroup.
-- @param #TASK self -- @param #TASK self
-- @return #TASK self -- @param #number MenuTime
function TASK:RemoveMenu() -- @return #TASK
function TASK:RemoveMenu( MenuTime )
self:F()
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
if TaskGroup:IsAlive() then if TaskGroup:IsAlive() and TaskGroup:GetPlayerNames() then
if not TaskGroup:GetState( TaskGroup, "Assigned" ) then self:RemoveMenuForGroup( TaskGroup, MenuTime )
self:T( { "Remove Menu for Group:", TaskGroup:GetName() } )
self:RemoveMenuForGroup( TaskGroup )
end
end end
end end
end end
@@ -559,13 +567,15 @@ end
--- Set the Menu for a Group --- Set the Menu for a Group
-- @param #TASK self -- @param #TASK self
function TASK:SetMenuForGroup( TaskGroup ) -- @param #number MenuTime
-- @return #TASK
function TASK:SetMenuForGroup( TaskGroup, MenuTime )
if not TaskGroup:GetState( TaskGroup, "Assigned" ) then if not TaskGroup:GetState( TaskGroup, "Assigned" ) then
self:SetPlannedMenuForGroup( TaskGroup, self:GetTaskName() ) self:SetPlannedMenuForGroup( TaskGroup, self:GetTaskName(), MenuTime )
else else
if not self:IsAssignedToGroup( TaskGroup ) then if not self:IsAssignedToGroup( TaskGroup ) then
self:SetAssignedMenuForGroup( TaskGroup ) self:SetAssignedMenuForGroup( TaskGroup, MenuTime )
end end
end end
end end
@@ -575,16 +585,24 @@ end
-- @param #TASK self -- @param #TASK self
-- @param Wrapper.Group#GROUP TaskGroup -- @param Wrapper.Group#GROUP TaskGroup
-- @param #string MenuText The menu text. -- @param #string MenuText The menu text.
-- @param #number MenuTime
-- @return #TASK self -- @return #TASK self
function TASK:SetPlannedMenuForGroup( TaskGroup, MenuText ) function TASK:SetPlannedMenuForGroup( TaskGroup, MenuText, MenuTime )
self:E( TaskGroup:GetName() ) self:E( TaskGroup:GetName() )
local Mission = self:GetMission() local Mission = self:GetMission()
local MissionMenu = Mission:GetMissionMenu( TaskGroup ) local MissionName = Mission:GetName()
local CommandCenter = Mission:GetCommandCenter()
local CommandCenterMenu = CommandCenter:GetMenu()
local MissionMenu = MENU_GROUP:New( TaskGroup, MissionName, CommandCenterMenu ):SetTime( MenuTime )
local MissionMenu = Mission:GetMenu( TaskGroup )
local TaskType = self:GetType() local TaskType = self:GetType()
local TaskTypeMenu = MENU_GROUP:New( TaskGroup, TaskType, MissionMenu ) local TaskTypeMenu = MENU_GROUP:New( TaskGroup, TaskType, MissionMenu ):SetTime( MenuTime )
local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, MenuText, TaskTypeMenu, self.MenuAssignToGroup, { self = self, TaskGroup = TaskGroup } ) local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, MenuText, TaskTypeMenu, self.MenuAssignToGroup, { self = self, TaskGroup = TaskGroup } ):SetTime( MenuTime )
return self return self
end end
@@ -592,17 +610,18 @@ end
--- Set the assigned menu options of the @{Task}. --- Set the assigned menu options of the @{Task}.
-- @param #TASK self -- @param #TASK self
-- @param Wrapper.Group#GROUP TaskGroup -- @param Wrapper.Group#GROUP TaskGroup
-- @param #number MenuTime
-- @return #TASK self -- @return #TASK self
function TASK:SetAssignedMenuForGroup( TaskGroup ) function TASK:SetAssignedMenuForGroup( TaskGroup, MenuTime )
self:E( TaskGroup:GetName() ) self:E( TaskGroup:GetName() )
local Mission = self:GetMission() local Mission = self:GetMission()
local MissionMenu = Mission:GetMissionMenu( TaskGroup ) local MissionMenu = Mission:GetMenu( TaskGroup )
self:E( { MissionMenu = MissionMenu } ) self:E( { MissionMenu = MissionMenu } )
local TaskTypeMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Task Status", MissionMenu, self.MenuTaskStatus, self, TaskGroup ) local TaskTypeMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Task Status", MissionMenu, self.MenuTaskStatus, self, TaskGroup ):SetTime( MenuTime )
local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Abort Task", MissionMenu, self.MenuTaskAbort, self, TaskGroup ) local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Abort Task", MissionMenu, self.MenuTaskAbort, self, TaskGroup ):SetTime( MenuTime )
return self return self
end end
@@ -610,14 +629,31 @@ end
--- Remove the menu option of the @{Task} for a @{Group}. --- Remove the menu option of the @{Task} for a @{Group}.
-- @param #TASK self -- @param #TASK self
-- @param Wrapper.Group#GROUP TaskGroup -- @param Wrapper.Group#GROUP TaskGroup
-- @param #number MenuTime
-- @return #TASK self -- @return #TASK self
function TASK:RemoveMenuForGroup( TaskGroup ) function TASK:RemoveMenuForGroup( TaskGroup, MenuTime )
self:F()
local Mission = self:GetMission() local Mission = self:GetMission()
local MissionName = Mission:GetName() local MissionName = Mission:GetName()
local MissionMenu = Mission:GetMissionMenu( TaskGroup ) local MissionMenu = Mission:GetMenu( TaskGroup )
MissionMenu:Remove()
if MissionMenu then
local TaskType = self:GetType()
local TypeMenu = MissionMenu:GetMenu( TaskType )
if TypeMenu then
local TaskMenu = TypeMenu:GetMenu( self:GetTaskName() )
if TaskMenu then
TaskMenu:RemoveTop( MenuTime )
end
TypeMenu:RemoveTop( MenuTime )
end
MissionMenu:RemoveTop( MenuTime )
end
end end
function TASK.MenuAssignToGroup( MenuParam ) function TASK.MenuAssignToGroup( MenuParam )
+26
View File
@@ -926,3 +926,29 @@ do -- Event Handling
end end
end end
do -- Players
--- Get player names
-- @param #GROUP self
-- @return #table The group has players, an array of player names is returned.
-- @return #nil The group has no players
function GROUP:GetPlayerNames()
local PlayerNames = nil
local Units = self:GetUnits()
for UnitID, UnitData in pairs( Units ) do
local Unit = UnitData -- Wrapper.Unit#UNIT
local PlayerName = Unit:GetPlayerName()
if PlayerName and PlayerName ~= "" then
PlayerNames = PlayerNames or {}
table.insert( PlayerNames, PlayerName )
end
end
self:F( PlayerNames )
return PlayerNames
end
end
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff