wavelength 1.0.0
Loading...
Searching...
No Matches
uipanel.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 "os/string.h"
9#include "os/strless.h"
10#include "rnd/rndanimatable.h"
11#include "rnd/rndloader.h"
12#include "rnd/rndobject.h"
13#include "rnd/rndtext.h"
14#include "rnd/rndview.h"
15#include "script/dataarray.h"
16#include "ui/uicomponent.h"
17#include "ui/uinavigator.h"
18
35class UIPanel : public MsgSink {
36public:
44
55 UIPanel(DataArray *pData, const char *pszDir);
56
63 ~UIPanel() override;
64
76 static void Init(DataArray *pConfig);
77
89 static UIPanel *New(DataArray *pData, const char *pszDir) {
90 return new UIPanel(pData, pszDir);
91 }
92
106 bool Dispatch(Message *pMsg) override;
107
118 bool DispatchPriv(Message *pMsg) override;
119
128 virtual void Load();
129
140 virtual void Unload();
141
152 virtual void Enter(bool bForce, float fTime);
153
164 virtual void Exit(bool bForce, float fTime);
165
172 virtual void Focus();
173
182 virtual void Unfocus() {
183 }
184
194 virtual void DrawGizmo() {
195 }
196
204 virtual void Poll(float fTime);
205
212 virtual void Draw();
213
221 virtual void SetShowing(bool bShowing);
222
235 virtual void SetFocus(UIComponent *pComponent, int nButton);
236
243 virtual void FinishLoad();
244
252 bool IsLoaded();
253
261 void AddComponent(UIComponent *pComponent);
262
270 void SetTextsShowing(bool bShowing);
271
282 float ComputeFrame(float fTime);
283
293 UIComponent *FindComponent(const char *pszName, bool bFail);
294
307 void LocalizeTexts(const char *pszFile, std::list<RndObject *> &objects);
308
310 const char *GetName() const {
311 return mName;
312 }
313
316 return mFocus;
317 }
318
320 int GetState() const {
321 return mState;
322 }
323
325 float GetTransitionStart() const {
326 return mTransitionStart;
327 }
328
330 const std::map<const char *, std::unique_ptr<UIComponent>, StrLess> &GetComponents() const {
331 return mComponents;
332 }
333
334protected:
335 float mFrame;
336
338
339 const char *mName;
340
342
343 int mState;
344
346
347 const char *mFocusName;
348
350
352
354
356
358
360
361 float mEnterMs;
362
363 float mExitMs;
364
366
368
370
372
374
376
378
379 std::list<RndText *> mTexts;
380
381 std::map<const char *, std::unique_ptr<UIComponent>, StrLess> mComponents;
382
383 std::unique_ptr<UINavigator> mNavigator;
384
386
388
390 std::unique_ptr<RndLoader> mOwnedLoader;
391
392private:
399 static float sEnterStartFrame;
400
407 static float sEnterStopFrame;
408
415 static float sExitStartFrame;
416
423 static float sExitStopFrame;
424};
Reference-counted array of script data nodes.
Definition dataarray.h:20
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
Mix-in for an object driven by a frame.
Definition rndanimatable.h:16
Loader of one .rnd file, which reads the file over several frames.
Definition rndloader.h:21
View that shows the children of another view, its children owner, under its own transform and frame.
Definition rndview.h:27
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
float mExitMs
Definition uipanel.h:363
RndAnimatable * mEnterExitAnim
Definition uipanel.h:353
UIPanel(DataArray *pData, const char *pszDir)
Construct a hidden panel from its script description.
~UIPanel() override
Destroy the panel, its components, and the objects its file loaded.
std::unique_ptr< UINavigator > mNavigator
Definition uipanel.h:383
RndView * mView
Definition uipanel.h:345
virtual void Focus()
React to the screen giving the panel the focus by letting the navigator move the focus.
int mLoadRefs
Definition uipanel.h:373
void SetTextsShowing(bool bShowing)
Show or hide every text object of the panel's file.
virtual void Draw()
Draw the panel's view once it has loaded, unless the panel is hidden.
UIComponent * FindComponent(const char *pszName, bool bFail)
Find a component by name.
bool Dispatch(Message *pMsg) override
Offer a message to the current screen, the panel, the navigator, and the component with the focus.
float GetTransitionStart() const
Definition uipanel.h:325
std::unique_ptr< RndLoader > mOwnedLoader
The loader the panel created, or null when it has none or uses a shared one.
Definition uipanel.h:390
DataArray * mData
Definition uipanel.h:377
void LocalizeTexts(const char *pszFile, std::list< RndObject * > &objects)
Collect and localise the text objects of the panel's file.
const char * GetName() const
Definition uipanel.h:310
void AddComponent(UIComponent *pComponent)
Register a component under its name.
virtual void Poll(float fTime)
Advance the panel's animations and its components to a time.
virtual void Exit(bool bForce, float fTime)
Start the exit animation.
float mEnterMs
Definition uipanel.h:361
virtual void SetShowing(bool bShowing)
Show or hide the panel's view.
RndLoader * mLoader
Definition uipanel.h:387
float mHiddenFrame
Definition uipanel.h:359
virtual void SetFocus(UIComponent *pComponent, int nButton)
Move the focus to a component.
std::list< RndText * > mTexts
Definition uipanel.h:379
int GetState() const
Definition uipanel.h:320
static void Init(DataArray *pConfig)
Read the default frames of the entry and exit animation.
float ComputeFrame(float fTime)
Report the frame of the entry and exit animation at a time.
const char * mName
Definition uipanel.h:339
const std::map< const char *, std::unique_ptr< UIComponent >, StrLess > & GetComponents() const
Definition uipanel.h:330
int mEnterReversed
Definition uipanel.h:365
UIComponent * mFocus
Definition uipanel.h:385
static UIPanel * New(DataArray *pData, const char *pszDir)
Create a panel from its script description.
Definition uipanel.h:89
float mExitStartFrame
Definition uipanel.h:371
virtual void Enter(bool bForce, float fTime)
Start the entry animation.
const char * mFocusName
Definition uipanel.h:347
int mState
Definition uipanel.h:343
bool DispatchPriv(Message *pMsg) override
Handle a message sent to the panel.
virtual void Unfocus()
React to the screen taking the focus away.
Definition uipanel.h:182
virtual void FinishLoad()
Find the loaded objects and create the components once the panel's file has loaded.
std::map< const char *, std::unique_ptr< UIComponent >, StrLess > mComponents
Definition uipanel.h:381
String mFile
Definition uipanel.h:341
int mLoaded
Definition uipanel.h:375
virtual void DrawGizmo()
Draw what goes under the panel.
Definition uipanel.h:194
RndAnimatable * mLoopAnim
Definition uipanel.h:351
virtual void Load()
Take a reference to the panel's file, queueing the file on the first reference.
float mEnterStartFrame
Definition uipanel.h:369
int mExitReversed
Definition uipanel.h:367
bool IsLoaded()
Report whether the panel's file has loaded, finishing the load when it has.
float mIdleFrame
Definition uipanel.h:337
float mTransitionStart
Definition uipanel.h:355
float mLoopStart
Definition uipanel.h:349
State
Where the panel is in its entry and exit, the values of mState.
Definition uipanel.h:38
@ kStateExiting
Definition uipanel.h:42
@ kStateEntering
Definition uipanel.h:41
@ kStateHidden
Definition uipanel.h:40
@ kStateShown
Definition uipanel.h:39
float mShownFrame
Definition uipanel.h:357
float mFrame
Definition uipanel.h:335
UIComponent * GetFocus() const
Definition uipanel.h:315
virtual void Unload()
Drop a reference to the panel's file, destroying the components and the loader on the last reference.