源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.9 KiB

  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 藏宝图 限时商店界面
  4. -- *>
  5. TreasureMapShopView = TreasureMapShopView or BaseClass(BaseView)
  6. local TreasureMapShopView = TreasureMapShopView
  7. function TreasureMapShopView:__init()
  8. self.base_file = "treasureMap"
  9. self.layout_file = "TreasureMapShopView"
  10. self.layer_name = "UI"
  11. self.destroy_imm = true
  12. self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
  13. self.hide_maincancas = false --全屏界面需要隐藏主UI
  14. self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
  15. self.model = TreasureMapModel:getInstance()
  16. self.has_receive_free_goods = false -- 是否已经领取了免费商品
  17. self.auto_close_time = 30
  18. self.load_callback = function ()
  19. self:LoadSuccess()
  20. self:AddEvent()
  21. end
  22. self.open_callback = function ( )
  23. self:UpdateView()
  24. self:AutoCloseTimer()
  25. end
  26. self.destroy_callback = function ( )
  27. self:DestroySuccess()
  28. end
  29. end
  30. function TreasureMapShopView:Open(vo)
  31. self.vo = vo
  32. BaseView.Open(self)
  33. end
  34. function TreasureMapShopView:LoadSuccess()
  35. local nodes = {
  36. "win_bg:raw", "close_btn:obj",
  37. "item_scroll", "item_scroll/Viewport/item_con",
  38. "auto_close:tmp",
  39. }
  40. self:GetChildren(nodes)
  41. lua_resM:setOutsideRawImage(self, self.win_bg_raw, GameResPath.GetViewBigBg("tm_shop_bg"))
  42. end
  43. function TreasureMapShopView:AddEvent()
  44. local function click_event(target)
  45. if target == self.close_btn_obj then
  46. if not self.has_receive_free_goods then -- 如果未领取免费商品,关闭界面时需要自动领取
  47. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42412)
  48. end
  49. self:Close()
  50. end
  51. end
  52. AddClickEvent(self.close_btn_obj, click_event)
  53. local function updateFreeStatus(status)
  54. self.has_receive_free_goods = status
  55. end
  56. self:BindEvent(self.model, TreasureMapConst.UPDATE_SHOP_FREE_RECEIVE_STATUS, updateFreeStatus)
  57. end
  58. function TreasureMapShopView:UpdateView()
  59. -- 加载配置
  60. local free_cfg = Config.Treasureeventrewards[tonumber(self.vo.free_reward)]
  61. local paid_cfg = Config.Treasuremapdoor[tonumber(self.vo.limit_reward)]
  62. -- 整合奖励配置
  63. local data = {}
  64. if free_cfg then
  65. local rewards = stringtotable(free_cfg.rewards)
  66. for k, v in ipairs(rewards) do
  67. data[#data+1] = {reward = v, is_free = true}
  68. end
  69. end
  70. if paid_cfg then
  71. local rewards = stringtotable(paid_cfg.rewards)
  72. for k, v in ipairs(rewards) do
  73. data[#data+1] = {reward = v, is_free = false}
  74. end
  75. end
  76. self.shop_item_creator = self.shop_item_creator or self:AddUIComponent(UI.ItemListCreator)
  77. local info = {
  78. data_list = data,
  79. item_con = self.item_con,
  80. scroll_view = self.item_scroll,
  81. item_class = TreasureMapShopItem,
  82. item_width = 171,
  83. item_height = 240,
  84. start_x = 6.5,
  85. start_y = -4,
  86. space_x = 29,
  87. space_y = 2,
  88. create_frequency = 0.01,
  89. alignment = UnityEngine.TextAnchor.UpperLeft,
  90. on_update_item = function(item, i, v)
  91. item:SetData(v, self.vo.expire_time, self.vo.limit_reward)
  92. end,
  93. }
  94. self.shop_item_creator:UpdateItems(info)
  95. end
  96. function TreasureMapShopView:AutoCloseTimer( )
  97. local end_time = TimeUtil:getServerTime() + self.auto_close_time
  98. local function auto_close_time_func()
  99. local left_time = end_time - TimeUtil:getServerTime()
  100. if left_time > 0 then
  101. self.auto_close_tmp.text = string.format("<color=%s>%s</color> 秒后自动关闭", ColorUtil.GREEN_DARK, left_time)
  102. else
  103. if not self.has_receive_free_goods then -- 如果未领取免费商品,关闭界面时需要自动领取
  104. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42412)
  105. end
  106. self:Close()
  107. end
  108. end
  109. auto_close_time_func()
  110. self:ClearAutoCloseTimer()
  111. self.auto_close_time_func_id = GlobalTimerQuest:AddPeriodQuest(auto_close_time_func, 0.5, -1)
  112. end
  113. function TreasureMapShopView:ClearAutoCloseTimer( )
  114. if self.auto_close_time_func_id then
  115. GlobalTimerQuest:CancelQuest(self.auto_close_time_func_id)
  116. self.auto_close_time_func_id = nil
  117. end
  118. end
  119. function TreasureMapShopView:DestroySuccess( )
  120. if not self.has_receive_free_goods then -- 如果未领取免费商品,关闭界面时需要自动领取
  121. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42412)
  122. end
  123. self:ClearAutoCloseTimer()
  124. self.model:SetTreasureMapShopRestNumData(nil)
  125. -- 关闭界面后,请求最新的限时商城数据
  126. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42414)
  127. self.model._check_tm_tips = TreasureMapConst.Normal
  128. self.model:CheckTreasureTipUseViewOpen()
  129. end