Presenters and CommonUI
By default the plugin draws each player's screens (main menu, pause menu, settings, dialogs) in a layer of its own over that player's part of the screen, and handles their input mode. A game whose UI already has a stack of screens (CommonUI or its own) can take the plugin's screens into that stack instead, with a presenter. The plugin has no dependency on CommonUI and turns nothing of it on.
Without a presenter
- No CommonUI in the project: nothing to do.
- CommonUI enabled: the plugin's screens coexist with CommonUI's action router. Each screen sets the input mode once when it opens and gives it back when it closes. While it is open, it takes back the focus the router gives to the game, when the player changes device and when the game viewport gets it, so that the keyboard and the gamepad keep driving the screen (HSP206, information only). If something gives the focus to the game viewport again and again, the screen stops after a few takebacks (HSP307): set the focus or the input mode in On Screen Closed. Button prompts follow CommonInput's current input type while Controls > Follow Common Input Device is ticked (the default), and the controller's accept button reaches the plugin's screens as a key, not as CommonUI's click (Input).
- A panel inside your activatable widget: place a Neo Settings Panel in one of your
Commons and bind its On Back Requested to Deactivate Widget. The panel handles Back itself.Activatable Widget
With a presenter
A presenter is a class of yours based on Neo Screen Presenter (Blueprint or C++), set as Project Settings > Integration > Screen Presenter Class. For each screen, the plugin wraps it in a Neo Screen widget and calls Present Screen with a Neo Screen Request:
| Field | Meaning |
|---|---|
| Screen | Settings, Main Menu, Pause Menu or Dialog |
| Player | The local player's controller |
| Widget | The screen as a UMG widget: put it in your UI |
| Modal | The screen takes the player's input while it is up: give it the focus and a menu input mode |
Return true and your UI owns the screen's place and the input mode; return false and the plugin draws it in its own layer as usual (logged once, HSP402). Dismiss Screen comes when the screen closes, only for the screens you accepted: remove what you added. One presenter is made per local player.
The Neo Screen widget draws the screen and handles its keys, Back included; it passes the focus it receives to the screen, and it never changes the input mode. Wire your UI's own back action to its Request Back.
With CommonUI, in four steps
- Make an activatable widget of your own (a Widget Blueprint based on Common Activatable Widget) to hold one plugin screen: a Named Slot or an empty Overlay is enough. Its desired input config: Menu when the request is modal, Game otherwise. Its desired focus target: the Neo Screen widget it holds. Tick Is Back Handler and override On Handle Back Action: call Request Back on that widget and return true (the default handling would deactivate your frame behind the plugin's back). CommonUI's Back then goes to the plugin's screen, which goes back one layer; your frame leaves the stack through Dismiss Screen when the screen closes.
- Make a presenter (a Blueprint based on Neo Screen Presenter). In Present Screen: push your activatable widget onto your stack (Push Widget on your Common Activatable Widget Stack), put the request's Widget inside it, return true. Return false for a player that has no stack of yours (a split-screen player without a layout).
- In Dismiss Screen: remove the activatable widget that holds the request's Widget from your stack.
- Set it as Project Settings > Neo Settings > Integration > Screen Presenter Class.
Your stack then plays its own transitions, and CommonUI's router gives the input to the top widget as it does for your other screens; one Back closes one layer of the plugin's screens.
The same in C++ (it needs your module to depend on CommonUI):
// A frame of your stack that holds one plugin screen.
UCLASS()
class UMyScreenFrame : public UCommonActivatableWidget
{
GENERATED_BODY()
public:
UMyScreenFrame(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bIsBackHandler = true; // CommonUI's Back comes to this frame...
}
void SetScreen(UNeoScreenWidget* InScreen, bool bInModal)
{
Screen = InScreen;
bModal = bInModal;
WidgetTree->RootWidget = InScreen; // the frame's whole content
}
virtual TOptional<FUIInputConfig> GetDesiredInputConfig() const override
{
return bModal ? FUIInputConfig(ECommonInputMode::Menu, EMouseCaptureMode::NoCapture)
: FUIInputConfig(ECommonInputMode::Game, EMouseCaptureMode::CapturePermanently_IncludingInitialMouseDown);
}
protected:
virtual UWidget* NativeGetDesiredFocusTarget() const override { return Screen; } // the screen takes the focus
virtual bool NativeOnHandleBackAction() override
{
// ...and goes to the plugin's screen, which goes back one layer (Dismiss Screen then removes this frame).
if (Screen != nullptr)
{
Screen->RequestBack();
return true;
}
return Super::NativeOnHandleBackAction();
}
private:
UPROPERTY(Transient)
TObjectPtr<UNeoScreenWidget> Screen;
bool bModal = true;
};
// The presenter: Stack is your game's UCommonActivatableWidgetStack for Request.Player (found your own way).
bool UMyPresenter::PresentScreen_Implementation(const FNeoScreenRequest& Request)
{
UCommonActivatableWidgetStack* Stack = FindMyStack(Request.Player);
if (Stack == nullptr || Request.Widget == nullptr)
{
return false; // the plugin draws it in its own layer
}
UNeoScreenWidget* Screen = Request.Widget;
const bool bModal = Request.bModal;
return Stack->AddWidget<UMyScreenFrame>(UMyScreenFrame::StaticClass(),
[Screen, bModal](UMyScreenFrame& Frame) { Frame.SetScreen(Screen, bModal); }) != nullptr;
}Dismiss removes the frame that holds Request. with Stack->Remove.
Lyra and other layouts
A primary game layout with layers (Lyra's Primary Game Layout) is reached the same way: the presenter pushes the plugin's screen onto the layer you choose (the menu layer for the settings, the modal layer for dialogs).
Something not as described? Every code the editor shows has its own entry in Troubleshooting.