#include "dxstdafx.h" #include ".\menuescene.h" #include ".\GameManager.h" MenueScene::MenueScene(void) : Scene() { this->lightSetted = false; this->usePhysXDebugger = false; this->bgSoundChannel = -1; this->bgSoundVolume = 1.0f; this->menuestatus = MENU_IDLE; this->soundStopped = false; } MenueScene::~MenueScene(void) { this->sprite->Release(); this->clearScene(); } void MenueScene::clearScene() { Scene::clearScene(); } void MenueScene::initScene(GameManager &_manager) { Scene::initScene(_manager); this->activeChallengeNumber = -1; this->selectedChallengeNumber = -1; //create sprite: D3DXCreateSprite(DXUTGetD3DDevice(),&sprite); //load background texture: Textures.push_back(this->manager->resManager.loadTexture("./media/textures/MenuBackgroundGTP.JPG", true)); for (UINT i = 0; i < this->challengeScreenList.size(); i++) { LoadingTextures.push_back(this->manager->resManager.loadTexture(this->challengeScreenList[i], true)); } this->activateStandardBackground(); SoundNode* bgSound = (SoundNode*) this->createNode(Scene::NODE_SOUND); //bgSound->loadFile("./media/music } void MenueScene::activateStandardBackground() { //draw crosshair: Textures[0]->GetLevelDesc(0, &desc); //get texture size //calculate transfomation: D3DXVECTOR2 scaling((float)this->manager->screenWidth/desc.Width,(float)this->manager->screenHeight/desc.Height); //set matrix: D3DXMatrixTransformation2D(&spriteMatrix,NULL,0.0,&scaling,NULL,0,NULL); this->sprite->SetTransform(&spriteMatrix); this->backgroundIndex = -1; } void MenueScene::activateLoadingBackground(int index) { //draw crosshair: this->LoadingTextures[index]->GetLevelDesc(0, &desc); //get texture size //calculate transfomation: D3DXVECTOR2 scaling((float)this->manager->screenWidth/desc.Width,(float)this->manager->screenHeight/desc.Height); //set matrix: D3DXMatrixTransformation2D(&spriteMatrix,NULL,0.0,&scaling,NULL,0,NULL); this->sprite->SetTransform(&spriteMatrix); this->backgroundIndex = index; } void MenueScene::addChallenge(std::string challengeName) { this->challengeList.push_back(challengeName); } void MenueScene::renderScene(float fElapsedTime) { if(this->isVisible()) { if(this->device==0) { this->device = DXUTGetD3DDevice(); this->physxRenderer.setDevice(*this->device); } this->device->SetRenderTarget(0, this->finalImageSurface); if(this->firstFrame) { this->setupGUI(); //this->playBackgroundSound(); } this->takeTime(); //ClearScreen //this->clearRenderTargetAndZBuffer(); //Clear SharedResources this->clearSharedResources(); //Fetch Physic Results this->fetchPhysicResults(); //Fading Stuff this->doFade(); //update game first this->updateMenueFirst(); //Trigger updates this->updateTrigger(); //Update Nodes this->updateNodes(); //Calculate Transformations this->calculateTransformations(); //startRenderPasses this->startRenderPasses(); this->device->SetRenderTarget(0, this->finalImageSurface); //Render Background: this->renderBackground(); //Render GUI: this->renderGUI(fElapsedTime); //Cleanup Memory this->cleanUpScene(); //Start Physic this->startPhysic(); this->firstFrame = false; } } void MenueScene::updateMenueFirst() { if(this->keyDown[VK_ESCAPE]) { this->keyDown[VK_ESCAPE] = false; manager->switchToGameScene(); } if (this->menuestatus == MENU_LOAD) { this->menuestatus = MENU_IDLE; this->loadGameScene(); } if (this->menuestatus == MENU_PREPARE) { this->menuestatus = MENU_LOAD; this->GUI->SetVisible(false); } } void MenueScene::prepareLoading(int index) { if (this->selectedChallengeNumber >= 0) { //change the number of the current challenge to index this->activeChallengeNumber = index; this->manager->printToConsole("preparing to load gamescene"); this->activeGameScene = &this->manager->gs;//&GameScene(); this->activeGameScene->setWidth(1000); this->activeGameScene->setHeight(1000); this->activateLoadingBackground(index); this->menuestatus = MENU_PREPARE; } } void MenueScene::loadGameScene() { //clear scene for re-use: if(!this->activeGameScene->alreadyUsed) { this->activeGameScene->alreadyUsed = true; } else { this->activeGameScene->clearScene(); } //clean up resources this->manager->resManager.cleanUpResources(false); //init scene: this->activeGameScene->initScene(*this->manager); //load the challenge: this->activeGameScene->loadGame(this->challengeList[this->activeChallengeNumber]); //add some light if(!this->lightSetted) { this->lightSetted = true; this->activeGameScene->setLight((*this->activeGameScene).getSunDirection()); } manager->switchToGameScene(); } void MenueScene::initGUI() { //FONTs this->GUI->SetFont( 1, L"Comic Sans MS", 18, FW_BOLD ); // Buttons this->GUI->AddButton( IDC_LOADGAME, L"Load Challenge...", 0, 0, 120, 35, L'8' ); this->GUI->AddButton( IDC_EXIT, L"Exit Game...", 30, 430, 120, 35, L'X' ); // List box this->GUI->AddListBox( IDC_CHALLENGELIST, 30, 200, 200, 150, 2 ); for( UINT i = 0; i < this->challengeNameList.size(); ++i ) { std::wstring temp2(this->challengeNameList.at(i).begin(), this->challengeNameList.at(i).end()); this->GUI->GetListBox( IDC_CHALLENGELIST )->AddItem( temp2.c_str(), (LPVOID)(size_t)i ); } this->setBackgroundSound("./media/music/soundpark/menu.mp3"); this->playBackgroundSound(); this->GUI->SetVisible(true); } void MenueScene::setupGUI() { //diese funktion ist leider naotwendig da ich die größe noch nicht in initGUI festlegen kann da der manager da noch NULL ist... float factorX = (float)this->manager->screenWidth/100; float factorY = (float)this->manager->screenHeight/100; this->GUI->GetListBox(IDC_CHALLENGELIST)->SetLocation((int)(81*factorX), (int)(5*factorY)); this->GUI->GetListBox(IDC_CHALLENGELIST)->SetSize((int)(18*factorX), (int)(52*factorY)); this->GUI->GetListBox(IDC_CHALLENGELIST)->GetElement(0)->iFont = 1; this->GUI->GetListBox(IDC_CHALLENGELIST)->GetElement(1)->iFont = 1; this->GUI->GetButton(IDC_LOADGAME)->SetLocation((int)(81*factorX), (int)(65*factorY)); this->GUI->GetButton(IDC_LOADGAME)->SetSize((int)(18*factorX), (int)(10*factorY)); this->GUI->GetButton(IDC_LOADGAME)->GetElement(0)->iFont = 1; this->GUI->GetButton(IDC_LOADGAME)->GetElement(1)->iFont = 1; this->GUI->GetButton(IDC_EXIT)->SetLocation((int)(81*factorX), (int)(81*factorY)); this->GUI->GetButton(IDC_EXIT)->SetSize((int)(18*factorX), (int)(10*factorY)); this->GUI->GetButton(IDC_EXIT)->GetElement(0)->iFont = 1; this->GUI->GetButton(IDC_EXIT)->GetElement(1)->iFont = 1; } void MenueScene::renderGUI(float fElapsedTime) { this->device->BeginScene(); this->GUI->OnRender(fElapsedTime); this->device->EndScene(); } void MenueScene::renderBackground() { this->device->BeginScene(); this->sprite->Begin(D3DXSPRITE_ALPHABLEND); if(this->backgroundIndex == -1) { this->sprite->Draw(this->Textures[0], NULL, NULL, NULL, 0xFFFFFFFF); } else { this->sprite->Draw(this->LoadingTextures[this->backgroundIndex], NULL, NULL, NULL, 0xFFFFFFFF); } this->sprite->End(); this->device->EndScene(); } void MenueScene::setDialogResourceManager(CDXUTDialogResourceManager * DialogResourceManager) { this->DialogResourceManager = DialogResourceManager; } void MenueScene::setGUI(CDXUTDialog * GUI) { this->GUI = GUI; } void MenueScene::OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ) { switch( nControlID ) { case IDC_LOADGAME: this->prepareLoading(this->selectedChallengeNumber); break; case IDC_CHALLENGELIST: switch( nEvent ) { case EVENT_LISTBOX_SELECTION: this->selectedChallengeNumber = ((CDXUTListBox *)pControl)->GetSelectedIndex(); break; default: break; } break; case IDC_EXIT: SendMessage( DXUTGetHWND(), WM_CLOSE, 0, 0 ); break; } } std::vector* MenueScene::getChallengeList() { return &this->challengeList; } std::vector* MenueScene::getChallengeNameList() { return &this->challengeNameList; } std::vector* MenueScene::getChallengeScreenList() { return &this->challengeScreenList; } LPD3DXSPRITE* MenueScene::getSprite() { return &this->sprite; } void MenueScene::OnLostDevice( void* pUserContext ) { this->sprite->OnLostDevice(); Scene::OnLostDevice(pUserContext); } void MenueScene::OnDestroyDevice( void* pUserContext ) { SAFE_RELEASE(this->sprite); this->sprite = NULL; this->Textures.clear(); Scene::OnDestroyDevice(pUserContext); } HRESULT MenueScene::OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { Scene::OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc, pUserContext); D3DXCreateSprite(this->device,&sprite); //load background texture: Textures.push_back(this->manager->resManager.loadTexture("./media/textures/MenuBackground.JPG")); //draw crosshair: Textures[0]->GetLevelDesc(0, &desc); //get texture size //calculate transfomation: D3DXVECTOR2 scaling((float)this->manager->screenWidth/desc.Width,(float)this->manager->screenHeight/desc.Height); //set matrix: D3DXMatrixTransformation2D(&spriteMatrix,NULL,0.0,&scaling,NULL,0,NULL); this->sprite->SetTransform(&spriteMatrix); return S_OK; } CDXUTDialog* MenueScene::getGUI() { return this->GUI; } //void MenueScene::setBackgroundSound(std::string filename) { // this->bgMusicStream = FSOUND_Stream_Open(filename.c_str(), FSOUND_LOOP_NORMAL, 0, 0); //} // //void MenueScene::playBackgroundSound() { // if(this->bgMusicStream!=NULL) { // this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream); // FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume)); // } //} // void MenueScene::updateSoundNodeVolume() { Scene::updateSoundNodeVolume(); if(this->bgSoundChannel!=-1 && !this->muteMusic) { if(this->sceneAlpha!=0) { if(this->soundStopped) { this->soundStopped = false; this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream); } FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha)); } else { FSOUND_Stream_Stop(this->bgMusicStream); this->soundStopped = true; } } } /*void MenueScene::setBackgroundSoundMute(bool _muteMusic) { this->muteMusic = _muteMusic; if(!this->muteMusic) { if(this->bgSoundChannel!=-1) { if(this->soundStopped) { this->soundStopped = false; this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream); } FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha)); } } else { if(this->bgSoundChannel!=-1) { FSOUND_SetVolume(this->bgSoundChannel, 0); } } }*/