Walkthrough: the SaveLoad screen¶
The companion plugin ArcRmlUIDemo is a complete game UI built on ArcRmlUI. This page reads one of its screens, Save /
Load, from top to bottom: a slot list with an empty state, a detail panel, a sort dropdown, a delete confirm, prompts
that follow the focus, one hotkey and Back. Each part links the page that explains the feature. The excerpts are copied
from /ArcRmlUIDemo/UI/Rml/Demo/SaveLoad.rml and the screen's view model,
Source/ArcRmlUIDemo/ArcRmlDemoSaveLoadViewModel.h / .cpp. Read it after the feature pages to see them combined in
one real screen. The excerpts are shortened to the lines that matter.
Demo code and plugin API
The RML attributes, <viewmodel> declarations, dc-import, <kbd action> and data-focus-active on this page are
ArcRmlUI. Everything in the ArcRmlUIDemo module is demo code that you write differently in your game: the
ARC_RML_DEMO_SET macro, the demo subsystem UArcRmlDemoSubsystem that opens and closes the screens, the view
model base classes, the resolver ArcRmlDemoViewModelResolver, the components under
/ArcRmlUIDemo/UI/Rml/Demo/Components/ and the gu-* classes of GameUI.rcss.
Run the demo¶
The demo is in the Arc Lunzo Samples repository on GitHub; its ArcRmlUIHost.uproject has the demo set up.
In your own project, put the repository's Plugins/ArcRmlUIDemo folder in your project's Plugins folder (its README.md lists the setup), open the map
/ArcRmlUIDemo/Demo/Maps/L_ArcRmlDemo and press Play. The map's game mode starts the demo; outside Shipping builds,
ArcRmlDemo.Start in the console starts it in any map with a local player. Load Game in the main menu opens the screen
in load mode, Save Game in the pause menu in save mode.
The head¶
<rml>
<head>
<title>ArcRmlUI Demo Save / Load</title>
<meta name="layer" content="UI.Layer.Menu"/>
<meta name="input-mode" content="menu"/>
<meta name="hide-lower" content="true"/>
<meta name="keep-alive" content="true"/>
<meta name="input-mapping" content="/ArcRmlUIDemo/Demo/Input/IMC_ArcDemo_SaveLoad"/>
<link type="text/rcss" href="/ArcRmlUIDemo/UI/Rml/Demo/tokens.rcss"/>
<link type="text/rcss" href="/ArcRmlUIDemo/UI/Rml/Fonts/Fonts.rcss"/>
<link type="text/rcss" href="GameUI.rcss"/>
<link type="text/rcss" href="SaveLoad.rcss"/>
<viewmodel name="ui"
class="/ArcRmlUIDemo/Demo/ViewModels/BP_ArcRmlDemoUIVM.BP_ArcRmlDemoUIVM_C"
context="VM_ArcRmlDemoUI"/>
<viewmodel name="saveload"
class="/ArcRmlUIDemo/Demo/ViewModels/BP_ArcRmlDemoSaveLoadVM.BP_ArcRmlDemoSaveLoadVM_C"
resolver="/Script/ArcRmlUIDemo.ArcRmlDemoViewModelResolver"/>
</head>
layer,input-modeandhide-lower: a menu over the screen below it, which is hidden while this one is open (Documents).keep-alive: closing parks the document, so the next open keeps its state.input-mapping: the screen's own actions;IMC_ArcDemo_SaveLoadmapsIA_ArcDemo_Delete(Del, gamepad X) andIA_ArcDemo_DevBar(F10), which shows or hides the demo's panel of screen buttons. Confirm and Back come from the project's CommonUI input (Input and gamepad).- The style sheets: the demo's tokens and fonts,
GameUI.rcssshared by every demo screen, and the screen's ownSaveLoad.rcss(Styling).
Two view models¶
The head declares two models, and the body reads each through its own :model:
<body :model="ui"
class:theme-ember="ui.Theme == 'ember'"
class:theme-daylight="ui.Theme == 'daylight'"
on:back="call('ui', 'Back'); stopPropagation()"
on:uiaction="callIf(ev.action == 'IA_ArcDemo_DevBar', 'ui', 'ToggleDevBar')">
<div class="gu-layer">
<div class="gu-screen" :model="saveload">
uiis shared by every demo screen: the theme and the dev bar. Its source iscontext, so it is looked up in the GameInstance's view model collection, where the demo adds it when it starts (Source: context). Theclass:theme-*bindings on<body>read itsTheme(Themes).saveloadis this screen's own state. Its source is a resolver (Source: resolver); the demo's resolver returns one instance per class and player, so the state survives closing and opening the screen.ev.actionin theon:uiactionline is the name of the Input Action that fired (UI actions); hereIA_ArcDemo_DevBar(F10) callsToggleDevBar.- Both classes are Blueprint children of C++ view models; the Blueprints hold the data defaults (Blueprint view models).
call('saveload', ...) and call('ui', ...) name the model they call (Calls), wherever the element sits.
The list and its empty state¶
<div class="sl-grid" :if="saveload.Slots.size > 0" data-focus-area="slots" data-focus-primary="">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/SaveSlotCard"
:for="slSlot, slSlot_index : saveload.Slots"
state="{{ slSlot.State }}"
slot-label="{{ slSlot.SlotLabel }}"
title="{{ slSlot.Title }}"
location="{{ slSlot.Location }}"
playtime="{{ slSlot.Playtime }}"
date="{{ slSlot.Date }}"
autosave-label="Auto"
empty-label="Empty slot"
empty-hint="{{ slSlot.EmptyHint }}"
corrupted-label="Data corrupted"
corrupted-hint="This file cannot be read."
selected="{{ slSlot_index == saveload.SelectedSlot }}"
focusable="{{ true }}"
autofocus="{{ slSlot_index == saveload.SelectedSlot }}"
on:click="call('saveload', 'Activate', slSlot_index)"
style="width: 100%"/>
</div>
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/EmptyState"
:if="saveload.Slots.size == 0"
icon="/ArcRmlUIDemo/UI/Rml/icons/folder-x.svg"
title="No saved games"
body="Your saves and autosaves will appear here."
style="width: 100%">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/Button"
label="New game"
icon-left="/ArcRmlUIDemo/UI/Rml/icons/plus.svg"/>
</dc-import>
:ifshows the grid whileSlotshas rows and the empty state when it has none;.sizeis the array's length (Fields).:for="slSlot, slSlot_index : saveload.Slots"on the import makes one card per row, with the row and its index (Lists). The click passes the index toActivate.selectedandautofocuscompare the index withSelectedSlot, so focus lands on the selected slot when the area is entered, also after the screen is opened again. No view model field follows the focus.
UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "ArcRmlDemo")
TArray<FArcRmlDemoSaveSlotRow> Slots;
UPROPERTY(BlueprintReadOnly, FieldNotify, Category = "ArcRmlDemo")
int32 SelectedSlot = 1;
Slots is a TArray of a row struct. The view model rebuilds it from the demo's game model, so a save or a delete
changes the list.
Components and slots¶
Every dc-import above expands a component by its package path, with props as attributes and {{ }} values bound to
the screen's model (Props). Children of an import fill its slots
(Slots):
- the "New game" button sits in the default slot of
EmptyState; - the sort dropdown sits in the default slot of
SectionHeader(below); - the action buttons sit in the
footerslot ofPanel, whose import setshas-footer="{{ true }}"because the panel shows its footer only with that prop:
<div slot="footer" class="sl-actions" data-focus-area="actions" data-focus-parent="slots">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/Button"
label="Delete"
variant="ghost"
icon-left="/ArcRmlUIDemo/UI/Rml/icons/trash-2.svg"
disabled="{{ saveload.bNoDelete }}"
focusable="{{ true }}"
data-focus-enter="modal"
on:click="callIf(!saveload.bNoDelete, 'saveload', 'Delete')"/>
Delete is reachable while disabled: disabled only changes its look, so the click is guarded with
callIf(!bNoDelete, ...) (callIf).
Focus areas¶
The screen has four areas (Focus areas):
| Area | Element | Attributes |
|---|---|---|
slots |
the slot grid | data-focus-primary |
sort |
the sort dropdown | none |
actions |
the panel footer | data-focus-parent="slots" |
modal |
the delete confirm | data-focus-contain |
<div class="sl-sort" data-focus-area="sort">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/Dropdown"
data-focus-owner=""
value="Most recent"
field="sort"
style="width: 100%"/>
</div>
slotsis the primary area, so the screen opens on the grid, at theautofocuscard.- Arrows leave an area at its edge to the nearest item of another area (Leaving an area).
- Back in
actionsreturns to its parentslots(Back and the parent area), and a leave from a slot intoactionsrecords that slot as the area's origin. The other areas have no parent, so their Back goes to<body>(Back).
The confirm is an area inside the screen, shown while bConfirm is true:
<div class="gu-area" :if="saveload.bConfirm" data-focus-area="modal" data-focus-contain="">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/Modal"
backdrop="{{ true }}"
variant="danger"
title="Delete this save?"
body="{{ saveload.ConfirmBody }}"
buttons="{{ saveload.ConfirmButtons }}"
focused="{{ 0 }}"/>
</div>
data-focus-contain: the arrows never leave the confirm (Containing focus).- The Delete button and both Delete prompts carry
data-focus-enter="modal". After their click, focus entersmodalonceDeletehas run and the area is shown, and lands on the button thatModal'sfocusedprop marksautofocus(Cancel). - The confirm's buttons call
Choose(index)onsaveload: 0 is Cancel, 1 deletes the slot.
void UArcRmlDemoSaveLoadViewModel::Delete()
{
if (bConfirm || !GetSlots().IsValidIndex(SelectedSlot) || GetSlots()[SelectedSlot].State == TEXT("empty"))
{
return;
}
ARC_RML_DEMO_SET(*this, bConfirm, true);
Refresh();
}
Limits
data-focus-enteris read only from a click (a mouse click, pad accept, a hotkey or cycle step), never from a key handler that calls the view model.- A
:ifthat turns true builds its branch again, so focus, scroll and hover state inside it start fresh (Limits). - A custom element that looks disabled stays a focus stop; only a disabled form control loses it.
Prompts per area¶
The footer holds one prompt group per area, and GameUI.rcss shows the group of the active area. The plugin sets
data-focus-active on <body> to the name of the area that holds the focus, so CSS can switch groups without a view
model field:
<div class="gu-prompts gu-default" data-area="slots" :if="!saveload.bConfirm">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/PromptBar">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/InputPrompt"
action="confirm"
label="{{ saveload.Mode == 'save' ? 'Save' : 'Load' }}"
disabled="{{ saveload.bNoPrimary }}"/>
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/InputPrompt"
action="/ArcRmlUIDemo/Demo/Input/IA_ArcDemo_Delete"
label="Delete"
disabled="{{ saveload.bNoDelete }}"
data-focus-enter="modal"
on:click="callIf(!saveload.bNoDelete, 'saveload', 'Delete')"/>
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/InputPrompt"
action="back"
label="Back"/>
</dc-import>
</div>
.gu-prompts {
display: none;
}
.gu-prompts.gu-all,
body:not([data-focus-active]) .gu-prompts.gu-default,
/* the full sheet repeats this selector for every focus area name used by any demo screen */
body[data-focus-active="slots"] .gu-prompts[data-area="slots"] {
display: contents;
}
The full sheet repeats this selector for every focus area name used by any demo screen. gu-default also shows while no area is active, and gu-all always. A
:if on bConfirm replaces the groups with Confirm and Cancel while the confirm is open:
<div class="gu-prompts gu-all" :if="saveload.bConfirm">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/PromptBar">
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/InputPrompt"
action="confirm"
label="Confirm"/>
<dc-import name="/ArcRmlUIDemo/UI/Rml/Demo/Components/InputPrompt"
action="back"
label="Cancel"/>
</dc-import>
</div>
InputPrompt shows its key with <kbd action> (Key labels): confirm and back are the project's Confirm and
Back, the path is the package path of the screen's Input Action, each shown for the current input device.
The hotkey¶
InputPrompt also sets data-hotkey on its element to its action, so on the Delete prompts, when that action fires, the prompt is clicked and its
on:click and data-focus-enter run as for the button
(The menu's own action).
A hotkey clicks only a visible element, so the key works exactly while a Delete prompt is shown: in slots and
actions, not in sort or while the confirm is open.
Limits
When several visible elements carry the same hotkey, the one on the focus chain is clicked, else the first visible one in the focused area, then in the document; nothing is reported. Here two prompt groups carry the Delete hotkey, and CSS shows one at a time.
Back¶
One handler on <body> handles Back for the whole screen (Back): the on:back attribute of the <body> shown in
Two view models, call('ui', 'Back'); stopPropagation().
Back in actions first returns focus to its parent slots, on the slot it was entered from, and never reaches
<body> (Back and the parent area). With no saves there is no slots area,
so that Back goes on to <body> like a Back in slots, sort or modal. <body> calls ui's Back and stops
the event (stopPropagation), so the host never closes the document by itself on this screen.
The demo's ui model passes Back to the model of the screen on top, here saveload:
void UArcRmlDemoSaveLoadViewModel::Back()
{
if (bConfirm)
{
Choose(0);
return;
}
Super::Back();
}
With the confirm open, Back cancels it. Otherwise the base class asks the demo subsystem to leave the screen, which
closes the document and shows the screen below. The breadcrumb at the top of the screen (a row of screen names) also calls Back
when you click its first name with the mouse; it is nofocus, so it is not a focus stop.