From bdce2662056af15077cf168691db4c49b80c2037 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 3 Feb 2026 08:36:04 -0600 Subject: [PATCH] feat(ui): add CSimpleFrame::SetAttribute --- src/ui/simple/CSimpleFrame.cpp | 35 ++++++++++++++++++++++++++++++++++ src/ui/simple/CSimpleFrame.hpp | 2 ++ 2 files changed, 37 insertions(+) diff --git a/src/ui/simple/CSimpleFrame.cpp b/src/ui/simple/CSimpleFrame.cpp index 2588bcf..67a1da0 100644 --- a/src/ui/simple/CSimpleFrame.cpp +++ b/src/ui/simple/CSimpleFrame.cpp @@ -376,6 +376,29 @@ void CSimpleFrame::RegisterForEvents(int32_t a2) { } } +void CSimpleFrame::RunOnAttributeChangedScript(const char* name, int32_t luaRef) { + if (!this->m_onAttributeChange.luaRef) { + return; + } + + auto L = FrameScript_GetContext(); + + // TODO taint management + + // Attribute name + auto nameLower = static_cast(alloca(SStrLen(name) + 1)); + SStrCopy(nameLower, name); + SStrLower(nameLower); + lua_pushstring(L, nameLower); + + // Attribute ref + lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef); + + this->RunScript(this->m_onAttributeChange, 2, nullptr); + + // TODO taint management +} + void CSimpleFrame::RunOnCharScript(const char* chr) { if (this->m_onChar.luaRef) { auto L = FrameScript_GetContext(); @@ -1329,6 +1352,18 @@ void CSimpleFrame::RemoveFrameRegion(CSimpleRegion* region, uint32_t drawlayer) this->NotifyDrawLayerChanged(drawlayer); } +void CSimpleFrame::SetAttribute(const char* name, int32_t luaRef) { + auto attr = this->m_attributes.Ptr(name); + + if (!attr) { + attr = this->m_attributes.New(name, 0, 0x0); + } + + attr->luaRef = luaRef; + + this->RunOnAttributeChangedScript(name, luaRef); +} + void CSimpleFrame::SetBackdrop(CBackdropGenerator* backdrop) { if (this->m_backdrop) { delete this->m_backdrop; diff --git a/src/ui/simple/CSimpleFrame.hpp b/src/ui/simple/CSimpleFrame.hpp index d014462..21ce7ea 100644 --- a/src/ui/simple/CSimpleFrame.hpp +++ b/src/ui/simple/CSimpleFrame.hpp @@ -146,6 +146,7 @@ class CSimpleFrame : public CScriptRegion { void RegisterForEvents(int32_t a2); void RegisterRegion(CSimpleRegion* region); void RemoveFrameRegion(CSimpleRegion* region, uint32_t drawlayer); + void RunOnAttributeChangedScript(const char* name, int32_t luaRef); void RunOnCharScript(const char* chr); void RunOnEnableScript(); void RunOnEnterScript(int32_t a2); @@ -159,6 +160,7 @@ class CSimpleFrame : public CScriptRegion { void RunOnShowScript(); void RunOnSizeChangedScript(float width, float height); void RunOnUpdateScript(float elapsedSec); + void SetAttribute(const char* name, int32_t luaRef); void SetBackdrop(CBackdropGenerator* backdrop); void SetBeingScrolled(int32_t a2, int32_t a3); void SetFrameAlpha(uint8_t alpha);