feat(ui): add CSimpleCheckbox::LoadXML

This commit is contained in:
fallenoak 2025-11-18 22:18:30 -06:00
parent 5e00730587
commit 0a2c95cda1
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 54 additions and 0 deletions

View File

@ -1,6 +1,9 @@
#include "ui/CSimpleCheckbox.hpp" #include "ui/CSimpleCheckbox.hpp"
#include "ui/CSimpleCheckboxScript.hpp" #include "ui/CSimpleCheckboxScript.hpp"
#include "ui/CSimpleTexture.hpp" #include "ui/CSimpleTexture.hpp"
#include "ui/LoadXML.hpp"
#include "util/StringTo.hpp"
#include <common/XML.hpp>
int32_t CSimpleCheckbox::s_metatable; int32_t CSimpleCheckbox::s_metatable;
int32_t CSimpleCheckbox::s_objectType; int32_t CSimpleCheckbox::s_objectType;
@ -40,6 +43,28 @@ int32_t CSimpleCheckbox::GetChecked() {
return this->m_checked; 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) { void CSimpleCheckbox::SetChecked(int32_t checked, int32_t force) {
if (checked == this->m_checked && !force) { if (checked == this->m_checked && !force) {
return; 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);
}

View File

@ -22,12 +22,15 @@ class CSimpleCheckbox : public CSimpleButton {
// Virtual member functions // Virtual member functions
virtual bool IsA(int32_t type); virtual bool IsA(int32_t type);
virtual int32_t GetScriptMetaTable(); virtual int32_t GetScriptMetaTable();
virtual void LoadXML(XMLNode* node, CStatus* status);
// Member functions // Member functions
CSimpleCheckbox(CSimpleFrame* parent) CSimpleCheckbox(CSimpleFrame* parent)
: CSimpleButton(parent) {}; : CSimpleButton(parent) {};
int32_t GetChecked(); int32_t GetChecked();
void SetChecked(int32_t checked, int32_t force); void SetChecked(int32_t checked, int32_t force);
void SetCheckedTexture(CSimpleTexture* texture);
void SetDisabledCheckedTexture(CSimpleTexture* texture);
}; };
#endif #endif