mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
GROUP menus are now working
- Caching the menus on the GROUP object. - When a new menu is created, it will chech the cache - When the menu is already in the cache, nothing will be done and the self is returned. - When the menu is not in the cache, the menu is created and the cache is updated. - The removal of menus now work flawlessly, because the cache is now used to traverse the path of submenus during removal.
This commit is contained in:
@@ -759,37 +759,34 @@ do
|
|||||||
-- @return #MENU_GROUP self
|
-- @return #MENU_GROUP self
|
||||||
function MENU_GROUP:New( MenuGroup, MenuText, ParentMenu )
|
function MENU_GROUP:New( MenuGroup, MenuText, ParentMenu )
|
||||||
|
|
||||||
local self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
|
-- Determine if the menu was not already created and already visible at the group.
|
||||||
self:F( { MenuGroup, MenuText, ParentMenu } )
|
-- If it is visible, then return the cached self, otherwise, create self and cache it.
|
||||||
|
|
||||||
self.MenuGroup = MenuGroup
|
MenuGroup._Menus = MenuGroup._Menus or {}
|
||||||
self.MenuGroupID = MenuGroup:GetID()
|
local Path = ( ParentMenu and ( table.concat( ParentMenu.MenuPath or {}, "@" ) .. "@" .. MenuText ) ) or MenuText
|
||||||
self.MenuText = MenuText
|
if MenuGroup._Menus[Path] then
|
||||||
self.ParentMenu = ParentMenu
|
self = MenuGroup._Menus[Path]
|
||||||
|
|
||||||
self.Menus = {}
|
|
||||||
|
|
||||||
-- This is special
|
|
||||||
|
|
||||||
self.MenuGroup._Menu = self.MenuGroup._Menu or {}
|
|
||||||
local MenuPath = self.MenuGroup._Menu
|
|
||||||
|
|
||||||
self:T( { MenuGroup:GetName(), MenuPath[table.concat(self.MenuParentPath)], self.MenuParentPath, MenuText } )
|
|
||||||
|
|
||||||
local MenuPathID = table.concat(self.MenuParentPath) .. "/" .. MenuText
|
|
||||||
if MenuPath[MenuPathID] then
|
|
||||||
self.MenuPath = MenuPath[MenuPathID]
|
|
||||||
else
|
else
|
||||||
|
self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) )
|
||||||
|
MenuGroup._Menus[Path] = self
|
||||||
|
|
||||||
self:T( { "Adding for MenuPath ", MenuText, self.MenuParentPath } )
|
self.Menus = {}
|
||||||
|
|
||||||
|
self.MenuGroup = MenuGroup
|
||||||
|
self.Path = Path
|
||||||
|
self.MenuGroupID = MenuGroup:GetID()
|
||||||
|
self.MenuText = MenuText
|
||||||
|
self.ParentMenu = ParentMenu
|
||||||
|
|
||||||
|
self:T( { "Adding Menu ", MenuText, self.MenuParentPath } )
|
||||||
self.MenuPath = missionCommands.addSubMenuForGroup( self.MenuGroupID, MenuText, self.MenuParentPath )
|
self.MenuPath = missionCommands.addSubMenuForGroup( self.MenuGroupID, MenuText, self.MenuParentPath )
|
||||||
MenuPath[MenuPathID] = self.MenuPath
|
|
||||||
if ParentMenu and ParentMenu.Menus then
|
if ParentMenu and ParentMenu.Menus then
|
||||||
ParentMenu.Menus[self.MenuPath] = self
|
ParentMenu.Menus[self.MenuPath] = self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T( { self.MenuGroupID, self.MenuPath } )
|
self:F( { MenuGroup:GetName(), MenuText, ParentMenu.MenuPath } )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -814,16 +811,16 @@ do
|
|||||||
|
|
||||||
self:RemoveSubMenus()
|
self:RemoveSubMenus()
|
||||||
|
|
||||||
self.MenuGroup._Menu = self.MenuGroup._Menu or {}
|
if self.MenuGroup._Menus[self.Path] then
|
||||||
local MenuPath = self.MenuGroup._Menu
|
self = self.MenuGroup._Menus[self.Path]
|
||||||
|
|
||||||
if MenuPath[table.concat(self.MenuParentPath) .. "/" .. self.MenuText] then
|
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
|
||||||
MenuPath[table.concat(self.MenuParentPath) .. "/" .. self.MenuText] = nil
|
if self.ParentMenu then
|
||||||
end
|
self.ParentMenu.Menus[self.MenuPath] = nil
|
||||||
|
end
|
||||||
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
|
self:E( self.MenuGroup._Menus[self.Path] )
|
||||||
if self.ParentMenu then
|
self.MenuGroup._Menus[self.Path] = nil
|
||||||
self.ParentMenu.Menus[self.MenuPath] = nil
|
self = nil
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -846,34 +843,30 @@ do
|
|||||||
-- @return Menu#MENU_GROUP_COMMAND self
|
-- @return Menu#MENU_GROUP_COMMAND self
|
||||||
function MENU_GROUP_COMMAND:New( MenuGroup, MenuText, ParentMenu, CommandMenuFunction, ... )
|
function MENU_GROUP_COMMAND:New( MenuGroup, MenuText, ParentMenu, CommandMenuFunction, ... )
|
||||||
|
|
||||||
local self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) )
|
MenuGroup._Menus = MenuGroup._Menus or {}
|
||||||
|
local Path = ( ParentMenu and ( table.concat( ParentMenu.MenuPath or {}, "@" ) .. "@" .. MenuText ) ) or MenuText
|
||||||
self.MenuGroup = MenuGroup
|
if MenuGroup._Menus[Path] then
|
||||||
self.MenuGroupID = MenuGroup:GetID()
|
self = MenuGroup._Menus[Path]
|
||||||
self.MenuText = MenuText
|
|
||||||
self.ParentMenu = ParentMenu
|
|
||||||
|
|
||||||
self.MenuGroup._MenuPath = self.MenuGroup._MenuPath or {}
|
|
||||||
local MenuPath = self.MenuGroup._MenuPath
|
|
||||||
|
|
||||||
self:E(self.MenuParentPath)
|
|
||||||
self:E( ParentMenu )
|
|
||||||
self:E( MenuText )
|
|
||||||
|
|
||||||
self:T( { MenuGroup:GetName(), MenuPath[table.concat(self.MenuParentPath)], self.MenuParentPath, MenuText, CommandMenuFunction, arg } )
|
|
||||||
|
|
||||||
local MenuPathID = table.concat(self.MenuParentPath) .. "/" .. MenuText
|
|
||||||
if MenuPath[MenuPathID] then
|
|
||||||
self.MenuPath = MenuPath[MenuPathID]
|
|
||||||
else
|
else
|
||||||
self:T( { "Adding for MenuPath ", MenuText, self.MenuParentPath } )
|
self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) )
|
||||||
|
MenuGroup._Menus[Path] = self
|
||||||
|
|
||||||
|
self.Path = Path
|
||||||
|
self.MenuGroup = MenuGroup
|
||||||
|
self.MenuGroupID = MenuGroup:GetID()
|
||||||
|
self.MenuText = MenuText
|
||||||
|
self.ParentMenu = ParentMenu
|
||||||
|
|
||||||
|
self:T( { "Adding Command Menu ", MenuText, self.MenuParentPath } )
|
||||||
self.MenuPath = missionCommands.addCommandForGroup( self.MenuGroupID, MenuText, self.MenuParentPath, self.MenuCallHandler, arg )
|
self.MenuPath = missionCommands.addCommandForGroup( self.MenuGroupID, MenuText, self.MenuParentPath, self.MenuCallHandler, arg )
|
||||||
MenuPath[MenuPathID] = self.MenuPath
|
|
||||||
if ParentMenu and ParentMenu.Menus then
|
if ParentMenu and ParentMenu.Menus then
|
||||||
ParentMenu.Menus[self.MenuPath] = self
|
ParentMenu.Menus[self.MenuPath] = self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:F( { MenuGroup:GetName(), MenuText, ParentMenu.MenuPath } )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -883,15 +876,16 @@ do
|
|||||||
function MENU_GROUP_COMMAND:Remove()
|
function MENU_GROUP_COMMAND:Remove()
|
||||||
self:F( { self.MenuGroupID, self.MenuPath } )
|
self:F( { self.MenuGroupID, self.MenuPath } )
|
||||||
|
|
||||||
self.MenuGroup._Menu = self.MenuGroup._Menu or {}
|
if self.MenuGroup._Menus[self.Path] then
|
||||||
local MenuPath = self.MenuGroup._Menu
|
self = self.MenuGroup._Menus[self.Path]
|
||||||
|
|
||||||
if MenuPath[table.concat(self.MenuParentPath) .. "/" .. self.MenuText] then
|
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
|
||||||
MenuPath[table.concat(self.MenuParentPath) .. "/" .. self.MenuText] = nil
|
self.ParentMenu.Menus[self.MenuPath] = nil
|
||||||
|
self:E( self.MenuGroup._Menus[self.Path] )
|
||||||
|
self.MenuGroup._Menus[self.Path] = nil
|
||||||
|
self = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
missionCommands.removeItemForGroup( self.MenuGroupID, self.MenuPath )
|
|
||||||
self.ParentMenu.Menus[self.MenuPath] = nil
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ function TASK_BASE:RemoveMenuForGroup( TaskGroup )
|
|||||||
local Mission = self:GetMission()
|
local Mission = self:GetMission()
|
||||||
local MissionName = Mission:GetName()
|
local MissionName = Mission:GetName()
|
||||||
|
|
||||||
local MissionMenu = MENU_GROUP:New( TaskGroup, MissionName )
|
local MissionMenu = Mission:GetMissionMenu( TaskGroup )
|
||||||
MissionMenu:Remove()
|
MissionMenu:Remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user