Misc - Having problems with template with events.
This commit is contained in:
parent
6f264f5e7b
commit
9671eb8ee9
|
@ -13,7 +13,7 @@ namespace Oyster
|
||||||
template <typename owner>
|
template <typename owner>
|
||||||
class EventButton
|
class EventButton
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
struct ButtonEvent
|
struct ButtonEvent
|
||||||
{
|
{
|
||||||
IEventButton::ButtonState state;
|
IEventButton::ButtonState state;
|
||||||
|
@ -42,13 +42,16 @@ namespace Oyster
|
||||||
|
|
||||||
void CheckCollision(InputClass *input);
|
void CheckCollision(InputClass *input);
|
||||||
|
|
||||||
|
void SendEvent(IEventButton::ButtonState state);
|
||||||
|
|
||||||
void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //?
|
void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //?
|
||||||
|
|
||||||
unsigned int GetID();
|
unsigned int GetID();
|
||||||
owner& GetOwner();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename owner>
|
||||||
|
unsigned int EventButton<owner>::PrivData::currID = 0;
|
||||||
|
|
||||||
template <typename owner>
|
template <typename owner>
|
||||||
EventButton<owner>::EventButton()
|
EventButton<owner>::EventButton()
|
||||||
|
@ -73,7 +76,7 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
this->privData.ID = privData.currID;
|
this->privData.ID = privData.currID;
|
||||||
this->privData.currID += 1;
|
this->privData.currID += 1;
|
||||||
this->privData.owner = NULL;
|
//this->privData.owner = NULL;
|
||||||
this->privData.EventFunc = EventFunc;
|
this->privData.EventFunc = EventFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +99,17 @@ namespace Oyster
|
||||||
void EventButton<owner>::CheckCollision(InputClass *input)
|
void EventButton<owner>::CheckCollision(InputClass *input)
|
||||||
{
|
{
|
||||||
//??????????????? TODO: everything
|
//??????????????? TODO: everything
|
||||||
|
SendEvent(Button_Smashed);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename owner>
|
||||||
|
void EventButton<owner>::SendEvent(IEventButton::ButtonState state)
|
||||||
|
{
|
||||||
|
ButtonEvent event;
|
||||||
|
event.state = state;
|
||||||
|
event.sender = this;
|
||||||
|
event.owner = privData.owner;
|
||||||
|
privData.EventFunc(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename owner>
|
template <typename owner>
|
||||||
|
@ -109,13 +123,8 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
return this->privData.ID;
|
return this->privData.ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename owner>
|
|
||||||
owner& EventButton<owner>::GetOwner()
|
|
||||||
{
|
|
||||||
return this->privData.owner;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -23,16 +23,16 @@ void EventButtonCollection::Update(InputClass* inputObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Owner>
|
template <class Owner>
|
||||||
void EventButtonCollection::AddButton(EventButton<Owner>& button)
|
void EventButtonCollection::AddButton(Owner a)
|
||||||
{
|
{
|
||||||
buttons.push_back(button);
|
//buttons.push_back(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Owner>
|
template <class Owner>
|
||||||
EventButton<Owner>& EventButtonCollection::CreateButton()
|
EventButton<Owner>& EventButtonCollection::CreateButton()
|
||||||
{
|
{
|
||||||
EventButton temp;
|
EventButton temp;
|
||||||
buttons.push_back(&temp);
|
buttons.push_back((IEventButton)&temp);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace Oyster
|
||||||
void Update(InputClass* inputObject);
|
void Update(InputClass* inputObject);
|
||||||
|
|
||||||
template <class Owner>
|
template <class Owner>
|
||||||
void AddButton(EventButton<Owner>& button);
|
void AddButton(Owner a);
|
||||||
|
|
||||||
template <class Owner>
|
template <class Owner>
|
||||||
EventButton<Owner>& CreateButton();
|
EventButton<Owner>& CreateButton();
|
||||||
|
|
|
@ -21,6 +21,8 @@ namespace Oyster
|
||||||
|
|
||||||
virtual void CheckCollision(InputClass *input) = 0;
|
virtual void CheckCollision(InputClass *input) = 0;
|
||||||
|
|
||||||
|
virtual void SendEvent(IEventButton::ButtonState state) = 0;
|
||||||
|
|
||||||
struct ButtonEvent;
|
struct ButtonEvent;
|
||||||
virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0;
|
virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue