源战役客户端
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

351 linhas
13 KiB

  1. DailyRechargeBaseView = DailyRechargeBaseView or BaseClass(BaseView)
  2. local DailyRechargeBaseView = DailyRechargeBaseView
  3. DailyRechargeBaseView.ShowType = {
  4. Recharge = 1,
  5. Pellet = 2,
  6. }
  7. DailyRechargeBaseView.Action = {-- 滚动动画参数
  8. move_y = 0.25,--负数向下 正数向上 每帧移动的距离
  9. delay_time = 2,--玩家手动操作以后 这个时间倒计时 播放动画
  10. space = 15,--间距参数
  11. chuanwen_delay_time = 10,--每条轮播传闻之间的间隔
  12. chuanwen_play_time = 20,--每条轮播传闻从左滚到右的时间
  13. chuanwen_start_time = 1.5,--轮播传闻启动时间
  14. item_height = 70,
  15. }
  16. function DailyRechargeBaseView:__init()
  17. self.base_file = "dailyRecharge"
  18. self.layout_file = "DailyRechargeBaseView"
  19. self.layer_name = "UI"
  20. self.destroy_imm = true
  21. self.change_scene_close = true
  22. self.append_to_ctl_queue = true --是否要添加进界面堆栈
  23. self.need_show_money = false --是否要显示顶部的金钱栏
  24. -- self.is_set_zdepth = true
  25. self.click_bg_toClose = false
  26. ------------------------
  27. -- 一级全屏界面:
  28. self.hide_maincancas = true --隐藏主界面
  29. self.use_background = true --不一定显示遮罩
  30. -- 二级界面:
  31. -- self.hide_maincancas = false --是否需要隐藏主界面,看策划需求
  32. -- self.use_background = true --需要遮罩
  33. ------------------------
  34. self.model = RechargeActivityModel:getInstance()
  35. self.show_type = DailyRechargeBaseView.ShowType.Recharge
  36. self.award_list = {}
  37. self.load_callback = function ()
  38. self:LoadSuccess()
  39. end
  40. self.open_callback = function ( )
  41. self:OpenSuccess()
  42. end
  43. self.close_win_callback = function ( )
  44. self:Close()
  45. end
  46. self.destroy_callback = function ( )
  47. self:DestroySuccess()
  48. end
  49. end
  50. function DailyRechargeBaseView:Open( sub_info,show_type )
  51. if self.pellet_sub_view and self.pellet_sub_view.isGaming then
  52. Message.show("弹球飞行中,请稍后...")
  53. return
  54. end
  55. self.sub_type = sub_info or self.sub_type--子信息
  56. self.show_type = show_type or self.show_type--展示类型
  57. BaseView.Open(self)
  58. end
  59. function DailyRechargeBaseView:LoadSuccess()
  60. local nodes = {
  61. "container",
  62. --以下节点全部归属于弹珠机
  63. "pelletCon/big_title_1:obj", "pelletCon/btn_help:obj","pelletCon/bg_1:raw", "pelletCon/closeBtn:obj", "pelletCon/con_right/btn_switch/red_switch:obj",
  64. "pelletCon/con_right/ScrollView_item:scroll", "pelletCon/con_right/ScrollView_item/Viewport/Content_item", "pelletCon/con_right/btn_switch:obj",
  65. "pelletCon/con_right/lb_money_have:tmp:obj", "pelletCon/con_right/icon_cost:img:obj",
  66. "pelletCon/btn_back:obj","pelletCon:obj"
  67. }
  68. self:GetChildren(nodes)
  69. self:AddEvent()
  70. lua_resM:setOutsideRawImage(self,self.bg_1_raw,GameResPath.GetViewBigBg("dailyRecharge_bg"),false)
  71. self.money_view = self.money_view or self:CreateItem(UIMoneyView, self.transform, self.layer_name)
  72. self.money_view:SetData()
  73. self.money_view:SetPosition(50,ScreenHeight/2-25)
  74. self.money_view:ChangeShowFlag( "DailyRechargePellet",self.model:GetPelletTicketId( self.sub_type ) )
  75. self:SetRightReward()
  76. end
  77. function DailyRechargeBaseView:SetRightReward( )
  78. if self.award_list and (not self.award_list[1]) then
  79. -- 一次就好
  80. local base_info = self.model:GetPelletBasicInfo()
  81. if not base_info then return end
  82. local award_cfg = self.model:GetPelletRewardCfg(true,true,base_info.round)
  83. if award_cfg then
  84. self:CreateAward(award_cfg)
  85. end
  86. end
  87. end
  88. function DailyRechargeBaseView:RefreshRed( )
  89. self.red_switch_obj:SetActive(self.model:GetPelletRed())
  90. end
  91. function DailyRechargeBaseView:AddEvent()
  92. local function call_back( target )
  93. if target == self.closeBtn_obj then
  94. --[[if self.pellet_sub_view and self.pellet_sub_view.isGaming then
  95. Message.show("弹球飞行中,请稍后...")
  96. return
  97. end--]]
  98. if self.show_type == DailyRechargeBaseView.ShowType.Pellet then
  99. self.show_type = DailyRechargeBaseView.ShowType.Recharge
  100. self:UpdateView()
  101. else
  102. self:Close()
  103. end
  104. elseif target == self.btn_help_obj then
  105. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, "33106")
  106. elseif target == self.btn_switch_obj then
  107. if self.pellet_sub_view and self.pellet_sub_view.isGaming then
  108. Message.show("弹球飞行中,请稍后...")
  109. return
  110. end
  111. self.show_type = DailyRechargeBaseView.ShowType.Pellet
  112. self:UpdateView()
  113. elseif target == self.btn_back_obj then
  114. self.show_type = DailyRechargeBaseView.ShowType.Recharge
  115. self:UpdateView()
  116. end
  117. end
  118. AddClickEvent(self.btn_help_obj,call_back,false)
  119. AddClickEvent(self.closeBtn_obj,call_back,false)
  120. AddClickEvent(self.btn_switch_obj,call_back,false)
  121. AddClickEvent(self.btn_back_obj,call_back,false)
  122. local function onBagChange()
  123. self:RefreshRightInfo()
  124. end
  125. self:BindEvent(GoodsModel:getInstance(), GoodsModel.CHANGE_BAGLIST, onBagChange)
  126. local function stop_award_action( ... )
  127. self:StopAwardAction()
  128. self:StartAwardActionTimeDelay()
  129. end
  130. AddDragBeginEvent(self.ScrollView_item.gameObject,stop_award_action)
  131. local function UPDATE_PELLET_INFO( )
  132. self:SetRightReward()
  133. end
  134. self:BindEvent(RechargeActivityModel:getInstance(), RechargeActivityModel.UPDATE_PELLET_INFO, UPDATE_PELLET_INFO)
  135. end
  136. function DailyRechargeBaseView:OpenSuccess()
  137. self:UpdateView()
  138. end
  139. function DailyRechargeBaseView:UpdateView()
  140. self.pelletCon_obj:SetActive(self.show_type == DailyRechargeBaseView.ShowType.Pellet)
  141. self:RefreshRightInfo()
  142. if self.show_type == DailyRechargeBaseView.ShowType.Recharge then
  143. self.recharge_sub_view = self.recharge_sub_view or self:CreateItem(DailyRechargeSubView, self.container, self.layer_name,self.sub_type)
  144. self.recharge_sub_view:SetVisible( true )
  145. self.recharge_sub_view:UpdateView()
  146. local function close_call_back( ... )
  147. self:Close()
  148. end
  149. local function pellet_call_back( ... )
  150. if self.pellet_sub_view and self.pellet_sub_view.isGaming then
  151. Message.show("弹球飞行中,请稍后...")
  152. return
  153. end
  154. self.show_type = DailyRechargeBaseView.ShowType.Pellet
  155. self:UpdateView()
  156. end
  157. self.recharge_sub_view:SetFuncCallBack(pellet_call_back,close_call_back)
  158. if self.pellet_sub_view then
  159. self.pellet_sub_view:SetVisible( false,true )
  160. if self.pellet_sub_view.isGaming == true then
  161. if not self.pellet_sub_view.break_game_mask_req then
  162. local validation_data = CustomActivityModel:getInstance():GetPelletEventValidationData()
  163. if validation_data.errcode == 1 then -- 验证通过,完成弹珠机
  164. CustomActivityModel:getInstance():Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33184, 0, self.sub_type)
  165. end
  166. end
  167. self.pellet_sub_view:ResetGame()
  168. end
  169. end
  170. else
  171. self.pellet_sub_view = self.pellet_sub_view or self:CreateItem(DailyRechargePelletView, self.container, self.layer_name,self.sub_type)
  172. self.pellet_sub_view:SetVisible( true,true )
  173. self.pellet_sub_view:ResetGame()
  174. if self.recharge_sub_view then
  175. self.recharge_sub_view:SetVisible( false )
  176. end
  177. end
  178. end
  179. function DailyRechargeBaseView:RefreshRightInfo( )
  180. local cost_id = self.model:GetPelletTicketId( self.sub_type )
  181. local cost_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId( cost_id )
  182. local num = cost_id and GoodsModel:getInstance():GetTypeGoodsNum( cost_id ) or 0
  183. if cost_basic and cost_basic.goods_icon then
  184. lua_resM:setOutsideImageSprite(self,self.icon_cost_img,GameResPath.GetGoodsIcon(cost_basic.goods_icon),false)
  185. end
  186. self.lb_money_have_tmp.text = "x1"
  187. self:RefreshRed()
  188. end
  189. function DailyRechargeBaseView:DestroySuccess( )
  190. if self.pellet_sub_view and self.pellet_sub_view.isGaming == true then
  191. --如果弹珠界面正在动画,而且还没去请求奖励,那么帮他完成
  192. if not self.pellet_sub_view.break_game_mask_req then
  193. local validation_data = CustomActivityModel:getInstance():GetPelletEventValidationData()
  194. if validation_data.errcode == 1 then -- 验证通过,完成弹珠机
  195. CustomActivityModel:getInstance():Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33184, 0, self.sub_type)
  196. end
  197. end
  198. end
  199. if self.time_id then
  200. GlobalTimerQuest:CancelQuest(self.time_id)
  201. self.time_id = nil
  202. end
  203. if self.time_id1 then
  204. GlobalTimerQuest:CancelQuest(self.time_id1)
  205. self.time_id1 = nil
  206. end
  207. if self.ScrollView_item_scroll then
  208. self.ScrollView_item_scroll.onValueChanged:RemoveAllListeners()
  209. end
  210. if self.award_list then
  211. for k,v in pairs(self.award_list) do
  212. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v)
  213. end
  214. self.award_list = {}
  215. end
  216. end
  217. --------------------------------------------------------新动画start-------------------------
  218. function DailyRechargeBaseView:StartAwardAction( )--开始滚动运动
  219. local function func()
  220. local new_pos_x,new_pos_y = GetAnchoredPosition(self.Content_item.transform)
  221. SetAnchoredPosition(self.Content_item.transform,new_pos_x,new_pos_y + DailyRechargeBaseView.Action.move_y)
  222. end
  223. if not self.time_id then
  224. self.time_id = GlobalTimerQuest:AddPeriodQuest(func,0.01,-1)
  225. end
  226. end
  227. function DailyRechargeBaseView:StopAwardAction()--停止动画
  228. if self.time_id then
  229. GlobalTimerQuest:CancelQuest(self.time_id)
  230. self.time_id = nil
  231. end
  232. end
  233. function DailyRechargeBaseView:StartAwardActionTimeDelay( )--开启动画播放倒计时
  234. if self.time_id1 then
  235. GlobalTimerQuest:CancelQuest(self.time_id1)
  236. self.time_id1 = nil
  237. end
  238. local function func()
  239. self:StartAwardAction()
  240. end
  241. if not self.time_id1 then
  242. self.time_id1 = GlobalTimerQuest:AddPeriodQuest(func,DailyRechargeBaseView.Action.delay_time)
  243. end
  244. end
  245. function DailyRechargeBaseView:CreateAward( award_cfg )--创建图片节点
  246. local show_list_data = award_cfg
  247. local len = TableSize(show_list_data)
  248. self.len = len > 20 and 20 or len
  249. local offer_y = (59 + DailyRechargeBaseView.Action.space)
  250. self.offer_y = offer_y
  251. local width = len*offer_y
  252. self.max_right = width/2
  253. self.max_left = -width/2
  254. for i = 1, len do
  255. if not self.award_list[i] then
  256. self.award_list[i] = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.Content_item)
  257. self.award_list[i]:SetPosition(-48,-(offer_y * i)+10)
  258. self.award_list[i]:SetItemSize(59,59)
  259. self.award_list[i]:SetIsAct(true)
  260. end
  261. self.award_list[i]:SetDataWithMapId(show_list_data[i][2], show_list_data[i][3], show_list_data[i][1])
  262. end
  263. self.all_hight = len*offer_y
  264. self.Content_item.sizeDelta = Vector2(DailyRechargeBaseView.Action.item_height,self.all_hight)
  265. self.vis_down = -self.all_hight/2--下可视极限
  266. self.vis_up = self.all_hight/2--上可视极限
  267. self.old_pos_x,self.old_pos_y = GetAnchoredPosition(self.Content_item.transform)
  268. local callback = function( )
  269. local _,new_pos_y = GetAnchoredPosition(self.Content_item.transform)
  270. for k,v in pairs(self.award_list) do
  271. if v.transform then
  272. local abs_pos = v.transform:TransformPoint(Vector3.zero)
  273. local pos = self.transform:InverseTransformPoint(Vector3.New(abs_pos.x, abs_pos.y, 0))
  274. ------------------------------------------无限滚动 到某一极限值 向左开头的item移到最后 向右最后的item移到最前
  275. if new_pos_y < self.old_pos_y then--往下移动
  276. if pos.y < self.vis_down then
  277. local real_x,real_y = GetAnchoredPosition(v.transform)
  278. real_y = real_y + self.all_hight
  279. SetAnchoredPosition(v.transform, real_x,real_y)
  280. end
  281. else--往上动
  282. if pos.y > self.vis_up then
  283. local real_x,real_y = GetAnchoredPosition(v.transform)
  284. real_y = real_y - self.all_hight
  285. SetAnchoredPosition(v.transform, real_x,real_y)
  286. end
  287. end
  288. end
  289. end
  290. self.old_pos_y = new_pos_y
  291. end
  292. self.ScrollView_item_scroll.onValueChanged:AddListener(callback)
  293. -------------------------
  294. self:StartAwardAction()
  295. end
  296. --------------------------------------------------------新动画end-------------------------
  297. function DailyRechargeBaseView:HideChangeCall( show_status )
  298. if self.show_type == DailyRechargeBaseView.ShowType.Pellet then
  299. if self.pellet_sub_view then
  300. --如果弹珠界面正在动画,而且还没去请求奖励,那么帮他完成
  301. if self.pellet_sub_view.isGaming == true and (not self.pellet_sub_view.break_game_mask_req) then
  302. local validation_data = CustomActivityModel:getInstance():GetPelletEventValidationData()
  303. if validation_data.errcode == 1 then -- 验证通过,完成弹珠机
  304. CustomActivityModel:getInstance():Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33184, 0, self.sub_type)
  305. end
  306. end
  307. self.pellet_sub_view:ResetGame()
  308. end
  309. end
  310. end
  311. function DailyRechargeBaseView:CancelHide( )
  312. BaseView.CancelHide(self)
  313. if self.is_loaded then
  314. if self.show_type == DailyRechargeBaseView.ShowType.Recharge then
  315. self.recharge_sub_view = self.recharge_sub_view or self:CreateItem(DailyRechargeSubView, self.container, self.layer_name,self.sub_type)
  316. self.recharge_sub_view:SetVisible( true )
  317. self.recharge_sub_view:UpdateView()
  318. end
  319. end
  320. end