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

184 lines
4.4 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-25 16:42:51 +01:00
this->sharedData = nullptr;
this->camera = nullptr;
this->plane = nullptr;
this->text = nullptr;
2014-02-19 13:15:19 +01:00
}
2014-02-25 16:42:51 +01:00
GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) :
2014-02-19 13:15:19 +01:00
GameStateUI()
{
2014-02-25 16:42:51 +01:00
this->sharedData = shared;
2014-02-19 13:15:19 +01:00
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-25 16:42:51 +01:00
this->sharedData = sharedData;
2014-02-24 19:45:13 +01:00
// setting input mode to all raw
2014-02-25 16:42:51 +01:00
this->sharedData->keyboardDevice->Activate();
this->sharedData->mouseDevice->Activate();
this->sharedData->mouseDevice->AddMouseEvent(this);
2014-02-24 19:45:13 +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-25 16:42:51 +01:00
this->sharedData = 0;
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-25 16:42:51 +01:00
if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_W) )
2014-02-21 09:36:43 +01:00
{ // move forward
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( Protocol_PlayerMovementForward() );
2014-02-19 13:15:19 +01:00
}
2014-02-25 16:42:51 +01:00
if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_S) )
2014-02-21 09:36:43 +01:00
{ // move backward
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( Protocol_PlayerMovementBackward() );
2014-02-19 13:15:19 +01:00
}
2014-02-25 16:42:51 +01:00
if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_A) )
2014-02-21 09:36:43 +01:00
{ // strafe left
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( Protocol_PlayerMovementLeft() );
2014-02-19 13:15:19 +01:00
}
2014-02-25 16:42:51 +01:00
if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_D) )
2014-02-21 09:36:43 +01:00
{ // strafe right
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( Protocol_PlayerMovementRight() );
2014-02-19 13:15:19 +01:00
}
2014-02-25 16:42:51 +01:00
if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_Space) )
2014-02-21 09:36:43 +01:00
{ // jump
if(!this->key_Jump)
2014-02-20 16:35:49 +01:00
{
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( Protocol_PlayerJump() );
2014-02-21 09:36:43 +01:00
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-25 16:42:51 +01:00
if( this->sharedData->mouseDevice->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;
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( playerShot );
2014-02-20 16:35:49 +01:00
this->key_Shoot = true;
}
}
else
this->key_Shoot = false;
2014-02-21 09:36:43 +01:00
2014-02-25 16:42:51 +01:00
if( this->sharedData->mouseDevice->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;
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( playerShot );
2014-02-20 16:35:49 +01:00
this->key_Shoot = true;
}
}
else
this->key_Shoot = false;
2014-02-21 09:36:43 +01:00
2014-02-25 16:42:51 +01:00
if( this->sharedData->mouseDevice->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;
2014-02-25 16:42:51 +01:00
this->sharedData->network->Send( playerShot );
2014-02-20 16:35:49 +01:00
this->key_Shoot = true;
}
}
else
this->key_Shoot = false;
2014-02-19 13:15:19 +01:00
2014-02-25 16:42:51 +01:00
if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_Escape) )
2014-02-19 13:15:19 +01:00
{
2014-02-20 16:35:49 +01:00
this->nextState = GameStateUI::UIState_shut_down;
}
}
2014-02-21 09:36:43 +01:00
2014-02-25 16:42:51 +01:00
void GamingUI::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, Input::Mouse* sender )
{
//send delta mouse movement
{
this->camera->PitchDown( (-coordinate.y) * this->sharedData->mouseSensitivity );;
2014-02-21 09:36:43 +01:00
//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-25 16:42:51 +01:00
this->sharedData->network->Send( Protocol_PlayerLeftTurn((coordinate.x) * this->sharedData->mouseSensitivity, this->camera->GetLook()) );
2014-02-20 16:35:49 +01:00
}
2014-02-19 13:15:19 +01:00
}
2014-02-25 16:42:51 +01:00
}