From 8e07475434c4c35c59b8da6a3e74167091277549 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 12 Feb 2014 10:02:52 +0100 Subject: [PATCH] GL - Buttons is now using one texture per button type. Fixed button state when spamming the button. --- .../GameClientState/Buttons/EventButtonGUI.h | 19 +++----------- .../GameClientState/LoginState.cpp | 25 +++++++++---------- Code/Misc/EventHandler/EventButton.h | 7 +++--- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h index 7e2de14f..73bccc49 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h @@ -42,26 +42,17 @@ namespace DanBias virtual ~EventButtonGUI() { Oyster::Graphics::API::DeleteTexture(texture); - Oyster::Graphics::API::DeleteTexture(texture2); - Oyster::Graphics::API::DeleteTexture(texture3); texture = NULL; - texture2 = NULL; - texture3 = NULL; } void CreateTexture(std::wstring textureName) { - std::wstring file = L".png"; - //Create texture - texture = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"none") + file); - texture2 = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"highlight") + file); - texture3 = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"down") + file); + texture = Oyster::Graphics::API::CreateTexture(textureName); } virtual void Render() { - if(EventButton::Enabled()) { //Render att xPos and yPos @@ -69,15 +60,15 @@ namespace DanBias if(EventButton::GetState() == ButtonState_None) { - Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height)); + Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1, 1, 1)); } else if(EventButton::GetState() == ButtonState_Hover) { - Oyster::Graphics::API::RenderGuiElement(texture2, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height)); + Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(0, 1, 0)); } else { - Oyster::Graphics::API::RenderGuiElement(texture3, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height)); + Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height), Oyster::Math::Float3(1, 0, 0)); } } @@ -87,8 +78,6 @@ namespace DanBias float xPos, yPos; float width, height; Oyster::Graphics::API::Texture texture; - Oyster::Graphics::API::Texture texture2; - Oyster::Graphics::API::Texture texture3; }; diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index d94d8ed5..7424b7b2 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -110,21 +110,21 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) //Create menu buttons privData->collection = new EventButtonCollection; EventHandler::Instance().AddCollection(privData->collection); - privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.2f, 0.1f, 0.2f)); - privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.3f, 0.1f, 0.2f)); - privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.4f, 0.1f, 0.2f)); - privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.5f, 0.1f, 0.2f)); + privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.2f, 0.1f, 0.2f)); + privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.3f, 0.1f, 0.2f)); + privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.4f, 0.1f, 0.2f)); + privData->collection->AddButton(new ButtonEllipse(L"circle.png", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.5f, 0.1f, 0.2f)); - privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.15f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.25f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.35f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.45f, 0.05f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.15f, 0.05f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.25f, 0.05f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.35f, 0.05f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.45f, 0.05f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); + privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); //Incr/decr buttons - privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); - privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button.png", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); privData->testNumber = 0; @@ -217,7 +217,6 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key } bool LoginState::Render(float dt) { - Oyster::Graphics::API::SetView(privData->view); Oyster::Graphics::API::SetProjection( privData->proj); @@ -241,7 +240,7 @@ bool LoginState::Render(float dt) _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)); + Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7, 0.2), Oyster::Math::Float2(0.1, 0.1), Oyster::Math::Float3(1, 0, 0)); Oyster::Graphics::API::EndFrame(); return true; diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 6a220845..6e99fcc7 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -155,15 +155,16 @@ namespace Oyster break; case ButtonState_Hover: - case ButtonState_Released: if(outside == false) { clicked = true; currentState = ButtonState_Pressed; } - else - currentState = ButtonState_Hover; break; + case ButtonState_Released: + currentState = ButtonState_Hover; + break; + case ButtonState_Pressed: case ButtonState_Down: