No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

healthinfo.lua 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. Icons = {}
  2. Icons[PlayerStates.Poison] = { tooltip = tr('You are poisoned'), path = '/images/game/states/poisoned', id = 'condition_poisoned' }
  3. Icons[PlayerStates.Burn] = { tooltip = tr('You are burning'), path = '/images/game/states/burning', id = 'condition_burning' }
  4. Icons[PlayerStates.Energy] = { tooltip = tr('You are electrified'), path = '/images/game/states/electrified', id = 'condition_electrified' }
  5. Icons[PlayerStates.Drunk] = { tooltip = tr('You are drunk'), path = '/images/game/states/drunk', id = 'condition_drunk' }
  6. Icons[PlayerStates.ManaShield] = { tooltip = tr('You are protected by a magic shield'), path = '/images/game/states/magic_shield', id = 'condition_magic_shield' }
  7. Icons[PlayerStates.Paralyze] = { tooltip = tr('You are paralysed'), path = '/images/game/states/slowed', id = 'condition_slowed' }
  8. Icons[PlayerStates.Haste] = { tooltip = tr('You are hasted'), path = '/images/game/states/haste', id = 'condition_haste' }
  9. Icons[PlayerStates.Swords] = { tooltip = tr('You may not logout during a fight'), path = '/images/game/states/logout_block', id = 'condition_logout_block' }
  10. Icons[PlayerStates.Drowning] = { tooltip = tr('You are drowning'), path = '/images/game/states/drowning', id = 'condition_drowning' }
  11. Icons[PlayerStates.Freezing] = { tooltip = tr('You are freezing'), path = '/images/game/states/freezing', id = 'condition_freezing' }
  12. Icons[PlayerStates.Dazzled] = { tooltip = tr('You are dazzled'), path = '/images/game/states/dazzled', id = 'condition_dazzled' }
  13. Icons[PlayerStates.Cursed] = { tooltip = tr('You are cursed'), path = '/images/game/states/cursed', id = 'condition_cursed' }
  14. Icons[PlayerStates.PartyBuff] = { tooltip = tr('You are strengthened'), path = '/images/game/states/strengthened', id = 'condition_strengthened' }
  15. 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' }
  16. Icons[PlayerStates.Pz] = { tooltip = tr('You are within a protection zone'), path = '/images/game/states/protection_zone', id = 'condition_protection_zone' }
  17. Icons[PlayerStates.Bleeding] = { tooltip = tr('You are bleeding'), path = '/images/game/states/bleeding', id = 'condition_bleeding' }
  18. Icons[PlayerStates.Hungry] = { tooltip = tr('You are hungry'), path = '/images/game/states/hungry', id = 'condition_hungry' }
  19. healthInfoWindow = nil
  20. healthBar = nil
  21. manaBar = nil
  22. experienceBar = nil
  23. soulLabel = nil
  24. capLabel = nil
  25. healthTooltip = 'Your character health is %d out of %d.'
  26. manaTooltip = 'Your character mana is %d out of %d.'
  27. experienceTooltip = 'You have %d%% to advance to level %d.'
  28. function init()
  29. connect(LocalPlayer, { onHealthChange = onHealthChange,
  30. onManaChange = onManaChange,
  31. onLevelChange = onLevelChange,
  32. onStatesChange = onStatesChange,
  33. onSoulChange = onSoulChange,
  34. onFreeCapacityChange = onFreeCapacityChange })
  35. connect(g_game, { onGameEnd = offline })
  36. healthInfoButton = modules.client_topmenu.addRightGameToggleButton('healthInfoButton', tr('Health Information'), '/images/topbuttons/healthinfo', toggle)
  37. healthInfoButton:setOn(true)
  38. healthInfoWindow = g_ui.loadUI('healthinfo', modules.game_interface.getRightPanel())
  39. healthInfoWindow:disableResize()
  40. healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
  41. manaBar = healthInfoWindow:recursiveGetChildById('manaBar')
  42. experienceBar = healthInfoWindow:recursiveGetChildById('experienceBar')
  43. soulLabel = healthInfoWindow:recursiveGetChildById('soulLabel')
  44. capLabel = healthInfoWindow:recursiveGetChildById('capLabel')
  45. -- load condition icons
  46. for k,v in pairs(Icons) do
  47. g_textures.preload(v.path)
  48. end
  49. if g_game.isOnline() then
  50. local localPlayer = g_game.getLocalPlayer()
  51. onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
  52. onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
  53. onLevelChange(localPlayer, localPlayer:getLevel(), localPlayer:getLevelPercent())
  54. onStatesChange(localPlayer, localPlayer:getStates(), 0)
  55. onSoulChange(localPlayer, localPlayer:getSoul())
  56. onFreeCapacityChange(localPlayer, localPlayer:getFreeCapacity())
  57. end
  58. healthInfoWindow:setup()
  59. end
  60. function terminate()
  61. disconnect(LocalPlayer, { onHealthChange = onHealthChange,
  62. onManaChange = onManaChange,
  63. onLevelChange = onLevelChange,
  64. onStatesChange = onStatesChange,
  65. onSoulChange = onSoulChange,
  66. onFreeCapacityChange = onFreeCapacityChange })
  67. disconnect(g_game, { onGameEnd = offline })
  68. healthInfoWindow:destroy()
  69. healthInfoButton:destroy()
  70. end
  71. function toggle()
  72. if healthInfoButton:isOn() then
  73. healthInfoWindow:close()
  74. healthInfoButton:setOn(false)
  75. else
  76. healthInfoWindow:open()
  77. healthInfoButton:setOn(true)
  78. end
  79. end
  80. function toggleIcon(bitChanged)
  81. local content = healthInfoWindow:recursiveGetChildById('conditionPanel')
  82. local icon = content:getChildById(Icons[bitChanged].id)
  83. if icon then
  84. icon:destroy()
  85. else
  86. icon = loadIcon(bitChanged)
  87. icon:setParent(content)
  88. end
  89. end
  90. function loadIcon(bitChanged)
  91. local icon = g_ui.createWidget('ConditionWidget', content)
  92. icon:setId(Icons[bitChanged].id)
  93. icon:setImageSource(Icons[bitChanged].path)
  94. icon:setTooltip(Icons[bitChanged].tooltip)
  95. return icon
  96. end
  97. function offline()
  98. healthInfoWindow:recursiveGetChildById('conditionPanel'):destroyChildren()
  99. end
  100. -- hooked events
  101. function onMiniWindowClose()
  102. healthInfoButton:setOn(false)
  103. end
  104. function onHealthChange(localPlayer, health, maxHealth)
  105. healthBar:setText(health .. ' / ' .. maxHealth)
  106. healthBar:setTooltip(tr(healthTooltip, health, maxHealth))
  107. healthBar:setValue(health, 0, maxHealth)
  108. end
  109. function onManaChange(localPlayer, mana, maxMana)
  110. manaBar:setText(mana .. ' / ' .. maxMana)
  111. manaBar:setTooltip(tr(manaTooltip, mana, maxMana))
  112. manaBar:setValue(mana, 0, maxMana)
  113. end
  114. function onLevelChange(localPlayer, value, percent)
  115. experienceBar:setText(percent .. '%')
  116. experienceBar:setTooltip(tr(experienceTooltip, percent, value+1))
  117. experienceBar:setPercent(percent)
  118. end
  119. function onSoulChange(localPlayer, soul)
  120. soulLabel:setText(tr('Soul') .. ': ' .. soul)
  121. end
  122. function onFreeCapacityChange(player, freeCapacity)
  123. capLabel:setText(tr('Cap') .. ': ' .. freeCapacity)
  124. end
  125. function onStatesChange(localPlayer, now, old)
  126. if now == old then return end
  127. local bitsChanged = bit32.bxor(now, old)
  128. for i = 1, 32 do
  129. local pow = math.pow(2, i-1)
  130. if pow > bitsChanged then break end
  131. local bitChanged = bit32.band(bitsChanged, pow)
  132. if bitChanged ~= 0 then
  133. toggleIcon(bitChanged)
  134. end
  135. end
  136. end
  137. -- personalization functions
  138. function hideLabels()
  139. local removeHeight = math.max(capLabel:getMarginRect().height, soulLabel:getMarginRect().height)
  140. capLabel:setOn(false)
  141. soulLabel:setOn(false)
  142. healthInfoWindow:setHeight(math.max(healthInfoWindow.minimizedHeight, healthInfoWindow:getHeight() - removeHeight))
  143. end
  144. function hideExperience()
  145. local removeHeight = experienceBar:getMarginRect().height
  146. experienceBar:setOn(false)
  147. healthInfoWindow:setHeight(math.max(healthInfoWindow.minimizedHeight, healthInfoWindow:getHeight() - removeHeight))
  148. end
  149. function setHealthTooltip(tooltip)
  150. healthTooltip = tooltip
  151. local localPlayer = g_game.getLocalPlayer()
  152. if localPlayer then
  153. healthBar:setTooltip(tr(healthTooltip, localPlayer:getHealth(), localPlayer:getMaxHealth()))
  154. end
  155. end
  156. function setManaTooltip(tooltip)
  157. manaTooltip = tooltip
  158. local localPlayer = g_game.getLocalPlayer()
  159. if localPlayer then
  160. manaBar:setTooltip(tr(manaTooltip, localPlayer:getMana(), localPlayer:getMaxMana()))
  161. end
  162. end
  163. function setExperienceTooltip(tooltip)
  164. experienceTooltip = tooltip
  165. local localPlayer = g_game.getLocalPlayer()
  166. if localPlayer then
  167. experienceBar:setTooltip(tr(experienceTooltip, localPlayer:getLevelPercent(), localPlayer:getLevel()+1))
  168. end
  169. end