GL - mergeerror with button handling

This commit is contained in:
lindaandersson 2014-02-11 15:03:27 +01:00
commit 56205ff774
19 changed files with 309 additions and 155 deletions

View File

@ -215,6 +215,9 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClientRecieverFunc.h" />
<ClInclude Include="GameClientState\Buttons\ButtonCircle.h" />
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />
<ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" />
<ClInclude Include="GameClientState\Camera.h" />
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
<ClInclude Include="GameClientState\C_obj\C_Player.h" />

View File

@ -142,6 +142,9 @@ namespace DanBias
HRESULT DanBiasGame::Update(float deltaTime)
{
//Update menu buttons
EventHandler::Instance().Update(m_data->inputObj);
m_data->inputObj->Update();
if(m_data->serverOwner)

View File

@ -0,0 +1,62 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef DANBIAS_CLIENT_BUTTON_CIRCLE_H
#define DANBIAS_CLIENT_BUTTON_CIRCLE_H
#include "EventButtonGUI.h"
namespace DanBias
{
namespace Client
{
template <typename Owner>
class ButtonCircle : public EventButtonGUI<Owner>
{
public:
ButtonCircle()
: EventButtonGUI(), radius(0)
{}
ButtonCircle(std::wstring textureName, Owner owner, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, owner, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
ButtonCircle(std::wstring textureName, EventFunc func, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, func, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
ButtonCircle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, func, owner, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
ButtonCircle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight)
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius)
{}
~ButtonCircle()
{}
//Circle vs point collision
bool Collision(InputClass* inputObject)
{
//Should come from the InputClass
float xMouse = 2, yMouse = 2;
float xDiff = xMouse - xPos;
float yDiff = yMouse - yPos;
float length = (xDiff * xDiff) + (yDiff * yDiff);
if(length <= radius*radius)
{
return true;
}
return false;
}
protected:
float radius;
};
}
}
#endif

View File

@ -0,0 +1,57 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef DANBIAS_CLIENT_BUTTON_RECTANGLE_H
#define DANBIAS_CLIENT_BUTTON_RECTANGLE_H
#include "EventButtonGUI.h"
namespace DanBias
{
namespace Client
{
template <typename Owner>
class ButtonRectangle : public EventButtonGUI<Owner>
{
public:
ButtonRectangle()
: EventButtonGUI(), halfWidth(0), halfHeight(0)
{}
ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButtonGUI(textureName, owner, xPos, yPos, halfWidth, halfHeight)
{}
ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButtonGUI(textureName, func, xPos, yPos, halfWidth, halfHeight)
{}
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButtonGUI(textureName, func, owner, xPos, yPos, halfWidth, halfHeight)
{}
ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButtonGUI(textureName, func, owner, userData, xPos, yPos, halfWidth, halfHeight)
{}
~ButtonRectangle()
{}
//Circle vs point collision
bool Collision(InputClass* inputObject)
{
//Should come from the InputClass
float xMouse = 1, yMouse = 0;
if(xMouse >= xPos - halfWidth && xMouse <= xPos + halfWidth
&& yMouse >= yPos - halfHeight && yMouse <= yPos + halfHeight)
{
return true;
}
return false;
}
protected:
};
}
}
#endif

View File

@ -0,0 +1,64 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef DANBIAS_CLIENT_EVENT_BUTTON_GUI_H
#define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H
#include "../Misc/EventHandler/EventButton.h"
namespace DanBias
{
namespace Client
{
template <typename Owner>
class EventButtonGUI : public Oyster::Event::EventButton<Owner>
{
public:
EventButtonGUI()
: EventButton(), xPos(0), yPos(0), halfWidth(0), halfHeight(0), texture(NULL)
{}
EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{
CreateTexture(textureName);
}
EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(func), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{
CreateTexture(textureName);
}
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(func, owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{
CreateTexture(textureName);
}
EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(func, owner, userData), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{
CreateTexture(textureName);
}
~EventButtonGUI()
{}
void CreateTexture(std::wstring textureName)
{
//Create texture
}
virtual void Render()
{
//Render att xPos and yPos
//With halfWidth and halfHeight
}
protected:
float xPos, yPos;
float halfWidth, halfHeight;
void* texture;
};
}
}
#endif

View File

@ -19,9 +19,43 @@ struct LoginState::myData
// game client*
}privData;
#include "Buttons\ButtonCircle.h"
#include "Buttons\ButtonRectangle.h"
#include "../Misc/EventHandler/EventHandler.h"
using namespace Oyster::Event;
enum TestEnum
{
Create,
Options,
Exit,
};
LoginState::LoginState(void)
{
EventButtonCollection* collection = new EventButtonCollection;
EventHandler::Instance().AddCollection(collection);
collection->AddButton(new ButtonRectangle<LoginState*>(L"textureName.jpg", &LoginState::ButtonCallback, this, (void*)Options, 0.0f, 0.0f, 0.0f, 0.0f));
}
void LoginState::ButtonCallback(Oyster::Event::ButtonEvent<LoginState*>& e)
{
TestEnum type = TestEnum((int)e.userData);
switch(type)
{
case Create:
if(e.state == ButtonState_Released)
{
//Change to create state or something similar
}
break;
case Options:
break;
case Exit:
break;
}
}
LoginState::~LoginState(void)

View File

@ -5,6 +5,8 @@
#include "OysterMath.h"
#include "NetworkClient.h"
#include <string>
#include "../Misc/EventHandler/EventButton.h"
namespace DanBias
{
namespace Client
@ -24,6 +26,8 @@ namespace DanBias
bool InitCamera(Oyster::Math::Float3 startPos);
ClientState Update(float deltaTime, InputClass* KeyInput);
static void ButtonCallback(Oyster::Event::ButtonEvent<LoginState*>& e);
bool Render(float dt);
bool Release();
void Protocol(ProtocolStruct* protocol)override;

View File

@ -105,11 +105,37 @@ void Object::setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
}
Oyster::Math::Float3 Object::GetPosition()
{
return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos;
}
Oyster::Math::Float4x4 Object::GetOrientation()
{
return this->rigidBody->GetState().GetOrientation();
Oyster::Physics::ICustomBody::State state;
state = this->rigidBody->GetState();
return state.GetOrientation();
}
Oyster::Math::Float3 Object::GetPosition()
{
return this->position;
}
Oyster::Math::Float3 Object::GetRotation()
{
return this->rotation;
}
Oyster::Math::Float3 Object::GetScaling()
{
return this->scale;
}
void Object::SetPosition(Oyster::Math::Float3 position)
{
this->position = position;
}
void Object::SetRotation(Oyster::Math::Float3 rotation)
{
this->rotation = rotation;
}
void Object::SetScaling(Oyster::Math::Float3 scale)
{
this->scale = scale;
}

View File

@ -29,10 +29,17 @@ namespace GameLogic
OBJECT_TYPE GetObjectType() const;
void setID(int id);
int GetID() const;
Oyster::Math::Float3 GetPosition();
Oyster::Math::Float4x4 GetOrientation();
Oyster::Math::Float3 GetPosition();
Oyster::Math::Float3 GetRotation();
Oyster::Math::Float3 GetScaling();
void SetPosition(Oyster::Math::Float3 position);
void SetRotation(Oyster::Math::Float3 rotation);
void SetScaling(Oyster::Math::Float3 scale);
Oyster::Physics::ICustomBody* GetRigidBody();
void ApplyLinearImpulse(Oyster::Math::Float3 force);
@ -55,6 +62,11 @@ namespace GameLogic
static const Game* gameInstance;
Oyster::Math::Float3 currLook;
Oyster::Math::Float3 newLook;
Oyster::Math::Float3 position;
Oyster::Math::Float3 rotation;
Oyster::Math::Float3 scale;
};
}

View File

@ -62,6 +62,7 @@ namespace Oyster
void SendEvent(ButtonState state);
//Set
void SetEnabled(bool enable);
void SetUserData(void* data);
void SetEventFunc(EventFunc func);
void SetOwner(Owner owner);
@ -206,6 +207,13 @@ namespace Oyster
}
}
//Set if the button should be updated and collided with.
template <typename Owner>
void EventButton<Owner>::SetEnabled(bool enable)
{
this->privData.enabled = enable;
}
template <typename Owner>
void EventButton<Owner>::SetUserData(void* data)
{

View File

@ -1,64 +0,0 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef MISC_EVENT_BUTTON_CIRCLE_H
#define MISC_EVENT_BUTTON_CIRCLE_H
#include "EventButton.h"
#include "../../Input/L_inputClass.h"
namespace Oyster
{
namespace Event
{
template <typename Owner>
class EventButtonCircle : public EventButton<Owner>
{
public:
EventButtonCircle()
: EventButton(), xPos(0), yPos(0), radius(0)
{}
EventButtonCircle(Owner owner, float xPos, float yPos, float radius)
: EventButton(owner), xPos(xPos), yPos(yPos), radius(radius)
{}
EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& e), float xPos, float yPos, float radius)
: EventButton(EventFunc), xPos(xPos), yPos(yPos), radius(radius)
{}
EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& e), Owner owner, float xPos, float yPos, float radius)
: EventButton(EventFunc, owner), xPos(xPos), yPos(yPos), radius(radius)
{}
EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& e), Owner owner, void* userData, float xPos, float yPos, float radius)
: EventButton(EventFunc, owner, userData), xPos(xPos), yPos(yPos), radius(radius)
{}
~EventButtonCircle()
{}
//Circle vs point collision
bool Collision(InputClass* inputObject)
{
//Should come from the InputClass
float xMouse = 2, yMouse = 2;
float xDiff = xMouse - xPos;
float yDiff = yMouse - yPos;
float length = (xDiff * xDiff) + (yDiff * yDiff);
if(length <= radius*radius)
{
return true;
}
return false;
}
private:
float xPos, yPos;
float radius;
};
}
}
#endif

View File

@ -34,6 +34,17 @@ void EventButtonCollection::Update(InputClass* inputObject)
}
}
void EventButtonCollection::Render()
{
if(this->collectionState == EventCollectionState_Enabled)
{
for(int i = 0; i < (int)buttons.size(); i++)
{
buttons[i]->Render();
}
}
}
EventCollectionState EventButtonCollection::GetState() const
{
return collectionState;

View File

@ -27,6 +27,10 @@ namespace Oyster
EventCollectionState_Unknown = -1,
};
/********************************
This EventButtonCollection will handle the destruction of the buttons when they are added to the collection.
********************************/
class EventButtonCollection
{
public:
@ -34,6 +38,7 @@ namespace Oyster
~EventButtonCollection();
void Update(InputClass* inputObject);
void Render();
template <typename Owner>
void AddButton(EventButton<Owner>* button)
@ -47,7 +52,7 @@ namespace Oyster
//Clear all buttons and reset the state.
void Clear();
private:
protected:
std::vector<IEventButton*> buttons;
EventCollectionState collectionState;

View File

@ -1,60 +0,0 @@
//////////////////////////////////////
// Created by Pontus Fransson 2014 //
//////////////////////////////////////
#ifndef MISC_EVENT_BUTTON_RECTANGLE_H
#define MISC_EVENT_BUTTON_RECTANGLE_H
#include "EventButton.h"
#include "../../Input/L_inputClass.h"
namespace Oyster
{
namespace Event
{
template <typename Owner>
class EventButtonRectangle : public EventButton<Owner>
{
public:
EventButtonRectangle()
: EventButton(), xPos(0), yPos(0), halfWidth(0), halfHeight(0)
{}
EventButtonRectangle(Owner owner, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{}
EventButtonRectangle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& e), float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(EventFunc), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{}
EventButtonRectangle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& e), Owner owner, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(EventFunc, owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{}
EventButtonRectangle(void (*EventFunc)( Oyster::Event::ButtonEvent<Owner>& e), Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight)
: EventButton(EventFunc, owner, userData), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight)
{}
~EventButtonRectangle()
{}
//Circle vs point collision
bool Collision(InputClass* inputObject)
{
//Should come from the InputClass
float xMouse = 1, yMouse = 0;
if(xMouse >= xPos - halfWidth && xMouse <= xPos + halfWidth
&& yMouse >= yPos - halfHeight && yMouse <= yPos + halfHeight)
{
return true;
}
return false;
}
private:
float xPos, yPos;
float halfWidth, halfHeight;
};
}
}
#endif

View File

@ -34,14 +34,15 @@ void EventHandler::Update(InputClass* inputObject)
}
}
void EventHandler::AddCollection(EventButtonCollection& collection)
void EventHandler::Render()
{
collections.push_back(&collection);
for(int i = 0; i < (int)collections.size(); i++)
{
collections.at(i)->Render();
}
}
EventButtonCollection& EventHandler::CreateCollection()
void EventHandler::AddCollection(EventButtonCollection* collection)
{
EventButtonCollection* temp = new EventButtonCollection;
collections.push_back(temp);
return *temp;
collections.push_back(collection);
}

View File

@ -9,8 +9,6 @@
#include "EventButtonCollection.h"
#include "EventButton.h"
#include "EventButtonCircle.h"
#include "EventButtonRectangle.h"
#include <vector>
@ -27,9 +25,9 @@ namespace Oyster
static EventHandler& Instance();
void Update(InputClass* inputObject);
void Render();
void AddCollection(EventButtonCollection& collection);
EventButtonCollection& CreateCollection();
void AddCollection(EventButtonCollection* collection);
private:
std::vector<EventButtonCollection*> collections;

View File

@ -25,14 +25,12 @@ namespace Oyster
public:
virtual ~IEventButton(){}
virtual void Update(InputClass *input){}
virtual void Render() = 0;
virtual void Update(InputClass *input) = 0;
virtual void SendEvent(ButtonState state){}
struct ButtonEvent;
virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )){}
virtual void SendEvent(ButtonState state) = 0;
virtual unsigned int GetID(){ return -1; }
virtual unsigned int GetID() = 0;
};
}

View File

@ -167,9 +167,7 @@
<ItemGroup>
<ClInclude Include="DynamicArray.h" />
<ClInclude Include="EventHandler\EventButton.h" />
<ClInclude Include="EventHandler\EventButtonCircle.h" />
<ClInclude Include="EventHandler\EventButtonCollection.h" />
<ClInclude Include="EventHandler\EventButtonRectangle.h" />
<ClInclude Include="EventHandler\EventHandler.h" />
<ClInclude Include="EventHandler\IEventButton.h" />
<ClInclude Include="GID.h" />

View File

@ -134,11 +134,5 @@
<ClInclude Include="EventHandler\IEventButton.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventHandler\EventButtonCircle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventHandler\EventButtonRectangle.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>