Layout Creation – Arma Reforger
Definitions
Display
A display is a layout that only provides information to the player; it does not require any input. The player can control his character normally, movement/cursor are not captured.
Menu
A menu is an interface that provides choices or functionality to the player.
Dialog
A dialog is an interface that requires player's input. There can be multiple dialogs at the same time, they are then ordered by priority. It is displayed on top of a menu, if any is present.
Widget
A widget is an element composing a layout - a button, a text, a scrollbar, any "layout part" is a widget.
Create a Mod
See Mod Project Setup.
Create a Layout
Using Resource Manager, open the mod's directory and create the directory tree UI
Double-click on it to open it, using the Layout Editor to edit it.
This first example will sport three features: a title, a change text button and a close button.
- Clicking the change button will change the title
- Clicking the close button will close the UI
- Clicking the title will do nothing.
Add the Close Button
The first widget is an important one; this button will be used to close the opened UI.
Place a WLib_ButtonText.layout button by dragging the layout file from the Resource Browser into the opened layout. In the Hierarchy window, name it ButtonClose.
To change this button's text, one could be tempted to change ButtonClose > SizeLayout > Overlay > Text's Text property.
However, as this prefab uses a SCR_ButtonTextComponent script component, the displayed value is set within this component.
Click on ButtonClose (the prefab's topmost widget) and in its properties, under Script, find this said component to change its Text property.
Add the Title Text
The second widget is the title. Place a RichText_Heading2.layout and name it "TextTitle".
Add the Change Text Button
Place another WLib_ButtonText.layout button and name it ButtonChange.
Menu/Dialog Setup
Menus and Dialogs share the same first steps:
- Add an enum constant by modding the ChimeraMenuPreset enum in a new script file:modded enum ChimeraMenuPreset { TAG_LayoutTutorialExample, }
- Override chimeraMenus.conf in the mod (see Data Modding Basics - Overriding_assets - right-click → override in LayoutTutorial)
- Declare this new layout in it by adding an entry (clicking the "+" button):
- The entry name ("object name" required on new entry) must match the enum constant, here TAG_LayoutTutorialExample, otherwise the engine will not be able to find the menu and will throw an error
- Layout - the path to the created layout
- Action Context - unused in this tutorial
- Class - the script class to be used with the menu/dialog, see the next chapter where we will create the TAG_LayoutTutorialUI class.
- Menu Items - unused in this tutorial
- Preload Count - unused in this tutorial
- Persistent - unused in this tutorial
Class Setup
The menu/dialog class must inherit from at least MenuBase, ChimeraMenuBase or MenuRootBase, depending on the required features.
Here is the example adapted to our earlier layout:
Usage
In order to test more easily, we can place a prefab with an ActionsManagerComponent to add actions that trigger UI creation. Each action targets a specific type (display, menu, dialog and their respective classes, TAG_DisplayAction, TAG_MenuAction and TAG_DialogAction).
Display
Menu
Dialog
Code
Using these actions allow to see the different behaviours of said interface - be sure to set the action's default layout (m_sLayout either in code or in Action's configuration UI.
See Also
MenuManager's various methods, including:
- IsAnyDialogOpen() - check if an existing dialog exists
- GetTopMenu() - get the topmost menu
- CloseAllMenus() - close all opened menus