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-27 11:41:17 +01:00
|
|
|
using namespace ::Input::Enum;
|
2014-02-19 13:15:19 +01:00
|
|
|
|
|
|
|
GamingUI::GamingUI() :
|
|
|
|
GameStateUI()
|
|
|
|
{
|
|
|
|
/* Should never be called! */
|
2014-02-27 11:41:17 +01:00
|
|
|
this->sharedData = nullptr;
|
|
|
|
this->camera = nullptr;
|
|
|
|
this->plane = nullptr;
|
|
|
|
this->text = nullptr;
|
|
|
|
this->key_backward = false;
|
|
|
|
this->key_forward = false;
|
|
|
|
this->key_strafeLeft = false;
|
|
|
|
this->key_strafeRight = false;
|
2014-02-26 11:53:33 +01:00
|
|
|
this->nextState = GameStateUI::UIState_same;
|
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-27 11:41:17 +01:00
|
|
|
this->sharedData = shared;
|
|
|
|
this->camera = camera;
|
|
|
|
this->plane = nullptr;
|
|
|
|
this->text = nullptr;
|
|
|
|
this->key_backward = false;
|
|
|
|
this->key_forward = false;
|
|
|
|
this->key_strafeLeft = false;
|
|
|
|
this->key_strafeRight = false;
|
|
|
|
this->nextState = GameStateUI::UIState_same;
|
2014-02-19 13:15:19 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 11:41:17 +01:00
|
|
|
GamingUI::~GamingUI() { }
|
2014-02-20 16:35:49 +01:00
|
|
|
bool GamingUI::Init()
|
|
|
|
{
|
2014-02-21 10:49:02 +01:00
|
|
|
// 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();
|
2014-02-27 11:41:17 +01:00
|
|
|
this->sharedData->keyboardDevice->AddKeyboardEvent(this);
|
2014-02-25 16:42:51 +01:00
|
|
|
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()
|
|
|
|
{
|
2014-02-27 11:41:17 +01:00
|
|
|
//Release as input event
|
|
|
|
this->sharedData->keyboardDevice->RemoveKeyboardEvent(this);
|
|
|
|
this->sharedData->mouseDevice->RemoveMouseEvent(this);
|
|
|
|
|
2014-02-19 13:15:19 +01:00
|
|
|
// TODO: Release UI components here.
|
2014-02-27 11:41:17 +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;
|
|
|
|
}
|
2014-02-21 10:49:02 +01:00
|
|
|
void GamingUI::SetHPtext( std::wstring hp )
|
|
|
|
{
|
|
|
|
this->text->setText(hp);
|
|
|
|
}
|
2014-02-19 13:15:19 +01:00
|
|
|
void GamingUI::ReadKeyInput()
|
|
|
|
{
|
2014-02-27 11:41:17 +01:00
|
|
|
if( this->key_forward ) this->sharedData->network->Send( Protocol_PlayerMovementForward() );
|
|
|
|
if( this->key_backward ) this->sharedData->network->Send( Protocol_PlayerMovementBackward() );
|
|
|
|
if( this->key_strafeLeft ) this->sharedData->network->Send( Protocol_PlayerMovementLeft() );
|
|
|
|
if( this->key_strafeRight ) this->sharedData->network->Send( Protocol_PlayerMovementRight() );
|
2014-02-20 16:35:49 +01:00
|
|
|
}
|
|
|
|
|
2014-02-26 16:57:32 +01:00
|
|
|
void GamingUI::OnMousePress ( Input::Enum::SAMI key, Input::Mouse* sender )
|
|
|
|
{
|
|
|
|
switch ( key )
|
|
|
|
{
|
|
|
|
case ::Input::Enum::SAMI_MouseLeftBtn: // shoot
|
2014-02-27 08:19:50 +01:00
|
|
|
this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_PrimaryPress) );
|
2014-02-26 16:57:32 +01:00
|
|
|
break;
|
|
|
|
case ::Input::Enum::SAMI_MouseRightBtn:
|
2014-02-27 08:19:50 +01:00
|
|
|
this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_SecondaryPress) );
|
2014-02-26 16:57:32 +01:00
|
|
|
break;
|
2014-02-27 08:19:50 +01:00
|
|
|
case ::Input::Enum::SAMI_MouseMiddleBtn:
|
|
|
|
this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_UtilityPress) );
|
2014-02-26 16:57:32 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void GamingUI::OnMouseRelease ( Input::Enum::SAMI key, Input::Mouse* sender )
|
|
|
|
{
|
|
|
|
switch ( key )
|
|
|
|
{
|
2014-02-27 08:19:50 +01:00
|
|
|
case ::Input::Enum::SAMI_MouseLeftBtn: // shoot
|
|
|
|
this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_PrimaryRelease) );
|
|
|
|
break;
|
2014-02-26 16:57:32 +01:00
|
|
|
case ::Input::Enum::SAMI_MouseRightBtn:
|
2014-02-27 08:19:50 +01:00
|
|
|
this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_SecondaryRelease) );
|
|
|
|
break;
|
|
|
|
case ::Input::Enum::SAMI_MouseMiddleBtn:
|
|
|
|
this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_UtilityRelease) );
|
2014-02-26 16:57:32 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 16:42:51 +01:00
|
|
|
void GamingUI::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, Input::Mouse* sender )
|
|
|
|
{
|
|
|
|
//send delta mouse movement
|
2014-02-27 11:41:17 +01:00
|
|
|
this->camera->PitchDown( (-coordinate.y) * this->sharedData->mouseSensitivity );
|
|
|
|
//this->camera->YawLeft( (-coordinate.x) * this->sharedData->mouseSensitivity );
|
|
|
|
//if( deltaPos.x != 0.0f ) //This made the camera reset to a specific rotation. Why?
|
2014-02-25 16:42:51 +01:00
|
|
|
{
|
2014-02-27 11:41:17 +01:00
|
|
|
this->sharedData->network->Send( Protocol_PlayerLeftTurn((coordinate.x) * this->sharedData->mouseSensitivity, this->camera->GetLook()) );
|
2014-02-19 13:15:19 +01:00
|
|
|
}
|
2014-02-20 16:35:49 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 11:41:17 +01:00
|
|
|
void GamingUI::OnKeyPress(Enum::SAKI key, Keyboard* sender)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case SAKI_W: this->key_forward = true;
|
|
|
|
break;
|
|
|
|
case SAKI_S: this->key_backward = true;
|
|
|
|
break;
|
|
|
|
case SAKI_A: this->key_strafeLeft = true;
|
|
|
|
break;
|
|
|
|
case SAKI_D: this->key_strafeRight = true;
|
|
|
|
break;
|
|
|
|
case SAKI_Space: this->sharedData->network->Send( Protocol_PlayerJump() );
|
|
|
|
break;
|
|
|
|
case SAKI_Escape: this->nextState = GameStateUI::UIState_main_menu;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void GamingUI::OnKeyRelease(Enum::SAKI key, Keyboard* sender)
|
|
|
|
{
|
|
|
|
if(sender != this->sharedData->keyboardDevice) return;
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case SAKI_W: this->key_forward = false;
|
|
|
|
break;
|
|
|
|
case SAKI_S: this->key_backward = false;
|
|
|
|
break;
|
|
|
|
case SAKI_A: this->key_strafeLeft = false;
|
|
|
|
break;
|
|
|
|
case SAKI_D: this->key_strafeRight = false;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-27 13:09:45 +01:00
|
|
|
|
|
|
|
//DEBUG:
|
|
|
|
|
|
|
|
if(key == SAKI_L)
|
|
|
|
this->sharedData->mouseDevice->Deactivate();
|
|
|
|
if(key == SAKI_M)
|
|
|
|
this->sharedData->mouseDevice->Activate();
|
2014-02-27 11:41:17 +01:00
|
|
|
}
|
2014-02-26 14:07:46 +01:00
|
|
|
|