2011-11-14 23:32:55 +01:00
|
|
|
Outfit = {}
|
|
|
|
|
|
|
|
-- private variables
|
2012-03-22 22:47:52 +01:00
|
|
|
local outfitWindow
|
|
|
|
local outfitCreature
|
|
|
|
local outfit
|
|
|
|
local outfits
|
|
|
|
local currentOutfit = 1
|
|
|
|
local currentColorBox
|
|
|
|
local currentClotheButtonBox
|
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
|
2012-03-22 22:47:52 +01:00
|
|
|
outfit.addons = outfit.addons + value
|
2011-11-16 19:52:41 +01:00
|
|
|
else
|
2012-03-22 22:47:52 +01:00
|
|
|
outfit.addons = outfit.addons - value
|
2011-11-16 19:52:41 +01:00
|
|
|
end
|
2012-03-22 22:47:52 +01:00
|
|
|
outfitCreature:setOutfit(outfit)
|
2011-11-16 19:52:41 +01:00
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
local function onColorCheckChange(colorBox)
|
|
|
|
if colorBox == currentColorBox then
|
|
|
|
colorBox.onCheckChange = nil
|
|
|
|
colorBox:setChecked(true)
|
|
|
|
colorBox.onCheckChange = onColorCheckChange
|
2011-11-30 03:42:21 +01:00
|
|
|
else
|
2012-03-22 22:47:52 +01:00
|
|
|
currentColorBox.onCheckChange = nil
|
|
|
|
currentColorBox:setChecked(false)
|
|
|
|
currentColorBox.onCheckChange = onColorCheckChange
|
|
|
|
|
|
|
|
currentColorBox = colorBox
|
|
|
|
|
|
|
|
if currentClotheButtonBox:getId() == 'head' then
|
|
|
|
outfit.head = currentColorBox.colorId
|
|
|
|
elseif currentClotheButtonBox:getId() == 'primary' then
|
|
|
|
outfit.body = currentColorBox.colorId
|
|
|
|
elseif currentClotheButtonBox:getId() == 'secondary' then
|
|
|
|
outfit.legs = currentColorBox.colorId
|
|
|
|
elseif currentClotheButtonBox:getId() == 'detail' then
|
|
|
|
outfit.feet = currentColorBox.colorId
|
2011-11-30 03:42:21 +01:00
|
|
|
end
|
2012-01-03 01:42:53 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
outfitCreature:setOutfit(outfit)
|
2011-11-30 03:42:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
local function onClotheCheckChange(clotheButtonBox)
|
|
|
|
if clotheButtonBox == currentClotheButtonBox then
|
|
|
|
clotheButtonBox.onCheckChange = nil
|
|
|
|
clotheButtonBox:setChecked(true)
|
|
|
|
clotheButtonBox.onCheckChange = onClotheCheckChange
|
2011-11-30 03:42:21 +01:00
|
|
|
else
|
2012-03-22 22:47:52 +01:00
|
|
|
currentClotheButtonBox.onCheckChange = nil
|
|
|
|
currentClotheButtonBox:setChecked(false)
|
|
|
|
currentClotheButtonBox.onCheckChange = onClotheCheckChange
|
|
|
|
|
|
|
|
currentClotheButtonBox = clotheButtonBox
|
|
|
|
|
|
|
|
local colorId = 0
|
|
|
|
if currentClotheButtonBox:getId() == 'head' then
|
|
|
|
colorId = outfit.head
|
|
|
|
elseif currentClotheButtonBox:getId() == 'primary' then
|
|
|
|
colorId = outfit.body
|
|
|
|
elseif currentClotheButtonBox:getId() == 'secondary' then
|
|
|
|
colorId = outfit.legs
|
|
|
|
elseif currentClotheButtonBox:getId() == 'detail' then
|
|
|
|
colorId = outfit.feet
|
2011-11-30 03:42:21 +01:00
|
|
|
end
|
2012-03-22 22:47:52 +01:00
|
|
|
outfitWindow:recursiveGetChildById('colorBox' .. colorId):setChecked(true)
|
2011-11-30 03:42:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
local function update()
|
2012-03-22 22:47:52 +01:00
|
|
|
local nameWidget = outfitWindow:getChildById('outfitName')
|
|
|
|
nameWidget:setText(outfits[currentOutfit][2])
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
local availableAddons = outfits[currentOutfit][3]
|
|
|
|
local addon1 = outfitWindow:getChildById('addon1')
|
|
|
|
local addon2 = outfitWindow:getChildById('addon2')
|
|
|
|
local addon3 = outfitWindow:getChildById('addon3')
|
2011-11-16 08:20:14 +01:00
|
|
|
addon1:setChecked(false)
|
|
|
|
addon2:setChecked(false)
|
|
|
|
addon3:setChecked(false)
|
2011-11-30 21:21:46 +01:00
|
|
|
addon1.onCheckChange = function(self) onAddonCheckChange(self, 1) end
|
|
|
|
addon2.onCheckChange = function(self) onAddonCheckChange(self, 2) end
|
|
|
|
addon3.onCheckChange = function(self) onAddonCheckChange(self, 4) end
|
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
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
outfit.type = outfits[currentOutfit][1]
|
|
|
|
outfit.addons = 0
|
|
|
|
outfitCreature:setOutfit(outfit)
|
2011-11-16 19:52:41 +01:00
|
|
|
end
|
|
|
|
|
2011-11-14 23:32:55 +01:00
|
|
|
-- public functions
|
2012-03-22 22:47:52 +01:00
|
|
|
function Outfit.init()
|
|
|
|
connect(g_game, { onOpenOutfitWindow = Outfit.create,
|
|
|
|
onGameEnd = Outfit.destroy })
|
|
|
|
end
|
|
|
|
|
|
|
|
function Outfit.terminate()
|
|
|
|
disconnect(g_game, { onOpenOutfitWindow = Outfit.create,
|
|
|
|
onGameEnd = Outfit.destroy })
|
|
|
|
Outfit.destroy()
|
2012-04-27 06:54:14 +02:00
|
|
|
|
|
|
|
Outfit = nil
|
2012-03-22 22:47:52 +01:00
|
|
|
end
|
|
|
|
|
2011-11-14 23:32:55 +01:00
|
|
|
function Outfit.create(creature, outfitList)
|
2012-03-22 22:47:52 +01:00
|
|
|
outfitCreature = creature
|
|
|
|
outfits = outfitList
|
2011-11-14 23:47:36 +01:00
|
|
|
Outfit.destroy()
|
2011-11-17 21:40:31 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
outfitWindow = displayUI('outfit.otui')
|
|
|
|
--outfitWindow:lock()
|
2012-01-03 01:42:53 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
outfit = outfitCreature:getOutfit()
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
currentClotheButtonBox = outfitWindow:getChildById('head')
|
|
|
|
outfitWindow:getChildById('head').onCheckChange = onClotheCheckChange
|
|
|
|
outfitWindow:getChildById('primary').onCheckChange = onClotheCheckChange
|
|
|
|
outfitWindow:getChildById('secondary').onCheckChange = onClotheCheckChange
|
|
|
|
outfitWindow:getChildById('detail').onCheckChange = onClotheCheckChange
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
local outfitCreatureBox = outfitWindow:getChildById('outfitCreatureBox')
|
|
|
|
local colorBoxPanel = outfitWindow:getChildById('colorBoxPanel')
|
|
|
|
outfitCreatureBox:setCreature(outfitCreature)
|
|
|
|
|
|
|
|
for j=0,6 do
|
|
|
|
for i=0,18 do
|
|
|
|
local colorBox = createWidget('ColorBox', colorBoxPanel)
|
2011-11-16 08:20:14 +01:00
|
|
|
local outfitColor = getOufitColor(j*19 + i)
|
2012-03-22 22:47:52 +01:00
|
|
|
colorBox:setImageColor(outfitColor)
|
|
|
|
colorBox:setId('colorBox' .. j*19+i)
|
|
|
|
colorBox.colorId = j*19 + i
|
2011-11-17 21:40:31 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
if j*19 + i == outfit.head then
|
|
|
|
currentColorBox = colorBox
|
|
|
|
colorBox:setChecked(true)
|
|
|
|
end
|
|
|
|
colorBox.onCheckChange = onColorCheckChange
|
2011-11-16 08:20:14 +01:00
|
|
|
end
|
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2012-03-22 22:47:52 +01:00
|
|
|
currentOutfit = 1
|
2011-11-16 22:28:47 +01:00
|
|
|
for i=1,#outfitList do
|
2012-03-22 22:47:52 +01:00
|
|
|
if outfitList[i][1] == outfit.type then
|
|
|
|
currentOutfit = i
|
2011-11-16 22:28:47 +01:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-16 08:20:14 +01:00
|
|
|
update()
|
2011-11-14 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Outfit.destroy()
|
2012-03-22 22:47:52 +01:00
|
|
|
if outfitWindow then
|
|
|
|
outfitWindow:destroy()
|
|
|
|
outfitWindow = nil
|
|
|
|
outfitCreature = nil
|
|
|
|
currentColorBox = nil
|
|
|
|
currentClotheButtonBox = nil
|
2011-11-14 23:47:36 +01:00
|
|
|
end
|
2011-11-14 23:32:55 +01:00
|
|
|
end
|
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
function Outfit.accept()
|
2012-03-22 22:47:52 +01:00
|
|
|
g_game.changeOutfit(outfit)
|
2011-11-16 19:52:41 +01:00
|
|
|
Outfit.destroy()
|
|
|
|
end
|
2011-11-16 18:03:11 +01:00
|
|
|
|
2011-11-16 19:52:41 +01:00
|
|
|
function Outfit.nextType()
|
2012-03-22 22:47:52 +01:00
|
|
|
currentOutfit = currentOutfit + 1
|
|
|
|
if currentOutfit > #outfits then
|
|
|
|
currentOutfit = 1
|
2011-11-15 03:04:07 +01:00
|
|
|
end
|
2011-11-16 08:20:14 +01:00
|
|
|
update()
|
2011-11-15 03:04:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Outfit.previousType()
|
2012-03-22 22:47:52 +01:00
|
|
|
currentOutfit = currentOutfit - 1
|
|
|
|
if currentOutfit <= 0 then
|
|
|
|
currentOutfit = #outfits
|
2011-11-15 03:04:07 +01:00
|
|
|
end
|
2011-11-16 08:20:14 +01:00
|
|
|
update()
|
2011-11-15 03:04:07 +01:00
|
|
|
end
|
|
|
|
|