源战役客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

278 řádky
8.6 KiB

před 1 měsícem
  1. --通用奖励结算界面
  2. ComAwardResultView = ComAwardResultView or BaseClass(BaseView)
  3. local ComAwardResultView = ComAwardResultView
  4. function ComAwardResultView:__init()
  5. self.base_file = "uiComponent"
  6. self.layout_file = "ComAwardResultView"
  7. self.layer_name = "Top"
  8. self.destroy_imm = true
  9. self.use_background = true
  10. self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  11. self.change_scene_close = true
  12. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  13. self.need_show_money = false --是否要显示顶部的金钱栏
  14. self.model = GuildModel:getInstance()
  15. self.base_height = 155
  16. self.delay_time = 15
  17. self.col_num = 5 -- 奖励展示的行展示数
  18. self.max_num = 25
  19. self.item_list = {}
  20. self.is_set_zdepth = true --是否设置z深度,当需要盖住下层的UI界面上的模型时,要设true
  21. self.jump_close = true --用于某些界面跳转了之后就需要关掉界面
  22. ItemUseModel:getInstance():HideItemUseView( )
  23. self.load_callback = function ()
  24. self:LoadSuccess()
  25. self:AddEvent()
  26. end
  27. self.open_callback = function ( )
  28. self:OpenSuccess()
  29. end
  30. self.destroy_callback = function ( )
  31. self:DestroySuccess()
  32. end
  33. end
  34. function ComAwardResultView:DestroySuccess()
  35. if self.pos_id then
  36. TweenLite.Stop(self.pos_id)
  37. self.pos_id = nil
  38. end
  39. if self.award_timer_id then
  40. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  41. self.award_timer_id = nil
  42. end
  43. if self.timer_id then
  44. GlobalTimerQuest:CancelQuest(self.timer_id)
  45. self.timer_id = nil
  46. end
  47. for i,item in pairs(self.item_list) do
  48. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, item)
  49. end
  50. self.item_list = {}
  51. ItemUseModel:getInstance():ShowItemUseView( )
  52. end
  53. function ComAwardResultView:LoadSuccess()
  54. local nodes = {
  55. "bg/titlebg:img", "bg/scroll_mask:obj",
  56. "bg:img", "bg/time_text:tmp", "bg/award_con:obj",
  57. "mask_bg:obj","bg/close_btn:obj",
  58. "bg/award_scroll:obj", "bg/award_scroll/Viewport/award_scroll_con",
  59. }
  60. self:GetChildren(nodes)
  61. lua_resM:setOutsideImageSprite(self, self.bg_img, GameResPath.GetCommonImage("com_award_result_view_new_bg"),false)
  62. lua_resM:setOutsideImageSprite(self, self.titlebg_img, GameResPath.GetCommonImage("com_award_result_view_new_title"),false)
  63. -- local function onDelay()
  64. -- local function end_call_func( ... )
  65. -- if self.effect_forever then
  66. -- self:AddUIEffect("getgoods_02",self.effect_forever, self.layer_name, nil, 1, true,nil,nil,nil)
  67. -- end
  68. -- end
  69. -- self:AddUIEffect("getgoods_01",self.effect, self.layer_name, nil, 1, false,nil,nil,end_call_func)
  70. -- end
  71. -- self.slow_effect_id = GlobalTimerQuest:AddDelayQuest(onDelay, 0.1)
  72. if self.need_refreshData then
  73. self:UpdateView( )
  74. end
  75. end
  76. function ComAwardResultView:AddEvent()
  77. local function onBtnClickHandler(target,x,y)
  78. if target == self.mask_bg_obj or self.close_btn_obj then--关闭
  79. self:BtnCloseEvt()
  80. end
  81. end
  82. AddClickEvent(self.mask_bg_obj,onBtnClickHandler)
  83. AddClickEvent(self.close_btn_obj,onBtnClickHandler)
  84. end
  85. --data.delay_time--关闭时间
  86. --data.title_res--标题资源
  87. --data.title_ab_name--标题资源ab包路径
  88. --data.award = {kind,type_id,goods_num,goods_vo}
  89. --data.col_num = 6 -- 每行展示的个数
  90. function ComAwardResultView:Open( data )
  91. data.col_num = 5--限定5了 不能改
  92. self.data = data
  93. self.delay_time = self.data and self.data.delay_time or self.delay_time
  94. BaseView.Open(self)
  95. end
  96. function ComAwardResultView:OpenSuccess( )
  97. self:UpdateView()
  98. end
  99. function ComAwardResultView:UpdateView( data )
  100. self.data = data or self.data
  101. if self.is_loaded then
  102. self.need_refreshData = false
  103. else
  104. self.need_refreshData = true
  105. return
  106. end
  107. if not self.data then return end
  108. if data then--有新数据 就重置
  109. self:Reset()
  110. end
  111. self:UpdateItemList()
  112. -- self:UpdateTime()
  113. if self.data.title_res then
  114. lua_resM:setOutsideImageSprite(self, self.titlebg_img, GameResPath.GetCommonImage(self.data.title_res),false)
  115. end
  116. end
  117. function ComAwardResultView:Reset( )
  118. if self.pos_id then
  119. TweenLite.Stop(self.pos_id)
  120. self.pos_id = nil
  121. end
  122. if self.award_timer_id then
  123. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  124. self.award_timer_id = nil
  125. end
  126. if self.timer_id then
  127. GlobalTimerQuest:CancelQuest(self.timer_id)
  128. self.timer_id = nil
  129. end
  130. if self.data then
  131. self.data.col_num = 5--限定5了 不能改
  132. self.delay_time = self.data.delay_time or self.delay_time
  133. end
  134. SetSizeDeltaY(self.award_scroll, self.base_height)
  135. end
  136. function ComAwardResultView:BtnCloseEvt()--关闭按钮回调
  137. if self.data and self.data.close_callback then
  138. self.data.close_callback()
  139. end
  140. self:Close()
  141. end
  142. function ComAwardResultView:UpdateItemList( )
  143. for k,v in pairs(self.item_list) do
  144. v:SetVisible(false,nil,true)
  145. end
  146. self.col_num = self.data.col_num or self.col_num
  147. local item_list = self.data.award
  148. if not item_list or TableSize(item_list) == 0 then return end
  149. local len = #item_list
  150. self.parent_con = self.award_scroll_con
  151. self.award_scroll_obj:SetActive(true)
  152. --如果比最大高度要高 那就只能滚动了
  153. local offer_x = 4
  154. local offer_y = 0
  155. local space_x = 8
  156. local space_y = 8
  157. local item_height = 78
  158. if len > self.max_num then
  159. self.parent_con = self.award_scroll_con
  160. self.award_con_obj:SetActive(false)
  161. SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(self.max_num/self.col_num))
  162. end
  163. local max_height = (item_height + space_y) * (math.ceil(self.max_num/self.col_num)-1)--最大高度限制5行
  164. local x = 0
  165. local y = 0
  166. for i, v in ipairs(item_list) do
  167. local item = self.item_list[i]
  168. if item == nil then
  169. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.parent_con)
  170. item:SetItemSize(78,78)
  171. item:SetGoodsVo(v[4])
  172. self.item_list[i] = item
  173. end
  174. local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(v[1], v[2])
  175. local goodVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(goods_Id)
  176. local stren_data = nil
  177. if v[4] then
  178. stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(v[4])
  179. stren_data.equip_key = "EquipView"
  180. end
  181. if not v.is_mul then--副本多倍
  182. if v.is_rare == 2 then
  183. item:SetNumLimitVisible(true,12)
  184. elseif v.is_rare == 1 then
  185. item:SetNumLimitVisible(true,13)
  186. end
  187. else
  188. item:SetNumLimitVisible(v.is_mul ~= nil ,15)
  189. end
  190. if goodVo then
  191. item:SetData(goods_Id, v[3], goodVo.color, stren_data, lock,true,nil)
  192. else
  193. -- error("没有找到物品信息 "..v.typeId)
  194. end
  195. item:SetVisible(false,nil,true)
  196. end
  197. if not self.data.not_show_anim then
  198. self.scroll_mask_obj:SetActive(true)
  199. local index = 0
  200. local function countDown()
  201. index = index + 1
  202. if len >= index then
  203. if self.item_list[index] then
  204. self.item_list[index]:SetVisible(true,nil,true)
  205. local height = (item_height + space_y) * (math.ceil(index/self.col_num) - 1)
  206. height = height >= max_height and max_height or height
  207. SetSizeDeltaY(self.bg, self.base_height + height)
  208. if index > self.max_num then
  209. SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(self.max_num/self.col_num))
  210. else
  211. SetSizeDeltaY(self.award_scroll, (item_height + space_y) * math.ceil(index/self.col_num))
  212. end
  213. SetSizeDeltaY(self.parent_con, (item_height + space_y) * math.ceil(index/self.col_num))
  214. --如果大于了就得滚动
  215. if index >= self.max_num then
  216. local pos_y = (math.ceil((index - self.max_num) / self.col_num) )* (item_height + space_y)
  217. if self.pos_id then
  218. TweenLite.Stop(self.pos_id)
  219. self.pos_id = nil
  220. end
  221. self.pos_id = TweenLite.to(self, self.parent_con, TweenLite.UiAnimationType.ANCHORED_POSY, pos_y, 0.15, callback)
  222. end
  223. end
  224. else
  225. if self.award_timer_id then
  226. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  227. self.award_timer_id = nil
  228. end
  229. self:UpdateTime()
  230. end
  231. end
  232. if not self.award_timer_id then
  233. self.award_timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,0.15)
  234. end
  235. else
  236. if self.award_timer_id then
  237. GlobalTimerQuest:CancelQuest(self.award_timer_id)
  238. self.award_timer_id = nil
  239. end
  240. for k,v in pairs(self.item_list) do
  241. v:SetVisible(true,nil,true)
  242. end
  243. end
  244. end
  245. function ComAwardResultView:UpdateTime( )
  246. local time = self.delay_time
  247. local function countDown()
  248. if self._use_delete_method then return end
  249. time = time - 1
  250. if time > 0 then
  251. self.time_text_tmp.text = (self.data.time_des or "点击任意处继续")..HtmlColorTxt(""..time.."s)", "#31e056")
  252. else
  253. self:Close()
  254. end
  255. end
  256. countDown()
  257. if not self.timer_id then
  258. self.timer_id = GlobalTimerQuest:AddPeriodQuest(countDown,1)
  259. end
  260. end