2011-11-14 23:32:55 +01:00
|
|
|
Outfit = {}
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local window = nil
|
2011-11-16 19:52:41 +01:00
|
|
|
local m_creature = nil
|
|
|
|
local m_outfit = nil
|
|
|
|
local m_outfits = nil
|
|
|
|
local m_currentOutfit = 1
|
|
|
|
local m_currentColor = nil
|
2011-11-14 23:32:55 +01:00
|
|
|
|
2011-11-16 08:20:14 +01:00
|
|
|
-- private functions
|
2011-11-16 19:52:41 +01:00
|
|
|
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
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
local function update()
|
2011-11-16 08:20:14 +01:00
|
|
|
local nameWidget = window:getChildById('name')
|
2011-11-16 19:52:41 +01:00
|
|
|
nameWidget:setText(m_outfits[currentOutfit][2])
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
local availableAddons = m_outfits[currentOutfit][3]
|
2011-11-16 08:20:14 +01:00
|
|
|
local addon1 = window:getChildById('addon1')
|
|
|
|
local addon2 = window:getChildById('addon2')
|
|
|
|
local addon3 = window:getChildById('addon3')
|
2011-11-16 19:52:41 +01:00
|
|
|
addon1.onCheckChange = function() onAddonCheckChange(addon1, 1) end
|
|
|
|
addon2.onCheckChange = function() onAddonCheckChange(addon2, 2) end
|
|
|
|
addon3.onCheckChange = function() onAddonCheckChange(addon3, 4) end
|
2011-11-16 08:20:14 +01:00
|
|
|
addon1:setChecked(false)
|
|
|
|
addon2:setChecked(false)
|
|
|
|
addon3:setChecked(false)
|
2011-11-16 19:52:41 +01:00
|
|
|
addon1:setEnabled(false)
|
|
|
|
addon2:setEnabled(false)
|
|
|
|
addon3:setEnabled(false)
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 08:20:14 +01:00
|
|
|
-- Maybe rework this someday
|
|
|
|
if availableAddons == 1 then
|
2011-11-16 19:52:41 +01:00
|
|
|
addon1:setEnabled(true)
|
2011-11-16 08:20:14 +01:00
|
|
|
elseif availableAddons == 2 then
|
2011-11-16 19:52:41 +01:00
|
|
|
addon2:setEnabled(true)
|
2011-11-16 08:20:14 +01:00
|
|
|
elseif availableAddons == 3 then
|
2011-11-16 19:52:41 +01:00
|
|
|
addon1:setEnabled(true)
|
|
|
|
addon2:setEnabled(true)
|
2011-11-16 08:20:14 +01:00
|
|
|
elseif availableAddons == 4 then
|
2011-11-16 19:52:41 +01:00
|
|
|
addon3:setEnabled(true)
|
2011-11-16 08:20:14 +01:00
|
|
|
elseif availableAddons == 5 then
|
2011-11-16 19:52:41 +01:00
|
|
|
addon1:setEnabled(true)
|
|
|
|
addon3:setEnabled(true)
|
2011-11-16 08:20:14 +01:00
|
|
|
elseif availableAddons == 6 then
|
2011-11-16 19:52:41 +01:00
|
|
|
addon2:setEnabled(true)
|
|
|
|
addon3:setEnabled(true)
|
2011-11-16 08:20:14 +01:00
|
|
|
elseif availableAddons == 7 then
|
2011-11-16 19:52:41 +01:00
|
|
|
addon1:setEnabled(true)
|
|
|
|
addon2:setEnabled(true)
|
|
|
|
addon3:setEnabled(true)
|
2011-11-16 08:20:14 +01:00
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
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
|
2011-11-16 08:20:14 +01:00
|
|
|
end
|
|
|
|
|
2011-11-14 23:32:55 +01:00
|
|
|
-- public functions
|
|
|
|
function Outfit.test()
|
|
|
|
local button = UIButton.create()
|
|
|
|
UI.root:addChild(button)
|
|
|
|
button:setText('Set Outfit')
|
|
|
|
button:setStyle('Button')
|
|
|
|
button:moveTo({x = 0, y = 100})
|
|
|
|
button:setWidth('100')
|
|
|
|
button:setHeight('30')
|
|
|
|
button.onClick = function() Game.openOutfitWindow() end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Outfit.create(creature, outfitList)
|
2011-11-14 23:47:36 +01:00
|
|
|
Outfit.destroy()
|
2011-11-14 23:32:55 +01:00
|
|
|
window = loadUI("/outfit/outfit.otui", UI.root)
|
2011-11-15 03:04:07 +01:00
|
|
|
window:lock()
|
2011-11-16 19:52:41 +01:00
|
|
|
|
|
|
|
m_outfit = creature:getOutfit()
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-14 23:32:55 +01:00
|
|
|
local creatureWidget = window:getChildById('creature')
|
|
|
|
creatureWidget:setCreature(creature)
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 08:20:14 +01:00
|
|
|
for i=0,18 do
|
|
|
|
for j=0,6 do
|
|
|
|
local color = UICheckBox.create()
|
|
|
|
window:addChild(color)
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 08:20:14 +01:00
|
|
|
local outfitColor = getOufitColor(j*19 + i)
|
2011-11-16 19:52:41 +01:00
|
|
|
color.colorId = j*19 + i
|
2011-11-16 08:20:14 +01:00
|
|
|
color:setStyle('Color')
|
|
|
|
color:setBackgroundColor(outfitColor)
|
2011-11-16 18:03:11 +01:00
|
|
|
color:setMarginTop(j * 3 + j * 14)
|
2011-11-16 19:52:41 +01:00
|
|
|
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
|
2011-11-16 08:20:14 +01:00
|
|
|
end
|
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
m_creature = creature
|
|
|
|
m_outfits = outfitList
|
2011-11-15 03:04:07 +01:00
|
|
|
currentOutfit = 1
|
2011-11-16 08:20:14 +01:00
|
|
|
update()
|
2011-11-14 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Outfit.destroy()
|
2011-11-14 23:47:36 +01:00
|
|
|
if window ~= nil then
|
|
|
|
window:destroy()
|
|
|
|
window = nil
|
|
|
|
end
|
2011-11-14 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
function Outfit.accept()
|
|
|
|
Game.setOutfit(m_outfit)
|
|
|
|
Outfit.destroy()
|
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
function Outfit.nextType()
|
2011-11-15 03:04:07 +01:00
|
|
|
currentOutfit = currentOutfit + 1
|
2011-11-16 19:52:41 +01:00
|
|
|
if currentOutfit > #m_outfits then
|
2011-11-15 03:04:07 +01:00
|
|
|
currentOutfit = 1
|
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 08:20:14 +01:00
|
|
|
update()
|
2011-11-15 03:04:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Outfit.previousType()
|
|
|
|
currentOutfit = currentOutfit - 1
|
|
|
|
if currentOutfit <= 0 then
|
2011-11-16 19:52:41 +01:00
|
|
|
currentOutfit = #m_outfits
|
2011-11-15 03:04:07 +01:00
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 08:20:14 +01:00
|
|
|
update()
|
2011-11-15 03:04:07 +01:00
|
|
|
end
|
|
|
|
|
2011-11-14 23:32:55 +01:00
|
|
|
-- hooked events
|
|
|
|
|
|
|
|
connect(Game, { onOpenOutfitWindow = Outfit.create,
|
|
|
|
onLogout = Outfit.destroy })
|
|
|
|
|
|
|
|
connect(Game, { onLogin = Outfit.test })
|