Misc - Fixed a few errors that can occur
This commit is contained in:
parent
8c1f1e6608
commit
0bae7b9c6b
|
@ -257,7 +257,6 @@ bool LoginState::Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
delete privData->collection;
|
delete privData->collection;
|
||||||
//EventHandler::Instance().DeleteCollection(privData->collection);
|
|
||||||
|
|
||||||
delete privData;
|
delete privData;
|
||||||
privData = NULL;
|
privData = NULL;
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
using namespace Oyster::Event;
|
using namespace Oyster::Event;
|
||||||
|
|
||||||
EventButtonCollection::EventButtonCollection()
|
EventButtonCollection::EventButtonCollection(EventCollectionState state)
|
||||||
: collectionState(EventCollectionState_Enabled)
|
: collectionState(state)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +65,13 @@ void EventButtonCollection::SetState(const EventCollectionState state)
|
||||||
|
|
||||||
void EventButtonCollection::Clear()
|
void EventButtonCollection::Clear()
|
||||||
{
|
{
|
||||||
|
int size = buttons.size();
|
||||||
|
for(int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
delete buttons[i];
|
||||||
|
buttons[i] = NULL;
|
||||||
|
}
|
||||||
buttons.clear();
|
buttons.clear();
|
||||||
|
|
||||||
collectionState = EventCollectionState_Enabled;
|
collectionState = EventCollectionState_Enabled;
|
||||||
}
|
}
|
|
@ -28,20 +28,20 @@ namespace Oyster
|
||||||
};
|
};
|
||||||
|
|
||||||
/********************************
|
/********************************
|
||||||
This EventButtonCollection will handle the destruction of the buttons when they are added to the collection.
|
This EventButtonCollection will handle the destruction of the buttons when they are added to the collection
|
||||||
|
|
||||||
********************************/
|
********************************/
|
||||||
class EventButtonCollection
|
class EventButtonCollection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EventButtonCollection();
|
EventButtonCollection(EventCollectionState state = EventCollectionState_Enabled);
|
||||||
~EventButtonCollection();
|
~EventButtonCollection();
|
||||||
|
|
||||||
void Update(InputClass* inputObject);
|
void Update(InputClass* inputObject);
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
template <typename Owner>
|
/*Add a button to the collection when a button is added to the collection you are not allowed to delete it.
|
||||||
void AddButton(EventButton<Owner>* button)
|
*/
|
||||||
|
template <typename Owner> void AddButton(EventButton<Owner>* button)
|
||||||
{
|
{
|
||||||
buttons.push_back(button);
|
buttons.push_back(button);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,11 @@ namespace Oyster
|
||||||
//Clear all buttons and reset the state.
|
//Clear all buttons and reset the state.
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
private:
|
||||||
|
//Can't copy
|
||||||
|
EventButtonCollection(const EventButtonCollection& obj);
|
||||||
|
EventButtonCollection& operator =(const EventButtonCollection& obj);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<IEventButton*> buttons;
|
std::vector<IEventButton*> buttons;
|
||||||
EventCollectionState collectionState;
|
EventCollectionState collectionState;
|
||||||
|
|
|
@ -23,6 +23,7 @@ EventHandler::~EventHandler()
|
||||||
for(int i = 0; i < size; i++)
|
for(int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
delete collections[i];
|
delete collections[i];
|
||||||
|
collections[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ void EventHandler::Clean()
|
||||||
for(int i = 0; i < size; i++)
|
for(int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
delete collections[i];
|
delete collections[i];
|
||||||
|
collections[i] = NULL;
|
||||||
}
|
}
|
||||||
collections.clear();
|
collections.clear();
|
||||||
}
|
}
|
||||||
|
@ -54,6 +56,12 @@ void EventHandler::Render()
|
||||||
|
|
||||||
void EventHandler::AddCollection(EventButtonCollection* collection)
|
void EventHandler::AddCollection(EventButtonCollection* collection)
|
||||||
{
|
{
|
||||||
|
for(int i = 0; i < collections.size(); i++)
|
||||||
|
{
|
||||||
|
//Do not add the collection if it's already in the list.
|
||||||
|
if(collections.at(i) == collection)
|
||||||
|
return;
|
||||||
|
}
|
||||||
collections.push_back(collection);
|
collections.push_back(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +72,7 @@ void EventHandler::DeleteCollection(EventButtonCollection* collection)
|
||||||
if(collections.at(i) == collection)
|
if(collections.at(i) == collection)
|
||||||
{
|
{
|
||||||
delete collection;
|
delete collection;
|
||||||
|
collection = NULL;
|
||||||
collections.erase(collections.begin() + i);
|
collections.erase(collections.begin() + i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,21 @@ namespace Oyster
|
||||||
void Update(InputClass* inputObject);
|
void Update(InputClass* inputObject);
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
|
/*Add a collection to the EventHandler will only add collections not already present in the list.
|
||||||
|
|
||||||
|
*/
|
||||||
void AddCollection(EventButtonCollection* collection);
|
void AddCollection(EventButtonCollection* collection);
|
||||||
void DeleteCollection(EventButtonCollection* collection);
|
void DeleteCollection(EventButtonCollection* collection);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//Can't copy this class.
|
||||||
|
EventHandler(const EventHandler& obj);
|
||||||
|
EventHandler& operator =(const EventHandler& obj);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<EventButtonCollection*> collections;
|
std::vector<EventButtonCollection*> collections;
|
||||||
|
|
||||||
|
//EventButtonCollection is a firend so it can delete it self.
|
||||||
friend class EventButtonCollection;
|
friend class EventButtonCollection;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue