UIRuneShopView.lua 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. local UIRuneShopView = require("UIRuneShop/UIRuneShopView_Generate")
  2. local FirstBuyBgIconPath = 'ShopIcons/txt_club_first'
  3. local ExtraBuyBgIconPath = 'ShopIcons/txt_club_free_extra_cn'
  4. local RuneShopRewardsPath = 'UIRuneShop/RewardsBoxItem'
  5. local lastClickLogTime
  6. local lastClickNum
  7. function UIRuneShopView:OnAwake(data)
  8. self.controller = require("UIRuneShop/UIRuneShopCtr"):new()
  9. self.controller:Init(self)
  10. self.controller:SetData(data)
  11. end
  12. function UIRuneShopView:AddEventListener()
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.COIN_CHANGED, self, self.OnCoinChanged)
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.DIAMOND_CHANGED, self, self.OnDiamondChanged)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.VIP_LV_CHANGED, self, self.OnVipLvChanged)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RUNE_SHOP_DATA_CHANGED, self, self.OnRuneShopDataChanged)
  17. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RUNE_SHOP_REWARDS_DATA_CHANGED, self, self.OnRuneShopRewardsDataChanged)
  18. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_CLOSEED_TASK_PAGE, self, self.OnCloseTask)
  19. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_TASK_JUMP, self, self.OnCloseAirShip)
  20. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.RED_POINT_MGR_NOTICE, self, self.OnRPNotify)
  21. end
  22. function UIRuneShopView:FillContent(data, uiBase)
  23. self.uiBase = uiBase
  24. local gameObject = self.uiBase:GetRoot()
  25. if gameObject ~= nil then
  26. self.gameObject = gameObject
  27. self.transform = gameObject.transform
  28. end
  29. self:InitGenerate(self.transform, data)
  30. self:Init()
  31. end
  32. function UIRuneShopView:Init()
  33. self.controller:InitData()
  34. self.itemStart = true
  35. lastClickLogTime = nil
  36. lastClickNum = nil
  37. self.giftsBox.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column)
  38. return self:GetItemByRowColumnGifts(loopGridView, itemIdx, row, column)
  39. end, nil, nil)
  40. self.limitedBox.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column)
  41. return self:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column)
  42. end, nil, nil)
  43. self:RefreshCoinView()
  44. self:RefreshGoldView()
  45. self:RefreshVipView()
  46. self:RefreshToggleGroupView()
  47. self:RefreshShopView(true)
  48. end
  49. function UIRuneShopView:RemoveEventListener()
  50. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  51. end
  52. function UIRuneShopView:AddUIEventListener()
  53. self.uiBase:AddButtonUniqueEventListener(self.btnClose.button, self, self.OnClickCloseBtn)
  54. self.uiBase:AddButtonUniqueEventListener(self.btnVIP.button, self, self.OnClickVipBtn)
  55. self.uiBase:AddToggleUniqueEventListener(self.monthToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.MonthCard)
  56. self.uiBase:AddToggleUniqueEventListener(self.giftsToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.Gifts)
  57. self.uiBase:AddToggleUniqueEventListener(self.limitedToggle.toggle, self, self.OnClickOneToggle, Enum.RuneShopType.LimitTime)
  58. self.uiBase:AddToggleUniqueEventListener(self.rewardsToggle.toggle, self, self.OnClickRewardsToggle)
  59. self.uiBase:AddButtonUniqueEventListener(self.dailyBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Daily)
  60. self.uiBase:AddButtonUniqueEventListener(self.weekBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Week)
  61. self.uiBase:AddButtonUniqueEventListener(self.monthBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Month)
  62. self.uiBase:AddButtonUniqueEventListener(self.goldBtn.button, self, self.OnClickShopSubBtn, Enum.RuneShopSubType.Gold)
  63. self.uiBase:AddButtonUniqueEventListener(self.btnLog.button, self, self.OnClickBtnLog)
  64. end
  65. function UIRuneShopView:OnHide()
  66. end
  67. function UIRuneShopView:OnShow(data)
  68. if data then
  69. self.controller:SetData(data)
  70. self.controller:InitData()
  71. end
  72. self:RefreshCoinView()
  73. self:RefreshGoldView()
  74. self:RefreshVipView()
  75. self:RefreshToggleGroupView()
  76. self:RefreshShopView(true)
  77. --
  78. end
  79. function UIRuneShopView:OnClose()
  80. end
  81. function UIRuneShopView:OnDispose()
  82. self:DisposeRefreshTimer()
  83. self.giftsBox.scrollView.loopGridView:Dispose()
  84. self.limitedBox.scrollView.loopGridView:Dispose()
  85. if self.rewardsBoxItem then
  86. self.rewardsBoxItemLua.scrollView.loopGridView:Dispose()
  87. end
  88. if self.seqId then
  89. ManagerContainer.ResMgr:UnloadAssetBySeqId(self.seqId)
  90. self.seqId = nil
  91. end
  92. if self.rewardsBoxItem then
  93. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, RuneShopRewardsPath, self.rewardsBoxItem.gameObject)
  94. self.rewardsBoxItem = nil
  95. self.isInited = false
  96. end
  97. lastClickLogTime = nil
  98. lastClickNum = nil
  99. self.controller:OnDispose()
  100. end
  101. function UIRuneShopView:OnCoinChanged()
  102. self:RefreshCoinView()
  103. end
  104. function UIRuneShopView:OnDiamondChanged()
  105. self:RefreshGoldView()
  106. end
  107. function UIRuneShopView:OnVipLvChanged()
  108. self:RefreshVipView()
  109. end
  110. function UIRuneShopView:OnRuneShopDataChanged(runeShopType, runeShopSubType)
  111. if runeShopType ~= self.controller:GetShopType() then return end
  112. local curRuneShopSubType = self.controller:GetShopSubType()
  113. if curRuneShopSubType and runeShopSubType ~= curRuneShopSubType then return end
  114. self.controller:RefreshCurShopData()
  115. self:RefreshShopView()
  116. end
  117. function UIRuneShopView:OnRuneShopRewardsDataChanged()
  118. self:RefreshShopView()
  119. end
  120. function UIRuneShopView:OnRPNotify(rpType)
  121. if rpType ~= Enum.RPNotifyType.RuneShopLimitGift then
  122. return
  123. end
  124. if Enum.RuneShopType.LimitTime ~= self.controller:GetShopType() then return end
  125. local curRuneShopSubType = self.controller:GetShopSubType()
  126. if curRuneShopSubType and nil ~= curRuneShopSubType then return end
  127. self:RefreshShopView()
  128. end
  129. function UIRuneShopView:OnClickBtnLog(button, params)
  130. local curTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  131. if not lastClickLogTime or (curTime - lastClickLogTime) > 15000 then
  132. lastClickLogTime = curTime
  133. lastClickNum = 0
  134. end
  135. if not lastClickNum then
  136. lastClickNum = 0
  137. end
  138. lastClickNum = lastClickNum + 1
  139. if lastClickNum >= 30 then
  140. lastClickNum = 0
  141. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'Log1', true})
  142. end
  143. end
  144. function UIRuneShopView:OnClickCloseBtn()
  145. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  146. end
  147. function UIRuneShopView:OnClickVipBtn()
  148. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIVip)
  149. end
  150. function UIRuneShopView:OnClickOneToggle(tog, params, b)
  151. if not b then return end
  152. local shopType = params[0]
  153. if self.controller:ChangeShopType(shopType) then
  154. self:RefreshShopView(true)
  155. end
  156. end
  157. function UIRuneShopView:OnClickRewardsToggle(tog, params, b)
  158. if not b then return end
  159. if self.controller:ChangeShopType(nil) then
  160. self:RefreshShopView(true)
  161. end
  162. end
  163. function UIRuneShopView:OnClickShopSubBtn(btn, params)
  164. local shopSubType = params[0]
  165. if self.controller:ChangeShopSubType(shopSubType) then
  166. self:RefreshGiftsView(true)
  167. end
  168. end
  169. function UIRuneShopView:OnClickMonthCardPrice(button, params)
  170. local id = params[0]
  171. local errorCodeKey = self.controller:SendPay(id)
  172. if not errorCodeKey then
  173. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  174. end
  175. end
  176. function UIRuneShopView:OnClickGiftItem(button, params)
  177. local id = params[0]
  178. local runeShopType = self.controller:GetShopType()
  179. local runeShopSubType = self.controller:GetShopSubType()
  180. if runeShopType == Enum.RuneShopType.Gifts then
  181. if runeShopSubType == Enum.RuneShopSubType.Gold then
  182. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id})
  183. return
  184. end
  185. end
  186. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id})
  187. end
  188. function UIRuneShopView:OnClickGiftPrice(button, params)
  189. -- 直接发起支付
  190. local id = params[0]
  191. local errorCodeKey = self.controller:SendPay(id)
  192. if not errorCodeKey then
  193. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  194. end
  195. end
  196. function UIRuneShopView:OnClickLimitedItem(button, params)
  197. local id = params[0]
  198. local itemIdx = params[1]
  199. local runeShopType = self.controller:GetShopType()
  200. local runeShopSubType = self.controller:GetShopSubType()
  201. if runeShopType == Enum.RuneShopType.Gifts then
  202. if runeShopSubType == Enum.RuneShopSubType.Gold then
  203. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopGoldBuyTips, {runeShopType, runeShopSubType, id})
  204. return
  205. end
  206. end
  207. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBuyTips, {runeShopType, runeShopSubType, id})
  208. ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:CancelRedPointStatusById(id)
  209. self.limitedBox.scrollView.loopGridView:RefreshItemByItemIndex(itemIdx)
  210. end
  211. function UIRuneShopView:OnClickLimitedPrice(button, params)
  212. -- 直接发起支付
  213. local id = params[0]
  214. local itemIdx = params[1]
  215. local errorCodeKey = self.controller:SendPay(id)
  216. if not errorCodeKey then
  217. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(errorCodeKey)
  218. end
  219. ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:CancelRedPointStatusById(id)
  220. self.limitedBox.scrollView.loopGridView:RefreshItemByItemIndex(itemIdx)
  221. end
  222. function UIRuneShopView:OnClickPlayRuleBtn()
  223. local rule
  224. rule = "AirshipText"
  225. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', rule})
  226. end
  227. function UIRuneShopView:OnClickTaskExpBtn()
  228. ManagerContainer.DataMgr.TaskDataNew:OpenTaskPanel();
  229. end
  230. function UIRuneShopView:OnClickBuyAdvancedRewardsBtn()
  231. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRewardsBuyTips)
  232. end
  233. function UIRuneShopView:OnClickGetAdvancedRewardBtn()
  234. if self.rewardsBaseData:GetMaxRewardsNum() > 0 then
  235. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPLORE_EXTRA_REWARD_REQ)
  236. end
  237. end
  238. function UIRuneShopView:OnCloseTask()
  239. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPLORE_INFO_REQ)
  240. end
  241. function UIRuneShopView:OnCloseAirShip()
  242. ManagerContainer.LuaUIMgr:Close(Enum.UIPageName.UIRuneShop)
  243. end
  244. function UIRuneShopView:PreLoadAssets()
  245. if not self.rewardsBoxItem then
  246. self.rewardsBoxItem = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, RuneShopRewardsPath)
  247. if self.rewardsBoxItem then
  248. self.rewardsBoxItemLua = CommonUtil.BindGridViewItem2LuaStatic("RewardsBoxItem",self.rewardsBoxItem.gameObject)
  249. self.rewardsBoxItemLua.transform:SetParent(self.rewardsBox.transform)
  250. self.rewardsBoxItemLua.transform.localPosition = Vector3.zero
  251. self.rewardsBoxItemLua.transform.localRotation = Quaternion.identity
  252. self.rewardsBoxItemLua.transform.localScale = Vector3.one
  253. self.rectTrans = self.rewardsBoxItemLua.rectTransform
  254. self.rectTrans.offsetMax = Vector2(0,0)
  255. self.rectTrans.offsetMin = Vector2(0,0)
  256. self.rectTrans.anchoredPosition3D = Vector3.zero
  257. self.rectTrans.anchoredPosition = Vector2(0,0)
  258. self.uiBase:AddButtonUniqueEventListener(self.rewardsBoxItemLua.btnPlayRule.button, self, self.OnClickPlayRuleBtn)
  259. self.uiBase:AddButtonUniqueEventListener(self.rewardsBoxItemLua.btnBuyMore.button, self, self.OnClickBuyAdvancedRewardsBtn)
  260. self.uiBase:AddButtonUniqueEventListener(self.btnTaskExp.button, self, self.OnClickTaskExpBtn)
  261. self.rewardsBoxItemLua.scrollView.loopGridView:InitGridView(0, function(loopGridView, itemIdx, row, column)
  262. return self:GetItemByRowColumnRewards(loopGridView, itemIdx, row, column)
  263. end, nil, nil)
  264. self:RefreshRewardsView()
  265. end
  266. end
  267. end
  268. function UIRuneShopView:RefreshCoinView()
  269. self.coin.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Coin))
  270. end
  271. function UIRuneShopView:RefreshGoldView()
  272. self.gold.number.text.text = CommonUtil.FormatNumber(self.controller:GetOwnResCountByItemId(Enum.ItemType.Diamond))
  273. end
  274. function UIRuneShopView:RefreshVipView()
  275. local curVipLv = self.controller:GetCurVipLv()
  276. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curVipLv)
  277. self.vipIcon.image.sprite = nil
  278. self.vipIcon.image.enabled = false
  279. self.vipFrame.image.sprite = nil
  280. self.vipFrame.image.enabled = false
  281. if not vipCfg then
  282. self.vipNameTxt.text.text = ''
  283. return
  284. end
  285. CommonUtil.LoadIcon(self, vipCfg.BigIcon, function(sprite)
  286. if sprite then
  287. self.vipIcon.image.sprite = sprite
  288. self.vipIcon.image.enabled = true
  289. end
  290. end)
  291. CommonUtil.LoadIcon(self, vipCfg.BigFrame, function(sprite)
  292. if sprite then
  293. self.vipFrame.image.sprite = sprite
  294. self.vipFrame.image.enabled = true
  295. end
  296. end)
  297. self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  298. end
  299. function UIRuneShopView:RefreshToggleGroupView()
  300. if not ManagerContainer.DataMgr.RuneShopDataMgr:GetAirShipIsOpen() then
  301. self.rewardsToggle:SetActive(false)
  302. else
  303. local state = true
  304. local unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(54)
  305. if not unlockState then
  306. state = false
  307. end
  308. self.rewardsToggle:SetActive(state)
  309. end
  310. local shopType = self.controller:GetShopType()
  311. local toggleGroup = self.content.toggleGroup
  312. local oldAllowSwitchOff = toggleGroup.allowSwitchOff
  313. toggleGroup.allowSwitchOff = true
  314. self.monthToggle.toggle.isOn = (shopType == Enum.RuneShopType.MonthCard)
  315. self.giftsToggle.toggle.isOn = (shopType == Enum.RuneShopType.Gifts)
  316. self.limitedToggle.toggle.isOn = (shopType == Enum.RuneShopType.LimitTime)
  317. self.rewardsToggle.toggle.isOn = (shopType == nil)
  318. toggleGroup.allowSwitchOff = oldAllowSwitchOff
  319. end
  320. function UIRuneShopView:RefreshShopView(resetPos)
  321. self:StopAndClearRefreshTimer()
  322. local shopType = self.controller:GetShopType()
  323. if not shopType then
  324. self.monthBox:SetActive(false)
  325. self.giftsBox:SetActive(false)
  326. self.limitedBox:SetActive(false)
  327. self.rewardsBox:SetActive(true)
  328. self.rewardsExpBox:SetActive(true)
  329. if self.rewardsBoxItem then
  330. self:RefreshRewardsView()
  331. else
  332. self.seqId = ManagerContainer.ResMgr:LuaLoadAssets(Enum.ResourceType.GameObject, Constants.UIPath, { RuneShopRewardsPath}, self, self.PreLoadAssets)
  333. end
  334. self.textBox.text.text = string.formatbykey('DscClub04')
  335. return
  336. end
  337. if shopType == Enum.RuneShopType.MonthCard then
  338. self.monthBox:SetActive(true)
  339. self.giftsBox:SetActive(false)
  340. self.limitedBox:SetActive(false)
  341. self.rewardsBox:SetActive(false)
  342. self.rewardsExpBox:SetActive(false)
  343. self:RefreshMonthCardView()
  344. self.textBox.text.text = string.formatbykey('DscClub01')
  345. elseif shopType == Enum.RuneShopType.Gifts then
  346. self.monthBox:SetActive(false)
  347. self.giftsBox:SetActive(true)
  348. self.limitedBox:SetActive(false)
  349. self.rewardsBox:SetActive(false)
  350. self.rewardsExpBox:SetActive(false)
  351. self:RefreshGiftsView(resetPos)
  352. self.textBox.text.text = string.formatbykey('DscClub02')
  353. elseif shopType == Enum.RuneShopType.LimitTime then
  354. self.monthBox:SetActive(false)
  355. self.giftsBox:SetActive(false)
  356. self.limitedBox:SetActive(true)
  357. self.rewardsBox:SetActive(false)
  358. self.rewardsExpBox:SetActive(false)
  359. self:RefreshLimitedView(resetPos)
  360. self.textBox.text.text = string.formatbykey('DscClub03')
  361. else
  362. self.monthBox:SetActive(false)
  363. self.giftsBox:SetActive(false)
  364. self.limitedBox:SetActive(false)
  365. self.rewardsBox:SetActive(false)
  366. self.rewardsExpBox:SetActive(false)
  367. self.textBox.text.text = ''
  368. end
  369. end
  370. function UIRuneShopView:RefreshMonthCardView()
  371. self:RefreshOneMonthCardView(self.monthCard1, 1)
  372. self:RefreshOneMonthCardView(self.monthCard2, 2)
  373. end
  374. function UIRuneShopView:RefreshOneMonthCardView(itemLua, idx)
  375. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  376. if not showGoodsDatas then
  377. itemLua:SetActive(false)
  378. return
  379. end
  380. local showGoodsData = showGoodsDatas[idx]
  381. if not showGoodsData then
  382. itemLua:SetActive(false)
  383. return
  384. end
  385. itemLua:SetActive(true)
  386. local cfgData = showGoodsData:GetCfgData()
  387. local buyRewards = cfgData.BuyReward
  388. if buyRewards then
  389. local buyReward = buyRewards[1]
  390. if buyReward then
  391. self:RefreshCurrenyItem(itemLua.buyReward1, buyReward[1], buyReward[2], true)
  392. else
  393. self:RefreshCurrenyItem(itemLua.buyReward1)
  394. end
  395. buyReward = buyRewards[2]
  396. if buyReward then
  397. self:RefreshCurrenyItem(itemLua.buyReward2, buyReward[1], buyReward[2], true)
  398. else
  399. self:RefreshCurrenyItem(itemLua.buyReward2)
  400. end
  401. else
  402. self:RefreshCurrenyItem(itemLua.buyReward1)
  403. self:RefreshCurrenyItem(itemLua.buyReward2)
  404. end
  405. local dayRewards = cfgData.DayReward
  406. if dayRewards then
  407. local dayReward = dayRewards[1]
  408. if dayReward then
  409. self:RefreshCurrenyItem(itemLua.dailyReward, dayReward[1], dayReward[2], true)
  410. else
  411. self:RefreshCurrenyItem(itemLua.dailyReward)
  412. end
  413. else
  414. self:RefreshCurrenyItem(itemLua.dailyReward)
  415. end
  416. local totalRewards = cfgData.TotalReward
  417. if totalRewards then
  418. local totalReward = totalRewards[1]
  419. if totalReward then
  420. self:RefreshCurrenyItem(itemLua.totalReward, totalReward[1], totalReward[2], true)
  421. else
  422. self:RefreshCurrenyItem(itemLua.totalReward)
  423. end
  424. else
  425. self:RefreshCurrenyItem(itemLua.totalReward)
  426. end
  427. local price = showGoodsData:GetPrice()
  428. if price <= 0 then
  429. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  430. else
  431. itemLua.presentPrice.number.text.text = tostring(price)
  432. end
  433. local timerStr, outTime = showGoodsData:CalculateLimitTime()
  434. if not outTime then
  435. self:StartRefreshTimer(itemLua, showGoodsData)
  436. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr)
  437. itemLua.active:SetActive(true)
  438. itemLua.unActive:SetActive(false)
  439. else
  440. self:StopRefreshTimer(itemLua)
  441. local mdec = cfgData.Monthdec
  442. if mdec then
  443. itemLua.textDsc.text.text = string.formatbykey(cfgData.Monthdec)
  444. else
  445. itemLua.textDsc.text.text = ""
  446. end
  447. itemLua.active:SetActive(false)
  448. itemLua.unActive:SetActive(true)
  449. end
  450. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickMonthCardPrice, showGoodsData:GetId())
  451. end
  452. function UIRuneShopView:RefreshGiftsView(resetPos)
  453. local shopSubType = self.controller:GetShopSubType()
  454. if shopSubType == Enum.RuneShopSubType.Week then
  455. self:RefreshShopSubBtnState(self.dailyBtn, false)
  456. self:RefreshShopSubBtnState(self.weekBtn, true)
  457. self:RefreshShopSubBtnState(self.monthBtn, false)
  458. self:RefreshShopSubBtnState(self.goldBtn, false)
  459. elseif shopSubType == Enum.RuneShopSubType.Month then
  460. self:RefreshShopSubBtnState(self.dailyBtn, false)
  461. self:RefreshShopSubBtnState(self.weekBtn, false)
  462. self:RefreshShopSubBtnState(self.monthBtn, true)
  463. self:RefreshShopSubBtnState(self.goldBtn, false)
  464. elseif shopSubType == Enum.RuneShopSubType.Gold then
  465. self:RefreshShopSubBtnState(self.dailyBtn, false)
  466. self:RefreshShopSubBtnState(self.weekBtn, false)
  467. self:RefreshShopSubBtnState(self.monthBtn, false)
  468. self:RefreshShopSubBtnState(self.goldBtn, true)
  469. else -- Enum.RuneShopSubType.Daily
  470. self:RefreshShopSubBtnState(self.dailyBtn, true)
  471. self:RefreshShopSubBtnState(self.weekBtn, false)
  472. self:RefreshShopSubBtnState(self.monthBtn, false)
  473. self:RefreshShopSubBtnState(self.goldBtn, false)
  474. end
  475. local endTime = self.controller:GetRemainTime()
  476. if endTime then
  477. self:StartRefreshTimer(self, true)
  478. if endTime < 0 then endTime = 0 end
  479. self.timeBox:SetActive(true)
  480. self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  481. else
  482. self:StopRefreshTimer(self)
  483. self.timeBox:SetActive(false)
  484. end
  485. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  486. local length = (showGoodsDatas and #showGoodsDatas or 0)
  487. if resetPos then
  488. self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length, 0)
  489. else
  490. self.giftsBox.scrollView.loopGridView:RefreshListByIndex(length)
  491. end
  492. end
  493. function UIRuneShopView:RefreshShopSubBtnState(itemLua, isOn)
  494. itemLua.off:SetActive(not isOn)
  495. itemLua.on:SetActive(isOn)
  496. itemLua.button.interactable = (not isOn)
  497. end
  498. function UIRuneShopView:GetItemByRowColumnGifts(loopGridView, itemIdx, row, column)
  499. local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1)
  500. if not data then return nil end
  501. local item = loopGridView:NewListViewItem('RuneShopGoodsItem')
  502. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopGoodsItem', item.gameObject)
  503. if itemLua then
  504. itemLua.itemIcon.image.sprite = nil
  505. itemLua.itemIcon.image.enabled = false
  506. local cfgData = data.cfgData
  507. if cfgData then
  508. CommonUtil.LoadIcon(self, cfgData.Pic, function(sprite)
  509. if sprite then
  510. itemLua.itemIcon.image.sprite = sprite
  511. itemLua.itemIcon.image.enabled = true
  512. end
  513. end, itemLua, 'ItemIcon')
  514. itemLua.itemName.text.text = string.formatbykey(cfgData.Name)
  515. if cfgData.FirstBuyReward and #cfgData.FirstBuyReward > 0 and data:IsFirstBuy() then
  516. itemLua.discount:SetActive(true)
  517. itemLua.discount.text.text.text = string.formatbykey('LabelFirst')
  518. self:RefreshGiftsItem(itemLua, FirstBuyBgIconPath, cfgData.FirstBuyPic, cfgData.Reward)
  519. elseif cfgData.ExtraBuyReward and #cfgData.ExtraBuyReward > 0 then
  520. itemLua.discount:SetActive(true)
  521. itemLua.discount.text.text.text = string.formatbykey('LabelExtra')
  522. self:RefreshGiftsItem(itemLua, ExtraBuyBgIconPath, cfgData.ExtraBuyPic, cfgData.Reward)
  523. else
  524. itemLua.discount:SetActive(false)
  525. self:RefreshGiftsItem(itemLua, nil, nil, cfgData.Reward)
  526. end
  527. else
  528. itemLua.discount:SetActive(false)
  529. itemLua.itemName.text.text = ''
  530. itemLua.specialReward:SetActive(false)
  531. itemLua.goodsItems:SetActive(false)
  532. end
  533. local remainBuyNum = data:GetRemainBuyNum()
  534. if remainBuyNum >= 0 then
  535. itemLua.purchaseLimit:SetActive(true)
  536. itemLua.purchaseLimit.text.text = string.formatbykey('RuneShopLimitBuy', tostring(remainBuyNum))
  537. else
  538. itemLua.purchaseLimit:SetActive(false)
  539. end
  540. local price = data:GetPrice()
  541. if price <= 0 then
  542. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  543. else
  544. itemLua.presentPrice.number.text.text = tostring(price)
  545. end
  546. if data:IsSoldout() then
  547. itemLua.soldout:SetActive(true)
  548. itemLua.button.onClick:RemoveAllListeners()
  549. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  550. else
  551. itemLua.soldout:SetActive(false)
  552. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickGiftItem, data:GetId())
  553. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickGiftPrice, data:GetId())
  554. end
  555. end
  556. return item
  557. end
  558. function UIRuneShopView:RefreshGiftsItem(itemLua, bgPic, numPic, rewards)
  559. if numPic and numPic ~= '' then
  560. itemLua.specialReward.bg.image.sprite = nil
  561. itemLua.specialReward.bg.image.enabled = false
  562. CommonUtil.LoadIcon(self, bgPic, function(sprite)
  563. if sprite then
  564. itemLua.specialReward.bg.image.sprite = sprite
  565. itemLua.specialReward.bg.image.enabled = true
  566. end
  567. end, itemLua, 'SpecialRewardBgIcon')
  568. itemLua.specialReward.num.image.sprite = nil
  569. itemLua.specialReward.num.image.enabled = false
  570. CommonUtil.LoadIcon(self, numPic, function(sprite)
  571. if sprite then
  572. itemLua.specialReward.num.image.sprite = sprite
  573. itemLua.specialReward.num.image.enabled = true
  574. end
  575. end, itemLua, 'SpecialRewardNumIcon')
  576. itemLua.specialReward:SetActive(true)
  577. itemLua.goodsItems:SetActive(false)
  578. else
  579. itemLua.specialReward:SetActive(false)
  580. if rewards then
  581. itemLua.goodsItems:SetActive(true)
  582. local reward = rewards[1]
  583. if reward then
  584. itemLua.iconSmallItem1:SetActive(true)
  585. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem1, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  586. else
  587. itemLua.iconSmallItem1:SetActive(false)
  588. end
  589. reward = rewards[2]
  590. if reward then
  591. itemLua.iconSmallItem2:SetActive(true)
  592. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem2, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  593. else
  594. itemLua.iconSmallItem2:SetActive(false)
  595. end
  596. reward = rewards[3]
  597. if reward then
  598. itemLua.iconSmallItem3:SetActive(true)
  599. CommonUtil.UpdateItemPrefab(self, itemLua.iconSmallItem3, {cfgId = reward[1], num = reward[2]}, Enum.ItemIEnterType.Bag)
  600. else
  601. itemLua.iconSmallItem3:SetActive(false)
  602. end
  603. else
  604. itemLua.goodsItems:SetActive(false)
  605. end
  606. end
  607. end
  608. function UIRuneShopView:RefreshLimitedView(resetPos)
  609. local showGoodsDatas = self.controller:GetShowGoodsDatas()
  610. local length = (showGoodsDatas and #showGoodsDatas or 0)
  611. if resetPos then
  612. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length, 0)
  613. else
  614. self.limitedBox.scrollView.loopGridView:RefreshListByIndex(length)
  615. end
  616. end
  617. --悬赏战令页面
  618. function UIRuneShopView:RefreshRewardsView()
  619. if not self.rewardsBoxItemLua then return end
  620. if ManagerContainer.DataMgr.RuneShopDataMgr.isRewardsDataDirty then
  621. self.rewardsBoxItemLua:SetActive(false)
  622. return
  623. end
  624. self.rewardsBoxItemLua:SetActive(true)
  625. self.rewardsBaseData = self.controller:GetRewardsBaseData()
  626. local showGoodsDatas = self.rewardsBaseData:GetShowRewardsData()
  627. local curLv = self.rewardsBaseData:GetShowRewardsCurLv()
  628. local curExp = self.rewardsBaseData:GetShowRewardsCurExp()
  629. local curCfg = self.rewardsBaseData:GetRewardsCurRoundCfg()
  630. if not curCfg then
  631. self.rewardsBoxItemLua:SetActive(false)
  632. return
  633. end
  634. self.isShowAirShip = false
  635. local length = (showGoodsDatas and #showGoodsDatas or 0)
  636. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.RuneShopRewards, false)
  637. --页面下方关于当前等级的信息展示
  638. local nextlv = curLv + 1
  639. if nextlv > length then
  640. nextlv = length
  641. end
  642. if curLv == length then
  643. self.rewardsmax:SetActive(true)
  644. self.numexp.text.text = tostring(curExp)..'/'.. tostring(curCfg.ExpCost)
  645. self.expSlider.slider.value = curExp/curCfg.ExpCost
  646. else
  647. self.rewardsmax:SetActive(false)
  648. self.curLvData = self.controller:GetShowRewardsDataByIdx(nextlv)
  649. self.numexp.text.text = tostring(curExp)..'/'.. tostring(self.curLvData.cfgData.Exp)
  650. self.expSlider.slider.value = curExp/self.curLvData.cfgData.Exp
  651. end
  652. self.rewardslv.text.text = tostring(curLv)
  653. self.rewardsBoxItemLua.btnBuyMore.num.text.text = tostring(curCfg.MissonExpUp)..'%'
  654. self.expUpBlue.num.text.text = tostring(curCfg.MissonExpUp)..'%'
  655. --根据等级经验 刷新小游艇
  656. local newLv =length - curLv
  657. --因为多一个开始节点和结束最终奖励节点,所以+2
  658. self.rewardsBoxItemLua.scrollView.loopGridView:RecycleAllItem()
  659. if self.isInited then
  660. self.rewardsBoxItemLua.scrollView.loopGridView:RefreshListByIndex(length+2 )
  661. else
  662. self.rewardsBoxItemLua.scrollView.loopGridView:RefreshListByIndex(length+2 , newLv)
  663. end
  664. self.rewardsBoxItemLua.scrollView.loopGridView.mOnBeginDragAction = function(gridView)
  665. self:RefreshBigRewardsFloatTips(gridView)
  666. end
  667. self.rewardsBoxItemLua.scrollView.loopGridView.mOnDragingAction = function(gridView)
  668. self:RefreshBigRewardsFloatTips(gridView)
  669. end
  670. self.rewardsBoxItemLua.scrollView.loopGridView.mOnEndDragAction = function(gridView)
  671. self:RefreshBigRewardsFloatTips(gridView)
  672. end
  673. self.isInited = true
  674. local isCash = self.rewardsBaseData:GetRewardsIsCash()
  675. if isCash == 1 then
  676. self.rewardsBoxItemLua.btnBuyMore:SetActive(false)
  677. self.rewardsBoxItemLua.labelUnLocked:SetActive(true)
  678. self.expUpBlue:SetActive(true)
  679. else
  680. self.rewardsBoxItemLua.btnBuyMore:SetActive(true)
  681. self.rewardsBoxItemLua.labelUnLocked:SetActive(false)
  682. self.expUpBlue:SetActive(false)
  683. end
  684. local endTime = self.rewardsBaseData:RefreshRewaradsRemainTime()
  685. if endTime then
  686. self:StartRefreshTimer(self.rewardsBoxItemLua, true)
  687. if endTime < 0 then endTime = 0 end
  688. self:RefreshBigRewardsFloatTips(nil)
  689. self.rewardsBoxItemLua.timeBox:SetActive(true)
  690. self.rewardsBoxItemLua.timeBox.textTime.text.text = string.formatbykey('AirshipTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  691. else
  692. self:StopRefreshTimer(self.rewardsBoxItemLua)
  693. self.rewardsBoxItemLua.timeBox:SetActive(false)
  694. end
  695. end
  696. --大奖标签跳转
  697. function UIRuneShopView:JumpToTarget(button , params)
  698. local data = clone(params[0])
  699. self.rewardsBoxItemLua.scrollView.loopGridView:RefreshListByIndex(#self.controller:GetShowRewardsData()+2 , data.targetid)
  700. self:RefreshBigRewardsFloatTips()
  701. end
  702. --设置悬赏单个对象
  703. function UIRuneShopView:UpdateRewardsItem(itemLua, idx, data, isEnd)
  704. local curExp = self.rewardsBaseData:GetShowRewardsCurExp()
  705. local curLv = self.rewardsBaseData:GetShowRewardsCurLv()
  706. --最终奖励宝箱
  707. if isEnd then
  708. self.uiBase:AddButtonUniqueEventListener(itemLua.btnBuyMore.button, self, self.OnClickGetAdvancedRewardBtn)
  709. local costExp = ManagerContainer.CfgMgr:GetRuneShopExploreCfgByRound(self.rewardsBaseData:GetShowRewardsRoundData()).ExpCost
  710. if self.rewardsBaseData:GetMaxRewardsNum() > 0 then
  711. itemLua.chestAnim.animator:Play('Open')
  712. itemLua.redPoint:SetActive(true)
  713. itemLua.btnBuyMore.num.text.text = tostring(self.rewardsBaseData:GetMaxRewardsNum())
  714. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.RuneShopRewards, true)
  715. else
  716. itemLua.chestAnim.animator:Play('Close')
  717. itemLua.redPoint:SetActive(false)
  718. --self.uiBase:(itemLua.btnBuyMore.button, self, self.OnClickGetAdvancedRewardBtn)
  719. end
  720. if self.rewardsBaseData:GetRewardsIsMax() then
  721. itemLua.airShip:SetActive(true)
  722. itemLua.levelSlider.slider.value = 1
  723. else
  724. if curLv == #self.rewardsBaseData:GetShowRewardsData() then
  725. itemLua.airShip:SetActive(true)
  726. itemLua.levelSlider.slider.value = curExp/costExp
  727. else
  728. itemLua.airShip:SetActive(false)
  729. end
  730. end
  731. itemLua.dsc.text.text.text = string.formatbykey("DscRewardsMax",tostring(costExp),'1')
  732. --通用item
  733. else
  734. --0级开始
  735. if idx == 0 then
  736. itemLua.startItem:SetActive(true)
  737. itemLua.rewardsBox2:SetActive(false)
  738. itemLua.levelBox2:SetActive(false)
  739. if curLv == 0 and curExp/self.curLvData.cfgData.Exp < 0.15 then
  740. itemLua.startItem.airShip:SetActive(true)
  741. else
  742. itemLua.startItem.airShip:SetActive(false)
  743. end
  744. --常规等级
  745. else
  746. CommonUtil.UpdateItemPrefab(self, itemLua, data, Enum.ItemIEnterType.Bag, self, nil)
  747. --self.tempItemLua = itemLua
  748. itemLua.numlv.text.text = idx
  749. itemLua.startItem:SetActive(false)
  750. itemLua.rewardsBox2:SetActive(true)
  751. itemLua.levelBox2:SetActive(true)
  752. itemLua.rewardsBox2.bgyellow:SetActive(false)
  753. if data.cfgData.RewardSign > 0 then
  754. itemLua.rewardsBox2.bgyellow:SetActive(true)
  755. end
  756. if data.isReward then
  757. --0为 默认状态
  758. if data.isReward == 0 then
  759. itemLua.rewardsLeft.arrived:SetActive(false)
  760. itemLua.rewardsLeft.received:SetActive(false)
  761. --1为已领取
  762. elseif data.isReward == 1 then
  763. itemLua.rewardsLeft.arrived:SetActive(false)
  764. itemLua.rewardsLeft.received:SetActive(true)
  765. --可领取
  766. elseif data.isReward == 2 then
  767. itemLua.rewardsLeft.arrived:SetActive(true)
  768. itemLua.rewardsLeft.received:SetActive(false)
  769. end
  770. else
  771. itemLua.rewardsLeft.arrived:SetActive(false)
  772. itemLua.rewardsLeft.received:SetActive(false)
  773. end
  774. if data.isCashReward and self.rewardsBaseData:GetRewardsIsCash()==1 then
  775. --0为 默认状态
  776. if data.isCashReward == 0 then
  777. itemLua.rewardsRight.arrived:SetActive(false)
  778. itemLua.rewardsRight.received:SetActive(false)
  779. --1为已领取
  780. elseif data.isCashReward == 1 then
  781. itemLua.rewardsRight.arrived:SetActive(false)
  782. itemLua.rewardsRight.received:SetActive(true)
  783. --可领取
  784. elseif data.isCashReward == 2 then
  785. itemLua.rewardsRight.arrived:SetActive(true)
  786. itemLua.rewardsRight.received:SetActive(false)
  787. end
  788. else
  789. itemLua.rewardsRight.arrived:SetActive(false)
  790. itemLua.rewardsRight.received:SetActive(false)
  791. end
  792. itemLua.activity:SetActive(false)
  793. --直接根据等级判断,小于当前等级的直接拉满,大于当前等级的则为空
  794. if curLv+1 > idx then
  795. itemLua.levelSlider.slider.value = 1
  796. itemLua.activity:SetActive(true)
  797. elseif curLv < idx+1 then
  798. itemLua.levelSlider.slider.value = 0
  799. end
  800. --左侧经验条slider,因遮挡问题,只有经验超出10%,小飞机才会飞到下一级
  801. if curLv == #self.rewardsBaseData:GetShowRewardsData() then
  802. itemLua.airShip:SetActive(false)
  803. else
  804. if curLv+1 == idx and curExp/self.curLvData.cfgData.Exp > 0.15 then
  805. itemLua.airShip:SetActive(true)
  806. --LogError('aaacc'..curExp.."aac"..self.curLvData.cfgData.Exp)
  807. itemLua.levelSlider.slider.value = curExp/self.curLvData.cfgData.Exp
  808. self.isShowAirShip = true
  809. else
  810. if curLv == idx and not self.isShowAirShip then
  811. itemLua.airShip:SetActive(true)
  812. --itemLua.levelSlider.slider.value = self.controller:GetShowRewardsCurExp()/self.curLvData.cfgData.Exp
  813. else
  814. itemLua.airShip:SetActive(false)
  815. end
  816. end
  817. end
  818. end
  819. end
  820. end
  821. function UIRuneShopView:RefreshBigRewardsFloatTips(gridView)
  822. --通过content高度计算当前处于哪个位置
  823. local py = self.rewardsBoxItemLua.scrollView.content.transform.localPosition.y
  824. local mid = #self.rewardsBaseData:GetShowRewardsData() - self:Toint(py/240)
  825. --下方的大奖小图标
  826. local minid = self.controller:GetShowReardsNearMinCashReward(mid -3)
  827. if minid then
  828. self.rewardsBoxItemLua.btnGotoDown:SetActive(true)
  829. local logicData ={}
  830. local rdata=self.controller:GetShowRewardsDataByIdx(minid)
  831. if rdata.cfgData.RewardSign == 1 then
  832. logicData = {cfgId = rdata.cfgData.Reward[1][1],num = rdata.cfgData.Reward[1][2] , targetid = #self.controller:GetShowRewardsData()-minid}
  833. elseif rdata.cfgData.RewardSign == 2 then
  834. logicData = {cfgId = rdata.cfgData.CashReward[1][1],num = rdata.cfgData.CashReward[1][2] , targetid = #self.controller:GetShowRewardsData()-minid}
  835. end
  836. CommonUtil.UpdateItemPrefab(self, self.rewardsBoxItemLua.btnGotoDown.iconSmallItem, logicData, Enum.ItemIEnterType.Bag, self, self.JumpToTarget)
  837. else
  838. self.rewardsBoxItemLua.btnGotoDown:SetActive(false)
  839. end
  840. --上方的大奖小图标
  841. local maxid = self.controller:GetShowReardsNearMaxCashReward(mid +3)
  842. if maxid then
  843. self.rewardsBoxItemLua.btnGotoUp:SetActive(true)
  844. local logicData ={}
  845. local rdata=self.controller:GetShowRewardsDataByIdx(maxid)
  846. if rdata.cfgData.RewardSign == 1 then
  847. logicData = {cfgId = rdata.cfgData.Reward[1][1],num = rdata.cfgData.Reward[1][2] , targetid = #self.controller:GetShowRewardsData()-maxid}
  848. elseif rdata.cfgData.RewardSign == 2 then
  849. logicData = {cfgId = rdata.cfgData.CashReward[1][1],num = rdata.cfgData.CashReward[1][2] , targetid = #self.controller:GetShowRewardsData()-maxid}
  850. end
  851. CommonUtil.UpdateItemPrefab(self, self.rewardsBoxItemLua.btnGotoUp.iconSmallItem, logicData, Enum.ItemIEnterType.Bag, self, self.JumpToTarget)
  852. else
  853. self.rewardsBoxItemLua.btnGotoUp:SetActive(false)
  854. end
  855. end
  856. function UIRuneShopView:Toint(n)
  857. local s = tostring(n)
  858. local i,j = s:find('%.')
  859. if i then
  860. return tonumber(s:sub(1,i-1))
  861. else
  862. return n
  863. end
  864. end
  865. function UIRuneShopView:GetItemByRowColumnLimited(loopGridView, itemIdx, row, column)
  866. local data = self.controller:GetShowGoodsDataByIdx(itemIdx + 1)
  867. if not data then return nil end
  868. local item = loopGridView:NewListViewItem('RuneShopLimitedItem')
  869. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopLimitedItem', item.gameObject)
  870. if itemLua then
  871. itemLua.itemIcon.image.sprite = nil
  872. itemLua.itemIcon.image.enabled = false
  873. local cfgData = data.cfgData
  874. if cfgData then
  875. CommonUtil.LoadIcon(self, cfgData.Banner, function(sprite)
  876. if sprite then
  877. itemLua.itemIcon.image.sprite = sprite
  878. itemLua.itemIcon.image.enabled = true
  879. end
  880. end, itemLua, 'ItemIcon')
  881. end
  882. if data:HasEndTime() then
  883. local timerStr = data:CalculateLimitTime()
  884. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  885. itemLua.timerLab:SetActive(true)
  886. self:StartRefreshTimer(itemLua, data)
  887. else
  888. self:StopRefreshTimer(itemLua)
  889. itemLua.timerLab:SetActive(false)
  890. end
  891. local price = data:GetPrice()
  892. if price <= 0 then
  893. itemLua.presentPrice.number.text.text = string.formatbykey('Free')
  894. else
  895. itemLua.presentPrice.number.text.text = tostring(price)
  896. end
  897. if data:IsSoldout() then
  898. itemLua.soldout:SetActive(true)
  899. itemLua.button.onClick:RemoveAllListeners()
  900. itemLua.presentPrice.button.onClick:RemoveAllListeners()
  901. else
  902. itemLua.soldout:SetActive(false)
  903. self.uiBase:AddButtonUniqueEventListener(itemLua.button, self, self.OnClickLimitedItem, data:GetId(), itemIdx)
  904. self.uiBase:AddButtonUniqueEventListener(itemLua.presentPrice.button, self, self.OnClickLimitedPrice, data:GetId(), itemIdx)
  905. end
  906. itemLua.redPoint:SetActive(ManagerContainer.RedPointMgr.RSLimitGiftRPCtr:GetRedPointStatusById(data:GetId()))
  907. end
  908. return item
  909. end
  910. function UIRuneShopView:GetItemByRowColumnRewards(loopGridView, itemIdx, row, column)
  911. --通用等级奖励
  912. local item
  913. if itemIdx == 0 then
  914. item = loopGridView:NewListViewItem('CloudTop')
  915. local itemEndLua = CommonUtil.BindGridViewItem2Lua(self, 'CloudTop', item.gameObject)
  916. self:UpdateRewardsItem(itemEndLua , itemIdx , data ,true)
  917. else
  918. item = loopGridView:NewListViewItem('RuneShopRewardsItem')
  919. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'RuneShopRewardsItem', item.gameObject)
  920. local data
  921. local showGoodsDatas = self.controller:GetShowRewardsData()
  922. local length = (showGoodsDatas and #showGoodsDatas or 0)
  923. if itemIdx-1 < length then
  924. data = self.controller:GetShowRewardsDataByIdx(length-(itemIdx-1))
  925. end
  926. self:UpdateRewardsItem(itemLua , length-(itemIdx-1) , data)
  927. end
  928. return item
  929. end
  930. function UIRuneShopView:RefreshCurrenyItem(itemLua, itemCfgId, itemNum, ignoreIcon)
  931. if not itemCfgId or not itemNum then
  932. itemLua:SetActive(false)
  933. return
  934. end
  935. itemLua.number.text.text = CommonUtil.FormatNumber(itemNum)
  936. itemLua:SetActive(true)
  937. if ignoreIcon then return end
  938. itemLua.icon.image.sprite = nil
  939. itemLua.icon.image.enabled = false
  940. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemCfgId)
  941. if itemCfgData then
  942. CommonUtil.LoadIcon(self, itemCfgData.MiniIcon, function(sprite)
  943. if sprite then
  944. itemLua.icon.image.sprite = sprite
  945. itemLua.icon.image.enabled = true
  946. end
  947. end)
  948. end
  949. end
  950. function UIRuneShopView:StartRefreshTimer(itemLua, goodsData)
  951. local timer = self.refreshTimer
  952. if not timer then
  953. timer = Timer.New(slot(self.RefreshTimer, self), 1, -1)
  954. self.refreshTimer = timer
  955. end
  956. local updateItemMap = timer.updateItemMap
  957. if not updateItemMap then
  958. updateItemMap = {}
  959. timer.updateItemMap = updateItemMap
  960. end
  961. updateItemMap[itemLua] = goodsData
  962. if not timer.running then
  963. timer:Start()
  964. end
  965. end
  966. function UIRuneShopView:StopRefreshTimer(itemLua)
  967. local timer = self.refreshTimer
  968. if timer then
  969. local updateItemMap = timer.updateItemMap
  970. if updateItemMap then
  971. updateItemMap[itemLua] = nil
  972. end
  973. if not updateItemMap or table_is_empty(updateItemMap) then
  974. timer:Stop()
  975. end
  976. end
  977. end
  978. function UIRuneShopView:StopAndClearRefreshTimer()
  979. if self.refreshTimer then
  980. self.refreshTimer:Stop()
  981. self.refreshTimer.time = 1
  982. self.refreshTimer.duration = 1
  983. self.refreshTimer.updateItemMap = nil
  984. end
  985. end
  986. function UIRuneShopView:DisposeRefreshTimer()
  987. self:StopAndClearRefreshTimer()
  988. self.refreshTimer = nil
  989. end
  990. function UIRuneShopView:RefreshTimer()
  991. local timer = self.refreshTimer
  992. if not timer then return end
  993. local updateItemMap = timer.updateItemMap
  994. if not updateItemMap or table_is_empty(updateItemMap) then
  995. timer:Stop()
  996. return
  997. end
  998. local minRemainTime = nil
  999. local runeShopType = self.controller:GetShopType()
  1000. if self.controller.isAirShip then
  1001. local endTime = self.controller:GetRewardsRemainTime()
  1002. if endTime then
  1003. if endTime < 0 then
  1004. endTime = 0
  1005. end
  1006. if endTime <= 0 then
  1007. timer.updateItemMap = nil
  1008. if self.controller:ChangeShopType(Enum.RuneShopType.MonthCard) then
  1009. self:RefreshToggleGroupView()
  1010. self:RefreshShopView(true)
  1011. end
  1012. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIRewardsBuyTips) then
  1013. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIRewardsBuyTips)
  1014. end
  1015. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.RuneShopRewards, false)
  1016. ManagerContainer.CfgMgr.RuneShopExploreRewardCfg =nil
  1017. ManagerContainer.CfgMgr.RuneShopRoundMap = nil
  1018. self.rewardsToggle:SetActive(false)
  1019. end
  1020. self.rewardsBoxItemLua.timeBox:SetActive(true)
  1021. self.rewardsBoxItemLua.timeBox.textTime.text.text = string.formatbykey('AirshipTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  1022. else
  1023. self.rewardsBoxItemLua.timeBox:SetActive(false)
  1024. timer.updateItemMap = nil
  1025. end
  1026. if endTime and endTime > 0 then
  1027. if not minRemainTime or minRemainTime > endTime then
  1028. minRemainTime = endTime
  1029. end
  1030. end
  1031. return
  1032. end
  1033. if runeShopType == Enum.RuneShopType.MonthCard then
  1034. for itemLua, goodsData in pairs(updateItemMap) do
  1035. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  1036. if not outTime then
  1037. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth2', timerStr)
  1038. itemLua.active:SetActive(true)
  1039. itemLua.unActive:SetActive(false)
  1040. else
  1041. updateItemMap[itemLua] = nil
  1042. itemLua.textDsc.text.text = string.formatbykey('DscClubMonth1')
  1043. itemLua.active:SetActive(false)
  1044. itemLua.unActive:SetActive(true)
  1045. end
  1046. if remainTime and remainTime > 0 then
  1047. if not minRemainTime or minRemainTime > remainTime then
  1048. minRemainTime = remainTime
  1049. end
  1050. end
  1051. end
  1052. if minRemainTime and minRemainTime > 0 then
  1053. minRemainTime = 1
  1054. end
  1055. elseif runeShopType == Enum.RuneShopType.Gifts then
  1056. local endTime = self.controller:GetRemainTime()
  1057. if endTime then
  1058. if endTime < 0 then endTime = 0 end
  1059. if endTime <= 0 then
  1060. timer.updateItemMap = nil
  1061. end
  1062. self.timeBox:SetActive(true)
  1063. self.timeBox.textTime.text.text = string.formatbykey('RuneShopRefreshTime', DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false))
  1064. else
  1065. self.timeBox:SetActive(false)
  1066. timer.updateItemMap = nil
  1067. end
  1068. if endTime and endTime > 0 then
  1069. if not minRemainTime or minRemainTime > endTime then
  1070. minRemainTime = endTime
  1071. end
  1072. end
  1073. elseif runeShopType == Enum.RuneShopType.LimitTime then
  1074. for itemLua, goodsData in pairs(updateItemMap) do
  1075. if goodsData:HasEndTime() then
  1076. local timerStr, outTime, remainTime = goodsData:CalculateLimitTime()
  1077. if outTime then
  1078. updateItemMap[itemLua] = nil
  1079. end
  1080. itemLua.timerLab.text.text.text = string.formatbykey('RuneShopLimitTime', timerStr)
  1081. itemLua.timerLab:SetActive(true)
  1082. if remainTime and remainTime > 0 then
  1083. if not minRemainTime or minRemainTime > remainTime then
  1084. minRemainTime = remainTime
  1085. end
  1086. end
  1087. else
  1088. updateItemMap[itemLua] = nil
  1089. itemLua.timerLab:SetActive(false)
  1090. end
  1091. if minRemainTime and minRemainTime > 0 then
  1092. minRemainTime = 1
  1093. end
  1094. end
  1095. end
  1096. if not minRemainTime or minRemainTime <= 0 then
  1097. self:StopRefreshTimer()
  1098. else
  1099. -- 降低刷新频率
  1100. if self.refreshTimer then
  1101. local validTime = nil
  1102. if minRemainTime >= 86400 then
  1103. validTime = minRemainTime % 3600
  1104. if validTime == 0 then validTime = 3600 end
  1105. elseif minRemainTime >= 3600 then
  1106. validTime = minRemainTime % 60
  1107. if validTime == 0 then validTime = 60 end
  1108. else
  1109. validTime = 1
  1110. end
  1111. if validTime then
  1112. self.refreshTimer.duration = validTime
  1113. else
  1114. self:StopRefreshTimer()
  1115. end
  1116. end
  1117. end
  1118. end
  1119. return UIRuneShopView