Danbias/Code/Game/GameClient/GameClientState/GamingUI.cpp

174 lines
3.6 KiB
C++
Raw Normal View History

2014-02-19 13:15:19 +01:00
#include "GamingUI.h"
#include <Protocols.h>
2014-02-19 14:00:36 +01:00
#include "Utilities.h"
2014-02-19 13:15:19 +01:00
using namespace ::DanBias::Client;
using namespace ::Oyster::Network;
using namespace ::GameLogic;
2014-02-19 14:00:36 +01:00
using namespace ::Utility::Value;
2014-02-20 16:35:49 +01:00
using namespace ::Oyster::Math;
2014-02-19 13:15:19 +01:00
GamingUI::GamingUI() :
GameStateUI()
{
/* Should never be called! */
this->input = nullptr;
this->netClient = nullptr;
this->camera = nullptr;
2014-02-20 16:35:49 +01:00
this->plane = nullptr;
this->text = nullptr;
2014-02-19 13:15:19 +01:00
}
GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) :
GameStateUI()
{
this->input = input;
this->netClient = connection;
this->camera = camera;
}
GamingUI::~GamingUI() { /* Do nothing */ }
2014-02-20 16:35:49 +01:00
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));
2014-02-19 13:15:19 +01:00
2014-02-20 16:35:49 +01:00
return true;
}
2014-02-19 13:15:19 +01:00
GameStateUI::UIState GamingUI::Update( float deltaTime )
{
2014-02-20 16:35:49 +01:00
ReadKeyInput();
2014-02-19 13:15:19 +01:00
return this->nextState;
}
bool GamingUI::HaveGUIRender() const
{
2014-02-20 16:35:49 +01:00
return true;
2014-02-19 13:15:19 +01:00
}
bool GamingUI::HaveTextRender() const
{
2014-02-20 16:35:49 +01:00
return true;
2014-02-19 13:15:19 +01:00
}
void GamingUI::RenderGUI() const
{
2014-02-20 16:35:49 +01:00
Oyster::Graphics::API::StartGuiRender();
this->plane->RenderTexture();
2014-02-19 13:15:19 +01:00
}
void GamingUI::RenderText() const
{
2014-02-20 16:35:49 +01:00
Oyster::Graphics::API::StartTextRender();
this->text->RenderText();
2014-02-19 13:15:19 +01:00
}
bool GamingUI::Release()
{
// TODO: Release UI components here.
2014-02-20 16:35:49 +01:00
if(this->plane)
delete this->plane;
if(this->text)
delete this->text;
2014-02-19 13:15:19 +01:00
return true;
}
void GamingUI::ReadKeyInput()
{
if( this->input->IsKeyPressed(DIK_W) )
{
this->netClient->Send( Protocol_PlayerMovementForward() );
}
if( this->input->IsKeyPressed(DIK_S) )
{
this->netClient->Send( Protocol_PlayerMovementBackward() );
}
if( this->input->IsKeyPressed(DIK_A) )
{
this->netClient->Send( Protocol_PlayerMovementLeft() );
}
if( this->input->IsKeyPressed(DIK_D) )
{
this->netClient->Send( Protocol_PlayerMovementRight() );
}
2014-02-20 16:35:49 +01:00
//send delta mouse movement
2014-02-19 13:15:19 +01:00
{
2014-02-19 14:00:36 +01:00
static const float mouseSensitivity = Radian( 1.0f );
this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity );
2014-02-20 16:35:49 +01:00
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) );
}
2014-02-19 13:15:19 +01:00
}
// shoot
2014-02-20 16:35:49 +01:00
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;
2014-02-19 13:15:19 +01:00
// jump
if( this->input->IsKeyPressed(DIK_SPACE) )
{
2014-02-20 16:35:49 +01:00
if(!this->key_Jump)
{
this->netClient->Send( Protocol_PlayerJump() );
this->key_Jump = true;
}
2014-02-19 13:15:19 +01:00
}
2014-02-20 16:35:49 +01:00
else
this->key_Jump = false;
if( this->input->IsKeyPressed(DIK_ESCAPE) )
{
this->nextState = GameStateUI::UIState_shut_down;
}
// !DEGUG KEYS
// TODO: implement sub-menu
}