source: GTP/trunk/App/Games/Jungle_Rumble/src/MenueScene.cpp @ 1395

Revision 1395, 11.3 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - Fontsize fix 1 (Michael)

Line 
1#include "dxstdafx.h"
2#include ".\menuescene.h"
3#include ".\GameManager.h"
4
5MenueScene::MenueScene(void) : Scene()
6{
7        this->lightSetted = false;
8        this->usePhysXDebugger = false;
9        this->bgSoundChannel = -1;
10        this->bgSoundVolume = 1.0f;
11        this->menuestatus = MENU_IDLE;
12        this->soundStopped = false;
13}
14
15MenueScene::~MenueScene(void)
16{
17        this->sprite->Release();
18        this->clearScene();
19}
20
21void MenueScene::clearScene()
22{
23        Scene::clearScene();
24}
25
26void MenueScene::initScene(GameManager &_manager) {
27       
28        Scene::initScene(_manager);
29       
30        this->activeChallengeNumber = -1;
31        this->selectedChallengeNumber = -1;
32       
33        //create sprite:
34        D3DXCreateSprite(DXUTGetD3DDevice(),&sprite);
35
36        //load background texture:
37        Textures.push_back(this->manager->resManager.loadTexture("./media/textures/MenuBackgroundGTP.JPG", true));
38       
39        for (UINT i = 0; i < this->challengeScreenList.size(); i++) {
40                LoadingTextures.push_back(this->manager->resManager.loadTexture(this->challengeScreenList[i], true));
41        }
42
43        this->activateStandardBackground();
44
45        SoundNode* bgSound = (SoundNode*) this->createNode(Scene::NODE_SOUND);
46        //bgSound->loadFile("./media/music
47}
48
49void MenueScene::activateStandardBackground() {
50        //draw crosshair:
51        Textures[0]->GetLevelDesc(0, &desc);    //get texture size             
52        //calculate transfomation:
53        D3DXVECTOR2 scaling((float)((float)this->manager->screenWidth/(float)desc.Width),(float)((float)this->manager->screenHeight/(float)desc.Height));
54        //set matrix:
55        D3DXMatrixTransformation2D(&spriteMatrix,NULL,0.0,&scaling,NULL,0,NULL);
56        this->sprite->SetTransform(&spriteMatrix);
57
58        this->backgroundIndex = -1;
59}
60
61void MenueScene::activateLoadingBackground(int index) {
62        //draw crosshair:
63        this->LoadingTextures[index]->GetLevelDesc(0, &desc);   //get texture size             
64        //calculate transfomation:
65        D3DXVECTOR2 scaling((float)((float)this->manager->screenWidth/(float)desc.Width),(float)((float)this->manager->screenHeight/(float)desc.Height));
66        //set matrix:
67        D3DXMatrixTransformation2D(&spriteMatrix,NULL,0.0,&scaling,NULL,0,NULL);
68        this->sprite->SetTransform(&spriteMatrix);
69
70        this->backgroundIndex = index;
71}
72
73void MenueScene::addChallenge(std::string challengeName)
74{
75        this->challengeList.push_back(challengeName);
76}
77
78void MenueScene::renderScene(float fElapsedTime)
79{
80        if(this->isVisible()) {
81                if(this->device==0) {
82                        this->device = DXUTGetD3DDevice();
83                        this->physxRenderer.setDevice(*this->device);
84                }
85                this->device->SetRenderTarget(0, this->finalImageSurface);
86
87                if(this->firstFrame) {
88                        this->setupGUI();
89                        //this->playBackgroundSound();
90                }
91
92                this->takeTime();
93                //ClearScreen
94                //this->clearRenderTargetAndZBuffer();
95                //Clear SharedResources
96                this->clearSharedResources();
97                //Fetch Physic Results
98                this->fetchPhysicResults();
99                //Fading Stuff
100                this->doFade();
101                //update game first
102                this->updateMenueFirst();
103                //Trigger updates
104                this->updateTrigger();
105                //Update Nodes
106                this->updateNodes();
107                //Calculate Transformations
108                this->calculateTransformations();
109               
110                //startRenderPasses
111                this->startRenderPasses();
112
113                this->device->SetRenderTarget(0, this->finalImageSurface);
114
115                //Render Background:
116                this->renderBackground();
117                //Render GUI:
118                this->renderGUI(fElapsedTime);
119
120                //Cleanup Memory
121                this->cleanUpScene();
122                //Start Physic
123                this->startPhysic();
124
125                this->firstFrame = false;
126        }
127}
128
129
130
131void MenueScene::updateMenueFirst() {
132        if(this->keyDown[VK_ESCAPE]) {
133            this->keyDown[VK_ESCAPE] = false;
134                manager->switchToGameScene();           
135        }
136        if (this->menuestatus == MENU_LOAD) {
137                this->menuestatus = MENU_IDLE;
138                this->loadGameScene();
139        }
140        if (this->menuestatus == MENU_PREPARE) {
141                this->menuestatus = MENU_LOAD;
142                this->GUI->SetVisible(false);
143        }
144}
145
146void MenueScene::prepareLoading(int index) {
147        if (this->selectedChallengeNumber >= 0) {
148                //change the number of the current challenge to index
149                this->activeChallengeNumber = index;
150
151                this->manager->printToConsole("preparing to load gamescene");
152               
153                this->activeGameScene = &this->manager->gs;//&GameScene();
154               
155                this->activeGameScene->setWidth(1000);
156                this->activeGameScene->setHeight(1000);
157               
158                this->activateLoadingBackground(index);
159
160                this->menuestatus = MENU_PREPARE;
161        }
162}
163
164void MenueScene::loadGameScene() {
165        //clear scene for re-use:
166        if(!this->activeGameScene->alreadyUsed) {
167                this->activeGameScene->alreadyUsed = true;
168        } else {
169                this->activeGameScene->clearScene();
170        }
171       
172        //clean up resources
173        this->manager->resManager.cleanUpResources(false);
174
175        //init scene:
176        this->activeGameScene->initScene(*this->manager);
177        //load the challenge:
178        this->activeGameScene->loadGame(this->challengeList[this->activeChallengeNumber]);
179        //add some light
180        if(!this->lightSetted) {
181                this->lightSetted = true;
182                this->activeGameScene->setLight((*this->activeGameScene).getSunDirection());
183        }
184       
185        manager->switchToGameScene();
186}
187
188void MenueScene::initGUI() {
189       
190        this->setBackgroundSound("./media/music/soundpark/menu.mp3");
191        this->playBackgroundSound();
192       
193        this->GUI->SetVisible(true);
194}
195
196void MenueScene::setupGUI() {
197        //diese funktion ist leider naotwendig da ich die größe noch nicht in initGUI festlegen kann da der manager da noch NULL ist...
198       
199        int fontsize = 0;
200        switch(this->manager->screenWidth) {
201                case 640:
202                        fontsize = 14;
203                        break;
204                case 800:
205                        fontsize = 18;
206                        break;
207                case 1024:
208                        fontsize = 24;
209                        break;
210                case 1200:
211                        fontsize = 30;
212                        break;
213                case 1600:
214                        fontsize = 36;
215                        break;
216                case 1900:
217                        fontsize = 42;
218                        break;
219                default:
220                        fontsize = 24;
221                        break;
222        }
223        this->GUI->SetFont( 1, L"Arial", fontsize, FW_BOLD );
224
225        // Buttons
226        this->GUI->AddButton( IDC_LOADGAME, L"Load Challenge...", 0, 0, 120, 35, L'8' );
227        this->GUI->AddButton( IDC_EXIT, L"Exit Game...", 30, 430, 120, 35, L'X' );
228
229        // List box
230    this->GUI->AddListBox( IDC_CHALLENGELIST, 30, 200, 200, 150, 2 );
231        for( UINT i = 0; i < this->challengeNameList.size(); ++i )
232    {
233                std::wstring temp2(this->challengeNameList.at(i).begin(), this->challengeNameList.at(i).end());
234                this->GUI->GetListBox( IDC_CHALLENGELIST )->AddItem( temp2.c_str(), (LPVOID)(size_t)i );
235    }
236
237        float factorX = ((float)this->manager->screenWidth)/((float)100);
238        float factorY = ((float)this->manager->screenHeight)/((float)100);
239       
240        this->GUI->GetListBox(IDC_CHALLENGELIST)->SetLocation((int)(81*factorX), (int)(5*factorY));
241        this->GUI->GetListBox(IDC_CHALLENGELIST)->SetSize((int)(18*factorX), (int)(52*factorY));
242        this->GUI->GetListBox(IDC_CHALLENGELIST)->GetElement(0)->iFont = 1;
243        this->GUI->GetListBox(IDC_CHALLENGELIST)->GetElement(1)->iFont = 1;
244
245        this->GUI->GetButton(IDC_LOADGAME)->SetLocation((int)(81*factorX), (int)(65*factorY));
246        this->GUI->GetButton(IDC_LOADGAME)->SetSize((int)(18*factorX), (int)(10*factorY));
247        this->GUI->GetButton(IDC_LOADGAME)->GetElement(0)->iFont = 1;
248        this->GUI->GetButton(IDC_LOADGAME)->GetElement(1)->iFont = 1;
249       
250        this->GUI->GetButton(IDC_EXIT)->SetLocation((int)(81*factorX), (int)(81*factorY));
251        this->GUI->GetButton(IDC_EXIT)->SetSize((int)(18*factorX), (int)(10*factorY));
252        this->GUI->GetButton(IDC_EXIT)->GetElement(0)->iFont = 1;
253        this->GUI->GetButton(IDC_EXIT)->GetElement(1)->iFont = 1;
254}
255
256void MenueScene::renderGUI(float fElapsedTime) {
257        this->device->BeginScene();
258        this->GUI->OnRender(fElapsedTime);
259        this->device->EndScene();
260}
261
262void MenueScene::renderBackground() {
263        this->device->BeginScene();
264        this->sprite->Begin(D3DXSPRITE_ALPHABLEND);
265        if(this->backgroundIndex == -1) {
266                this->sprite->Draw(this->Textures[0], NULL, NULL, NULL, 0xFFFFFFFF);
267        } else {
268                this->sprite->Draw(this->LoadingTextures[this->backgroundIndex], NULL, NULL, NULL, 0xFFFFFFFF);
269        }
270        this->sprite->End();
271        this->device->EndScene();
272}
273
274void MenueScene::setDialogResourceManager(CDXUTDialogResourceManager * DialogResourceManager) {
275        this->DialogResourceManager = DialogResourceManager;
276}
277
278void MenueScene::setGUI(CDXUTDialog * GUI) {
279        this->GUI = GUI;
280}
281
282void MenueScene::OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
283{
284    switch( nControlID )
285    {
286        case IDC_LOADGAME:
287                        this->prepareLoading(this->selectedChallengeNumber);
288                        break;
289                case IDC_CHALLENGELIST:
290                        switch( nEvent )
291            {
292                case EVENT_LISTBOX_SELECTION:
293                                        this->selectedChallengeNumber = ((CDXUTListBox *)pControl)->GetSelectedIndex();
294                                        break;
295                                default:
296                                        break;
297                        }
298                        break;
299                case IDC_EXIT:
300                        SendMessage( DXUTGetHWND(), WM_CLOSE, 0, 0 );
301                        break;
302    }
303}
304
305std::vector<std::string>* MenueScene::getChallengeList() {
306        return &this->challengeList;
307}
308
309std::vector<std::string>* MenueScene::getChallengeNameList() {
310        return &this->challengeNameList;
311}
312
313std::vector<std::string>* MenueScene::getChallengeScreenList() {
314        return &this->challengeScreenList;
315}
316
317LPD3DXSPRITE* MenueScene::getSprite() {
318        return &this->sprite;
319}
320
321void MenueScene::OnLostDevice( void* pUserContext )
322{
323        this->sprite->OnLostDevice();
324        Scene::OnLostDevice(pUserContext);
325}
326
327void MenueScene::OnDestroyDevice( void* pUserContext )
328{
329        SAFE_RELEASE(this->sprite);
330        this->sprite = NULL;
331        this->Textures.clear();
332        Scene::OnDestroyDevice(pUserContext);
333}
334
335HRESULT MenueScene::OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
336{
337        Scene::OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc, pUserContext);
338        D3DXCreateSprite(this->device,&sprite);
339       
340        //load background texture:
341        Textures.push_back(this->manager->resManager.loadTexture("./media/textures/MenuBackground.JPG"));
342       
343        //draw crosshair:
344        Textures[0]->GetLevelDesc(0, &desc);    //get texture size             
345        //calculate transfomation:
346        D3DXVECTOR2 scaling((float)this->manager->screenWidth/desc.Width,(float)this->manager->screenHeight/desc.Height);
347        //set matrix:
348        D3DXMatrixTransformation2D(&spriteMatrix,NULL,0.0,&scaling,NULL,0,NULL);
349        this->sprite->SetTransform(&spriteMatrix);
350        return S_OK;
351}
352
353CDXUTDialog* MenueScene::getGUI() {
354        return this->GUI;
355}
356
357//void MenueScene::setBackgroundSound(std::string filename) {
358//      this->bgMusicStream = FSOUND_Stream_Open(filename.c_str(), FSOUND_LOOP_NORMAL, 0, 0);
359//}
360//
361//void MenueScene::playBackgroundSound() {
362//      if(this->bgMusicStream!=NULL) {
363//              this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream);
364//              FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume));
365//      }
366//}
367//
368void MenueScene::updateSoundNodeVolume()
369{
370        Scene::updateSoundNodeVolume();
371        if(this->bgSoundChannel!=-1 && !this->muteMusic) {
372                if(this->sceneAlpha!=0) {
373                        if(this->soundStopped) {
374                                this->soundStopped = false;
375                                this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream);
376                        }
377                        FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha));
378                } else {
379                        FSOUND_Stream_Stop(this->bgMusicStream);
380                        this->soundStopped = true;
381                }
382        }
383}
384
385/*void MenueScene::setBackgroundSoundMute(bool _muteMusic)
386{       
387        this->muteMusic = _muteMusic;
388        if(!this->muteMusic) {
389                if(this->bgSoundChannel!=-1) {
390                        if(this->soundStopped) {
391                                this->soundStopped = false;
392                                this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream);
393                        }
394                        FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha));
395                }
396        } else {
397                if(this->bgSoundChannel!=-1) {
398                        FSOUND_SetVolume(this->bgSoundChannel, 0);
399                }
400        }
401}*/
Note: See TracBrowser for help on using the repository browser.