From 0a2c95cda15e3e5c9c807249cc83c02a966550d7 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 18 Nov 2025 22:18:30 -0600 Subject: [PATCH] feat(ui): add CSimpleCheckbox::LoadXML --- src/ui/CSimpleCheckbox.cpp | 51 ++++++++++++++++++++++++++++++++++++++ src/ui/CSimpleCheckbox.hpp | 3 +++ 2 files changed, 54 insertions(+) diff --git a/src/ui/CSimpleCheckbox.cpp b/src/ui/CSimpleCheckbox.cpp index 31b96e4..160ca41 100644 --- a/src/ui/CSimpleCheckbox.cpp +++ b/src/ui/CSimpleCheckbox.cpp @@ -1,6 +1,9 @@ #include "ui/CSimpleCheckbox.hpp" #include "ui/CSimpleCheckboxScript.hpp" #include "ui/CSimpleTexture.hpp" +#include "ui/LoadXML.hpp" +#include "util/StringTo.hpp" +#include int32_t CSimpleCheckbox::s_metatable; int32_t CSimpleCheckbox::s_objectType; @@ -40,6 +43,28 @@ int32_t CSimpleCheckbox::GetChecked() { return this->m_checked; } +void CSimpleCheckbox::LoadXML(XMLNode* node, CStatus* status) { + CSimpleButton::LoadXML(node, status); + + auto checkedAttr = node->GetAttributeByName("checked"); + if (checkedAttr && *checkedAttr) { + auto checked = StringToBOOL(checkedAttr); + this->SetChecked(checked, 0); + } + + for (auto child = node->m_child; child; child = child->m_next) { + if (!SStrCmpI(child->GetName(), "CheckedTexture")) { + auto checkedTexture = LoadXML_Texture(child, this, status); + this->SetCheckedTexture(checkedTexture); + + } else if (!SStrCmpI(child->GetName(), "DisabledCheckedTexture")) { + auto disabledTexture = LoadXML_Texture(child, this, status); + this->SetDisabledCheckedTexture(disabledTexture); + + } + } +} + void CSimpleCheckbox::SetChecked(int32_t checked, int32_t force) { if (checked == this->m_checked && !force) { return; @@ -63,3 +88,29 @@ void CSimpleCheckbox::SetChecked(int32_t checked, int32_t force) { } } } + +void CSimpleCheckbox::SetCheckedTexture(CSimpleTexture* texture) { + if (this->m_checkedTexture) { + delete this->m_checkedTexture; + } + + if (texture) { + texture->SetFrame(this, DRAWLAYER_ARTWORK_OVERLAY, 0); + } + + this->m_checkedTexture = texture; + this->SetChecked(this->m_checked, 1); +} + +void CSimpleCheckbox::SetDisabledCheckedTexture(CSimpleTexture* texture) { + if (this->m_disabledTexture) { + delete this->m_disabledTexture; + } + + if (texture) { + texture->SetFrame(this, DRAWLAYER_ARTWORK_OVERLAY, 0); + } + + this->m_disabledTexture = texture; + this->SetChecked(this->m_checked, 1); +} diff --git a/src/ui/CSimpleCheckbox.hpp b/src/ui/CSimpleCheckbox.hpp index a85c91c..894d5c7 100644 --- a/src/ui/CSimpleCheckbox.hpp +++ b/src/ui/CSimpleCheckbox.hpp @@ -22,12 +22,15 @@ class CSimpleCheckbox : public CSimpleButton { // Virtual member functions virtual bool IsA(int32_t type); virtual int32_t GetScriptMetaTable(); + virtual void LoadXML(XMLNode* node, CStatus* status); // Member functions CSimpleCheckbox(CSimpleFrame* parent) : CSimpleButton(parent) {}; int32_t GetChecked(); void SetChecked(int32_t checked, int32_t force); + void SetCheckedTexture(CSimpleTexture* texture); + void SetDisabledCheckedTexture(CSimpleTexture* texture); }; #endif