Mercurial > LightClone
changeset 40:00d17d8f407d
Hookup game over dialog; Remove Code class
author | koryspansel |
---|---|
date | Thu, 22 Sep 2011 10:21:14 -0700 |
parents | d0ce73ced12e |
children | a986355cca5f |
files | LightClone/LightClone.vcproj LightClone/Source/Bot.h LightClone/Source/Code.cpp LightClone/Source/Code.h LightClone/Source/Dialog.h LightClone/Source/GuiInterface.cpp LightClone/Source/Util.cpp LightClone/Source/World.cpp LightClone/Source/World.h LightClone/ToDo.txt |
diffstat | 10 files changed, 80 insertions(+), 262 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/LightClone.vcproj Thu Sep 22 10:21:14 2011 -0700 @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WINVER=0x0600;_WIN32_WINNT=0x0600;_WIN32_WINDOWS=0x0410;_WIN32_IE=0x0700;WIN32_LEAN_AND_MEAN" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;WINVER=0x0600;_WIN32_WINNT=0x0600;_WIN32_WINDOWS=0x0410;_WIN32_IE=0x0700;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_WARNINGS" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -118,7 +118,7 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;WINVER=0x0600;_WIN32_WINNT=0x0600;_WIN32_WINDOWS=0x0410;_WIN32_IE=0x0700;WIN32_LEAN_AND_MEAN" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;WINVER=0x0600;_WIN32_WINNT=0x0600;_WIN32_WINDOWS=0x0410;_WIN32_IE=0x0700;WIN32_LEAN_AND_MEAN;_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="2" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" @@ -185,10 +185,6 @@ > </File> <File - RelativePath=".\Source\Code.cpp" - > - </File> - <File RelativePath=".\Source\CodePanel.cpp" > </File> @@ -347,10 +343,6 @@ > </File> <File - RelativePath=".\Source\Code.h" - > - </File> - <File RelativePath=".\Source\CodePanel.h" > </File>
--- a/LightClone/Source/Bot.h Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/Source/Bot.h Thu Sep 22 10:21:14 2011 -0700 @@ -10,7 +10,6 @@ #include "ResourceManager.h" #include "VirtualMachine.h" #include "Environment.h" -#include "Code.h" #include "Clock.h" #include "Program.h"
--- a/LightClone/Source/Code.cpp Thu Sep 22 09:01:42 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * Code - */ - -#include "Code.h" - -/* - * Code - */ -Code::Code() -{ - pSlot = 0; - nSize = 0; - nLength = 0; -} - -/* - * Initialize - */ -void Code::Initialize(uint32 nValue) -{ - if(pSlot) - { - delete[] pSlot; - pSlot = 0; - } - - nLength = 0; - nSize = nValue; - pSlot = new uint32[nValue]; - - Clear(); -} - -/* - * Clear - */ -void Code::Clear() -{ - for(uint32 i = 0; i < nSize; ++i) - { - pSlot[i] = 0; - } -} - -/* - * SetSlot - */ -void Code::SetSlot(uint32 nSlot, uint32 nValue) -{ - if(nSlot < nSize) - { - pSlot[nSlot] = nValue; - } -} - -/* - * GetSlot - */ -uint32 Code::GetSlot(uint32 nSlot) -{ - return nSlot < nSize ? pSlot[nSlot] : 0; -} - -/* - * ClearSlot - */ -void Code::ClearSlot(uint32 nSlot) -{ - if(nSlot < nSize) - { - pSlot[nSlot] = 0; - } -} - -/* - * IsEmptySlot - */ -bool Code::IsEmptySlot(uint32 nSlot) const -{ - return nSlot < nSize ? (pSlot[nSlot] < Action_Forward || pSlot[nSlot] > Action_Light) : true; -} - -/* - * GetSize - */ -uint32 Code::GetSize() const -{ - return nSize; -} - -/* - * GetLength - */ -uint32 Code::GetLength() const -{ - uint32 nLength = 0; - - for(uint32 i = 0; i < nSize; ++i) - { - if(pSlot[nLength] != 0) - { - ++nLength; - } - } - - return nLength; -}
--- a/LightClone/Source/Code.h Thu Sep 22 09:01:42 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Code - */ - -#ifndef __CODE_H__ -#define __CODE_H__ - -#include "Core.h" - -/* - * Code - */ -class Code -{ - /* - * pSlot - * Code blocks are made up of an array of actions - */ - uint32* pSlot; - - /* - * nSize - */ - uint32 nSize; - - /* - * nLength - */ - uint32 nLength; - -public: - - /* - * Code - */ - Code(); - - /* - * Initialize - */ - void Initialize(uint32 nLength); - - /* - * Clear - */ - void Clear(); - - /* - * SetSlot - */ - void SetSlot(uint32 nSlot, uint32 nValue); - - /* - * GetSlot - */ - uint32 GetSlot(uint32 nSlot); - - /* - * ClearSlot - */ - void ClearSlot(uint32 nSlot); - - /* - * IsEmptySlot - */ - bool IsEmptySlot(uint32 nSlot) const; - - /* - * GetSize - */ - uint32 GetSize() const; - - /* - * GetLength - */ - uint32 GetLength() const; -}; - -#endif //__CODE_H__
--- a/LightClone/Source/Dialog.h Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/Source/Dialog.h Thu Sep 22 10:21:14 2011 -0700 @@ -9,6 +9,8 @@ #include "GuiDialog.h" #include "GuiLabel.h" #include "GuiButton.h" +#include <stdarg.h> +#include <stdio.h> /* * DialogResult @@ -103,9 +105,17 @@ /* * SetMessage */ - void SetMessage(const char* pMessage) + void SetMessage(const char* pFormat, ...) { - kLabel.SetText(pMessage); + va_list kArguments; + va_start(kArguments, pFormat); + + char kBuffer[128]; + vsprintf(kBuffer, pFormat, kArguments); + + kLabel.SetText(kBuffer); + + va_end(kArguments); } /*
--- a/LightClone/Source/GuiInterface.cpp Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/Source/GuiInterface.cpp Thu Sep 22 10:21:14 2011 -0700 @@ -61,12 +61,6 @@ if(pCursor) { - /* - char kBuffer[128]; - sprintf_s(kBuffer, "<%0.2f, %0.2f>\n", fX, fY); - OutputDebugStringA(kBuffer); - */ - pCursor->SetPosition(fMouseX, fMouseY); pCursor->Update(fElapsed); }
--- a/LightClone/Source/Util.cpp Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/Source/Util.cpp Thu Sep 22 10:21:14 2011 -0700 @@ -13,8 +13,8 @@ uint8* pData = NULL; uint32 nSize = 0; - FILE* pFile = NULL; - if(fopen_s(&pFile, pName, "rt") == 0) + FILE* pFile = fopen(pName, "rt"); + if(pFile) { fseek(pFile, 0, SEEK_END); nSize = (uint32)ftell(pFile);
--- a/LightClone/Source/World.cpp Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/Source/World.cpp Thu Sep 22 10:21:14 2011 -0700 @@ -14,6 +14,7 @@ World::World() { nGameState = GameState_Active; + nGameStatePrevious = GameState_Active; nSimulationState = SimulationState_Idle; nCurrentLevel = 0; } @@ -42,7 +43,7 @@ eCode = InitializeInterface(pResourceManager); if(eCode == Error_Success) { - nCurrentLevel = 1; + nCurrentLevel = 0; nGameState = GameState_LoadMap; } } @@ -129,7 +130,7 @@ if(nGameState == GameState_LoadMap) { char kBuffer[256]; - sprintf_s(kBuffer, "Data\\Maps\\Map%02d.map", nCurrentLevel++); + sprintf(kBuffer, "Data\\Maps\\Map%02d.map", nCurrentLevel++); ErrorCode eCode = Load(kBuffer); if(eCode == Error_Success) @@ -144,6 +145,10 @@ } else { + kMessageDialog.SetButton(0, "Ok", 0); + kMessageDialog.SetMessage("Congratulations!\nYou have completed the game"); + kMessageDialog.Show(); + nGameState = GameState_Over; } @@ -159,23 +164,17 @@ { if(kEnvironment.RequirementsMet()) { - kLevelDialog.SetButton(0, "Ok", 0); - kLevelDialog.SetMessage("Congratulations!\nYou have completed level XX"); - kLevelDialog.Show(); + kMessageDialog.SetButton(0, "Ok", 0); + kMessageDialog.SetMessage("Congratulations!\nYou have completed level XX"); + kMessageDialog.Show(); nGameState = GameState_Complete; } } } - - kInterface.Update(fElapsed); } - else - if(nGameState == GameState_Complete) - { - kInterface.Update(fElapsed); - } + kInterface.Update(fElapsed); } /* @@ -340,16 +339,21 @@ pBackground->Add(pButtonReset); pBackground->Add(pButtonExit); - kLevelDialog.Initialize(pResourceManager); - kLevelDialog.Subscribe(GuiDialog::EventResult, &World::OnResult, this); + kMessageDialog.Initialize(pResourceManager); + kMessageDialog.Subscribe(GuiDialog::EventResult, &World::OnResult, this); + + const D3DXVECTOR2& kMessageSize = kMessageDialog.GetDimensions(); + kMessageDialog.SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kMessageSize.x), 0.5f * (ScreenSizeY - kMessageSize.y)); - const D3DXVECTOR2& kDialogSize = kLevelDialog.GetDimensions(); + kConfigDialog.Initialize(pResourceManager); + kConfigDialog.Subscribe(GuiDialog::EventResult, &World::OnConfirm, this); - kLevelDialog.SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kDialogSize.x), 0.5f * (ScreenSizeY - kDialogSize.y)); + const D3DXVECTOR2& kConfigSize = kMessageDialog.GetDimensions(); + kConfigDialog.SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kConfigSize.x), 0.5f * (ScreenSizeY - kConfigSize.y)); kInterface.Add(pBackground); - kInterface.Add(&kLevelDialog); - //kInterface.Add(pGameDialog); + kInterface.Add(&kMessageDialog); + kInterface.Add(&kConfigDialog); } return eCode; @@ -490,7 +494,8 @@ */ void World::OnExit(GuiEventArguments& kArguments) { - nGameState = GameState_Exit; + nGameStatePrevious = nGameState; + nGameState = GameState_Confirm; } /* @@ -498,18 +503,34 @@ */ void World::OnResult(GuiEventArguments& kArguments) { - if(GameState_Complete) + if(nGameState == GameState_Complete) { nGameState = GameState_LoadMap; } else - if(GameState_Over) + if(nGameState == GameState_Over) { + nCurrentLevel = 0; + nGameState = GameState_LoadMap; + } +} + +/* + * OnConfirm + */ +void World::OnConfirm(GuiEventArguments& kArguments) +{ + GuiResultArguments& kResultArguments = (GuiResultArguments&)kArguments; + + if(kResultArguments.nResult == DialogResult_Yes) + { + nGameState = GameState_Exit; } else - if(GameState_Confirm) + if(kResultArguments.nResult == DialogResult_No) { + nGameState = nGameStatePrevious; } }
--- a/LightClone/Source/World.h Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/Source/World.h Thu Sep 22 10:21:14 2011 -0700 @@ -11,7 +11,6 @@ #include "RenderContext.h" #include "Environment.h" #include "Bot.h" -#include "Code.h" #include "Loader.h" #include "CameraController.h" #include "InputManager.h" @@ -63,6 +62,11 @@ uint32 nGameState; /* + * nGameStatePrevious + */ + uint32 nGameStatePrevious; + + /* * nSimulationState */ uint32 nSimulationState; @@ -128,29 +132,14 @@ CodePanel* pFunctionB; /* - * pLevelDialog + * kMessageDialog */ - //GuiImage* pLevelDialog; - - /* - * pLevelDialogOk - */ - //GuiButton* pLevelDialogOk; + Dialog<1> kMessageDialog; /* - * pGameDialog - */ - //GuiImage* pGameDialog; - - /* - * pGameDialogOk + * kConfirmDialog */ - //GuiButton* pGameDialogOk; - - /* - * kLevelDialog - */ - Dialog<1> kLevelDialog; + Dialog<2> kConfigDialog; public: @@ -260,6 +249,11 @@ * OnResult */ void OnResult(GuiEventArguments& kArguments); + + /* + * OnConfirm + */ + void OnConfirm(GuiEventArguments& kArguments); }; #endif //__WORLD_H__
--- a/LightClone/ToDo.txt Thu Sep 22 09:01:42 2011 -0700 +++ b/LightClone/ToDo.txt Thu Sep 22 10:21:14 2011 -0700 @@ -1,13 +1,8 @@ 1. Only draw slots that are being used -2. Center grid in viewport -3. Button tool tips -4. Main menu -5. Pause menu -6. Robot model & texture -7. Implement confirm exit dialog -8. Help interface -9. Add button to clear code panes -10. Implement drag and drop - a. Add drag and drop interface to GuiInterface and move handling into subclasses - b. Support creating a new element when dragging and destroying it when done -11. Implement gui batching \ No newline at end of file +2. Button tool tips +3. Main menu +4. Pause menu +5. Robot model & texture +6. Implement confirm exit dialog +7. Help interface +8. Implement gui batching \ No newline at end of file