Exp bar on healthinfo module

This commit is contained in:
Ricardo Ianelli 2013-02-10 03:31:12 -02:00
parent b08d0ff157
commit 9c0c19b5b2
2 changed files with 42 additions and 4 deletions

View File

@ -20,15 +20,18 @@ Icons[65536] = { tooltip = tr('You are hungry'), path = '/images/game/states/hun
healthInfoWindow = nil healthInfoWindow = nil
healthBar = nil healthBar = nil
manaBar = nil manaBar = nil
experienceBar = nil
soulBar = nil soulBar = nil
healthLabel = nil healthLabel = nil
manaLabel = nil manaLabel = nil
experienceLabel = nil
soulLabel = nil soulLabel = nil
capLabel = nil capLabel = nil
function init() function init()
connect(LocalPlayer, { onHealthChange = onHealthChange, connect(LocalPlayer, { onHealthChange = onHealthChange,
onManaChange = onManaChange, onManaChange = onManaChange,
onLevelChange = onLevelChange,
onStatesChange = onStatesChange, onStatesChange = onStatesChange,
onSoulChange = onSoulChange, onSoulChange = onSoulChange,
onFreeCapacityChange = onFreeCapacityChange }) onFreeCapacityChange = onFreeCapacityChange })
@ -42,8 +45,10 @@ function init()
healthInfoWindow:disableResize() healthInfoWindow:disableResize()
healthBar = healthInfoWindow:recursiveGetChildById('healthBar') healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
manaBar = healthInfoWindow:recursiveGetChildById('manaBar') manaBar = healthInfoWindow:recursiveGetChildById('manaBar')
experienceBar = healthInfoWindow:recursiveGetChildById('experienceBar')
healthLabel = healthInfoWindow:recursiveGetChildById('healthLabel') healthLabel = healthInfoWindow:recursiveGetChildById('healthLabel')
manaLabel = healthInfoWindow:recursiveGetChildById('manaLabel') manaLabel = healthInfoWindow:recursiveGetChildById('manaLabel')
experienceLabel = healthInfoWindow:recursiveGetChildById('experienceLabel')
soulBar = healthInfoWindow:recursiveGetChildById('soulBar') soulBar = healthInfoWindow:recursiveGetChildById('soulBar')
soulLabel = healthInfoWindow:recursiveGetChildById('soulLabel') soulLabel = healthInfoWindow:recursiveGetChildById('soulLabel')
capLabel = healthInfoWindow:recursiveGetChildById('capLabel') capLabel = healthInfoWindow:recursiveGetChildById('capLabel')
@ -52,6 +57,7 @@ function init()
local localPlayer = g_game.getLocalPlayer() local localPlayer = g_game.getLocalPlayer()
onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth()) onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana()) onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
onLevelChange(localPlayer, localPlayer:getLevel(), localPlayer:getLevelPercent())
onStatesChange(localPlayer, localPlayer:getStates(), 0) onStatesChange(localPlayer, localPlayer:getStates(), 0)
onSoulChange(localPlayer, localPlayer:getSoul()) onSoulChange(localPlayer, localPlayer:getSoul())
onFreeCapacityChange(localPlayer, localPlayer:getFreeCapacity()) onFreeCapacityChange(localPlayer, localPlayer:getFreeCapacity())
@ -63,6 +69,7 @@ end
function terminate() function terminate()
disconnect(LocalPlayer, { onHealthChange = onHealthChange, disconnect(LocalPlayer, { onHealthChange = onHealthChange,
onManaChange = onManaChange, onManaChange = onManaChange,
onLevelChange = onLevelChange,
onStatesChange = onStatesChange, onStatesChange = onStatesChange,
onSoulChange = onSoulChange, onSoulChange = onSoulChange,
onFreeCapacityChange = onFreeCapacityChange }) onFreeCapacityChange = onFreeCapacityChange })
@ -90,6 +97,13 @@ function hideLabels()
healthInfoWindow:setHeight(math.max(healthInfoWindow.minimizedHeight, healthInfoWindow:getHeight() - removeHeight)) healthInfoWindow:setHeight(math.max(healthInfoWindow.minimizedHeight, healthInfoWindow:getHeight() - removeHeight))
end end
function hideExperience()
experienceBar:hide()
experienceLabel:hide()
local removeHeight = experienceBar:getHeight() + experienceBar:getMarginTop() + experienceBar:getMarginBottom()
healthInfoWindow:setHeight(math.max(healthInfoWindow.minimizedHeight, healthInfoWindow:getHeight() - removeHeight))
end
function onMiniWindowClose() function onMiniWindowClose()
healthInfoButton:setOn(false) healthInfoButton:setOn(false)
end end
@ -116,6 +130,11 @@ function onManaChange(localPlayer, mana, maxMana)
manaBar:setPercent(percent) manaBar:setPercent(percent)
end end
function onLevelChange(localPlayer, value, percent)
experienceLabel:setText(percent .. "%")
experienceBar:setPercent(percent)
end
function onSoulChange(localPlayer, soul) function onSoulChange(localPlayer, soul)
soulLabel:setText(tr('Soul') .. ': ' .. soul) soulLabel:setText(tr('Soul') .. ': ' .. soul)
end end
@ -151,5 +170,4 @@ function toggleIcon(bitChanged)
icon:setImageSource(Icons[bitChanged].path) icon:setImageSource(Icons[bitChanged].path)
icon:setTooltip(Icons[bitChanged].tooltip) icon:setTooltip(Icons[bitChanged].tooltip)
end end
end end

View File

@ -14,6 +14,15 @@ ManaBar < ProgressBar
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
margin-top: 4 margin-top: 4
ExperienceBar < ProgressBar
id: experienceBar
height: 15
background-color: yellow
anchors.top: prev.bottom
anchors.left: parent.left
anchors.right: parent.right
margin-top: 4
HealthLabel < GameLabel HealthLabel < GameLabel
id: healthLabel id: healthLabel
@ -32,6 +41,15 @@ ManaLabel < GameLabel
anchors.fill: manaBar anchors.fill: manaBar
margin-top: 2 margin-top: 2
text: 0 / 0 text: 0 / 0
ExperienceLabel < GameLabel
id: experienceLabel
color: white
text-align: center
font: verdana-11px-rounded
anchors.fill: experienceBar
margin-top: 2
text: 0 / 0
SoulLabel < GameLabel SoulLabel < GameLabel
id: soulLabel id: soulLabel
@ -66,7 +84,7 @@ MiniWindow
icon: /images/topbuttons/healthinfo icon: /images/topbuttons/healthinfo
id: healthInfoWindow id: healthInfoWindow
!text: tr('Health Info') !text: tr('Health Info')
height: 102 height: 117
@onClose: modules.game_healthinfo.onMiniWindowClose() @onClose: modules.game_healthinfo.onMiniWindowClose()
&save: true &save: true
@ -75,6 +93,8 @@ MiniWindow
HealthLabel HealthLabel
ManaBar ManaBar
ManaLabel ManaLabel
ExperienceBar
ExperienceLabel
Panel Panel
id: conditionPanel id: conditionPanel
layout: layout:
@ -89,4 +109,4 @@ MiniWindow
border-color: #00000077 border-color: #00000077
background-color: #ffffff11 background-color: #ffffff11
SoulLabel SoulLabel
CapLabel CapLabel