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

150 lines
4.0 KiB
C++
Raw Normal View History

2014-02-13 13:30:14 +01:00
#include "LobbyAdminState.h"
#include "DllInterfaces/GFXAPI.h"
#include "OysterMath.h"
#include "C_obj/C_Player.h"
#include "C_obj/C_StaticObj.h"
#include "C_obj/C_DynamicObj.h"
#include <GameServerAPI.h>
#include <Protocols.h>
#include "EventHandler\EventHandler.h"
#include "Buttons\ButtonRectangle.h"
using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
using namespace ::Oyster::Event;
using namespace ::Oyster::Math3D;
struct LobbyAdminState::MyData
{
MyData(){}
GameClientState::ClientState nextState;
NetworkClient *nwClient;
2014-02-20 16:15:47 +01:00
::Input::Mouse *mouseInput;
2014-02-13 13:30:14 +01:00
Graphics::API::Texture background;
EventButtonCollection guiElements;
2014-02-13 13:30:14 +01:00
} privData;
void OnButtonInteract_Ready( Oyster::Event::ButtonEvent<LobbyAdminState*>& e );
2014-02-13 13:30:14 +01:00
LobbyAdminState::LobbyAdminState(void) {}
LobbyAdminState::~LobbyAdminState(void)
{
if( this->privData )
this->Release();
}
2014-02-17 11:27:43 +01:00
bool LobbyAdminState::Init( SharedStateContent &shared )
2014-02-13 13:30:14 +01:00
{
privData = new MyData();
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-13 13:30:14 +01:00
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
// create buttons
ButtonRectangle<LobbyAdminState*> *button;
2014-02-13 13:30:14 +01:00
button = new ButtonRectangle<LobbyAdminState*>( L"earth_md.png", L"Ready", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
this->privData->guiElements.AddButton( button );
2014-02-13 13:30:14 +01:00
// bind button collection to the singleton eventhandler
EventHandler::Instance().AddCollection( &this->privData->guiElements );
2014-02-13 13:30:14 +01:00
return true;
}
2014-02-17 11:27:43 +01:00
GameClientState::ClientState LobbyAdminState::Update( float deltaTime )
2014-02-13 13:30:14 +01:00
{
MouseInput mouseState;
{
2014-02-21 21:04:30 +01:00
::Input::Struct::SAIPointInt2D pos;
2014-02-20 16:15:47 +01:00
this->privData->mouseInput->GetPixelPosition( pos );
2014-02-13 13:30:14 +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 13:30:14 +01:00
EventHandler::Instance().Update( mouseState );
return this->privData->nextState;
}
bool LobbyAdminState::Render( )
{
Graphics::API::NewFrame();
Graphics::API::StartGuiRender();
2014-02-14 12:09:59 +01:00
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
this->privData->guiElements.RenderTexture();
Graphics::API::StartTextRender();
this->privData->guiElements.RenderText();
2014-02-13 13:30:14 +01:00
Graphics::API::EndFrame();
return true;
}
bool LobbyAdminState::Release()
{
privData = NULL;
return true;
}
void LobbyAdminState::ChangeState( ClientState next )
{
if( next == GameClientState::ClientState_LobbyReady )
{ // If all is ready start server
}
else
this->privData->nextState = next;
}
using namespace ::Oyster::Network;
const GameClientState::NetEvent & LobbyAdminState::DataRecieved( const GameClientState::NetEvent &message )
2014-02-13 13:30:14 +01:00
{
// fetching the id data.
short ID = message.args.data.protocol[0].value.netShort;
2014-02-13 13:30:14 +01:00
// Block irrelevant messages.
if( ProtocolIsLobby(ID) )
{
switch(ID)
{
2014-02-14 17:12:38 +01:00
case protocol_Lobby_CreateGame: break; /** @todo TODO: implement */
case protocol_Lobby_StartGame: break; /** @todo TODO: implement */
case protocol_Lobby_JoinGame: break; /** @todo TODO: implement */
case protocol_Lobby_Login: break; /** @todo TODO: implement */
case protocol_Lobby_Refresh: break; /** @todo TODO: implement */
case protocol_Lobby_ClientData: break; /** @todo TODO: implement */
case protocol_Lobby_GameData: break; /** @todo TODO: implement */
default: break;
2014-02-13 13:30:14 +01:00
}
}
else if( ProtocolIsGeneral(ID) )
{
switch( ID )
{
case protocol_General_Status: break; /** @todo TODO: implement */
case protocol_General_Text: break; /** @todo TODO: implement */
default: break;
}
}
return message;
2014-02-13 13:30:14 +01:00
}
void OnButtonInteract_Ready( Oyster::Event::ButtonEvent<LobbyAdminState*>& e )
2014-02-13 13:30:14 +01:00
{
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_LobbyReady );
break;
default: break;
}
}