Mercurial > LightClone
annotate LightClone/Source/World.cpp @ 18:33cb6979ac51
More work on GUI system
author | koryspansel |
---|---|
date | Wed, 14 Sep 2011 17:24:49 -0700 |
parents | 4951acfe92fc |
children | 51718795f019 |
rev | line source |
---|---|
7
31373c5bd1b9
Start on World refactor
koryspansel <koryspansel@bendbroadband.com>
parents:
diff
changeset
|
1 /* |
31373c5bd1b9
Start on World refactor
koryspansel <koryspansel@bendbroadband.com>
parents:
diff
changeset
|
2 * World |
31373c5bd1b9
Start on World refactor
koryspansel <koryspansel@bendbroadband.com>
parents:
diff
changeset
|
3 */ |
31373c5bd1b9
Start on World refactor
koryspansel <koryspansel@bendbroadband.com>
parents:
diff
changeset
|
4 |
31373c5bd1b9
Start on World refactor
koryspansel <koryspansel@bendbroadband.com>
parents:
diff
changeset
|
5 #include "World.h" |
9 | 6 #include "VertexTypes.h" |
17
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
7 #include "GuiLabel.h" |
7
31373c5bd1b9
Start on World refactor
koryspansel <koryspansel@bendbroadband.com>
parents:
diff
changeset
|
8 |
8 | 9 /* |
10 * World | |
11 */ | |
9 | 12 World::World() : kToolbar(8), kMain(16), kFunction(8), kControls(4) |
8 | 13 { |
9 | 14 nGameState = GameState_Active; |
15 nSimulationState = SimulationState_Idle; | |
16 pFunction = 0; | |
17 nCurrentFunction = 0; | |
18 nCurrentLevel = 0; | |
19 | |
20 kArrowBounds[0] = Rectangle2(1206.0f + 0 * 16.0f, 473.0f + 0 * 54.0f, 16.0f, 16.0f); | |
21 kArrowBounds[1] = Rectangle2(1206.0f + 2 * 16.0f, 473.0f + 0 * 54.0f, 16.0f, 16.0f); | |
22 | |
23 kDialog1Bounds[0] = Rectangle2(567.0f, 412.0f, 150.0f, 60.0f); | |
24 | |
25 kDialog2Bounds[0] = Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); | |
26 kDialog2Bounds[1] = Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); | |
27 | |
28 kToolbar.Add(1023.0f + 0 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f); | |
29 kToolbar.Add(1023.0f + 1 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f); | |
30 kToolbar.Add(1023.0f + 2 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f); | |
31 kToolbar.Add(1023.0f + 3 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f); | |
32 kToolbar.Add(1023.0f + 0 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f); | |
33 kToolbar.Add(1023.0f + 1 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f); | |
34 kToolbar.Add(1023.0f + 2 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f); | |
35 kToolbar.Add(1023.0f + 3 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f); | |
36 | |
37 kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f); | |
38 kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f); | |
39 kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f); | |
40 kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f); | |
41 kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f); | |
42 kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f); | |
43 kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f); | |
44 kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f); | |
45 kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f); | |
46 kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f); | |
47 kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f); | |
48 kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f); | |
49 kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f); | |
50 kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f); | |
51 kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f); | |
52 kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f); | |
53 | |
54 kFunction.Add(1023.0f + 0 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f); | |
55 kFunction.Add(1023.0f + 1 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f); | |
56 kFunction.Add(1023.0f + 2 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f); | |
57 kFunction.Add(1023.0f + 3 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f); | |
58 kFunction.Add(1023.0f + 0 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f); | |
59 kFunction.Add(1023.0f + 1 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f); | |
60 kFunction.Add(1023.0f + 2 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f); | |
61 kFunction.Add(1023.0f + 3 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f); | |
62 | |
63 kControls.Add(1023.0f + 0.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); | |
64 kControls.Add(1023.0f + 1.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); | |
65 kControls.Add(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); | |
8 | 66 } |
67 | |
68 /* | |
69 * Initialize | |
70 */ | |
14 | 71 ErrorCode World::Initialize(EventSystem* pSystem, ResourceManager* pResourceManager, InputManager* pInput) |
8 | 72 { |
73 ErrorCode eCode = Error_Fail; | |
74 | |
9 | 75 if(pResourceManager && pInput) |
8 | 76 { |
14 | 77 pEventSystem = pSystem; |
9 | 78 pInputManager = pInput; |
79 | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
80 eCode = kEnvironment.Initialize(pResourceManager); |
8 | 81 if(eCode == Error_Success) |
82 { | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
83 eCode = kBot.Initialize(pResourceManager); |
8 | 84 if(eCode == Error_Success) |
85 { | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
86 //eCode = kProgram.Initialize(pResourceManager); |
9 | 87 if(eCode == Error_Success) |
88 { | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
89 eCode = InitializeInterface(pResourceManager); |
9 | 90 if(eCode == Error_Success) |
91 { | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
92 nCurrentLevel = 0; |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
93 nGameState = GameState_LoadMap; |
9 | 94 } |
95 } | |
8 | 96 } |
97 } | |
98 } | |
99 | |
100 return eCode; | |
101 } | |
102 | |
103 /* | |
104 * Terminate | |
105 */ | |
106 void World::Terminate() | |
107 { | |
9 | 108 kInterface.Terminate(); |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
109 //kProgram.Terminate(); |
9 | 110 kBot.Terminate(); |
8 | 111 kEnvironment.Terminate(); |
112 } | |
113 | |
114 /* | |
9 | 115 * Activate |
116 */ | |
117 void World::Activate() | |
118 { | |
119 nGameState = GameState_LoadMap; | |
120 } | |
121 | |
122 /* | |
123 * Deactivate | |
124 */ | |
125 void World::Deactivate() | |
126 { | |
127 nGameState = GameState_Exit; | |
128 } | |
129 | |
130 /* | |
131 * IsActive | |
132 */ | |
133 bool World::IsActive() | |
134 { | |
135 return nGameState != GameState_Exit; | |
136 } | |
137 | |
138 /* | |
139 * Load | |
140 */ | |
141 bool World::Load(const char* pName) | |
142 { | |
143 ErrorCode eCode = kLoader.Load(pName); | |
144 if(eCode == Error_Success) | |
145 { | |
146 if(pFunction) | |
147 { | |
148 delete[] pFunction; | |
149 pFunction = NULL; | |
150 } | |
151 | |
152 const Size& kSize = kLoader.GetSize(); | |
153 | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
154 eCode = kEnvironment.Setup(kSize.X, kSize.Y); |
9 | 155 if(eCode == Error_Success) |
156 { | |
157 for(uint32 nY = 0; nY < kSize.Y; ++nY) | |
158 { | |
159 for(uint32 nX = 0; nX < kSize.X; ++nX) | |
160 { | |
161 kEnvironment.SetType(nX, nY, kLoader.GetTowerType(nX, nY)); | |
162 kEnvironment.SetAltitude(nX, nY, kLoader.GetTowerHeight(nX, nY)); | |
163 } | |
164 } | |
165 | |
166 kBot.Setup(&kEnvironment); | |
167 kBot.kPosition = kLoader.GetInitialPosition(); | |
168 kBot.kDirection = kLoader.GetInitialDirection(); | |
169 | |
170 const uint32 nCount = kLoader.GetFunctionCount(); | |
171 | |
172 pFunction = new Code[nCount + 1]; | |
173 pFunction[0].Initialize(MainFunctionLength); | |
174 pFunction[0].Clear(); | |
175 | |
176 for(uint32 i = 0; i < nCount; ++i) | |
177 { | |
178 const uint32 nLength = kLoader.GetFunctionLength(i); | |
179 | |
180 pFunction[i + 1].Initialize(nLength); | |
181 pFunction[i + 1].Clear(); | |
182 } | |
183 } | |
184 } | |
185 | |
186 return eCode == Error_Success; | |
187 } | |
188 | |
189 /* | |
190 * ResetEnvironment | |
191 */ | |
192 void World::ResetEnvironment() | |
193 { | |
194 kEnvironment.Reset(); | |
195 } | |
196 | |
197 /* | |
198 * ResetBot | |
199 */ | |
200 void World::ResetBot() | |
201 { | |
202 kBot.Reset(); | |
203 kBot.kPosition = kLoader.GetInitialPosition(); | |
204 kBot.kDirection = kLoader.GetInitialDirection(); | |
205 } | |
206 | |
207 /* | |
208 * ResetCode | |
209 */ | |
210 void World::ClearCode() | |
211 { | |
212 for(uint32 i = 0; i < kLoader.GetFunctionCount(); ++i) | |
213 { | |
214 pFunction[i].Clear(); | |
215 } | |
216 } | |
217 | |
218 /* | |
8 | 219 * Update |
220 */ | |
221 void World::Update(float fElapsed) | |
222 { | |
9 | 223 ProcessInput(fElapsed); |
224 | |
225 if(nGameState == GameState_LoadMap) | |
226 { | |
227 char kBuffer[256]; | |
228 sprintf_s(kBuffer, "Data\\Maps\\Map%02d.map", nCurrentLevel++); | |
229 | |
230 nGameState = Load(kBuffer) ? GameState_Active : GameState_Over; | |
231 } | |
232 else | |
233 | |
234 if(nGameState == GameState_Active) | |
235 { | |
236 if(nSimulationState == SimulationState_Active) | |
237 { | |
238 if(kBot.Update(fElapsed)) | |
239 { | |
240 if(kEnvironment.RequirementsMet()) | |
241 { | |
242 kDialog.Reset("Some message"); | |
243 kDialog.AddButton(DialogButton_Ok, "Ok", 0.0f, 0.0f, 0.0f, 0.0f); | |
244 | |
245 nGameState = GameState_Complete; | |
246 } | |
247 } | |
248 } | |
17
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
249 |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
250 kInterface.Update(fElapsed); |
9 | 251 } |
8 | 252 } |
253 | |
254 /* | |
255 * Render | |
256 */ | |
9 | 257 void World::Render(RenderContext& kContext) |
258 { | |
259 const uint32 nColor = D3DCOLOR_XRGB(32, 32, 32); | |
260 | |
261 kContext.Begin(nColor); | |
262 | |
263 if(nGameState >= GameState_Active) | |
264 { | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
265 kCameraController.SetMode(CameraMode_3D); |
9 | 266 Render3D(kContext); |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
267 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
268 kCameraController.SetMode(CameraMode_2D); |
9 | 269 Render2D(kContext); |
270 } | |
271 | |
272 kContext.End(); | |
273 } | |
274 | |
275 /* | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
276 * InitializeInterface |
9 | 277 */ |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
278 ErrorCode World::InitializeInterface(ResourceManager* pResourceManager) |
9 | 279 { |
17
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
280 GuiContainer* pRoot = kInterface.GetRoot(); |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
281 //ASSERT(pRoot != NULL); |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
282 |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
283 GuiLabel* |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
284 pLabel = new GuiLabel(); |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
285 pLabel->Initialize(pResourceManager); |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
286 pLabel->SetFont("Courier New", 16); |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
287 pLabel->SetText("This is a test!"); |
18 | 288 pLabel->SetFlags(GuiLabelFlag_CenterX | GuiLabelFlag_CenterY); |
17
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
289 pLabel->SetPosition(0.5f * ScreenSizeX, 0.5f * ScreenSizeY); |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
290 |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
291 pRoot->Add(pLabel); |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
292 |
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
293 //return kInterface.Initialize(pResourceManager); |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
294 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
295 /* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
296 GuiElement* pRoot = kInterface.GetRoot(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
297 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
298 //CodePanel* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
299 pToolbar = new CodePanel(8); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
300 pToolbar->SetBackgroundTexture("Data\\Textures\\CodePanel.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
301 pToolbar->SetSlotTexture("Data\\Textures\\Slot.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
302 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
303 //CodePanel* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
304 pMain = new CodePanel(16); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
305 pMain->SetBackgroundTexture("Data\\Textures\\CodePanel.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
306 pMain->SetSlotTexture("Data\\Textures\\Slot.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
307 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
308 //CodePanel* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
309 pFunctionA = new CodePanel(16); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
310 pFunctionA->SetBackgroundTexture("Data\\Textures\\CodePanel.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
311 pFunctionA->SetSlotTexture("Data\\Textures\\Slot.tga"); |
9 | 312 |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
313 //CodePanel* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
314 pFunctionB = new CodePanel(16); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
315 pFunctionB->SetBackgroundTexture("Data\\Textures\\CodePanel.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
316 pFunctionB->SetSlotTexture("Data\\Textures\\Slot.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
317 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
318 //SelectorPanel* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
319 pSelectorPanel = new SelectorPanel(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
320 pSelectorPanel->SetLeftTexture("Data\\Textures\\Left.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
321 pSelectorPanel->SetRightTexture("Data\\Textures\\Right.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
322 pSelectorPanel->Add(pFunctionA); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
323 pSelectorPanel->Add(pFunctionB); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
324 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
325 //GuiButton* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
326 pButtonStart = new GuiButton(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
327 pButtonStart->SetTexture("Data\\Textures\\Play.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
328 pButtonStart->SetDimensions(...); |
11
d80d06d5ff53
Begin working on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
10
diff
changeset
|
329 pButtonStart->SetCallback(&World::OnClick, this); |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
330 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
331 //GuiButton* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
332 pButtonStop = new GuiButton(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
333 pButtonStop->SetTexture("Data\\Textures\\Stop.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
334 pButtonStop->SetDimensions(...); |
11
d80d06d5ff53
Begin working on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
10
diff
changeset
|
335 pButtonStop->SetCallback(&World::OnClick, this); |
9 | 336 |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
337 //GuiButton* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
338 pButtonReset = new GuiButton(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
339 pButtonReset->SetTexture("Data\\Textures\\Reset.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
340 pButtonReset->SetDimensions(...); |
11
d80d06d5ff53
Begin working on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
10
diff
changeset
|
341 pButtonReset->SetCallback(&World::OnClick, this); |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
342 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
343 //GuiButton* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
344 pButtonExit = new GuiButton(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
345 pButtonExit->SetTexture("Data\\Textures\\Exit.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
346 pButtonExit->SetDimensions(...); |
11
d80d06d5ff53
Begin working on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
10
diff
changeset
|
347 pButtonExit->SetCallback(&World::OnClick, this); |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
348 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
349 //GuiPanel* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
350 pControlPanel = new GuiPanel(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
351 pControlPanel->SetTexture("Data\\Textures\\ControlPanel.tga") |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
352 pControlPanel->SetDimensions(...); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
353 pControlPanel->Add(pButtonStart); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
354 pControlPanel->Add(pButtonStop); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
355 pControlPanel->Add(pButtonReset); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
356 pControlPanel->Add(pButtonExit); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
357 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
358 //GuiDialog* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
359 pLevelDialog = new GuiDialog(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
360 pLevelDialog->AddButton(DialogButton_Ok, "Ok"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
361 pLevelDialog->SetVisible(false); |
9 | 362 |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
363 //GuiDialog* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
364 pGameDialog = new GuiDialog(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
365 pGameDialog->AddButton(DialogButton_Ok, "Ok"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
366 pGameDialog->SetVisible(false); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
367 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
368 //GuiDialog* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
369 pConfirmDialog = new GuiDialog(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
370 pConfirmDialog->AddButton(DialogButton_Yes, "Yes"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
371 pConfirmDialog->AddButton(DialogButton_No, "No"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
372 pConfirmDialog->SetVisible(false); |
9 | 373 |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
374 //GuiPanel* |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
375 pContainerPanel = new GuiPanel(); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
376 pContainerPanel->SetBackgroundTexture("Data\\Texturse\\ContainerPanel.tga"); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
377 pContainerPanel->Add(pToolbar); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
378 pContainerPanel->Add(pMain); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
379 pContainerPanel->Add(pSelectorPanel); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
380 pContainerPanel->Add(pControlPanel); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
381 |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
382 pRoot->Add(pControlPanel); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
383 pRoot->Add(pLevelDialog); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
384 pRoot->Add(pGameDialog); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
385 pRoot->Add(pConfirmDialog); |
17
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
386 */ |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
387 |
17
4951acfe92fc
Reworking GUI system
koryspansel <koryspansel@bendbroadband.com>
parents:
16
diff
changeset
|
388 return Error_Success; |
9 | 389 } |
390 | |
391 /* | |
392 * Render3D | |
393 */ | |
394 void World::Render3D(RenderContext& kContext) | |
395 { | |
10
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
396 kEnvironment.Render(kContext, kCameraController); |
292e534f00c2
Moved rendering into Bot/Environment; Started work on Gui system
koryspansel <koryspansel@bendbroadband.com>
parents:
9
diff
changeset
|
397 kBot.Render(kContext, kCameraController); |
9 | 398 } |
399 | |
400 /* | |
401 * Render2D | |
402 */ | |
403 void World::Render2D(RenderContext& kContext) | |
404 { | |
405 kInterface.Render(kContext, kCameraController); | |
406 } | |
407 | |
408 /* | |
409 * ProcessInput | |
410 */ | |
411 void World::ProcessInput(float fElapsed) | |
412 { | |
14 | 413 //pInputManager->Update(fElapsed); |
9 | 414 |
415 #if defined(_DEBUG) | |
416 if(pInputManager->IsKeyDown(DIK_LEFT)) | |
417 { | |
418 kCameraController.Yaw(0.01f); | |
419 } | |
420 else | |
421 | |
422 if(pInputManager->IsKeyDown(DIK_RIGHT)) | |
423 { | |
424 kCameraController.Yaw(-0.01f); | |
425 } | |
426 | |
427 if(pInputManager->IsKeyDown(DIK_UP)) | |
428 { | |
429 kCameraController.Pitch(0.01f); | |
430 } | |
431 else | |
432 | |
433 if(pInputManager->IsKeyDown(DIK_DOWN)) | |
434 { | |
435 kCameraController.Pitch(-0.01f); | |
436 } | |
437 | |
438 if(pInputManager->IsKeyDown(DIK_NEXT)) | |
439 { | |
440 kCameraController.Move(0.1f); | |
441 } | |
442 else | |
443 | |
444 if(pInputManager->IsKeyDown(DIK_PRIOR)) | |
445 { | |
446 kCameraController.Move(-0.1f); | |
447 } | |
448 #endif | |
449 | |
450 const float fMouseX = pInputManager->GetMouseX(); | |
451 const float fMouseY = pInputManager->GetMouseY(); | |
452 | |
453 if(nGameState == GameState_Active) | |
454 { | |
455 if(pInputManager->IsButtonDown(0) && !pInputManager->WasButtonDown(0)) | |
456 { | |
457 int32 nSelection = kControls.Pick(fMouseX, fMouseY); | |
458 if(nSelection >= 0) | |
459 { | |
460 if(nSelection == ControlButton_Play) | |
461 { | |
462 if(nSimulationState == SimulationState_Idle) | |
463 { | |
464 ResetBot(); | |
465 kBot.Upload(pFunction, kLoader.GetFunctionCount() + 1); | |
466 | |
467 nSimulationState = SimulationState_Active; | |
468 } | |
469 } | |
470 else | |
471 | |
472 if(nSelection == ControlButton_Stop) | |
473 { | |
474 if(nSimulationState == SimulationState_Active) | |
475 { | |
476 ResetEnvironment(); | |
477 ResetBot(); | |
478 | |
479 nSimulationState = SimulationState_Idle; | |
480 } | |
481 } | |
482 else | |
483 | |
484 if(nSelection == ControlButton_Exit) | |
485 { | |
486 nGameState = GameState_Exit; | |
487 } | |
488 } | |
489 else | |
490 { | |
491 // pick against the toolbar | |
492 nSelection = kToolbar.Pick(fMouseX, fMouseY); | |
493 if(nSelection >= 0) | |
494 { | |
495 kDragController.Begin(Action_Forward + nSelection); | |
496 } | |
497 else | |
498 { | |
499 // pick against the main pane | |
500 nSelection = kMain.Pick(fMouseX, fMouseY); | |
501 if(nSelection >= 0) | |
502 { | |
503 Code* pCode = pFunction; | |
504 if(!pCode->IsEmptySlot(nSelection)) | |
505 { | |
506 kDragController.Begin(pCode->GetSlot(nSelection)); | |
507 pCode->ClearSlot(nSelection); | |
508 } | |
509 } | |
510 else | |
511 { | |
512 // pick against the function pane | |
513 nSelection = kFunction.Pick(fMouseX, fMouseY); | |
514 if(nSelection >= 0) | |
515 { | |
516 Code* pCode = pFunction + nCurrentFunction + 1; | |
517 if(!pCode->IsEmptySlot(nSelection)) | |
518 { | |
519 kDragController.Begin(pCode->GetSlot(nSelection)); | |
520 pCode->ClearSlot(nSelection); | |
521 } | |
522 } | |
523 else | |
524 { | |
525 // pick against the function pane arrows | |
526 for(uint32 i = 0; i < sizeof(kArrowBounds) / sizeof(kArrowBounds[0]); ++i) | |
527 { | |
528 if(kArrowBounds[i].Contains(fMouseX, fMouseY)) | |
529 { | |
530 const uint32 nCount = kLoader.GetFunctionCount(); | |
531 nCurrentFunction = (nCurrentFunction + 2 * (int32)i - 1 + nCount) % nCount; | |
532 } | |
533 } | |
534 } | |
535 } | |
536 } | |
537 } | |
538 } | |
539 else | |
540 | |
541 if(!pInputManager->IsButtonDown(0) && pInputManager->WasButtonDown(0)) | |
542 { | |
543 if(kDragController.IsActive()) | |
544 { | |
545 const uint32 nAction = kDragController.End(); | |
546 | |
547 int32 nSelection = kMain.Pick(fMouseX, fMouseY); | |
548 if(nSelection >= 0) | |
549 { | |
550 pFunction[0].SetSlot(nSelection, nAction); | |
551 } | |
552 else | |
553 { | |
554 nSelection = kFunction.Pick(fMouseX, fMouseY); | |
555 if(nSelection >= 0) | |
556 { | |
557 pFunction[nCurrentFunction + 1].SetSlot(nSelection, nAction); | |
558 } | |
559 } | |
560 } | |
561 } | |
562 } | |
563 else | |
564 | |
565 if(nGameState == GameState_Complete) | |
566 { | |
567 if(pInputManager->IsButtonDown(0) && !pInputManager->WasButtonDown(0)) | |
568 { | |
569 for(uint32 i = 0; i < sizeof(kDialog1Bounds) / sizeof(kDialog1Bounds[0]); ++i) | |
570 { | |
571 if(kDialog1Bounds[i].Contains(fMouseX, fMouseY)) | |
572 { | |
573 if(i == 0) | |
574 { | |
575 if(nSimulationState == SimulationState_Active) | |
576 { | |
577 ResetEnvironment(); | |
578 ResetBot(); | |
579 | |
580 nSimulationState = SimulationState_Idle; | |
581 } | |
582 | |
583 nGameState = GameState_LoadMap; | |
584 } | |
585 } | |
586 } | |
587 | |
588 /* | |
589 int32 nSelection = kDialog.Pick(fMouseX, fMouseY); | |
590 | |
591 if(nSelection == DialogButton_A) | |
592 { | |
593 if(nSimulationState == SimulationState_Active) | |
594 { | |
595 ResetEnvironment(); | |
596 ResetBot(); | |
597 | |
598 nSimulationState = SimulationState_Idle; | |
599 } | |
600 | |
601 nGameState = GameState_LoadMap; | |
602 } | |
603 */ | |
604 } | |
605 } | |
606 else | |
607 | |
608 if(nGameState == GameState_Over) | |
609 { | |
610 // check to see if button was clicked | |
611 if(pInputManager->IsButtonDown(0) && !pInputManager->WasButtonDown(0)) | |
612 { | |
613 for(uint32 i = 0; i < sizeof(kDialog1Bounds) / sizeof(kDialog1Bounds[0]); ++i) | |
614 { | |
615 if(kDialog1Bounds[i].Contains(fMouseX, fMouseY)) | |
616 { | |
617 if(i == 0) | |
618 { | |
619 nCurrentLevel = 0; | |
620 nGameState = GameState_LoadMap; | |
621 } | |
622 } | |
623 } | |
624 | |
625 /* | |
626 int32 nSelection = kDialog.Pick(fMouseX, fMouseY); | |
627 | |
628 if(nSelection == DialogButton_A) | |
629 { | |
630 nCurrentLevel = 0; | |
631 nGameState = GameState_LoadMap; | |
632 } | |
633 */ | |
634 } | |
635 } | |
636 else | |
637 | |
638 if(nGameState == GameState_Confirm) | |
639 { | |
640 // check to see if button was clicked | |
641 if(pInputManager->IsButtonDown(0) && !pInputManager->WasButtonDown(0)) | |
642 { | |
643 for(uint32 i = 0; i < sizeof(kDialog2Bounds) / sizeof(kDialog2Bounds[0]); ++i) | |
644 { | |
645 if(kDialog2Bounds[i].Contains(fMouseX, fMouseY)) | |
646 { | |
647 if(i == 0) | |
648 { | |
649 nGameState = GameState_Exit; | |
650 } | |
651 else | |
652 | |
653 if(i == 1) | |
654 { | |
655 nGameState = GameState_Active; | |
656 } | |
657 } | |
658 } | |
659 | |
660 /* | |
661 int32 nSelection = kDialog.Pick(fMouseX, fMouseY); | |
662 | |
663 if(nSelection == DialogButton_A) | |
664 { | |
665 nGameState = GameState_Exit; | |
666 } | |
667 else | |
668 | |
669 if(nSelection == DialogButton_B) | |
670 { | |
671 nGameState = GameState_Active; | |
672 } | |
673 */ | |
674 } | |
675 } | |
676 } |