KLWolfSoulFortressSummonPanel.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ---@class KLWolfSoulFortressSummonPanel:UIKmlLuaPanelBase
  2. ---@field view KLWolfSoulFortressSummonPanelView
  3. ---@field all_item KLWolfSoulFortressSummonItem[]
  4. ---@field nextStateTime number
  5. local KLWolfSoulFortressSummonPanel = class(UIKmlLuaPanelBase)
  6. local this = KLWolfSoulFortressSummonPanel
  7. function this:AsyncLoadUI()
  8. end
  9. ---创建时调用一次
  10. function this:Init()
  11. SL:ReqViewUnionMessage()
  12. self.all_item = {}
  13. GUI:DataListInitData(self.view.summonDataList, function()
  14. return self:BtnDataListItemCountFunc()
  15. end, function(realIndex)
  16. return self:BtnDataListItemGetFunc(realIndex)
  17. end, function(realIndex, kmlcontrol)
  18. return self:BtnDataListItemInitFunc(realIndex, kmlcontrol)
  19. end, function(realIndex, kmlcontrol)
  20. return self:BtnDataListItemUpdateFunc(realIndex, kmlcontrol)
  21. end)
  22. end
  23. ---注册UI事件和服务器消息waa
  24. function this:RegistEvents()
  25. GUI:AddOnClickEvent(self.view.btnClose, self, self.CloseOnclick)
  26. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_WOLF_SOUL_PREPARE_PANEL, self.RES_WOLF_SOUL_PREPARE_PANEL, self)
  27. SL:RegisterLuaNetMsg(MessageDef.ResBagChangeMessage, this.ResBagChangeMessage, self)
  28. end
  29. ---背包变化
  30. ---@param message BagProtos.BagChangeRes
  31. function this:ResBagChangeMessage(_, message)
  32. if #message.coinList > 0 then
  33. for k, v in pairs(message.coinList) do
  34. if v.itemId == self.summonNeedItemId then
  35. GUI:Text_setString(self.view.textGuildMoney, tostring(v.count))
  36. break
  37. end
  38. end
  39. end
  40. end
  41. ---@param message {"1":召唤数量}
  42. function this:RES_WOLF_SOUL_PREPARE_PANEL(_, message)
  43. InfoManager.wolfSoulFortressInfo.summonCount = message["1"]
  44. self.guardians = InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.guardians
  45. GUI:Text_setString(self.view.textSummonCount, string.format("%s/%s", InfoManager.wolfSoulFortressInfo.summonCount, self.guardians))
  46. end
  47. function this:CloseOnclick()
  48. GUI:UIPanel_Close("dev/outui/Activity/Panel/KLWolfSoulFortressSummon/KLWolfSoulFortressSummonPanel")
  49. end
  50. ---界面显示时调用一次
  51. function this:Show()
  52. end
  53. ---创建或者刷新界面数据时调用
  54. function this:Refresh()
  55. InfoManager.wolfSoulFortressInfo:GetCfgByOpenServerDay()
  56. SL.HideMainPanel()
  57. GUI:DataListUpdateData(self.view.summonDataList)
  58. if InfoManager.wolfSoulFortressInfo.state == 1 then
  59. self.nextStateTime = InfoManager.wolfSoulFortressInfo.nextStateTime
  60. self:RefreshTimeText()
  61. if not self.timer then
  62. self.timer = SL:StartLoopForever(1, self.RefreshTimeText, self) ---Timer.StartLoopForever(1, self.RefreshTimeText, self)
  63. end
  64. else
  65. GUI:Text_setString(self.view.textTime, SL.Time.FormatTimeHMS(math.floor(0))) --Time.FormatTimeHMS(math.floor(0)))
  66. end
  67. ---多个消耗道具都一样用第一个就行
  68. self.summonNeedItemId = InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.guardiansType[1][2]
  69. self.guardians = InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.guardians
  70. GUI:Text_setString(self.view.textGuildMoney, tostring(SL:GetBagItemCount(self.summonNeedItemId)))
  71. GUI:Text_setString(self.view.textSummonCount, string.format("%s/%s", InfoManager.wolfSoulFortressInfo.summonCount, self.guardians))
  72. end
  73. function this:RefreshTimeText()
  74. if not self.nextStateTime then
  75. return
  76. end
  77. local nextTime = self.nextStateTime - SL.Time:GetServerTime()---Time.GetServerTime()
  78. if nextTime < 0 then
  79. if self.timer then
  80. ---Timer.Stop(self.timer)
  81. SL:UnSchedule(self.timer)
  82. self.timer = nil
  83. end
  84. GUI:UIPanel_Close("dev/outui/Activity/Panel/KLWolfSoulFortressSummon/KLWolfSoulFortressSummonPanel")
  85. end
  86. GUI:Text_setString(self.view.textTime, SL.Time:FormatTimeHMS(math.floor(nextTime))) ---Time.FormatTimeHMS(math.floor(nextTime)))
  87. end
  88. function this:BtnDataListItemCountFunc()
  89. local count = #InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.guardiansType
  90. if not count then
  91. count = 0
  92. end
  93. return count
  94. end
  95. function this:BtnDataListItemGetFunc(realIndex)
  96. local item = GUI:UIPanel_Open("dev/outui/Activity/Item/KLWolfSoulFortressSummon/KLWolfSoulFortressSummonItem", self.view.summonDataList, self, nil, true)
  97. self.all_item[item.view.root] = item
  98. return item.view.root
  99. end
  100. function this:BtnDataListItemInitFunc(realIndex, kmlcontrol)
  101. end
  102. function this:BtnDataListItemUpdateFunc(realIndex, kmlcontrol)
  103. local tempData = {
  104. index = realIndex + 1,
  105. data = InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.guardiansType[realIndex + 1]
  106. }
  107. self.all_item[kmlcontrol]:RefreshItem(tempData)
  108. end
  109. function this:Close()
  110. SL.ShowMainPanel()
  111. if self.timer then
  112. ---Timer.Stop(self.timer)
  113. SL:UnSchedule(self.timer)
  114. self.timer = nil
  115. end
  116. end
  117. return this