CompetitionExchange.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. local CompetitionExchange = class("CompetitionExchange")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. local itemIdx = 0
  4. local scores
  5. function CompetitionExchange:ctor()
  6. self.root = nil
  7. end
  8. function CompetitionExchange:Init(root)
  9. self.root = root
  10. local content = GlobalConfig.Instance:GetConfigStrValue(219)
  11. if content ~= "" and content ~= nil then
  12. scores = CommonUtil.DeserializeGlobalStrToTable(content)
  13. end
  14. self:AddEventListener()
  15. self:Refresh()
  16. end
  17. function CompetitionExchange:AddEventListener()
  18. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.root.uiData.name, UIEventNames.SEASON_EXCHANGE_NTF, function(delta)
  19. self:Refresh()
  20. if delta > 0 then
  21. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam("CompetitionTip4", delta)
  22. end
  23. end)
  24. end
  25. function CompetitionExchange:Refresh()
  26. local curCompetitionData = ManagerContainer.DataMgr.CompetitionData:GetCurCompetitionData()
  27. self.root.myScore.num.text.text = curCompetitionData.comParam
  28. local seasons = ManagerContainer.CfgMgr:GetCompetitionDatasByType(curCompetitionData.competitionId)
  29. if not next(seasons) then
  30. return
  31. end
  32. local competitionType = seasons[1].CompetitionType
  33. local percent = ManagerContainer.DataMgr.CompetitionData:GetRankPercent()
  34. if percent > 0 then
  35. local tips = ""--percent > 60 and I18N.T("DscSeasonTips3") or I18N.T("DscSeasonTips4")
  36. self.root.collection.num.uILocalizeScript:SetContentAndValues("DscSeasonR"..competitionType, {tips, percent, ""})
  37. else
  38. self.root.collection.num.uILocalizeScript:SetContentAndValues("DscSeasonR"..competitionType, {I18N.T("DscSeasonTips4"), 60, ""})
  39. end
  40. local periodIdx = ManagerContainer.DataMgr.CompetitionData:GetCurPeriodIdx()
  41. if not periodIdx then
  42. return
  43. end
  44. local periodData = ManagerContainer.DataMgr.CompetitionData:GetCurPeriodData(periodIdx)
  45. if not periodData then
  46. return
  47. end
  48. local rewardCompetitionId = periodData.paramList[1]
  49. self.competitionCfgData = ManagerContainer.CfgMgr:GetCompetitionDataById(rewardCompetitionId)
  50. if not self.competitionCfgData then
  51. return
  52. end
  53. CommonUtil.LoadIcon(self.root, self.competitionCfgData.CompetitionTitleIcon, function (sprite)
  54. self.root.reward.icon.image.sprite = sprite
  55. end)
  56. self.root.reward.num.uILocalizeScript:SetContent(self.competitionCfgData.CompetitionTitle)
  57. local delta = curCompetitionData.nextComScore - curCompetitionData.comParam
  58. self.root.next:SetActive(percent > 0 and delta > 0)
  59. self.root.next.num.text.text = delta
  60. self:RefreshExchangeItems()
  61. end
  62. local function GetScore(id)
  63. for k,v in pairs(scores) do
  64. if tonumber(v[1]) == id then
  65. if k < 4 then
  66. return v[2]
  67. elseif k == 4 then
  68. return v[2].."~"..v[3]
  69. end
  70. end
  71. end
  72. return 0
  73. end
  74. function CompetitionExchange:RefreshExchangeItems()
  75. if not self.competitionCfgData then return end
  76. local items = self.competitionCfgData.HuodongItem
  77. for i = 1, 4 do
  78. local item = self.root["item"..i]
  79. if items and item and items[i] then
  80. local itemData = ManagerContainer.DataMgr.BagData:GetItemByCfgId(items[i])
  81. local num = itemData and itemData.num or 0
  82. local data = {cfgId = items[i], num = num}
  83. item.num.text.text = GetScore(items[i])
  84. IconItemCtr:SetData(self.root, item.iconSmallItem, data, Enum.ItemIEnterType.Bag, self.root, self.root.ShowItemTips)
  85. item.iconSmallItem.num:SetActive(true)
  86. item.iconSmallItem.num.text.text = num
  87. end
  88. end
  89. end
  90. function CompetitionExchange:ShowItemTips(button, params)
  91. local data = params[0]
  92. local itemData = ManagerContainer.DataMgr.BagData:GetItemDataByCfgId(data.cfgId)
  93. if not itemData then
  94. itemData = data
  95. end
  96. local data1 = clone(itemData)
  97. data1.displayBtn = true
  98. local _extData = {_id = data1.id}
  99. ManagerContainer.LuaUIMgr:OpenTips(data1, _extData)
  100. end
  101. function CompetitionExchange:OnSureClick(button, params)
  102. if not self.competitionCfgData then return end
  103. local idx = params[0]
  104. local itemList = {}
  105. local items = self.competitionCfgData.HuodongItem
  106. local itemData = ManagerContainer.DataMgr.BagData:GetItemByCfgId(items[idx])
  107. local cfgData = ManagerContainer.CfgMgr:GetItemById(items[idx])
  108. local num = itemData and itemData.num or 0
  109. if num > 0 then
  110. itemList[#itemList + 1] = {key = items[idx], value = idx < 4 and num or 1}
  111. end
  112. if #itemList == 0 then
  113. ManagerContainer.LuaUIMgr:ErrorNoticeDisplayWithParam(idx < 4 and "DscSeasonResult11" or "DscSeasonResult12", I18N.T(cfgData.Name))
  114. return
  115. end
  116. ManagerContainer.DataMgr.CompetitionData:SendExchangeScoreReq(itemList)
  117. end
  118. function CompetitionExchange:Dispose()
  119. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.SEASON_EXCHANGE_NTF_MAIN)
  120. self.competitionCfgData = nil
  121. self.root = nil
  122. end
  123. return CompetitionExchange