changeset 32:c227be6a15fe

Fixed drag and drop handling; Just needs to be hooked up now
author koryspansel
date Tue, 20 Sep 2011 21:26:22 -0700
parents 0b729faa4e73
children 06b151afc8d0
files LightClone/Source/CodePanel.cpp LightClone/Source/CodePanel.h LightClone/Source/CodeSlot.cpp LightClone/Source/CodeSlot.h LightClone/Source/GuiElement.cpp LightClone/Source/GuiInterface.cpp LightClone/Source/World.cpp LightClone/Source/World.h
diffstat 8 files changed, 124 insertions(+), 212 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/Source/CodePanel.cpp	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/CodePanel.cpp	Tue Sep 20 21:26:22 2011 -0700
@@ -7,9 +7,9 @@
 /*
  * CodePanel
  */
-CodePanel::CodePanel(uint32 nMaximum) : GuiImage(), nSlotCount(nMaximum)
+CodePanel::CodePanel(uint32 nWidth, uint32 nHeight) : GuiImage(), nSizeX(nWidth), nSizeY(nHeight)
 {
-	pSlot = new CodeSlot*[nMaximum];
+	pSlot = new CodeSlot*[nSizeX * nSizeY];
 }
 
 /*
@@ -17,20 +17,40 @@
  */
 ErrorCode CodePanel::Initialize(ResourceManager* pResourceManager)
 {
+	const float fSlotSizeX		= 48.0f;
+	const float fSlotSizeY		= 48.0f;
+	const float fSlotPadding	= 16.0f;
+	const float fSlotSpacing	= 8.0f;
+
 	ErrorCode eCode = GuiImage::Initialize(pResourceManager);
 	if(eCode == Error_Success)
 	{
+		//SetTexture("Data\\Textures\\Slot.tga");
 		SetTexture("Data\\Textures\\Panel.tga");
+		SetDimensions(2.0f * fSlotPadding + (fSlotSizeX + fSlotSpacing) * nSizeX - fSlotSpacing, 2.0f * fSlotPadding + (fSlotSizeY + fSlotSpacing) * nSizeY - fSlotSpacing);
 
-		for(uint32 i = 0; i < nSlotCount; ++i)
+		for(uint32 i = 0; i < nSizeY; ++i)
 		{
-			pSlot[i] = new CodeSlot();
-			pSlot[i]->Initialize(pResourceManager);
-			pSlot[i]->SetPosition(48.0f * i, 0.0f);
+			for(uint32 j = 0; j < nSizeX; ++j)
+			{
+				pSlot[i * nSizeX + j] = new CodeSlot();
+				pSlot[i * nSizeX + j]->Initialize(pResourceManager);
+				pSlot[i * nSizeX + j]->SetTexture("Data\\Textures\\Slot.tga");
+				pSlot[i * nSizeX + j]->SetDimensions(fSlotSizeX, fSlotSizeY);
+				pSlot[i * nSizeX + j]->SetPosition(fSlotPadding + (fSlotSizeX + fSlotSpacing) * j, fSlotPadding + (fSlotSizeY + fSlotSpacing) * i);
 
-			Add(pSlot[i]);
+				Add(pSlot[i * nSizeX + j]);
+			}
 		}
 	}
 
 	return eCode;
 }
+
+/*
+ * SetSlot
+ */
+void CodePanel::SetSlot(uint32 nSlot, uint32 nAction)
+{
+	pSlot[nSlot]->SetAction(nAction);
+}
\ No newline at end of file
--- a/LightClone/Source/CodePanel.h	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/CodePanel.h	Tue Sep 20 21:26:22 2011 -0700
@@ -19,21 +19,36 @@
 	CodeSlot** pSlot;
 
 	/*
-	 * nSlotCount
+	 * nSizeX
 	 */
-	uint32 nSlotCount;
+	uint32 nSizeX;
+
+	/*
+	 * nSizeY
+	 */
+	uint32 nSizeY;
 
 public:
 
 	/*
 	 * CodePanel
 	 */
-	CodePanel(uint32 nMaximum);
+	CodePanel(uint32 nWidth, uint32 nHeight);
 
 	/*
 	 * Initialize
 	 */
 	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
+
+	/*
+	 * SetAvailableSlots
+	 */
+	void SetAvailableSlots(uint32 nCount);
+
+	/*
+	 * SetSlot
+	 */
+	void SetSlot(uint32 nSlot, uint32 nAction);
 };
 
 #endif //__CODEPANEL_H__
--- a/LightClone/Source/CodeSlot.cpp	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/CodeSlot.cpp	Tue Sep 20 21:26:22 2011 -0700
@@ -16,8 +16,8 @@
 	"Data\\Textures\\RotateCCW.tga",
 	"Data\\Textures\\Jump.tga",
 	"Data\\Textures\\Light.tga",
-	"Data\\Textures\\FunctionA.tga",
-	"Data\\Textures\\FunctionB.tga",
+	"Data\\Textures\\Function1.tga",
+	"Data\\Textures\\Function2.tga",
 };
 
 /*
@@ -25,6 +25,8 @@
  */
 CodeSlot::CodeSlot() : GuiImage()
 {
+	SetFlag(GuiElementFlag_Pickable);
+
 	nAction		= Action_Default;
 	bMouseDown	= false;
 }
@@ -37,7 +39,7 @@
 	ErrorCode eCode = GuiImage::Initialize(pManager);
 	if(eCode == Error_Success)
 	{
-		SetTexture("Data\\Textures\\Slot.tga", true);
+		SetTexture("Data\\Textures\\Slot.tga");
 	}
 
 	return eCode;
@@ -51,6 +53,24 @@
 }
 
 /*
+ * SetAction
+ */
+void CodeSlot::SetAction(uint32 nValue)
+{
+	nAction = nValue;
+
+	SetTexture(nAction == Action_Default ? "Data\\Textures\\Slot.tga" : ActionTextureName[nAction - Action_Forward]);
+}
+
+/*
+ * GetAction
+ */
+uint32 CodeSlot::GetAction() const
+{
+	return nAction;
+}
+
+/*
  * OnMouseDown
  */
 void CodeSlot::OnMouseDown(uint32 nButton, float fX, float fY)
@@ -58,6 +78,7 @@
 	if(nButton == MouseButton_Left)
 	{
 		bMouseDown = true;
+		pInterface->AcquireCursor(this);
 	}
 }
 
@@ -67,6 +88,11 @@
 void CodeSlot::OnMouseUp(uint32 nButton, float fX, float fY)
 {
 	bMouseDown = false;
+	
+	if(pInterface->IsCursorAcquiredBy(this))
+	{
+		pInterface->ReleaseCursor();
+	}
 }
 
 /*
@@ -74,11 +100,22 @@
  */
 void CodeSlot::OnMouseMove(float fX, float fY)
 {
-	if(bMouseDown)
+	//if(bMouseDown)
+	if(pInterface->IsCursorAcquiredBy(this))
 	{
 		if(nAction != Action_Default)
 		{
-			pInterface->BeginDrag(this, MouseButton_Left);
+			CodeSlot* pInstance = new CodeSlot();
+			pInstance->Initialize(pResourceManager);
+			pInstance->SetAction(nAction);
+			pInstance->SetDimensions(kDimensions);
+			pInstance->SetPosition(kPosition);
+			pInstance->SetInterface(pInterface);
+
+			//CodeSlot* pInstance = Clone();
+
+			pInterface->ReleaseCursor();
+			pInterface->BeginDrag(pInstance, MouseButton_Left);
 		}
 	}
 }
--- a/LightClone/Source/CodeSlot.h	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/CodeSlot.h	Tue Sep 20 21:26:22 2011 -0700
@@ -40,6 +40,16 @@
 	 */
 	virtual void Terminate();
 
+	/*
+	 * SetAction
+	 */
+	void SetAction(uint32 nAction);
+
+	/*
+	 * GetAction
+	 */
+	uint32 GetAction() const;
+
 protected:
 
 	/*
--- a/LightClone/Source/GuiElement.cpp	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/GuiElement.cpp	Tue Sep 20 21:26:22 2011 -0700
@@ -64,6 +64,11 @@
 void GuiElement::SetInterface(GuiInterface* pInstance)
 {
 	pInterface = pInstance;
+
+	for(uint32 i = 0; i < kChildren.Size(); ++i)
+	{
+		kChildren[i]->SetInterface(pInstance);
+	}
 }
 
 /*
@@ -197,12 +202,9 @@
 
 	for(int32 i = (int32)kChildren.Size() - 1; i >= 0 && !pElement; --i)
 	{
-		if(kChildren[i]->HasFlag(GuiElementFlag_Visible | GuiElementFlag_Pickable))
+		if(kChildren[i]->Contains(fX, fY))
 		{
-			if(kChildren[i]->Contains(fX, fY))
-			{
-				pElement = kChildren[i]->Pick(fX, fY);
-			}
+			pElement = kChildren[i]->Pick(fX, fY);
 		}
 	}
 
--- a/LightClone/Source/GuiInterface.cpp	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/GuiInterface.cpp	Tue Sep 20 21:26:22 2011 -0700
@@ -177,13 +177,16 @@
 
 		if(pCursor)
 		{
-			pCursor->Render(kContext, kCamera);
-
 			if(pDragElement)
 			{
-				//TODO: Move to cursor position
-				//pDragElement->Render(kContext, kCamera);
+				const D3DXVECTOR2& kPosition = pCursor->GetPosition();
+				const D3DXVECTOR2& kDimensions = pDragElement->GetDimensions();
+
+				pDragElement->SetPosition(kPosition - 0.5f * kDimensions);
+				pDragElement->Render(kContext, kCamera);
 			}
+
+			pCursor->Render(kContext, kCamera);
 		}
 	}
 
@@ -241,5 +244,6 @@
 		pTarget->OnDrop(pDragElement, fX, fY);
 	}
 
+	delete pDragElement;
 	pDragElement = NULL;
 }
--- a/LightClone/Source/World.cpp	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/World.cpp	Tue Sep 20 21:26:22 2011 -0700
@@ -18,51 +18,6 @@
 	pFunction				= 0;
 	nCurrentFunction		= 0;
 	nCurrentLevel			= 0;
-
-	//kArrowBounds[0]			= Rectangle2(1206.0f + 0 * 16.0f, 473.0f + 0 * 54.0f, 16.0f, 16.0f);
-	//kArrowBounds[1]			= Rectangle2(1206.0f + 2 * 16.0f, 473.0f + 0 * 54.0f, 16.0f, 16.0f);
-
-	//kDialog1Bounds[0]		= Rectangle2(567.0f, 412.0f, 150.0f, 60.0f);
-
-	//kDialog2Bounds[0]		= Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f);
-	//kDialog2Bounds[1]		= Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f);
-
-	/*
-	kToolbar.Add(1023.0f + 0 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kToolbar.Add(1023.0f + 1 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kToolbar.Add(1023.0f + 2 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kToolbar.Add(1023.0f + 3 * 54.0f, 85.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kToolbar.Add(1023.0f + 0 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kToolbar.Add(1023.0f + 1 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kToolbar.Add(1023.0f + 2 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kToolbar.Add(1023.0f + 3 * 54.0f, 85.0f + 1 * 54.0f, 48.0f, 48.0f);
-
-	kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 2 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 0 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 1 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 2 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f);
-	kMain.Add(1023.0f + 3 * 54.0f, 238.0f + 3 * 54.0f, 48.0f, 48.0f);
-
-	kFunction.Add(1023.0f + 0 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kFunction.Add(1023.0f + 1 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kFunction.Add(1023.0f + 2 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kFunction.Add(1023.0f + 3 * 54.0f, 501.0f + 0 * 54.0f, 48.0f, 48.0f);
-	kFunction.Add(1023.0f + 0 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kFunction.Add(1023.0f + 1 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kFunction.Add(1023.0f + 2 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f);
-	kFunction.Add(1023.0f + 3 * 54.0f, 501.0f + 1 * 54.0f, 48.0f, 48.0f);
-	*/
 }
 
 /*
@@ -286,50 +241,16 @@
 		pBackground->SetTexture("Data\\Textures\\Background01.tga", true);
 		pBackground->SetPosition(ScreenSizeX - pBackground->GetWidth(), 0.0f);
 
-		pToolbar = new GuiImage();
+		pToolbar = new CodePanel(4, 2);
 		pToolbar->Initialize(pResourceManager);
-		pToolbar->SetTexture("Data\\Textures\\Panel.tga", true);
-		pToolbar->SetPosition(1000.0f, 100.0f);
-
-		for(uint32 i = 0; i < sizeof(pToolbarSlot) / sizeof(pToolbarSlot[0]); ++i)
-		{
-			//TODO: Use correct toolbar images
-			pToolbarSlot[i] = new GuiImage();
-			pToolbarSlot[i]->Initialize(pResourceManager);
-			pToolbarSlot[i]->SetTexture("Data\\Textures\\Slot.tga", true);
-			pToolbarSlot[i]->SetPosition(1000.0f, 100.0f);	//TODO: Setup correct rows & columns
-
-			pToolbar->Add(pToolbarSlot[i]);
-		}
-
-		pFunctionMain = new GuiImage();
-		pFunctionMain->Initialize(pResourceManager);
-		//pFunctionMain->SetTexture("Data\\Textures\\Panel.tga", true);
-		pFunctionMain->SetPosition(1000.0f, 100.0f);
-
-		for(uint32 i = 0; i < sizeof(pToolbarSlot) / sizeof(pToolbarSlot[0]); ++i)
-		{
-			pFunctionMainSlot[i] = new GuiImage();
-			pFunctionMainSlot[i]->Initialize(pResourceManager);
-			pFunctionMainSlot[i]->SetTexture("Data\\Textures\\Slot.tga", true);
-			pFunctionMainSlot[i]->SetPosition(1000.0f, 100.0f);	//TODO: Setup correct rows & columns
-
-			pFunctionMain->Add(pFunctionMainSlot[i]);
-		}
-
-		pFunctionA = new GuiImage();
-		pFunctionA->Initialize(pResourceManager);
-		//pFunctionA->SetTexture("Data\\Textures\\Panel.tga", true);
-		pFunctionA->SetPosition(1000.0f, 400.0f);
-
-		//TODO: Add slots for function a
-
-		pFunctionB = new GuiImage();
-		pFunctionB->Initialize(pResourceManager);
-		//pFunctionB->SetTexture("Data\\Textures\\Panel.tga", true);
-		pFunctionB->SetPosition(1000.0f, 600.0f);
-
-		//TODO: Add slots for function b
+		pToolbar->SetPosition(1004.0f, 69.0f);
+		pToolbar->SetSlot(0, Action_Forward);
+		pToolbar->SetSlot(1, Action_RotateCW);
+		pToolbar->SetSlot(2, Action_RotateCCW);
+		pToolbar->SetSlot(3, Action_Jump);
+		pToolbar->SetSlot(4, Action_Light);
+		pToolbar->SetSlot(5, Action_FunctionA);
+		pToolbar->SetSlot(6, Action_FunctionB);
 
 		pButtonPlay = new GuiButton();
 		pButtonPlay->Initialize(pResourceManager);
@@ -408,76 +329,13 @@
 		pGameDialog->Add(pGameDialogOk);
 
 		kInterface.Add(pBackground);
+		kInterface.Add(pToolbar);
 		kInterface.Add(pButtonPlay);
 		kInterface.Add(pButtonStop);
 		//kInterface.Add(pButtonReset);
 		kInterface.Add(pButtonExit);
 		kInterface.Add(pLevelDialog);
 		kInterface.Add(pGameDialog);
-
-		/*
-		//CodePanel* 
-		pToolbar = new CodePanel(8);
-		pToolbar->Initialize(pResourceManager);
-		pToolbar->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
-		pToolbar->SetSlotTexture("Data\\Textures\\Slot.tga");
-
-		//CodePanel* 
-		pMain = new CodePanel(16);
-		pMain->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
-		pMain->SetSlotTexture("Data\\Textures\\Slot.tga");
-		pMain->Subscribe(CodePanel::Drop, &World::OnDrop, this);
-
-		//CodePanel* 
-		pFunctionA = new CodePanel(16);
-		pFunctionA->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
-		pFunctionA->SetSlotTexture("Data\\Textures\\Slot.tga");
-		pFunctionA->Subscribe(CodePanel::Drop, &World::OnDrop, this);
-
-		//CodePanel* 
-		pFunctionB = new CodePanel(16);
-		pFunctionB->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
-		pFunctionB->SetSlotTexture("Data\\Textures\\Slot.tga");
-		pFunctionB->Subscribe(CodePanel::Drop, &World::OnDrop, this);
-
-		//GuiPanel*
-		pControlPanel = new GuiPanel();
-		pControlPanel->SetTexture("Data\\Textures\\ControlPanel.tga")
-		pControlPanel->SetDimensions(...);
-		pControlPanel->Add(pButtonStart);
-		pControlPanel->Add(pButtonStop);
-		pControlPanel->Add(pButtonReset);
-		pControlPanel->Add(pButtonExit);
-
-		//GuiDialog*
-		pLevelDialog = new GuiDialog();
-		pLevelDialog->AddButton(DialogButton_Ok, "Ok");
-		pLevelDialog->SetVisible(false);
-
-		//GuiDialog*
-		pGameDialog = new GuiDialog();
-		pGameDialog->AddButton(DialogButton_Ok, "Ok");
-		pGameDialog->SetVisible(false);
-
-		//GuiDialog*
-		pConfirmDialog = new GuiDialog();
-		pConfirmDialog->AddButton(DialogButton_Yes, "Yes");
-		pConfirmDialog->AddButton(DialogButton_No, "No");
-		pConfirmDialog->SetVisible(false);
-
-		//GuiPanel* 
-		pContainerPanel = new GuiPanel();
-		pContainerPanel->SetBackgroundTexture("Data\\Texturse\\ContainerPanel.tga");
-		pContainerPanel->Add(pToolbar);
-		pContainerPanel->Add(pMain);
-		pContainerPanel->Add(pSelectorPanel);
-		pContainerPanel->Add(pControlPanel);
-
-		pRoot->Add(pControlPanel);
-		pRoot->Add(pLevelDialog);
-		pRoot->Add(pGameDialog);
-		pRoot->Add(pConfirmDialog);
-		*/
 	}
 
 	return eCode;
--- a/LightClone/Source/World.h	Tue Sep 20 20:41:07 2011 -0700
+++ b/LightClone/Source/World.h	Tue Sep 20 21:26:22 2011 -0700
@@ -18,6 +18,7 @@
 #include "GuiInterface.h"
 #include "GuiImage.h"
 #include "GuiButton.h"
+#include "CodePanel.h"
 
 /*
  * World
@@ -112,42 +113,7 @@
 	/*
 	 * pToolbar
 	 */
-	GuiImage* pToolbar;
-
-	/*
-	 * pToolbarSlot
-	 */
-	GuiImage* pToolbarSlot[8];
-
-	/*
-	 * pFunctionMain
-	 */
-	GuiImage* pFunctionMain;
-
-	/*
-	 * pFunctionMainSlot
-	 */
-	GuiImage* pFunctionMainSlot[16];
-
-	/*
-	 * pFunctionA
-	 */
-	GuiImage* pFunctionA;
-
-	/*
-	 * pFunctionASlot
-	 */
-	GuiImage* pFunctionASlot[16];
-
-	/*
-	 * pFunctionB
-	 */
-	GuiImage* pFunctionB;
-
-	/*
-	 * pFunctionBSlot
-	 */
-	GuiImage* pFunctionBSlot[16];
+	CodePanel* pToolbar;
 
 	/*
 	 * pLevelDialog