From a864ad81e71e0f65379b4c67b66ba8bffaec67ba Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 31 Jan 2014 14:16:58 +0100 Subject: [PATCH] Misc - EventHandler, EventCollection updated. --- .../EventHandler/EventButtonCollection.cpp | 36 ++++++++++++++++--- .../Misc/EventHandler/EventButtonCollection.h | 19 +++++++++- Code/Misc/EventHandler/EventHandler.cpp | 7 ++-- Code/Misc/EventHandler/EventHandler.h | 5 ++- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index b3d37bfe..268712c5 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -2,9 +2,9 @@ using namespace Oyster::Event; -EventButtonCollection::EventButtonCollection() +EventButtonCollection::EventButtonCollection() + : collectionState(EventCollectionState_Enabled) { - } EventButtonCollection::~EventButtonCollection() @@ -13,13 +13,39 @@ EventButtonCollection::~EventButtonCollection() void EventButtonCollection::Update(InputClass* inputObject) { - for(int i = 0; i < buttons.size(); i++) + if(this->collectionState == EventCollectionState_Enabled) { - buttons.at(i)->Update(inputObject); + for(int i = 0; i < buttons.size(); i++) + { + buttons.at(i)->CheckCollision(inputObject); + } } } -EventButton* EventButtonCollection::AddButton(EventButton* button) +void EventButtonCollection::AddButton(EventButton& button) { + buttons.push_back(button); +} +EventButton& EventButtonCollection::CreateButton() +{ + EventButton temp; + buttons.push_back(&temp); + return temp; +} + +EventCollectionState EventButtonCollection::GetState() const +{ + return collectionState; +} + +void EventButtonCollection::SetState(const EventCollectionState state) +{ + collectionState = state; +} + +void EventButtonCollection::Clear() +{ + buttons.clear(); + collectionState = EventCollectionState_Enabled; } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 31201f9c..4368e195 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -11,6 +11,15 @@ namespace Oyster { namespace Event { + enum EventCollectionState + { + EventCollectionState_Disabled, + EventCollectionState_Enabled, + + EventCollectionState_Count, + EventCollectionState_Unknown = -1, + }; + class EventButtonCollection { public: @@ -19,10 +28,18 @@ namespace Oyster void Update(InputClass* inputObject); - EventButton* AddButton(EventButton* button); + void AddButton(EventButton& button); + EventButton& CreateButton(); + + EventCollectionState GetState() const; + void SetState(const EventCollectionState state); + + //Clear all buttons and reset the state. + void Clear(); private: std::vector buttons; + EventCollectionState collectionState; }; } diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 8f6705df..e064ad41 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -11,7 +11,6 @@ EventHandler& EventHandler::Instance() EventHandler::EventHandler() { - } EventHandler::~EventHandler() @@ -26,12 +25,12 @@ void EventHandler::Update(InputClass* inputObject) } } -EventButtonCollection* EventHandler::CreateCollection() +void EventHandler::AddCollection(EventButtonCollection& collection) { - + collections.push_back(&collection); } -EventButtonCollection* EventHandler::GetCollection(/*ID*/); +EventButtonCollection& EventHandler::CreateCollection() { } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index c3ecc0a2..1a438e8c 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -21,9 +21,8 @@ namespace Oyster void Update(InputClass* inputObject); - EventButtonCollection* CreateCollection(); - EventButtonCollection* GetCollection(/*ID*/); - + void AddCollection(EventButtonCollection& collection); + EventButtonCollection& CreateCollection(); private: std::vector collections;