diff --git a/modules/outfit/outfit.lua b/modules/outfit/outfit.lua index 4328e064..d0bbb03b 100644 --- a/modules/outfit/outfit.lua +++ b/modules/outfit/outfit.lua @@ -2,6 +2,8 @@ Outfit = {} -- private variables local window = nil +local outfits = nil +local currentOutfit = 1 -- public functions function Outfit.test() @@ -18,9 +20,13 @@ end function Outfit.create(creature, outfitList) Outfit.destroy() window = loadUI("/outfit/outfit.otui", UI.root) + window:lock() local creatureWidget = window:getChildById('creature') creatureWidget:setCreature(creature) + + outfits = outfitList + currentOutfit = 1 end function Outfit.destroy() @@ -30,6 +36,30 @@ function Outfit.destroy() end end +function Outfit.nextType() + local creatureWidget = window:getChildById('creature') + currentOutfit = currentOutfit + 1 + if currentOutfit > #outfits then + currentOutfit = 1 + end + + creatureWidget:setOutfitType(outfits[currentOutfit][1]) + + -- TODO: update addons +end + +function Outfit.previousType() + local creatureWidget = window:getChildById('creature') + currentOutfit = currentOutfit - 1 + if currentOutfit <= 0 then + currentOutfit = #outfits + end + + creatureWidget:setOutfitType(outfits[currentOutfit][1]) + + -- TODO: update addons +end + -- private functions -- hooked events diff --git a/modules/outfit/outfit.otui b/modules/outfit/outfit.otui index 118dc097..67a6b772 100644 --- a/modules/outfit/outfit.otui +++ b/modules/outfit/outfit.otui @@ -10,6 +10,22 @@ Window anchors.left: parent.left margin.top: 30 margin.left: 20 + + Button + onClick: Outfit.previousType() + text: << + width: 32 + margin.top: 3 + anchors.top: creature.bottom + anchors.left: creature.left + + Button + onClick: Outfit.nextType() + text: >> + width: 32 + margin.top: 3 + anchors.top: creature.bottom + anchors.right: creature.right HorizontalSeparator anchors.left: parent.left diff --git a/src/otclient/otclientluafunctions.cpp b/src/otclient/otclientluafunctions.cpp index 2cd4e4d2..f9f00c6b 100644 --- a/src/otclient/otclientluafunctions.cpp +++ b/src/otclient/otclientluafunctions.cpp @@ -77,6 +77,8 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("create", &UICreature::create); g_lua.bindClassMemberFunction("getCreature", &UICreature::getCreature); g_lua.bindClassMemberFunction("setCreature", &UICreature::setCreature); + g_lua.bindClassMemberFunction("setOutfitType", &UICreature::setOutfitType); + g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create); diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index c1760414..4f028202 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -50,3 +50,12 @@ void UICreature::onStyleApply(const OTMLNodePtr& styleNode) UIWidget::onStyleApply(styleNode); } + +void UICreature::setOutfitType(int outfitType) +{ + if(m_creature) { + Outfit outfit = m_creature->getOutfit(); + outfit.setType(outfitType); + m_creature->setOutfit(outfit); + } +} diff --git a/src/otclient/ui/uicreature.h b/src/otclient/ui/uicreature.h index de4bf43a..dbf22ac6 100644 --- a/src/otclient/ui/uicreature.h +++ b/src/otclient/ui/uicreature.h @@ -34,6 +34,8 @@ public: void render(); void setCreature(const CreaturePtr& creature) { m_creature = creature; } + void setOutfitType(int outfitType); + CreaturePtr getCreature() { return m_creature; } protected: