reorganize modules

This commit is contained in:
Eduardo Bart
2011-12-05 16:27:07 -02:00
parent ffeb34e0e7
commit cf0aab6d4d
90 changed files with 186 additions and 181 deletions

View File

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

View File

@@ -0,0 +1,10 @@
Module
name: game_healthbar
description: Displays health and mana points
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'healthbar'
return true

View File

@@ -0,0 +1,42 @@
HealthBar < UIProgressBar
color: black
height: 15
background-color: red
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
ManaBar < UIProgressBar
color: black
height: 15
background-color: blue
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
HealthLabel < Label
color: white
text-align: center
font: verdana-11px-rounded
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
margin-top: 2
ManaLabel < Label
color: white
text-align: center
font: verdana-11px-rounded
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin-bottom: -1
UIWindow
id: healthManaPanel
width: 192
margin-top: 10
margin-left: 6
margin-right: 6
move-policy: free updated