1 | #include "dxstdafx.h"
|
---|
2 | #include ".\HUDRenderer.h"
|
---|
3 | #include "GameManager.h"
|
---|
4 | #include "UserPlayer.h"
|
---|
5 | #include "HUD.h"
|
---|
6 |
|
---|
7 | extern bool GLOBAL_display_help_screenQ;
|
---|
8 |
|
---|
9 |
|
---|
10 | HUDRenderer::HUDRenderer(void) : Renderer()
|
---|
11 | {
|
---|
12 | this->setRenderPriority(300);
|
---|
13 | this->rendererType |= Renderer::RENDERER_HUD;
|
---|
14 | this->sprite = NULL;
|
---|
15 | }
|
---|
16 |
|
---|
17 | HUDRenderer::~HUDRenderer(void)
|
---|
18 | {
|
---|
19 | SAFE_RELEASE(this->myFont);
|
---|
20 | SAFE_RELEASE(sprite);
|
---|
21 | this->myFont = NULL;
|
---|
22 | this->sprite = NULL;
|
---|
23 | }
|
---|
24 |
|
---|
25 | void HUDRenderer::init() {
|
---|
26 | // Create a D3DX font object
|
---|
27 | this->setRenderPriority(60);
|
---|
28 | D3DXCreateSprite(DXUTGetD3DDevice(),&sprite);
|
---|
29 | D3DXCreateFont( this->device, 26, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &myFont );
|
---|
30 | fontColor = D3DCOLOR_ARGB(255,255,255,255);
|
---|
31 | SetRect(&textRectangle, 0, this->myScene->manager->screenHeight-200, this->myScene->manager->screenWidth, this->myScene->manager->screenHeight);
|
---|
32 | SetRect(&timeRectangle, 0, this->myScene->manager->screenHeight-100, this->myScene->manager->screenWidth - 20, this->myScene->manager->screenHeight);
|
---|
33 | SetRect(&ammoRectangle, 0, this->myScene->manager->screenHeight-60, this->myScene->manager->screenWidth - 20, this->myScene->manager->screenHeight);
|
---|
34 | SetRect(&helpRectangle, 10, this->myScene->manager->screenHeight-500, this->myScene->manager->screenWidth - 20, this->myScene->manager->screenHeight);
|
---|
35 |
|
---|
36 |
|
---|
37 | }
|
---|
38 |
|
---|
39 | void HUDRenderer::render()
|
---|
40 | {
|
---|
41 | if(this->myScene->getActivePassId()==Scene::PASS_NORMAL) {
|
---|
42 | this->device->BeginScene();
|
---|
43 | SPTR<Node> node = this->myNode.lock();
|
---|
44 | HUD *hud = (HUD *) (node.get());
|
---|
45 | if(hud!=NULL) {
|
---|
46 | //disable z buffer:
|
---|
47 | this->device->SetRenderState(D3DRS_ZENABLE, FALSE);
|
---|
48 |
|
---|
49 | // get the scene in order to receive players
|
---|
50 | GameScene* gs = (GameScene*)(this->myScene);
|
---|
51 | //get the sprite:
|
---|
52 | //LPD3DXSPRITE sprite = *hud->getSprite();
|
---|
53 | //create scale/rotate matrices
|
---|
54 | D3DXMATRIX mat;
|
---|
55 | D3DXMATRIX mat2;
|
---|
56 | //create surface descriptor
|
---|
57 | D3DSURFACE_DESC desc;
|
---|
58 | D3DSURFACE_DESC desc2;
|
---|
59 |
|
---|
60 | //draw crosshair:
|
---|
61 | hud->Textures[0]->GetLevelDesc(0, &desc); //get texture size
|
---|
62 | //calculate transfomation:
|
---|
63 | D3DXVECTOR3 center((FLOAT)desc.Width/2, (FLOAT)desc.Height/2, 0);
|
---|
64 | D3DXVECTOR2 trans((float)(this->myScene->getMousePos()[0]),(float)(this->myScene->getMousePos()[1]));
|
---|
65 | D3DXVECTOR2 scaling(hud->getScaleCrosshairX(),hud->getScaleCrosshairY());
|
---|
66 | //set matrix:
|
---|
67 | D3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling,NULL,0,&trans);
|
---|
68 | sprite->SetTransform(&mat);
|
---|
69 | //draw crosshair:
|
---|
70 | sprite->Begin(D3DXSPRITE_ALPHABLEND);
|
---|
71 | sprite->Draw(hud->Textures[0], NULL, ¢er, NULL, 0xFFFFFFFF);
|
---|
72 |
|
---|
73 | //draw radar:
|
---|
74 | hud->Textures[1]->GetLevelDesc(0, &desc); //get texture size
|
---|
75 | //calculate transfomation:
|
---|
76 | D3DXVECTOR2 rotPoint((FLOAT)desc.Width/2*hud->getScaleRadarX() + hud->getRadarOffsetX(), (FLOAT) this->myScene->manager->screenHeight - (desc.Height/2*hud->getScaleRadarY() + hud->getRadarOffsetY()));
|
---|
77 | trans = D3DXVECTOR2(rotPoint.x - (FLOAT)(gs->player->getPosition().x/this->myScene->getWidth()*desc.Width*hud->getScaleRadarX()),rotPoint.y - (FLOAT)(desc.Height*hud->getScaleRadarY() - (gs->player->getPosition().z/this->myScene->getDepth()*desc.Height*hud->getScaleRadarY())));
|
---|
78 | D3DXVECTOR2 trans2(trans.x, trans.y);
|
---|
79 | scaling = D3DXVECTOR2(hud->getScaleRadarX(),hud->getScaleRadarY());
|
---|
80 | float rotation = -(gs->player->myRotation.y);
|
---|
81 | //reset matrix:
|
---|
82 | D3DXMatrixIdentity(&mat);
|
---|
83 | D3DXMatrixIdentity(&mat2);
|
---|
84 | D3DXMATRIX res;
|
---|
85 | D3DXMatrixTransformation2D(&mat,0,0.0,&scaling,0,0.0f,&trans);
|
---|
86 | D3DXMatrixTransformation2D(&mat2,0,0.0,0,&rotPoint,rotation,0);
|
---|
87 | D3DXMatrixMultiply(&res, &mat, &mat2);
|
---|
88 | sprite->SetTransform(&res);
|
---|
89 | //draw radar:
|
---|
90 | sprite->Draw(hud->Textures[1], NULL, 0, 0, 0xFFFFFFFF);
|
---|
91 |
|
---|
92 | //draw ai players (enemies)
|
---|
93 | hud->Textures[2]->GetLevelDesc(0, &desc2); //get texture size
|
---|
94 | //calculate location:
|
---|
95 | center = D3DXVECTOR3((FLOAT)desc2.Width/2, (FLOAT)desc2.Height/2, 0);
|
---|
96 | //get list:
|
---|
97 | std::list<SPTR<Node> > *playerList = ((GameScene *)this->myScene)->getPlayerList();
|
---|
98 | std::list<SPTR<Node> >::iterator it;
|
---|
99 | Player *activeOpponent = NULL;
|
---|
100 | for(it=playerList->begin();it!=playerList->end();it++) {
|
---|
101 | activeOpponent = ((Player *) (*it).get());
|
---|
102 | if(activeOpponent != (Player *)gs->player) {
|
---|
103 | trans = D3DXVECTOR2(trans2.x + activeOpponent->getPosition().x/this->myScene->getWidth()*desc.Width*hud->getScaleRadarX(), trans2.y + (desc.Height*hud->getScaleRadarY() - (activeOpponent->getPosition().z/this->myScene->getDepth()*desc.Height*hud->getScaleRadarY())));
|
---|
104 | //reset matrix:
|
---|
105 | D3DXMatrixIdentity(&mat);
|
---|
106 | D3DXMatrixIdentity(&mat2);
|
---|
107 | D3DXMATRIX res;
|
---|
108 | D3DXMatrixTransformation2D(&mat,0,0.0,0,0,0.0f,&trans);
|
---|
109 | D3DXMatrixTransformation2D(&mat2,0,0.0,0,&rotPoint,rotation,0);
|
---|
110 | D3DXMatrixMultiply(&res, &mat, &mat2);
|
---|
111 | sprite->SetTransform(&res);
|
---|
112 | //draw player:
|
---|
113 | sprite->Draw(hud->Textures[2], NULL, ¢er, NULL, 0xFF0000FF);
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | //draw player:
|
---|
118 | trans = D3DXVECTOR2((FLOAT)(desc.Width/2*hud->getScaleRadarX() + hud->getRadarOffsetX()),(FLOAT) this->myScene->manager->screenHeight - (desc.Height/2*hud->getScaleRadarY() + hud->getRadarOffsetY()));
|
---|
119 | //reset matrix:
|
---|
120 | D3DXMatrixIdentity(&mat);
|
---|
121 | D3DXMatrixTransformation2D(&mat,0,0.0,0,0,0,&trans);
|
---|
122 | sprite->SetTransform(&mat);
|
---|
123 | //draw player:
|
---|
124 | sprite->Draw(hud->Textures[2], NULL, ¢er, NULL, 0xFFFF0000);
|
---|
125 |
|
---|
126 | //draw human player health logo & health bar:
|
---|
127 | hud->Textures[3]->GetLevelDesc(0, &desc); //get texture size
|
---|
128 | hud->Textures[4]->GetLevelDesc(0, &desc2);
|
---|
129 | float offset = 20;
|
---|
130 | RECT rectangle;
|
---|
131 | float health = gs->player->getHealth();
|
---|
132 | if(health>100.0f) {
|
---|
133 | this->myScene->manager->printToConsole("Health over 100 percent!!!!");
|
---|
134 | health = 100.0f;
|
---|
135 | }
|
---|
136 | if (health<0.0f) {
|
---|
137 | this->myScene->manager->printToConsole("Health under 0 percent!!!!");
|
---|
138 | health = 0.0f;
|
---|
139 | }
|
---|
140 | SetRect(&rectangle, 0, 0, (int)(desc2.Width*health/100), (int)(desc2.Height));
|
---|
141 | scaling = D3DXVECTOR2(hud->getScaleUserPlayer(),hud->getScaleUserPlayer());
|
---|
142 | //reset matrix:
|
---|
143 | D3DXMatrixIdentity(&mat);
|
---|
144 | D3DXMatrixTransformation2D(&mat,0,0.0,&scaling,0,0.0f,0);
|
---|
145 | sprite->SetTransform(&mat);
|
---|
146 | //set logo position:
|
---|
147 | D3DXVECTOR3 pos (offset,offset,0.0f);
|
---|
148 | //draw health logo:
|
---|
149 | sprite->Draw(hud->Textures[3], NULL, NULL, &pos, 0xFFFFFFFF);
|
---|
150 | //set bar position:
|
---|
151 | pos = D3DXVECTOR3(offset + desc.Width + offset, offset, 0);
|
---|
152 | sprite->Draw(hud->Textures[4], &rectangle, NULL, &pos, 0xFFFFFFFF);
|
---|
153 |
|
---|
154 | //draw ai players health logos & health bars:
|
---|
155 | hud->Textures[5]->GetLevelDesc(0, &desc); //get texture size
|
---|
156 | hud->Textures[6]->GetLevelDesc(0, &desc2); //get texture size
|
---|
157 | //scale according to xml settings
|
---|
158 | scaling = D3DXVECTOR2(hud->getScaleAIPlayer(),hud->getScaleAIPlayer());
|
---|
159 | D3DXVECTOR2 scalepos((float)this->myScene->manager->screenWidth, 0);
|
---|
160 | D3DXMatrixIdentity(&mat);
|
---|
161 | D3DXMatrixTransformation2D(&mat,&scalepos,0.0,&scaling,0,0.0f,0);
|
---|
162 | sprite->SetTransform(&mat);
|
---|
163 | //draw info for alle opponents:
|
---|
164 | float sum = offset;
|
---|
165 | for(it=playerList->begin();it!=playerList->end();it++) {
|
---|
166 | activeOpponent = ((Player *) (*it).get());
|
---|
167 | if(activeOpponent != (Player *)gs->player) {
|
---|
168 | //set logo position:
|
---|
169 | pos = D3DXVECTOR3((float)this->myScene->manager->screenWidth - desc.Width - offset,sum,0);
|
---|
170 | //draw logo:
|
---|
171 | sprite->Draw(hud->Textures[5], NULL, NULL, &pos, 0xFFFFFFFF);
|
---|
172 | //set health bar position:
|
---|
173 | health = activeOpponent->getHealth();
|
---|
174 | if(health>100.0f) {
|
---|
175 | this->myScene->manager->printToConsole("Health over 100 percent!!!!");
|
---|
176 | health = 100.0f;
|
---|
177 | }
|
---|
178 | if (health<0.0f) {
|
---|
179 | this->myScene->manager->printToConsole("Health under 0 percent!!!!");
|
---|
180 | health = 0.0f;
|
---|
181 | }
|
---|
182 | SetRect(&rectangle, (int)(desc2.Width - desc2.Width*health/100), 0, (int)desc2.Width, (int)(desc2.Height));
|
---|
183 | pos = D3DXVECTOR3((float)this->myScene->manager->screenWidth - desc.Width - 2*offset - desc2.Width + (int)(desc2.Width - desc2.Width*health/100),sum, 0);
|
---|
184 | //draw health bar:
|
---|
185 | sprite->Draw(hud->Textures[6], &rectangle, NULL, &pos, 0xFFFFFFFF);
|
---|
186 | //next player position:
|
---|
187 | sum += desc.Width + offset;
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | //reset matrix:
|
---|
192 | D3DXMatrixIdentity(&mat);
|
---|
193 | sprite->SetTransform(&mat);
|
---|
194 |
|
---|
195 | //time output:
|
---|
196 | std::ostringstream ostr;
|
---|
197 | ostr.str("");
|
---|
198 | ostr << "Time left: ";
|
---|
199 | ostr << hud->minutes;
|
---|
200 | ostr << " min ";
|
---|
201 | ostr << hud->seconds;
|
---|
202 | ostr << " sec";
|
---|
203 | std::string temp = ostr.str();
|
---|
204 | std::wstring time(temp.begin(), temp.end());
|
---|
205 | myFont->DrawText(sprite, time.c_str(), -1, &timeRectangle, DT_RIGHT, fontColor);
|
---|
206 |
|
---|
207 | //ammunition output:
|
---|
208 | ostr.str("");
|
---|
209 | ostr << "Ammo: ";
|
---|
210 | ostr << hud->ammoAmount;
|
---|
211 | temp = ostr.str();
|
---|
212 | std::wstring ammo(temp.begin(), temp.end());
|
---|
213 | myFont->DrawText(sprite, ammo.c_str(), -1, &ammoRectangle, DT_RIGHT, fontColor);
|
---|
214 |
|
---|
215 | //message output:
|
---|
216 | #if(0)
|
---|
217 | // display message for messagethreshold period of time
|
---|
218 | if (hud->messagetimer < hud->messagethreshold) {
|
---|
219 | hud->messagetimer += hud->messagedt;
|
---|
220 | if(!hud->bHelp) {
|
---|
221 | myFont->DrawText(sprite, hud->messagestring.c_str(), -1, &textRectangle, DT_CENTER | DT_WORDBREAK, fontColor);
|
---|
222 | }
|
---|
223 | else {
|
---|
224 | myFont->DrawText(sprite, hud->messagestring.c_str(), -1, &helpRectangle, DT_LEFT | DT_WORDBREAK, fontColor);
|
---|
225 | }
|
---|
226 | }
|
---|
227 | #elif(1) // MG
|
---|
228 | // F1 toggles help screen display
|
---|
229 | if (hud->messagetimer < hud->messagethreshold) {
|
---|
230 | hud->messagetimer += hud->messagedt;
|
---|
231 | }
|
---|
232 |
|
---|
233 | if(GLOBAL_display_help_screenQ) {
|
---|
234 | myFont->DrawText(sprite, this->myScene->manager->HelpScreenString_Get().c_str(), -1, &helpRectangle, DT_LEFT | DT_WORDBREAK, fontColor);
|
---|
235 | }
|
---|
236 | else {
|
---|
237 | // No help screen active => display message (if active)
|
---|
238 | if (hud->messagetimer < hud->messagethreshold) {
|
---|
239 | myFont->DrawText(sprite, hud->messagestring.c_str(), -1, &textRectangle, DT_CENTER | DT_WORDBREAK, fontColor);
|
---|
240 | }
|
---|
241 | }
|
---|
242 | #endif
|
---|
243 |
|
---|
244 | //you win output:
|
---|
245 | if (hud->youwintimer < hud->youwinthreshold) {
|
---|
246 | hud->youwintimer += hud->youwindt;
|
---|
247 | //now draw the you win stuff:
|
---|
248 | std::list<HUD::Letter>::iterator iter;
|
---|
249 | for(UINT i = 0; i < hud->YouWin.size(); i++) {
|
---|
250 | HUD::Letter *tempLetter = &hud->YouWin.at(i);
|
---|
251 | scaling = D3DXVECTOR2(tempLetter->scale,tempLetter->scale);
|
---|
252 | scalepos = D3DXVECTOR2(tempLetter->x - tempLetter->centerX,tempLetter->y - tempLetter->centerY);
|
---|
253 | rotPoint = D3DXVECTOR2(tempLetter->x,tempLetter->y);
|
---|
254 | rotation = hud->youwintimer * tempLetter->rotation;
|
---|
255 | D3DXMatrixIdentity(&mat);
|
---|
256 | D3DXMatrixTransformation2D(&mat,&scalepos,0.0,&scaling,&rotPoint,rotation,0);
|
---|
257 | sprite->SetTransform(&mat);
|
---|
258 | pos = D3DXVECTOR3(tempLetter->x, tempLetter->y, 0);
|
---|
259 | center = D3DXVECTOR3((FLOAT)tempLetter->centerX, (FLOAT)tempLetter->centerY, 0);
|
---|
260 | sprite->Draw(tempLetter->texture, NULL, ¢er, &pos, 0xFFFFFFFF);
|
---|
261 | }
|
---|
262 | }
|
---|
263 | //you lose output:
|
---|
264 | if (hud->youlosetimer < hud->youlosethreshold) {
|
---|
265 | hud->youlosetimer += hud->youlosedt;
|
---|
266 | //now draw the you lose stuff:
|
---|
267 | std::list<HUD::Letter>::iterator iter;
|
---|
268 | for(UINT i = 0; i < hud->YouLose.size(); i++) {
|
---|
269 | HUD::Letter *tempLetter = &hud->YouLose.at(i);
|
---|
270 | scaling = D3DXVECTOR2(tempLetter->scale,tempLetter->scale);
|
---|
271 | scalepos = D3DXVECTOR2(tempLetter->x - tempLetter->centerX,tempLetter->y - tempLetter->centerY);
|
---|
272 | rotPoint = D3DXVECTOR2(tempLetter->x,tempLetter->y);
|
---|
273 | rotation = hud->youlosetimer * tempLetter->rotation;
|
---|
274 | D3DXMatrixIdentity(&mat);
|
---|
275 | D3DXMatrixTransformation2D(&mat,&scalepos,0.0,&scaling,&rotPoint,rotation,0);
|
---|
276 | sprite->SetTransform(&mat);
|
---|
277 | pos = D3DXVECTOR3(tempLetter->x, tempLetter->y, 0);
|
---|
278 | center = D3DXVECTOR3((FLOAT)tempLetter->centerX, (FLOAT)tempLetter->centerY, 0);
|
---|
279 | sprite->Draw(tempLetter->texture, NULL, ¢er, &pos, 0xFFFFFFFF);
|
---|
280 | }
|
---|
281 | }
|
---|
282 |
|
---|
283 | //toasted output:
|
---|
284 | if (hud->toastedtimer < hud->toastedthreshold) {
|
---|
285 | hud->toastedtimer += hud->toasteddt;
|
---|
286 | //now draw the you lose stuff:
|
---|
287 | std::list<HUD::Letter>::iterator iter;
|
---|
288 | for(UINT i = 0; i < hud->Toasted.size(); i++) {
|
---|
289 | HUD::Letter *tempLetter = &hud->Toasted.at(i);
|
---|
290 | scaling = D3DXVECTOR2(tempLetter->scale,tempLetter->scale);
|
---|
291 | scalepos = D3DXVECTOR2(tempLetter->x - tempLetter->centerX,tempLetter->y - tempLetter->centerY);
|
---|
292 | rotPoint = D3DXVECTOR2(tempLetter->x,tempLetter->y);
|
---|
293 | rotation = hud->toastedtimer * tempLetter->rotation;
|
---|
294 | D3DXMatrixIdentity(&mat);
|
---|
295 | D3DXMatrixTransformation2D(&mat,&scalepos,0.0,&scaling,&rotPoint,rotation,0);
|
---|
296 | sprite->SetTransform(&mat);
|
---|
297 | pos = D3DXVECTOR3(tempLetter->x, tempLetter->y, 0);
|
---|
298 | center = D3DXVECTOR3((FLOAT)tempLetter->centerX, (FLOAT)tempLetter->centerY, 0);
|
---|
299 | sprite->Draw(tempLetter->texture, NULL, ¢er, &pos, 0xFFFFFFFF);
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | sprite->End();
|
---|
304 |
|
---|
305 | //deactivate textures
|
---|
306 | this->device->SetTexture(0, 0);
|
---|
307 |
|
---|
308 | //enable z buffer:
|
---|
309 | this->device->SetRenderState(D3DRS_ZENABLE, TRUE);
|
---|
310 | }
|
---|
311 | this->device->EndScene();
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | void HUDRenderer::OnLostDevice( void* pUserContext )
|
---|
316 | {
|
---|
317 | this->myFont->OnLostDevice();
|
---|
318 | this->sprite->OnLostDevice();
|
---|
319 | }
|
---|
320 |
|
---|
321 | void HUDRenderer::OnDestroyDevice( void* pUserContext )
|
---|
322 | {
|
---|
323 | SAFE_RELEASE(this->myFont);
|
---|
324 | SAFE_RELEASE(sprite);
|
---|
325 | this->myFont = NULL;
|
---|
326 | this->sprite = NULL;
|
---|
327 | }
|
---|
328 |
|
---|
329 | HRESULT HUDRenderer::OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
|
---|
330 | {
|
---|
331 | this->device = pd3dDevice;
|
---|
332 | D3DXCreateSprite(this->device,&sprite);
|
---|
333 | D3DXCreateFont( this->device, 26, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &myFont );
|
---|
334 | fontColor = D3DCOLOR_ARGB(255,255,255,255);
|
---|
335 | return S_OK;
|
---|
336 | }
|
---|
337 |
|
---|
338 | bool HUDRenderer::isLowerThan(Renderer* renderer)
|
---|
339 | {
|
---|
340 | //Unter der Annahme, dass es kein zweites HUD gibt!
|
---|
341 | return this->getRenderPriority() < renderer->getRenderPriority();
|
---|
342 | }
|
---|