-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.h
179 lines (164 loc) · 7.22 KB
/
State.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//State.h
#ifndef NEOGUI_STATE_H
#define NEOGUI_STATE_H
#include <Lua/lua.hpp>
#include <sdlObjects/TextureManager.h>
#include <sdlObjects/ObjectManager.h>
#include <antXml/antXml.h>
#include "Bind.h"
#include "Button.h"
#include "Dialog.h"
#include "Frame.h"
#include "List.h"
#include "Message.h"
#include "Paragraph.h"
#include "Slider.h"
#include "StatusBar.h"
using namespace sdlUtility;
namespace sdlGUI {
namespace Lists {
static const int Binds = 1;
static const int Buttons = 2;
static const int Dialogs = 3;
static const int Frames = 4;
static const int Lists = 5;
static const int Messages = 6;
static const int Paragraphs = 7;
static const int Sliders = 8;
static const int StatusBars = 9;
}
namespace Events {
static const int DebugFocusChanged = 1000;
}
class State: public sdlObjects::ObjectManager<Element> {
//Members
protected:
bool ScaleMode;
std::map<std::string, bool> AddOnRequirements;
std::map< std::string, std::vector<std::string> > FontIndex;
std::map< std::string, std::string > StateIndex;
sdlObjects::List<std::string, Bind, Element> Binds;
sdlObjects::List<std::string, Button, Element> Buttons;
sdlObjects::List<std::string, Dialog, Element> Dialogs;
sdlObjects::List<std::string, Frame, Element> Frames;
sdlObjects::List<std::string, List, Element> Lists;
sdlObjects::List<std::string, Message, Element> Messages;
sdlObjects::List<std::string, Paragraph, Element> Paragraphs;
sdlObjects::List<std::string, Slider, Element> Sliders;
sdlObjects::List<std::string, StatusBar, Element> StatusBars;
Element *Focus;
Frame Interface;
sdlObjects::TextureManager TextureManager;
Vector2 CursorPosition;
SDL_Cursor *Cursor;
//Access Methods
public:
State(lua_State *Lua);
~State();
template <class Type> void Get(Type *&Object, std::string ID);
std::string GetElementClass(std::string ID);
Vector2 &GetCursorPosition();
Element *GetFocus(bool State = false);
sdlObjects::TextureManager *GetTextureManager();
bool IsShown();
//Process Methods
public:
void BrowseTextboxes();
void ClearState();
void DisableKeyBindings();
void EnableKeyBindings();
void Hide();
int Input(SDL_Event &Event);
void Initialize(std::string AssetsDirectory, std::string GraphicsDirectory, std::string UserDirectory);
void MakeElement(int List, std::string AddOn, std::string Name, std::string ParentName);
void LoadAddOnData(std::string AddOn);
void LoadCursor(std::string Name);
void LoadParagraphText(std::string ID, std::string Text);
void LoadState(std::string Location);
void Process();
void ReloadState();
void RemoveElement(int List, std::string ID);
void Render(float Interpolation);
void ResetInput();
void SaveAddOnData(std::string AddOn, std::string SaveData);
void SetElementFont(std::string ID, std::string FontID);
void SetFocus(std::string ID, bool State = false);
void SetResolution(int Width, int Height);
void SetScale(float ScaleX, float ScaleY);
void SetScaleMode(bool ScaleMode);
void SetElementTexture(std::string ID, std::string TextureID);
void Show();
void Toggle();
void Who();
protected:
bool ElementAllowsDebug(Element *Element);
void GetSharedAttributes(antXml::Tag &Tag, Element *Element);
void GetSpecificAttributes(antXml::Tag &Tag, std::vector<std::string> &Data);
void HandleEvents();
template <class IDType, class Type, class InheritedType> void HandleListEvents(sdlObjects::List<IDType, Type, InheritedType> &List);
int InputFocus(SDL_Event &Event);
template <class IDType, class Type, class InheritedType> int InputList(sdlObjects::List<IDType, Type, InheritedType> &List, SDL_Event &Event, InheritedType *Parent = NULL);
int InputRelatedTo(Element *Parent, SDL_Event &Event);
void Load(std::string Name, Element *Parent = NULL, bool Embedded = false);
void LoadElement(Element *Element, antXml::Tag &Tag);
void LoadFontIndex(std::string Path);
void LoadStateIndex(std::string Path);
void LoadTextureIndex(std::string Path);
void MakeElement(int List, std::string AddOn, std::string Name, Element *Parent = NULL);
template <class IDType, class Type, class InheritedType> void ProcessList(sdlObjects::List<IDType, Type, InheritedType> &List, InheritedType *Parent = NULL);
void ProcessRelatedTo(Element *Parent);
void PushElementCallback(Element *Element, std::string Function);
void ReloadMessageTextures();
bool Remove(Element *Target);
void RemoveRelatedTo(Element *Parent);
template <class IDType, class Type, class InheritedType> void RenderList(float Interpolation, sdlObjects::List<IDType, Type, InheritedType> &List, InheritedType *Parent = NULL);
void RenderRelatedTo(Element *Parent, float Interpolation);
void ResetAllExcept(int List, Element *Parent = NULL);
void ResetRelatedTo(Element *Parent);
void SetFocus(Element *Object, bool State = false);
void SetParagraphFont(Paragraph *Paragraph, std::string FontID);
void SetMessageFont(Message *Message, std::string FontID);
void SetMessageFont(Message *Message, std::vector<std::string> &Data);
};
template <>
inline void State::Get(Bind *&Bind, std::string ID) {
Bind = Binds[ID];
}
template <>
inline void State::Get(Button *&Button, std::string ID) {
Button = Buttons[ID];
}
template <>
inline void State::Get(Dialog *&Dialog, std::string ID) {
Dialog = Dialogs[ID];
}
template <>
inline void State::Get(Frame *&Frame, std::string ID) {
if (ID == "Interface.Interface") Frame = &this->Interface; else Frame = Frames[ID];
}
template <>
inline void State::Get(List *&List, std::string ID) {
List = Lists[ID];
}
template <>
inline void State::Get(Message *&Message, std::string ID) {
Message = Messages[ID];
}
template <>
inline void State::Get(Paragraph *&Paragraph, std::string ID) {
Paragraph = Paragraphs[ID];
}
template <>
inline void State::Get(Slider *&Slider, std::string ID) {
Slider = Sliders[ID];
}
template <>
inline void State::Get(StatusBar *&StatusBar, std::string ID) {
StatusBar = StatusBars[ID];
}
template <>
inline void State::Get(Element *&Element, std::string ID) {
if (ID == "Interface.Interface") Element = &this->Interface; else Element = Objects[ID];
}
}
#endif