Mercurial > LightClone
changeset 73:0574e2cf8bac
Additional screen types
author | koryspansel |
---|---|
date | Tue, 11 Oct 2011 17:44:10 -0700 |
parents | 9a9be3d8632e |
children | 40c0b5305de8 |
files | LightClone/LightClone.vcproj LightClone/Source/ConfirmScreen.cpp LightClone/Source/ConfirmScreen.h LightClone/Source/Dialog.h LightClone/Source/GameOverScreen.cpp LightClone/Source/GameOverScreen.h LightClone/Source/GameScreen.cpp LightClone/Source/GameScreen.h LightClone/Source/LevelOverScreen.cpp LightClone/Source/LevelOverScreen.h LightClone/Source/Mediator.cpp LightClone/Source/Mediator.h LightClone/Source/ScreenManager.cpp |
diffstat | 13 files changed, 547 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj Tue Oct 11 13:49:40 2011 -0700 +++ b/LightClone/LightClone.vcproj Tue Oct 11 17:44:10 2011 -0700 @@ -338,6 +338,14 @@ Name="Screens" > <File + RelativePath=".\Source\ConfirmScreen.cpp" + > + </File> + <File + RelativePath=".\Source\GameOverScreen.cpp" + > + </File> + <File RelativePath=".\Source\GameScreen.cpp" > </File> @@ -346,6 +354,10 @@ > </File> <File + RelativePath=".\Source\LevelOverScreen.cpp" + > + </File> + <File RelativePath=".\Source\MainScreen.cpp" > </File> @@ -552,6 +564,14 @@ Name="Screens" > <File + RelativePath=".\Source\ConfirmScreen.h" + > + </File> + <File + RelativePath=".\Source\GameOverScreen.h" + > + </File> + <File RelativePath=".\Source\GameScreen.h" > </File> @@ -560,6 +580,10 @@ > </File> <File + RelativePath=".\Source\LevelOverScreen.h" + > + </File> + <File RelativePath=".\Source\MainScreen.h" > </File>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/ConfirmScreen.cpp Tue Oct 11 17:44:10 2011 -0700 @@ -0,0 +1,87 @@ +/* + * ConfirmScreen + */ + +#include "ConfirmScreen.h" +#include "ScreenManager.h" + +/* + * Initialize + */ +ErrorCode ConfirmScreen::Initialize(ServiceProvider* pServiceProvider) +{ + ErrorCode eCode = kInterface.Initialize(pServiceProvider); + if(eCode == Error_Success) + { + pDialog = new ChoiceDialog(); + pDialog->Initialize(pServiceProvider); + pDialog->Subscribe(GuiDialog::EventResult, &ConfirmScreen::OnResult, this); + + const D3DXVECTOR2& kMessageSize = pDialog->GetDimensions(); + pDialog->SetPosition(0.5f * ((ScreenSizeX - 280) - kMessageSize.x), 0.5f * (ScreenSizeY - kMessageSize.y)); + } + + return Error_Success; +} + +/* + * Terminate + */ +void ConfirmScreen::Terminate() +{ + kInterface.Terminate(); + + Screen::Terminate(); +} + +/* + * Update + */ +void ConfirmScreen::Update(float fElapsed) +{ + kInterface.Update(fElapsed); +} + +/* + * Render + */ +void ConfirmScreen::Render(RenderContext& kContext) +{ + kCameraController.SetMode(CameraMode_2D); + kInterface.Render(kContext, kCameraController); +} + +/* + * OnEnter + */ +void ConfirmScreen::OnEnter() +{ + pDialog->SetFlag(GuiElementFlag_Visible); +} + +/* + * OnExit + */ +void ConfirmScreen::OnExit() +{ + pDialog->ClearFlag(GuiElementFlag_Visible); +} + +/* + * OnResult + */ +void ConfirmScreen::OnResult(GuiEventArguments& kArguments) +{ + GuiResultArguments& kResultArguments = (GuiResultArguments&)kArguments; + + if(kResultArguments.nResult == DialogResult_Yes) + { + pScreenManager->Set(NULL); + } + else + + if(kResultArguments.nResult == DialogResult_No) + { + pScreenManager->Pop(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/ConfirmScreen.h Tue Oct 11 17:44:10 2011 -0700 @@ -0,0 +1,76 @@ +/* + * ConfirmScreen + */ + +#ifndef __CONFIRMSCREEN_H__ +#define __CONFIRMSCREEN_H__ + +#include "Core.h" +#include "Screen.h" +#include "CameraController.h" +#include "GuiInterface.h" +#include "Dialog.h" + +/* + * ConfirmScreen + */ +class ConfirmScreen : public Screen +{ + /* + * kCameraController + */ + CameraController kCameraController; + + /* + * kInterface + */ + GuiInterface kInterface; + + /* + * pMessageDialog + */ + ChoiceDialog* pDialog; + +public: + + /* + * Initialize + */ + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); + + /* + * Terminate + */ + virtual void Terminate(); + + /* + * Update + */ + virtual void Update(float fElapsed); + + /* + * Render + */ + virtual void Render(RenderContext& kContext); + +protected: + + /* + * OnEnter + */ + virtual void OnEnter(); + + /* + * OnExit + */ + virtual void OnExit(); + +private: + + /* + * OnResult + */ + void OnResult(GuiEventArguments& kArguments); +}; + +#endif //__CONFIRMSCREEN_H__
--- a/LightClone/Source/Dialog.h Tue Oct 11 13:49:40 2011 -0700 +++ b/LightClone/Source/Dialog.h Tue Oct 11 17:44:10 2011 -0700 @@ -140,4 +140,14 @@ } }; +/* + * MessageDialog + */ +typedef Dialog<1> MessageDialog; + +/* + * ChoiceDialog + */ +typedef Dialog<2> ChoiceDialog; + #endif //__DIALOG_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/GameOverScreen.cpp Tue Oct 11 17:44:10 2011 -0700 @@ -0,0 +1,81 @@ +/* + * GameOverScreen + */ + +#include "GameOverScreen.h" +#include "ScreenManager.h" + +/* + * Initialize + */ +ErrorCode GameOverScreen::Initialize(ServiceProvider* pServiceProvider) +{ + ErrorCode eCode = kInterface.Initialize(pServiceProvider); + if(eCode == Error_Success) + { + pDialog = new MessageDialog(); + pDialog->Initialize(pServiceProvider); + pDialog->Subscribe(GuiDialog::EventResult, &GameOverScreen::OnResult, this); + + const D3DXVECTOR2& kMessageSize = pDialog->GetDimensions(); + pDialog->SetPosition(0.5f * ((ScreenSizeX - 280) - kMessageSize.x), 0.5f * (ScreenSizeY - kMessageSize.y)); + } + + return Error_Success; +} + +/* + * Terminate + */ +void GameOverScreen::Terminate() +{ + kInterface.Terminate(); + + Screen::Terminate(); +} + +/* + * Update + */ +void GameOverScreen::Update(float fElapsed) +{ + kInterface.Update(fElapsed); +} + +/* + * Render + */ +void GameOverScreen::Render(RenderContext& kContext) +{ + kCameraController.SetMode(CameraMode_2D); + kInterface.Render(kContext, kCameraController); +} + +/* + * OnEnter + */ +void GameOverScreen::OnEnter() +{ + pDialog->SetFlag(GuiElementFlag_Visible); +} + +/* + * OnExit + */ +void GameOverScreen::OnExit() +{ + pDialog->ClearFlag(GuiElementFlag_Visible); +} + +/* + * OnResult + */ +void GameOverScreen::OnResult(GuiEventArguments& kArguments) +{ + GuiResultArguments& kResultArguments = (GuiResultArguments&)kArguments; + + if(kResultArguments.nResult == DialogResult_Ok) + { + pScreenManager->Set("Main"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/GameOverScreen.h Tue Oct 11 17:44:10 2011 -0700 @@ -0,0 +1,76 @@ +/* + * GameOverScreen + */ + +#ifndef __GAMEOVERSCREEN_H__ +#define __GAMEOVERSCREEN_H__ + +#include "Core.h" +#include "Screen.h" +#include "CameraController.h" +#include "GuiInterface.h" +#include "Dialog.h" + +/* + * GameOverScreen + */ +class GameOverScreen : public Screen +{ + /* + * kCameraController + */ + CameraController kCameraController; + + /* + * kInterface + */ + GuiInterface kInterface; + + /* + * pMessageDialog + */ + MessageDialog* pDialog; + +public: + + /* + * Initialize + */ + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); + + /* + * Terminate + */ + virtual void Terminate(); + + /* + * Update + */ + virtual void Update(float fElapsed); + + /* + * Render + */ + virtual void Render(RenderContext& kContext); + +protected: + + /* + * OnEnter + */ + virtual void OnEnter(); + + /* + * OnExit + */ + virtual void OnExit(); + +private: + + /* + * OnResult + */ + void OnResult(GuiEventArguments& kArguments); +}; + +#endif //__GAMEOVERSCREEN_H__
--- a/LightClone/Source/GameScreen.cpp Tue Oct 11 13:49:40 2011 -0700 +++ b/LightClone/Source/GameScreen.cpp Tue Oct 11 17:44:10 2011 -0700 @@ -3,6 +3,7 @@ */ #include "GameScreen.h" +#include "ScreenManager.h" /* * Initialize @@ -289,20 +290,6 @@ pBackground->Add(pButtonReset); pBackground->Add(pButtonExit); - pMessageDialog = new MessageDialog(); - pMessageDialog->Initialize(pServiceProvider); - pMessageDialog->Subscribe(GuiDialog::EventResult, &GameScreen::OnResult, this); - - const D3DXVECTOR2& kMessageSize = pMessageDialog->GetDimensions(); - pMessageDialog->SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kMessageSize.x), 0.5f * (ScreenSizeY - kMessageSize.y)); - - pConfirmDialog = new ChoiceDialog(); - pConfirmDialog->Initialize(pServiceProvider); - pConfirmDialog->Subscribe(GuiDialog::EventResult, &GameScreen::OnConfirm, this); - - const D3DXVECTOR2& kConfigSize = pConfirmDialog->GetDimensions(); - pConfirmDialog->SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kConfigSize.x), 0.5f * (ScreenSizeY - kConfigSize.y)); - pDebugText = new GuiLabel(); pDebugText->Initialize(pServiceProvider); pDebugText->SetFont("Courier New", 16); @@ -312,8 +299,6 @@ kInterface.Add(pBackground); kInterface.Add(pDebugText); - kInterface.Add(pMessageDialog); - kInterface.Add(pConfirmDialog); } return eCode; @@ -474,11 +459,7 @@ } else { - pMessageDialog->SetButton(0, "Ok", 0); - pMessageDialog->SetMessage("Congratulations!\nYou have completed the game"); - pMessageDialog->Show(); - - nLogicState = LogicState_GameOver; + pScreenManager->Push("GameOver"); } nSimulationState = SimulationState_Idle; @@ -493,11 +474,8 @@ { if(kEnvironment.RequirementsMet()) { - pMessageDialog->SetButton(0, "Ok", 0); - pMessageDialog->SetMessage("Congratulations!\nYou have completed level %d", nCurrentLevel); - pMessageDialog->Show(); - - nLogicState = LogicState_LevelComplete; + nLogicState = LogicState_LevelLoad; + pScreenManager->Push("LevelOver"); } } } @@ -573,49 +551,5 @@ */ void GameScreen::OnExit(GuiEventArguments& kArguments) { - pConfirmDialog->SetMessage("Are you sure you want to exit?"); - pConfirmDialog->SetButton(0, "Yes", DialogResult_Yes); - pConfirmDialog->SetButton(1, "No", DialogResult_No); - pConfirmDialog->Show(); - - //nWorldState = WorldState_Confirm; + pScreenManager->Push("Confirm"); } - -/* - * OnResult - */ -void GameScreen::OnResult(GuiEventArguments& kArguments) -{ - if(nLogicState == LogicState_LevelComplete) - { - nLogicState = LogicState_LevelLoad; - } - else - - if(nLogicState == LogicState_GameOver) - { - nCurrentLevel = 0; - nLogicState = LogicState_LevelLoad; - - //TODO: Return to main menu - //nWorldState = WorldState_Main; - } -} - -/* - * OnConfirm - */ -void GameScreen::OnConfirm(GuiEventArguments& kArguments) -{ - GuiResultArguments& kResultArguments = (GuiResultArguments&)kArguments; - - if(kResultArguments.nResult == DialogResult_Yes) - { - } - else - - if(kResultArguments.nResult == DialogResult_No) - { - //nWorldState = WorldState_Game; - } -}
--- a/LightClone/Source/GameScreen.h Tue Oct 11 13:49:40 2011 -0700 +++ b/LightClone/Source/GameScreen.h Tue Oct 11 17:44:10 2011 -0700 @@ -12,20 +12,10 @@ #include "GuiImage.h" #include "GuiButton.h" #include "ActionPanel.h" -#include "Dialog.h" #include "Loader.h" #include "Environment.h" #include "Bot.h" - -/* - * MessageDialog - */ -typedef Dialog<1> MessageDialog; - -/* - * ChoiceDialog - */ -typedef Dialog<2> ChoiceDialog; +#include "Dialog.h" /* * GameScreen @@ -200,16 +190,6 @@ * OnExit */ void OnExit(GuiEventArguments& kArguments); - - /* - * OnResult - */ - void OnResult(GuiEventArguments& kArguments); - - /* - * OnConfirm - */ - void OnConfirm(GuiEventArguments& kArguments); }; #endif //__GAMESCREEN_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/LevelOverScreen.cpp Tue Oct 11 17:44:10 2011 -0700 @@ -0,0 +1,81 @@ +/* + * LevelOverScreen + */ + +#include "LevelOverScreen.h" +#include "ScreenManager.h" + +/* + * Initialize + */ +ErrorCode LevelOverScreen::Initialize(ServiceProvider* pServiceProvider) +{ + ErrorCode eCode = kInterface.Initialize(pServiceProvider); + if(eCode == Error_Success) + { + pDialog = new MessageDialog(); + pDialog->Initialize(pServiceProvider); + pDialog->Subscribe(GuiDialog::EventResult, &LevelOverScreen::OnResult, this); + + const D3DXVECTOR2& kMessageSize = pDialog->GetDimensions(); + pDialog->SetPosition(0.5f * ((ScreenSizeX - 280) - kMessageSize.x), 0.5f * (ScreenSizeY - kMessageSize.y)); + } + + return Error_Success; +} + +/* + * Terminate + */ +void LevelOverScreen::Terminate() +{ + kInterface.Terminate(); + + Screen::Terminate(); +} + +/* + * Update + */ +void LevelOverScreen::Update(float fElapsed) +{ + kInterface.Update(fElapsed); +} + +/* + * Render + */ +void LevelOverScreen::Render(RenderContext& kContext) +{ + kCameraController.SetMode(CameraMode_2D); + kInterface.Render(kContext, kCameraController); +} + +/* + * OnEnter + */ +void LevelOverScreen::OnEnter() +{ + pDialog->SetFlag(GuiElementFlag_Visible); +} + +/* + * OnExit + */ +void LevelOverScreen::OnExit() +{ + pDialog->ClearFlag(GuiElementFlag_Visible); +} + +/* + * OnResult + */ +void LevelOverScreen::OnResult(GuiEventArguments& kArguments) +{ + GuiResultArguments& kResultArguments = (GuiResultArguments&)kArguments; + + if(kResultArguments.nResult == DialogResult_Ok) + { + pScreenManager->Pop(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/LevelOverScreen.h Tue Oct 11 17:44:10 2011 -0700 @@ -0,0 +1,76 @@ +/* + * LevelOverScreen + */ + +#ifndef __LEVELOVERSCREEN_H__ +#define __LEVELOVERSCREEN_H__ + +#include "Core.h" +#include "Screen.h" +#include "CameraController.h" +#include "GuiInterface.h" +#include "Dialog.h" + +/* + * LevelOverScreen + */ +class LevelOverScreen : public Screen +{ + /* + * kCameraController + */ + CameraController kCameraController; + + /* + * kInterface + */ + GuiInterface kInterface; + + /* + * pDialog + */ + MessageDialog* pDialog; + +public: + + /* + * Initialize + */ + virtual ErrorCode Initialize(ServiceProvider* pServiceProvider); + + /* + * Terminate + */ + virtual void Terminate(); + + /* + * Update + */ + virtual void Update(float fElapsed); + + /* + * Render + */ + virtual void Render(RenderContext& kContext); + +protected: + + /* + * OnEnter + */ + virtual void OnEnter(); + + /* + * OnExit + */ + virtual void OnExit(); + +private: + + /* + * OnResult + */ + void OnResult(GuiEventArguments& kArguments); +}; + +#endif //__LEVELOVERSCREEN_H__
--- a/LightClone/Source/Mediator.cpp Tue Oct 11 13:49:40 2011 -0700 +++ b/LightClone/Source/Mediator.cpp Tue Oct 11 17:44:10 2011 -0700 @@ -23,6 +23,9 @@ kScreenManager.Register("Help", &kHelpScreen); kScreenManager.Register("Game", &kGameScreen); kScreenManager.Register("Pause", &kPauseScreen); + kScreenManager.Register("LevelOver", &kLevelOverScreen); + kScreenManager.Register("GameOver", &kGameOverScreen); + kScreenManager.Register("Confirm", &kConfirmScreen); } /*
--- a/LightClone/Source/Mediator.h Tue Oct 11 13:49:40 2011 -0700 +++ b/LightClone/Source/Mediator.h Tue Oct 11 17:44:10 2011 -0700 @@ -18,6 +18,9 @@ #include "HelpScreen.h" #include "PauseScreen.h" #include "GameScreen.h" +#include "LevelOverScreen.h" +#include "GameOverScreen.h" +#include "ConfirmScreen.h" /* * Mediator @@ -84,6 +87,21 @@ */ PauseScreen kPauseScreen; + /* + * kLevelOverScreen + */ + LevelOverScreen kLevelOverScreen; + + /* + * kGameOverScreen + */ + GameOverScreen kGameOverScreen; + + /* + * kConfirmScreen + */ + ConfirmScreen kConfirmScreen; + public: /*
--- a/LightClone/Source/ScreenManager.cpp Tue Oct 11 13:49:40 2011 -0700 +++ b/LightClone/Source/ScreenManager.cpp Tue Oct 11 17:44:10 2011 -0700 @@ -78,9 +78,16 @@ { bDirty = false; - for(int32 i = kStack.Size() - 1; i >= 0 && !bDirty; --i) + //for(int32 i = kStack.Size() - 1; i >= 0 && !bDirty; --i) + //{ + // kStack[i]->Update(fElapsed); + //} + if(kStack.Size() > 0) { - kStack[i]->Update(fElapsed); + Screen* pTop = kStack.Peek(); + ASSERT(pTop != NULL); + + pTop->Update(fElapsed); } }