health bar improvements
This commit is contained in:
parent
e74bca2c3a
commit
91572b4802
|
@ -7,11 +7,21 @@ local healthManaPanel = nil
|
|||
function HealthMana.create()
|
||||
healthManaPanel = loadUI("/health_mana/health_mana.otui", Game.gameRightPanel)
|
||||
|
||||
local healthBar = UIProgressBar.create()
|
||||
healthManaPanel:addChild(healthBar)
|
||||
healthBar:setId('healthBar')
|
||||
healthBar:setStyle('HealthBar')
|
||||
|
||||
local healthLabel = UILabel.create()
|
||||
healthManaPanel:addChild(healthLabel)
|
||||
healthLabel:setId('healthLabel')
|
||||
healthLabel:setStyle('HealthLabel')
|
||||
healthLabel:setText('0 / 0')
|
||||
|
||||
local manaBar = UIProgressBar.create()
|
||||
healthManaPanel:addChild(manaBar)
|
||||
manaBar:setId('manaBar')
|
||||
manaBar:setStyle('ManaBar')
|
||||
|
||||
local manaLabel = UILabel.create()
|
||||
healthManaPanel:addChild(manaLabel)
|
||||
|
@ -19,7 +29,7 @@ function HealthMana.create()
|
|||
manaLabel:setStyle('ManaLabel')
|
||||
manaLabel:setText('0 / 0')
|
||||
|
||||
healthManaPanel:setHeight(healthLabel:getHeight() + manaLabel:getHeight())
|
||||
healthManaPanel:setHeight(healthBar:getHeight() + manaBar:getHeight() + 4)
|
||||
end
|
||||
|
||||
function HealthMana.destroy()
|
||||
|
@ -31,11 +41,17 @@ end
|
|||
function Game.onHealthChange(health, maxHealth)
|
||||
local label = healthManaPanel:getChildById('healthLabel')
|
||||
label:setText(health .. ' / ' .. maxHealth)
|
||||
|
||||
local healthBar = healthManaPanel:getChildById('healthBar')
|
||||
healthBar:setPercent(health / maxHealth * 100)
|
||||
end
|
||||
|
||||
function Game.onManaChange(mana, maxMana)
|
||||
local label = healthManaPanel:getChildById('manaLabel')
|
||||
label:setText(mana .. ' / ' .. maxMana)
|
||||
|
||||
local manaBar = healthManaPanel:getChildById('manaBar')
|
||||
manaBar:setPercent(mana / maxMana * 100)
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = HealthMana.create,
|
||||
|
|
|
@ -1,22 +1,36 @@
|
|||
HealthBar < UIProgressBar
|
||||
color: black
|
||||
height: 15
|
||||
background-color: red
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
||||
ManaBar < UIProgressBar
|
||||
color: black
|
||||
height: 15
|
||||
background-color: blue
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
||||
HealthLabel < Label
|
||||
color: white
|
||||
background-color: red
|
||||
align: center
|
||||
font: verdana-11px-monochrome
|
||||
font: verdana-11px-rounded
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
image: /core_styles/images/empty_rect.png
|
||||
margin.top: 2
|
||||
|
||||
ManaLabel < Label
|
||||
color: white
|
||||
background-color: blue
|
||||
align: center
|
||||
font: verdana-11px-monochrome
|
||||
font: verdana-11px-rounded
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
image: /core_styles/images/empty_rect.png
|
||||
margin.bottom: -1
|
||||
|
||||
UIWindow
|
||||
id: healthManaPanel
|
||||
|
@ -25,5 +39,4 @@ UIWindow
|
|||
margin.left: 6
|
||||
margin.right: 6
|
||||
move policy: free updated
|
||||
image: /core_styles/images/empty_rect.png
|
||||
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
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 = loadUI("/skills/skills.otui", 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 nameLabel = UILabel.create()
|
||||
skillPanel:addChild(nameLabel)
|
||||
nameLabel:setStyle('SkillNameLabel')
|
||||
nameLabel:setText(skills[i])
|
||||
|
||||
local levelLabel = UILabel.create()
|
||||
skillPanel: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)
|
||||
end
|
||||
end
|
||||
|
||||
function Skills.destroy()
|
||||
skillWindow:destroy()
|
||||
skillWindow = nil
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
function Game.onSkillUpdate(id, level, percent)
|
||||
local skillPanel = skillWindow:getChildById('skillPanel')
|
||||
|
||||
local levelLabel = skillPanel:getChildById('skillLevelId' .. (id + 1))
|
||||
levelLabel:setText(level)
|
||||
|
||||
local percentBar = skillPanel:getChildById('skillPercentId' .. (id + 1))
|
||||
percentBar:setPercent(percent)
|
||||
percentBar:setTooltip("lalalalal2")
|
||||
end
|
||||
|
||||
connect(Game, { onLogin = Skills.create,
|
||||
onLogout = Skills.destroy })
|
Loading…
Reference in New Issue