tibia-client/modules/outfit/outfit.lua

125 lines
2.8 KiB
Lua
Raw Normal View History

2011-11-14 23:32:55 +01:00
Outfit = {}
-- private variables
local window = nil
2011-11-15 03:04:07 +01:00
local outfits = nil
local currentOutfit = 1
2011-11-14 23:32:55 +01:00
2011-11-16 08:20:14 +01:00
-- private functions
local function update()
local creatureWidget = window:getChildById('creature')
creatureWidget:setOutfitType(outfits[currentOutfit][1])
2011-11-16 08:20:14 +01:00
local nameWidget = window:getChildById('name')
nameWidget:setText(outfits[currentOutfit][2])
2011-11-16 08:20:14 +01:00
local availableAddons = outfits[currentOutfit][3]
local addon1 = window:getChildById('addon1')
local addon2 = window:getChildById('addon2')
local addon3 = window:getChildById('addon3')
addon1:setChecked(false)
addon2:setChecked(false)
addon3:setChecked(false)
2011-11-16 08:20:14 +01:00
-- Maybe rework this someday
if availableAddons == 1 then
addon1:setChecked(true)
elseif availableAddons == 2 then
addon2:setChecked(true)
elseif availableAddons == 3 then
addon1:setChecked(true)
addon2:setChecked(true)
elseif availableAddons == 4 then
addon3:setChecked(true)
elseif availableAddons == 5 then
addon1:setChecked(true)
addon3:setChecked(true)
elseif availableAddons == 6 then
addon2:setChecked(true)
addon3:setChecked(true)
elseif availableAddons == 7 then
addon1:setChecked(true)
addon2:setChecked(true)
addon3:setChecked(true)
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-14 23:32:55 +01:00
local creatureWidget = window:getChildById('creature')
creatureWidget:setCreature(creature)
2011-11-16 08:20:14 +01:00
local firstColor = UIWidget.create()
window:addChild(firstColor)
firstColor:setStyle('ColorFirst')
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 08:20:14 +01:00
local outfitColor = getOufitColor(j*19 + i)
2011-11-16 08:20:14 +01:00
color:setStyle('Color')
color:setBackgroundColor(outfitColor)
color:setMarginTop(j * 3 + j * 14)
color:setMarginLeft(i * 3 + i * 14)
2011-11-16 08:20:14 +01:00
end
end
2011-11-15 03:04:07 +01:00
outfits = outfitList
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-15 03:04:07 +01:00
function Outfit.nextType()
2011-11-15 03:04:07 +01:00
currentOutfit = currentOutfit + 1
if currentOutfit > #outfits then
currentOutfit = 1
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
end
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 })