From aa22dd952a86b03826bc960413133c42d3e18cd8 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Thu, 5 Feb 2026 07:05:28 -0600 Subject: [PATCH] feat(ui): add CSimpleStatusBar::OnLayerUpdate --- src/ui/simple/CSimpleStatusBar.cpp | 50 ++++++++++++++++++++++++++++++ src/ui/simple/CSimpleStatusBar.hpp | 3 ++ 2 files changed, 53 insertions(+) diff --git a/src/ui/simple/CSimpleStatusBar.cpp b/src/ui/simple/CSimpleStatusBar.cpp index e5c3f20..c3c0d28 100644 --- a/src/ui/simple/CSimpleStatusBar.cpp +++ b/src/ui/simple/CSimpleStatusBar.cpp @@ -28,6 +28,16 @@ void CSimpleStatusBar::RegisterScriptMethods(lua_State* L) { FrameScript_Object::FillScriptMethodTable(L, SimpleStatusBarMethods, NUM_SIMPLE_STATUS_BAR_SCRIPT_METHODS); } +float CSimpleStatusBar::GetAnimValue() const { + auto range = this->m_maxValue - this->m_minValue; + + if (range <= 0.0f) { + return 0.0f; + } + + return (this->m_value - this->m_minValue) / range; +} + FrameScript_Object::ScriptIx* CSimpleStatusBar::GetScriptByName(const char* name, ScriptData& data) { auto script = this->CSimpleFrame::GetScriptByName(name, data); @@ -129,6 +139,46 @@ void CSimpleStatusBar::LoadXML(const XMLNode* node, CStatus* status) { } } +void CSimpleStatusBar::OnLayerUpdate(float elapsedSec) { + this->CSimpleFrame::OnLayerUpdate(elapsedSec); + + if (!this->m_changed || !this->m_rangeSet || !this->m_valueSet || !this->m_barTexture) { + return; + } + + auto animValue = this->GetAnimValue(); + + if (animValue <= 0.0f) { + this->m_barTexture->Hide(); + this->m_changed = false; + + return; + } + + float width, height; + this->GetSize(width, height, false); + + auto fill = 1.0f - animValue; + + this->m_barTexture->Show(); + + if (this->m_orientation == ORIENTATION_VERTICAL) { + this->m_barTexture->SetPoint(FRAMEPOINT_BOTTOMLEFT, this, FRAMEPOINT_BOTTOMLEFT, 0.0f, 0.0f, true); + this->m_barTexture->SetPoint(FRAMEPOINT_BOTTOMRIGHT, this, FRAMEPOINT_BOTTOMRIGHT, 0.0f, 0.0f, true); + + this->m_barTexture->SetPoint(FRAMEPOINT_TOPLEFT, this, FRAMEPOINT_TOPLEFT, 0.0f, -(fill * height), true); + this->m_barTexture->SetPoint(FRAMEPOINT_TOPRIGHT, this, FRAMEPOINT_TOPRIGHT, 0.0f, -(fill * height), true); + } else { + this->m_barTexture->SetPoint(FRAMEPOINT_TOPLEFT, this, FRAMEPOINT_TOPLEFT, 0.0f, 0.0f, true); + this->m_barTexture->SetPoint(FRAMEPOINT_BOTTOMLEFT, this, FRAMEPOINT_BOTTOMLEFT, 0.0f, 0.0f, true); + + this->m_barTexture->SetPoint(FRAMEPOINT_TOPRIGHT, this, FRAMEPOINT_TOPRIGHT, -(fill * width), 0.0f, true); + this->m_barTexture->SetPoint(FRAMEPOINT_BOTTOMRIGHT, this, FRAMEPOINT_BOTTOMRIGHT, -(fill * width), 0.0f, true); + } + + this->m_changed = false; +} + void CSimpleStatusBar::RunOnMinMaxChangedScript() { if (!this->m_onMinMaxChanged.luaRef) { return; diff --git a/src/ui/simple/CSimpleStatusBar.hpp b/src/ui/simple/CSimpleStatusBar.hpp index 203f6a4..0a81141 100644 --- a/src/ui/simple/CSimpleStatusBar.hpp +++ b/src/ui/simple/CSimpleStatusBar.hpp @@ -19,6 +19,8 @@ class CSimpleStatusBar : public CSimpleFrame { virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data); virtual bool IsA(int32_t type); // TODO + virtual void OnLayerUpdate(float elapsedSec); + // TODO virtual void SetValue(float value); virtual void LoadXML(const XMLNode* node, CStatus* status); @@ -28,6 +30,7 @@ class CSimpleStatusBar : public CSimpleFrame { , m_changed(false) , m_rangeSet(false) , m_valueSet(false) {}; + float GetAnimValue() const; float GetMaxValue() const; float GetMinValue() const; float GetValue() const;