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.

unjustifiedpoints.lua 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. unjustifiedPointsWindow = nil
  2. unjustifiedPointsButton = nil
  3. contentsPanel = nil
  4. openPvpSituationsLabel = nil
  5. currentSkullWidget = nil
  6. skullTimeLabel = nil
  7. dayProgressBar = nil
  8. weekProgressBar = nil
  9. monthProgressBar = nil
  10. daySkullWidget = nil
  11. weekSkullWidget = nil
  12. monthSkullWidget = nil
  13. function init()
  14. connect(g_game, { onGameStart = online,
  15. onUnjustifiedPointsChange = onUnjustifiedPointsChange,
  16. onOpenPvpSituationsChange = onOpenPvpSituationsChange })
  17. connect(LocalPlayer, { onSkullChange = onSkullChange } )
  18. unjustifiedPointsButton = modules.client_topmenu.addRightGameToggleButton('unjustifiedPointsButton',
  19. tr('Unjustified Points'), '/images/topbuttons/unjustifiedpoints', toggle)
  20. unjustifiedPointsButton:setOn(true)
  21. unjustifiedPointsButton:hide()
  22. unjustifiedPointsWindow = g_ui.loadUI('unjustifiedpoints', modules.game_interface.getRightPanel())
  23. unjustifiedPointsWindow:disableResize()
  24. unjustifiedPointsWindow:setup()
  25. contentsPanel = unjustifiedPointsWindow:getChildById('contentsPanel')
  26. openPvpSituationsLabel = contentsPanel:getChildById('openPvpSituationsLabel')
  27. currentSkullWidget = contentsPanel:getChildById('currentSkullWidget')
  28. skullTimeLabel = contentsPanel:getChildById('skullTimeLabel')
  29. dayProgressBar = contentsPanel:getChildById('dayProgressBar')
  30. weekProgressBar = contentsPanel:getChildById('weekProgressBar')
  31. monthProgressBar = contentsPanel:getChildById('monthProgressBar')
  32. daySkullWidget = contentsPanel:getChildById('daySkullWidget')
  33. weekSkullWidget = contentsPanel:getChildById('weekSkullWidget')
  34. monthSkullWidget = contentsPanel:getChildById('monthSkullWidget')
  35. if g_game.isOnline() then
  36. online()
  37. end
  38. end
  39. function terminate()
  40. disconnect(g_game, { onGameStart = online,
  41. onUnjustifiedPointsChange = onUnjustifiedPointsChange,
  42. onOpenPvpSituationsChange = onOpenPvpSituationsChange })
  43. disconnect(LocalPlayer, { onSkullChange = onSkullChange } )
  44. unjustifiedPointsWindow:destroy()
  45. unjustifiedPointsButton:destroy()
  46. end
  47. function onMiniWindowClose()
  48. unjustifiedPointsButton:setOn(false)
  49. end
  50. function toggle()
  51. if unjustifiedPointsButton:isOn() then
  52. unjustifiedPointsWindow:close()
  53. unjustifiedPointsButton:setOn(false)
  54. else
  55. unjustifiedPointsWindow:open()
  56. unjustifiedPointsButton:setOn(true)
  57. end
  58. end
  59. function online()
  60. if g_game.getFeature(GameUnjustifiedPoints) then
  61. unjustifiedPointsButton:show()
  62. else
  63. unjustifiedPointsButton:hide()
  64. unjustifiedPointsWindow:close()
  65. end
  66. refresh()
  67. end
  68. function refresh()
  69. local localPlayer = g_game.getLocalPlayer()
  70. local unjustifiedPoints = g_game.getUnjustifiedPoints()
  71. onUnjustifiedPointsChange(unjustifiedPoints)
  72. onSkullChange(localPlayer, localPlayer:getSkull())
  73. onOpenPvpSituationsChange(g_game.getOpenPvpSituations())
  74. end
  75. function onSkullChange(localPlayer, skull)
  76. if not localPlayer:isLocalPlayer() then return end
  77. if skull == SkullRed or skull == SkullBlack then
  78. currentSkullWidget:setIcon(getSkullImagePath(skull))
  79. currentSkullWidget:setTooltip('Remaining skull time')
  80. else
  81. currentSkullWidget:setIcon('')
  82. currentSkullWidget:setTooltip('You have no skull')
  83. end
  84. daySkullWidget:setIcon(getSkullImagePath(getNextSkullId(skull)))
  85. weekSkullWidget:setIcon(getSkullImagePath(getNextSkullId(skull)))
  86. monthSkullWidget:setIcon(getSkullImagePath(getNextSkullId(skull)))
  87. end
  88. function onOpenPvpSituationsChange(amount)
  89. openPvpSituationsLabel:setText(amount)
  90. end
  91. local function getColorByKills(kills)
  92. if kills < 2 then
  93. return 'red'
  94. elseif kills < 3 then
  95. return 'yellow'
  96. end
  97. return 'green'
  98. end
  99. function onUnjustifiedPointsChange(unjustifiedPoints)
  100. if unjustifiedPoints.skullTime == 0 then
  101. skullTimeLabel:setText('No skull')
  102. skullTimeLabel:setTooltip('You have no skull')
  103. else
  104. skullTimeLabel:setText(unjustifiedPoints.skullTime .. ' days')
  105. skullTimeLabel:setTooltip('Remaining skull time')
  106. end
  107. dayProgressBar:setValue(unjustifiedPoints.killsDay, 0, 100)
  108. dayProgressBar:setBackgroundColor(getColorByKills(unjustifiedPoints.killsDayRemaining))
  109. dayProgressBar:setTooltip(string.format('Unjustified points gained during the last 24 hours.\n%i kill%s left.', unjustifiedPoints.killsDayRemaining, (unjustifiedPoints.killsDayRemaining == 1 and '' or 's')))
  110. dayProgressBar:setText(string.format('%i kill%s left', unjustifiedPoints.killsDayRemaining, (unjustifiedPoints.killsDayRemaining == 1 and '' or 's')))
  111. weekProgressBar:setValue(unjustifiedPoints.killsWeek, 0, 100)
  112. weekProgressBar:setBackgroundColor(getColorByKills(unjustifiedPoints.killsWeekRemaining))
  113. weekProgressBar:setTooltip(string.format('Unjustified points gained during the last 7 days.\n%i kill%s left.', unjustifiedPoints.killsWeekRemaining, (unjustifiedPoints.killsWeekRemaining == 1 and '' or 's')))
  114. weekProgressBar:setText(string.format('%i kill%s left', unjustifiedPoints.killsWeekRemaining, (unjustifiedPoints.killsWeekRemaining == 1 and '' or 's')))
  115. monthProgressBar:setValue(unjustifiedPoints.killsMonth, 0, 100)
  116. monthProgressBar:setBackgroundColor(getColorByKills(unjustifiedPoints.killsMonthRemaining))
  117. monthProgressBar:setTooltip(string.format('Unjustified points gained during the last 30 days.\n%i kill%s left.', unjustifiedPoints.killsMonthRemaining, (unjustifiedPoints.killsMonthRemaining == 1 and '' or 's')))
  118. monthProgressBar:setText(string.format('%i kill%s left', unjustifiedPoints.killsMonthRemaining, (unjustifiedPoints.killsMonthRemaining == 1 and '' or 's')))
  119. end