rework on healthbar module

This commit is contained in:
Eduardo Bart 2012-01-03 13:17:52 -02:00
parent f750920a36
commit 26800dfe2a
4 changed files with 30 additions and 38 deletions

4
TODO
View File

@ -20,17 +20,13 @@ find a way to add new widgets without focusing them
rename Game to g_game, etc
implement Console key binding
impl vertical sync, clipboard
crash handler
modify COnnection::poll()
setOnClose
review and reenable some warnings
make lua/c++ logger more friendly
bind every global lua function in a static class
use metatable for Point,Rect,Color,Size lua classes
lua binder generator
restore win32 platform
set special types for g_configs like lists/point/size
restore ctrl+g and keybindings
create a class for reading binary files
handle corrupt errors in dat/spr

View File

@ -14,7 +14,6 @@ function MessageBox.create(title, text, flags)
window:setTitle(title)
local label = window:getChildById('messageBoxLabel')
label:setStyle('Label')
label:setText(text)
label:resizeToText()

View File

@ -1,54 +1,44 @@
HealthBar = {}
-- private variables
local healthManaPanel = nil
local healthManaPanel
local healthBar
local manaBar
local healthLabel
local manaLabel
-- public functions
function HealthBar.create()
healthManaPanel = displayUI('healthbar.otui', { parent = Game.gameRightPanel })
local healthBar = createWidget('HealthBar', healthManaPanel)
healthBar:setId('healthBar')
local healthLabel = createWidget('HealthLabel', healthManaPanel)
healthLabel:setId('healthLabel')
healthLabel:setText('0 / 0')
local manaBar = createWidget('ManaBar', healthManaPanel)
manaBar:setId('manaBar')
local manaLabel = createWidget('ManaLabel', healthManaPanel)
manaLabel:setId('manaLabel')
manaLabel:setText('0 / 0')
healthManaPanel:setHeight(healthBar:getHeight() + manaBar:getHeight() + 4)
healthBar = healthManaPanel:getChildById('healthBar')
manaBar = healthManaPanel:getChildById('manaBar')
healthLabel = healthManaPanel:getChildById('healthLabel')
manaLabel = healthManaPanel:getChildById('manaLabel')
end
function HealthBar.destroy()
healthManaPanel:destroy()
healthManaPanel = nil
healthBar = nil
manaBar = nil
healthLabel = nil
manaLabel = nil
end
-- hooked events
function HealthBar.onHealthChange(health, maxHealth)
local label = healthManaPanel:getChildById('healthLabel')
label:setText(health .. ' / ' .. maxHealth)
local healthBar = healthManaPanel:getChildById('healthBar')
healthLabel:setText(health .. ' / ' .. maxHealth)
healthBar:setPercent(health / maxHealth * 100)
end
function HealthBar.onManaChange(mana, maxMana)
local label = healthManaPanel:getChildById('manaLabel')
label:setText(mana .. ' / ' .. maxMana)
local manaBar = healthManaPanel:getChildById('manaBar')
manaLabel:setText(mana .. ' / ' .. maxMana)
local percent
if maxMana == 0 then
percent = 100
else
percent = mana / maxMana * 100
percent = (mana * 100)/maxMana
end
manaBar:setPercent(percent)
end

View File

@ -1,4 +1,5 @@
HealthBar < UIProgressBar
id: healthBar
color: black
height: 15
background-color: red
@ -7,6 +8,7 @@ HealthBar < UIProgressBar
anchors.right: parent.right
ManaBar < UIProgressBar
id: manaBar
color: black
height: 15
background-color: blue
@ -15,28 +17,33 @@ ManaBar < UIProgressBar
anchors.right: parent.right
HealthLabel < GameLabel
id: healthLabel
color: white
text-align: center
font: verdana-11px-rounded
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.fill: healthBar
margin-top: 2
text: 0 / 0
ManaLabel < GameLabel
id: manaLabel
color: white
text-align: center
font: verdana-11px-rounded
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin-bottom: -1
anchors.fill: manaBar
margin-top: 2
text: 0 / 0
UIWindow
id: healthManaPanel
width: 192
height: 34
margin-top: 10
margin-left: 6
margin-right: 6
move-policy: free updated
HealthBar
HealthLabel
ManaBar
ManaLabel