1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_CLIENT_COMPONENT_H
4#define GAME_CLIENT_COMPONENT_H
5
6#if defined(CONF_VIDEORECORDER)
7#include <engine/shared/video.h>
8#endif
9
10#include <engine/input.h>
11
12class CGameClient;
13
14/**
15* This class is inherited by all the client components.
16*
17* These components can implement the virtual methods such as OnInit(), OnMessage(int Msg, void *pRawMsg) to provide their functionality.
18*/
19class CComponent
20{
21protected:
22 friend class CGameClient;
23
24 CGameClient *m_pClient;
25
26 // perhaps propagate pointers for these as well
27
28 /**
29 * Get the kernel interface.
30 */
31 class IKernel *Kernel() const;
32 class IEngine *Engine() const;
33 /**
34 * Get the graphics interface.
35 */
36 class IGraphics *Graphics() const;
37 /**
38 * Get the text rendering interface.
39 */
40 class ITextRender *TextRender() const;
41 /**
42 * Get the input interface.
43 */
44 class IInput *Input() const;
45 /**
46 * Get the storage interface.
47 */
48 class IStorage *Storage() const;
49 /**
50 * Get the ui interface.
51 */
52 class CUi *Ui() const;
53 /**
54 * Get the sound interface.
55 */
56 class ISound *Sound() const;
57 /**
58 * Get the render tools interface.
59 */
60 class CRenderTools *RenderTools() const;
61 /**
62 * Get the config manager interface.
63 */
64 class IConfigManager *ConfigManager() const;
65 /**
66 * Get the config interface.
67 */
68 class CConfig *Config() const;
69 /**
70 * Get the console interface.
71 */
72 class IConsole *Console() const;
73 /**
74 * Get the demo player interface.
75 */
76 class IDemoPlayer *DemoPlayer() const;
77 /**
78 * Get the demo recorder interface.
79 *
80 * @param Recorder A member of the RECORDER_x enum
81 * @see RECORDER_MANUAL
82 * @see RECORDER_AUTO
83 * @see RECORDER_RACE
84 * @see RECORDER_REPLAYS
85 */
86 class IDemoRecorder *DemoRecorder(int Recorder) const;
87 class IFavorites *Favorites() const;
88 /**
89 * Get the server browser interface.
90 */
91 class IServerBrowser *ServerBrowser() const;
92 /**
93 * Get the layers interface.
94 */
95 class CLayers *Layers() const;
96 /**
97 * Get the collision interface.
98 */
99 class CCollision *Collision() const;
100#if defined(CONF_AUTOUPDATE)
101 /**
102 * Get the updater interface.
103 */
104 class IUpdater *Updater() const;
105#endif
106
107 /**
108 * Gets the current time.
109 * @see time_get()
110 */
111 int64_t time() const;
112
113 /**
114 * Gets the local time.
115 */
116 float LocalTime() const;
117
118 /**
119 * Get the http interface
120 */
121 class IHttp *Http() const;
122
123public:
124 /**
125 * The component virtual destructor.
126 */
127 virtual ~CComponent() {}
128 /**
129 * Gets the size of the non-abstract component.
130 */
131 virtual int Sizeof() const = 0;
132 /**
133 * Get a pointer to the game client.
134 */
135 class CGameClient *GameClient() const { return m_pClient; }
136 /**
137 * Get the client interface.
138 */
139 class IClient *Client() const;
140
141 /**
142 * This method is called when the client changes state, e.g from offline to online.
143 * @see IClient::STATE_CONNECTING
144 * @see IClient::STATE_LOADING
145 * @see IClient::STATE_ONLINE
146 */
147 virtual void OnStateChange(int NewState, int OldState){};
148 /**
149 * Called to let the components register their console commands.
150 */
151 virtual void OnConsoleInit(){};
152 /**
153 * Called to let the components run initialization code.
154 */
155 virtual void OnInit(){};
156 /**
157 * Called to cleanup the component.
158 * This method is called when the client is closed.
159 */
160 virtual void OnShutdown(){};
161 /**
162 * Called to reset the component.
163 * This method is usually called on your component constructor to avoid code duplication.
164 * @see CHud::CHud()
165 * @see CHud::OnReset()
166 */
167 virtual void OnReset(){};
168 /**
169 * Called when the window has been resized.
170 */
171 virtual void OnWindowResize() {}
172 /**
173 * Called when skins have been invalidated and must be updated.
174 */
175 virtual void OnRefreshSkins() {}
176 /**
177 * Called when the component should get rendered.
178 *
179 * The render order depends on the component insertion order.
180 */
181 virtual void OnRender(){};
182 /**
183 * Called when a new snapshot is received.
184 */
185 virtual void OnNewSnapshot(){};
186 /**
187 * Called when the input gets released, for example when a text box loses focus.
188 */
189 virtual void OnRelease(){};
190 /**
191 * Called on map load.
192 */
193 virtual void OnMapLoad(){};
194 /**
195 * Called when receiving a network message.
196 * @param Msg The message type.
197 * @param pRawMsg The message data.
198 * @see NETMSGTYPE_SV_DDRACETIME
199 * @see CNetMsg_Sv_DDRaceTime
200 */
201 virtual void OnMessage(int Msg, void *pRawMsg) {}
202 /**
203 * Called on mouse movement, where the x and y values are deltas.
204 *
205 * @param x The amount of change in the x coordinate since the last call.
206 * @param y The amount of change in the y coordinate since the last call.
207 * @param CursorType The type of cursor that caused the movement.
208 */
209 virtual bool OnCursorMove(float x, float y, IInput::ECursorType CursorType) { return false; }
210 /**
211 * Called on a input event.
212 * @param Event The input event.
213 */
214 virtual bool OnInput(const IInput::CEvent &Event) { return false; }
215};
216
217#endif
218