From 91572b4802493041079e8d5cde8f91812b682c2a Mon Sep 17 00:00:00 2001 From: Henrique Date: Mon, 14 Nov 2011 06:21:01 -0200 Subject: [PATCH] health bar improvements --- modules/health_mana/health_mana.lua | 18 ++++++++- modules/health_mana/health_mana.otui | 27 ++++++++++---- modules/skills/skills.lua~ | 56 ---------------------------- 3 files changed, 37 insertions(+), 64 deletions(-) delete mode 100644 modules/skills/skills.lua~ diff --git a/modules/health_mana/health_mana.lua b/modules/health_mana/health_mana.lua index f74eee85..388d11dc 100644 --- a/modules/health_mana/health_mana.lua +++ b/modules/health_mana/health_mana.lua @@ -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, diff --git a/modules/health_mana/health_mana.otui b/modules/health_mana/health_mana.otui index e653d36a..856a476e 100644 --- a/modules/health_mana/health_mana.otui +++ b/modules/health_mana/health_mana.otui @@ -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 diff --git a/modules/skills/skills.lua~ b/modules/skills/skills.lua~ deleted file mode 100644 index fcded665..00000000 --- a/modules/skills/skills.lua~ +++ /dev/null @@ -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 })