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

180 lines
4.1 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-20 16:55:34 +01:00
using namespace ::Input;
2014-02-19 13:15:19 +01:00
GamingUI::GamingUI() :
GameStateUI()
{
/* Should never be called! */
2014-02-20 16:55:34 +01:00
this->mouseInput = nullptr;
this->keyboardInput = nullptr;
2014-02-19 13:15:19 +01:00
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
}
2014-02-20 16:55:34 +01:00
GamingUI::GamingUI( Mouse *mouseInput, Keyboard *keyboardInput, NetworkClient *connection, Camera_FPSV2 *camera ) :
2014-02-19 13:15:19 +01:00
GameStateUI()
{
2014-02-20 16:55:34 +01:00
this->mouseInput = mouseInput;
this->keyboardInput = keyboardInput;
2014-02-19 13:15:19 +01:00
this->netClient = connection;
this->camera = camera;
}
GamingUI::~GamingUI() { /* Do nothing */ }
2014-02-20 16:35:49 +01:00
bool GamingUI::Init()
{
// z value should be between 0.5 - 0.9 so that it will be behind other states
2014-02-20 16:35:49 +01:00
// 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
this->plane->RenderTexture();
2014-02-19 13:15:19 +01:00
}
void GamingUI::RenderText() const
{
2014-02-20 16:35:49 +01:00
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::SetHPtext( std::wstring hp )
{
this->text->setText(hp);
}
2014-02-19 13:15:19 +01:00
void GamingUI::ReadKeyInput()
{
2014-02-21 09:36:43 +01:00
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_W) )
{ // move forward
2014-02-19 13:15:19 +01:00
this->netClient->Send( Protocol_PlayerMovementForward() );
}
2014-02-21 09:36:43 +01:00
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_S) )
{ // move backward
2014-02-19 13:15:19 +01:00
this->netClient->Send( Protocol_PlayerMovementBackward() );
}
2014-02-21 09:36:43 +01:00
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_A) )
{ // strafe left
2014-02-19 13:15:19 +01:00
this->netClient->Send( Protocol_PlayerMovementLeft() );
}
2014-02-21 09:36:43 +01:00
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_D) )
{ // strafe right
2014-02-19 13:15:19 +01:00
this->netClient->Send( Protocol_PlayerMovementRight() );
}
2014-02-21 09:36:43 +01:00
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_Space) )
{ // jump
if(!this->key_Jump)
2014-02-20 16:35:49 +01:00
{
2014-02-21 09:36:43 +01:00
this->netClient->Send( Protocol_PlayerJump() );
this->key_Jump = true;
2014-02-20 16:35:49 +01:00
}
2014-02-19 13:15:19 +01:00
}
2014-02-21 09:36:43 +01:00
else
this->key_Jump = false;
2014-02-19 13:15:19 +01:00
// shoot
2014-02-21 09:36:43 +01:00
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseLeftBtn) )
2014-02-20 16:35:49 +01:00
{
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;
2014-02-21 09:36:43 +01:00
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseRightBtn) )
2014-02-20 16:35:49 +01:00
{
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;
2014-02-21 09:36:43 +01:00
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseMiddleBtn) )
2014-02-20 16:35:49 +01:00
{
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
2014-02-21 09:36:43 +01:00
//send delta mouse movement
2014-02-19 13:15:19 +01:00
{
2014-02-21 09:36:43 +01:00
static const float mouseSensitivity = Radian( 1.0f );
::Input::Struct::SAIPoint2D deltaPos;
this->mouseInput->GetDeltaPosition( deltaPos );
this->camera->PitchDown( deltaPos.y * mouseSensitivity );;
//if( deltaPos.x != 0.0f ) //This made the camera reset to a specific rotation. Why?
2014-02-20 16:35:49 +01:00
{
2014-02-21 09:36:43 +01:00
this->netClient->Send( Protocol_PlayerLeftTurn(deltaPos.x * mouseSensitivity) );
2014-02-20 16:35:49 +01:00
}
2014-02-19 13:15:19 +01:00
}
2014-02-20 16:35:49 +01:00
2014-02-21 09:36:43 +01:00
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_Escape) )
2014-02-20 16:35:49 +01:00
{
this->nextState = GameStateUI::UIState_shut_down;
}
}