KLUIHurtExpPanel.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ---@class KLUIHurtExpPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIHurtExpPanelView
  3. local KLUIHurtExpPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUIHurtExpPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.end_time = SL:GetConfig("cfg_global",24001).value
  8. self.end_time = tonumber(self.end_time)
  9. self.last_time = Time.GetServerTime()
  10. self.updateID = SL:Schedule(self.updateID,0,5,-1,function()
  11. self:RefreshUI()
  12. end)
  13. self.update2ID = SL:Schedule(self.update2ID,0,1,-1,function()
  14. self:CheckSafe()
  15. end)
  16. end
  17. ---创建或者刷新界面数据时调用
  18. function this:Refresh()
  19. end
  20. function this:CheckSafe()
  21. local isSafe = SL:GetMetaValue(EMetaVarGetKey.IN_SAFE_AREA)
  22. if isSafe then
  23. GUI:UIPanel_Close("dev/ui/MainUI/Panel/KLUIHurtExp/KLUIHurtExpPanel")
  24. end
  25. end
  26. ---注册UI事件和服务器消息
  27. function this:RegistEvents()
  28. --SL:RegisterLUAEvent(LUA_EVENT_NET_PLAYER_DIE, self.PlayerDie, self) --玩家死亡
  29. end
  30. function this:RefreshTime()
  31. self.last_time = Time.GetServerTime()
  32. end
  33. function this:RefreshUI()
  34. local current_time = Time.GetServerTime()
  35. if self.last_time < current_time - 1000 * self.end_time -100 then
  36. GUI:UIPanel_Close("dev/ui/MainUI/Panel/KLUIHurtExp/KLUIHurtExpPanel")
  37. return
  38. end
  39. self:ShowHurt()
  40. self:ShowExp()
  41. end
  42. function this:ShowHurt()
  43. local hurt_num = InfoManager.mainUIInfo:GetHurtNum()
  44. local str = string.format("伤害 <color=#1add1f>%s</color>/秒",hurt_num)
  45. GUI:Text_setString(self.view.hurt,str)
  46. end
  47. function this:ShowExp()
  48. local exp_num = InfoManager.mainUIInfo:GetExpNum()
  49. exp_num = math.floor(exp_num)
  50. exp_num = SL:GetSimpleNumber(exp_num,0)
  51. local str = string.format("经验 <color=#1add1f>%s</color>/分",exp_num)
  52. GUI:Text_setString(self.view.exp,str)
  53. end
  54. function this:Close()
  55. if self.updateID then
  56. SL:UnSchedule(self.updateID)
  57. self.updateID = nil
  58. end
  59. if self.update2ID then
  60. SL:UnSchedule(self.update2ID)
  61. self.update2ID = nil
  62. end
  63. end
  64. return this