Module Menu

Core -- MENU_ classes model the definition of hierarchical menu structures and commands for players within a mission.


DCS Menus can be managed using the MENU classes. The advantage of using MENU classes is that it hides the complexity of dealing with menu management in more advanced scanerios where you need to set menus and later remove them, and later set them again. You'll find while using use normal DCS scripting functions, that setting and removing menus is not a easy feat if you have complex menu hierarchies defined. Using the MOOSE menu classes, the removal and refreshing of menus are nicely being handled within these classes, and becomes much more easy. On top, MOOSE implements variable parameter passing for command menus.

There are basically two different MENU class types that you need to use:

To manage main menus, the classes begin with MENU_:

To manage command menus, which are menus that allow the player to issue functions, the classes begin with MENUCOMMAND:


-

Author: Sven Van de Velde (FlightControl)

Contributions:


Global(s)

MENU_BASE

MENU_BASE class, extends Base#BASE

The MENU_BASE class defines the main MENU class where other MENU classes are derived from.

MENU_COALITION

MENU_COALITION class, extends Menu#MENU_BASE

The Menu#MENU_COALITION class manages the main menus for coalitions.

MENU_COALITION_COMMAND

MENUCOALITIONCOMMAND class, extends Menu#MENUCOMMANDBASE

The MENUCOALITIONCOMMAND class manages the command menus for coalitions, which allow players to execute functions during mission execution.

MENU_COMMAND_BASE

MENUCOMMANDBASE class, extends Base#BASE


The MENUCOMMANDBASE class defines the main MENU class where other MENU COMMAND_ classes are derived from, in order to set commands.

MENU_GROUP

MENU_GROUP class, extends Menu#MENU_BASE

The MENU_GROUP class manages the main menus for coalitions.

MENU_GROUP_COMMAND

MENUGROUPCOMMAND class, extends Menu#MENUCOMMANDBASE

The Menu#MENUGROUPCOMMAND class manages the command menus for coalitions, which allow players to execute functions during mission execution.

MENU_INDEX
MENU_MISSION

MENU_MISSION class, extends Menu#MENU_BASE

The MENU_MISSION class manages the main menus for a complete mission.

MENU_MISSION_COMMAND

MENUMISSIONCOMMAND class, extends Menu#MENUCOMMANDBASE

The MENUMISSIONCOMMAND class manages the command menus for a complete mission, which allow players to execute functions during mission execution.

Type MENU_BASE

MENU_BASE:ClearParentMenu(MenuText)
MENU_BASE:GetMenu(MenuText)

Gets a Menu from a parent Menu

MENU_BASE.MenuTag
MENU_BASE.MenuTime
MENU_BASE.New(#, self, MenuText, ParentMenu)

Consructor

MENU_BASE:SetParentMenu(MenuText, Menu)
MENU_BASE:SetTag(MenuTag)

Sets a tag for later selection of menu refresh.

MENU_BASE:SetTime(MenuTime)

Sets a time stamp for later prevention of menu removal.

Type MENU_COALITION

MENU_COALITION.Menus
MENU_COALITION:New(Coalition, MenuText, ParentMenu)

MENU_COALITION constructor.

MENU_COALITION:Remove(MenuTime, MenuTag)

Removes the main menu and the sub menus recursively of this MENU_COALITION.

MENU_COALITION:RemoveSubMenus()

Removes the sub menus recursively of this MENU_COALITION.

Type MENU_COALITION_COMMAND

MENU_COALITION_COMMAND:New(Coalition, MenuText, ParentMenu, CommandMenuFunction, CommandMenuArgument, ...)

MENU_COALITION constructor.

MENU_COALITION_COMMAND:Remove(MenuTime, MenuTag)

Removes a radio command item for a coalition

Type MENU_COMMAND_BASE

MENU_COMMAND_BASE.MenuCallHandler
MENU_COMMAND_BASE.New(#, self, MenuText, ParentMenu, CommandMenuFunction, CommandMenuArguments)

Constructor

MENU_COMMAND_BASE.SetCommandMenuArguments(#, self, CommandMenuArguments)

This sets the new command arguments of a menu, so that if a menu is regenerated, or if command arguments change, that the arguments set for the menu are loosely coupled with the menu itself!!! If the arguments change, no new menu needs to be generated if the menu text is the same!!!

MENU_COMMAND_BASE.SetCommandMenuFunction(#, self, CommandMenuFunction)

This sets the new command function of a menu, so that if a menu is regenerated, or if command function changes, that the function set for the menu is loosely coupled with the menu itself!!! If the function changes, no new menu needs to be generated if the menu text is the same!!!

Type MENU_GROUP

MENU_GROUP.Group
MENU_GROUP.GroupID
MENU_GROUP.MenuPath
MENU_GROUP.Menus
MENU_GROUP:New(Group, MenuText, ParentMenu)

MENU_GROUP constructor.

MENU_GROUP:Remove(MenuTime, MenuTag)

Removes the main menu and sub menus recursively of this MENU_GROUP.

MENU_GROUP:RemoveSubMenus(MenuTime, MenuTag)

Removes the sub menus recursively of this MENU_GROUP.

Type MENU_GROUP_COMMAND

MENU_GROUP_COMMAND.Group
MENU_GROUP_COMMAND.GroupID
MENU_GROUP_COMMAND.MenuPath
MENU_GROUP_COMMAND:New(Group, MenuText, ParentMenu, CommandMenuFunction, CommandMenuArgument, ...)

Creates a new radio command item for a group

MENU_GROUP_COMMAND:Remove(MenuTime, MenuTag)

Removes a menu structure for a group.

Type MENU_MISSION

MENU_MISSION.Menus
MENU_MISSION:New(MenuText, ParentMenu)

MENU_MISSION constructor.

MENU_MISSION:Remove(MenuTime, MenuTag)

Removes the main menu and the sub menus recursively of this MENU_MISSION.

MENU_MISSION:RemoveSubMenus()

Removes the sub menus recursively of this MENU_MISSION.

Type MENU_MISSION_COMMAND

MENU_MISSION_COMMAND:New(MenuText, ParentMenu, CommandMenuFunction, CommandMenuArgument, ...)

MENU_MISSION constructor.

MENU_MISSION_COMMAND:Remove()

Removes a radio command item for a coalition

Global(s)

#MENU_BASE MENU_BASE

MENU_BASE class, extends Base#BASE

The MENU_BASE class defines the main MENU class where other MENU classes are derived from.

This is an abstract class, so don't use it.

#MENU_COALITION MENU_COALITION

MENU_COALITION class, extends Menu#MENU_BASE

The Menu#MENU_COALITION class manages the main menus for coalitions.

You can add menus with the MENU_COALITION.New method, which constructs a MENU_COALITION object and returns you the object reference. Using this object reference, you can then remove ALL the menus and submenus underlying automatically with MENU_COALITION.Remove.

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).
 -- Then switch planes and check if the menu is still there.

 local Plane1 = CLIENT:FindByName( "Plane 1" )
 local Plane2 = CLIENT:FindByName( "Plane 2" )


 -- This would create a menu for the red coalition under the main DCS "Others" menu.
 local MenuCoalitionRed = MENU_COALITION:New( coalition.side.RED, "Manage Menus" )


 local function ShowStatus( StatusText, Coalition )

   MESSAGE:New( Coalition, 15 ):ToRed()
   Plane1:Message( StatusText, 15 )
   Plane2:Message( StatusText, 15 )
 end

 local MenuStatus -- Menu#MENU_COALITION
 local MenuStatusShow -- Menu#MENU_COALITION_COMMAND

 local function RemoveStatusMenu()
   MenuStatus:Remove()
 end

 local function AddStatusMenu()
   
   -- This would create a menu for the red coalition under the MenuCoalitionRed menu object.
   MenuStatus = MENU_COALITION:New( coalition.side.RED, "Status for Planes" )
   MenuStatusShow = MENU_COALITION_COMMAND:New( coalition.side.RED, "Show Status", MenuStatus, ShowStatus, "Status of planes is ok!", "Message to Red Coalition" )
 end

 local MenuAdd = MENU_COALITION_COMMAND:New( coalition.side.RED, "Add Status Menu", MenuCoalitionRed, AddStatusMenu )
 local MenuRemove = MENU_COALITION_COMMAND:New( coalition.side.RED, "Remove Status Menu", MenuCoalitionRed, RemoveStatusMenu )
 
#MENU_COALITION_COMMAND MENU_COALITION_COMMAND

MENUCOALITIONCOMMAND class, extends Menu#MENUCOMMANDBASE

The MENUCOALITIONCOMMAND class manages the command menus for coalitions, which allow players to execute functions during mission execution.

You can add menus with the MENUCOALITIONCOMMAND.New method, which constructs a MENUCOALITIONCOMMAND object and returns you the object reference. Using this object reference, you can then remove ALL the menus and submenus underlying automatically with MENUCOALITIONCOMMAND.Remove.

#MENU_COMMAND_BASE MENU_COMMAND_BASE

MENUCOMMANDBASE class, extends Base#BASE


The MENUCOMMANDBASE class defines the main MENU class where other MENU COMMAND_ classes are derived from, in order to set commands.

#MENU_GROUP MENU_GROUP

MENU_GROUP class, extends Menu#MENU_BASE

The MENU_GROUP class manages the main menus for coalitions.

You can add menus with the MENU_GROUP.New method, which constructs a MENU_GROUP object and returns you the object reference. Using this object reference, you can then remove ALL the menus and submenus underlying automatically with MENU_GROUP.Remove.

Usage:

 -- This demo creates a menu structure for the two groups of planes.
 -- Each group will receive a different menu structure.
 -- To test, join the planes, then look at the other radio menus (Option F10).
 -- Then switch planes and check if the menu is still there.
 -- And play with the Add and Remove menu options.
 
 -- Note that in multi player, this will only work after the DCS groups bug is solved.

 local function ShowStatus( PlaneGroup, StatusText, Coalition )

   MESSAGE:New( Coalition, 15 ):ToRed()
   PlaneGroup:Message( StatusText, 15 )
 end

 local MenuStatus = {}

 local function RemoveStatusMenu( MenuGroup )
   local MenuGroupName = MenuGroup:GetName()
   MenuStatus[MenuGroupName]:Remove()
 end

 --- @param Wrapper.Group#GROUP MenuGroup
 local function AddStatusMenu( MenuGroup )
   local MenuGroupName = MenuGroup:GetName()
   -- This would create a menu for the red coalition under the MenuCoalitionRed menu object.
   MenuStatus[MenuGroupName] = MENU_GROUP:New( MenuGroup, "Status for Planes" )
   MENU_GROUP_COMMAND:New( MenuGroup, "Show Status", MenuStatus[MenuGroupName], ShowStatus, MenuGroup, "Status of planes is ok!", "Message to Red Coalition" )
 end

 SCHEDULER:New( nil,
   function()
     local PlaneGroup = GROUP:FindByName( "Plane 1" )
     if PlaneGroup and PlaneGroup:IsAlive() then
       local MenuManage = MENU_GROUP:New( PlaneGroup, "Manage Menus" )
       MENU_GROUP_COMMAND:New( PlaneGroup, "Add Status Menu Plane 1", MenuManage, AddStatusMenu, PlaneGroup )
       MENU_GROUP_COMMAND:New( PlaneGroup, "Remove Status Menu Plane 1", MenuManage, RemoveStatusMenu, PlaneGroup )
     end
   end, {}, 10, 10 )

 SCHEDULER:New( nil,
   function()
     local PlaneGroup = GROUP:FindByName( "Plane 2" )
     if PlaneGroup and PlaneGroup:IsAlive() then
       local MenuManage = MENU_GROUP:New( PlaneGroup, "Manage Menus" )
       MENU_GROUP_COMMAND:New( PlaneGroup, "Add Status Menu Plane 2", MenuManage, AddStatusMenu, PlaneGroup )
       MENU_GROUP_COMMAND:New( PlaneGroup, "Remove Status Menu Plane 2", MenuManage, RemoveStatusMenu, PlaneGroup )
     end
   end, {}, 10, 10 )
#MENU_GROUP_COMMAND MENU_GROUP_COMMAND

MENUGROUPCOMMAND class, extends Menu#MENUCOMMANDBASE

The Menu#MENUGROUPCOMMAND class manages the command menus for coalitions, which allow players to execute functions during mission execution.

You can add menus with the MENUGROUPCOMMAND.New method, which constructs a MENUGROUPCOMMAND object and returns you the object reference. Using this object reference, you can then remove ALL the menus and submenus underlying automatically with MENUGROUPCOMMAND.Remove.

MENU_INDEX
#MENU_MISSION MENU_MISSION

MENU_MISSION class, extends Menu#MENU_BASE

The MENU_MISSION class manages the main menus for a complete mission.

You can add menus with the MENU_MISSION.New method, which constructs a MENU_MISSION object and returns you the object reference. Using this object reference, you can then remove ALL the menus and submenus underlying automatically with MENU_MISSION.Remove.

#MENU_MISSION_COMMAND MENU_MISSION_COMMAND

MENUMISSIONCOMMAND class, extends Menu#MENUCOMMANDBASE

The MENUMISSIONCOMMAND class manages the command menus for a complete mission, which allow players to execute functions during mission execution.

You can add menus with the MENUMISSIONCOMMAND.New method, which constructs a MENUMISSIONCOMMAND object and returns you the object reference. Using this object reference, you can then remove ALL the menus and submenus underlying automatically with MENUMISSIONCOMMAND.Remove.

Type Menu

Type MENU_BASE

Field(s)

MENU_BASE:ClearParentMenu(MenuText)

Parameter

  • MenuText :

MENU_BASE:GetMenu(MenuText)

Gets a Menu from a parent Menu

Parameter

  • #string MenuText : The text of the child menu.

Return value

#MENU_BASE:

MENU_BASE.MenuTag
MENU_BASE.MenuTime
MENU_BASE.New(#, self, MenuText, ParentMenu)

Consructor

Parameters

  • # : ENU_BASE

  • self :

  • MenuText :

  • ParentMenu :

Return value

#MENU_BASE:

MENU_BASE:SetParentMenu(MenuText, Menu)

Parameters

  • MenuText :

  • Menu :

MENU_BASE:SetTag(MenuTag)

Sets a tag for later selection of menu refresh.

Parameter

  • #string MenuTag : A Tag or Key that will filter only menu items set with this key.

Return value

#MENU_BASE:

MENU_BASE:SetTime(MenuTime)

Sets a time stamp for later prevention of menu removal.

Parameter

  • MenuTime :

Return value

#MENU_BASE:

Type MENU_COALITION

Field(s)

MENU_COALITION.Menus
MENU_COALITION:New(Coalition, MenuText, ParentMenu)

MENU_COALITION constructor.

Creates a new MENU_COALITION object and creates the menu for a complete coalition.

Parameters

  • Dcs.DCSCoalition#coalition.side Coalition : The coalition owning the menu.

  • #string MenuText : The text for the menu.

  • #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 value

#MENU_COALITION: self

MENU_COALITION:Remove(MenuTime, MenuTag)

Removes the main menu and the sub menus recursively of this MENU_COALITION.

Parameters

  • MenuTime :

  • MenuTag :

Return value

#nil:

MENU_COALITION:RemoveSubMenus()

Removes the sub menus recursively of this MENU_COALITION.

Note that the main menu is kept!

Return value

#MENU_COALITION:

Type MENU_COALITION_COMMAND

Field(s)

MENU_COALITION_COMMAND:New(Coalition, MenuText, ParentMenu, CommandMenuFunction, CommandMenuArgument, ...)

MENU_COALITION constructor.

Creates a new radio command item for a coalition, which can invoke a function with parameters.

Parameters

  • Dcs.DCSCoalition#coalition.side Coalition : The coalition owning the menu.

  • #string MenuText : The text for the menu.

  • Menu#MENU_COALITION ParentMenu : The parent menu.

  • CommandMenuFunction : A function that is called when the menu key is pressed.

  • 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 value

#MENUCOALITIONCOMMAND:

MENU_COALITION_COMMAND:Remove(MenuTime, MenuTag)

Removes a radio command item for a coalition

Parameters

  • MenuTime :

  • MenuTag :

Return value

#nil:

Type MENU_COMMAND_BASE

Field(s)

#function MENU_COMMAND_BASE.MenuCallHandler
MENU_COMMAND_BASE.New(#, self, MenuText, ParentMenu, CommandMenuFunction, CommandMenuArguments)

Constructor

Parameters

  • # : ENUCOMMANDBASE

  • self :

  • MenuText :

  • ParentMenu :

  • CommandMenuFunction :

  • CommandMenuArguments :

Return value

#MENUCOMMANDBASE:

MENU_COMMAND_BASE.SetCommandMenuArguments(#, self, CommandMenuArguments)

This sets the new command arguments of a menu, so that if a menu is regenerated, or if command arguments change, that the arguments set for the menu are loosely coupled with the menu itself!!! If the arguments change, no new menu needs to be generated if the menu text is the same!!!

Parameters

  • # : ENUCOMMANDBASE

  • self :

  • CommandMenuArguments :

Return value

#MENUCOMMANDBASE:

MENU_COMMAND_BASE.SetCommandMenuFunction(#, self, CommandMenuFunction)

This sets the new command function of a menu, so that if a menu is regenerated, or if command function changes, that the function set for the menu is loosely coupled with the menu itself!!! If the function changes, no new menu needs to be generated if the menu text is the same!!!

Parameters

  • # : ENUCOMMANDBASE

  • self :

  • CommandMenuFunction :

Return value

#MENUCOMMANDBASE:

Type MENU_GROUP

Field(s)

MENU_GROUP.Group
MENU_GROUP.GroupID
MENU_GROUP.MenuPath
MENU_GROUP.Menus
MENU_GROUP:New(Group, MenuText, ParentMenu)

MENU_GROUP constructor.

Creates a new radio menu item for a group.

Parameters

  • Wrapper.Group#GROUP Group : The Group owning the menu.

  • #string MenuText : The text for the menu.

  • #table ParentMenu : The parent menu.

Return value

#MENU_GROUP: self

MENU_GROUP:Remove(MenuTime, MenuTag)

Removes the main menu and sub menus recursively of this MENU_GROUP.

Parameters

  • MenuTime :

  • MenuTag : A Tag or Key to filter the menus to be refreshed with the Tag set.

Return value

#nil:

MENU_GROUP:RemoveSubMenus(MenuTime, MenuTag)

Removes the sub menus recursively of this MENU_GROUP.

Parameters

  • MenuTime :

  • MenuTag : A Tag or Key to filter the menus to be refreshed with the Tag set.

Return value

#MENU_GROUP: self

Type MENU_GROUP_COMMAND

Field(s)

MENU_GROUP_COMMAND.Group
MENU_GROUP_COMMAND.GroupID
MENU_GROUP_COMMAND.MenuPath
MENU_GROUP_COMMAND:New(Group, MenuText, ParentMenu, CommandMenuFunction, CommandMenuArgument, ...)

Creates a new radio command item for a group

Parameters

  • Wrapper.Group#GROUP Group : The Group owning the menu.

  • MenuText : The text for the menu.

  • ParentMenu : The parent menu.

  • CommandMenuFunction : A function that is called when the menu key is pressed.

  • CommandMenuArgument : An argument for the function.

  • ... :

Return value

#MENUGROUPCOMMAND:

MENU_GROUP_COMMAND:Remove(MenuTime, MenuTag)

Removes a menu structure for a group.

Parameters

  • MenuTime :

  • MenuTag : A Tag or Key to filter the menus to be refreshed with the Tag set.

Return value

#nil:

Type MENU_MISSION

Field(s)

MENU_MISSION.Menus
MENU_MISSION:New(MenuText, ParentMenu)

MENU_MISSION constructor.

Creates a new MENU_MISSION object and creates the menu for a complete mission file.

Parameters

  • #string MenuText : The text for the menu.

  • #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 value

#MENU_MISSION:

MENU_MISSION:Remove(MenuTime, MenuTag)

Removes the main menu and the sub menus recursively of this MENU_MISSION.

Parameters

  • MenuTime :

  • MenuTag :

Return value

#nil:

MENU_MISSION:RemoveSubMenus()

Removes the sub menus recursively of this MENU_MISSION.

Note that the main menu is kept!

Return value

#MENU_MISSION:

Type MENU_MISSION_COMMAND

Field(s)

MENU_MISSION_COMMAND:New(MenuText, ParentMenu, CommandMenuFunction, CommandMenuArgument, ...)

MENU_MISSION constructor.

Creates a new radio command item for a complete mission file, which can invoke a function with parameters.

Parameters

  • #string MenuText : The text for the menu.

  • Menu#MENU_MISSION ParentMenu : The parent menu.

  • CommandMenuFunction : A function that is called when the menu key is pressed.

  • 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 value

#MENUMISSIONCOMMAND: self

MENU_MISSION_COMMAND:Remove()

Removes a radio command item for a coalition

Return value

#nil: