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

610 lines
24 KiB

  1. -- <*
  2. -- @Author: huangcong
  3. -- @Description: 源能转盘
  4. -- *>
  5. PowerTurnTableView = PowerTurnTableView or BaseClass(BaseView)
  6. local PowerTurnTableView = PowerTurnTableView
  7. function PowerTurnTableView:__init()
  8. self.base_file = "powerTurnTable"
  9. self.layout_file = "PowerTurnTableView"
  10. self.layer_name = "UI"
  11. self.destroy_imm = true
  12. self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
  13. self.change_scene_close = false
  14. self.append_to_ctl_queue = true --添加进入控制队列
  15. self:AddPreLoadList("powerTurnTable", {"PowerTurnTableRecordItem"})
  16. self.model = PowerTurnTableModel:getInstance()
  17. self.base_type = CustomActivityModel.CustomActBaseType.POWER_TURNTABLE
  18. self.sub_type = CustomActivityModel:getInstance():getActMinSubType(self.base_type)
  19. self.record_item_list = {}
  20. self.choose_list = {}
  21. self.choose_index = 0
  22. self.show_goods_num = 10
  23. self.cur_pointer_angle = 0--当前指针旋转角度
  24. self.is_skip_action = self.model.is_skip_turn_table_action--是否跳过抽奖动画
  25. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  26. self.load_callback = function ()
  27. self:LoadSuccess()
  28. self:AddEvent()
  29. end
  30. self.open_callback = function ( )
  31. self:UpdateView()
  32. end
  33. self.destroy_callback = function ( )
  34. self:DestroySuccess()
  35. end
  36. end
  37. function PowerTurnTableView:Hide( )
  38. BaseView.Hide(self)
  39. CustomActivityModel:getInstance():SetGoodsCanFly(true)
  40. end
  41. function PowerTurnTableView:CancelHide( )
  42. BaseView.CancelHide(self)
  43. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  44. end
  45. function PowerTurnTableView:Open(sub_type)
  46. self.sub_type = sub_type or self.sub_type
  47. BaseView.Open(self)
  48. end
  49. function PowerTurnTableView:LoadSuccess()
  50. local nodes = {
  51. "bg:raw","timeText:tmp", "titleText:tmp", "skip_toggle:tog:obj",
  52. "tipText2:tmp", "tipText1:tmp", "curSoreText:tmp","oneBtn/freeText:tmp",
  53. "showImg:img", "numText:tmp", "record_scroll/Viewport/record_con", "record_scroll",
  54. "skip_toggle/Label:tmp", "moneyCon", "btn/btnMax:obj", "btn/btnImg:obj","btn/maxEffect", "scoreBtn/scoreBtnRed:obj",
  55. --表盘
  56. "pointer",
  57. --按钮
  58. "oneBtn:obj", "oneBtn/oneBtnRedDot:obj", "oneBtn/oneBtnTimeText:tmp", "oneBtn/oneBtnText:tmp", "oneBtn/oneBtnGoodsImg:img",
  59. "tenBtn:obj", "tenBtn/tenBtnTimeText:tmp", "tenBtn/tenBtnGoodsImg:img", "tenBtn/tenBtnText:tmp",
  60. "scoreBtn:obj","tipText2/helpBtn:obj", "closeBtn:obj", "scoreBtn/effect", "titleText/probabilityBtn:obj",
  61. }
  62. self:GetChildren(nodes)
  63. self.titleText_tmp.text = "获奖记录"
  64. self.tipText1_tmp.text = "源能值满必得二等奖及以上奖励哦~"
  65. self.tipText2_tmp.text = string.format("每转动1次获得<color=#fdffc2>%s</color>积分",Config.Sourceturntablekv["turn_score"].val)
  66. self.tenBtnText_tmp.text = "转动 10 次"
  67. self.oneBtnText_tmp.text = "转动 1 次"
  68. self.Label_tmp.text = "跳过动画"
  69. self.skip_toggle_tog.isOn = self.is_skip_action
  70. local show_img_res_index = 1
  71. local act_list = CustomActivityModel:getInstance():getActList(self.base_type, self.sub_type)
  72. local is_use_artword = false
  73. if act_list and act_list.condition_list then
  74. for k,v in ipairs(act_list.condition_list) do
  75. if v[1] == "show_bg" then
  76. show_img_res_index = tonumber(v[2])
  77. break
  78. end
  79. end
  80. end
  81. lua_resM:setImageSprite(self, self.showImg_img, "powerTurnTable_asset", "powerTurnTable_show_img"..show_img_res_index)
  82. self.item_list = {}
  83. for i=1,10 do
  84. self.item_list[i] = {}
  85. self.item_list[i].box_trm = self:GetChild("box"..i)
  86. self.item_list[i].award_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_list[i].box_trm)
  87. self.item_list[i].award_item:SetItemSize(78,78)
  88. self.item_list[i].award_item:SetIsAct(true)
  89. self.item_list[i].choose_bg_obj = self:GetChild("light"..i).gameObject
  90. self.item_list[i].tipImg_img = self:GetChild("tipImg"..i):GetComponent("Image")
  91. self.item_list[i].tipImg_obj = self:GetChild("tipImg"..i).gameObject
  92. self.item_list[i].awardNum_tmp = self:GetChild("awardNum"..i):GetComponent(typeof(TMPro.TextMeshProUGUI))
  93. end
  94. lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("powerTurnTable_bg"), false)
  95. self.model:Fire(PowerTurnTableModel.REQUEST_INFO,33505,self.sub_type)
  96. if not self.money_view then
  97. self.money_view = UIMoneyView.New(self.moneyCon)
  98. end
  99. self.money_view:SetPosition(0,0)
  100. self.money_view:SetData()
  101. self:SetActDetailShow()
  102. if not self.model.login_red_list[self.sub_type] then--清除登陆红点
  103. self.model.login_red_list[self.sub_type] = true
  104. self.model:CheckPowerTurnTableMainRedDot(self.sub_type)
  105. end
  106. end
  107. function PowerTurnTableView:AddEvent()
  108. local function on_click( target,x,y )
  109. if target == self.oneBtn_obj then--抽一次
  110. self:LuckyDraw(1,x,y)
  111. elseif target == self.tenBtn_obj then--抽十次
  112. self:LuckyDraw(10,x,y)
  113. elseif target == self.skip_toggle_obj then--取消动画
  114. self.is_skip_action = not self.is_skip_action
  115. self.model.is_skip_turn_table_action = self.is_skip_action
  116. elseif target == self.scoreBtn_obj then--积分兑换
  117. self.model:Fire(PowerTurnTableModel.OPEN_EXCHANGE_VIEW,self.sub_type)
  118. self.model:SetPowerTTScoreCookie(self.sub_type,TimeUtil:getServerTime( ))
  119. self:UpdateView()
  120. elseif target == self.helpBtn_obj then--帮助按钮
  121. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 33500)
  122. elseif target == self.closeBtn_obj then--关闭按钮
  123. if self.is_playing then
  124. Message.show("正在动画中哦")
  125. return
  126. end
  127. self:Close()
  128. elseif target == self.probabilityBtn_obj then--概率按钮
  129. UIToolTipMgr:getInstance():AppendLuckyProbTips(331, self.base_type, self.sub_type)
  130. end
  131. end
  132. AddClickEvent(self.closeBtn_obj, on_click)
  133. AddClickEvent(self.helpBtn_obj, on_click)
  134. AddClickEvent(self.skip_toggle_obj, on_click)
  135. AddClickEvent(self.scoreBtn_obj, on_click)
  136. AddClickEvent(self.oneBtn_obj, on_click)
  137. AddClickEvent(self.tenBtn_obj, on_click)
  138. AddClickEvent(self.probabilityBtn_obj, on_click)
  139. local function start_action(subtype, id_list,cur_point)
  140. if self.sub_type == subtype and not self._use_delete_method then
  141. for i,v in ipairs(self.item_list) do--重置一遍状态
  142. v.choose_bg_obj:SetActive(false)
  143. v.awardNum_tmp.text = ""
  144. end
  145. self.id_list = id_list
  146. local choose_list = {}
  147. local choose_action_list = {}
  148. for i,v in ipairs(id_list) do
  149. if not choose_list[v.id] then
  150. choose_list[v.id] = {num = 0,id = v.id}
  151. end
  152. choose_list[v.id] = {num = choose_list[v.id].num + 1,id = v.id}
  153. choose_action_list[#choose_action_list + 1] = {num = choose_list[v.id].num,id = v.id}
  154. end
  155. self.choose_action_list = choose_action_list
  156. self.show_award_list = DeepCopy(choose_action_list)
  157. if #self.id_list > 1 then
  158. self.action_time = Config.Sourceturntablekv["ten_time"].val/self.show_goods_num
  159. self.quan_num = 2
  160. else
  161. self.action_time = Config.Sourceturntablekv["one_time"].val
  162. self.quan_num = 3
  163. end
  164. self.cur_point = cur_point + Config.Sourceturntablekv["turn_luck"].val
  165. --提前更新按钮状态
  166. self:UpdateFreeState()
  167. self:PlayAction()
  168. end
  169. end
  170. self:BindEvent(self.model, PowerTurnTableModel.START_TURN_ACTION, start_action)
  171. local function update_view_func(subtype)
  172. if self.sub_type == subtype and not self._use_delete_method then
  173. self:UpdateView()
  174. end
  175. end
  176. self:BindEvent(self.model, PowerTurnTableModel.UPDATE_VIEW_INFO, update_view_func)
  177. local function update_record_func(subtype)
  178. if self.sub_type == subtype and not self._use_delete_method then
  179. self:UpdateRecordItemList()
  180. end
  181. end
  182. self:BindEvent(self.model, PowerTurnTableModel.UPDATE_RECORD_INFO, update_record_func)
  183. end
  184. function PowerTurnTableView:UpdateView()
  185. self.server_info = self.model:GetPowerTurnTableInfo(self.sub_type)
  186. if not self.server_info or not self.server_info.sub_type then
  187. return
  188. end
  189. self:UpdateFreeState()
  190. self.curSoreText_tmp.text = string.format("当前积分:<color=%s>%s</color>", ColorUtil.YELLOW_DARK, self.server_info.score)
  191. -- self:ClearUIEffect(self.effect)
  192. -- if self.server_info.score > 0 then
  193. -- self:AddUIEffect("ui_effect_shouchong05_1", self.effect, self.layer_name, nil, 1, false,nil,nil,nil,nil,nil)
  194. -- end
  195. local cur = self.server_info.point
  196. local max = Config.Sourceturntablekv["luck_total"].val
  197. self.numText_tmp.text = string.format("%s/%s",cur,max)
  198. self.btnMax_obj:SetActive(cur >= max)
  199. self.btnImg_obj:SetActive(cur < max)
  200. self:ClearUIEffect(self.maxEffect)
  201. self.maxEffect.gameObject:SetActive(cur >= max)
  202. if cur >= max then
  203. self:AddUIEffect("angericon", self.maxEffect, self.layer_name, nil, 1.2, true, nil, nil, nil)
  204. self.numText_tmp.text = ""
  205. end
  206. self:UpdateTurnTable()
  207. self:UpdateCost()
  208. local score_red = false
  209. local last_time_list = self.model:GetPowerTTScoreCookie()
  210. if not last_time_list[self.sub_type] then
  211. score_red = true
  212. end
  213. score_red = score_red or (self.model.time_red_list[self.sub_type] and self.model.can_exchange_red_list[self.sub_type])
  214. self.scoreBtnRed_obj:SetActive(score_red and self.server_info.score > 0)
  215. end
  216. function PowerTurnTableView:UpdateFreeState( )
  217. local is_free = self.server_info and self.server_info.free_time > 0 and true or false
  218. self.freeText_tmp.text = not is_free and "" or HtmlColorTxt("免费", ColorUtil.GREEN_DARK)
  219. self.oneBtnGoodsImg.gameObject:SetActive(not is_free)
  220. self.oneBtnTimeText.gameObject:SetActive(not is_free)
  221. self.oneBtnRedDot_obj:SetActive(is_free)
  222. end
  223. function PowerTurnTableView:ShowGetReward( )
  224. --触发快捷使用
  225. OperateActivityModel:getInstance():Fire(OperateActivityModel.QUIK_USE, true)
  226. --道具飞背包
  227. local goods_data = self.server_info.pool_list[self.choose_index]
  228. if not goods_data then
  229. print("huangcong:PowerTurnTableView [start:130] self.choose_index:", self.choose_index)
  230. return
  231. end
  232. local goods_fly_data = {[1] = goods_data.reward[2]}
  233. if TableSize(goods_fly_data) > 0 then
  234. MainUIModel:getInstance():PlayGoodsFlyList(goods_fly_data)
  235. end
  236. --飘字
  237. goods_fly_data = {
  238. [1] = {
  239. goods_type_id = goods_data.reward[2],
  240. num = goods_data.reward[3],
  241. }
  242. }
  243. if TableSize(goods_fly_data) > 0 then
  244. MainUIModel:getInstance():AddFloatInfo(goods_fly_data, true)
  245. end
  246. end
  247. function PowerTurnTableView:ShowTagAwardList( )
  248. local need_open = false
  249. local new_award_list = {}
  250. for i,v in ipairs(self.show_award_list) do
  251. local cur_goods_data = self.server_info.pool_list[v.id]
  252. if cur_goods_data.tag > 0 then
  253. need_open = true
  254. end
  255. new_award_list[#new_award_list + 1] = {cur_goods_data.reward[1], cur_goods_data.reward[2], cur_goods_data.reward[3]}
  256. end
  257. if need_open then
  258. GiftModel:getInstance():Fire(GiftModel.OPEN_SHOW_ACT_GOODS_VIEW, new_award_list)
  259. end
  260. end
  261. function PowerTurnTableView:PlayAction()
  262. local choose_data = self.choose_action_list[1]
  263. if not choose_data or not choose_data.num then return end
  264. self:ClearTweener()
  265. self.is_playing = true
  266. self.choose_index = choose_data.id
  267. local end_callback = function ()
  268. self:SetSelectLight(choose_data.id,choose_data.num)
  269. if #self.choose_action_list > 0 then
  270. table.remove(self.choose_action_list, 1)
  271. end
  272. local cur = self.cur_point
  273. local max = Config.Sourceturntablekv["luck_total"].val
  274. self.numText_tmp.text = string.format("%s/%s",cur,max)
  275. self.btnMax_obj:SetActive(cur >= max)
  276. self.btnImg_obj:SetActive(cur < max)
  277. self:ClearUIEffect(self.maxEffect)
  278. self.maxEffect.gameObject:SetActive(cur >= max)
  279. self:ShowGetReward()
  280. if cur >= max then
  281. self:AddUIEffect("angericon", self.maxEffect, self.layer_name, nil, 1.2, true, nil, nil, nil)
  282. self.numText_tmp.text = ""
  283. end
  284. if #self.choose_action_list > 0 then
  285. self.cur_point = self.cur_point + Config.Sourceturntablekv["turn_luck"].val
  286. self:PlayAction()
  287. else
  288. self:ShowTagAwardList()
  289. self.is_playing = false
  290. self.model:Fire(PowerTurnTableModel.UPDATE_VIEW_INFO,self.sub_type)
  291. end
  292. end
  293. local angle1 = -(self.choose_index - 1) * 360 / self.show_goods_num - 360 * self.quan_num
  294. if self.is_skip_action then
  295. self.pointer.localRotation = Quaternion.Euler(0,0,angle1)
  296. end_callback()
  297. else
  298. self.out_tween_id = TweenLite.to(self, self.pointer, TweenLite.UiAnimationType.ROTATION, angle1, self.action_time, end_callback, TweenFunc.EASE_OUT)
  299. end
  300. self.cur_pointer_angle = angle1
  301. end
  302. function PowerTurnTableView:ClearTweener()
  303. if self.out_tween_id then
  304. TweenLite.Stop(self.out_tween_id)
  305. self.out_tween_id = nil
  306. end
  307. end
  308. function PowerTurnTableView:SetSelectLight( index,num )
  309. if self.item_list[index] then
  310. self.item_list[index].choose_bg_obj:SetActive(true)
  311. if num > 0 then
  312. self.item_list[index].awardNum_tmp.text = "x"..num
  313. else
  314. self.item_list[index].awardNum_tmp.text = ""
  315. end
  316. end
  317. end
  318. --更新转盘数据
  319. function PowerTurnTableView:UpdateTurnTable( )
  320. local award_cfg_list = self.server_info.pool_list
  321. if not award_cfg_list or #award_cfg_list == 0 then return end
  322. for i=1,10 do
  323. local info = award_cfg_list[i]
  324. if info then
  325. self.item_list[i].award_item:SetDataWithMapId(info.reward[2],info.reward[3])
  326. self.item_list[i].tipImg_obj:SetActive(info.tag > 0)
  327. if info.tag > 0 then
  328. lua_resM:setImageSprite(self, self.item_list[i].tipImg_img, "powerTurnTable_asset", "powerTurnTable_tag_"..info.tag)
  329. end
  330. end
  331. end
  332. end
  333. --更新消耗
  334. function PowerTurnTableView:UpdateCost( )
  335. local one_data = Config.Sourceturntablekv["turn_cost_1"].val
  336. local ten_data = Config.Sourceturntablekv["turn_cost_10"].val
  337. if not one_data or not ten_data then return end
  338. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(self.cost_id)
  339. self.cost_id = tonumber(stringtotable(ten_data)[1][2])
  340. local one_cost_num = tonumber(stringtotable(one_data)[1][3])
  341. local ten_cost_num = tonumber(stringtotable(ten_data)[1][3])
  342. -- self.oneBtnTimeText_tmp.text = HtmlColorTxt("X"..one_cost_num, one_cost_num > goods_num and ColorUtil.RED_DARK or ColorUtil.GREEN_DARK)
  343. -- self.tenBtnTimeText_tmp.text = HtmlColorTxt("X"..ten_cost_num, ten_cost_num > goods_num and ColorUtil.RED_DARK or ColorUtil.GREEN_DARK)
  344. self.oneBtnTimeText_tmp.text = one_cost_num
  345. self.tenBtnTimeText_tmp.text = ten_cost_num
  346. self.one_cost_num = one_cost_num
  347. self.ten_cost_num = ten_cost_num
  348. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.cost_id)
  349. lua_resM:setOutsideImageSprite(self, self.oneBtnGoodsImg_img, GameResPath.GetGoodsIcon(goods_basic.goods_icon), false)
  350. lua_resM:setOutsideImageSprite(self, self.tenBtnGoodsImg_img, GameResPath.GetGoodsIcon(goods_basic.goods_icon), false)
  351. self.money_view:ChangeShowFlag("PowerTurnTable",self.cost_id)
  352. end
  353. function PowerTurnTableView:DestroySuccess( )
  354. self:ClearUIEffect(self.btnImg)
  355. self:ClearUIEffect(self.effect)
  356. CustomActivityModel:getInstance():SetGoodsCanFly(true)
  357. if self.money_view then
  358. self.money_view:DeleteMe()
  359. self.money_view = nil
  360. end
  361. self:ClearTweener()
  362. self:StopRecordItemAction()
  363. for i,v in ipairs(self.item_list) do
  364. if v.award_item then
  365. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v.award_item)
  366. v.award_item = nil
  367. end
  368. end
  369. for i,v in ipairs(self.record_item_list) do
  370. v:DeleteMe()
  371. v = nil
  372. end
  373. self.record_item_list = {}
  374. end
  375. function PowerTurnTableView:LuckyDraw( lucky_num,x,y )
  376. if self.is_playing then
  377. Message.show("正在动画中哦")
  378. return
  379. end
  380. if self.server_info and self.server_info.free_time > 0 and lucky_num == 1 then
  381. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  382. self.model:Fire(PowerTurnTableModel.REQUEST_INFO,33504,self.sub_type,lucky_num>1 and 2 or 1,self.is_skip_action and 1 or 0)
  383. return
  384. end
  385. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(self.cost_id)
  386. if lucky_num > goods_num then
  387. -- Message.show("转盘道具数量不足哦!")
  388. -- UIToolTipMgr:getInstance():AppendGoodsTips(self.cost_id, x, y, nil)
  389. local jin = RoleManager.Instance.mainRoleInfo.jin
  390. local one_price = GoodsModel:getInstance():GetGoodsPrice(self.cost_id) or 60
  391. local good_num = GoodsModel:getInstance():GetTypeGoodsNum(self.cost_id)
  392. local good_name = GoodsModel:getInstance():getGoodsName(self.cost_id,true)
  393. local num = lucky_num > 1 and self.ten_cost_num or self.one_cost_num
  394. local function ok( ... )
  395. if jin >= one_price*(num - good_num) then
  396. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  397. self.model:Fire(PowerTurnTableModel.REQUEST_INFO,33504,self.sub_type,lucky_num>1 and 2 or 1,self.is_skip_action and 1 or 0)
  398. else
  399. local qc_data = {
  400. price = one_price*(num - good_num),
  401. }
  402. GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
  403. end
  404. end
  405. if self.model.buy_toggle[self.sub_type] then
  406. ok()
  407. else
  408. local need_price = one_price*(num - good_num)
  409. local need_num = math.ceil(need_price/one_price)
  410. local cur_type_str = string.format("抽奖 %s 次",HtmlColorTxt(lucky_num, ColorUtil.GREEN_DARK))
  411. if cur_view_cfg then
  412. cur_type_str = cur_type_str
  413. end
  414. local function toggle_function( flag )
  415. self.model.buy_toggle[self.sub_type] = flag
  416. end
  417. local asset, source = WordManager:GetCommonMoneyIcon(1)
  418. local toggle_tip_data = {
  419. gold_ab_res = asset,
  420. gold_res = source,
  421. price = need_price,
  422. insufficientText = "",
  423. priceText = string.format("<color=%s>%s</color> 补齐所需的 %s\n%s",ColorUtil.YELLOW_DARK,need_price,good_name,cur_type_str),
  424. titleText = "提示",
  425. ok_callback = ok,
  426. toggle_function = toggle_function,
  427. is_complex_ok_callback = true,
  428. }
  429. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  430. end
  431. else
  432. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  433. self.model:Fire(PowerTurnTableModel.REQUEST_INFO,33504,self.sub_type,lucky_num>1 and 2 or 1,self.is_skip_action and 1 or 0)
  434. end
  435. end
  436. -- 创建服务器记录
  437. function PowerTurnTableView:UpdateRecordItemList( )
  438. -- 创建的时候要暂停动画
  439. self:StopRecordItemAction()
  440. local record_list = self.model:GetRecordInfo(self.sub_type) or {}
  441. for k, v in pairs(self.record_item_list) do
  442. v:SetVisible(false)
  443. end
  444. -- 节点高度
  445. local max_item_num = 20 -- 最大节点数
  446. local node_height = self.record_scroll.sizeDelta.y
  447. local height = 5
  448. local item
  449. self.record_count = 0
  450. for k, v in ipairs(record_list) do
  451. if k > max_item_num then
  452. break
  453. end
  454. item = self.record_item_list[k]
  455. if not item then
  456. item = PowerTurnTableRecordItem.New(self.record_con)
  457. self.record_item_list[k] = item
  458. end
  459. item:SetAnchoredPosition(2, -height)
  460. item:SetVisible(true)
  461. height = height + item:SetData(v, self.sub_type, -height)
  462. self.record_count = self.record_count + 1
  463. end
  464. SetSizeDeltaY(self.record_con, height)
  465. -- 记录一下当前的节点数
  466. -- 生成节点的高度超过了容器高度,就需要展示轮播
  467. if height > node_height then
  468. self:StartRecordItemAction()
  469. end
  470. end
  471. -- 开始轮播记录动画
  472. function PowerTurnTableView:StartRecordItemAction()
  473. self:StopRecordItemAction()
  474. local time = 3
  475. local function func()
  476. self:UpdateRecordItemPos()
  477. self:MoveRecordItem()
  478. end
  479. self.auto_record_item_anim_id = GlobalTimerQuest:AddPeriodQuest(func, time, -1)
  480. end
  481. function PowerTurnTableView:StopRecordItemAction()
  482. if self.auto_record_item_anim_id then
  483. GlobalTimerQuest:CancelQuest(self.auto_record_item_anim_id)
  484. self.auto_record_item_anim_id = nil
  485. end
  486. self:StopRecordItemAnim()
  487. end
  488. -- 播放招财记录节点的动画
  489. function PowerTurnTableView:MoveRecordItem()
  490. local first_text = self.record_item_list[1]
  491. local move_height = first_text:GetAnchoredPosition().y
  492. move_height = move_height > 0 and 0 or move_height
  493. for k,text in pairs(self.record_item_list) do
  494. text:StartAction(move_height + 5)
  495. end
  496. end
  497. -- 停止招财记录节点的动画
  498. function PowerTurnTableView:StopRecordItemAnim()
  499. for k,text in pairs(self.record_item_list) do
  500. text:StopAction()
  501. end
  502. end
  503. function PowerTurnTableView:UpdateRecordItemPos()
  504. local delete_index = {}
  505. local height = 5
  506. local count = 0
  507. for i = 1, self.record_count do
  508. local text = self.record_item_list[i]
  509. if text then
  510. local vis = text:GetVisible()
  511. local h = text:GetRecordHeight()
  512. local y = text:GetAnchoredPosition().y
  513. height = height + (vis and h or 0)
  514. if y + h > 5 and vis then -- 将超出屏幕并显示中的节点保存到移动临时队列 0.1 由于浮点误差有可能出现不该隐藏的节点也添加到队列中,做加大误差处理
  515. table.insert(delete_index, i)
  516. end
  517. end
  518. end
  519. local del_num = 0
  520. local t = {}
  521. for i,v in ipairs(delete_index) do
  522. local index = v - del_num
  523. local text = table.remove(self.record_item_list, index)
  524. t[#t+1] = text
  525. del_num = del_num + 1
  526. end
  527. -- 将临时队列的节点存回去
  528. for i = 1, #t do
  529. t[i]:SetAnchoredPosition(2, -height)
  530. table.insert(self.record_item_list, t[i])
  531. end
  532. end
  533. function PowerTurnTableView:SetActDetailShow()
  534. if self.is_loaded then
  535. if self.timer_id then
  536. GlobalTimerQuest:CancelQuest(self.timer_id)
  537. self.timer_id = nil
  538. end
  539. local act_list = CustomActivityModel:getInstance():getActList(self.base_type, self.sub_type)
  540. if act_list then
  541. local sec = act_list.etime - TimeUtil:getServerTime()
  542. if sec > 0 then
  543. local function onTimer()
  544. sec = sec - 1
  545. if sec > 0 then
  546. self.timeText_tmp.text = string.format("活动剩余:<color=%s>%s</color>",ColorUtil.GREEN_DARK,TimeUtil:timeConvert6(sec,sec<24*3600))
  547. else
  548. self.timeText_tmp.text = string.format("活动剩余:%s",HtmlColorTxt("已结束", ColorUtil.RED_DARK))
  549. GlobalTimerQuest:CancelQuest(self.timer_id)
  550. self.timer_id = nil
  551. end
  552. end
  553. if not self.timer_id then
  554. self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  555. end
  556. onTimer()
  557. else
  558. self.timeText_tmp.text = string.format("活动剩余:%s",HtmlColorTxt("已结束", ColorUtil.RED_DARK))
  559. end
  560. end
  561. end
  562. end