mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge pull request #314 from FlightControl-Master/FlightControl-menu-optimization
Flightcontrol menu optimization
This commit is contained in:
commit
8c4ae420e2
@ -108,7 +108,7 @@ do -- ACT_ASSIST
|
||||
function ACT_ASSIST:onafterStart( ProcessUnit, From, Event, To )
|
||||
|
||||
local ProcessGroup = ProcessUnit:GetGroup()
|
||||
local MissionMenu = self:GetMission():GetMissionMenu( ProcessGroup )
|
||||
local MissionMenu = self:GetMission():GetMenu( ProcessGroup )
|
||||
|
||||
local function MenuSmoke( MenuParam )
|
||||
self:E( MenuParam )
|
||||
|
||||
@ -138,6 +138,8 @@ do -- MENU_BASE
|
||||
}
|
||||
|
||||
--- Consructor
|
||||
-- @param #MENU_BASE
|
||||
-- @return #MENU_BASE
|
||||
function MENU_BASE:New( MenuText, ParentMenu )
|
||||
|
||||
local MenuParentPath = {}
|
||||
@ -150,10 +152,43 @@ do -- MENU_BASE
|
||||
self.MenuPath = nil
|
||||
self.MenuText = MenuText
|
||||
self.MenuParentPath = MenuParentPath
|
||||
self.Menus = {}
|
||||
self.MenuCount = 0
|
||||
self.MenuRemoveParent = false
|
||||
self.MenuTime = timer.getTime()
|
||||
|
||||
return self
|
||||
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 @{Menu} to remove automatically the parent menu when the menu removed is the last child menu of that parent @{Menu}.
|
||||
-- @param #MENU_BASE self
|
||||
-- @param #boolean RemoveParent If true, the parent menu is automatically removed when this menu is the last child menu of that parent @{Menu}.
|
||||
-- @return #MENU_BASE
|
||||
function MENU_BASE:SetRemoveParent( RemoveParent )
|
||||
self:F( { RemoveParent } )
|
||||
self.MenuRemoveParent = RemoveParent
|
||||
return self
|
||||
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
|
||||
|
||||
do -- MENU_COMMAND_BASE
|
||||
@ -161,7 +196,7 @@ do -- MENU_COMMAND_BASE
|
||||
--- The MENU_COMMAND_BASE class
|
||||
-- @type MENU_COMMAND_BASE
|
||||
-- @field #function MenuCallHandler
|
||||
-- @extends Menu#MENU_BASE
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
MENU_COMMAND_BASE = {
|
||||
ClassName = "MENU_COMMAND_BASE",
|
||||
CommandMenuFunction = nil,
|
||||
@ -170,6 +205,8 @@ do -- MENU_COMMAND_BASE
|
||||
}
|
||||
|
||||
--- Constructor
|
||||
-- @param #MENU_COMMAND_BASE
|
||||
-- @return #MENU_COMMAND_BASE
|
||||
function MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, CommandMenuArguments )
|
||||
|
||||
local self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
|
||||
@ -189,7 +226,7 @@ do -- MENU_MISSION
|
||||
|
||||
--- The MENU_MISSION class
|
||||
-- @type MENU_MISSION
|
||||
-- @extends Menu#MENU_BASE
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
MENU_MISSION = {
|
||||
ClassName = "MENU_MISSION"
|
||||
}
|
||||
@ -198,7 +235,7 @@ do -- MENU_MISSION
|
||||
-- @param #MENU_MISSION self
|
||||
-- @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).
|
||||
-- @return #MENU_MISSION self
|
||||
-- @return #MENU_MISSION
|
||||
function MENU_MISSION:New( MenuText, ParentMenu )
|
||||
|
||||
local self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
|
||||
@ -225,7 +262,7 @@ do -- MENU_MISSION
|
||||
|
||||
--- Removes the sub menus recursively of this MENU_MISSION. Note that the main menu is kept!
|
||||
-- @param #MENU_MISSION self
|
||||
-- @return #MENU_MISSION self
|
||||
-- @return #MENU_MISSION
|
||||
function MENU_MISSION:RemoveSubMenus()
|
||||
self:F( self.MenuPath )
|
||||
|
||||
@ -256,7 +293,7 @@ do -- MENU_MISSION_COMMAND
|
||||
|
||||
--- The MENU_MISSION_COMMAND class
|
||||
-- @type MENU_MISSION_COMMAND
|
||||
-- @extends Menu#MENU_COMMAND_BASE
|
||||
-- @extends Core.Menu#MENU_COMMAND_BASE
|
||||
MENU_MISSION_COMMAND = {
|
||||
ClassName = "MENU_MISSION_COMMAND"
|
||||
}
|
||||
@ -306,7 +343,7 @@ do -- MENU_COALITION
|
||||
|
||||
--- The MENU_COALITION class
|
||||
-- @type MENU_COALITION
|
||||
-- @extends Menu#MENU_BASE
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
-- @usage
|
||||
-- -- 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).
|
||||
@ -380,7 +417,7 @@ do -- MENU_COALITION
|
||||
|
||||
--- Removes the sub menus recursively of this MENU_COALITION. Note that the main menu is kept!
|
||||
-- @param #MENU_COALITION self
|
||||
-- @return #MENU_COALITION self
|
||||
-- @return #MENU_COALITION
|
||||
function MENU_COALITION:RemoveSubMenus()
|
||||
self:F( self.MenuPath )
|
||||
|
||||
@ -411,7 +448,7 @@ do -- MENU_COALITION_COMMAND
|
||||
|
||||
--- The MENU_COALITION_COMMAND class
|
||||
-- @type MENU_COALITION_COMMAND
|
||||
-- @extends Menu#MENU_COMMAND_BASE
|
||||
-- @extends Core.Menu#MENU_COMMAND_BASE
|
||||
MENU_COALITION_COMMAND = {
|
||||
ClassName = "MENU_COALITION_COMMAND"
|
||||
}
|
||||
@ -423,7 +460,7 @@ do -- MENU_COALITION_COMMAND
|
||||
-- @param Menu#MENU_COALITION ParentMenu The parent menu.
|
||||
-- @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.
|
||||
-- @return #MENU_COALITION_COMMAND self
|
||||
-- @return #MENU_COALITION_COMMAND
|
||||
function MENU_COALITION_COMMAND:New( Coalition, MenuText, ParentMenu, CommandMenuFunction, ... )
|
||||
|
||||
local self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) )
|
||||
@ -468,7 +505,7 @@ do -- MENU_CLIENT
|
||||
|
||||
--- MENU_COALITION constructor. Creates a new radio command item for a coalition, which can invoke a function with parameters.
|
||||
-- @type MENU_CLIENT
|
||||
-- @extends Menu#MENU_BASE
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
-- @usage
|
||||
-- -- This demo creates a menu structure for the two clients of planes.
|
||||
-- -- Each client will receive a different menu structure.
|
||||
@ -609,7 +646,7 @@ do -- MENU_CLIENT
|
||||
|
||||
--- The MENU_CLIENT_COMMAND class
|
||||
-- @type MENU_CLIENT_COMMAND
|
||||
-- @extends Menu#MENU_COMMAND
|
||||
-- @extends Core.Menu#MENU_COMMAND
|
||||
MENU_CLIENT_COMMAND = {
|
||||
ClassName = "MENU_CLIENT_COMMAND"
|
||||
}
|
||||
@ -695,7 +732,7 @@ do
|
||||
|
||||
--- The MENU_GROUP class
|
||||
-- @type MENU_GROUP
|
||||
-- @extends Menu#MENU_BASE
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
-- @usage
|
||||
-- -- This demo creates a menu structure for the two groups of planes.
|
||||
-- -- Each group will receive a different menu structure.
|
||||
@ -769,8 +806,6 @@ do
|
||||
self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
|
||||
MenuGroup._Menus[Path] = self
|
||||
|
||||
self.Menus = {}
|
||||
|
||||
self.MenuGroup = MenuGroup
|
||||
self.Path = Path
|
||||
self.MenuGroupID = MenuGroup:GetID()
|
||||
@ -780,8 +815,10 @@ do
|
||||
self:T( { "Adding Menu ", MenuText, self.MenuParentPath } )
|
||||
self.MenuPath = missionCommands.addSubMenuForGroup( self.MenuGroupID, MenuText, self.MenuParentPath )
|
||||
|
||||
if ParentMenu and ParentMenu.Menus then
|
||||
ParentMenu.Menus[self.MenuPath] = self
|
||||
if self.ParentMenu and self.ParentMenu.Menus then
|
||||
self.ParentMenu.Menus[MenuText] = self
|
||||
self:F( { self.ParentMenu.Menus, MenuText } )
|
||||
self.ParentMenu.MenuCount = self.ParentMenu.MenuCount + 1
|
||||
end
|
||||
end
|
||||
|
||||
@ -792,43 +829,56 @@ do
|
||||
|
||||
--- Removes the sub menus recursively of this MENU_GROUP.
|
||||
-- @param #MENU_GROUP self
|
||||
-- @param MenuTime
|
||||
-- @return #MENU_GROUP self
|
||||
function MENU_GROUP:RemoveSubMenus()
|
||||
self:F2( self.MenuPath )
|
||||
function MENU_GROUP:RemoveSubMenus( MenuTime )
|
||||
self:F2( { self.MenuPath, MenuTime, self.MenuTime } )
|
||||
|
||||
self:T( { "Removing Group SubMenus:", self.MenuGroup:GetName(), self.MenuPath } )
|
||||
for MenuID, Menu in pairs( self.Menus ) do
|
||||
Menu:Remove()
|
||||
for MenuText, Menu in pairs( self.Menus ) do
|
||||
Menu:Remove( MenuTime )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Removes the main menu and sub menus recursively of this MENU_GROUP.
|
||||
-- @param #MENU_GROUP self
|
||||
-- @param MenuTime
|
||||
-- @return #nil
|
||||
function MENU_GROUP:Remove()
|
||||
self:F2( { self.MenuGroupID, self.MenuPath } )
|
||||
function MENU_GROUP:Remove( MenuTime )
|
||||
self:F( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
|
||||
|
||||
self:RemoveSubMenus()
|
||||
|
||||
if self.MenuGroup._Menus[self.Path] then
|
||||
self = self.MenuGroup._Menus[self.Path]
|
||||
self:RemoveSubMenus( MenuTime )
|
||||
|
||||
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
|
||||
if self.ParentMenu then
|
||||
self.ParentMenu.Menus[self.MenuPath] = nil
|
||||
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
|
||||
self.ParentMenu.MenuCount = self.ParentMenu.MenuCount - 1
|
||||
if self.ParentMenu.MenuCount == 0 then
|
||||
if self.MenuRemoveParent == true then
|
||||
self:T( "Removing Parent Menu " )
|
||||
self.ParentMenu:Remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
self:T( { "Removing Group Menu:", self.MenuGroup:GetName(), self.MenuGroup._Menus[self.Path].Path } )
|
||||
self.MenuGroup._Menus[self.Path] = nil
|
||||
self = 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
|
||||
end
|
||||
|
||||
|
||||
--- The MENU_GROUP_COMMAND class
|
||||
-- @type MENU_GROUP_COMMAND
|
||||
-- @extends Menu#MENU_BASE
|
||||
-- @extends Core.Menu#MENU_BASE
|
||||
MENU_GROUP_COMMAND = {
|
||||
ClassName = "MENU_GROUP_COMMAND"
|
||||
}
|
||||
@ -840,13 +890,14 @@ do
|
||||
-- @param ParentMenu The parent menu.
|
||||
-- @param CommandMenuFunction A function that is called when the menu key is pressed.
|
||||
-- @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, ... )
|
||||
|
||||
MenuGroup._Menus = MenuGroup._Menus or {}
|
||||
local Path = ( ParentMenu and ( table.concat( ParentMenu.MenuPath or {}, "@" ) .. "@" .. MenuText ) ) or MenuText
|
||||
if MenuGroup._Menus[Path] then
|
||||
self = MenuGroup._Menus[Path]
|
||||
self:T( { "Re-using Group Command Menu:", MenuGroup:GetName(), MenuText } )
|
||||
else
|
||||
self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) )
|
||||
MenuGroup._Menus[Path] = self
|
||||
@ -860,30 +911,42 @@ do
|
||||
self:T( { "Adding Group Command Menu:", MenuGroup:GetName(), MenuText, self.MenuParentPath } )
|
||||
self.MenuPath = missionCommands.addCommandForGroup( self.MenuGroupID, MenuText, self.MenuParentPath, self.MenuCallHandler, arg )
|
||||
|
||||
if ParentMenu and ParentMenu.Menus then
|
||||
ParentMenu.Menus[self.MenuPath] = self
|
||||
if self.ParentMenu and self.ParentMenu.Menus then
|
||||
self.ParentMenu.Menus[MenuText] = self
|
||||
self.ParentMenu.MenuCount = self.ParentMenu.MenuCount + 1
|
||||
self:F( { ParentMenu.Menus, MenuText } )
|
||||
end
|
||||
end
|
||||
|
||||
--self:F( { MenuGroup:GetName(), MenuText, ParentMenu.MenuPath } )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Removes a menu structure for a group.
|
||||
-- @param #MENU_GROUP_COMMAND self
|
||||
-- @param MenuTime
|
||||
-- @return #nil
|
||||
function MENU_GROUP_COMMAND:Remove()
|
||||
self:F2( { self.MenuGroupID, self.MenuPath } )
|
||||
function MENU_GROUP_COMMAND:Remove( MenuTime )
|
||||
self:F( { self.MenuGroupID, self.MenuPath, MenuTime, self.MenuTime } )
|
||||
|
||||
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
|
||||
self:T( { "Removing Group Command Menu:", self.MenuGroup:GetName(), self.MenuGroup._Menus[self.Path].Path } )
|
||||
self.MenuGroup._Menus[self.Path] = nil
|
||||
self = nil
|
||||
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 )
|
||||
self:T( { "Removing Group Command Menu:", self.MenuGroup:GetName(), self.MenuText, self.Path, self.MenuGroup._Menus[self.Path].Path } )
|
||||
|
||||
self.ParentMenu.Menus[self.MenuText] = nil
|
||||
self.ParentMenu.MenuCount = self.ParentMenu.MenuCount - 1
|
||||
if self.ParentMenu.MenuCount == 0 then
|
||||
if self.MenuRemoveParent == true then
|
||||
self:T( "Removing Parent Menu " )
|
||||
self.ParentMenu:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
self.MenuGroup._Menus[self.Path] = nil
|
||||
self = nil
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
|
||||
@ -1298,10 +1298,11 @@ do -- DETECTION_UNITS
|
||||
local DetectedItemSet = DetectedItem.Set -- Core.Set#SET_UNIT
|
||||
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 DetectedObject = nil
|
||||
self:E( DetectedUnit )
|
||||
if DetectedUnit:IsAlive() then
|
||||
--self:E(DetectedUnit:GetName())
|
||||
DetectedObject = self:GetDetectedObject( DetectedUnit:GetName() )
|
||||
|
||||
@ -20,7 +20,9 @@ function REPORT:New( Title )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
self.Report = {}
|
||||
self.Report[#self.Report+1] = Title
|
||||
if Title then
|
||||
self.Report[#self.Report+1] = Title
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
@ -31,7 +33,7 @@ end
|
||||
-- @return #REPORT
|
||||
function REPORT:Add( Text )
|
||||
self.Report[#self.Report+1] = Text
|
||||
return self.Report[#self.Report+1]
|
||||
return self.Report[#self.Report]
|
||||
end
|
||||
|
||||
function REPORT:Text()
|
||||
@ -194,17 +196,26 @@ function COMMANDCENTER:SetMenu()
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
for MissionID, Mission in pairs( self:GetMissions() ) do
|
||||
local Mission = Mission -- Tasking.Mission#MISSION
|
||||
Mission:SetMenu()
|
||||
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.
|
||||
-- @param #COMMANDCENTER self
|
||||
@ -240,7 +251,8 @@ end
|
||||
-- @param #sring Name (optional) The name of the Group used as a prefix for the message to the Group. If not provided, there will be nothing shown.
|
||||
function COMMANDCENTER:MessageToGroup( Message, TaskGroup, Name )
|
||||
|
||||
local Prefix = Name and "@ Group (" .. Name .. "): " or ''
|
||||
local Prefix = "@ Group"
|
||||
Prefix = Prefix .. ( Name and " (" .. Name .. "): " or '' )
|
||||
Message = Prefix .. Message
|
||||
self:GetPositionable():MessageToGroup( Message , 20, TaskGroup, self:GetName() )
|
||||
|
||||
|
||||
@ -363,23 +363,25 @@ end
|
||||
|
||||
--- Sets the Planned Task menu.
|
||||
-- @param #MISSION self
|
||||
function MISSION:SetMenu()
|
||||
-- @param #number MenuTime
|
||||
function MISSION:SetMenu( MenuTime )
|
||||
self:F()
|
||||
|
||||
for _, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK
|
||||
Task:SetMenu()
|
||||
for _, TaskData in pairs( self:GetTasks() ) do
|
||||
local Task = TaskData -- Tasking.Task#TASK
|
||||
Task:SetMenu( MenuTime )
|
||||
end
|
||||
end
|
||||
|
||||
--- Removes the Planned Task menu.
|
||||
-- @param #MISSION self
|
||||
function MISSION:RemoveMenu()
|
||||
-- @param #number MenuTime
|
||||
function MISSION:RemoveMenu( MenuTime )
|
||||
self:F()
|
||||
|
||||
for _, Task in pairs( self:GetTasks() ) do
|
||||
local Task = Task -- Tasking.Task#TASK
|
||||
Task:RemoveMenu()
|
||||
Task:RemoveMenu( MenuTime )
|
||||
end
|
||||
end
|
||||
|
||||
@ -391,20 +393,6 @@ function MISSION:GetCommandCenter()
|
||||
return self.CommandCenter
|
||||
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.
|
||||
-- @param #MISSION self
|
||||
@ -420,28 +408,18 @@ end
|
||||
-- @param #MISSION self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return Core.Menu#MENU_COALITION self
|
||||
function MISSION:GetMissionMenu( TaskGroup )
|
||||
function MISSION:GetMenu( TaskGroup )
|
||||
|
||||
local CommandCenter = self:GetCommandCenter()
|
||||
local CommandCenterMenu = CommandCenter.CommandCenterMenu
|
||||
local CommandCenterMenu = CommandCenter:GetMenu()
|
||||
|
||||
local MissionName = self:GetName()
|
||||
|
||||
local TaskGroupName = TaskGroup:GetName()
|
||||
local MissionMenu = MENU_GROUP:New( TaskGroup, MissionName, CommandCenterMenu )
|
||||
local MissionMenu = CommandCenterMenu:GetMenu( MissionName )
|
||||
|
||||
return MissionMenu
|
||||
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.
|
||||
-- @param #string TaskName The Name of the @{Task} within the @{Mission}.
|
||||
-- @return Tasking.Task#TASK The Task
|
||||
|
||||
@ -343,7 +343,7 @@ end
|
||||
|
||||
|
||||
|
||||
--- Assign the @{Task}to a @{Group}.
|
||||
--- Assign the @{Task} to a @{Group}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @return #TASK
|
||||
@ -354,7 +354,11 @@ function TASK:AssignToGroup( TaskGroup )
|
||||
|
||||
TaskGroup:SetState( TaskGroup, "Assigned", self )
|
||||
|
||||
self:RemoveMenuForGroup( TaskGroup )
|
||||
local Mission = self:GetMission()
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
MissionMenu:RemoveSubMenus()
|
||||
|
||||
--self:RemoveMenuForGroup( TaskGroup )
|
||||
self:SetAssignedMenuForGroup( TaskGroup )
|
||||
|
||||
local TaskUnits = TaskGroup:GetUnits()
|
||||
@ -469,7 +473,7 @@ function TASK:UnAssignFromGroup( TaskGroup )
|
||||
|
||||
TaskGroup:SetState( TaskGroup, "Assigned", nil )
|
||||
|
||||
self:RemoveMenuForGroup( TaskGroup )
|
||||
self:RemoveAssignedMenuForGroup( TaskGroup )
|
||||
|
||||
local TaskUnits = TaskGroup:GetUnits()
|
||||
for UnitID, UnitData in pairs( TaskUnits ) do
|
||||
@ -527,45 +531,35 @@ end
|
||||
|
||||
--- Set the menu options of the @{Task} to all the groups in the SetGroup.
|
||||
-- @param #TASK self
|
||||
function TASK:SetMenu()
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK
|
||||
function TASK:SetMenu( MenuTime )
|
||||
self:F()
|
||||
|
||||
self.SetGroup:Flush()
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
if self:IsStatePlanned() or self:IsStateReplanned() then
|
||||
self:SetMenuForGroup( TaskGroup )
|
||||
for TaskGroupID, TaskGroupData in pairs( self.SetGroup:GetSet() ) do
|
||||
local TaskGroup = TaskGroupData -- Wrapper.Group#GROUP
|
||||
if TaskGroup:IsAlive() and TaskGroup:GetPlayerNames() then
|
||||
if self:IsStatePlanned() or self:IsStateReplanned() then
|
||||
self:SetMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Remove the menu options of the @{Task} to all the groups in the SetGroup.
|
||||
-- @param #TASK self
|
||||
-- @return #TASK self
|
||||
function TASK:RemoveMenu()
|
||||
|
||||
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
|
||||
if TaskGroup:IsAlive() then
|
||||
if not TaskGroup:GetState( TaskGroup, "Assigned" ) then
|
||||
self:T( { "Remove Menu for Group:", TaskGroup:GetName() } )
|
||||
self:RemoveMenuForGroup( TaskGroup )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Set the Menu for a Group
|
||||
-- @param #TASK self
|
||||
function TASK:SetMenuForGroup( TaskGroup )
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK
|
||||
function TASK:SetMenuForGroup( TaskGroup, MenuTime )
|
||||
|
||||
if not TaskGroup:GetState( TaskGroup, "Assigned" ) then
|
||||
self:SetPlannedMenuForGroup( TaskGroup, self:GetTaskName() )
|
||||
self:SetPlannedMenuForGroup( TaskGroup, self:GetTaskName(), MenuTime )
|
||||
else
|
||||
if not self:IsAssignedToGroup( TaskGroup ) then
|
||||
self:SetAssignedMenuForGroup( TaskGroup )
|
||||
self:SetAssignedMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -575,16 +569,24 @@ end
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @param #string MenuText The menu text.
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK self
|
||||
function TASK:SetPlannedMenuForGroup( TaskGroup, MenuText )
|
||||
function TASK:SetPlannedMenuForGroup( TaskGroup, MenuText, MenuTime )
|
||||
self:E( TaskGroup:GetName() )
|
||||
|
||||
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 TaskTypeMenu = MENU_GROUP:New( TaskGroup, TaskType, MissionMenu )
|
||||
local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, MenuText, TaskTypeMenu, self.MenuAssignToGroup, { self = self, TaskGroup = TaskGroup } )
|
||||
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 } ):SetTime( MenuTime ):SetRemoveParent( true )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -592,32 +594,84 @@ end
|
||||
--- Set the assigned menu options of the @{Task}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK self
|
||||
function TASK:SetAssignedMenuForGroup( TaskGroup )
|
||||
function TASK:SetAssignedMenuForGroup( TaskGroup, MenuTime )
|
||||
self:E( TaskGroup:GetName() )
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local MissionMenu = Mission:GetMissionMenu( TaskGroup )
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
|
||||
self:E( { MissionMenu = MissionMenu } )
|
||||
|
||||
local TaskTypeMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Task Status", MissionMenu, self.MenuTaskStatus, self, TaskGroup )
|
||||
local TaskMenu = MENU_GROUP_COMMAND:New( TaskGroup, "Abort Task", MissionMenu, self.MenuTaskAbort, 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 ):SetTime( MenuTime )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Remove the menu options of the @{Task} to all the groups in the SetGroup.
|
||||
-- @param #TASK self
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK
|
||||
function TASK:RemoveMenu( MenuTime )
|
||||
self:F()
|
||||
|
||||
for TaskGroupID, TaskGroup in pairs( self.SetGroup:GetSet() ) do
|
||||
local TaskGroup = TaskGroup -- Wrapper.Group#GROUP
|
||||
if TaskGroup:IsAlive() and TaskGroup:GetPlayerNames() then
|
||||
if not self:IsAssignedToGroup( TaskGroup ) then
|
||||
self:RemovePlannedMenuForGroup( TaskGroup, MenuTime )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Remove the menu option of the @{Task} for a @{Group}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK self
|
||||
function TASK:RemoveMenuForGroup( TaskGroup )
|
||||
function TASK:RemovePlannedMenuForGroup( TaskGroup, MenuTime )
|
||||
self:F()
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local MissionName = Mission:GetName()
|
||||
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
|
||||
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:Remove( MenuTime )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local MissionMenu = Mission:GetMissionMenu( TaskGroup )
|
||||
MissionMenu:Remove()
|
||||
--- Remove the assigned menu option of the @{Task} for a @{Group}.
|
||||
-- @param #TASK self
|
||||
-- @param Wrapper.Group#GROUP TaskGroup
|
||||
-- @param #number MenuTime
|
||||
-- @return #TASK self
|
||||
function TASK:RemoveAssignedMenuForGroup( TaskGroup )
|
||||
self:F()
|
||||
|
||||
local Mission = self:GetMission()
|
||||
local MissionName = Mission:GetName()
|
||||
|
||||
local MissionMenu = Mission:GetMenu( TaskGroup )
|
||||
|
||||
if MissionMenu then
|
||||
MissionMenu:RemoveSubMenus()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function TASK.MenuAssignToGroup( MenuParam )
|
||||
@ -634,7 +688,10 @@ end
|
||||
-- @param #TASK self
|
||||
function TASK:MenuTaskStatus( TaskGroup )
|
||||
|
||||
self:ReportDetails()
|
||||
local ReportText = self:ReportDetails()
|
||||
|
||||
self:T( ReportText )
|
||||
self:GetMission():GetCommandCenter():MessageToGroup( ReportText, TaskGroup )
|
||||
|
||||
end
|
||||
|
||||
@ -1076,24 +1133,19 @@ function TASK:ReportDetails()
|
||||
-- Determine the status of the Task.
|
||||
local State = self:GetState()
|
||||
|
||||
|
||||
-- Loop each Unit active in the Task, and find Player Names.
|
||||
local PlayerNames = {}
|
||||
for PlayerGroupID, PlayerGroup in pairs( self:GetGroups():GetSet() ) do
|
||||
local Player = PlayerGroup -- Wrapper.Group#GROUP
|
||||
for PlayerUnitID, PlayerUnit in pairs( PlayerGroup:GetUnits() ) do
|
||||
local PlayerUnit = PlayerUnit -- Wrapper.Unit#UNIT
|
||||
if PlayerUnit and PlayerUnit:IsAlive() then
|
||||
local PlayerName = PlayerUnit:GetPlayerName()
|
||||
PlayerNames[#PlayerNames+1] = PlayerName
|
||||
end
|
||||
local PlayerReport = REPORT:New( " - Players:" )
|
||||
for PlayerGroupID, PlayerGroupData in pairs( self:GetGroups():GetSet() ) do
|
||||
local PlayerGroup = PlayerGroupData -- Wrapper.Group#GROUP
|
||||
PlayerNames = PlayerGroup:GetPlayerNames()
|
||||
if PlayerNames then
|
||||
PlayerReport:Add( " -- Group " .. PlayerGroup:GetCallsign() .. ": " .. table.concat( PlayerNames, ", " ) )
|
||||
end
|
||||
local PlayerNameText = table.concat( PlayerNames, ", " )
|
||||
Report:Add( "Task " .. Name .. " - State '" .. State .. "' - Players " .. PlayerNameText )
|
||||
end
|
||||
|
||||
-- Loop each Process in the Task, and find Reporting Details.
|
||||
|
||||
Report:Add( string.format( " - Task %s\n -- State '%s'\n%s", Name, State, PlayerReport:Text() ) )
|
||||
return Report:Text()
|
||||
end
|
||||
|
||||
|
||||
@ -926,3 +926,29 @@ do -- Event Handling
|
||||
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
Loading…
x
Reference in New Issue
Block a user