tibia-client/modules/game_outfit/outfit.lua

209 lines
5.7 KiB
Lua
Raw Normal View History

2011-11-14 23:32:55 +01:00
Outfit = {}
-- private variables
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
outfit.addons = outfit.addons + value
2011-11-16 19:52:41 +01:00
else
outfit.addons = outfit.addons - value
2011-11-16 19:52:41 +01:00
end
outfitCreature:setOutfit(outfit)
2011-11-16 19:52:41 +01:00
end
local function onColorCheckChange(colorBox)
if colorBox == currentColorBox then
colorBox.onCheckChange = nil
colorBox:setChecked(true)
colorBox.onCheckChange = onColorCheckChange
else
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
end
outfitCreature:setOutfit(outfit)
end
end
local function onClotheCheckChange(clotheButtonBox)
if clotheButtonBox == currentClotheButtonBox then
clotheButtonBox.onCheckChange = nil
clotheButtonBox:setChecked(true)
clotheButtonBox.onCheckChange = onClotheCheckChange
else
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
end
outfitWindow:recursiveGetChildById('colorBox' .. colorId):setChecked(true)
end
end
2011-11-16 19:52:41 +01:00
local function update()
local nameWidget = outfitWindow:getChildById('outfitName')
nameWidget:setText(outfits[currentOutfit][2])
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 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
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
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()
end
2011-11-14 23:32:55 +01:00
function Outfit.create(creature, outfitList)
outfitCreature = creature
outfits = outfitList
2011-11-14 23:47:36 +01:00
Outfit.destroy()
2011-11-17 21:40:31 +01:00
outfitWindow = displayUI('outfit.otui')
--outfitWindow:lock()
outfit = outfitCreature:getOutfit()
currentClotheButtonBox = outfitWindow:getChildById('head')
outfitWindow:getChildById('head').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('primary').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('secondary').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('detail').onCheckChange = onClotheCheckChange
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)
colorBox:setImageColor(outfitColor)
colorBox:setId('colorBox' .. j*19+i)
colorBox.colorId = j*19 + i
2011-11-17 21:40:31 +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
currentOutfit = 1
2011-11-16 22:28:47 +01:00
for i=1,#outfitList do
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()
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()
g_game.changeOutfit(outfit)
2011-11-16 19:52:41 +01:00
Outfit.destroy()
end
2011-11-16 19:52:41 +01:00
function Outfit.nextType()
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()
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