Started adding GameUI

This commit is contained in:
lindaandersson 2014-02-20 16:35:49 +01:00
parent de70388dfb
commit d83e545e58
13 changed files with 290 additions and 227 deletions

View File

@ -226,6 +226,8 @@
<ClCompile Include="GameClientState\RespawnUI.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClientState\Buttons\Plane_UI.h" />
<ClInclude Include="GameClientState\Buttons\Text_UI.h" />
<ClInclude Include="GameClientState\Camera_Basic.h" />
<ClInclude Include="GameClientState\Buttons\ButtonEllipse.h" />
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>

View File

@ -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);
}
}

View File

@ -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

View File

@ -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

View File

@ -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;
}
}

View File

@ -3,6 +3,7 @@
#include "GameClientState.h"
#include "OysterMath.h"
#include <string>
#include "GameStateUI.h"
namespace DanBias { namespace Client
{
@ -31,6 +32,8 @@ namespace DanBias { namespace Client
private:
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
GameStateUI *currGameUI, *gameUI, *respawnUI;
};
} }
#endif

View File

@ -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"

View File

@ -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) )
{
if(!this->key_Jump)
{
this->netClient->Send( Protocol_PlayerJump() );
this->key_Jump = true;
}
}
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
}

View File

@ -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();

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>

View File

@ -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;

View File

@ -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];
}