2014-01-30 23:23:37 +01:00
|
|
|
#include "LanMenuState.h"
|
|
|
|
|
|
|
|
#include "C_obj/C_Player.h"
|
|
|
|
#include "C_obj/C_StaticObj.h"
|
|
|
|
#include "C_obj/C_DynamicObj.h"
|
|
|
|
#include "DllInterfaces/GFXAPI.h"
|
|
|
|
|
2014-01-31 14:14:20 +01:00
|
|
|
#include "LobbyState.h"
|
|
|
|
#include "GameState.h"
|
2014-02-12 10:43:06 +01:00
|
|
|
#include "../Network/NetworkAPI/NetworkClient.h"
|
2014-01-31 14:14:20 +01:00
|
|
|
|
2014-02-13 10:14:44 +01:00
|
|
|
#include "EventHandler\EventHandler.h"
|
|
|
|
#include "Buttons\ButtonRectangle.h"
|
2014-02-14 09:40:53 +01:00
|
|
|
#include "Buttons\TextField.h"
|
2014-02-13 10:14:44 +01:00
|
|
|
|
2014-01-30 23:23:37 +01:00
|
|
|
#include <GameServerAPI.h>
|
2014-02-13 10:14:44 +01:00
|
|
|
#include <string>
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-12 10:43:06 +01:00
|
|
|
using namespace ::DanBias::Client;
|
2014-02-12 16:31:15 +01:00
|
|
|
using namespace ::Oyster;
|
2014-02-12 10:43:06 +01:00
|
|
|
using namespace ::Oyster::Network;
|
2014-02-13 10:14:44 +01:00
|
|
|
using namespace ::Oyster::Event;
|
|
|
|
using namespace ::Oyster::Math3D;
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
struct LanMenuState::MyData
|
2014-01-30 23:23:37 +01:00
|
|
|
{
|
2014-02-12 16:31:15 +01:00
|
|
|
MyData(){}
|
2014-01-31 14:14:20 +01:00
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
GameClientState::ClientState nextState;
|
|
|
|
NetworkClient *nwClient;
|
2014-02-20 16:15:47 +01:00
|
|
|
::Input::Mouse *mouseInput;
|
2014-02-21 12:09:38 +01:00
|
|
|
::Input::Keyboard *keyboardInput;
|
2014-02-13 10:14:44 +01:00
|
|
|
Graphics::API::Texture background;
|
2014-02-14 09:40:53 +01:00
|
|
|
EventButtonCollection guiElements;
|
|
|
|
|
|
|
|
TextField<LanMenuState*> *connectIP;
|
2014-02-13 10:14:44 +01:00
|
|
|
unsigned short connectPort;
|
2014-02-12 09:49:08 +01:00
|
|
|
} privData;
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-14 09:40:53 +01:00
|
|
|
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<LanMenuState*>& e );
|
2014-02-14 14:31:01 +01:00
|
|
|
void OnButtonInteract_Exit( Oyster::Event::ButtonEvent<LanMenuState*>& e );
|
2014-02-13 10:14:44 +01:00
|
|
|
|
2014-02-12 09:49:08 +01:00
|
|
|
LanMenuState::LanMenuState() {}
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-13 10:14:44 +01:00
|
|
|
LanMenuState::~LanMenuState()
|
|
|
|
{
|
|
|
|
if( this->privData )
|
|
|
|
this->Release();
|
|
|
|
}
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-17 11:27:43 +01:00
|
|
|
bool LanMenuState::Init( SharedStateContent &shared )
|
2014-01-30 23:23:37 +01:00
|
|
|
{
|
2014-02-13 10:14:44 +01:00
|
|
|
this->privData = new MyData();
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
this->privData->nextState = GameClientState::ClientState_Same;
|
2014-02-17 11:27:43 +01:00
|
|
|
this->privData->nwClient = shared.network;
|
2014-02-20 16:15:47 +01:00
|
|
|
this->privData->mouseInput = shared.mouseDevice;
|
2014-02-21 12:09:38 +01:00
|
|
|
this->privData->keyboardInput = shared.keyboardDevice;
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-18 09:32:10 +01:00
|
|
|
this->privData->background = Graphics::API::CreateTexture( L"color_white.png" );
|
2014-02-13 10:14:44 +01:00
|
|
|
|
2014-02-14 09:40:53 +01:00
|
|
|
// create guiElements
|
2014-02-18 09:32:10 +01:00
|
|
|
this->privData->connectIP = new TextField<LanMenuState*>( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None );
|
2014-02-14 09:40:53 +01:00
|
|
|
this->privData->connectIP->ReserveLines( 1 );
|
2014-02-19 10:55:59 +01:00
|
|
|
this->privData->connectIP->AppendText( L"127.0.0.1" );
|
|
|
|
//this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server
|
2014-02-14 14:31:01 +01:00
|
|
|
this->privData->connectIP->SetFontHeight( 0.08f );
|
|
|
|
this->privData->connectIP->SetLineSpacing( 0.005f );
|
|
|
|
this->privData->connectIP->SetTopAligned();
|
2014-02-13 10:14:44 +01:00
|
|
|
|
2014-02-14 09:40:53 +01:00
|
|
|
this->privData->guiElements.AddButton( this->privData->connectIP );
|
2014-02-13 10:14:44 +01:00
|
|
|
|
2014-02-14 14:31:01 +01:00
|
|
|
ButtonRectangle<LanMenuState*> *guiElements;
|
2014-02-18 09:32:10 +01:00
|
|
|
guiElements = new ButtonRectangle<LanMenuState*>( L"color_white.png", L"Connect", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
|
2014-02-14 14:31:01 +01:00
|
|
|
this->privData->guiElements.AddButton( guiElements );
|
|
|
|
|
2014-02-18 09:32:10 +01:00
|
|
|
guiElements = new ButtonRectangle<LanMenuState*>( L"color_white.png", L"Exit", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
|
2014-02-14 14:31:01 +01:00
|
|
|
this->privData->guiElements.AddButton( guiElements );
|
|
|
|
|
2014-02-14 09:40:53 +01:00
|
|
|
// bind guiElements collection to the singleton eventhandler
|
|
|
|
EventHandler::Instance().AddCollection( &this->privData->guiElements );
|
2014-02-13 10:14:44 +01:00
|
|
|
|
|
|
|
this->privData->connectPort = 15151;
|
|
|
|
|
2014-02-20 16:15:47 +01:00
|
|
|
this->privData->keyboardInput->BindTextTarget( &(*this->privData->connectIP)[0] );
|
|
|
|
this->privData->keyboardInput->Activate();
|
|
|
|
|
2014-01-30 23:23:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-17 11:27:43 +01:00
|
|
|
GameClientState::ClientState LanMenuState::Update( float deltaTime )
|
2014-01-31 14:14:20 +01:00
|
|
|
{
|
2014-02-13 10:14:44 +01:00
|
|
|
MouseInput mouseState;
|
2014-01-31 14:14:20 +01:00
|
|
|
{
|
2014-02-20 16:15:47 +01:00
|
|
|
::Input::Struct::SAIPoint2D pos;
|
|
|
|
this->privData->mouseInput->GetPixelPosition( pos );
|
2014-01-31 14:14:20 +01:00
|
|
|
|
2014-02-20 16:15:47 +01:00
|
|
|
mouseState.x = pos.x;
|
|
|
|
mouseState.y = pos.y;
|
|
|
|
mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn );
|
|
|
|
}
|
2014-02-13 10:14:44 +01:00
|
|
|
EventHandler::Instance().Update( mouseState );
|
2014-01-31 14:14:20 +01:00
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
return this->privData->nextState;
|
2014-01-31 14:14:20 +01:00
|
|
|
}
|
|
|
|
|
2014-02-12 14:33:56 +01:00
|
|
|
bool LanMenuState::Render( )
|
2014-01-30 23:23:37 +01:00
|
|
|
{
|
2014-02-12 16:31:15 +01:00
|
|
|
Graphics::API::NewFrame();
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
Graphics::API::StartGuiRender();
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-14 12:09:59 +01:00
|
|
|
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
|
2014-02-14 09:40:53 +01:00
|
|
|
this->privData->guiElements.RenderTexture();
|
|
|
|
|
|
|
|
Graphics::API::StartTextRender();
|
|
|
|
this->privData->guiElements.RenderText();
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
Graphics::API::EndFrame();
|
2014-01-30 23:23:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LanMenuState::Release()
|
|
|
|
{
|
|
|
|
privData = NULL;
|
|
|
|
return true;
|
2014-02-12 16:31:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LanMenuState::ChangeState( ClientState next )
|
|
|
|
{
|
2014-02-13 10:14:44 +01:00
|
|
|
switch( next )
|
|
|
|
{
|
|
|
|
case GameClientState::ClientState_Lobby:
|
|
|
|
// attempt to connect to lobby
|
2014-02-17 14:33:11 +01:00
|
|
|
if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) )
|
|
|
|
return;
|
2014-02-13 10:14:44 +01:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
this->privData->nextState = next;
|
2014-02-13 10:14:44 +01:00
|
|
|
}
|
|
|
|
|
2014-02-14 09:40:53 +01:00
|
|
|
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<LanMenuState*>& e )
|
2014-02-13 10:14:44 +01:00
|
|
|
{
|
|
|
|
switch( e.state )
|
|
|
|
{
|
|
|
|
case ButtonState_Released:
|
2014-02-14 15:19:10 +01:00
|
|
|
e.owner->ChangeState( GameClientState::ClientState_Lobby );
|
2014-02-13 10:14:44 +01:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2014-02-14 14:31:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnButtonInteract_Exit( Oyster::Event::ButtonEvent<LanMenuState*>& e )
|
|
|
|
{
|
|
|
|
switch( e.state )
|
|
|
|
{
|
|
|
|
case ButtonState_Released:
|
|
|
|
e.owner->ChangeState( GameClientState::ClientState_Main );
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|