2012-07-24 07:30:08 +02:00
Icons = { }
2014-07-11 06:19:30 +02:00
Icons [ PlayerStates.Poison ] = { tooltip = tr ( ' You are poisoned ' ) , path = ' /images/game/states/poisoned ' , id = ' condition_poisoned ' }
Icons [ PlayerStates.Burn ] = { tooltip = tr ( ' You are burning ' ) , path = ' /images/game/states/burning ' , id = ' condition_burning ' }
Icons [ PlayerStates.Energy ] = { tooltip = tr ( ' You are electrified ' ) , path = ' /images/game/states/electrified ' , id = ' condition_electrified ' }
Icons [ PlayerStates.Drunk ] = { tooltip = tr ( ' You are drunk ' ) , path = ' /images/game/states/drunk ' , id = ' condition_drunk ' }
Icons [ PlayerStates.ManaShield ] = { tooltip = tr ( ' You are protected by a magic shield ' ) , path = ' /images/game/states/magic_shield ' , id = ' condition_magic_shield ' }
Icons [ PlayerStates.Paralyze ] = { tooltip = tr ( ' You are paralysed ' ) , path = ' /images/game/states/slowed ' , id = ' condition_slowed ' }
Icons [ PlayerStates.Haste ] = { tooltip = tr ( ' You are hasted ' ) , path = ' /images/game/states/haste ' , id = ' condition_haste ' }
Icons [ PlayerStates.Swords ] = { tooltip = tr ( ' You may not logout during a fight ' ) , path = ' /images/game/states/logout_block ' , id = ' condition_logout_block ' }
Icons [ PlayerStates.Drowning ] = { tooltip = tr ( ' You are drowning ' ) , path = ' /images/game/states/drowning ' , id = ' condition_drowning ' }
Icons [ PlayerStates.Freezing ] = { tooltip = tr ( ' You are freezing ' ) , path = ' /images/game/states/freezing ' , id = ' condition_freezing ' }
Icons [ PlayerStates.Dazzled ] = { tooltip = tr ( ' You are dazzled ' ) , path = ' /images/game/states/dazzled ' , id = ' condition_dazzled ' }
Icons [ PlayerStates.Cursed ] = { tooltip = tr ( ' You are cursed ' ) , path = ' /images/game/states/cursed ' , id = ' condition_cursed ' }
Icons [ PlayerStates.PartyBuff ] = { tooltip = tr ( ' You are strengthened ' ) , path = ' /images/game/states/strengthened ' , id = ' condition_strengthened ' }
Icons [ PlayerStates.PzBlock ] = { tooltip = tr ( ' You may not logout or enter a protection zone ' ) , path = ' /images/game/states/protection_zone_block ' , id = ' condition_protection_zone_block ' }
Icons [ PlayerStates.Pz ] = { tooltip = tr ( ' You are within a protection zone ' ) , path = ' /images/game/states/protection_zone ' , id = ' condition_protection_zone ' }
Icons [ PlayerStates.Bleeding ] = { tooltip = tr ( ' You are bleeding ' ) , path = ' /images/game/states/bleeding ' , id = ' condition_bleeding ' }
Icons [ PlayerStates.Hungry ] = { tooltip = tr ( ' You are hungry ' ) , path = ' /images/game/states/hungry ' , id = ' condition_hungry ' }
2012-07-12 18:45:22 +02:00
2012-07-24 07:30:08 +02:00
healthInfoWindow = nil
healthBar = nil
manaBar = nil
2013-02-10 06:31:12 +01:00
experienceBar = nil
2012-07-24 07:30:08 +02:00
soulLabel = nil
capLabel = nil
2013-02-10 04:17:20 +01:00
healthTooltip = ' Your character health is %d out of %d. '
manaTooltip = ' Your character mana is %d out of %d. '
experienceTooltip = ' You have %d%% to advance to level %d. '
2012-07-24 07:30:08 +02:00
function init ( )
connect ( LocalPlayer , { onHealthChange = onHealthChange ,
onManaChange = onManaChange ,
2013-02-10 06:31:12 +01:00
onLevelChange = onLevelChange ,
2012-07-24 07:30:08 +02:00
onStatesChange = onStatesChange ,
onSoulChange = onSoulChange ,
onFreeCapacityChange = onFreeCapacityChange } )
connect ( g_game , { onGameEnd = offline } )
2013-01-18 23:39:11 +01:00
healthInfoButton = modules.client_topmenu . addRightGameToggleButton ( ' healthInfoButton ' , tr ( ' Health Information ' ) , ' /images/topbuttons/healthinfo ' , toggle )
2012-07-12 18:45:22 +02:00
healthInfoButton : setOn ( true )
2012-08-21 07:35:08 +02:00
2013-01-18 23:39:11 +01:00
healthInfoWindow = g_ui.loadUI ( ' healthinfo ' , modules.game_interface . getRightPanel ( ) )
2012-08-21 07:35:08 +02:00
healthInfoWindow : disableResize ( )
2012-07-12 18:45:22 +02:00
healthBar = healthInfoWindow : recursiveGetChildById ( ' healthBar ' )
manaBar = healthInfoWindow : recursiveGetChildById ( ' manaBar ' )
2013-02-10 06:31:12 +01:00
experienceBar = healthInfoWindow : recursiveGetChildById ( ' experienceBar ' )
2012-07-12 18:45:22 +02:00
soulLabel = healthInfoWindow : recursiveGetChildById ( ' soulLabel ' )
2012-07-13 01:40:55 +02:00
capLabel = healthInfoWindow : recursiveGetChildById ( ' capLabel ' )
2012-07-12 18:45:22 +02:00
2013-02-23 06:53:27 +01:00
-- load condition icons
for k , v in pairs ( Icons ) do
2013-02-23 07:16:42 +01:00
g_textures.preload ( v.path )
2013-02-23 06:53:27 +01:00
end
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 ( ) )
2013-02-10 06:31:12 +01:00
onLevelChange ( localPlayer , localPlayer : getLevel ( ) , localPlayer : getLevelPercent ( ) )
2012-07-24 07:30:08 +02:00
onStatesChange ( localPlayer , localPlayer : getStates ( ) , 0 )
onSoulChange ( localPlayer , localPlayer : getSoul ( ) )
onFreeCapacityChange ( localPlayer , localPlayer : getFreeCapacity ( ) )
2012-07-12 18:45:22 +02:00
end
2012-08-21 23:40:47 +02:00
healthInfoWindow : setup ( )
2012-07-12 18:45:22 +02:00
end
2012-07-24 07:30:08 +02:00
function terminate ( )
disconnect ( LocalPlayer , { onHealthChange = onHealthChange ,
onManaChange = onManaChange ,
2013-02-10 06:31:12 +01:00
onLevelChange = onLevelChange ,
2012-07-24 07:30:08 +02:00
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 ( )
2013-02-01 05:32:15 +01:00
healthInfoButton : destroy ( )
2012-07-12 18:45:22 +02:00
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
2013-02-09 22:57:37 +01:00
function toggleIcon ( bitChanged )
local content = healthInfoWindow : recursiveGetChildById ( ' conditionPanel ' )
local icon = content : getChildById ( Icons [ bitChanged ] . id )
if icon then
icon : destroy ( )
else
2013-02-23 06:53:27 +01:00
icon = loadIcon ( bitChanged )
icon : setParent ( content )
2013-02-09 22:57:37 +01:00
end
end
2013-02-23 06:53:27 +01:00
function loadIcon ( bitChanged )
local icon = g_ui.createWidget ( ' ConditionWidget ' , content )
icon : setId ( Icons [ bitChanged ] . id )
icon : setImageSource ( Icons [ bitChanged ] . path )
icon : setTooltip ( Icons [ bitChanged ] . tooltip )
return icon
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
2013-02-09 22:57:37 +01:00
function onMiniWindowClose ( )
healthInfoButton : setOn ( false )
end
2012-07-24 07:30:08 +02:00
function onHealthChange ( localPlayer , health , maxHealth )
2013-02-09 22:57:37 +01:00
healthBar : setText ( health .. ' / ' .. maxHealth )
2013-02-10 04:17:20 +01:00
healthBar : setTooltip ( tr ( healthTooltip , health , maxHealth ) )
2013-02-09 22:57:37 +01:00
healthBar : setValue ( health , 0 , maxHealth )
2012-07-12 18:45:22 +02:00
end
2012-07-24 07:30:08 +02:00
function onManaChange ( localPlayer , mana , maxMana )
2013-02-09 22:57:37 +01:00
manaBar : setText ( mana .. ' / ' .. maxMana )
2013-02-10 04:17:20 +01:00
manaBar : setTooltip ( tr ( manaTooltip , mana , maxMana ) )
2013-02-09 22:57:37 +01:00
manaBar : setValue ( mana , 0 , maxMana )
2012-07-12 18:45:22 +02:00
end
2013-02-10 06:31:12 +01:00
function onLevelChange ( localPlayer , value , percent )
2013-02-10 04:17:20 +01:00
experienceBar : setText ( percent .. ' % ' )
experienceBar : setTooltip ( tr ( experienceTooltip , percent , value + 1 ) )
2013-02-10 06:31:12 +01:00
experienceBar : 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
2013-02-10 04:17:20 +01:00
-- personalization functions
function hideLabels ( )
local removeHeight = math.max ( capLabel : getMarginRect ( ) . height , soulLabel : getMarginRect ( ) . height )
capLabel : setOn ( false )
soulLabel : setOn ( false )
healthInfoWindow : setHeight ( math.max ( healthInfoWindow.minimizedHeight , healthInfoWindow : getHeight ( ) - removeHeight ) )
end
function hideExperience ( )
local removeHeight = experienceBar : getMarginRect ( ) . height
experienceBar : setOn ( false )
healthInfoWindow : setHeight ( math.max ( healthInfoWindow.minimizedHeight , healthInfoWindow : getHeight ( ) - removeHeight ) )
end
function setHealthTooltip ( tooltip )
healthTooltip = tooltip
2013-02-21 01:50:45 +01:00
local localPlayer = g_game.getLocalPlayer ( )
if localPlayer then
healthBar : setTooltip ( tr ( healthTooltip , localPlayer : getHealth ( ) , localPlayer : getMaxHealth ( ) ) )
end
2013-02-10 04:17:20 +01:00
end
function setManaTooltip ( tooltip )
manaTooltip = tooltip
2013-02-21 01:50:45 +01:00
local localPlayer = g_game.getLocalPlayer ( )
if localPlayer then
manaBar : setTooltip ( tr ( manaTooltip , localPlayer : getMana ( ) , localPlayer : getMaxMana ( ) ) )
end
2013-02-10 04:17:20 +01:00
end
function setExperienceTooltip ( tooltip )
experienceTooltip = tooltip
2013-02-21 01:50:45 +01:00
local localPlayer = g_game.getLocalPlayer ( )
if localPlayer then
experienceBar : setTooltip ( tr ( experienceTooltip , localPlayer : getLevelPercent ( ) , localPlayer : getLevel ( ) + 1 ) )
end
2013-02-10 04:17:20 +01:00
end