From 26800dfe2a37507e365abee4323fab016718c127 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Tue, 3 Jan 2012 13:17:52 -0200 Subject: [PATCH] rework on healthbar module --- TODO | 4 -- .../core_widgets/messagebox/messagebox.lua | 1 - modules/game_healthbar/healthbar.lua | 42 +++++++------------ modules/game_healthbar/healthbar.otui | 21 ++++++---- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/TODO b/TODO index 2b806db3..431c99fe 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/modules/core_widgets/messagebox/messagebox.lua b/modules/core_widgets/messagebox/messagebox.lua index 4eecbae6..8f2186db 100644 --- a/modules/core_widgets/messagebox/messagebox.lua +++ b/modules/core_widgets/messagebox/messagebox.lua @@ -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() diff --git a/modules/game_healthbar/healthbar.lua b/modules/game_healthbar/healthbar.lua index 440b7ea9..d6e74241 100644 --- a/modules/game_healthbar/healthbar.lua +++ b/modules/game_healthbar/healthbar.lua @@ -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 diff --git a/modules/game_healthbar/healthbar.otui b/modules/game_healthbar/healthbar.otui index b1ce60d7..98338987 100644 --- a/modules/game_healthbar/healthbar.otui +++ b/modules/game_healthbar/healthbar.otui @@ -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