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/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/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); + /** * */