wavelength 1.0.0
Loading...
Searching...
No Matches
uimanager.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <map>
5#include <memory>
6
7#include "app/msgsink.h"
8#include "app/msgsource.h"
10#include "os/string.h"
11#include "os/strless.h"
12#include "rnd/rndloader.h"
13#include "rnd/rndobject.h"
14#include "script/dataarray.h"
15#include "ui/uicomponent.h"
16#include "ui/uipanel.h"
17#include "ui/uiscreen.h"
18#include "ui/uistyle.h"
19
36class UIManager : public MsgSource, public MsgSink {
37public:
47 public:
56 explicit Callback(DataArray *pConfig);
57
64 ~Callback() override {
65 }
66
79 int ShouldLoad(RndObject *pExisting, const char *pszName, const char *pszClass) override;
80
87 void Report();
88
89 private:
90 DataArray *mAllowed;
91 String mRejected;
92 };
93
101 typedef UIPanel *(*PanelFactory)(DataArray *pData, const char *pszDir);
102
109 typedef UIScreen *(*ScreenFactory)(DataArray *pData);
110
117 typedef UIStyle *(*StyleFactory)(DataArray *pData);
118
126 typedef UIComponent *(*ComponentFactory)(DataArray *pData, const char *pszDir);
127
135
142 ~UIManager() override;
143
151 void Init();
152
159 void Terminate();
160
168 void AddScreen(UIScreen *pScreen);
169
177 void AddPanel(UIPanel *pPanel);
178
186 void AddStyle(UIStyle *pStyle);
187
197
198#ifdef VIDEO_STANDARD_PAL
206 void StopRepeat();
207#endif
208
217 bool DispatchPriv(Message *pMsg) override;
218
230 __attribute__((noinline)) bool HandleJoypad(JoypadInputMsg *pMsg);
231
243 bool Dispatch(Message *pMsg) override;
244
252 void Poll(float fTime);
253
260 void Draw();
261
271 UIScreen *FindScreen(const char *pszName, bool bFail);
272
282 UIPanel *FindPanel(const char *pszName, bool bFail);
283
294 UIComponent *FindComponent(const char *pszPanel, const char *pszComponent, bool bFail);
295
305 UIStyle *FindStyle(const char *pszName, bool bFail);
306
316 void GotoScreen(const char *pszName);
317
330 void GotoScreen(UIScreen *pScreen);
331
342
353
361 void LoadGroup(const char *pszGroup);
362
370 void UnloadGroup(const char *pszGroup);
371
380 bool IsGroupLoaded(const char *pszGroup);
381
390 void RegisterPanelType(PanelFactory pfnFactory, const char *pszType);
391
400 void RegisterScreenType(ScreenFactory pfnFactory, const char *pszType);
401
410 void RegisterStyleType(StyleFactory pfnFactory, const char *pszType);
411
420 void RegisterComponentType(ComponentFactory pfnFactory, const char *pszType);
421
433 UIPanel *CreatePanel(DataArray *pData, const char *pszDir);
434
446
458
470 UIComponent *CreateComponent(DataArray *pData, const char *pszDir);
471
480 void LoadFile(const char *pszFile, bool bLoadAll);
481
492 void VerifyGroup(const char **ppszGroup);
493
503
506 return mCurrentScreen;
507 }
508
510 float GetTime() const {
511 return mTime;
512 }
513
515 int GetEditMode() const {
516 return mEditMode;
517 }
518
519private:
520 std::unique_ptr<Callback> mCallback;
521 DataArray *mAllowableGroups;
522 std::map<const char *, std::unique_ptr<UIScreen>, StrLess> mScreens;
523 std::map<const char *, std::unique_ptr<UIPanel>, StrLess> mPanels;
524 std::map<const char *, std::unique_ptr<UIStyle>, StrLess> mStyles;
525 UIScreen *mCurrentScreen;
526 float mTime;
527 int mEditMode;
528 std::list<std::unique_ptr<RndObject>> mSharedObjects;
529 std::map<String, PanelFactory> mPanelFactories;
530 std::map<String, ScreenFactory> mScreenFactories;
531 std::map<String, StyleFactory> mStyleFactories;
532 std::map<String, ComponentFactory> mComponentFactories;
533 int mRepeatButton;
534 int mRepeatPad;
535 float mRepeatTime;
536 int mRepeatPending;
537 int mRepeatCount;
538
547 static float RepeatDelay(int nCount);
548
555 static float sFirstRepeatDelay;
556
563 static float sRepeatDelay;
564};
565
571extern UIManager TheUI;
Reference-counted array of script data nodes.
Definition dataarray.h:20
Message the controller poll sends when a button is pressed or released.
Definition joypadinputmsg.h:23
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
Receiver of engine messages.
Definition msgsink.h:21
MsgSource()
Construct a source with no sinks.
Interface a loader consults before it creates each object of its file.
Definition rndloader.h:35
Base of every object the renderer can load, resolve by name, and serialise.
Definition rndobject.h:20
Ordering of C strings by their text, for maps keyed by name.
Definition strless.h:10
Growable text buffer that is also a PrnStream.
Definition string.h:19
One control of a front-end panel, such as a label, a button, or a list.
Definition uicomponent.h:21
void Report()
Report the objects the loads skipped without permission.
Callback(DataArray *pConfig)
Construct a callback.
~Callback() override
Destroy the callback.
Definition uimanager.h:64
int ShouldLoad(RndObject *pExisting, const char *pszName, const char *pszClass) override
Create an object only when no object of the name exists.
Owner of every front-end screen, panel, and style, and of the screen that shows.
Definition uimanager.h:36
UIScreen * GetCurrentScreen() const
Definition uimanager.h:505
void RegisterPanelType(PanelFactory pfnFactory, const char *pszType)
Register a panel type.
UIScreen *(* ScreenFactory)(DataArray *pData)
Routine that creates a screen from its script description.
Definition uimanager.h:109
UIComponent *(* ComponentFactory)(DataArray *pData, const char *pszDir)
Routine that creates a component from its script description.
Definition uimanager.h:126
float GetTime() const
Definition uimanager.h:510
bool IsNavigationMsg(Message *pMsg)
Report whether a message is a controller button or a keyboard key.
void Init()
Read the ui section of the configuration, load the shared .rnd files, and register the built-in panel...
void Poll(float fTime)
Advance the current screen to a time, and send the repeat of a held directional button.
UIManager()
Construct an empty manager.
void UnloadGroup(const char *pszGroup)
Unload the panels of every screen of a loading group.
UIStyle * FindStyle(const char *pszName, bool bFail)
Find a style by name.
void LoadGroup(const char *pszGroup)
Load the panels of every screen of a loading group.
UIPanel * FocusPanel()
Report the panel with the focus on the current screen.
void SetCurrentScreen(UIScreen *pScreen)
Record the current screen.
UIComponent * CreateComponent(DataArray *pData, const char *pszDir)
Create a component through the factory registered for its entry type.
void AddScreen(UIScreen *pScreen)
Register a screen under its name.
void RegisterScreenType(ScreenFactory pfnFactory, const char *pszType)
Register a screen type.
void LoadFile(const char *pszFile, bool bLoadAll)
Read a front-end description and create what it describes.
void GotoScreen(UIScreen *pScreen)
Change to a screen.
UIComponent * FindComponent(const char *pszPanel, const char *pszComponent, bool bFail)
Find a component of a panel by name.
bool DispatchPriv(Message *pMsg) override
Track the directional buttons for the repeat.
UIPanel * CreatePanel(DataArray *pData, const char *pszDir)
Create a panel through the factory registered for its entry type.
void GotoScreen(const char *pszName)
Change to the screen of a name.
UIPanel * FindPanel(const char *pszName, bool bFail)
Find a panel by name.
void Terminate()
Destroy every style, screen, panel, and shared object.
void RegisterComponentType(ComponentFactory pfnFactory, const char *pszType)
Register a component type.
UIPanel *(* PanelFactory)(DataArray *pData, const char *pszDir)
Routine that creates a panel from its script description.
Definition uimanager.h:101
void AddStyle(UIStyle *pStyle)
Register a style under its name.
UIStyle * CreateStyle(DataArray *pData)
Create a style through the factory registered for its entry type.
bool IsGroupLoaded(const char *pszGroup)
Report whether every screen of a loading group has loaded.
void AddPanel(UIPanel *pPanel)
Register a panel under its name.
int GetEditMode() const
Definition uimanager.h:515
void VerifyGroup(const char **ppszGroup)
Check a loading group against the allowable_groups of the configuration.
void RegisterStyleType(StyleFactory pfnFactory, const char *pszType)
Register a style type.
UIScreen * CreateScreen(DataArray *pData)
Create a screen through the factory registered for its entry type.
UIScreen * FindScreen(const char *pszName, bool bFail)
Find a screen by name.
void ReportLocalizeErrors()
Report the localisation errors the panels recorded while their texts loaded.
~UIManager() override
Destroy the manager.
__attribute__((noinline)) bool HandleJoypad(JoypadInputMsg *pMsg)
Start or stop the repeat of a directional button.
void Draw()
Draw the current screen.
UIStyle *(* StyleFactory)(DataArray *pData)
Routine that creates a style from its script description.
Definition uimanager.h:117
bool Dispatch(Message *pMsg) override
Offer a message to the sinks, then to the manager, then to the current screen.
Group of components drawn from one .rnd file, which a screen shows.
Definition uipanel.h:35
One front-end screen, a set of panels shown together with one panel holding the focus.
Definition uiscreen.h:35
Material and font a component draws with in each of its states.
Definition uistyle.h:15
UIManager TheUI
The front-end manager.