diff --git a/modules/outfit/outfit.lua b/modules/outfit/outfit.lua index b4711c34..0ec363db 100644 --- a/modules/outfit/outfit.lua +++ b/modules/outfit/outfit.lua @@ -2,47 +2,84 @@ Outfit = {} -- private variables local window = nil -local outfits = nil -local currentOutfit = 1 +local m_creature = nil +local m_outfit = nil +local m_outfits = nil +local m_currentOutfit = 1 +local m_currentColor = nil -- private functions +local function onAddonCheckChange(addon, value) + if addon:isChecked() then + m_outfit.addons = m_outfit.addons + value + else + m_outfit.addons = m_outfit.addons - value + end + m_creature:setOutfit(m_outfit) +end + local function update() - local creatureWidget = window:getChildById('creature') - creatureWidget:setOutfitType(outfits[currentOutfit][1]) - local nameWidget = window:getChildById('name') - nameWidget:setText(outfits[currentOutfit][2]) + nameWidget:setText(m_outfits[currentOutfit][2]) - local availableAddons = outfits[currentOutfit][3] + local availableAddons = m_outfits[currentOutfit][3] local addon1 = window:getChildById('addon1') local addon2 = window:getChildById('addon2') local addon3 = window:getChildById('addon3') + addon1.onCheckChange = function() onAddonCheckChange(addon1, 1) end + addon2.onCheckChange = function() onAddonCheckChange(addon2, 2) end + addon3.onCheckChange = function() onAddonCheckChange(addon3, 4) end addon1:setChecked(false) addon2:setChecked(false) addon3:setChecked(false) + addon1:setEnabled(false) + addon2:setEnabled(false) + addon3:setEnabled(false) -- Maybe rework this someday if availableAddons == 1 then - addon1:setChecked(true) + addon1:setEnabled(true) elseif availableAddons == 2 then - addon2:setChecked(true) + addon2:setEnabled(true) elseif availableAddons == 3 then - addon1:setChecked(true) - addon2:setChecked(true) + addon1:setEnabled(true) + addon2:setEnabled(true) elseif availableAddons == 4 then - addon3:setChecked(true) + addon3:setEnabled(true) elseif availableAddons == 5 then - addon1:setChecked(true) - addon3:setChecked(true) + addon1:setEnabled(true) + addon3:setEnabled(true) elseif availableAddons == 6 then - addon2:setChecked(true) - addon3:setChecked(true) + addon2:setEnabled(true) + addon3:setEnabled(true) elseif availableAddons == 7 then - addon1:setChecked(true) - addon2:setChecked(true) - addon3:setChecked(true) + addon1:setEnabled(true) + addon2:setEnabled(true) + addon3:setEnabled(true) end + m_outfit.type = m_outfits[currentOutfit][1] + m_outfit.addons = 0 + m_creature:setOutfit(m_outfit) + +end + +local function onColorCheckChange(color) + if color == m_currentColor then + color.onCheckChange = nil + color:setChecked(true) + color.onCheckChange = function() onColorCheckChange(color) end + else + m_currentColor.onCheckChange = nil + m_currentColor:setChecked(false) + local color2 = m_currentColor + m_currentColor.onCheckChange = function() onColorCheckChange(color2) end + + m_currentColor = color + + m_outfit.head = m_currentColor.colorId + m_creature:setOutfit(m_outfit) + end end -- public functions @@ -61,29 +98,35 @@ function Outfit.create(creature, outfitList) Outfit.destroy() window = loadUI("/outfit/outfit.otui", UI.root) window:lock() + + m_outfit = creature:getOutfit() local creatureWidget = window:getChildById('creature') creatureWidget:setCreature(creature) - local firstColor = UIWidget.create() - window:addChild(firstColor) - firstColor:setStyle('ColorFirst') - for i=0,18 do for j=0,6 do local color = UICheckBox.create() window:addChild(color) local outfitColor = getOufitColor(j*19 + i) - + color.colorId = j*19 + i color:setStyle('Color') color:setBackgroundColor(outfitColor) color:setMarginTop(j * 3 + j * 14) - color:setMarginLeft(i * 3 + i * 14) + color:setMarginLeft(10 + i * 3 + i * 14) + + if j*19 + i == m_outfit.head then + m_currentColor = color + color:setChecked(true) + end + + color.onCheckChange = function() onColorCheckChange(color) end end end - outfits = outfitList + m_creature = creature + m_outfits = outfitList currentOutfit = 1 update() end @@ -95,25 +138,27 @@ function Outfit.destroy() end end -function Outfit.nextType() +function Outfit.accept() + Game.setOutfit(m_outfit) + Outfit.destroy() +end +function Outfit.nextType() currentOutfit = currentOutfit + 1 - if currentOutfit > #outfits then + if currentOutfit > #m_outfits then currentOutfit = 1 end update() - end function Outfit.previousType() currentOutfit = currentOutfit - 1 if currentOutfit <= 0 then - currentOutfit = #outfits + currentOutfit = #m_outfits end update() - end -- hooked events diff --git a/modules/outfit/outfit.otui b/modules/outfit/outfit.otui index 4444d9a3..9a41e961 100644 --- a/modules/outfit/outfit.otui +++ b/modules/outfit/outfit.otui @@ -1,16 +1,10 @@ -ColorFirst < UIWidget - id: color - margin.left: 20 - anchors.top: creature.top - anchors.left: creature.right - Color < ColorBox - anchors.top: color.top - anchors.left: color.right + anchors.top: head.top + anchors.left: head.right Window title: Select Outfit - size: 450 280 + size: 550 280 anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter @@ -32,12 +26,37 @@ Window anchors.top: name.bottom anchors.left: name.left margin.top: 5 + + Button + id: head + text: Head + anchors.top: creature.top + anchors.left: creature.right + margin.left: 10 + + Button + id: primary + text: Primary + anchors.top: prev.bottom + anchors.left: prev.left + + Button + id: secondary + text: Secondary + anchors.top: prev.bottom + anchors.left: prev.left + + Button + id: detail + text: Detail + anchors.top: prev.bottom + anchors.left: prev.left Button @onClick: Outfit.nextType() text: >> width: 32 - margin.top: 3 + margin.top: 4 anchors.top: creature.bottom anchors.right: creature.right @@ -45,7 +64,7 @@ Window @onClick: Outfit.previousType() text: << width: 32 - margin.top: 3 + margin.top: 4 anchors.top: creature.bottom anchors.left: creature.left diff --git a/src/otclient/otclientluafunctions.cpp b/src/otclient/otclientluafunctions.cpp index 66fbaa10..f7311e68 100644 --- a/src/otclient/otclientluafunctions.cpp +++ b/src/otclient/otclientluafunctions.cpp @@ -86,8 +86,6 @@ 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 4f028202..c1760414 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -50,12 +50,3 @@ 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 dbf22ac6..89ce6906 100644 --- a/src/otclient/ui/uicreature.h +++ b/src/otclient/ui/uicreature.h @@ -34,7 +34,6 @@ public: void render(); void setCreature(const CreaturePtr& creature) { m_creature = creature; } - void setOutfitType(int outfitType); CreaturePtr getCreature() { return m_creature; }