From 5e00730587a9cf95da60e4161829d889616a3311 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 18 Nov 2025 21:30:18 -0600 Subject: [PATCH] feat(ui): implement CSimpleCheckbox_SetChecked --- src/ui/CSimpleCheckbox.cpp | 25 +++++++++++++++++++++++++ src/ui/CSimpleCheckbox.hpp | 1 + src/ui/CSimpleCheckboxScript.cpp | 9 ++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ui/CSimpleCheckbox.cpp b/src/ui/CSimpleCheckbox.cpp index 25f0f2f..31b96e4 100644 --- a/src/ui/CSimpleCheckbox.cpp +++ b/src/ui/CSimpleCheckbox.cpp @@ -1,5 +1,6 @@ #include "ui/CSimpleCheckbox.hpp" #include "ui/CSimpleCheckboxScript.hpp" +#include "ui/CSimpleTexture.hpp" int32_t CSimpleCheckbox::s_metatable; int32_t CSimpleCheckbox::s_objectType; @@ -38,3 +39,27 @@ bool CSimpleCheckbox::IsA(int32_t type) { int32_t CSimpleCheckbox::GetChecked() { return this->m_checked; } + +void CSimpleCheckbox::SetChecked(int32_t checked, int32_t force) { + if (checked == this->m_checked && !force) { + return; + } + + this->m_checked = checked; + + if (this->m_checkedTexture) { + this->m_checkedTexture->Hide(); + } + + if (this->m_disabledTexture) { + this->m_disabledTexture->Hide(); + } + + if (this->m_checked) { + if (this->m_disabledTexture && this->m_state == BUTTONSTATE_DISABLED) { + this->m_disabledTexture->Show(); + } else if (this->m_checkedTexture) { + this->m_checkedTexture->Show(); + } + } +} diff --git a/src/ui/CSimpleCheckbox.hpp b/src/ui/CSimpleCheckbox.hpp index 78fb381..a85c91c 100644 --- a/src/ui/CSimpleCheckbox.hpp +++ b/src/ui/CSimpleCheckbox.hpp @@ -27,6 +27,7 @@ class CSimpleCheckbox : public CSimpleButton { CSimpleCheckbox(CSimpleFrame* parent) : CSimpleButton(parent) {}; int32_t GetChecked(); + void SetChecked(int32_t checked, int32_t force); }; #endif diff --git a/src/ui/CSimpleCheckboxScript.cpp b/src/ui/CSimpleCheckboxScript.cpp index 5a6cfcc..869489b 100644 --- a/src/ui/CSimpleCheckboxScript.cpp +++ b/src/ui/CSimpleCheckboxScript.cpp @@ -1,11 +1,18 @@ #include "ui/CSimpleCheckboxScript.hpp" #include "ui/CSimpleCheckbox.hpp" #include "util/Lua.hpp" +#include "util/StringTo.hpp" #include "util/Unimplemented.hpp" #include int32_t CSimpleCheckbox_SetChecked(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleCheckbox::GetObjectType(); + auto checkbox = static_cast(FrameScript_GetObjectThis(L, type)); + + auto checked = StringToBOOL(L, 2, 1); + checkbox->SetChecked(checked, 0); + + return 0; } int32_t CSimpleCheckbox_GetChecked(lua_State* L) {