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