reorganize modules

This commit is contained in:
Eduardo Bart
2011-12-05 16:27:07 -02:00
parent ffeb34e0e7
commit cf0aab6d4d
90 changed files with 186 additions and 181 deletions

View 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 })

View File

@@ -0,0 +1,8 @@
Module
name: game_skills
description: Manage skills window
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'skills'
return true

View File

@@ -0,0 +1,44 @@
SkillFirstWidget < UIWidget
SkillButton < UIButton
height: 14
margin-top: 4
margin-left: 10
margin-right: 10
SkillNameLabel < Label
font: verdana-11px-monochrome
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
SkillLevelLabel < Label
font: verdana-11px-monochrome
text-align: right
width: 32
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
SkillPercentPanel < UIProgressBar
color: black
background-color: green
tooltip: test
height: 5
margin-top: 3
margin-left: 10
margin-right: 10
MiniWindow
id: skillWindow
title: Skills
size: 200 220
Panel
id: skillPanel
anchors.fill: parent
margin-top: 26
margin-bottom: 3
margin-left: 3
margin-right: 3
layout: verticalBox