2011-11-03 13:17:10 +01:00
|
|
|
Skills = {}
|
2011-09-13 23:54:23 +02:00
|
|
|
|
2011-11-03 13:17:10 +01:00
|
|
|
-- private variables
|
|
|
|
local skillWindow = nil
|
2011-11-03 10:59:11 +01:00
|
|
|
local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}
|
2011-09-13 23:54:23 +02:00
|
|
|
|
2011-11-03 13:17:10 +01:00
|
|
|
-- public functions
|
|
|
|
function Skills.create()
|
|
|
|
skillWindow = loadUI("/skills/skills.otui", Game.gameRightPanel)
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2011-09-13 23:54:23 +02:00
|
|
|
local skillPanel = skillWindow:getChildById('skillPanel')
|
2011-11-03 10:59:11 +01:00
|
|
|
|
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-11-03 10:59:11 +01:00
|
|
|
|
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-03 10:59:11 +01:00
|
|
|
|
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
|
|
|
|
|
2011-11-03 13:17:10 +01:00
|
|
|
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")
|
2011-11-03 21:54:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
connect(Game, { onLogin = Skills.create,
|
2011-11-03 23:14:56 +01:00
|
|
|
onLogout = Skills.destroy })
|