2014-01-30 11:58:44 +01:00
|
|
|
#include "LoginState.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>
|
|
|
|
|
|
|
|
using namespace DanBias::Client;
|
|
|
|
|
2014-02-11 15:06:46 +01:00
|
|
|
//Menu buttons
|
2014-02-12 09:08:38 +01:00
|
|
|
#include "Buttons/ButtonEllipse.h"
|
2014-02-11 15:06:46 +01:00
|
|
|
#include "Buttons/ButtonRectangle.h"
|
|
|
|
#include "../Misc/EventHandler/EventHandler.h"
|
|
|
|
using namespace Oyster::Event;
|
|
|
|
|
2014-01-30 11:58:44 +01:00
|
|
|
struct LoginState::myData
|
|
|
|
{
|
|
|
|
myData(){}
|
|
|
|
Oyster::Math3D::Float4x4 view;
|
|
|
|
Oyster::Math3D::Float4x4 proj;
|
|
|
|
C_Object* object[2];
|
|
|
|
int modelCount;
|
|
|
|
// UI object
|
|
|
|
// game client*
|
2014-02-11 15:06:46 +01:00
|
|
|
|
|
|
|
//Menu button collection
|
|
|
|
EventButtonCollection* collection;
|
|
|
|
|
2014-02-12 09:08:38 +01:00
|
|
|
int testNumber;
|
2014-01-30 11:58:44 +01:00
|
|
|
}privData;
|
|
|
|
|
2014-02-11 14:13:35 +01:00
|
|
|
|
|
|
|
enum TestEnum
|
|
|
|
{
|
|
|
|
Create,
|
|
|
|
Options,
|
2014-02-12 09:08:38 +01:00
|
|
|
Incr,
|
|
|
|
Decr,
|
2014-02-11 14:13:35 +01:00
|
|
|
Exit,
|
|
|
|
};
|
|
|
|
|
2014-01-30 11:58:44 +01:00
|
|
|
LoginState::LoginState(void)
|
|
|
|
{
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoginState::ButtonCallback(Oyster::Event::ButtonEvent<LoginState*>& e)
|
|
|
|
{
|
|
|
|
TestEnum type = TestEnum((int)e.userData);
|
2014-01-30 11:58:44 +01:00
|
|
|
|
2014-02-11 14:13:35 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case Create:
|
2014-02-12 09:08:38 +01:00
|
|
|
/*if(e.state == ButtonState_None)
|
2014-02-11 14:13:35 +01:00
|
|
|
{
|
2014-02-12 09:08:38 +01:00
|
|
|
int a = 0;
|
|
|
|
std::cout << "None" << std::endl;
|
|
|
|
}
|
|
|
|
else if(e.state == ButtonState_Hover)
|
|
|
|
{
|
|
|
|
int a = 0;
|
|
|
|
std::cout << "Hover" << std::endl;
|
|
|
|
}
|
|
|
|
else if(e.state == ButtonState_Down)
|
|
|
|
{
|
|
|
|
int a = 0;
|
|
|
|
std::cout << "Down" << std::endl;
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
2014-02-12 09:08:38 +01:00
|
|
|
else if(e.state == ButtonState_Pressed)
|
|
|
|
{
|
|
|
|
int a = 0;
|
|
|
|
std::cout << "Pressed" << std::endl;
|
|
|
|
}
|
|
|
|
else if(e.state == ButtonState_Released)
|
|
|
|
{
|
|
|
|
//Change to create state or something similar
|
|
|
|
int a = 0;
|
|
|
|
std::cout << "Released" << std::endl;
|
|
|
|
}*/
|
2014-02-11 14:13:35 +01:00
|
|
|
break;
|
|
|
|
case Options:
|
|
|
|
break;
|
|
|
|
case Exit:
|
|
|
|
break;
|
2014-02-12 09:08:38 +01:00
|
|
|
|
|
|
|
case Incr:
|
|
|
|
if(e.state == ButtonState_Released)
|
|
|
|
e.owner->privData->testNumber++;
|
|
|
|
break;
|
|
|
|
case Decr:
|
|
|
|
if(e.state == ButtonState_Released)
|
|
|
|
e.owner->privData->testNumber--;
|
|
|
|
break;
|
2014-02-11 14:13:35 +01:00
|
|
|
}
|
2014-01-30 11:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LoginState::~LoginState(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
|
|
|
|
{
|
|
|
|
privData = new myData();
|
2014-02-12 09:08:38 +01:00
|
|
|
this->nwClient = nwClient;
|
2014-01-30 11:58:44 +01:00
|
|
|
// load models
|
2014-02-11 15:06:46 +01:00
|
|
|
//LoadModels(L"UImodels.txt");
|
2014-01-30 11:58:44 +01:00
|
|
|
InitCamera(Oyster::Math::Float3(0,0,5.4f));
|
2014-02-11 15:06:46 +01:00
|
|
|
|
|
|
|
//Create menu buttons
|
|
|
|
privData->collection = new EventButtonCollection;
|
|
|
|
EventHandler::Instance().AddCollection(privData->collection);
|
2014-02-12 09:08:38 +01:00
|
|
|
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.2f, 0.1f, 0.2f));
|
|
|
|
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.3f, 0.1f, 0.2f));
|
|
|
|
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.4f, 0.1f, 0.2f));
|
|
|
|
privData->collection->AddButton(new ButtonEllipse<LoginState*>(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.5f, 0.1f, 0.2f));
|
|
|
|
|
|
|
|
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.15f, 0.05f, 0.1f, 0.1f));
|
|
|
|
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.25f, 0.05f, 0.1f, 0.1f));
|
|
|
|
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.35f, 0.05f, 0.1f, 0.1f));
|
|
|
|
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.45f, 0.05f, 0.1f, 0.1f));
|
|
|
|
|
|
|
|
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f));
|
|
|
|
|
|
|
|
//Incr/decr buttons
|
|
|
|
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f));
|
|
|
|
privData->collection->AddButton(new ButtonRectangle<LoginState*>(L"button_", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f));
|
|
|
|
|
|
|
|
privData->testNumber = 0;
|
2014-02-11 15:06:46 +01:00
|
|
|
|
2014-01-30 11:58:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LoginState::LoadModels(std::wstring file)
|
|
|
|
{
|
|
|
|
Oyster::Graphics::Definitions::Pointlight plight;
|
2014-02-05 15:54:48 +01:00
|
|
|
plight.Pos = Oyster::Math::Float3(0,0,5);
|
2014-02-11 15:00:52 +01:00
|
|
|
plight.Color = Oyster::Math::Float3(1,0,1);
|
2014-02-05 11:46:04 +01:00
|
|
|
plight.Radius = 100;
|
2014-01-30 11:58:44 +01:00
|
|
|
plight.Bright = 1;
|
|
|
|
Oyster::Graphics::API::AddLight(plight);
|
|
|
|
// open file
|
|
|
|
// read file
|
|
|
|
// init models
|
|
|
|
privData->modelCount = 2;
|
|
|
|
|
|
|
|
ModelInitData modelData;
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
modelData.rotation = Oyster::Math::Quaternion::identity;
|
|
|
|
modelData.scale = Oyster::Math::Float3(1,1,1);
|
2014-01-30 11:58:44 +01:00
|
|
|
modelData.visible = true;
|
2014-02-10 14:41:43 +01:00
|
|
|
modelData.modelPath = L"box.dan";
|
2014-02-10 14:00:14 +01:00
|
|
|
|
2014-02-05 15:54:48 +01:00
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
modelData.position = Oyster::Math::Float3(2,2,2);
|
|
|
|
privData->object[0] = new C_StaticObj();
|
2014-01-30 11:58:44 +01:00
|
|
|
privData->object[0]->Init(modelData);
|
|
|
|
|
2014-02-10 14:41:43 +01:00
|
|
|
modelData.position = Oyster::Math::Float3(-2,0,-2);
|
2014-02-10 14:00:14 +01:00
|
|
|
privData->object[1] = new C_StaticObj();
|
2014-01-30 11:58:44 +01:00
|
|
|
privData->object[1]->Init(modelData);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoginState::InitCamera(Oyster::Math::Float3 startPos)
|
|
|
|
{
|
|
|
|
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
|
|
|
|
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
|
|
|
|
Oyster::Graphics::API::SetProjection(privData->proj);
|
|
|
|
|
|
|
|
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
|
|
|
|
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* KeyInput)
|
|
|
|
{
|
|
|
|
// picking
|
|
|
|
// mouse events
|
|
|
|
// different menus
|
|
|
|
// play sounds
|
|
|
|
// update animation
|
|
|
|
// send data to server
|
|
|
|
// check data from server
|
|
|
|
|
|
|
|
// create game
|
|
|
|
if( KeyInput->IsKeyPressed(DIK_C))
|
|
|
|
{
|
|
|
|
DanBias::GameServerAPI::ServerInitDesc desc;
|
|
|
|
|
|
|
|
DanBias::GameServerAPI::ServerInitiate(desc);
|
|
|
|
DanBias::GameServerAPI::ServerStart();
|
|
|
|
// my ip
|
2014-02-09 18:58:14 +01:00
|
|
|
nwClient->Connect(15152, "127.0.0.1");
|
2014-01-30 11:58:44 +01:00
|
|
|
|
|
|
|
if (!nwClient->IsConnected())
|
|
|
|
{
|
|
|
|
// failed to connect
|
|
|
|
return ClientState_Same;
|
|
|
|
}
|
2014-02-12 09:08:38 +01:00
|
|
|
privData->collection->SetState(EventCollectionState_Disabled);
|
2014-01-30 15:20:35 +01:00
|
|
|
return ClientState_LobbyCreated;
|
2014-01-30 11:58:44 +01:00
|
|
|
}
|
|
|
|
// join game
|
|
|
|
if( KeyInput->IsKeyPressed(DIK_J))
|
|
|
|
{
|
|
|
|
// game ip
|
2014-02-09 18:58:14 +01:00
|
|
|
nwClient->Connect(15152, "127.0.0.1");
|
2014-01-30 11:58:44 +01:00
|
|
|
|
|
|
|
if (!nwClient->IsConnected())
|
|
|
|
{
|
|
|
|
// failed to connect
|
|
|
|
return ClientState_Same;
|
|
|
|
}
|
2014-02-12 09:08:38 +01:00
|
|
|
privData->collection->SetState(EventCollectionState_Disabled);
|
2014-01-30 11:58:44 +01:00
|
|
|
return ClientState_Lobby;
|
|
|
|
}
|
|
|
|
return ClientState_Same;
|
|
|
|
}
|
2014-02-11 15:00:52 +01:00
|
|
|
bool LoginState::Render(float dt)
|
2014-01-30 11:58:44 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
Oyster::Graphics::API::SetView(privData->view);
|
|
|
|
Oyster::Graphics::API::SetProjection( privData->proj);
|
|
|
|
|
|
|
|
Oyster::Graphics::API::NewFrame();
|
|
|
|
// render objects
|
|
|
|
for (int i = 0; i < privData->modelCount; i++)
|
|
|
|
{
|
|
|
|
privData->object[i]->Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
// render effects
|
|
|
|
|
|
|
|
// render lights
|
|
|
|
|
2014-02-11 15:06:46 +01:00
|
|
|
//Render buttons
|
2014-02-12 09:08:38 +01:00
|
|
|
Oyster::Graphics::API::StartGuiRender();
|
2014-02-11 15:06:46 +01:00
|
|
|
EventHandler::Instance().Render();
|
|
|
|
|
2014-02-12 09:08:38 +01:00
|
|
|
std::wstring number;
|
|
|
|
wchar_t temp[10];
|
|
|
|
_itow_s(privData->testNumber, temp, 10);
|
|
|
|
number = temp;
|
|
|
|
Oyster::Graphics::API::StartTextRender();
|
|
|
|
Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7, 0.2), Oyster::Math::Float2(0.1, 0.1));
|
|
|
|
|
2014-01-30 11:58:44 +01:00
|
|
|
Oyster::Graphics::API::EndFrame();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool LoginState::Release()
|
|
|
|
{
|
2014-02-11 15:00:52 +01:00
|
|
|
Oyster::Graphics::API::ClearLights();
|
2014-01-30 11:58:44 +01:00
|
|
|
for (int i = 0; i < privData->modelCount; i++)
|
|
|
|
{
|
|
|
|
privData->object[i]->Release();
|
|
|
|
delete privData->object[i];
|
|
|
|
privData->object[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-12 09:08:38 +01:00
|
|
|
delete privData->collection;
|
|
|
|
//EventHandler::Instance().DeleteCollection(privData->collection);
|
|
|
|
|
2014-01-30 11:58:44 +01:00
|
|
|
delete privData;
|
|
|
|
privData = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void LoginState::Protocol(ProtocolStruct* protocol)
|
|
|
|
{
|
|
|
|
if((PlayerName*)protocol)
|
|
|
|
PlayerJoinProtocol((PlayerName*)protocol);
|
|
|
|
|
|
|
|
}
|
|
|
|
void LoginState::PlayerJoinProtocol(PlayerName* name)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|