diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index c084532d..7f42f218 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -226,6 +226,8 @@ + + diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - false + true $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index c14d24f2..e598a790 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -113,7 +113,7 @@ namespace DanBias { if(buttonText.size() > 0) { - Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, -0.001f), size, size.y * 0.5f, textColor); + Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, +0.001f), size, size.y * 0.5f, textColor); } } diff --git a/Code/Game/GameClient/GameClientState/Buttons/Plane_UI.h b/Code/Game/GameClient/GameClientState/Buttons/Plane_UI.h new file mode 100644 index 00000000..8293eeb1 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Buttons/Plane_UI.h @@ -0,0 +1,51 @@ +#ifndef DANBIAS_CLIENT_PLANE_UI_H +#define DANBIAS_CLIENT_PLANE_UI_H + +#include "DllInterfaces/GFXAPI.h" + +namespace DanBias +{ + namespace Client + { + class Plane_UI + { + public: + Plane_UI( ) + { + pos = Oyster::Math::Float3::null; + size = Oyster::Math::Float2::null; + tintColor = Oyster::Math::Float4(1); + texture = NULL; + } + Plane_UI( std::wstring textureName, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, Oyster::Math::Float4 tintColor = Oyster::Math::Float4(1)) + : pos(pos), size(size), tintColor(tintColor) + { + CreateTexture(textureName); + } + virtual ~Plane_UI() + { + Oyster::Graphics::API::DeleteTexture(texture); + texture = NULL; + } + void CreateTexture(std::wstring textureName) + { + //Create texture + texture = Oyster::Graphics::API::CreateTexture(textureName); + } + + virtual void RenderTexture() const + { + if(texture) + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, tintColor); + } + private: + Oyster::Math::Float3 pos; + Oyster::Math::Float2 size; + + Oyster::Graphics::API::Texture texture; + Oyster::Math::Float4 tintColor; + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h new file mode 100644 index 00000000..380c73e1 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h @@ -0,0 +1,41 @@ +#ifndef DANBIAS_CLIENT_TEXT_UI_H +#define DANBIAS_CLIENT_TEXT_UI_H + +#include "DllInterfaces/GFXAPI.h" + +namespace DanBias +{ + namespace Client + { + class Text_UI + { + public: + Text_UI( ) + { + pos = Oyster::Math::Float3::null; + size = Oyster::Math::Float2::null; + text = L""; + textColor = Oyster::Math::Float4(1); + } + Text_UI(std::wstring text, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, Oyster::Math::Float4 textColor = Oyster::Math::Float4(1)) + : pos(pos), size(size), text(text), textColor(textColor) + { + } + void RenderText() const + { + if(text.size() > 0) + { + Oyster::Graphics::API::RenderText(text, pos, size, size.y * 0.5f, textColor); + } + } + private: + Oyster::Math::Float3 pos; + Oyster::Math::Float2 size; + + std::wstring text; + Oyster::Math::Float4 textColor; + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 532bd29d..b5c779b6 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -9,6 +9,8 @@ #include "C_obj/C_DynamicObj.h" #include "C_obj/C_StaticObj.h" #include "Utilities.h" +#include "GamingUI.h" +#include "RespawnUI.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -107,6 +109,12 @@ bool GameState::Init( SharedStateContent &shared ) light->second->Render(); } + // 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->currGameUI = gameUI; + ((GamingUI*)gameUI)->Init(); + // TODO init respawn return true; } @@ -163,7 +171,22 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { - this->ReadKeyInput(); + GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime ); + switch (UIstate) + { + case DanBias::Client::GameStateUI::UIState_same: + break; + case DanBias::Client::GameStateUI::UIState_gaming: + break; + case DanBias::Client::GameStateUI::UIState_main_menu: + //this->privData->nextState = + break; + case DanBias::Client::GameStateUI::UIState_shut_down: + this->privData->nextState = ClientState_Quit; + break; + default: + break; + } return this->privData->nextState; } @@ -191,13 +214,6 @@ bool GameState::Render() } } - - /*auto light = this->privData->lights->begin(); - for( ; light != this->privData->lights->end(); ++light ) - { - light->second->Render(); - }*/ - #ifdef _DEBUG //RB DEBUG render wire frame if(this->privData->renderWhireframe) @@ -242,6 +258,12 @@ bool GameState::Render() //!RB DEBUG #endif + // render current UI state + if(currGameUI->HaveGUIRender()) + currGameUI->RenderGUI(); + if(currGameUI->HaveTextRender()) + currGameUI->RenderText(); + Oyster::Graphics::API::EndFrame(); return true; } @@ -275,6 +297,21 @@ bool GameState::Release() privData = NULL; } + + if(respawnUI) + { + respawnUI->Release(); + delete respawnUI; + respawnUI = NULL; + } + if(gameUI) + { + gameUI->Release(); + delete gameUI; + gameUI = NULL; + } + currGameUI = NULL; + return true; } @@ -283,151 +320,6 @@ void GameState::ChangeState( ClientState next ) this->privData->nextState = next; } -void GameState::ReadKeyInput() -{ - if( this->privData->input->IsKeyPressed(DIK_W) ) - { - //if(!this->privData->key_forward) - { - this->privData->nwClient->Send( Protocol_PlayerMovementForward() ); - this->privData->key_forward = true; - } - } - else - this->privData->key_forward = false; - - if( this->privData->input->IsKeyPressed(DIK_S) ) - { - //if( !this->privData->key_backward ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementBackward() ); - this->privData->key_backward = true; - } - } - else - this->privData->key_backward = false; - - if( this->privData->input->IsKeyPressed(DIK_A) ) - { - //if( !this->privData->key_strafeLeft ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementLeft() ); - this->privData->key_strafeLeft = true; - } - } - else - this->privData->key_strafeLeft = false; - - if( this->privData->input->IsKeyPressed(DIK_D) ) - { - //if( !this->privData->key_strafeRight ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); - this->privData->key_strafeRight = true; - } - } - else - this->privData->key_strafeRight = false; - - //send delta mouse movement - { - static const float mouseSensitivity = Radian( 1.0f ); - this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity ); - float yaw = this->privData->input->GetYaw(); - //if( yaw != 0.0f ) //This made the camera reset to a specific rotation. - { - this->privData->nwClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) ); - } - } - - // shoot - if( this->privData->input->IsKeyPressed(DIK_Z) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = true; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = false; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - if( this->privData->input->IsKeyPressed(DIK_X) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = true; - playerShot.utilityPressed = false; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - if( this->privData->input->IsKeyPressed(DIK_C) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = true; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - - // jump - if( this->privData->input->IsKeyPressed(DIK_SPACE) ) - { - if(!this->privData->key_Jump) - { - this->privData->nwClient->Send( Protocol_PlayerJump() ); - this->privData->key_Jump = true; - } - } - else - this->privData->key_Jump = false; - - - // DEGUG KEYS - - // Reload shaders - if( this->privData->input->IsKeyPressed(DIK_R) ) - { - if( !this->privData->key_Reload_Shaders ) - { -#ifdef _DEBUG - Graphics::API::ReloadShaders(); -#endif - this->privData->key_Reload_Shaders = true; - } - } - else - this->privData->key_Reload_Shaders = false; - - // toggle wire frame render - if( this->privData->input->IsKeyPressed(DIK_T) ) - { - if( !this->privData->key_Wireframe_Toggle ) - { - this->privData->renderWhireframe = !this->privData->renderWhireframe; - this->privData->key_Wireframe_Toggle = true; - } - } - else - this->privData->key_Wireframe_Toggle = false; - // !DEGUG KEYS - // TODO: implement sub-menu -} - const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) @@ -582,8 +474,13 @@ 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: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectDie: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectRespawn: + this->currGameUI = this->gameUI; + return GameClientState::event_processed; + case protocol_Gameplay_ObjectDie: + this->currGameUI = this->respawnUI; + // set countdown + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 8c5ca64e..8935481d 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -3,6 +3,7 @@ #include "GameClientState.h" #include "OysterMath.h" #include +#include "GameStateUI.h" namespace DanBias { namespace Client { @@ -31,6 +32,8 @@ namespace DanBias { namespace Client private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; + GameStateUI *currGameUI, *gameUI, *respawnUI; + }; } } #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.h b/Code/Game/GameClient/GameClientState/GameStateUI.h index 40350211..152a7f04 100644 --- a/Code/Game/GameClient/GameClientState/GameStateUI.h +++ b/Code/Game/GameClient/GameClientState/GameStateUI.h @@ -1,5 +1,5 @@ -#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H -#define DANBIAS_CLIENT_GAMECLIENTSTATE_H +#ifndef DANBIAS_CLIENT_GAMESTATEUI_H +#define DANBIAS_CLIENT_GAMESTATEUI_H #include "Utilities.h" #include "NetworkClient.h" diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 8ff43d88..3c4dd73c 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -6,6 +6,7 @@ using namespace ::DanBias::Client; using namespace ::Oyster::Network; using namespace ::GameLogic; using namespace ::Utility::Value; +using namespace ::Oyster::Math; GamingUI::GamingUI() : GameStateUI() @@ -14,6 +15,8 @@ GamingUI::GamingUI() : this->input = nullptr; this->netClient = nullptr; this->camera = nullptr; + this->plane = nullptr; + this->text = nullptr; } GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : @@ -25,35 +28,49 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 * } GamingUI::~GamingUI() { /* Do nothing */ } +bool GamingUI::Init() +{ + // 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)); + return true; +} GameStateUI::UIState GamingUI::Update( float deltaTime ) { + ReadKeyInput(); return this->nextState; } bool GamingUI::HaveGUIRender() const { - return false; // TODO: change to true when we want UI elements like a crosshair + return true; } bool GamingUI::HaveTextRender() const { - return false; // TODO: change to true when we want UI elements like a chat window + return true; } void GamingUI::RenderGUI() const { - // TODO: Render crosshairs and such here. Don't forget to adjust GamingUI::HaveGUIRender + Oyster::Graphics::API::StartGuiRender(); + this->plane->RenderTexture(); } void GamingUI::RenderText() const { - // TODO: Render chattext and such here. Don't forget to adjust GamingUI::HaveGUIRender + Oyster::Graphics::API::StartTextRender(); + this->text->RenderText(); } bool GamingUI::Release() { // TODO: Release UI components here. + if(this->plane) + delete this->plane; + if(this->text) + delete this->text; return true; } @@ -79,75 +96,107 @@ void GamingUI::ReadKeyInput() this->netClient->Send( Protocol_PlayerMovementRight() ); } -// if( this->input->IsKeyPressed(DIK_R) ) -// { -// if( !this->key_Reload_Shaders ) -// { -//#ifdef _DEBUG -// Graphics::API::ReloadShaders(); -//#endif -// this->key_Reload_Shaders = true; -// } -// } -// else -// this->key_Reload_Shaders = false; - - //send delta mouse movement +//send delta mouse movement { static const float mouseSensitivity = Radian( 1.0f ); this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity ); - this->netClient->Send( Protocol_PlayerLeftTurn(this->input->GetYaw() * mouseSensitivity) ); + float yaw = this->input->GetYaw(); + //if( yaw != 0.0f ) //This made the camera reset to a specific rotation. + { + this->netClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) ); + } } // shoot - //if( this->input->IsKeyPressed(DIK_Z) ) - //{ - // if( !this->key_Shoot ) - // { - // Protocol_PlayerShot playerShot; - // playerShot.primaryPressed = true; - // playerShot.secondaryPressed = false; - // playerShot.utilityPressed = false; - // this->netClient->Send( playerShot ); - // this->key_Shoot = true; - // } - //} - //else - // this->key_Shoot = false; - - //if( this->input->IsKeyPressed(DIK_X) ) - //{ - // if( !this->key_Shoot ) - // { - // Protocol_PlayerShot playerShot; - // playerShot.primaryPressed = false; - // playerShot.secondaryPressed = true; - // playerShot.utilityPressed = false; - // this->netClient->Send( playerShot ); - // this->key_Shoot = true; - // } - //} - //else - // this->key_Shoot = false; - - //if( this->input->IsKeyPressed(DIK_C) ) - //{ - // if( !this->key_Shoot ) - // { - // Protocol_PlayerShot playerShot; - // playerShot.primaryPressed = false; - // playerShot.secondaryPressed = false; - // playerShot.utilityPressed = true; - // this->netClient->Send( playerShot ); - // this->key_Shoot = true; - // } - //} - //else - // this->key_Shoot = false; + if( this->input->IsKeyPressed(DIK_Z) ) + { + if( !this->key_Shoot ) + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = true; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = false; + this->netClient->Send( playerShot ); + this->key_Shoot = true; + } + } + else + this->key_Shoot = false; + if( this->input->IsKeyPressed(DIK_X) ) + { + if( !this->key_Shoot ) + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = true; + playerShot.utilityPressed = false; + this->netClient->Send( playerShot ); + this->key_Shoot = true; + } + } + else + this->key_Shoot = false; + if( this->input->IsKeyPressed(DIK_C) ) + { + if( !this->key_Shoot ) + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = true; + this->netClient->Send( playerShot ); + this->key_Shoot = true; + } + } + else + this->key_Shoot = false; // jump if( this->input->IsKeyPressed(DIK_SPACE) ) { - this->netClient->Send( Protocol_PlayerJump() ); + if(!this->key_Jump) + { + this->netClient->Send( Protocol_PlayerJump() ); + this->key_Jump = true; + } } -} \ No newline at end of file + else + this->key_Jump = false; + + + // DEGUG KEYS + + // Reload shaders + if( this->input->IsKeyPressed(DIK_R) ) + { + if( !this->key_Reload_Shaders ) + { +#ifdef _DEBUG + Oyster::Graphics::API::ReloadShaders(); +#endif + this->key_Reload_Shaders = true; + } + } + else + this->key_Reload_Shaders = false; + + // toggle wire frame render + if( this->input->IsKeyPressed(DIK_T) ) + { + if( !this->key_Wireframe_Toggle ) + { + this->renderWhireframe = !this->renderWhireframe; + this->key_Wireframe_Toggle = true; + } + } + else + this->key_Wireframe_Toggle = false; + + if( this->input->IsKeyPressed(DIK_ESCAPE) ) + { + this->nextState = GameStateUI::UIState_shut_down; + } + // !DEGUG KEYS + // TODO: implement sub-menu +} + diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h index 9f93674b..2e7fa5fe 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.h +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -4,6 +4,8 @@ #include "GameStateUI.h" #include "L_inputClass.h" #include "Camera_FPSV2.h" +#include "Buttons\Text_UI.h" +#include "Buttons\Plane_UI.h" namespace DanBias { namespace Client { @@ -12,6 +14,7 @@ namespace DanBias { namespace Client public: GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera ); virtual ~GamingUI(); + bool Init(); UIState Update( float deltaTime ); bool HaveGUIRender() const; @@ -24,6 +27,22 @@ namespace DanBias { namespace Client InputClass *input; ::Oyster::Network::NetworkClient *netClient; Camera_FPSV2 *camera; + Text_UI* text; + Plane_UI* plane; + + bool key_forward; + bool key_backward; + bool key_strafeRight; + bool key_strafeLeft; + bool key_Shoot; + bool key_Jump; + + // DEGUG KEYS + bool key_Reload_Shaders; + bool key_Wireframe_Toggle; + bool renderWhireframe; + // !DEGUG KEYS + GamingUI(); void ReadKeyInput(); diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.user b/Code/OysterGraphics/OysterGraphics.vcxproj.user index 9a0b0ae0..3f030911 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.user +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.user @@ -1,6 +1,6 @@  - true + false \ No newline at end of file diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index b71be6d7..98642604 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -56,8 +56,8 @@ namespace Oyster //size.x = size.x / (text.length() * TEXT_SPACING /2); - pos *= 2; - pos -= 1; + pos.xy *= 2; + pos.xy -= 1; pos.y *= -1; diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 258d0f25..2d5790ab 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -40,4 +40,5 @@ void main( uint3 DTid : SV_DispatchThreadID ) //Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(Output.Length*0.5f)].xyz,1); //Output[DTid.xy] = SSAO * float4(1,1,1,1); + //Output[DTid.xy] = Ambient[DTid.xy]; } \ No newline at end of file