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-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-13 10:14:44 +01:00
|
|
|
Graphics::API::Texture background;
|
|
|
|
EventButtonCollection button;
|
|
|
|
::std::wstring connectIP;
|
|
|
|
unsigned short connectPort;
|
2014-02-12 09:49:08 +01:00
|
|
|
} privData;
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-13 10:14:44 +01:00
|
|
|
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<GameClientState*>& e );
|
|
|
|
|
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-12 16:31:15 +01:00
|
|
|
bool LanMenuState::Init(Network::NetworkClient* nwClient)
|
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;
|
|
|
|
this->privData->nwClient = nwClient;
|
2014-01-30 23:23:37 +01:00
|
|
|
|
2014-02-13 10:14:44 +01:00
|
|
|
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
|
|
|
|
|
|
|
|
// create buttons
|
|
|
|
ButtonRectangle<GameClientState*> *button;
|
|
|
|
|
|
|
|
button = new ButtonRectangle<GameClientState*>( L"earth_md.png", OnButtonInteract_Connect, this, 0.5f, 0.2f, 0.3f, 0.1f, true );
|
|
|
|
this->privData->button.AddButton( button );
|
|
|
|
|
|
|
|
// bind button collection to the singleton eventhandler
|
|
|
|
EventHandler::Instance().AddCollection( &this->privData->button );
|
|
|
|
|
|
|
|
this->privData->connectIP = L"127.0.0.1";
|
|
|
|
this->privData->connectPort = 15151;
|
|
|
|
|
2014-01-30 23:23:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* KeyInput)
|
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-13 10:14:44 +01:00
|
|
|
mouseState.x = KeyInput->GetPitch();
|
|
|
|
mouseState.y = KeyInput->GetYaw();
|
|
|
|
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
|
2014-01-31 14:14:20 +01:00
|
|
|
}
|
|
|
|
|
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-13 10:14:44 +01:00
|
|
|
Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) );
|
|
|
|
this->privData->button.Render();
|
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
|
|
|
|
if( !this->privData->nwClient->Connect(this->privData->connectPort, this->privData->connectIP) )
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
this->privData->nextState = next;
|
2014-02-13 10:14:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<GameClientState*>& e )
|
|
|
|
{
|
|
|
|
switch( e.state )
|
|
|
|
{
|
|
|
|
case ButtonState_Released:
|
|
|
|
e.owner->ChangeState( GameClientState::ClientState_LobbyCreate );
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2014-01-30 23:23:37 +01:00
|
|
|
}
|