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 rename Game to g_game, etc
implement Console key binding implement Console key binding
impl vertical sync, clipboard impl vertical sync, clipboard
crash handler
modify COnnection::poll() modify COnnection::poll()
setOnClose setOnClose
review and reenable some warnings review and reenable some warnings
make lua/c++ logger more friendly make lua/c++ logger more friendly
bind every global lua function in a static class bind every global lua function in a static class
use metatable for Point,Rect,Color,Size lua classes 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 set special types for g_configs like lists/point/size
restore ctrl+g and keybindings
create a class for reading binary files create a class for reading binary files
handle corrupt errors in dat/spr handle corrupt errors in dat/spr

View File

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

View File

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

View File

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