From 03804e0ff4cdf928e3134f0334d60303421f83e4 Mon Sep 17 00:00:00 2001 From: VDm Date: Mon, 9 Dec 2024 22:10:40 +0400 Subject: [PATCH] chore(ui): add CSimpleFrame_SetBackdropColor and CSimpleFrame_SetBackdropBorderColor --- src/net/connection/RealmConnection.cpp | 2 +- src/ui/CBackdropGenerator.cpp | 7 +++++ src/ui/CBackdropGenerator.hpp | 1 + src/ui/CSimpleFrame.cpp | 14 ++++++++- src/ui/CSimpleFrame.hpp | 1 + src/ui/CSimpleFrameScript.cpp | 43 ++++++++++++++++++++++++-- 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/net/connection/RealmConnection.cpp b/src/net/connection/RealmConnection.cpp index 64d5c48..345686d 100644 --- a/src/net/connection/RealmConnection.cpp +++ b/src/net/connection/RealmConnection.cpp @@ -110,7 +110,7 @@ int32_t RealmConnection::HandleAuthChallenge(AuthenticationChallenge* challenge) // TODO switch to WDataStore CDataStore msg; - uint32_t localChallenge; + uint32_t localChallenge = 0; msg.Put(static_cast(CMSG_AUTH_SESSION)); diff --git a/src/ui/CBackdropGenerator.cpp b/src/ui/CBackdropGenerator.cpp index 5be5ac0..467b472 100644 --- a/src/ui/CBackdropGenerator.cpp +++ b/src/ui/CBackdropGenerator.cpp @@ -152,6 +152,13 @@ void CBackdropGenerator::LoadXML(XMLNode* node, CStatus* status) { } } +void CBackdropGenerator::SetVertexColor(const CImVector& color) { + this->m_color = color; + if (this->m_backgroundTexture) { + this->m_backgroundTexture->SetVertexColor(color); + } +} + void CBackdropGenerator::SetBorderVertexColor(const CImVector& borderColor) { this->m_borderColor = borderColor; diff --git a/src/ui/CBackdropGenerator.hpp b/src/ui/CBackdropGenerator.hpp index 06f248e..ce9fca6 100644 --- a/src/ui/CBackdropGenerator.hpp +++ b/src/ui/CBackdropGenerator.hpp @@ -42,6 +42,7 @@ class CBackdropGenerator { CBackdropGenerator(); void Generate(const CRect* rect); void LoadXML(XMLNode* node, CStatus* status); + void SetVertexColor(const CImVector& color); void SetBorderVertexColor(const CImVector& borderColor); void SetOutput(CSimpleFrame* frame); }; diff --git a/src/ui/CSimpleFrame.cpp b/src/ui/CSimpleFrame.cpp index f0ef022..6aa167a 100644 --- a/src/ui/CSimpleFrame.cpp +++ b/src/ui/CSimpleFrame.cpp @@ -1327,7 +1327,19 @@ void CSimpleFrame::SetBeingScrolled(int32_t a2, int32_t a3) { } void CSimpleFrame::SetFrameAlpha(uint8_t alpha) { - // TODO + if (this->m_alpha == alpha) { + return; + } + + this->m_alpha = alpha; + + for (auto region = this->m_regions.Head(); region; region = this->m_regions.Link(region)->Next()) { + region->OnColorChanged(true); + } + + for (auto child = this->m_children.Head(); child; child = this->m_children.Link(child)->Next()) { + child->frame->SetFrameAlpha(alpha); + } } void CSimpleFrame::SetFrameFlag(int32_t flag, int32_t on) { diff --git a/src/ui/CSimpleFrame.hpp b/src/ui/CSimpleFrame.hpp index 02eb4ab..86fd306 100644 --- a/src/ui/CSimpleFrame.hpp +++ b/src/ui/CSimpleFrame.hpp @@ -37,6 +37,7 @@ class CSimpleFrame : public CScriptRegion { float m_depth = 0.0; FRAME_STRATA m_strata = FRAME_STRATA_MEDIUM; int32_t m_level = 0; + uint8_t m_alpha = 255; uint32_t m_eventmask = 0; int32_t m_shown = 0; int32_t m_visible = 0; diff --git a/src/ui/CSimpleFrameScript.cpp b/src/ui/CSimpleFrameScript.cpp index dd9e075..752578f 100644 --- a/src/ui/CSimpleFrameScript.cpp +++ b/src/ui/CSimpleFrameScript.cpp @@ -2,6 +2,7 @@ #include "gx/Coordinate.hpp" #include "ui/CSimpleFrame.hpp" #include "ui/FrameScript.hpp" +#include "ui/CBackdropGenerator.hpp" #include "util/Lua.hpp" #include "util/Unimplemented.hpp" #include @@ -460,7 +461,26 @@ int32_t CSimpleFrame_GetBackdropColor(lua_State* L) { } int32_t CSimpleFrame_SetBackdropColor(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + if (lua_type(L, 1) != LUA_TTABLE) { + luaL_error(L, "Attempt to find 'this' in non-table object (used '.' instead of ':' ?)"); + } + + lua_rawgeti(L, 1, 0); + auto object = reinterpret_cast(lua_touserdata(L, -1)); + lua_settop(L, -2); + + STORM_ASSERT(object); + + CImVector color; + auto red = lua_tonumber(L, 2); + auto green = lua_tonumber(L, 3); + auto blue = lua_tonumber(L, 4); + auto alpha = lua_isnumber(L, 5) ? lua_tonumber(L, 5) : 1.0; + color.Set(alpha, red, green, blue); + + if (object->m_backdrop) { + object->m_backdrop->SetVertexColor(color); + } } int32_t CSimpleFrame_GetBackdropBorderColor(lua_State* L) { @@ -468,7 +488,26 @@ int32_t CSimpleFrame_GetBackdropBorderColor(lua_State* L) { } int32_t CSimpleFrame_SetBackdropBorderColor(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + if (lua_type(L, 1) != LUA_TTABLE) { + luaL_error(L, "Attempt to find 'this' in non-table object (used '.' instead of ':' ?)"); + } + + lua_rawgeti(L, 1, 0); + auto object = reinterpret_cast(lua_touserdata(L, -1)); + lua_settop(L, -2); + + STORM_ASSERT(object); + + CImVector color; + auto red = lua_tonumber(L, 2); + auto green = lua_tonumber(L, 3); + auto blue = lua_tonumber(L, 4); + auto alpha = lua_isnumber(L, 5) ? lua_tonumber(L, 5) : 1.0; + color.Set(alpha, red, green, blue); + + if (object->m_backdrop) { + object->m_backdrop->SetBorderVertexColor(color); + } } int32_t CSimpleFrame_SetDepth(lua_State* L) {