# HG changeset patch # User koryspansel # Date 1316707302 25200 # Node ID d0ce73ced12e06fb1295fd85b5d8cdde37e6c71d # Parent 2caa7c7e2cb562a28f6bdb8e71b41ebd568d5b54 Added base GuiDialog for event handling; Hookup level complete dialog diff -r 2caa7c7e2cb5 -r d0ce73ced12e LightClone.smp Binary file LightClone.smp has changed diff -r 2caa7c7e2cb5 -r d0ce73ced12e LightClone/LightClone.vcproj --- a/LightClone/LightClone.vcproj Wed Sep 21 21:40:19 2011 -0700 +++ b/LightClone/LightClone.vcproj Thu Sep 22 09:01:42 2011 -0700 @@ -244,6 +244,10 @@ > + + @@ -398,6 +402,10 @@ > + + diff -r 2caa7c7e2cb5 -r d0ce73ced12e LightClone/Source/Dialog.h --- a/LightClone/Source/Dialog.h Wed Sep 21 21:40:19 2011 -0700 +++ b/LightClone/Source/Dialog.h Thu Sep 22 09:01:42 2011 -0700 @@ -6,15 +6,26 @@ #define __DIALOG_H__ #include "Core.h" -#include "GuiImage.h" +#include "GuiDialog.h" #include "GuiLabel.h" #include "GuiButton.h" /* + * DialogResult + */ +enum +{ + DialogResult_Ok = 0, + + DialogResult_Yes = 0, + DialogResult_No = 1, +}; + +/* * Dialog */ template -class Dialog : public GuiImage +class Dialog : public GuiDialog { /* * kLabel @@ -26,12 +37,17 @@ */ GuiButton kButton[ButtonCount]; + /* + * kResult + */ + uint32 kResult[ButtonCount]; + public: /* * Dialog */ - Dialog() : GuiImage() + Dialog() : GuiDialog() { } @@ -40,15 +56,17 @@ */ virtual ErrorCode Initialize(ResourceManager* pResourceManager) { - ErrorCode eCode = GuiImage::Initialize(pResourceManager); + ErrorCode eCode = GuiDialog::Initialize(pResourceManager); if(eCode == Error_Success) { - SetTexture("Data\\Textures\\Dialog.tga", true); + SetTexture("Data\\Textures\\Dialog0.tga", true); //SetDimensions(300.0f, 200.0f); kLabel.Initialize(pResourceManager); - kLabel.SetPosition(150.0f, 50.0f); + kLabel.SetPosition(0.5f * kDimensions.x, 0.15f * kDimensions.y); kLabel.SetLabelFlag(GuiLabelFlag_CenterX); + kLabel.SetFont("Courier New", 16); + kLabel.SetColor(D3DCOLOR_XRGB(0, 0, 0)); Add(&kLabel); @@ -58,8 +76,23 @@ kButton[i].SetTexture(GuiButtonState_Normal, "Data\\Textures\\ButtonN.tga", true); kButton[i].SetTexture(GuiButtonState_Hover, "Data\\Textures\\ButtonH.tga"); kButton[i].SetTexture(GuiButtonState_Down, "Data\\Textures\\ButtonD.tga"); + kButton[i].SetFont("Courier New", 16); + kButton[i].SetColor(D3DCOLOR_XRGB(0, 0, 0)); kButton[i].Subscribe(GuiButton::EventClick, &Dialog::OnClick, this); + const D3DXVECTOR2& kButtonSize = kButton[i].GetDimensions(); + + //x = 0.5 * Wb + //1 = 0.5 * Wd - x + //2 = 0.25 * Wd - x; 0.75 * Wd - x + + const float fScale = 1.0f / (float)(ButtonCount + 1); + + const float fX = (i + 1) * fScale * kDimensions.x - 0.5f * kButtonSize.x; + const float fY = 0.65f * kDimensions.y; + + kButton[i].SetPosition(fX, fY); + Add(&kButton[i]); } } @@ -67,6 +100,23 @@ return eCode; } + /* + * SetMessage + */ + void SetMessage(const char* pMessage) + { + kLabel.SetText(pMessage); + } + + /* + * SetButton + */ + void SetButton(uint32 nButton, const char* pText, uint32 nResult) + { + kButton[nButton].SetText(pText); + kResult[nButton] = nResult; + } + private: /* @@ -74,13 +124,12 @@ */ void OnClick(GuiEventArguments& kArguments) { - if(kArguments.pSource == &kButton[0]) + for(uint32 nButton = 0; nButton < ButtonCount; ++nButton) { - } - else - - if(kArguments.pSource == &kButton[1]) - { + if(kArguments.pSource == &kButton[nButton]) + { + Close(kResult[nButton]); + } } } }; diff -r 2caa7c7e2cb5 -r d0ce73ced12e LightClone/Source/GuiDialog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/GuiDialog.cpp Thu Sep 22 09:01:42 2011 -0700 @@ -0,0 +1,37 @@ +/* + * GuiDialog + */ + +#include "GuiDialog.h" + +/* + * EventResult + */ +const char* GuiDialog::EventResult = "GuiDialog:EventResult"; + +/* + * GuiDialog + */ +GuiDialog::GuiDialog() : GuiImage() +{ + ClearFlag(GuiElementFlag_Visible); +} + +/* + * Show + */ +ErrorCode GuiDialog::Show() +{ + return SetFlag(GuiElementFlag_Visible), Error_Success; +} + +/* + * Close + */ +void GuiDialog::Close(uint32 nResult) +{ + ClearFlag(GuiElementFlag_Visible); + + GuiResultArguments kArguments(this, nResult); + Fire(GuiDialog::EventResult, kArguments); +} diff -r 2caa7c7e2cb5 -r d0ce73ced12e LightClone/Source/GuiDialog.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightClone/Source/GuiDialog.h Thu Sep 22 09:01:42 2011 -0700 @@ -0,0 +1,61 @@ +/* + * GuiButton + */ + +#ifndef __GUIDIALOG_H__ +#define __GUIDIALOG_H__ + +#include "Core.h" +#include "GuiImage.h" + +/* + * GuiResultArguments + */ +struct GuiResultArguments : public GuiEventArguments +{ + /* + * nResult + */ + uint32 nResult; + + /* + * GuiResultArguments + */ + GuiResultArguments(GuiElement* pSource, uint32 nResultCode) : GuiEventArguments(pSource), nResult(nResultCode) + { + } +}; + +/* + * GuiDialog + */ +class GuiDialog : public GuiImage +{ +public: + + /* + * EventResult + */ + static const char* EventResult; + +public: + + /* + * GuiDialog + */ + GuiDialog(); + + /* + * Show + */ + ErrorCode Show(); + +protected: + + /* + * Close + */ + void Close(uint32 nResult); +}; + +#endif //__GUIDIALOG_H__ diff -r 2caa7c7e2cb5 -r d0ce73ced12e LightClone/Source/World.cpp --- a/LightClone/Source/World.cpp Wed Sep 21 21:40:19 2011 -0700 +++ b/LightClone/Source/World.cpp Thu Sep 22 09:01:42 2011 -0700 @@ -42,7 +42,7 @@ eCode = InitializeInterface(pResourceManager); if(eCode == Error_Success) { - nCurrentLevel = 2; + nCurrentLevel = 1; nGameState = GameState_LoadMap; } } @@ -91,7 +91,7 @@ /* * Load */ -bool World::Load(const char* pName) +ErrorCode World::Load(const char* pName) { ErrorCode eCode = kLoader.Load(pName); if(eCode == Error_Success) @@ -116,7 +116,7 @@ } } - return eCode == Error_Success; + return eCode; } /* @@ -131,7 +131,23 @@ char kBuffer[256]; sprintf_s(kBuffer, "Data\\Maps\\Map%02d.map", nCurrentLevel++); - nGameState = Load(kBuffer) ? GameState_Active : GameState_Over; + ErrorCode eCode = Load(kBuffer); + if(eCode == Error_Success) + { + kProgram.Clear(); + + pMain->Clear(); + pFunctionA->Clear(); + pFunctionB->Clear(); + + nGameState = GameState_Active; + } + else + { + nGameState = GameState_Over; + } + + nSimulationState = SimulationState_Idle; } else @@ -143,9 +159,9 @@ { if(kEnvironment.RequirementsMet()) { - //kDialog.Reset("Some message"); - //kDialog.AddButton(DialogButton_Ok, "Ok", 0.0f, 0.0f, 0.0f, 0.0f); - //pLevelDialog->SetFlag(GuiElementFlag_Visible); + kLevelDialog.SetButton(0, "Ok", 0); + kLevelDialog.SetMessage("Congratulations!\nYou have completed level XX"); + kLevelDialog.Show(); nGameState = GameState_Complete; } @@ -324,44 +340,15 @@ pBackground->Add(pButtonReset); pBackground->Add(pButtonExit); - /* - pLevelDialog = new GuiImage(); - pLevelDialog->Initialize(pResourceManager); - pLevelDialog->ClearFlag(GuiElementFlag_Visible); - pLevelDialog->SetTexture("Data\\Textures\\Dialog0.tga", true); - pLevelDialog->SetPosition(0.5f * (ScreenSizeX - pLevelDialog->GetWidth()), 0.5f * (ScreenSizeY - pLevelDialog->GetHeight())); - - pLevelDialogOk = new GuiButton(); - pLevelDialogOk->Initialize(pResourceManager); - pLevelDialogOk->SetTexture(GuiButtonState_Normal, "Data\\Textures\\ButtonN.tga"); - pLevelDialogOk->SetTexture(GuiButtonState_Hover, "Data\\Textures\\ButtonH.tga"); - pLevelDialogOk->SetTexture(GuiButtonState_Down, "Data\\Textures\\ButtonD.tga"); - pLevelDialogOk->SetFont("Courier New", 24); - pLevelDialogOk->SetText("Ok"); - pLevelDialogOk->SetDimensions(150.0f, 52.0f); - pLevelDialogOk->SetPosition(0.5f * (pLevelDialog->GetWidth() - pLevelDialogOk->GetWidth()), 171.0f); - pLevelDialogOk->Subscribe(GuiButton::EventClick, &World::OnExit, this); + kLevelDialog.Initialize(pResourceManager); + kLevelDialog.Subscribe(GuiDialog::EventResult, &World::OnResult, this); - pLevelDialog->Add(pLevelDialogOk); - - pGameDialog = new GuiImage(); - pGameDialog->Initialize(pResourceManager); - pGameDialog->ClearFlag(GuiElementFlag_Visible); - pGameDialog->SetTexture("Data\\Textures\\Dialog0.tga", true); - pGameDialog->SetPosition(0.5f * (ScreenSizeX - pGameDialog->GetWidth()), 0.5f * (ScreenSizeY - pGameDialog->GetHeight())); + const D3DXVECTOR2& kDialogSize = kLevelDialog.GetDimensions(); - pGameDialogOk = new GuiButton(); - pGameDialogOk->Initialize(pResourceManager); - pGameDialogOk->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button.tga", true); - pGameDialogOk->SetText("Ok"); - pGameDialogOk->SetPosition(0.5f * (pGameDialog->GetWidth() - pGameDialogOk->GetWidth()), 171.0f); - pGameDialogOk->Subscribe(GuiButton::EventClick, &World::OnExit, this); - - pGameDialog->Add(pGameDialogOk); - */ + kLevelDialog.SetPosition(0.5f * ((ScreenSizeX - pBackground->GetWidth()) - kDialogSize.x), 0.5f * (ScreenSizeY - kDialogSize.y)); kInterface.Add(pBackground); - //kInterface.Add(pLevelDialog); + kInterface.Add(&kLevelDialog); //kInterface.Add(pGameDialog); } @@ -505,3 +492,24 @@ { nGameState = GameState_Exit; } + +/* + * OnResult + */ +void World::OnResult(GuiEventArguments& kArguments) +{ + if(GameState_Complete) + { + nGameState = GameState_LoadMap; + } + else + + if(GameState_Over) + { + } + else + + if(GameState_Confirm) + { + } +} diff -r 2caa7c7e2cb5 -r d0ce73ced12e LightClone/Source/World.h --- a/LightClone/Source/World.h Wed Sep 21 21:40:19 2011 -0700 +++ b/LightClone/Source/World.h Thu Sep 22 09:01:42 2011 -0700 @@ -187,7 +187,7 @@ /* * Load */ - bool Load(const char* pName); + ErrorCode Load(const char* pName); /* * Update @@ -255,6 +255,11 @@ * OnExit */ void OnExit(GuiEventArguments& kArguments); + + /* + * OnResult + */ + void OnResult(GuiEventArguments& kArguments); }; #endif //__WORLD_H__