outfit changing hair
This commit is contained in:
parent
558872f57d
commit
f381cb0a74
|
@ -2,47 +2,84 @@ Outfit = {}
|
||||||
|
|
||||||
-- private variables
|
-- private variables
|
||||||
local window = nil
|
local window = nil
|
||||||
local outfits = nil
|
local m_creature = nil
|
||||||
local currentOutfit = 1
|
local m_outfit = nil
|
||||||
|
local m_outfits = nil
|
||||||
|
local m_currentOutfit = 1
|
||||||
|
local m_currentColor = nil
|
||||||
|
|
||||||
-- private functions
|
-- 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 function update()
|
||||||
local creatureWidget = window:getChildById('creature')
|
|
||||||
creatureWidget:setOutfitType(outfits[currentOutfit][1])
|
|
||||||
|
|
||||||
local nameWidget = window:getChildById('name')
|
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 addon1 = window:getChildById('addon1')
|
||||||
local addon2 = window:getChildById('addon2')
|
local addon2 = window:getChildById('addon2')
|
||||||
local addon3 = window:getChildById('addon3')
|
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)
|
addon1:setChecked(false)
|
||||||
addon2:setChecked(false)
|
addon2:setChecked(false)
|
||||||
addon3:setChecked(false)
|
addon3:setChecked(false)
|
||||||
|
addon1:setEnabled(false)
|
||||||
|
addon2:setEnabled(false)
|
||||||
|
addon3:setEnabled(false)
|
||||||
|
|
||||||
-- Maybe rework this someday
|
-- Maybe rework this someday
|
||||||
if availableAddons == 1 then
|
if availableAddons == 1 then
|
||||||
addon1:setChecked(true)
|
addon1:setEnabled(true)
|
||||||
elseif availableAddons == 2 then
|
elseif availableAddons == 2 then
|
||||||
addon2:setChecked(true)
|
addon2:setEnabled(true)
|
||||||
elseif availableAddons == 3 then
|
elseif availableAddons == 3 then
|
||||||
addon1:setChecked(true)
|
addon1:setEnabled(true)
|
||||||
addon2:setChecked(true)
|
addon2:setEnabled(true)
|
||||||
elseif availableAddons == 4 then
|
elseif availableAddons == 4 then
|
||||||
addon3:setChecked(true)
|
addon3:setEnabled(true)
|
||||||
elseif availableAddons == 5 then
|
elseif availableAddons == 5 then
|
||||||
addon1:setChecked(true)
|
addon1:setEnabled(true)
|
||||||
addon3:setChecked(true)
|
addon3:setEnabled(true)
|
||||||
elseif availableAddons == 6 then
|
elseif availableAddons == 6 then
|
||||||
addon2:setChecked(true)
|
addon2:setEnabled(true)
|
||||||
addon3:setChecked(true)
|
addon3:setEnabled(true)
|
||||||
elseif availableAddons == 7 then
|
elseif availableAddons == 7 then
|
||||||
addon1:setChecked(true)
|
addon1:setEnabled(true)
|
||||||
addon2:setChecked(true)
|
addon2:setEnabled(true)
|
||||||
addon3:setChecked(true)
|
addon3:setEnabled(true)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
|
@ -62,28 +99,34 @@ function Outfit.create(creature, outfitList)
|
||||||
window = loadUI("/outfit/outfit.otui", UI.root)
|
window = loadUI("/outfit/outfit.otui", UI.root)
|
||||||
window:lock()
|
window:lock()
|
||||||
|
|
||||||
|
m_outfit = creature:getOutfit()
|
||||||
|
|
||||||
local creatureWidget = window:getChildById('creature')
|
local creatureWidget = window:getChildById('creature')
|
||||||
creatureWidget:setCreature(creature)
|
creatureWidget:setCreature(creature)
|
||||||
|
|
||||||
local firstColor = UIWidget.create()
|
|
||||||
window:addChild(firstColor)
|
|
||||||
firstColor:setStyle('ColorFirst')
|
|
||||||
|
|
||||||
for i=0,18 do
|
for i=0,18 do
|
||||||
for j=0,6 do
|
for j=0,6 do
|
||||||
local color = UICheckBox.create()
|
local color = UICheckBox.create()
|
||||||
window:addChild(color)
|
window:addChild(color)
|
||||||
|
|
||||||
local outfitColor = getOufitColor(j*19 + i)
|
local outfitColor = getOufitColor(j*19 + i)
|
||||||
|
color.colorId = j*19 + i
|
||||||
color:setStyle('Color')
|
color:setStyle('Color')
|
||||||
color:setBackgroundColor(outfitColor)
|
color:setBackgroundColor(outfitColor)
|
||||||
color:setMarginTop(j * 3 + j * 14)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
outfits = outfitList
|
m_creature = creature
|
||||||
|
m_outfits = outfitList
|
||||||
currentOutfit = 1
|
currentOutfit = 1
|
||||||
update()
|
update()
|
||||||
end
|
end
|
||||||
|
@ -95,25 +138,27 @@ function Outfit.destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Outfit.nextType()
|
function Outfit.accept()
|
||||||
|
Game.setOutfit(m_outfit)
|
||||||
|
Outfit.destroy()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Outfit.nextType()
|
||||||
currentOutfit = currentOutfit + 1
|
currentOutfit = currentOutfit + 1
|
||||||
if currentOutfit > #outfits then
|
if currentOutfit > #m_outfits then
|
||||||
currentOutfit = 1
|
currentOutfit = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Outfit.previousType()
|
function Outfit.previousType()
|
||||||
currentOutfit = currentOutfit - 1
|
currentOutfit = currentOutfit - 1
|
||||||
if currentOutfit <= 0 then
|
if currentOutfit <= 0 then
|
||||||
currentOutfit = #outfits
|
currentOutfit = #m_outfits
|
||||||
end
|
end
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hooked events
|
-- hooked events
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
ColorFirst < UIWidget
|
|
||||||
id: color
|
|
||||||
margin.left: 20
|
|
||||||
anchors.top: creature.top
|
|
||||||
anchors.left: creature.right
|
|
||||||
|
|
||||||
Color < ColorBox
|
Color < ColorBox
|
||||||
anchors.top: color.top
|
anchors.top: head.top
|
||||||
anchors.left: color.right
|
anchors.left: head.right
|
||||||
|
|
||||||
Window
|
Window
|
||||||
title: Select Outfit
|
title: Select Outfit
|
||||||
size: 450 280
|
size: 550 280
|
||||||
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
@ -33,11 +27,36 @@ Window
|
||||||
anchors.left: name.left
|
anchors.left: name.left
|
||||||
margin.top: 5
|
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
|
Button
|
||||||
@onClick: Outfit.nextType()
|
@onClick: Outfit.nextType()
|
||||||
text: >>
|
text: >>
|
||||||
width: 32
|
width: 32
|
||||||
margin.top: 3
|
margin.top: 4
|
||||||
anchors.top: creature.bottom
|
anchors.top: creature.bottom
|
||||||
anchors.right: creature.right
|
anchors.right: creature.right
|
||||||
|
|
||||||
|
@ -45,7 +64,7 @@ Window
|
||||||
@onClick: Outfit.previousType()
|
@onClick: Outfit.previousType()
|
||||||
text: <<
|
text: <<
|
||||||
width: 32
|
width: 32
|
||||||
margin.top: 3
|
margin.top: 4
|
||||||
anchors.top: creature.bottom
|
anchors.top: creature.bottom
|
||||||
anchors.left: creature.left
|
anchors.left: creature.left
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,6 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction<UICreature>("create", &UICreature::create<UICreature>);
|
g_lua.bindClassStaticFunction<UICreature>("create", &UICreature::create<UICreature>);
|
||||||
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
|
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
|
||||||
g_lua.bindClassMemberFunction<UICreature>("setCreature", &UICreature::setCreature);
|
g_lua.bindClassMemberFunction<UICreature>("setCreature", &UICreature::setCreature);
|
||||||
g_lua.bindClassMemberFunction<UICreature>("setOutfitType", &UICreature::setOutfitType);
|
|
||||||
|
|
||||||
|
|
||||||
g_lua.registerClass<UIMap, UIWidget>();
|
g_lua.registerClass<UIMap, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UIMap>("create", &UIWidget::create<UIMap>);
|
g_lua.bindClassStaticFunction<UIMap>("create", &UIWidget::create<UIMap>);
|
||||||
|
|
|
@ -50,12 +50,3 @@ void UICreature::onStyleApply(const OTMLNodePtr& styleNode)
|
||||||
|
|
||||||
UIWidget::onStyleApply(styleNode);
|
UIWidget::onStyleApply(styleNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UICreature::setOutfitType(int outfitType)
|
|
||||||
{
|
|
||||||
if(m_creature) {
|
|
||||||
Outfit outfit = m_creature->getOutfit();
|
|
||||||
outfit.setType(outfitType);
|
|
||||||
m_creature->setOutfit(outfit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ public:
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
||||||
void setOutfitType(int outfitType);
|
|
||||||
|
|
||||||
CreaturePtr getCreature() { return m_creature; }
|
CreaturePtr getCreature() { return m_creature; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue