GUI Management
Here is the deal:
I need to code strong tools and classes to continue to bring MMO idea to life.
First thing i’m thinking about, after races and classes for the game, is how user will login (i’m talking about user interface) ?
User will have to register on website, then use this login/password on the DS to connect to server. Well, only at this point, i need at least two things :
A place where user can enter text
A way to enter text.
A way to show messages to user (while processing connection, checking password etc …)
All right.
I need a GUI.
Lets go. I created 4 important classes.
CControl : What is a basic control ? Well, on the GUI, it is a graphic control. So usual X,Y,Width,Height and CControl * Owner are fine. Then, i defined 2 virtual methods (pure virtual) : ProcessMessage(tMessage msg) and DispatchMessage(tMessage msg)
ProcessMessage will be called when a control have to treat a message sent by owner.
i.e : When a button is clicked or focused, it needs to have a special behaviour
DispatchMessage will send message received to needed controls.
i.e Buttons click is only treated by clicked button.
Well, i added a Render() method too. Components needs to be rendered (pure virtual for CControl).
Well, here is class definition :
class CControl
{
public:
u16 X,Y;
u16 Width, Height;
CControl * Owner;
CControl(CControl * aOwner);
Observed Childrens;
bool Visible;
virtual ~CControl();
void ClearData();
virtual void ProcessMessage(tMessage msg);
virtual void DispatchToConcerned(tMessage msg);
virtual void Render() = 0;
virtual void DispatchMessage(tMessage msg);
};
Well, now i want to code a window. Simply a window where i’ll can put controls (a form).
class CWindow : public CControl
{
public:
CWindow(CControl * aOwner);
virtual void ProcessMessage(tMessage msg){};
virtual ~CWindow(){};
virtual void DispatchToConcerned(tMessage msg);
virtual void Render();
virtual void DrawWindow();
virtual void DispatchMessage(tMessage msg);
};
And now a button :
class CButton : public CControl
{
public:
CButton(CControl * aOwner);
virtual void ProcessMessage(tMessage msg);
virtual ~CButton(){};
virtual void Render();
std::string caption;
TFunctor * OnActivate;
TFunctor * OnClick;
};
Yes, you are pretty nice Octo, but what’s this TFunctor ??
Well, user will click on a button. The purpose of the operation is to call function when this happends. TFunctor is a base class wich will allow me to point to functions on any class using a TSpecificFunctor template.
Example :
CButton * ButtonClose = new CButton(this);
ButtonClose->X = 12;
ButtonClose->Y = 10;
ButtonClose->Height = 4;
ButtonClose->Width = 7;
this->Childrens.push_back(ButtonClose);
TSpecificFunctor * foncteur_close = new TSpecificFunctor(this, &CChatWindow::CloseButtonClick);
ButtonClose->OnClick = foncteur_close;
Well, now if ButtonClose is clicked (i’ll not show now internal system to Dispatch message ), CChatWindow::CloseButtonClick will be called.