GL - Eventhandler does not delete collections any more.

This commit is contained in:
Pontus Fransson 2014-02-12 15:12:01 +01:00
parent b95e1d6b7a
commit b9c4fe1849
5 changed files with 27 additions and 39 deletions

View File

@ -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;

View File

@ -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<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f));
//privData->collection = new EventButtonCollection;
EventHandler::Instance().AddCollection(&privData->collection);
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.2f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.3f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.4f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", &LoginState::ButtonCallback, this, (void*)Options, 0.2f, 0.5f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.15f, 0.05f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.25f, 0.05f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.35f, 0.05f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Options, 0.45f, 0.05f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f));
//Incr/decr buttons
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f));
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f));
//Incr/decr buttons .
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(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;

View File

@ -20,6 +20,7 @@ EventButtonCollection::~EventButtonCollection()
if(EventHandler::Instance().collections.at(i) == this)
{
EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i);
break;
}
}

View File

@ -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;
}

View File

@ -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<EventButtonCollection*> collections;
//EventButtonCollection is a firend so it can delete it self.
//EventButtonCollection is a friend so it can delete it self.
friend class EventButtonCollection;
};
}