diff --git a/src/ui/CSimpleSlider.cpp b/src/ui/CSimpleSlider.cpp index d0afc10..1dd3e12 100644 --- a/src/ui/CSimpleSlider.cpp +++ b/src/ui/CSimpleSlider.cpp @@ -1,7 +1,11 @@ #include "ui/CSimpleSlider.hpp" #include "math/Utils.hpp" #include "ui/CSimpleSliderScript.hpp" +#include "ui/CSimpleTexture.hpp" +#include "ui/LoadXML.hpp" #include "util/Lua.hpp" +#include "util/StringTo.hpp" +#include int32_t CSimpleSlider::s_metatable; int32_t CSimpleSlider::s_objectType; @@ -56,6 +60,26 @@ bool CSimpleSlider::IsA(int32_t type) { || type == CScriptObject::s_objectType; } +void CSimpleSlider::LoadXML(XMLNode* node, CStatus* status) { + this->CSimpleFrame::LoadXML(node, status); + + int32_t drawLayer = DRAWLAYER_ARTWORK_OVERLAY; + + auto drawLayerStr = node->GetAttributeByName("drawLayer"); + if (drawLayerStr && *drawLayerStr) { + StringToDrawLayer(drawLayerStr, drawLayer); + } + + for (auto child = node->m_child; child; child = child->m_next) { + if (!SStrCmpI(child->GetName(), "ThumbTexture")) { + auto thumbTexture = LoadXML_Texture(child, this, status); + this->SetThumbTexture(thumbTexture, drawLayer); + } + } + + // TODO +} + void CSimpleSlider::RunOnMinMaxChangedScript() { if (!this->m_onMinMaxChanged.luaRef) { return; @@ -101,6 +125,24 @@ void CSimpleSlider::SetMinMaxValues(float min, float max) { } } +void CSimpleSlider::SetThumbTexture(CSimpleTexture* texture, int32_t drawLayer) { + if (this->m_thumbTexture == texture) { + return; + } + + if (this->m_thumbTexture) { + delete this->m_thumbTexture; + } + + if (texture) { + texture->SetFrame(this, drawLayer, 1); + texture->ClearAllPoints(); + } + + this->m_changed = 1; + this->m_thumbTexture = texture; +} + void CSimpleSlider::SetValue(float value) { if (!this->m_rangeSet) { return; diff --git a/src/ui/CSimpleSlider.hpp b/src/ui/CSimpleSlider.hpp index e1d62ed..41b9304 100644 --- a/src/ui/CSimpleSlider.hpp +++ b/src/ui/CSimpleSlider.hpp @@ -23,6 +23,7 @@ class CSimpleSlider : public CSimpleFrame { float m_range = 0.0f; float m_value = 0.0f; float m_valueStep = 0.0f; + CSimpleTexture* m_thumbTexture = nullptr; ScriptIx m_onValueChanged; ScriptIx m_onMinMaxChanged; @@ -30,6 +31,7 @@ class CSimpleSlider : public CSimpleFrame { virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data); virtual bool IsA(int32_t type); virtual int32_t GetScriptMetaTable(); + virtual void LoadXML(XMLNode* node, CStatus* status); // Member functions CSimpleSlider(CSimpleFrame* parent) @@ -44,6 +46,7 @@ class CSimpleSlider : public CSimpleFrame { void RunOnMinMaxChangedScript(); void RunOnValueChangedScript(); void SetMinMaxValues(float min, float max); + void SetThumbTexture(CSimpleTexture* texture, int32_t drawLayer); void SetValue(float value); float Sub96BC10(float value); };