From 3b225ea054dab39a92592ee05f8018ecee247eb4 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 13 Feb 2014 15:32:54 +0100 Subject: [PATCH 1/4] Merge --- .../GameClientState/Buttons/ButtonEllipse.h | 20 ++--- .../GameClientState/Buttons/ButtonRectangle.h | 24 +++--- .../GameClientState/Buttons/EventButtonGUI.h | 76 +++++++++++++------ .../EventHandler/EventButtonCollection.cpp | 15 +++- .../Misc/EventHandler/EventButtonCollection.h | 3 +- Code/Misc/EventHandler/EventHandler.cpp | 12 ++- Code/Misc/EventHandler/EventHandler.h | 3 +- Code/Network/NetworkAPI/NetworkClient.cpp | 14 ++++ Code/Network/NetworkAPI/NetworkClient.h | 5 ++ 9 files changed, 122 insertions(+), 50 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h index 5570fb2f..a922f141 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -21,17 +21,17 @@ namespace DanBias ButtonEllipse() : EventButtonGUI(), radius(0) {} - ButtonEllipse(std::wstring textureName, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, EventFunc func, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float textureWidth, float textureHeight, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureWidth, textureHeight, resizeToScreenAspectRatio) + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonEllipse() {} @@ -42,8 +42,8 @@ namespace DanBias //Should come from the InputClass float xMouse = input.x, yMouse = input.y; - double normx = (xMouse - xPos) / width; - double normy = (yMouse - yPos) / height; + double normx = (xMouse - pos.x) / size.x; + double normy = (yMouse - pos.y) / size.y; return (normx * normx + normy * normy) < 0.25; } diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h index 711afdf8..a0b3e94b 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h @@ -21,17 +21,17 @@ namespace DanBias ButtonRectangle() : EventButtonGUI(), width(0), height(0) {} - ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, owner, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, width, height, resizeToScreenAspectRatio) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} virtual ~ButtonRectangle() {} @@ -42,10 +42,10 @@ namespace DanBias //Should come from the InputClass float xMouse = input.x, yMouse = input.y; - float widthTemp = xPos - width * 0.5f; - float widthTemp2 = xPos + width * 0.5f; - float heightTemp = yPos - height * 0.5f; - float heightTemp2 = yPos + height * 0.5f; + float widthTemp = pos.x - size.x * 0.5f; + float widthTemp2 = pos.x + size.x * 0.5f; + float heightTemp = pos.y - size.y * 0.5f; + float heightTemp2 = pos.y + size.y * 0.5f; //std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl; if(xMouse >= widthTemp && xMouse <= widthTemp2 && diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h index e71dd0fa..d4884fd7 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h @@ -8,40 +8,56 @@ #include "../Misc/EventHandler/EventButton.h" #include "../OysterGraphics/DllInterfaces/GFXAPI.h" + + namespace DanBias { namespace Client { + /*Dictates if the texture should be resized based on the screen aspect ratio. + + */ + enum ResizeAspectRatio + { + ResizeAspectRatio_None, + ResizeAspectRatio_Width, + ResizeAspectRatio_Height, + + ResizeAspectRatio_Count, + ResizeAspectRatio_Unknown = -1 + }; + + template class EventButtonGUI : public Oyster::Event::EventButton { public: EventButtonGUI() - : EventButton(), xPos(0), yPos(0), width(0), height(0), texture(NULL) + : EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(0, 0, 0) {} - EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(func), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(func, owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height, bool resizeToScreenAspectRatio = true) - : EventButton(func, owner, userData), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + : EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); - if(resizeToScreenAspectRatio) ResizeWithAspectRatio(); + if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } virtual ~EventButtonGUI() { @@ -55,7 +71,7 @@ namespace DanBias texture = Oyster::Graphics::API::CreateTexture(textureName); } - virtual void Render() + virtual void RenderTexture() { if(EventButton::Enabled()) { @@ -64,32 +80,48 @@ namespace DanBias if(EventButton::GetState() == ButtonState_None) { - Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 1.0f, 1.0f)); + Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f)); } else if(EventButton::GetState() == ButtonState_Hover) { - Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(0.0f, 1.0f, 0.0f)); + Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f)); } else { - Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1.0f, 0.0f, 0.0f)); + Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f)); } } } - void ResizeWithAspectRatio() + virtual void RenderText() + { + if(buttonText.size() > 0) + { + Oyster::Graphics::API::RenderText(buttonText, pos.xy, size, textColor); + } + } + + private: + void ResizeWithAspectRatio(ResizeAspectRatio resize) { RECT r; GetClientRect(WindowShell::GetHWND(), &r); - height *= (float)r.right/(float)r.bottom; + + if(resize == ResizeAspectRatio_Height) + size.y *= (float)r.right/(float)r.bottom; + else if(resize == ResizeAspectRatio_Width) + size.x *= (float)r.bottom/(float)r.right; } protected: - float xPos, yPos; - float width, height; - Oyster::Graphics::API::Texture texture; + Oyster::Math::Float3 pos; + Oyster::Math::Float2 size; + Oyster::Graphics::API::Texture texture; + + std::wstring buttonText; + Oyster::Math::Float3 textColor; }; } } diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 9e52805e..72d0ba24 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -43,13 +43,24 @@ void EventButtonCollection::Update(MouseInput& input) } } -void EventButtonCollection::Render() +void EventButtonCollection::RenderTexture() { if(this->collectionState == EventCollectionState_Enabled) { for(int i = 0; i < (int)buttons.size(); i++) { - buttons[i]->Render(); + buttons[i]->RenderTexture(); + } + } +} + +void EventButtonCollection::RenderText() +{ + if(this->collectionState == EventCollectionState_Enabled) + { + for(int i = 0; i < (int)buttons.size(); i++) + { + buttons[i]->RenderText(); } } } diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 3cb3c891..8c39d171 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -37,7 +37,8 @@ namespace Oyster ~EventButtonCollection(); void Update(MouseInput& input); - void Render(); + void RenderTexture(); + void RenderText(); /*Add a button to the collection when a button is added to the collection you are not allowed to delete it. */ diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 558b776c..24dca38a 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -35,11 +35,19 @@ void EventHandler::Update(MouseInput& input) } } -void EventHandler::Render() +void EventHandler::RenderTexture() { for(int i = 0; i < (int)collections.size(); i++) { - collections.at(i)->Render(); + collections.at(i)->RenderTexture(); + } +} + +void EventHandler::RenderText() +{ + for(int i = 0; i < (int)collections.size(); i++) + { + collections.at(i)->RenderText(); } } diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 79196afb..82c25e1a 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -27,7 +27,8 @@ namespace Oyster void Clean(); void Update(MouseInput& input); - void Render(); + void RenderTexture(); + void RenderText(); /*Add a collection to the EventHandler will only add collections not already present in the list. diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index de6539df..501aefdb 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -21,6 +21,9 @@ #include #include +//For conversion from wstring to string +#include + using namespace Oyster::Network; using namespace Oyster::Thread; using namespace Utility::DynamicMemory; @@ -295,6 +298,17 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[]) return true; } +bool NetworkClient::Connect(unsigned short port, std::wstring serverIP) +{ + //Convert from wstring to string. + typedef std::codecvt_utf8 convert_typeX; + std::wstring_convert converterX; + + std::string ip = converterX.to_bytes(serverIP); + + return this->Connect(port, ip.c_str()); +} + void NetworkClient::Disconnect() { if(!privateData) return; diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 4533070c..58d81360 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -88,6 +88,11 @@ namespace Oyster */ bool Connect(unsigned short port, const char serverIP[]); + /** + * + */ + bool Connect(unsigned short port, std::wstring serverIP); + /** * */ From 49fc55be606233805482bf9e942fd3e88e29314a Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 14 Feb 2014 09:40:53 +0100 Subject: [PATCH 2/4] Textfield and Bunch of fixes --- Code/Game/DanBiasGame/DanBiasGame.vcxproj | 1 + .../GameClientState/Buttons/TextField.h | 196 ++++++++++++++++-- .../DanBiasGame/GameClientState/GameState.cpp | 34 +-- .../GameClientState/LanMenuState.cpp | 38 ++-- Code/Misc/EventHandler/IEventButton.h | 3 +- Code/Misc/Misc.vcxproj.user | 2 +- 6 files changed, 214 insertions(+), 60 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 974736b4..1f0bf1ce 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -240,6 +240,7 @@ + diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/TextField.h b/Code/Game/DanBiasGame/GameClientState/Buttons/TextField.h index df3ff60e..4333f1da 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/TextField.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/TextField.h @@ -1,30 +1,202 @@ /******************************************************************** - * Created by Dan Andersson, 2014 + * Text field that allows multiple lines. + * + * Written by Dan Andersson, 2014 ********************************************************************/ -#include -#include "EventButtonGUI.h" -#include "OysterMath.h" #ifndef DANBIAS_CLIENT_TEXT_FIELD_H #define DANBIAS_CLIENT_TEXT_FIELD_H +#include +#include +#include "ButtonRectangle.h" +#include "OysterMath.h" +#include "Utilities.h" + namespace DanBias { namespace Client { - template - class TextField : public EventButtonGUI + template + class TextField : public ButtonRectangle { 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 + TextField::TextField() + : ButtonRectangle() + { + this->textHeight = 0.025f; + this->lineSpacing = 0.001f; + this->isBottomAligned = true; + } + + template + TextField::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 + TextField::~TextField() {} + + template + void TextField::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 + const ::std::wstring & TextField::operator[]( unsigned int i ) const + { + return this->lines[(::std::vector<::std::wstring>::size_type)i]; + } + + template + ::std::wstring & TextField::operator[]( unsigned int i ) + { + return this->lines[(::std::vector<::std::wstring>::size_type)i]; + } + + template + void TextField::SetTextHeight( ::Oyster::Math::Float h ) + { + this->textHeight = h; + } + + template + void TextField::SetLineSpacing( ::Oyster::Math::Float ls ) + { + this->lineSpacing = ls; + } + + template + void TextField::SetBottomAligned() + { + this->isBottomAligned = true; + } + + template + void TextField::SetTopAligned() + { + this->isBottomAligned = false; + } + + template + unsigned int TextField::GetNumLines() const + { + return (unsigned int)this->lines.size(); + } + + template + void TextField::ReserveLines( unsigned int num ) + { + this->lines.reserve( (::std::vector<::std::wstring>::size_type)num ); + } + + template + void TextField::ClearText() + { + this->lines.resize( 0 ); + } + + template + void TextField::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 + void TextField::PopBack() + { + this->lines.pop_back(); + } + + template + void TextField::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 \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index a1cdb32a..edcb5289 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -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; } diff --git a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp index a043d3bf..bffd8c8a 100644 --- a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp @@ -11,6 +11,7 @@ #include "EventHandler\EventHandler.h" #include "Buttons\ButtonRectangle.h" +#include "Buttons\TextField.h" #include #include @@ -28,12 +29,13 @@ struct LanMenuState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; Graphics::API::Texture background; - EventButtonCollection button; - ::std::wstring connectIP; + EventButtonCollection guiElements; + + TextField *connectIP; unsigned short connectPort; } privData; -void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& e ); +void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& 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 *button; + // create guiElements + ButtonRectangle *guiElements; + //0.5f, 0.2f, 0.3f, 0.1f, + guiElements = new ButtonRectangle( 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 ); + + this->privData->connectIP = new TextField( 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 ); - button = new ButtonRectangle( L"earth_md.png", OnButtonInteract_Connect, this, 0.5f, 0.2f, 0.3f, 0.1f, true ); - this->privData->button.AddButton( button ); + this->privData->guiElements.AddButton( this->privData->connectIP ); - // bind button collection to the singleton eventhandler - EventHandler::Instance().AddCollection( &this->privData->button ); + // 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& e ) +void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& e ) { switch( e.state ) { diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 62044eb2..d0c754f9 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -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; diff --git a/Code/Misc/Misc.vcxproj.user b/Code/Misc/Misc.vcxproj.user index 9a0b0ae0..3f030911 100644 --- a/Code/Misc/Misc.vcxproj.user +++ b/Code/Misc/Misc.vcxproj.user @@ -1,6 +1,6 @@  - true + false \ No newline at end of file From d4139e265e07714f3789546e40bdc3c76e00c4de Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 14 Feb 2014 09:46:17 +0100 Subject: [PATCH 3/4] MainState fix new compilation errors dealt with --- .../DanBiasGame/GameClientState/MainState.cpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/MainState.cpp b/Code/Game/DanBiasGame/GameClientState/MainState.cpp index c7fe78c8..771fc1ee 100644 --- a/Code/Game/DanBiasGame/GameClientState/MainState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/MainState.cpp @@ -28,9 +28,9 @@ struct MainState::MyData EventButtonCollection button; }; -void OnButtonInteract_Create( Oyster::Event::ButtonEvent& e ); -void OnButtonInteract_Join( Oyster::Event::ButtonEvent& e ); -void OnButtonInteract_Quit( Oyster::Event::ButtonEvent& e ); +void OnButtonInteract_Create( Oyster::Event::ButtonEvent& e ); +void OnButtonInteract_Join( Oyster::Event::ButtonEvent& e ); +void OnButtonInteract_Quit( Oyster::Event::ButtonEvent& e ); MainState::MainState(void) {} @@ -50,15 +50,15 @@ bool MainState::Init( NetworkClient* nwClient ) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); // create buttons - ButtonRectangle *button; + ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", OnButtonInteract_Create, this, 0.5f, 0.2f, 0.3f, 0.1f, true ); + button = new ButtonRectangle( L"earth_md.png", L"Create", Float3(1.0f), OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->button.AddButton( button ); - button = new ButtonRectangle( L"skysphere_md.png", OnButtonInteract_Join, this, 0.5f, 0.4f, 0.3f, 0.1f, true ); + button = new ButtonRectangle( L"skysphere_md.png", L"Join", Float3(1.0f), OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->button.AddButton( button ); - button = new ButtonRectangle( L"plane_texture_md.png", OnButtonInteract_Quit, this, 0.5f, 0.8f, 0.3f, 0.1f, true ); + button = new ButtonRectangle( L"plane_texture_md.png", L"Quit", Float3(1.0f), OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->button.AddButton( button ); // bind button collection to the singleton eventhandler @@ -87,7 +87,10 @@ bool MainState::Render() Graphics::API::StartGuiRender(); Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) ); - this->privData->button.Render(); + this->privData->button.RenderTexture(); + + Graphics::API::StartTextRender(); + this->privData->button.RenderText(); Graphics::API::EndFrame(); return true; @@ -111,7 +114,7 @@ void MainState::ChangeState( ClientState next ) this->privData->nextState = next; } -void OnButtonInteract_Create( Oyster::Event::ButtonEvent& e ) +void OnButtonInteract_Create( Oyster::Event::ButtonEvent& e ) { switch( e.state ) { @@ -122,7 +125,7 @@ void OnButtonInteract_Create( Oyster::Event::ButtonEvent& e ) } } -void OnButtonInteract_Join( Oyster::Event::ButtonEvent& e ) +void OnButtonInteract_Join( Oyster::Event::ButtonEvent& e ) { switch( e.state ) { @@ -133,7 +136,7 @@ void OnButtonInteract_Join( Oyster::Event::ButtonEvent& e ) } } -void OnButtonInteract_Quit( Oyster::Event::ButtonEvent& e ) +void OnButtonInteract_Quit( Oyster::Event::ButtonEvent& e ) { switch( e.state ) { From b9895f8c7fcf8a35cf3f561dccdb4c84f2a8f2ba Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 14 Feb 2014 09:54:05 +0100 Subject: [PATCH 4/4] All states fix All new compilation errors dealt with --- .../GameClientState/LanMenuState.cpp | 2 +- .../GameClientState/LobbyAdminState.cpp | 19 +++++++++++-------- .../GameClientState/LobbyState.cpp | 19 +++++++++++-------- .../DanBiasGame/GameClientState/MainState.cpp | 16 ++++++++-------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp index bffd8c8a..c4d2b41d 100644 --- a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp @@ -57,7 +57,7 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient) // create guiElements ButtonRectangle *guiElements; //0.5f, 0.2f, 0.3f, 0.1f, - guiElements = new ButtonRectangle( 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 ); + guiElements = new ButtonRectangle( L"earth_md.png", L"Connect", 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 ); this->privData->connectIP = new TextField( L"earth_md.png", Float3(1.0f), this, Float3(0.1f, 0.2f, 0.5f), Float2(0.45f, 0.1f), ResizeAspectRatio_Width ); diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyAdminState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyAdminState.cpp index e6e764ea..21afb54b 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyAdminState.cpp @@ -23,10 +23,10 @@ struct LobbyAdminState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; Graphics::API::Texture background; - EventButtonCollection button; + EventButtonCollection guiElements; } privData; -void OnButtonInteract_Ready( Oyster::Event::ButtonEvent& e ); +void OnButtonInteract_Ready( Oyster::Event::ButtonEvent& e ); LobbyAdminState::LobbyAdminState(void) {} @@ -46,13 +46,13 @@ bool LobbyAdminState::Init(NetworkClient* nwClient) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); // create buttons - ButtonRectangle *button; + ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", OnButtonInteract_Ready, this, 0.5f, 0.2f, 0.3f, 0.1f, true ); - this->privData->button.AddButton( button ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler - EventHandler::Instance().AddCollection( &this->privData->button ); + EventHandler::Instance().AddCollection( &this->privData->guiElements ); return true; } @@ -85,7 +85,10 @@ bool LobbyAdminState::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; @@ -139,7 +142,7 @@ void LobbyAdminState::DataRecieved( NetEvent& e ) +void OnButtonInteract_Ready( Oyster::Event::ButtonEvent& e ) { switch( e.state ) { diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index 77ec5a86..37f10f1d 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -23,10 +23,10 @@ struct LobbyState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; Graphics::API::Texture background; - EventButtonCollection button; + EventButtonCollection guiElements; } privData; -void OnButtonInteract_Ready( Oyster::Event::ButtonEvent& e ); +void OnButtonInteract_Ready( Oyster::Event::ButtonEvent& e ); LobbyState::LobbyState(void) {} @@ -46,13 +46,13 @@ bool LobbyState::Init(NetworkClient* nwClient) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); // create buttons - ButtonRectangle *button; + ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", OnButtonInteract_Ready, this, 0.5f, 0.2f, 0.3f, 0.1f, true ); - this->privData->button.AddButton( button ); + button = new ButtonRectangle( L"earth_md.png", L"", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler - EventHandler::Instance().AddCollection( &this->privData->button ); + EventHandler::Instance().AddCollection( &this->privData->guiElements ); return true; } @@ -85,7 +85,10 @@ bool LobbyState::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; @@ -139,7 +142,7 @@ void LobbyState::DataRecieved( NetEvent& e ) +void OnButtonInteract_Ready( Oyster::Event::ButtonEvent& e ) { switch( e.state ) { diff --git a/Code/Game/DanBiasGame/GameClientState/MainState.cpp b/Code/Game/DanBiasGame/GameClientState/MainState.cpp index 771fc1ee..dc6f88b3 100644 --- a/Code/Game/DanBiasGame/GameClientState/MainState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/MainState.cpp @@ -25,7 +25,7 @@ struct MainState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; Graphics::API::Texture background; - EventButtonCollection button; + EventButtonCollection guiElements; }; void OnButtonInteract_Create( Oyster::Event::ButtonEvent& e ); @@ -53,16 +53,16 @@ bool MainState::Init( NetworkClient* nwClient ) ButtonRectangle *button; button = new ButtonRectangle( L"earth_md.png", L"Create", Float3(1.0f), OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); - this->privData->button.AddButton( button ); + this->privData->guiElements.AddButton( button ); button = new ButtonRectangle( L"skysphere_md.png", L"Join", Float3(1.0f), OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); - this->privData->button.AddButton( button ); + this->privData->guiElements.AddButton( button ); button = new ButtonRectangle( L"plane_texture_md.png", L"Quit", Float3(1.0f), OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); - this->privData->button.AddButton( button ); + this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler - EventHandler::Instance().AddCollection( &this->privData->button ); + EventHandler::Instance().AddCollection( &this->privData->guiElements ); return true; } @@ -87,10 +87,10 @@ bool MainState::Render() Graphics::API::StartGuiRender(); Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) ); - this->privData->button.RenderTexture(); + this->privData->guiElements.RenderTexture(); Graphics::API::StartTextRender(); - this->privData->button.RenderText(); + this->privData->guiElements.RenderText(); Graphics::API::EndFrame(); return true; @@ -101,7 +101,7 @@ bool MainState::Release() if( this->privData ) { Graphics::API::DeleteTexture( this->privData->background ); // TODO: @todo bug caught when exiting by X - EventHandler::Instance().ReleaseCollection( &this->privData->button ); + EventHandler::Instance().ReleaseCollection( &this->privData->guiElements ); this->privData = NULL; // button collection will be autoreleased from EventHandler