diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 83806118..2a02099a 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -215,6 +215,9 @@ + + + diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index a286d2ff..587a3df1 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -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) diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonCircle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonCircle.h new file mode 100644 index 00000000..f399382d --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonCircle.h @@ -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 + class ButtonCircle : public EventButtonGUI + { + 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 \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h new file mode 100644 index 00000000..a77f5346 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h @@ -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 + class ButtonRectangle : public EventButtonGUI + { + 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 \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h new file mode 100644 index 00000000..598d594d --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h @@ -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 + class EventButtonGUI : public Oyster::Event::EventButton + { + 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 \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 276f4d6e..8744b611 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -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(L"textureName.jpg", &LoginState::ButtonCallback, this, (void*)Options, 0.0f, 0.0f, 0.0f, 0.0f)); +} + +void LoginState::ButtonCallback(Oyster::Event::ButtonEvent& 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) diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.h b/Code/Game/DanBiasGame/GameClientState/LoginState.h index e68d9527..a2079835 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.h +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.h @@ -5,6 +5,8 @@ #include "OysterMath.h" #include "NetworkClient.h" #include +#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& e); + bool Render(float dt); bool Release(); void Protocol(ProtocolStruct* protocol)override; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 6fbc8189..6e198e45 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -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; } \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 1098cb56..6e4b9a81 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -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; + }; } diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 64215da2..636552cc 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -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 + void EventButton::SetEnabled(bool enable) + { + this->privData.enabled = enable; + } + template void EventButton::SetUserData(void* data) { diff --git a/Code/Misc/EventHandler/EventButtonCircle.h b/Code/Misc/EventHandler/EventButtonCircle.h deleted file mode 100644 index 3a298acb..00000000 --- a/Code/Misc/EventHandler/EventButtonCircle.h +++ /dev/null @@ -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 - class EventButtonCircle : public EventButton - { - 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& e), float xPos, float yPos, float radius) - : EventButton(EventFunc), xPos(xPos), yPos(yPos), radius(radius) - {} - EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent& e), Owner owner, float xPos, float yPos, float radius) - : EventButton(EventFunc, owner), xPos(xPos), yPos(yPos), radius(radius) - {} - EventButtonCircle(void (*EventFunc)( Oyster::Event::ButtonEvent& 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 \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 6a77c520..4096bd44 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -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; diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 0cc77b42..56bb3d27 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -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 void AddButton(EventButton* button) @@ -47,7 +52,7 @@ namespace Oyster //Clear all buttons and reset the state. void Clear(); - private: + protected: std::vector buttons; EventCollectionState collectionState; diff --git a/Code/Misc/EventHandler/EventButtonRectangle.h b/Code/Misc/EventHandler/EventButtonRectangle.h deleted file mode 100644 index fc917437..00000000 --- a/Code/Misc/EventHandler/EventButtonRectangle.h +++ /dev/null @@ -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 - class EventButtonRectangle : public EventButton - { - 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& 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& 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& 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 \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index a7347075..7c7f7722 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -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); } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 4ca1a9ab..c58d628d 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -9,8 +9,6 @@ #include "EventButtonCollection.h" #include "EventButton.h" -#include "EventButtonCircle.h" -#include "EventButtonRectangle.h" #include @@ -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 collections; diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 901a8265..13e6f21b 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -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; }; } diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 593de858..efb3cc48 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -167,9 +167,7 @@ - - diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index c50f2804..edcf0e99 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -134,11 +134,5 @@ Header Files - - Header Files - - - Header Files - \ No newline at end of file