tibia-client/modules/game_skills/skills.lua

68 lines
1.9 KiB
Lua
Raw Normal View History

Skills = {}
2011-09-13 23:54:23 +02:00
-- private variables
local skillWindow = nil
local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}
2011-09-13 23:54:23 +02:00
-- public functions
function Skills.create()
2011-11-17 21:40:31 +01:00
skillWindow = UI.display('skills.otui', { parent = Game.gameRightPanel })
2011-09-13 23:54:23 +02:00
local skillPanel = skillWindow:getChildById('skillPanel')
2011-09-13 23:54:23 +02:00
-- create first widget cause of layout
local widget = UIWidget.create()
skillPanel:addChild(widget)
widget:setStyle('SkillFirstWidget')
2011-09-13 23:54:23 +02:00
-- create skills
for i=1,#skills,1 do
2011-11-14 09:46:27 +01:00
local skillButton = UIButton.create()
skillPanel:addChild(skillButton)
skillButton:setStyle('SkillButton')
2011-09-13 23:54:23 +02:00
local nameLabel = UILabel.create()
2011-11-14 09:46:27 +01:00
skillButton :addChild(nameLabel)
2011-09-13 23:54:23 +02:00
nameLabel:setStyle('SkillNameLabel')
nameLabel:setText(skills[i])
2011-11-14 09:46:27 +01:00
nameLabel:resizeToText()
2011-09-13 23:54:23 +02:00
local levelLabel = UILabel.create()
2011-11-14 20:33:49 +01:00
skillButton:addChild(levelLabel)
2011-09-13 23:54:23 +02:00
levelLabel:setStyle('SkillLevelLabel')
levelLabel:setId('skillLevelId' .. i)
2011-11-03 23:14:56 +01:00
levelLabel:setText('0')
2011-11-14 03:40:18 +01:00
local percentBar = UIProgressBar.create()
skillPanel:addChild(percentBar)
percentBar:setStyle('SkillPercentPanel')
percentBar:setId('skillPercentId' .. i)
2011-11-14 09:46:27 +01:00
skillButton.onClick = function(self)
percentBar:setVisible(not percentBar:isVisible())
self:updateParentLayout()
return true
end
2011-09-13 23:54:23 +02:00
end
end
function Skills.destroy()
skillWindow:destroy()
skillWindow = nil
end
-- hooked events
2011-11-04 00:34:32 +01:00
function Game.onSkillUpdate(id, level, percent)
2011-11-14 09:46:27 +01:00
local skillPanel = skillWindow:recursiveGetChildById('skillPanel')
2011-11-03 23:14:56 +01:00
2011-11-14 09:46:27 +01:00
local levelLabel = skillPanel:recursiveGetChildById('skillLevelId' .. (id + 1))
2011-11-03 23:14:56 +01:00
levelLabel:setText(level)
2011-11-14 03:40:18 +01:00
local percentBar = skillPanel:getChildById('skillPercentId' .. (id + 1))
percentBar:setPercent(percent)
percentBar:setTooltip(percent .. "% to go")
end
connect(Game, { onLogin = Skills.create,
2011-11-03 23:14:56 +01:00
onLogout = Skills.destroy })