Textfield and Bunch of fixes
This commit is contained in:
parent
3b225ea054
commit
49fc55be60
|
@ -240,6 +240,7 @@
|
|||
<ClInclude Include="Include\DanBiasGame.h" />
|
||||
<ClInclude Include="GameClientState\LobbyState.h" />
|
||||
<ClInclude Include="GameClientState\C_Object.h" />
|
||||
<ClInclude Include="GameClientState\Buttons\TextField.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -1,30 +1,202 @@
|
|||
/********************************************************************
|
||||
* Created by Dan Andersson, 2014
|
||||
* Text field that allows multiple lines.
|
||||
*
|
||||
* Written by Dan Andersson, 2014
|
||||
********************************************************************/
|
||||
#include <string>
|
||||
#include "EventButtonGUI.h"
|
||||
#include "OysterMath.h"
|
||||
|
||||
#ifndef DANBIAS_CLIENT_TEXT_FIELD_H
|
||||
#define DANBIAS_CLIENT_TEXT_FIELD_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ButtonRectangle.h"
|
||||
#include "OysterMath.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
namespace DanBias { namespace Client
|
||||
{
|
||||
template <typename Owner>
|
||||
class TextField : public EventButtonGUI<Owner>
|
||||
template<typename Owner>
|
||||
class TextField : public ButtonRectangle<Owner>
|
||||
{
|
||||
public:
|
||||
::std::wstring text;
|
||||
|
||||
TextField( std::wstring textureName, Owner owner, ::Oyster::Math::Float3 centerPos, ::Oyster::Math::Float2 size );
|
||||
TextField();
|
||||
TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height );
|
||||
virtual ~TextField();
|
||||
|
||||
virtual void RenderText();
|
||||
|
||||
const ::std::wstring & operator[]( unsigned int i ) const;
|
||||
::std::wstring & operator[]( unsigned int i );
|
||||
|
||||
void SetTextHeight( ::Oyster::Math::Float h );
|
||||
void SetLineSpacing( ::Oyster::Math::Float ls );
|
||||
|
||||
void SetBottomAligned();
|
||||
void SetTopAligned();
|
||||
|
||||
unsigned int GetNumLines() const;
|
||||
unsigned int GetMaxLineLength() const;
|
||||
|
||||
void ReserveLines( unsigned int num );
|
||||
void ClearText();
|
||||
void AppendText( const ::std::wstring &text );
|
||||
|
||||
void PopBack();
|
||||
void PopFront();
|
||||
|
||||
private:
|
||||
::Oyster::Math::Float3 center;
|
||||
::Oyster::Math::Float2 reach;
|
||||
|
||||
bool isBottomAligned;
|
||||
::Oyster::Math::Float textHeight, lineSpacing;
|
||||
::std::vector<::std::wstring> lines;
|
||||
};
|
||||
|
||||
// IMPLEMENTATIONS //////////////////////////////////////////////////
|
||||
|
||||
template<typename Owner>
|
||||
TextField<Owner>::TextField()
|
||||
: ButtonRectangle()
|
||||
{
|
||||
this->textHeight = 0.025f;
|
||||
this->lineSpacing = 0.001f;
|
||||
this->isBottomAligned = true;
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
TextField<Owner>::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize )
|
||||
: ButtonRectangle( backgroundTexture, L"", textColor, owner, pos, size, resize )
|
||||
{
|
||||
this->textHeight = 0.025f;
|
||||
this->lineSpacing = 0.001f;
|
||||
this->isBottomAligned = true;
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
TextField<Owner>::~TextField() {}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::RenderText()
|
||||
{
|
||||
::Oyster::Math::Float lineStep = this->textHeight + this->lineSpacing;
|
||||
::Oyster::Math::Float2 rowSize = ::Oyster::Math::Float2( this->size.x, this->textHeight );
|
||||
|
||||
if( this->isBottomAligned )
|
||||
{
|
||||
::Oyster::Math::Float2 topLeft = this->pos;
|
||||
topLeft.y += this->size.y - lineStep;
|
||||
|
||||
auto line = this->lines.rbegin();
|
||||
for( ; line != this->lines.rend(); ++line )
|
||||
{
|
||||
if( topLeft.y - lineStep >= this->pos.y )
|
||||
{
|
||||
::Oyster::Graphics::API::RenderText( (*line), topLeft, rowSize, this->textColor );
|
||||
topLeft.y -= lineStep;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
::Oyster::Math::Float2 topLeft = this->pos;
|
||||
|
||||
auto line = this->lines.begin();
|
||||
for( ; line != this->lines.end(); ++line )
|
||||
{
|
||||
if( topLeft.y + lineStep < this->size.y )
|
||||
{
|
||||
::Oyster::Graphics::API::RenderText( (*line), topLeft, rowSize, this->textColor );
|
||||
topLeft.y += lineStep;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
const ::std::wstring & TextField<Owner>::operator[]( unsigned int i ) const
|
||||
{
|
||||
return this->lines[(::std::vector<::std::wstring>::size_type)i];
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
::std::wstring & TextField<Owner>::operator[]( unsigned int i )
|
||||
{
|
||||
return this->lines[(::std::vector<::std::wstring>::size_type)i];
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::SetTextHeight( ::Oyster::Math::Float h )
|
||||
{
|
||||
this->textHeight = h;
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::SetLineSpacing( ::Oyster::Math::Float ls )
|
||||
{
|
||||
this->lineSpacing = ls;
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::SetBottomAligned()
|
||||
{
|
||||
this->isBottomAligned = true;
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::SetTopAligned()
|
||||
{
|
||||
this->isBottomAligned = false;
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
unsigned int TextField<Owner>::GetNumLines() const
|
||||
{
|
||||
return (unsigned int)this->lines.size();
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::ReserveLines( unsigned int num )
|
||||
{
|
||||
this->lines.reserve( (::std::vector<::std::wstring>::size_type)num );
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::ClearText()
|
||||
{
|
||||
this->lines.resize( 0 );
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::AppendText( const ::std::wstring &text )
|
||||
{
|
||||
::std::vector<::std::wstring> split;
|
||||
split.reserve( 10 );
|
||||
::Utility::String::Split( split, text, L"\n", 0 );
|
||||
auto line = split.begin();
|
||||
for( ; line != split.end; ++line )
|
||||
{
|
||||
this->lines.push_back( (*line) );
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::PopBack()
|
||||
{
|
||||
this->lines.pop_back();
|
||||
}
|
||||
|
||||
template<typename Owner>
|
||||
void TextField<Owner>::PopFront()
|
||||
{
|
||||
::std::vector<::std::wstring>::size_type i = 0,
|
||||
n = this->lines.size() - 1;
|
||||
for( ; i < n; ++i )
|
||||
{
|
||||
this->lines[i] = this->lines[i+1];
|
||||
}
|
||||
|
||||
this->lines.pop_back();
|
||||
}
|
||||
} }
|
||||
|
||||
#endif
|
|
@ -49,39 +49,7 @@ bool GameState::Init(NetworkClient* nwClient)
|
|||
|
||||
GameState::gameStateState GameState::LoadGame()
|
||||
{
|
||||
// Oyster::Graphics::Definitions::Pointlight plight;
|
||||
// plight.Pos = Float3(315.0f, 0.0f ,5.0f);
|
||||
// plight.Color = Float3(0.9f,0.7f,0.2f);
|
||||
// plight.Radius = 100.0f;
|
||||
// plight.Bright = 0.9f;
|
||||
// Oyster::Graphics::API::AddLight(plight);
|
||||
// plight.Pos = Float3(10.0f,350.0f,5.0f);
|
||||
// plight.Color = Float3(0.9f,0.7f,0.3f);
|
||||
// plight.Radius = 200.0f;
|
||||
// plight.Bright = 0.7f;
|
||||
// Oyster::Graphics::API::AddLight(plight);
|
||||
// plight.Pos = Float3(350.0f,350.0f,5.0f);
|
||||
// plight.Color = Float3(0.9f,0.7f,0.3f);
|
||||
// plight.Radius = 200.0f;
|
||||
// plight.Bright = 0.7f;
|
||||
// Oyster::Graphics::API::AddLight(plight);
|
||||
// plight.Pos = Float3(10.0f,350.0f,350.0f);
|
||||
// plight.Color = Float3(0.9f,0.7f,0.3f);
|
||||
// plight.Radius = 200.0f;
|
||||
// plight.Bright = 0.7f;
|
||||
// Oyster::Graphics::API::AddLight(plight);
|
||||
// plight.Pos = Float3(10.0f,-15.0f,5.0f);
|
||||
// plight.Color = Float3(0.0f,0.0f,1.0f);
|
||||
// plight.Radius = 50.0f;
|
||||
// plight.Bright = 2.0f;
|
||||
//
|
||||
// Oyster::Graphics::API::AddLight(plight);
|
||||
//// LoadModels();
|
||||
// InitCamera(Float3(0.0f,0.0f,20.0f));
|
||||
// // hardcoded objects
|
||||
//// LoadModels();
|
||||
// Float3 startPos = Float3(0,0,20.0f);
|
||||
// InitCamera(startPos);
|
||||
|
||||
return gameStateState_playing;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "EventHandler\EventHandler.h"
|
||||
#include "Buttons\ButtonRectangle.h"
|
||||
#include "Buttons\TextField.h"
|
||||
|
||||
#include <GameServerAPI.h>
|
||||
#include <string>
|
||||
|
@ -28,12 +29,13 @@ struct LanMenuState::MyData
|
|||
GameClientState::ClientState nextState;
|
||||
NetworkClient *nwClient;
|
||||
Graphics::API::Texture background;
|
||||
EventButtonCollection button;
|
||||
::std::wstring connectIP;
|
||||
EventButtonCollection guiElements;
|
||||
|
||||
TextField<LanMenuState*> *connectIP;
|
||||
unsigned short connectPort;
|
||||
} privData;
|
||||
|
||||
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<GameClientState*>& e );
|
||||
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<LanMenuState*>& e );
|
||||
|
||||
LanMenuState::LanMenuState() {}
|
||||
|
||||
|
@ -52,16 +54,23 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient)
|
|||
|
||||
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
|
||||
|
||||
// create buttons
|
||||
ButtonRectangle<GameClientState*> *button;
|
||||
// create guiElements
|
||||
ButtonRectangle<LanMenuState*> *guiElements;
|
||||
//0.5f, 0.2f, 0.3f, 0.1f,
|
||||
guiElements = new ButtonRectangle<LanMenuState*>( L"earth_md.png", L"", Float3(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
|
||||
this->privData->guiElements.AddButton( guiElements );
|
||||
|
||||
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 );
|
||||
this->privData->connectIP = new TextField<LanMenuState*>( L"earth_md.png", Float3(1.0f), this, Float3(0.1f, 0.2f, 0.5f), Float2(0.45f, 0.1f), ResizeAspectRatio_Width );
|
||||
this->privData->connectIP->ReserveLines( 1 );
|
||||
(*this->privData->connectIP)[0] = L"127.0.0.1";
|
||||
this->privData->connectIP->SetTextHeight( 0.1f );
|
||||
this->privData->connectIP->SetLineSpacing( 0.0f );
|
||||
|
||||
// bind button collection to the singleton eventhandler
|
||||
EventHandler::Instance().AddCollection( &this->privData->button );
|
||||
this->privData->guiElements.AddButton( this->privData->connectIP );
|
||||
|
||||
// bind guiElements collection to the singleton eventhandler
|
||||
EventHandler::Instance().AddCollection( &this->privData->guiElements );
|
||||
|
||||
this->privData->connectIP = L"127.0.0.1";
|
||||
this->privData->connectPort = 15151;
|
||||
|
||||
return true;
|
||||
|
@ -88,7 +97,10 @@ bool LanMenuState::Render( )
|
|||
Graphics::API::StartGuiRender();
|
||||
|
||||
Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) );
|
||||
this->privData->button.Render();
|
||||
this->privData->guiElements.RenderTexture();
|
||||
|
||||
Graphics::API::StartTextRender();
|
||||
this->privData->guiElements.RenderText();
|
||||
|
||||
Graphics::API::EndFrame();
|
||||
return true;
|
||||
|
@ -106,7 +118,7 @@ void LanMenuState::ChangeState( ClientState next )
|
|||
{
|
||||
case GameClientState::ClientState_Lobby:
|
||||
// attempt to connect to lobby
|
||||
if( !this->privData->nwClient->Connect(this->privData->connectPort, this->privData->connectIP) )
|
||||
if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) )
|
||||
return;
|
||||
break;
|
||||
default: break;
|
||||
|
@ -115,7 +127,7 @@ void LanMenuState::ChangeState( ClientState next )
|
|||
this->privData->nextState = next;
|
||||
}
|
||||
|
||||
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<GameClientState*>& e )
|
||||
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<LanMenuState*>& e )
|
||||
{
|
||||
switch( e.state )
|
||||
{
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace Oyster
|
|||
public:
|
||||
virtual ~IEventButton(){}
|
||||
|
||||
virtual void Render() = 0;
|
||||
virtual void RenderTexture() = 0;
|
||||
virtual void RenderText() = 0;
|
||||
|
||||
virtual void Update(MouseInput& input) = 0;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue