源战役客户端
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.

239 lines
9.7 KiB

  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 藏宝图 玩法介绍界面
  4. -- *>
  5. TreasureMapDescView = TreasureMapDescView or BaseClass(BaseView)
  6. local TreasureMapDescView = TreasureMapDescView
  7. local SetAnchoredPositionX = SetAnchoredPositionX
  8. function TreasureMapDescView:__init()
  9. self.base_file = "treasureMap"
  10. self.layout_file = "TreasureMapDescView"
  11. self.layer_name = "UI"
  12. self.destroy_imm = true
  13. self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
  14. self.hide_maincancas = false --全屏界面需要隐藏主UI
  15. self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
  16. self:AddPreLoadList("treasureMap", {"TreasureMapDescScrollItem"})
  17. self.model = TreasureMapModel:getInstance()
  18. self.load_callback = function ()
  19. self:LoadSuccess()
  20. self:AddEvent()
  21. end
  22. self.open_callback = function ( )
  23. self:UpdateView()
  24. end
  25. self.destroy_callback = function ( )
  26. self:DestroySuccess()
  27. end
  28. end
  29. function TreasureMapDescView:Open( )
  30. BaseView.Open(self)
  31. end
  32. function TreasureMapDescView:LoadSuccess()
  33. local nodes = {
  34. "bg_mask",
  35. -- 类型1相关
  36. "bg_mask/bg_type1:raw",
  37. "bg_mask/bg_type1/desc_scroll_1",
  38. "bg_mask/bg_type1/desc_scroll_1/Viewport/desc_con_1",
  39. "bg_mask/bg_type1/item_scroll_1",
  40. "bg_mask/bg_type1/item_scroll_1/Viewport/item_con_1",
  41. "bg_mask/bg_type1/reward_btn1:obj", "bg_mask/bg_type1/tm_mys_desc_btn:obj",
  42. -- 类型2相关
  43. "bg_mask/bg_type2:raw",
  44. "bg_mask/bg_type2/desc_scroll_2",
  45. "bg_mask/bg_type2/desc_scroll_2/Viewport/desc_con_2",
  46. "bg_mask/bg_type2/item_scroll_2",
  47. "bg_mask/bg_type2/item_scroll_2/Viewport/item_con_2",
  48. "bg_mask/bg_type2/reward_btn2:obj", "bg_mask/bg_type2/feed_back_btn:obj", "bg_mask/bg_type2/feedback_red:obj",
  49. "bg_mask/bg_type2/feed_back_tip_bg:obj",
  50. "bg_mask/bg_type2/feed_back_tip_bg/feed_back_tip_lb:tmp",
  51. -- 其他
  52. "bg_roll:raw",
  53. "close_btn:obj",
  54. }
  55. self:GetChildren(nodes)
  56. -- 暂时屏蔽
  57. self.feed_back_tip_bg_obj:SetActive(false)
  58. lua_resM:setOutsideRawImage(self, self.bg_roll_raw, GameResPath.GetViewBigBg("tm_desc_bg0"))
  59. lua_resM:setOutsideRawImage(self, self.bg_type1_raw, GameResPath.GetViewBigBg("tm_desc_bg1"))
  60. lua_resM:setOutsideRawImage(self, self.bg_type2_raw, GameResPath.GetViewBigBg("tm_desc_bg2"))
  61. end
  62. function TreasureMapDescView:AddEvent()
  63. local function click_event(target)
  64. if target == self.close_btn_obj then
  65. self:Close()
  66. elseif target == self.reward_btn1_obj then -- 奖励预览(普通)
  67. self.model:Fire(TreasureMapConst.OPEN_REWARD_PERVIEW_VIEW, true, 1)
  68. elseif target == self.reward_btn2_obj then -- 奖励预览(高级)
  69. self.model:Fire(TreasureMapConst.OPEN_REWARD_PERVIEW_VIEW, true, 2)
  70. elseif target == self.tm_mys_desc_btn_obj then -- 秘闻说明
  71. GlobalEventSystem:Fire(EventName.OPEN_INSTRUCTION_VIEW, 42400)
  72. elseif target == self.feed_back_btn_obj then -- 遗宝回馈界面
  73. self.model:Fire(TreasureMapConst.OPEN_FEEDBACK_VIEW, true)
  74. end
  75. end
  76. AddClickEvent(self.close_btn_obj, click_event)
  77. AddClickEvent(self.reward_btn1_obj, click_event)
  78. AddClickEvent(self.reward_btn2_obj, click_event)
  79. AddClickEvent(self.tm_mys_desc_btn_obj, click_event)
  80. AddClickEvent(self.feed_back_btn_obj, click_event)
  81. local function updateFeedbackRed(red_type)
  82. if red_type and red_type == TreasureMapConst.RedType.MonthReward then
  83. self:UpdateFeedbackRed()
  84. end
  85. end
  86. self:BindEvent(self.model, TreasureMapConst.UPDATE_TREASUREMAP_RED, updateFeedbackRed)
  87. end
  88. function TreasureMapDescView:UpdateView()
  89. self:ShowOpenAnim()
  90. self:UpdateTypeOneDesc()
  91. self:UpdateTypeTwoDesc()
  92. self:UpdateFeedbackRed()
  93. end
  94. -- 播放打开动画
  95. function TreasureMapDescView:ShowOpenAnim( )
  96. SetAnchoredPositionX(self.bg_roll, 0)
  97. SetAnchoredPositionX(self.bg_mask, 522)
  98. SetAnchoredPositionX(self.bg_type1, -906)
  99. SetAnchoredPositionX(self.bg_type2, -906)
  100. -- 通用等待
  101. local show_delay = cc.DelayTime.New(0.3)
  102. -- 主卷轴动画
  103. local roll_action_func = function(percent)
  104. SetAnchoredPositionX(self.bg_roll, -415 * percent)
  105. end
  106. local roll_action = cc.Sequence.New(show_delay, cc.CustomUpdate.New(0.3, roll_action_func))
  107. cc.ActionManager:getInstance():addAction(roll_action, self.bg_roll)
  108. -- 蒙版动画
  109. local mask_action_func = function(percent)
  110. SetAnchoredPositionX(self.bg_mask, 71 + 451 * (1 - percent))
  111. end
  112. local mask_action = cc.Sequence.New(show_delay, cc.CustomUpdate.New(0.3, mask_action_func))
  113. cc.ActionManager:getInstance():addAction(mask_action, self.bg_mask)
  114. -- 两个卷轴
  115. local type_action_func = function(percent)
  116. SetAnchoredPositionX(self.bg_type1, -906 * (1 - percent))
  117. SetAnchoredPositionX(self.bg_type2, -906 * (1 - percent))
  118. end
  119. local type_action = cc.Sequence.New(show_delay, cc.CustomUpdate.New(0.3, type_action_func))
  120. cc.ActionManager:getInstance():addAction(type_action, self.bg_type1)
  121. end
  122. -- 更新类型1描述说明
  123. function TreasureMapDescView:UpdateTypeOneDesc( )
  124. -- 加载描述内容
  125. self.type1_item_list = self.type1_item_list or {}
  126. local desc_data = {}
  127. desc_data[#desc_data+1] = {title = "来源:"}
  128. desc_data[#desc_data+1] = {
  129. desc1 = "1.常用商店购买", click_callback_desc = "<u>去购买</u>", click_callback = function()
  130. OpenFun.Open(153, 5)
  131. end,
  132. }
  133. desc_data[#desc_data+1] = {
  134. desc1 = "2.每日活跃产出", click_callback_desc = "<u>提升活跃</u>", click_callback = function()
  135. OpenFun.Open(157, 0)
  136. end,
  137. }
  138. desc_data[#desc_data+1] = {desc1 = "3.运营活动产出", height_offset = 10,}
  139. desc_data[#desc_data+1] = {title = "使用说明:"}
  140. local max_num = self.model:GetTreasureMapKvCfg("map_times_max").value
  141. desc_data[#desc_data+1] = {desc2 = string.format("在背包点击后会自动寻路至宝藏地点,寻宝过程中可能会出现<color=#fdffc2>神秘老人</color>、<color=#fdffc2>珍品之门</color>和<color=#fdffc2>宝藏看守者</color>等<color=#fdffc2>藏宝秘闻</color>事件\n每日使用上限%s张",
  142. max_num)}
  143. self:UpdateDescContent(self.type1_item_list, desc_data, self.desc_con_1)
  144. -- 加载奖励
  145. local reward_data = stringtotable(self.model:GetTreasureMapKvCfg("common_map_show").value)
  146. self:UpdateRewardItems("type1_reward_list", reward_data, self.item_scroll_1, self.item_con_1)
  147. end
  148. -- 更新类型2描述说明
  149. function TreasureMapDescView:UpdateTypeTwoDesc( )
  150. -- 加载描述内容
  151. self.type2_item_list = self.type2_item_list or {}
  152. local desc_data = {}
  153. desc_data[#desc_data+1] = {title = "来源:"}
  154. desc_data[#desc_data+1] = {
  155. desc1 = "1.常用商店购买", click_callback_desc = "<u>去购买</u>", click_callback = function()
  156. OpenFun.Open(153, 5)
  157. end,
  158. }
  159. desc_data[#desc_data+1] = {desc1 = "2.运营活动产出", height_offset = 10,}
  160. desc_data[#desc_data+1] = {title = "使用说明:"}
  161. local max_num = self.model:GetTreasureMapKvCfg("map_times_max").value
  162. desc_data[#desc_data+1] = {desc2 = string.format("在背包点击后会自动寻路至含有<color=#fdffc2>高级珍品</color>的宝藏地点,寻宝一定次数可获得<color=#fdffc2>遗迹的馈赠</color>,每日寻宝一定次数可触发大奖概率UP\n每日使用上限%s张",
  163. max_num)}
  164. self:UpdateDescContent(self.type2_item_list, desc_data, self.desc_con_2)
  165. -- 加载奖励
  166. local reward_data = stringtotable(self.model:GetTreasureMapKvCfg("advanced_map_show").value)
  167. self:UpdateRewardItems("type2_reward_list", reward_data, self.item_scroll_2, self.item_con_2)
  168. end
  169. -- 加载描述内容
  170. function TreasureMapDescView:UpdateDescContent(item_list, data, con)
  171. for k, v in ipairs(item_list) do
  172. v:SetVisible(false)
  173. end
  174. local height = 2
  175. local item
  176. for k, v in ipairs(data) do
  177. item = item_list[k] or TreasureMapDescScrollItem.New(con)
  178. item:SetAnchoredPosition(0, -height)
  179. height = height + item:SetData(v)
  180. end
  181. SetSizeDeltaY(con, height)
  182. end
  183. -- 加载奖励内容
  184. function TreasureMapDescView:UpdateRewardItems(ilc_name, data, scroll, con)
  185. self[ilc_name] = self[ilc_name] or self:AddUIComponent(UI.ItemListCreator)
  186. local info = {
  187. data_list = data,
  188. scroll_view = scroll,
  189. item_con = con,
  190. obj_pool_type = UIObjPool.UIType.AwardItem,
  191. item_width = 48,
  192. item_height = 48,
  193. start_x = 8,
  194. start_y = -5,
  195. space_x = 12,
  196. space_y = 9,
  197. create_frequency = 0.01,
  198. alignment = UnityEngine.TextAnchor.UpperLeft,
  199. on_update_item = function(item, i, v)
  200. item:SetData(v)
  201. item:SetIsFixSize(false)
  202. item:SetItemSize(48, 48)
  203. end,
  204. }
  205. self[ilc_name]:UpdateItems(info)
  206. end
  207. function TreasureMapDescView:UpdateFeedbackRed( )
  208. self.feedback_red_obj:SetActive(self.model:GetTreasureMapRed(TreasureMapConst.RedType.MonthReward))
  209. end
  210. function TreasureMapDescView:DestroySuccess( )
  211. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.bg_roll)
  212. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.bg_mask)
  213. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.bg_type1)
  214. for k, v in pairs(self.type1_item_list) do
  215. v:DeleteMe()
  216. v = nil
  217. end
  218. self.type1_item_list = nil
  219. for k, v in pairs(self.type2_item_list) do
  220. v:DeleteMe()
  221. v = nil
  222. end
  223. self.type2_item_list = nil
  224. end