# HG changeset patch # User koryspansel # Date 1316148300 25200 # Node ID a785b0aaf004f5e0e8fb630e4e4d0e9316d25e08 # Parent 502ed0a0059a2a74d8816486f35f71d342605348 More work on the Gui system diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/FixedString.h --- a/LightClone/Source/FixedString.h Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/FixedString.h Thu Sep 15 21:45:00 2011 -0700 @@ -82,6 +82,8 @@ } kString[nLength] = 0; + + return *this; } /* diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/GuiButton.cpp --- a/LightClone/Source/GuiButton.cpp Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/GuiButton.cpp Thu Sep 15 21:45:00 2011 -0700 @@ -13,7 +13,7 @@ /* * GuiButton */ -GuiButton::GuiButton() : nState(GuiButtonState_Normal), pEffect(NULL), pVertexBuffer(NULL) +GuiButton::GuiButton() : nState(GuiButtonState_Normal), pEffect(NULL), pVertexBuffer(NULL), pFont(NULL) { memset(pTexture, 0, sizeof(pTexture)); } @@ -45,6 +45,12 @@ */ void GuiButton::Terminate() { + if(pFont) + { + pFont->Release(); + pFont = NULL; + } + for(uint32 i = 0; i < GuiButtonState_Count; ++i) { if(pTexture[i]) @@ -79,41 +85,66 @@ */ void GuiButton::Render(RenderContext& kContext, Camera& kCamera) { - if(pTexture[nState]) + if(bVisible) { - uint32 nPasses = 0; + if(pTexture[nState]) + { + uint32 nPasses = 0; - const float fOffsetX = -0.5f * ScreenSizeX; - const float fOffsetY = +0.5f * ScreenSizeY; + const float fOffsetX = -0.5f * ScreenSizeX; + const float fOffsetY = +0.5f * ScreenSizeY; + + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + kContext.ApplyCameraToEffect(kCamera, pEffect); - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f); + + const D3DXVECTOR2& kLocation = GetPosition(); - kContext.ApplyCameraToEffect(kCamera, pEffect); + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f); - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f); + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture[nState]); - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, fOffsetX + kPosition.x + 0.5f, fOffsetY - kPosition.y + 0.5f, 0.0f); + pEffect->SetTechnique(pEffect->GetTechnique(0)); + pEffect->Begin(&nPasses, 0); + pEffect->BeginPass(0); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + pEffect->EndPass(); + pEffect->End(); + + if(pFont && kText.Length() > 0) + { + const int32 nX = (int32)(kLocation.x + 0.5f * kDimensions.x); + const int32 nY = (int32)(kLocation.y + 0.5f * kDimensions.y); - pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture[nState]); + RECT kRectangle; + kRectangle.left = nX; + kRectangle.top = nY; + kRectangle.right = nX; + kRectangle.bottom = nY; - pEffect->SetTechnique(pEffect->GetTechnique(0)); - pEffect->Begin(&nPasses, 0); - pEffect->BeginPass(0); + const uint32 nLength = kText.Length(); - kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); + pFont->DrawTextA(NULL, kText, nLength, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, kColor); + pFont->DrawTextA(NULL, kText, nLength, &kRectangle, DT_CENTER | DT_VCENTER, kColor); + } + } - pEffect->EndPass(); - pEffect->End(); + GuiElement::Render(kContext, kCamera); } } + /* * SetTexture */ @@ -147,10 +178,33 @@ } /* + * SetFont + */ +ErrorCode GuiButton::SetFont(const char* pName, uint32 nSize, uint32 nWeight) +{ + if(pFont) + { + pFont->Release(); + pFont = NULL; + } + + return pResourceManager->CreateFontFromName(pName, nSize, nWeight, &pFont); +} + +/* + * SetText + */ +void GuiButton::SetText(const char* pText) +{ + kText = pText; +} + +/* * OnMouseDown */ void GuiButton::OnMouseDown(uint32 nButton, float fX, float fY) { + //TODO: Proper states and click handling GuiEventArguments kArguments; kArguments.pSource = this; diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/GuiButton.h --- a/LightClone/Source/GuiButton.h Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/GuiButton.h Thu Sep 15 21:45:00 2011 -0700 @@ -59,6 +59,16 @@ */ IDirect3DTexture9* pTexture[GuiButtonState_Count]; + /* + * pFont + */ + ID3DXFont* pFont; + + /* + * kText + */ + FixedString<> kText; + public: /* @@ -92,6 +102,16 @@ ErrorCode SetTexture(uint32 nState, const char* pName, bool bResize = false); /* + * SetFont + */ + ErrorCode SetFont(const char* pName, uint32 nSize, uint32 nHeight = FW_NORMAL); + + /* + * SetText + */ + void SetText(const char* pText); + + /* * OnMouseDown */ virtual void OnMouseDown(uint32 nButton, float fX, float fY); diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/GuiElement.cpp --- a/LightClone/Source/GuiElement.cpp Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/GuiElement.cpp Thu Sep 15 21:45:00 2011 -0700 @@ -7,7 +7,7 @@ /* * GuiElement */ -GuiElement::GuiElement() : pContainer(NULL), kPosition(0.0f, 0.0f), kDimensions(0.0f, 0.0f) +GuiElement::GuiElement() : pContainer(NULL), kPosition(0.0f, 0.0f), kDimensions(0.0f, 0.0f), kColor(0xFFFFFFFF), bVisible(true) { } @@ -49,9 +49,12 @@ */ void GuiElement::Render(RenderContext& kContext, Camera& kCamera) { - for(uint32 i = 0; i < kChildren.Size(); ++i) + if(bVisible) { - kChildren[i]->Render(kContext, kCamera); + for(uint32 i = 0; i < kChildren.Size(); ++i) + { + kChildren[i]->Render(kContext, kCamera); + } } } @@ -132,31 +135,69 @@ } /* + * GetWidth + */ +float GuiElement::GetWidth() const +{ + return kDimensions.x; +} + +/* + * GetHeight + */ +float GuiElement::GetHeight() const +{ + return kDimensions.y; +} + +/* + * SetVisible + */ +void GuiElement::SetVisible(bool bValue) +{ + bVisible = bValue; +} + +/* + * IsVisible + */ +bool GuiElement::IsVisible() const +{ + return bVisible; +} + +/* * Pick */ GuiElement* GuiElement::Pick(float fX, float fY) { GuiElement* pElement = NULL; - for(uint32 i = 0; i < kChildren.Size() && !pElement; ++i) + for(int32 i = (int32)kChildren.Size() - 1; i >= 0 && !pElement; --i) { - const D3DXVECTOR2& kLocation = kChildren[i]->GetPosition(); - const D3DXVECTOR2& kSize = kChildren[i]->GetDimensions(); + if(kChildren[i]->bVisible) + { + const D3DXVECTOR2& kLocation = kChildren[i]->GetPosition(); + const D3DXVECTOR2& kSize = kChildren[i]->GetDimensions(); - if(Rectangle2(kLocation.x, kLocation.y, kSize.x, kSize.y).Contains(fX, fY)) - { - pElement = kChildren[i]; + if(Rectangle2(kLocation.x, kLocation.y, kSize.x, kSize.y).Contains(fX, fY)) + { + pElement = kChildren[i]->Pick(fX, fY); + } } } if(!pElement) { - const D3DXVECTOR2& kLocation = GetPosition(); - const D3DXVECTOR2& kSize = GetDimensions(); + if(bVisible) + { + const D3DXVECTOR2& kLocation = GetPosition(); + const D3DXVECTOR2& kSize = GetDimensions(); - if(Rectangle2(kLocation.x, kLocation.y, kSize.x, kSize.y).Contains(fX, fY)) - { - pElement = this; + if(Rectangle2(kLocation.x, kLocation.y, kSize.x, kSize.y).Contains(fX, fY)) + { + pElement = this; + } } } diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/GuiElement.h --- a/LightClone/Source/GuiElement.h Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/GuiElement.h Thu Sep 15 21:45:00 2011 -0700 @@ -47,6 +47,11 @@ D3DCOLOR kColor; /* + * bVisible + */ + bool bVisible; + + /* * kChildren */ List kChildren; @@ -129,6 +134,26 @@ const D3DXVECTOR2 GetDimensions() const; /* + * GetWidth + */ + float GetWidth() const; + + /* + * GetHeight + */ + float GetHeight() const; + + /* + * SetVisible + */ + void SetVisible(bool bValue); + + /* + * IsVisible + */ + bool IsVisible() const; + + /* * Pick */ virtual GuiElement* Pick(float fX, float fY); diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/GuiImage.cpp --- a/LightClone/Source/GuiImage.cpp Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/GuiImage.cpp Thu Sep 15 21:45:00 2011 -0700 @@ -68,38 +68,45 @@ */ void GuiImage::Render(RenderContext& kContext, Camera& kCamera) { - if(pTexture) + if(bVisible) { - uint32 nPasses = 0; + if(pTexture) + { + uint32 nPasses = 0; - const float fOffsetX = -0.5f * ScreenSizeX; - const float fOffsetY = +0.5f * ScreenSizeY; + const float fOffsetX = -0.5f * ScreenSizeX; + const float fOffsetY = +0.5f * ScreenSizeY; - const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); + + kContext.ApplyCameraToEffect(kCamera, pEffect); - kContext.ApplyCameraToEffect(kCamera, pEffect); + D3DXMATRIX kScale; + D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f); - D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f); + const D3DXVECTOR2& kLocation = GetPosition(); - D3DXMATRIX kTranslate; - D3DXMatrixTranslation(&kTranslate, fOffsetX + kPosition.x + 0.5f, fOffsetY - kPosition.y + 0.5f, 0.0f); + D3DXMATRIX kTranslate; + D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f); - D3DXMATRIX kWorldMatrix; - D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + D3DXMATRIX kWorldMatrix; + D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); + + pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); + pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); + pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture); - pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); - pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); - pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture); + pEffect->SetTechnique(pEffect->GetTechnique(0)); + pEffect->Begin(&nPasses, 0); + pEffect->BeginPass(0); + + kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - pEffect->SetTechnique(pEffect->GetTechnique(0)); - pEffect->Begin(&nPasses, 0); - pEffect->BeginPass(0); + pEffect->EndPass(); + pEffect->End(); + } - kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); - - pEffect->EndPass(); - pEffect->End(); + GuiElement::Render(kContext, kCamera); } } diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/GuiInterface.cpp --- a/LightClone/Source/GuiInterface.cpp Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/GuiInterface.cpp Thu Sep 15 21:45:00 2011 -0700 @@ -114,10 +114,20 @@ */ void GuiInterface::Render(RenderContext& kContext, Camera& kCamera) { - GuiElement::Render(kContext, kCamera); + //TODO: Begin batch + //kContext.BeginBatch(); - if(pCursor) + if(bVisible) { - pCursor->Render(kContext, kCamera); + //TODO: Inside Render functions call kContext.AddToBatch(pTexture, kPosition, kDimensions, kColor) + GuiElement::Render(kContext, kCamera); + + if(pCursor) + { + pCursor->Render(kContext, kCamera); + } } + + //TODO: End batch + //kContext.EndBatch() } diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/GuiLabel.cpp --- a/LightClone/Source/GuiLabel.cpp Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/GuiLabel.cpp Thu Sep 15 21:45:00 2011 -0700 @@ -44,31 +44,36 @@ */ void GuiLabel::Render(RenderContext& kContext, Camera& kCamera) { - if(pFont) + if(bVisible) { - //TODO: Position needs to be relative to the parent + if(pFont) + { + const D3DXVECTOR2& kLocation = GetPosition(); + + RECT kRectangle; + kRectangle.left = (int32)kLocation.x; + kRectangle.top = (int32)kLocation.y; + kRectangle.right = (int32)kLocation.x; + kRectangle.bottom = (int32)kLocation.y; - RECT kRectangle; - kRectangle.left = (int32)kPosition.x; - kRectangle.top = (int32)kPosition.y; - kRectangle.right = (int32)kPosition.x; - kRectangle.bottom = (int32)kPosition.y; + uint32 nLength = strlen(kLabel); + uint32 nFormat = 0; + + if(nFlags & GuiLabelFlag_CenterX) + { + nFormat |= DT_CENTER; + } - uint32 nLength = strlen(kLabel); - uint32 nFormat = 0; + if(nFlags & GuiLabelFlag_CenterY) + { + nFormat |= DT_VCENTER; + } - if(nFlags & GuiLabelFlag_CenterX) - { - nFormat |= DT_CENTER; + pFont->DrawTextA(NULL, kLabel, nLength, &kRectangle, nFormat | DT_CALCRECT, kColor); + pFont->DrawTextA(NULL, kLabel, nLength, &kRectangle, nFormat, kColor); } - if(nFlags & GuiLabelFlag_CenterY) - { - nFormat |= DT_VCENTER; - } - - pFont->DrawTextA(NULL, kLabel, nLength, &kRectangle, nFormat | DT_CALCRECT, kColor); - pFont->DrawTextA(NULL, kLabel, nLength, &kRectangle, nFormat, kColor); + GuiElement::Render(kContext, kCamera); } } diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/World.cpp --- a/LightClone/Source/World.cpp Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/World.cpp Thu Sep 15 21:45:00 2011 -0700 @@ -61,12 +61,6 @@ 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); - - /* - kControls.Add(1023.0f + 0.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); - kControls.Add(1023.0f + 1.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); - kControls.Add(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f); - */ } /* @@ -288,7 +282,7 @@ GuiImage* pBackground = new GuiImage(); pBackground->Initialize(pResourceManager); pBackground->SetTexture("Data\\Textures\\Background01.tga", true); - pBackground->SetPosition(ScreenSizeX - pBackground->GetDimensions().x, 0.0f); + pBackground->SetPosition(ScreenSizeX - pBackground->GetWidth(), 0.0f); GuiButton* pButtonPlay = new GuiButton(); pButtonPlay->Initialize(pResourceManager); @@ -326,11 +320,47 @@ pLabel->SetPosition(0.5f * ScreenSizeX, 0.5f * ScreenSizeY); */ + pLevelDialog = new GuiImage(); + pLevelDialog->Initialize(pResourceManager); + //pLevelDialog->SetVisible(false); + pLevelDialog->SetTexture("Data\\Textures\\Dialog2.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\\Slot.tga"); + pLevelDialogOk->SetFont("Courier New", 24); + pLevelDialogOk->SetText("Ok"); + pLevelDialogOk->SetDimensions(150.0f, 52.0f); + //pLevelDialogOk->SetPosition(23.0f, 171.0f); + pLevelDialogOk->SetPosition(0.5f * (pLevelDialog->GetWidth() - pLevelDialogOk->GetWidth()), 171.0f); + pLevelDialogOk->Subscribe(GuiButton::EventClick, &World::OnExit, this); + + pLevelDialog->Add(pLevelDialogOk); + + /* + pGameDialogOk = new GuiButton(); + pGameDialogOk->Initialize(pResourceManager); + pGameDialogOk->SetTexture(GuiButtonState_Normal, "Data\\Textures\\Button.tga", true); + //pGameDialogOk->SetText("Ok"); + pGameDialogOk->SetPosition(1023.0f + 3.0f * 54.0f, 640.0f); + pGameDialogOk->Subscribe(GuiButton::EventClick, &World::OnExit, this); + */ + + pGameDialog = new GuiImage(); + pGameDialog->Initialize(pResourceManager); + pGameDialog->SetVisible(false); + pGameDialog->SetTexture("Data\\Textures\\Dialog2.tga", true); + pGameDialog->SetPosition(0.5f * (ScreenSizeX - pGameDialog->GetWidth()), 0.5f * (ScreenSizeY - pGameDialog->GetHeight())); + //pGameDialog->Add(pGameDialogOk); + kInterface.Add(pBackground); kInterface.Add(pButtonPlay); kInterface.Add(pButtonStop); //kInterface.Add(pButtonReset); kInterface.Add(pButtonExit); + kInterface.Add(pLevelDialog); + kInterface.Add(pGameDialog); /* //CodePanel* @@ -357,30 +387,6 @@ pFunctionB->SetSlotTexture("Data\\Textures\\Slot.tga"); pFunctionB->Subscribe(CodePanel::Drop, &World::OnDrop, this); - //GuiButton* - pButtonStart = new GuiButton(); - pButtonStart->SetTexture("Data\\Textures\\Play.tga"); - pButtonStart->SetDimensions(...); - pButtonStart->Subscribe(GuiButton::Click, &World::OnClick, this); - - //GuiButton* - pButtonStop = new GuiButton(); - pButtonStop->SetTexture("Data\\Textures\\Stop.tga"); - pButtonStop->SetDimensions(...); - pButtonStart->Subscribe(GuiButton::Click, &World::OnClick, this); - - //GuiButton* - pButtonReset = new GuiButton(); - pButtonReset->SetTexture("Data\\Textures\\Reset.tga"); - pButtonReset->SetDimensions(...); - pButtonStart->Subscribe(GuiButton::Click, &World::OnClick, this); - - //GuiButton* - pButtonExit = new GuiButton(); - pButtonExit->SetTexture("Data\\Textures\\Exit.tga"); - pButtonExit->SetDimensions(...); - pButtonStart->Subscribe(GuiButton::Click, &World::OnClick, this); - //GuiPanel* pControlPanel = new GuiPanel(); pControlPanel->SetTexture("Data\\Textures\\ControlPanel.tga") @@ -490,55 +496,32 @@ { if(pInputManager->IsButtonDown(0) && !pInputManager->WasButtonDown(0)) { - /* - int32 nSelection = kControls.Pick(fMouseX, fMouseY); + // pick against the toolbar + int32 nSelection = kToolbar.Pick(fMouseX, fMouseY); if(nSelection >= 0) { - if(nSelection == ControlButton_Play) + kDragController.Begin(Action_Forward + nSelection); + } + else + { + // pick against the main pane + nSelection = kMain.Pick(fMouseX, fMouseY); + if(nSelection >= 0) { - if(nSimulationState == SimulationState_Idle) + Code* pCode = pFunction; + if(!pCode->IsEmptySlot(nSelection)) { - ResetBot(); - kBot.Upload(pFunction, kLoader.GetFunctionCount() + 1); - - nSimulationState = SimulationState_Active; + kDragController.Begin(pCode->GetSlot(nSelection)); + pCode->ClearSlot(nSelection); } } else - - if(nSelection == ControlButton_Stop) { - if(nSimulationState == SimulationState_Active) - { - ResetEnvironment(); - ResetBot(); - - nSimulationState = SimulationState_Idle; - } - } - else - - if(nSelection == ControlButton_Exit) - { - nGameState = GameState_Exit; - } - } - else - */ - { - // pick against the toolbar - nSelection = kToolbar.Pick(fMouseX, fMouseY); - if(nSelection >= 0) - { - kDragController.Begin(Action_Forward + nSelection); - } - else - { - // pick against the main pane - nSelection = kMain.Pick(fMouseX, fMouseY); + // pick against the function pane + nSelection = kFunction.Pick(fMouseX, fMouseY); if(nSelection >= 0) { - Code* pCode = pFunction; + Code* pCode = pFunction + nCurrentFunction + 1; if(!pCode->IsEmptySlot(nSelection)) { kDragController.Begin(pCode->GetSlot(nSelection)); @@ -547,27 +530,13 @@ } else { - // pick against the function pane - nSelection = kFunction.Pick(fMouseX, fMouseY); - if(nSelection >= 0) + // pick against the function pane arrows + for(uint32 i = 0; i < sizeof(kArrowBounds) / sizeof(kArrowBounds[0]); ++i) { - Code* pCode = pFunction + nCurrentFunction + 1; - if(!pCode->IsEmptySlot(nSelection)) + if(kArrowBounds[i].Contains(fMouseX, fMouseY)) { - kDragController.Begin(pCode->GetSlot(nSelection)); - pCode->ClearSlot(nSelection); - } - } - else - { - // pick against the function pane arrows - for(uint32 i = 0; i < sizeof(kArrowBounds) / sizeof(kArrowBounds[0]); ++i) - { - if(kArrowBounds[i].Contains(fMouseX, fMouseY)) - { - const uint32 nCount = kLoader.GetFunctionCount(); - nCurrentFunction = (nCurrentFunction + 2 * (int32)i - 1 + nCount) % nCount; - } + const uint32 nCount = kLoader.GetFunctionCount(); + nCurrentFunction = (nCurrentFunction + 2 * (int32)i - 1 + nCount) % nCount; } } } @@ -718,6 +687,13 @@ */ void World::OnPlay(GuiEventArguments& kArguments) { + if(nSimulationState == SimulationState_Idle) + { + ResetBot(); + kBot.Upload(pFunction, kLoader.GetFunctionCount() + 1); + + nSimulationState = SimulationState_Active; + } } /* @@ -725,6 +701,13 @@ */ void World::OnStop(GuiEventArguments& kArguments) { + if(nSimulationState == SimulationState_Active) + { + ResetEnvironment(); + ResetBot(); + + nSimulationState = SimulationState_Idle; + } } /* @@ -739,4 +722,5 @@ */ void World::OnExit(GuiEventArguments& kArguments) { + nGameState = GameState_Exit; } diff -r 502ed0a0059a -r a785b0aaf004 LightClone/Source/World.h --- a/LightClone/Source/World.h Thu Sep 15 20:31:15 2011 -0700 +++ b/LightClone/Source/World.h Thu Sep 15 21:45:00 2011 -0700 @@ -18,8 +18,9 @@ #include "InputManager.h" #include "ButtonPane.h" #include "Dialog.h" -//#include "Interface.h" #include "GuiInterface.h" +#include "GuiImage.h" +#include "GuiButton.h" /* * World @@ -107,11 +108,6 @@ ButtonPane kFunction; /* - * kControlBounds - */ - //ButtonPane kControls; - - /* * kArrowBounds */ Rectangle2 kArrowBounds[2]; @@ -127,16 +123,30 @@ Rectangle2 kDialog2Bounds[2]; /* - * kInterface - * Move to World - */ - //Interface kInterface; - - /* * kDialog */ Dialog kDialog; + /* + * pLevelDialog + */ + GuiImage* pLevelDialog; + + /* + * pLevelDialogOk + */ + GuiButton* pLevelDialogOk; + + /* + * pGameDialog + */ + GuiImage* pGameDialog; + + /* + * pGameDialogOk + */ + GuiButton* pGameDialogOk; + public: /*