Skip to content

Menu System

DoDoCat edited this page Jul 4, 2020 · 7 revisions

Xml:

<Menu id="mnu_start_game">
	<Title>Welcome to OpenMB, please choose the game difficult before starting game.</Title>
	<Logic>mnu_start_game.script</Logic>
	<Children>
		<MenuItem id="mni_start_game_easy">Easy</MenuItem>
		<MenuItem id="mni_start_game_medium">Medium</MenuItem>
		<MenuItem id="mni_start_game_hard">Hard</MenuItem>
		<MenuItem id="mni_return">Return</MenuItem>
	</Children>
</Menu>

Elements:

<Menu> Element

Each menu should start with a element named <Menu> and end with a </Menu>
There is only one attribute called id in <Menu> which set the menu id

<Title> Element

The menu title

<Logic> Element

Logic block will define which script file will be called when this menu is loaded by engine
this engine should be a valid script file and only has two functions:

  • menuInit - When the menu is inited by the engine
  • menuButtonClicked - When you click a menu item

<Children> Element

Children block will contains the items of this menu

<MenuItem> Element

MenuItem will be showned as the menu options which player can choose
Each menuItem has id and displayText

Usage:

menuInit script function

Parameter Name Description
None -

menuButtonClicked script function

Parameter Name Description
Menu Item ID Which menu item you clicked

Example

Think about you create a menu in xml with ID menu_example and script is menu_example.script
It has three menu item as following:

  • Option 1 with ID mni_option_1
  • Option 2 with ID mni_option_2

You can use your menu in script like this:

function menuInit
end

function menuButtonClicked
   store_input_param %menuID 1 #Store the menu ID into variable %menuID
   switch %menuID
       case mni_option_1
           display_message @{You clicked Option 1!}
           end
       case mni_option_2
           display_message @{You clicked Option 2!}
           end
   end
end

switch a menu

Use switch_menu script command to switch a specific menu, the parameter on needed is menu's id
such like:

switch_menu YourMenuID