diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h index 291bf07d..4785d630 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -44,7 +44,6 @@ namespace DanBias GetCursorPos(&p); ScreenToClient(WindowShell::GetHWND(), &p); GetClientRect(WindowShell::GetHWND(), &r); - //Should come from the InputClass float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 70bbbbea..297335c8 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -25,7 +25,7 @@ struct LoginState::myData // game client* //Menu button collection - EventButtonCollection* collection; + EventButtonCollection collection; bool createGame; int testNumber; }privData; @@ -109,23 +109,23 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) InitCamera(Oyster::Math::Float3(0,0,5.4f)); //Create menu buttons - privData->collection = new EventButtonCollection; - EventHandler::Instance().AddCollection(privData->collection); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f)); - - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f)); - - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); - - //Incr/decr buttons - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); + //privData->collection = new EventButtonCollection; + EventHandler::Instance().AddCollection(&privData->collection); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f)); + + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f)); + + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); + + //Incr/decr buttons . + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); + privData->collection.AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); privData->createGame = false; privData->testNumber = 0; @@ -198,7 +198,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key // failed to connect return ClientState_Same; } - privData->collection->SetState(EventCollectionState_Disabled); + privData->collection.SetState(EventCollectionState_Disabled); return ClientState_LobbyCreated; } // join game @@ -213,7 +213,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key // failed to connect return ClientState_Same; } - privData->collection->SetState(EventCollectionState_Disabled); + privData->collection.SetState(EventCollectionState_Disabled); return ClientState_Lobby; } return ClientState_Same; @@ -259,7 +259,7 @@ bool LoginState::Release() privData->object[i] = NULL; } - delete privData->collection; + EventHandler::Instance().ReleaseCollection(&privData->collection); delete privData; privData = NULL; diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 2bd5f09a..5c1438c3 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -20,6 +20,7 @@ EventButtonCollection::~EventButtonCollection() if(EventHandler::Instance().collections.at(i) == this) { EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i); + break; } } diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 4b623714..234a3935 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -19,22 +19,11 @@ EventHandler::EventHandler() EventHandler::~EventHandler() { - int size = collections.size(); - for(int i = 0; i < size; i++) - { - delete collections[i]; - collections[i] = NULL; - } + Clean(); } void EventHandler::Clean() { - int size = collections.size(); - for(int i = 0; i < size; i++) - { - delete collections[i]; - collections[i] = NULL; - } collections.clear(); } @@ -65,14 +54,12 @@ void EventHandler::AddCollection(EventButtonCollection* collection) collections.push_back(collection); } -void EventHandler::DeleteCollection(EventButtonCollection* collection) +void EventHandler::ReleaseCollection(EventButtonCollection* collection) { for(int i = 0; i < collections.size(); i++) { if(collections.at(i) == collection) { - delete collection; - collection = NULL; collections.erase(collections.begin() + i); break; } diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 71a35ecd..a2560f0f 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -33,7 +33,8 @@ namespace Oyster */ void AddCollection(EventButtonCollection* collection); - void DeleteCollection(EventButtonCollection* collection); + + void ReleaseCollection(EventButtonCollection* collection); private: //Can't copy this class. @@ -43,7 +44,7 @@ namespace Oyster private: std::vector collections; - //EventButtonCollection is a firend so it can delete it self. + //EventButtonCollection is a friend so it can delete it self. friend class EventButtonCollection; }; }