mirror of
https://github.com/edubart/otclient.git
synced 2025-10-17 13:03:27 +02:00
reorganize modules
This commit is contained in:
65
modules/game_healthbar/healthbar.lua
Normal file
65
modules/game_healthbar/healthbar.lua
Normal 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 })
|
10
modules/game_healthbar/healthbar.otmod
Normal file
10
modules/game_healthbar/healthbar.otmod
Normal 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
|
||||
|
||||
|
42
modules/game_healthbar/healthbar.otui
Normal file
42
modules/game_healthbar/healthbar.otui
Normal 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
|
||||
|
Reference in New Issue
Block a user