changeset 39:d0ce73ced12e

Added base GuiDialog for event handling; Hookup level complete dialog
author koryspansel <koryspansel@bendbroadband.com>
date Thu, 22 Sep 2011 09:01:42 -0700
parents 2caa7c7e2cb5
children 00d17d8f407d
files LightClone.smp LightClone/LightClone.vcproj LightClone/Source/Dialog.h LightClone/Source/GuiDialog.cpp LightClone/Source/GuiDialog.h LightClone/Source/World.cpp LightClone/Source/World.h
diffstat 7 files changed, 222 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
Binary file LightClone.smp has changed
--- 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 @@
 					>
 				</File>
 				<File
+					RelativePath=".\Source\GuiDialog.cpp"
+					>
+				</File>
+				<File
 					RelativePath=".\Source\GuiElement.cpp"
 					>
 				</File>
@@ -398,6 +402,10 @@
 					>
 				</File>
 				<File
+					RelativePath=".\Source\GuiDialog.h"
+					>
+				</File>
+				<File
 					RelativePath=".\Source\GuiElement.h"
 					>
 				</File>
--- 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<uint32 ButtonCount>
-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]);
+			}
 		}
 	}
 };
--- /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);
+}
--- /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__
--- 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)
+	{
+	}
+}
--- 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__