feat(ui): add CSimpleStatusBar::SetValue

This commit is contained in:
fallenoak 2026-02-04 13:23:14 -06:00
parent bc2dabeea9
commit 61484450b8
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 36 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "ui/simple/CSimpleStatusBar.hpp"
#include "ui/simple/CSimpleStatusBarScript.hpp"
#include "util/Lua.hpp"
int32_t CSimpleStatusBar::s_metatable;
int32_t CSimpleStatusBar::s_objectType;
@ -47,3 +48,35 @@ FrameScript_Object::ScriptIx* CSimpleStatusBar::GetScriptByName(const char* name
int32_t CSimpleStatusBar::GetScriptMetaTable() {
return CSimpleStatusBar::s_metatable;
}
void CSimpleStatusBar::RunOnValueChangedScript() {
if (!this->m_onValueChanged.luaRef) {
return;
}
auto L = FrameScript_GetContext();
lua_pushnumber(L, this->m_value);
this->RunScript(this->m_onValueChanged, 1, nullptr);
}
void CSimpleStatusBar::SetValue(float value) {
if (!this->m_rangeSet) {
return;
}
// Clamp value
value = std::min(std::max(value, this->m_minValue), this->m_maxValue);
if (this->m_valueSet && this->m_value == value) {
return;
}
this->m_value = value;
this->m_changed = true;
this->m_valueSet = true;
this->RunOnValueChangedScript();
}

View File

@ -17,9 +17,12 @@ class CSimpleStatusBar : public CSimpleFrame {
// Public virtual member functions
virtual int32_t GetScriptMetaTable();
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
// TODO
virtual void SetValue(float value);
// Public member functions
CSimpleStatusBar(CSimpleFrame* parent);
void RunOnValueChangedScript();
protected:
// Protected member variables