feat(ui): implement CSimpleCheckbox_SetChecked

This commit is contained in:
fallenoak 2025-11-18 21:30:18 -06:00
parent 1cd1bb5672
commit 5e00730587
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
3 changed files with 34 additions and 1 deletions

View File

@ -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();
}
}
}

View File

@ -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

View File

@ -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 <cstdint>
int32_t CSimpleCheckbox_SetChecked(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CSimpleCheckbox::GetObjectType();
auto checkbox = static_cast<CSimpleCheckbox*>(FrameScript_GetObjectThis(L, type));
auto checked = StringToBOOL(L, 2, 1);
checkbox->SetChecked(checked, 0);
return 0;
}
int32_t CSimpleCheckbox_GetChecked(lua_State* L) {