mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 03:24:55 +02:00
rework on healthbar module
This commit is contained in:
@@ -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()
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user