diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 7f42f218..031f967f 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -224,6 +224,7 @@ + @@ -251,6 +252,7 @@ + diff --git a/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h index 380c73e1..d37b347e 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h @@ -21,6 +21,10 @@ namespace DanBias : pos(pos), size(size), text(text), textColor(textColor) { } + void setText(std::wstring text) + { + this->text = text; + } void RenderText() const { if(text.size() > 0) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 631f4399..078bc74b 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -11,6 +11,7 @@ #include "Utilities.h" #include "GamingUI.h" #include "RespawnUI.h" +#include "StatsUI.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -96,9 +97,11 @@ bool GameState::Init( SharedStateContent &shared ) // create UI states this->gameUI = new GamingUI(this->privData->input, this->privData->nwClient, &this->privData->camera); this->respawnUI = new RespawnUI(this->privData->nwClient, 20); + this->statsUI = new StatsUI(); this->currGameUI = gameUI; ((GamingUI*)gameUI)->Init(); - // TODO init respawn + ((RespawnUI*)respawnUI)->Init(); + ((StatsUI*)statsUI)->Init(); return true; } @@ -246,12 +249,24 @@ bool GameState::Render() //!RB DEBUG #endif - // render current UI state + Oyster::Graphics::API::StartGuiRender(); + // render gui elemnts if(currGameUI->HaveGUIRender()) currGameUI->RenderGUI(); + if(renderStats) + { + if(statsUI->HaveGUIRender()) + statsUI->RenderGUI(); + } + Oyster::Graphics::API::StartTextRender(); if(currGameUI->HaveTextRender()) currGameUI->RenderText(); - + if(renderStats) + { + if(statsUI->HaveTextRender()) + statsUI->RenderText(); + } + Oyster::Graphics::API::EndFrame(); return true; } @@ -298,6 +313,12 @@ bool GameState::Release() delete gameUI; gameUI = NULL; } + if(statsUI) + { + statsUI->Release(); + delete statsUI; + statsUI = NULL; + } currGameUI = NULL; return true; @@ -332,10 +353,33 @@ void GameState::ReadKeyInput() { this->renderWhireframe = !this->renderWhireframe; this->key_Wireframe_Toggle = true; + // DEBUG set you as dead when render wireframe + this->currGameUI = respawnUI; + // !DEBUG } } else + { this->key_Wireframe_Toggle = false; + // DEBUG set you as dead when render wireframe + this->currGameUI = gameUI; + // !DEBUG + } + + // toggle wire frame render + if( this->privData->input->IsKeyPressed(DIK_TAB) ) + { + if( !this->key_showStats ) + { + this->renderStats = true; + this->key_showStats = true; + } + } + else + { + this->renderStats = false; + this->key_showStats = false; + } } const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { @@ -356,8 +400,22 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState switch(ID) { case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectDamage: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectHealthStatus: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectDamage: + { + Protocol_ObjectDamage decoded(data); + if( this->privData->myId == decoded.object_ID ) + { + if(currGameUI == gameUI) + { + ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + } + } + } + return GameClientState::event_processed; + case protocol_Gameplay_ObjectHealthStatus: + { + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectPosition: { Protocol_ObjectPosition decoded(data); @@ -493,12 +551,34 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectRespawn: - this->currGameUI = this->gameUI; + case protocol_Gameplay_ObjectRespawn: + { + // set player pos + Protocol_ObjectRespawn decoded(data); + // move player. Remember to change camera + this->privData->camera.SetPosition( decoded.position ); + this->privData->player.setPos( decoded.position ); + this->privData->player.updateWorld(); + // RB DEBUG + this->privData->player.setRBPos ( decoded.position ); + this->privData->player.updateRBWorld(); + // !RB DEBUG + + this->currGameUI = this->gameUI; + } return GameClientState::event_processed; case protocol_Gameplay_ObjectDie: - this->currGameUI = this->respawnUI; - // set countdown + { + Protocol_ObjectDie decoded(data); + // if is this player. Remember to change camera + if( this->privData->myId == decoded.objectID ) + { + this->currGameUI = this->respawnUI; + // set countdown + ((RespawnUI*)currGameUI)->SetCountdown( decoded.seconds ); + } + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectDisconnectPlayer: { //Removes diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 5a9519ad..8342d558 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -32,13 +32,16 @@ namespace DanBias { namespace Client private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; - GameStateUI *currGameUI, *gameUI, *respawnUI; + GameStateUI *currGameUI, *gameUI, *respawnUI, *statsUI; // DEGUG KEYS bool key_Reload_Shaders; bool key_Wireframe_Toggle; bool renderWhireframe; + bool key_showStats; + bool renderStats; // !DEGUG KEYS + }; } } #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index b57aff5d..03840881 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -30,6 +30,7 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 * GamingUI::~GamingUI() { /* Do nothing */ } bool GamingUI::Init() { + // z value should be between 0.5 - 0.9 so that it will be behind other states // add textures and text this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f)); @@ -54,13 +55,11 @@ bool GamingUI::HaveTextRender() const void GamingUI::RenderGUI() const { - Oyster::Graphics::API::StartGuiRender(); this->plane->RenderTexture(); } void GamingUI::RenderText() const { - Oyster::Graphics::API::StartTextRender(); this->text->RenderText(); } @@ -73,7 +72,10 @@ bool GamingUI::Release() delete this->text; return true; } - +void GamingUI::SetHPtext( std::wstring hp ) +{ + this->text->setText(hp); +} void GamingUI::ReadKeyInput() { if( this->input->IsKeyPressed(DIK_W) ) diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h index af77fe0b..36e94262 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.h +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -22,11 +22,14 @@ namespace DanBias { namespace Client void RenderGUI() const; void RenderText() const; bool Release(); + void SetHPtext( std::wstring hp ); private: InputClass *input; ::Oyster::Network::NetworkClient *netClient; Camera_FPSV2 *camera; + + // TODO add multiple UI elements Text_UI* text; Plane_UI* plane; diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.cpp b/Code/Game/GameClient/GameClientState/RespawnUI.cpp index 4588d367..21732df6 100644 --- a/Code/Game/GameClient/GameClientState/RespawnUI.cpp +++ b/Code/Game/GameClient/GameClientState/RespawnUI.cpp @@ -3,6 +3,7 @@ using namespace ::DanBias::Client; using namespace ::Oyster::Network; using namespace ::Utility::Value; +using namespace ::Oyster::Math; RespawnUI::RespawnUI() : GameStateUI() @@ -17,13 +18,23 @@ RespawnUI::RespawnUI( NetworkClient *connection, float delay ) : { this->netClient = connection; this->countDown = delay; + this->text = nullptr; } RespawnUI::~RespawnUI() { /* Do nothing */ } +bool RespawnUI::Init() +{ + // z value should be between 0.5 - 0.9 so that it will be behind other states + // add textures and text + this->text = new Text_UI(L"DEAD", Float3(0.5f,0.0f,0.5f), Float2(0.2f,0.2f)); + return true; +} GameStateUI::UIState RespawnUI::Update( float deltaTime ) { this->countDown = Max( this->countDown - deltaTime, 0.0f ); + // countDown == 0 + // return UIState_gaming state; return this->nextState; } @@ -34,25 +45,32 @@ bool RespawnUI::HaveGUIRender() const bool RespawnUI::HaveTextRender() const { - return false; // TODO: change to true when we want UI elements like a chat window + return true; // TODO: change to true when we want UI elements like a chat window } void RespawnUI::RenderGUI() const { - // TODO: We need? + // TODO:BLOODY SCREEN } void RespawnUI::RenderText() const { + this->text->RenderText(); // TODO: Text countdown somewhere on screen would be nice } bool RespawnUI::Release() { // TODO: Release UI components here. + if(this->text) + delete this->text; return true; } +void RespawnUI::SetCountdown( float cd ) +{ + this->countDown = cd; + // this text should be rendered +} - diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.h b/Code/Game/GameClient/GameClientState/RespawnUI.h index c45616b7..6e5df64e 100644 --- a/Code/Game/GameClient/GameClientState/RespawnUI.h +++ b/Code/Game/GameClient/GameClientState/RespawnUI.h @@ -2,6 +2,8 @@ #define DANBIAS_CLIENT_RESPAWN_UI_H #include "GameStateUI.h" +#include "Buttons\Text_UI.h" +#include "Buttons\Plane_UI.h" namespace DanBias { namespace Client { @@ -10,18 +12,23 @@ namespace DanBias { namespace Client public: RespawnUI( ::Oyster::Network::NetworkClient *connection, float delay ); virtual ~RespawnUI(); + bool Init(); + // TODO countdown UIState Update( float deltaTime ); bool HaveGUIRender() const; bool HaveTextRender() const; void RenderGUI() const; void RenderText() const; bool Release(); + void SetCountdown( float cd ); private: ::Oyster::Network::NetworkClient *netClient; float countDown; + // TODO add multiple UI elements + Text_UI* text; RespawnUI(); }; } } diff --git a/Code/Game/GameClient/GameClientState/StatsUI.cpp b/Code/Game/GameClient/GameClientState/StatsUI.cpp new file mode 100644 index 00000000..ab07b89d --- /dev/null +++ b/Code/Game/GameClient/GameClientState/StatsUI.cpp @@ -0,0 +1,65 @@ +#include "StatsUI.h" +#include +#include "Utilities.h" + +using namespace ::DanBias::Client; +using namespace ::GameLogic; +using namespace ::Utility::Value; +using namespace ::Oyster::Math; + +StatsUI::StatsUI() : + GameStateUI() +{ + /* Should never be called! */ + this->plane = nullptr; + this->text = nullptr; +} + +StatsUI::~StatsUI() { /* Do nothing */ } +bool StatsUI::Init() +{ + // z value should be between 0.1 - 0.5 so that it will be in front of other states + // add textures and text for player stats + this->plane = new Plane_UI(L"box_tex.png", Float3(0.0f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); + this->text = new Text_UI(L"Stats", Float3(0.0f,0.0f,0.1f), Float2(0.1f,0.1f)); + + return true; +} +GameStateUI::UIState StatsUI::Update( float deltaTime ) +{ + return this->nextState; +} + +bool StatsUI::HaveGUIRender() const +{ + // Set true if UIstate have any plane to render + return true; +} + +bool StatsUI::HaveTextRender() const +{ + // Set true if UIstate have any text to render + return true; +} + +void StatsUI::RenderGUI() const +{ + // render all the planes + this->plane->RenderTexture(); +} + +void StatsUI::RenderText() const +{ + // render all the text + this->text->RenderText(); +} + +bool StatsUI::Release() +{ + // TODO: Release UI components here. + if(this->plane) + delete this->plane; + if(this->text) + delete this->text; + return true; +} diff --git a/Code/Game/GameClient/GameClientState/StatsUI.h b/Code/Game/GameClient/GameClientState/StatsUI.h new file mode 100644 index 00000000..589f956b --- /dev/null +++ b/Code/Game/GameClient/GameClientState/StatsUI.h @@ -0,0 +1,34 @@ +#ifndef DANBIAS_CLIENT_STATS_UI_H +#define DANBIAS_CLIENT_STATS_UI_H + +#include "GameStateUI.h" +#include "Buttons\Text_UI.h" +#include "Buttons\Plane_UI.h" + +namespace DanBias { namespace Client +{ + class StatsUI : public GameStateUI + { + public: + StatsUI(); + virtual ~StatsUI(); + bool Init(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + // TODO add function to add a new players statistics + // TODO add function to remove a players statistics + + private: + // TODO add multiple UI elements + // one for each player ingame + Text_UI* text; + Plane_UI* plane; + }; +} } + +#endif \ No newline at end of file