KLUIBuffInfoPanel.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---@class KLUIBuffInfoPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIBuffInfoPanelView
  3. local KLUIBuffInfoPanel = class(UIKmlLuaPanelBase)
  4. ---创建时调用一次
  5. function KLUIBuffInfoPanel:Init()
  6. end
  7. ---创建或者刷新界面数据时调用
  8. function KLUIBuffInfoPanel:Refresh()
  9. if self.timer then
  10. SL:UnSchedule(self.timer)
  11. self.timer = nil
  12. end
  13. ---@type cfg_buff_column
  14. local buffTbl = SL:GetConfig("cfg_buff",self.args.cfgId)
  15. local des = SL:GetMetaValue(EMetaVarGetKey.GET_BUFF_DESCRIDE,self.args.cfgId)
  16. if self.args.buffText then
  17. des = self.args.buffText
  18. end
  19. if buffTbl then
  20. if self.args.endTime > 0 then
  21. self.timer = SL:Schedule(self.timer,0,1,-1,function()
  22. local leftTime = self.args.endTime - Time.GetServerTime()
  23. if leftTime <= 0 then
  24. SL:UnSchedule(self.timer)
  25. self.timer = nil
  26. self:ClosePanel()
  27. else
  28. local time_str = "<color=#ff2323>"..self:GetTime(leftTime) .."</color>"
  29. local str = buffTbl.buffName .. "\n".. time_str .. "\n" ..des
  30. GUI:Text_setString(self.view.des,str)
  31. end
  32. end)
  33. else
  34. local str = buffTbl.buffName .. "\n" ..des
  35. --特权卡永久使用特殊处理
  36. if self.args.cfgId == 30000011 or self.args.cfgId == 30000012 or self.args.cfgId == 30000013 then
  37. str = buffTbl.buffName .. "\n".. "<color=#e6e600>已永久激活</color>" .. "\n" ..des
  38. end
  39. GUI:Text_setString(self.view.des,str)
  40. end
  41. end
  42. end
  43. function KLUIBuffInfoPanel:GetTime(_second)
  44. local second = math.floor(_second/1000)
  45. local day = math.floor(second / (3600 * 24))
  46. local hour = math.floor(second % (3600 * 24) / 3600)
  47. local minute = math.floor(second % 3600 / 60)
  48. local sec = math.floor(second % 60)
  49. local str = ""
  50. if day>0 then
  51. str = str ..day .. "天"
  52. end
  53. if hour>0 then
  54. str = str ..hour .. "小时"
  55. end
  56. if minute>0 then
  57. str = str ..minute .. "分"
  58. end
  59. str = str ..sec .. "秒"
  60. return str
  61. end
  62. ---注册UI事件和服务器消息
  63. function KLUIBuffInfoPanel:RegistEvents()
  64. GUI:AddOnClickEvent(self.view.maskBtn,self,self.ClosePanel)
  65. end
  66. function KLUIBuffInfoPanel:ClosePanel()
  67. GUI:UIPanel_Close(nil,self)
  68. if self.timer then
  69. SL:UnSchedule(self.timer)
  70. self.timer = nil
  71. end
  72. end
  73. function KLUIBuffInfoPanel:Close()
  74. if self.timer then
  75. SL:UnSchedule(self.timer)
  76. self.timer = nil
  77. end
  78. end
  79. return KLUIBuffInfoPanel