Danbias/Code/Game/DanBiasGame/GameClientState/MainState.cpp

145 lines
3.5 KiB
C++
Raw Normal View History

2014-02-12 09:49:08 +01:00
#include "MainState.h"
2014-01-30 11:58:44 +01:00
#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>
2014-02-12 10:43:06 +01:00
#include "NetworkClient.h"
2014-01-30 11:58:44 +01:00
2014-02-12 14:33:56 +01:00
#include "EventHandler\EventHandler.h"
#include "Buttons\ButtonRectangle.h"
2014-02-12 10:43:06 +01:00
using namespace ::DanBias::Client;
2014-02-12 15:05:36 +01:00
using namespace ::Oyster;
2014-02-12 10:43:06 +01:00
using namespace ::Oyster::Math3D;
using namespace ::Oyster::Network;
2014-02-12 15:05:36 +01:00
using namespace ::Oyster::Event;
2014-02-12 10:43:06 +01:00
using namespace ::Utility::DynamicMemory;
2014-02-12 14:33:56 +01:00
using namespace ::Utility::StaticArray;
2014-01-30 11:58:44 +01:00
2014-02-12 10:43:06 +01:00
struct MainState::MyData
2014-01-30 11:58:44 +01:00
{
2014-02-12 10:43:06 +01:00
MyData() {}
2014-02-12 16:31:15 +01:00
GameClientState::ClientState nextState;
2014-02-12 10:43:06 +01:00
NetworkClient *nwClient;
2014-02-12 16:31:15 +01:00
Graphics::API::Texture background;
2014-02-12 14:33:56 +01:00
EventButtonCollection button;
2014-02-12 10:43:06 +01:00
};
2014-01-30 11:58:44 +01:00
2014-02-12 16:31:15 +01:00
void OnButtonInteract_Create( Oyster::Event::ButtonEvent<GameClientState*>& e );
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<GameClientState*>& e );
void OnButtonInteract_Quit( Oyster::Event::ButtonEvent<GameClientState*>& e );
2014-02-12 14:33:56 +01:00
2014-02-12 09:49:08 +01:00
MainState::MainState(void) {}
2014-01-30 11:58:44 +01:00
2014-02-12 16:31:15 +01:00
MainState::~MainState(void)
{
if( this->privData )
this->Release();
}
2014-01-30 11:58:44 +01:00
2014-02-12 10:43:06 +01:00
bool MainState::Init( NetworkClient* nwClient )
2014-01-30 11:58:44 +01:00
{
2014-02-12 10:43:06 +01:00
this->privData = new MyData();
2014-02-12 16:31:15 +01:00
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
2014-02-12 14:33:56 +01:00
// create buttons
2014-02-12 17:20:42 +01:00
ButtonRectangle<GameClientState*> *button;
button = new ButtonRectangle<GameClientState*>( L"earth_md.png", OnButtonInteract_Create, this, 0.5f, 0.2f, 0.1f, 0.3f, true );
this->privData->button.AddButton( button );
button = new ButtonRectangle<GameClientState*>( L"skysphere_md.png", OnButtonInteract_Join, this, 0.5f, 0.4f, 0.1f, 0.3f, true );
this->privData->button.AddButton( button );
button = new ButtonRectangle<GameClientState*>( L"plane_texture_md.png", OnButtonInteract_Quit, this, 0.5f, 0.8f, 0.1f, 0.3f, true );
2014-02-12 14:33:56 +01:00
this->privData->button.AddButton( button );
// bind button collection to the singleton eventhandler
EventHandler::Instance().AddCollection( &this->privData->button );
2014-01-30 11:58:44 +01:00
return true;
}
2014-02-12 09:49:08 +01:00
GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput)
2014-01-30 11:58:44 +01:00
{
2014-02-12 17:20:42 +01:00
EventHandler::Instance().Update( KeyInput );
2014-02-12 16:31:15 +01:00
return this->privData->nextState;
2014-01-30 11:58:44 +01:00
}
2014-02-12 09:49:08 +01:00
bool MainState::Render()
2014-01-30 11:58:44 +01:00
{
2014-02-12 15:05:36 +01:00
Graphics::API::NewFrame();
Graphics::API::StartGuiRender();
2014-01-30 11:58:44 +01:00
2014-02-12 16:31:15 +01:00
Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) );
this->privData->button.Render();
2014-01-30 11:58:44 +01:00
2014-02-12 15:05:36 +01:00
Graphics::API::EndFrame();
2014-01-30 11:58:44 +01:00
return true;
}
2014-02-12 09:49:08 +01:00
bool MainState::Release()
2014-01-30 11:58:44 +01:00
{
2014-02-12 17:20:42 +01:00
if( privData )
{
Graphics::API::DeleteTexture( this->privData->background );
2014-02-12 14:33:56 +01:00
2014-02-12 17:20:42 +01:00
privData = NULL;
// button collection will be autoreleased from EventHandler
}
2014-01-30 11:58:44 +01:00
return true;
}
2014-02-12 16:31:15 +01:00
void MainState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
2014-02-12 14:33:56 +01:00
/// button actions
2014-02-12 16:31:15 +01:00
//ButtonState_None, // onExit
//ButtonState_Hover,
//ButtonState_Pressed,
//ButtonState_Down,
//ButtonState_Released,
void OnButtonInteract_Create( Oyster::Event::ButtonEvent<GameClientState*>& e )
2014-02-12 14:33:56 +01:00
{
2014-02-12 16:31:15 +01:00
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_LobbyCreate );
break;
default: break;
}
}
2014-02-12 14:33:56 +01:00
2014-02-12 16:31:15 +01:00
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<GameClientState*>& e )
{
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_Lan );
break;
default: break;
}
2014-02-12 14:33:56 +01:00
}
2014-02-12 16:31:15 +01:00
void OnButtonInteract_Quit( Oyster::Event::ButtonEvent<GameClientState*>& e )
{
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_Quit );
break;
default: break;
}
}