2012-07-24 07:30:08 +02:00
Icons = { }
2012-07-12 18:45:22 +02:00
Icons [ 1 ] = { tooltip = tr ( ' You are poisoned ' ) , path = ' /game_healthinfo/icons/poisoned.png ' , id = ' condition_poisoned ' }
Icons [ 2 ] = { tooltip = tr ( ' You are burning ' ) , path = ' /game_healthinfo/icons/burning.png ' , id = ' condition_burning ' }
Icons [ 4 ] = { tooltip = tr ( ' You are electrified ' ) , path = ' /game_healthinfo/icons/electrified.png ' , id = ' condition_electrified ' }
2012-07-26 08:10:28 +02:00
Icons [ 8 ] = { tooltip = tr ( ' You are drunk ' ) , path = ' /game_healthinfo/icons/drunk.png ' , id = ' condition_drunk ' }
2012-07-12 18:45:22 +02:00
Icons [ 16 ] = { tooltip = tr ( ' You are protected by a magic shield ' ) , path = ' /game_healthinfo/icons/magic_shield.png ' , id = ' condition_magic_shield ' }
Icons [ 32 ] = { tooltip = tr ( ' You are paralysed ' ) , path = ' /game_healthinfo/icons/slowed.png ' , id = ' condition_slowed ' }
Icons [ 64 ] = { tooltip = tr ( ' You are hasted ' ) , path = ' /game_healthinfo/icons/haste.png ' , id = ' condition_haste ' }
Icons [ 128 ] = { tooltip = tr ( ' You may not logout during a fight ' ) , path = ' /game_healthinfo/icons/logout_block.png ' , id = ' condition_logout_block ' }
Icons [ 256 ] = { tooltip = tr ( ' You are drowing ' ) , path = ' /game_healthinfo/icons/drowning.png ' , id = ' condition_drowning ' }
Icons [ 512 ] = { tooltip = tr ( ' You are freezing ' ) , path = ' /game_healthinfo/icons/freezing.png ' , id = ' condition_freezing ' }
Icons [ 1024 ] = { tooltip = tr ( ' You are dazzled ' ) , path = ' /game_healthinfo/icons/dazzled.png ' , id = ' condition_dazzled ' }
Icons [ 2048 ] = { tooltip = tr ( ' You are cursed ' ) , path = ' /game_healthinfo/icons/cursed.png ' , id = ' condition_cursed ' }
Icons [ 4096 ] = { tooltip = tr ( ' You are strengthened ' ) , path = ' /game_healthinfo/icons/strengthened.png ' , id = ' condition_strengthened ' }
Icons [ 8192 ] = { tooltip = tr ( ' You may not logout or enter a protection zone ' ) , path = ' /game_healthinfo/icons/protection_zone_block.png ' , id = ' condition_protection_zone_block ' }
Icons [ 16384 ] = { tooltip = tr ( ' You are within a protection zone ' ) , path = ' /game_healthinfo/icons/protection_zone.png ' , id = ' condition_protection_zone ' }
Icons [ 32768 ] = { tooltip = tr ( ' You are bleeding ' ) , path = ' /game_healthinfo/icons/bleeding.png ' , id = ' condition_bleeding ' }
Icons [ 65536 ] = { tooltip = tr ( ' You are hungry ' ) , path = ' /game_healthinfo/icons/hungry.png ' , id = ' condition_hungry ' }
2012-07-24 07:30:08 +02:00
healthInfoWindow = nil
healthBar = nil
manaBar = nil
soulBar = nil
healthLabel = nil
manaLabel = nil
soulLabel = nil
capLabel = nil
function init ( )
connect ( LocalPlayer , { onHealthChange = onHealthChange ,
onManaChange = onManaChange ,
onStatesChange = onStatesChange ,
onSoulChange = onSoulChange ,
onFreeCapacityChange = onFreeCapacityChange } )
connect ( g_game , { onGameEnd = offline } )
healthInfoButton = TopMenu.addRightGameToggleButton ( ' healthInfoButton ' , tr ( ' Health Information ' ) , ' healthinfo.png ' , toggle )
2012-07-12 18:45:22 +02:00
healthInfoButton : setOn ( true )
2012-08-21 07:35:08 +02:00
healthInfoWindow = g_ui.loadUI ( ' healthinfo.otui ' , modules.game_interface . getRightPanel ( ) )
healthInfoWindow : disableResize ( )
2012-07-12 18:45:22 +02:00
healthBar = healthInfoWindow : recursiveGetChildById ( ' healthBar ' )
manaBar = healthInfoWindow : recursiveGetChildById ( ' manaBar ' )
healthLabel = healthInfoWindow : recursiveGetChildById ( ' healthLabel ' )
manaLabel = healthInfoWindow : recursiveGetChildById ( ' manaLabel ' )
soulBar = healthInfoWindow : recursiveGetChildById ( ' soulBar ' )
soulLabel = healthInfoWindow : recursiveGetChildById ( ' soulLabel ' )
2012-07-13 01:40:55 +02:00
capLabel = healthInfoWindow : recursiveGetChildById ( ' capLabel ' )
2012-07-12 18:45:22 +02:00
if g_game.isOnline ( ) then
local localPlayer = g_game.getLocalPlayer ( )
2012-07-24 07:30:08 +02:00
onHealthChange ( localPlayer , localPlayer : getHealth ( ) , localPlayer : getMaxHealth ( ) )
onManaChange ( localPlayer , localPlayer : getMana ( ) , localPlayer : getMaxMana ( ) )
onStatesChange ( localPlayer , localPlayer : getStates ( ) , 0 )
onSoulChange ( localPlayer , localPlayer : getSoul ( ) )
onFreeCapacityChange ( localPlayer , localPlayer : getFreeCapacity ( ) )
2012-07-12 18:45:22 +02:00
end
end
2012-07-24 07:30:08 +02:00
function terminate ( )
disconnect ( LocalPlayer , { onHealthChange = onHealthChange ,
onManaChange = onManaChange ,
onStatesChange = onStatesChange ,
onSoulChange = onSoulChange ,
onFreeCapacityChange = onFreeCapacityChange } )
2012-07-12 18:45:22 +02:00
2012-07-24 07:30:08 +02:00
disconnect ( g_game , { onGameEnd = offline } )
2012-07-12 18:45:22 +02:00
healthInfoWindow : destroy ( )
healthInfoButton : destroy ( )
healthInfoWindow = nil
healthInfoButton = nil
2012-07-13 01:40:55 +02:00
2012-07-12 18:45:22 +02:00
healthBar = nil
manaBar = nil
soulBar = nil
2012-07-13 01:40:55 +02:00
2012-07-12 18:45:22 +02:00
healthLabel = nil
manaLabel = nil
soulLabel = nil
2012-07-13 01:40:55 +02:00
capLabel = nil
2012-07-12 18:45:22 +02:00
HealthInfo = nil
end
2012-07-24 07:30:08 +02:00
function toggle ( )
2012-07-12 18:45:22 +02:00
if healthInfoButton : isOn ( ) then
healthInfoWindow : close ( )
healthInfoButton : setOn ( false )
else
healthInfoWindow : open ( )
healthInfoButton : setOn ( true )
end
end
2012-08-20 23:58:43 +02:00
function hideLabels ( )
capLabel : hide ( )
soulLabel : hide ( )
local removeHeight = capLabel : getHeight ( ) + capLabel : getMarginTop ( ) + capLabel : getMarginBottom ( )
healthInfoWindow : setHeight ( healthInfoWindow : getHeight ( ) - removeHeight )
end
2012-07-24 07:30:08 +02:00
function onMiniWindowClose ( )
2012-07-12 18:45:22 +02:00
healthInfoButton : setOn ( false )
end
2012-07-24 07:30:08 +02:00
function offline ( )
2012-07-12 18:45:22 +02:00
healthInfoWindow : recursiveGetChildById ( ' conditionPanel ' ) : destroyChildren ( )
end
-- hooked events
2012-07-24 07:30:08 +02:00
function onHealthChange ( localPlayer , health , maxHealth )
2012-07-12 18:45:22 +02:00
healthLabel : setText ( health .. ' / ' .. maxHealth )
healthBar : setPercent ( health / maxHealth * 100 )
end
2012-07-24 07:30:08 +02:00
function onManaChange ( localPlayer , mana , maxMana )
2012-07-12 18:45:22 +02:00
manaLabel : setText ( mana .. ' / ' .. maxMana )
local percent
if maxMana == 0 then
percent = 100
else
percent = ( mana * 100 ) / maxMana
end
manaBar : setPercent ( percent )
end
2012-07-24 07:30:08 +02:00
function onSoulChange ( localPlayer , soul )
2012-07-13 01:40:55 +02:00
soulLabel : setText ( tr ( ' Soul ' ) .. ' : ' .. soul )
2012-07-12 18:45:22 +02:00
end
2012-07-24 07:30:08 +02:00
function onFreeCapacityChange ( player , freeCapacity )
2012-07-13 01:40:55 +02:00
capLabel : setText ( tr ( ' Cap ' ) .. ' : ' .. freeCapacity )
end
2012-07-24 07:30:08 +02:00
function onStatesChange ( localPlayer , now , old )
2012-07-12 18:45:22 +02:00
if now == old then return end
local bitsChanged = bit32.bxor ( now , old )
for i = 1 , 32 do
local pow = math.pow ( 2 , i - 1 )
if pow > bitsChanged then break end
local bitChanged = bit32.band ( bitsChanged , pow )
if bitChanged ~= 0 then
2012-07-24 07:30:08 +02:00
toggleIcon ( bitChanged )
2012-07-12 18:45:22 +02:00
end
end
end
2012-07-24 07:30:08 +02:00
function toggleIcon ( bitChanged )
2012-07-12 18:45:22 +02:00
local content = healthInfoWindow : recursiveGetChildById ( ' conditionPanel ' )
local icon = content : getChildById ( Icons [ bitChanged ] . id )
if icon then
icon : destroy ( )
else
icon = g_ui.createWidget ( ' ConditionWidget ' , content )
icon : setId ( Icons [ bitChanged ] . id )
icon : setImageSource ( Icons [ bitChanged ] . path )
icon : setTooltip ( Icons [ bitChanged ] . tooltip )
end
end