Layout Creation – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Link|Arma Reforger:Resource Manager|Resource Manager}}" to "{{Link|Arma Reforger:Resource Manager}}")
m (Some wiki formatting)
 
Line 66: Line 66:


Place another {{Link|enfusion://ResourceManager/~ArmaReforger:UI/layouts/WidgetLibrary/Buttons/WLib_ButtonText.layout|WLib_ButtonText.layout}} button and name it {{hl|ButtonChange}}.
Place another {{Link|enfusion://ResourceManager/~ArmaReforger:UI/layouts/WidgetLibrary/Buttons/WLib_ButtonText.layout|WLib_ButtonText.layout}} button and name it {{hl|ButtonChange}}.
----




Line 116: Line 114:
}
}


/*
// Close button
Close button
*/


SCR_ButtonTextComponent buttonClose = SCR_ButtonTextComponent.GetButtonText(BUTTON_CLOSE, rootWidget);
SCR_ButtonTextComponent buttonClose = SCR_ButtonTextComponent.GetButtonText(BUTTON_CLOSE, rootWidget);
Line 126: Line 122:
Print("Button Close not found - won't be able to exit by button", LogLevel.WARNING);
Print("Button Close not found - won't be able to exit by button", LogLevel.WARNING);


/*
// Change button
Change button
*/


SCR_ButtonTextComponent buttonChange = SCR_ButtonTextComponent.GetButtonText(BUTTON_CHANGE, rootWidget);
SCR_ButtonTextComponent buttonChange = SCR_ButtonTextComponent.GetButtonText(BUTTON_CHANGE, rootWidget);
Line 151: Line 145:
inputManager.AddActionListener("MenuOpenWB", EActionTrigger.DOWN, Close);
inputManager.AddActionListener("MenuOpenWB", EActionTrigger.DOWN, Close);
inputManager.AddActionListener("MenuBackWB", EActionTrigger.DOWN, Close);
inputManager.AddActionListener("MenuBackWB", EActionTrigger.DOWN, Close);
#endif
#endif // WORKBENCH
}
}
else if (!buttonClose)
else if (!buttonClose)
Line 173: Line 167:
inputManager.RemoveActionListener("MenuOpenWB", EActionTrigger.DOWN, Close);
inputManager.RemoveActionListener("MenuOpenWB", EActionTrigger.DOWN, Close);
inputManager.RemoveActionListener("MenuBackWB", EActionTrigger.DOWN, Close);
inputManager.RemoveActionListener("MenuBackWB", EActionTrigger.DOWN, Close);
#endif
#endif // WORKBENCH
}
}
}
}

Latest revision as of 17:12, 22 February 2025

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.

Think Head-Up Display (HUD).

Menu

A menu is an interface that provides choices or functionality to the player.

Think Field Manual, Inventory etc.

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.

Think OK/Cancel popup window, name input, etc.

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\layouts; in it, right-click > GUI layout (or the Create button > GUI layout) to create a .layout file - this is our new layout.

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.

  • Widget names will be used later in the code.
  • The WLib prefix means Widget Library and is used to find widget prefabs more easily.
  • Buttons are only useful in Menu and Dialog; as a Display is not interactable

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:
    Copy
    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).

See Action Context Setup for more information.

Display

Copy
GetGame().GetWorkspace().CreateWidgets(m_sLayout);

Menu

Copy
GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.TAG_LayoutTutorialExample);

Dialog

Copy
GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.TAG_LayoutTutorialExample, DialogPriority.INFORMATIVE, 0, true);

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:

  • cIsAnyDialogOpen() - check if an existing dialog exists
  • cGetTopMenu() - get the topmost menu
  • cCloseAllMenus() - close all opened menus