Misc - EventHandler, EventCollection updated.

This commit is contained in:
Pontus Fransson 2014-01-31 14:16:58 +01:00
parent d6769ac62f
commit a864ad81e7
4 changed files with 54 additions and 13 deletions

View File

@ -3,8 +3,8 @@
using namespace Oyster::Event; using namespace Oyster::Event;
EventButtonCollection::EventButtonCollection() EventButtonCollection::EventButtonCollection()
: collectionState(EventCollectionState_Enabled)
{ {
} }
EventButtonCollection::~EventButtonCollection() EventButtonCollection::~EventButtonCollection()
@ -13,13 +13,39 @@ EventButtonCollection::~EventButtonCollection()
void EventButtonCollection::Update(InputClass* inputObject) void EventButtonCollection::Update(InputClass* inputObject)
{ {
if(this->collectionState == EventCollectionState_Enabled)
{
for(int i = 0; i < buttons.size(); i++) for(int i = 0; i < buttons.size(); i++)
{ {
buttons.at(i)->Update(inputObject); 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;
} }

View File

@ -11,6 +11,15 @@ namespace Oyster
{ {
namespace Event namespace Event
{ {
enum EventCollectionState
{
EventCollectionState_Disabled,
EventCollectionState_Enabled,
EventCollectionState_Count,
EventCollectionState_Unknown = -1,
};
class EventButtonCollection class EventButtonCollection
{ {
public: public:
@ -19,10 +28,18 @@ namespace Oyster
void Update(InputClass* inputObject); 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: private:
std::vector<EventButton*> buttons; std::vector<EventButton*> buttons;
EventCollectionState collectionState;
}; };
} }

View File

@ -11,7 +11,6 @@ EventHandler& EventHandler::Instance()
EventHandler::EventHandler() EventHandler::EventHandler()
{ {
} }
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()
{ {
} }

View File

@ -21,9 +21,8 @@ namespace Oyster
void Update(InputClass* inputObject); void Update(InputClass* inputObject);
EventButtonCollection* CreateCollection(); void AddCollection(EventButtonCollection& collection);
EventButtonCollection* GetCollection(/*ID*/); EventButtonCollection& CreateCollection();
private: private:
std::vector<EventButtonCollection*> collections; std::vector<EventButtonCollection*> collections;