mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
reorganize modules
This commit is contained in:
67
modules/game_skills/skills.lua
Normal file
67
modules/game_skills/skills.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
Skills = {}
|
||||
|
||||
-- private variables
|
||||
local skillWindow = nil
|
||||
local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}
|
||||
|
||||
-- public functions
|
||||
function Skills.create()
|
||||
skillWindow = UI.display('skills.otui', { parent = Game.gameRightPanel })
|
||||
|
||||
local skillPanel = skillWindow:getChildById('skillPanel')
|
||||
|
||||
-- create first widget cause of layout
|
||||
local widget = UIWidget.create()
|
||||
skillPanel:addChild(widget)
|
||||
widget:setStyle('SkillFirstWidget')
|
||||
|
||||
-- create skills
|
||||
for i=1,#skills,1 do
|
||||
local skillButton = UIButton.create()
|
||||
skillPanel:addChild(skillButton)
|
||||
skillButton:setStyle('SkillButton')
|
||||
|
||||
local nameLabel = UILabel.create()
|
||||
skillButton :addChild(nameLabel)
|
||||
nameLabel:setStyle('SkillNameLabel')
|
||||
nameLabel:setText(skills[i])
|
||||
nameLabel:resizeToText()
|
||||
|
||||
local levelLabel = UILabel.create()
|
||||
skillButton:addChild(levelLabel)
|
||||
levelLabel:setStyle('SkillLevelLabel')
|
||||
levelLabel:setId('skillLevelId' .. i)
|
||||
levelLabel:setText('0')
|
||||
|
||||
local percentBar = UIProgressBar.create()
|
||||
skillPanel:addChild(percentBar)
|
||||
percentBar:setStyle('SkillPercentPanel')
|
||||
percentBar:setId('skillPercentId' .. i)
|
||||
|
||||
skillButton.onClick = function(self)
|
||||
percentBar:setVisible(not percentBar:isVisible())
|
||||
self:updateParentLayout()
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Skills.destroy()
|
||||
skillWindow:destroy()
|
||||
skillWindow = nil
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
function Game.onSkillUpdate(id, level, percent)
|
||||
local skillPanel = skillWindow:recursiveGetChildById('skillPanel')
|
||||
|
||||
local levelLabel = skillPanel:recursiveGetChildById('skillLevelId' .. (id + 1))
|
||||
levelLabel:setText(level)
|
||||
|
||||
local percentBar = skillPanel:getChildById('skillPercentId' .. (id + 1))
|
||||
percentBar:setPercent(percent)
|
||||
percentBar:setTooltip(percent .. "% to go")
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = Skills.create,
|
||||
onLogout = Skills.destroy })
|
Reference in New Issue
Block a user