Mercurial > LightClone
view LightClone/Source/CodePanel.cpp @ 40:00d17d8f407d
Hookup game over dialog; Remove Code class
author | koryspansel |
---|---|
date | Thu, 22 Sep 2011 10:21:14 -0700 |
parents | 2caa7c7e2cb5 |
children | 95677f648a2c |
line wrap: on
line source
/* * CodePanel */ #include "CodePanel.h" /* * EventAction */ const char* CodePanel::EventAction = "CodePanel:EventAction"; /* * CodePanel */ CodePanel::CodePanel(uint32 nWidth, uint32 nHeight) : GuiImage(), nSizeX(nWidth), nSizeY(nHeight) { pSlot = new CodeSlot[nSizeX * nSizeY]; } /* * Initialize */ 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) { SetDimensions(2.0f * fSlotPadding + (fSlotSizeX + fSlotSpacing) * nSizeX - fSlotSpacing, 2.0f * fSlotPadding + (fSlotSizeY + fSlotSpacing) * nSizeY - fSlotSpacing); for(uint32 i = 0; i < nSizeY; ++i) { for(uint32 j = 0; j < nSizeX; ++j) { const uint32 nIndex = i * nSizeX + j; pSlot[nIndex].Initialize(pResourceManager); pSlot[nIndex].SetTexture("Data\\Textures\\Slot.tga"); pSlot[nIndex].SetDimensions(fSlotSizeX, fSlotSizeY); pSlot[nIndex].SetPosition(fSlotPadding + (fSlotSizeX + fSlotSpacing) * j, fSlotPadding + (fSlotSizeY + fSlotSpacing) * i); pSlot[nIndex].Subscribe(CodeSlot::EventDrop, &CodePanel::OnActionDropped, this); pSlot[nIndex].SetSlot(nIndex); pSlot[nIndex].SetAction(Action_Default); Add(&pSlot[nIndex]); } } } return eCode; } /* * SetAction */ void CodePanel::SetAction(uint32 nIndex, uint32 nAction) { pSlot[nIndex].SetAction(nAction); } /* * GetAction */ uint32 CodePanel::GetAction(uint32 nIndex) const { return pSlot[nIndex].GetAction(); } /* * Clear */ void CodePanel::Clear() { const uint32 nCount = nSizeX * nSizeY; for(uint32 i = 0; i < nCount; ++i) { pSlot[i].SetAction(Action_Default); } } /* * SetPermanent */ void CodePanel::SetPermanent(bool bPermanent) { const uint32 nCount = nSizeX * nSizeY; for(uint32 i = 0; i < nCount; ++i) { pSlot[i].SetPermanent(bPermanent); } } /* * OnActionDropped */ void CodePanel::OnActionDropped(GuiEventArguments& kArguments) { CodeSlot* pSlot = (CodeSlot*)kArguments.pSource; //ASSERT(pSlot != NULL); const uint32 nIndex = pSlot->GetSlot(); //if(nIndex < nActionSlots) { ActionArguments kActionArguments(this, nIndex); Fire(CodePanel::EventAction, kActionArguments); } Fire(CodePanel::EventDrop, kArguments); }