UIGuildWarActivityShopView.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. local UIGuildWarActivityShopView = require("UIActivity/UIActivityTowerView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. local RankBgColorIcon = {"FrameNew/bg_label_red", "FrameNew/bg_label_yellow", "FrameNew/bg_label_purple", "FrameNew/bg_label_blue", "FrameNew/bg_label_green", "FrameNew/bg_label_green"}
  4. local RankBGColor = {Color(1, 0.76, 0.72, 1), Color(1, 0.86, 0.57, 1), Color(0.98, 0.67, 1, 1), Color(0.65, 0.87, 1, 1), Color(0.66, 0.92, 0.71, 1), Color(0.66, 0.92, 0.71, 1)}
  5. local BannerPath = 'RankBanner/banner_tower_guildwar_cn'
  6. local pageToggleData = {}
  7. local countlimit = 10
  8. local reward
  9. function UIGuildWarActivityShopView:OnAwake(data)
  10. self.controller = require("UIGuildWar/UIGuildWarActivityShopCtr"):new()
  11. self.controller:Init(self)
  12. self.controller:SetData(data)
  13. end
  14. function UIGuildWarActivityShopView:AddEventListener()
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RUNE_SHOP_DATA_CHANGED, self, self.RefreshNew)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.GUILD_WAR_OPEN_STATE_CHANGED, self, self.OnOpenStateChanged)
  17. end
  18. function UIGuildWarActivityShopView:FillContent(data, uiBase)
  19. self.uiBase = uiBase
  20. local gameObject = self.uiBase:GetRoot()
  21. if gameObject ~= nil then
  22. self.gameObject = gameObject
  23. self.transform = gameObject.transform
  24. end
  25. self:InitGenerate(self.transform, data)
  26. self:Init()
  27. end
  28. function UIGuildWarActivityShopView:Init()
  29. self.rankIdx = 0
  30. self.controller:InitData()
  31. self:InitGrid()
  32. self:InitTopInfo()
  33. end
  34. function UIGuildWarActivityShopView:InitGrid()
  35. self.RankListScroll.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  36. return self:GetRankItemByRowColumn(gridView, itemIndex, row, column)
  37. end, nil)
  38. self.LimitedListScroll.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  39. return self:GetShopItemByRowColumn(gridView, itemIndex, row, column)
  40. end, nil)
  41. self.RankListScroll.loopGridView.ScrollRect.enabled = false
  42. self.LimitedListScroll.loopGridView.ScrollRect.enabled = false
  43. self.RankListScroll:SetActive(true)
  44. self.LimitedListScroll:SetActive(true)
  45. end
  46. function UIGuildWarActivityShopView:InitTopInfo()
  47. self.mapToggle.text.uILocalizeScript:SetContent("RankReward")
  48. self.rewardsToggle.text.uILocalizeScript:SetContent("GuildWarDiagram31")
  49. CommonUtil.LoadIcon(self, BannerPath, function (sprite)
  50. self.banner1.image.sprite = sprite
  51. end)
  52. self.btnQuestion:SetActive(false)
  53. self.timeBox:SetActive(false)
  54. self.banner1:SetActive(true)
  55. self.banner2:SetActive(false)
  56. self.banner3:SetActive(false)
  57. self.btnGoto:SetActive(false)
  58. self.btnGetRewards:SetActive(false)
  59. self.bottom:SetActive(false)
  60. end
  61. function UIGuildWarActivityShopView:OnValueChangedToggle(index, needRefresh)
  62. local rankListState = (pageToggleData.toggleDefaultIndex <= 2)
  63. local limitedState = (pageToggleData.toggleDefaultIndex == 3)
  64. self.rankListBox:SetActive(rankListState)
  65. self.limitedBox:SetActive(limitedState)
  66. if rankListState then
  67. local cfgDatas = nil
  68. if pageToggleData.toggleDefaultIndex == 1 then
  69. cfgDatas = self.controller:GetGuildsmenRewords()
  70. elseif pageToggleData.toggleDefaultIndex == 2 then
  71. cfgDatas = self.controller:GetMvpRewords()
  72. end
  73. local num = cfgDatas and #cfgDatas or 0
  74. if not needRefresh then
  75. self.RankListScroll.loopGridView:RefreshListByIndex(num, 0)
  76. else
  77. self.RankListScroll.loopGridView:RefreshListByIndex(num)
  78. end
  79. elseif limitedState then
  80. self.controller:RefreshCurShopData(true)
  81. local datas = self.controller:GetShowGoodsDatas()
  82. local num = datas and #datas or 0
  83. if not needRefresh then
  84. self.LimitedListScroll.loopGridView:RefreshListByIndex(num, 0)
  85. else
  86. self.LimitedListScroll.loopGridView:RefreshListByIndex(num)
  87. end
  88. end
  89. end
  90. function UIGuildWarActivityShopView:RefreshNew()
  91. if pageToggleData.toggleDefaultIndex == 3 then
  92. self:OnValueChangedToggle(nil, true)
  93. end
  94. end
  95. function UIGuildWarActivityShopView:GetRankItemByRowColumn(gridView, itemIndex, row, column)
  96. local cfgDatas = nil
  97. if pageToggleData.toggleDefaultIndex == 1 then
  98. cfgDatas = self.controller:GetGuildsmenRewords()
  99. elseif pageToggleData.toggleDefaultIndex == 2 then
  100. cfgDatas = self.controller:GetMvpRewords()
  101. end
  102. if not cfgDatas then
  103. return nil
  104. end
  105. local cfgData = cfgDatas[itemIndex + 1]
  106. if not cfgData then
  107. return nil
  108. end
  109. local item = gridView:NewListViewItem('RankRewardsItem')
  110. item.gameObject.name = itemIndex
  111. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RankRewardsItem', item.gameObject)
  112. itemLua.textName:SetActive(false)
  113. itemLua.textDsc:SetActive(false)
  114. itemLua.num:SetActive(false)
  115. itemLua.textAdvTarget:SetActive(true)
  116. itemLua.textLowestTarget:SetActive(false)
  117. itemLua.labelEstimate:SetActive(false)
  118. itemLua.labelReceived:SetActive(false)
  119. local rank = nil
  120. local rankLangKey = nil
  121. local nameLangKey = nil
  122. local itemDatas = nil
  123. if pageToggleData.toggleDefaultIndex == 1 then
  124. rank = cfgData[1]
  125. rankLangKey = cfgData[2]
  126. itemDatas = cfgData[3]
  127. elseif pageToggleData.toggleDefaultIndex == 2 then
  128. local type = cfgData[1]
  129. rank = cfgData[2]
  130. rankLangKey = cfgData[3]
  131. itemDatas = cfgData[4]
  132. if rank == 1 then
  133. if type == 1 then
  134. nameLangKey = 'GuildWarDiagram26'
  135. else
  136. nameLangKey = 'GuildWarDiagram25'
  137. end
  138. elseif rank == 2 then
  139. if type == 1 then
  140. nameLangKey = 'GuildWarDiagram28'
  141. else
  142. nameLangKey = 'GuildWarDiagram27'
  143. end
  144. else
  145. if type == 1 then
  146. nameLangKey = 'GuildWarDiagram30'
  147. else
  148. nameLangKey = 'GuildWarDiagram29'
  149. end
  150. end
  151. end
  152. CommonUtil.LoadIcon(self, RankBgColorIcon[rank], function (sprite)
  153. itemLua.imageLabel.image.sprite = sprite
  154. end, itemLua, "rankBg")
  155. itemLua.nameBG.image.color = RankBGColor[rank]
  156. itemLua.labelRank.text.uILocalizeScript:SetContent(rankLangKey)
  157. itemLua.textAdvTarget.text.text = nameLangKey and I18N.T(nameLangKey) or ''
  158. CommonUtil.BatchCreateItemsLoopSpawnPrefabNew1(self, itemDatas, Enum.PrefabNames.IconSmallItem, "IconItem", itemLua.RewardsNode.transform, Enum.ItemIEnterType.Bag, self, self.OnItemClick)
  159. return item
  160. end
  161. function UIGuildWarActivityShopView:GetShopItemByRowColumn(gridView, itemIndex, row, column)
  162. local datas = self.controller:GetShowGoodsDatas()
  163. if not datas then return end
  164. local item = gridView:NewListViewItem('RankShopLimitedItem')
  165. item.gameObject.name = itemIndex
  166. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RankShopLimitedItem', item.gameObject)
  167. local data = datas[itemIndex + 1]
  168. local cfgData = data.cfgData
  169. CommonUtil.LoadIcon(self, cfgData.Banner, function (sprite)
  170. itemLua.itemBg.image.sprite = sprite
  171. end)
  172. CommonUtil.LoadIcon(self, cfgData.NameImg, function (sprite)
  173. itemLua.itemText.image.sprite = sprite
  174. end)
  175. itemLua.saveLabel.text.text.text = cfgData.ExtraNum
  176. itemLua.presentPrice.number.text.text = data.price
  177. itemLua.labelLimited.textLimited.uILocalizeScript:SetContentAndValues("RushListLimitBuy", {data:GetRemainBuyNum()})
  178. itemLua.soldout:SetActive(not data:IsCanBuy())
  179. local itemDatas = {}
  180. for _,v in pairs(cfgData.Reward) do
  181. local itemData = {cfgId = v[1], num = v[2]}
  182. itemDatas[#itemDatas + 1] = itemData
  183. end
  184. CommonUtil.BatchCreateItemsLoopSpawnPrefabNew(self, itemDatas, Enum.PrefabNames.RankShopRewardIconItem, itemLua.RewardsNode.transform, Enum.ItemIEnterType.Bag, self, self.OnItemClick)
  185. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnPay, data)
  186. return item
  187. end
  188. function UIGuildWarActivityShopView:OnItemClick(button, params)
  189. local data = params[0]
  190. ManagerContainer.LuaUIMgr:OpenTips(data)
  191. end
  192. function UIGuildWarActivityShopView:OnPay(button, params)
  193. local data = params[0]
  194. local shopType, shopSubType = self.controller:GetCurShopType()
  195. local errorCode = ManagerContainer.PayMgr:RuneShopPay(shopType, shopSubType, data.id)
  196. local errorCodeKey = ManagerContainer.PayMgr:GetInitPayErrorCodeLangKey(errorCode)
  197. if not errorCodeKey then
  198. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  199. end
  200. end
  201. function UIGuildWarActivityShopView:RemoveEventListener()
  202. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  203. end
  204. function UIGuildWarActivityShopView:AddUIEventListener()
  205. self.uiBase:AddButtonEventListener(self.backBtn.button, self, self.OnCloseClick)
  206. CommonUtil.CreateToggleMouduleOnlyBtns(self, pageToggleData, self.toggleGroup, 1, self.OnValueChangedToggle, self)
  207. end
  208. function UIGuildWarActivityShopView:OnCloseClick()
  209. self:UIClose()
  210. end
  211. function UIGuildWarActivityShopView:OnHide()
  212. end
  213. function UIGuildWarActivityShopView:OnShow(data)
  214. self.controller:SetData(data)
  215. end
  216. function UIGuildWarActivityShopView:OnClose()
  217. end
  218. function UIGuildWarActivityShopView:OnDispose()
  219. CommonUtil.RecycleFromBatchItemsByPrefabName(self, Enum.PrefabNames.IconSmallItem)
  220. self.RankListScroll.loopGridView:Dispose()
  221. CommonUtil.RecycleFromBatchItemsByPrefabName(self, Enum.PrefabNames.RankShopRewardIconItem)
  222. self.LimitedListScroll.loopGridView:Dispose()
  223. self.controller:OnDispose()
  224. end
  225. function UIGuildWarActivityShopView:OnPageInEnd()
  226. self.super.OnPageInEnd(self)
  227. self.RankListScroll.loopGridView.ScrollRect.enabled = true
  228. self.LimitedListScroll.loopGridView.ScrollRect.enabled = true
  229. end
  230. function UIGuildWarActivityShopView:OnOpenStateChanged(isOpen)
  231. if isOpen then return end
  232. self:UIClose()
  233. end
  234. return UIGuildWarActivityShopView