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

469 lines
15 KiB

  1. TreasureHouseView = TreasureHouseView or BaseClass(BaseView)
  2. local TreasureHouseView = TreasureHouseView
  3. --[[
  4. TreasureHouseView.TabData = {
  5. [1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
  6. }
  7. --]]
  8. function TreasureHouseView:__init()
  9. self.base_file = "treasureHouse"
  10. self.layout_file = "TreasureHouseView"
  11. self.layer_name = "UI"
  12. self.destroy_imm = true
  13. self.use_background = true --全屏界面默认使用这个参数
  14. self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  15. self.change_scene_close = true
  16. self.append_to_ctl_queue = true --是否要添加进界面堆栈
  17. self.need_show_money = true --是否要显示顶部的金钱栏
  18. self:AddPreLoadList("treasureHouse", {"TreasureHouseRecordItem"})
  19. self.model = TreasureHouseModel:getInstance()
  20. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10400)
  21. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10403)
  22. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10406)
  23. self.reward_item_list = {}
  24. self.reward_item_con = {}--item节点
  25. self.record_item_list = {}
  26. self.reward_count_item_list = {}--保底奖励列表
  27. self.is_not_show_action = false
  28. self.load_callback = function ()
  29. self:LoadSuccess()
  30. end
  31. self.open_callback = function ( )
  32. self:OpenSuccess()
  33. end
  34. self.switch_callback = function(index)
  35. self:SwitchTab(index)
  36. end
  37. self.destroy_callback = function ( )
  38. self:DestroySuccess()
  39. end
  40. end
  41. function TreasureHouseView:Open( )
  42. BaseView.Open(self)
  43. end
  44. function TreasureHouseView:LoadSuccess()
  45. local nodes = {
  46. "bg:raw", "one_btn:obj", "tip_text:tmp", "record_scroll/Viewport/record_con",
  47. "record_scroll", "reward_btn:obj", "task_scroll/Viewport/task_con", "cur_ratio_text:tmp",
  48. "task_scroll", "close_btn:obj", "ten_btn:obj", "progress_image:img", "Toggle:tog:obj",
  49. "reward_con", "role_con", "time_text:tmp", "goods_name_text:tmp",
  50. "con_money", "title_image", "cost_image2:img", "cost_text1:tmp", "cost_image1:img", "cost_text2:tmp",
  51. "num_text:txt", "di_image", "recordTips:tmp",
  52. }
  53. self:GetChildren(nodes)
  54. for i=1,15 do
  55. self.reward_item_con[i] = self:GetChild("item_con/item_con"..i)
  56. end
  57. self:AddEvent()
  58. self:CreateMoneyView()
  59. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("treasureHouse_bg"),false)
  60. local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( TreasureHouseConst.TREASURE_HOUSE_TICKET_ID ).goods_icon
  61. lua_resM:setOutsideImageSprite(self,self.cost_image1_img,GameResPath.GetGoodsIcon(goods_icon),false)
  62. lua_resM:setOutsideImageSprite(self,self.cost_image2_img,GameResPath.GetGoodsIcon(goods_icon),false)
  63. local str = ChuanWenManager:getInstance():FormatColorTag2(TreasureHouseConst.TIP_DESC, true)
  64. self.tip_text_tmp.text = str
  65. if self.model:IsTreasureHouseUpRatio() then
  66. local ratio = stringtotable(Config.Treasurehousekv["prob_up"].value)
  67. local ratio_str = HtmlColorTxt(string.format("大奖概率*%s%%",ratio[1][2]), ColorUtil.YELLOW_DARK )
  68. local str = string.format("当前加成:%s", ratio_str)
  69. self.cur_ratio_text_tmp.text = str
  70. else
  71. self.cur_ratio_text_tmp.text = "当前加成:无"
  72. end
  73. local function bg_back_func( ... )
  74. if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
  75. self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
  76. self:MoveUIToBack(self.bg_raw)
  77. self:MoveUIToBack(self.title_image)
  78. self:MoveUIToBack(self.di_image)
  79. end
  80. end
  81. if self.background_wnd then
  82. bg_back_func()
  83. else
  84. self.bg_back_func = bg_back_func
  85. end
  86. end
  87. function TreasureHouseView:AddEvent()
  88. local function on_click( target )
  89. if target == self.close_btn_obj then
  90. self:Close()
  91. elseif target == self.one_btn_obj then
  92. self:OnDrawBtnClick(1)
  93. elseif target == self.ten_btn_obj then
  94. self:OnDrawBtnClick(10)
  95. elseif target == self.Toggle_obj then
  96. self.is_not_show_action = not self.is_not_show_action
  97. elseif target == self.reward_btn_obj then
  98. self.model:Fire(TreasureHouseConst.OPEN_TREASURE_HOUSE_REWARD_VIEW)
  99. end
  100. end
  101. AddClickEvent(self.close_btn_obj, on_click)
  102. AddClickEvent(self.one_btn_obj, on_click)
  103. AddClickEvent(self.ten_btn_obj, on_click)
  104. AddClickEvent(self.Toggle_obj, on_click)
  105. AddClickEvent(self.reward_btn_obj, on_click)
  106. local function on_update_record_list( )
  107. self:UpdateRecordItemList()
  108. end
  109. self.on_update_record_list_id = self.model:BindOne("treasure_house_record_info", on_update_record_list)
  110. local function on_update_base_info( )
  111. self:UpdateCountRewardList()
  112. self:UpdateModel()
  113. end
  114. self.on_update_base_info_id = self.model:BindOne("treasure_house_base_info", on_update_base_info)
  115. local function on_update_task_info( )
  116. self:UpdateTaskItem()
  117. end
  118. self.on_update_task_info_id = self.model:BindOne("treasure_house_task_info", on_update_task_info)
  119. end
  120. function TreasureHouseView:OpenSuccess()
  121. self:UpdateView()
  122. end
  123. function TreasureHouseView:CreateMoneyView( )
  124. if not self.money_view then
  125. self.money_view = UIMoneyView.New(self.con_money)
  126. end
  127. self.money_view:SetPosition(0,0)
  128. self.money_view:SetData()
  129. self.money_view:ChangeShowFlag("treasureHouse",TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
  130. end
  131. function TreasureHouseView:UpdateView()
  132. self:UpdateRewardItem()
  133. self:UpdateTaskItem()
  134. self:UpdateRecordItemList()
  135. self:UpdateCountRewardList()
  136. self:UpdateModel()
  137. end
  138. function TreasureHouseView:UpdateRewardItem( )
  139. local data = self.model:GetTreasureHouseRewardList()
  140. for i=1,15 do
  141. local item = self.reward_item_list[i]
  142. if not item then
  143. item = TreasureHouseItem.New(self.reward_item_con[i])
  144. self.reward_item_list[i] = item
  145. end
  146. item:SetData(data[i], i)
  147. end
  148. end
  149. function TreasureHouseView:UpdateTaskItem( )
  150. local cfg = Config.Treasurehousetask
  151. local server_data = self.model:GetTreasureHouseTaskInfo()
  152. if not self.task_list_com then
  153. self.task_list_com = self:AddUIComponent(UI.ItemListCreator)
  154. end
  155. local info = {
  156. data_list = cfg,
  157. item_con = self.task_con,
  158. scroll_view = self.task_scroll,
  159. item_class = TreasureHouseTaskItem,
  160. start_y = 0, start_x = -2,
  161. create_frequency = 0.02,
  162. create_num_per_time = 3,
  163. item_height = 72,
  164. space_y = 2,
  165. on_update_item = function(item, i, v)
  166. item:SetData(i, v)
  167. item:SetServerData(server_data[v.id])
  168. end,
  169. }
  170. self.task_list_com:UpdateItems(info)
  171. end
  172. function TreasureHouseView:UpdateCountRewardList( )
  173. local period = 1
  174. local round = 1
  175. local base_info = self.model:GetTreasureHouseBaseInfo()
  176. local count_awards = base_info.count_awards or {}
  177. if TableSize(base_info) > 0 then
  178. period = base_info.curr_period
  179. local max_round = self.model:GetMaxRoundByPeriod(period)
  180. round = base_info.award_round > max_round and max_round or base_info.award_round
  181. end
  182. local data = self.model:GetTreasureHouseCFG(period,round)
  183. local sort_func = function ( a, b )
  184. return a.count < b.count
  185. end
  186. table.sort(data, sort_func)
  187. local x_offset = 85+30
  188. for i,v in ipairs(data) do
  189. local item = self.reward_count_item_list[i]
  190. if not item then
  191. item = TreasureHouseItem.New(self.reward_con)
  192. item:SetPosition((i-1)*x_offset, -2)
  193. self.reward_count_item_list[i] = item
  194. end
  195. item:SetData(v,i, true)
  196. item:SetServerData(count_awards[i])
  197. end
  198. self:UpdateProgress()
  199. self.time_text_tmp.text = self.model:GetTreasureTime()
  200. end
  201. function TreasureHouseView:UpdateProgress( )
  202. local base_info = self.model:GetTreasureHouseBaseInfo()
  203. local num = 0
  204. local cfg_data = DeepCopy(self.model:GetTreasureHouseCFG(1,1))
  205. if TableSize(base_info) > 0 then
  206. local max_round = self.model:GetMaxRoundByPeriod(base_info.curr_period)
  207. cfg_data = DeepCopy(self.model:GetTreasureHouseCFG(base_info.curr_period, base_info.award_round > max_round and max_round or base_info.award_round))
  208. num = base_info.curr_count
  209. if base_info.award_round ~= base_info.real_round then--如果有轮次没领的
  210. for i=base_info.award_round,base_info.real_round-1 do
  211. local round = i > max_round and max_round or i
  212. num = self.model:GetMaxNumByPeriodAndRound(base_info.curr_period, round) + num
  213. end
  214. end
  215. end
  216. self.num_text_txt.text = num
  217. local width_list = {[1] ={0.014,0.161}, [2] = {0.27,0.4},[3] ={0.53, 0.67},[4]= {0.8, 0.93},[5]= {1,1},}
  218. local per_space = 25
  219. local data = {}
  220. for i=1,4 do
  221. data[i] = cfg_data[i]
  222. if i~= 1 then
  223. data[i].min_count = data[i-1].count+1
  224. else
  225. data[i].min_count = 0
  226. end
  227. end
  228. local index = 1
  229. for i,v in ipairs(data) do
  230. if num>= v.min_count and num <= v.count then
  231. index = i
  232. break
  233. end
  234. end
  235. data[5] = { min_count = data[4].count, count = 999 }
  236. if num >= data[5].min_count then
  237. index = 5
  238. end
  239. local min_percent = 0
  240. local max_percent = 0
  241. if index then
  242. min_percent = width_list[index][1]
  243. max_percent = width_list[index][2]
  244. end
  245. local offset_percent = max_percent - min_percent
  246. local time_offset = data[index].count - data[index].min_count + 1
  247. local percent = (num - data[index].min_count + 1) / time_offset * offset_percent + min_percent
  248. self.progress_image_img.fillAmount = percent
  249. end
  250. function TreasureHouseView:UpdateModel( )
  251. local data = self.model:GetTreasureHouseBaseInfo()
  252. local period = 1
  253. local cfg = Config.Treasurehouseperiod[period]
  254. if cfg then
  255. local fashion_id,color_id = FashionModel:getInstance():GetFashionIdByGoodsId(cfg.show)
  256. local goods_name = GoodsModel:getInstance():getGoodsName(cfg.show, false)
  257. self.goods_name_text_tmp.text = goods_name
  258. local res_data = {
  259. father_node = self,
  260. transform = self.role_con,
  261. fashion_type = FuncOpenModel.TypeId.Clothes,
  262. size = Vector2(720,720),
  263. raycast_size = Vector2(340,600),
  264. scale = 180,
  265. position = Vector3(-85,40,179),
  266. ui_model_type = UIModelCommon.ModelType.BackModel,
  267. }
  268. FuncOpenModel:getInstance():SetModelRes(res_data)
  269. end
  270. end
  271. -- 创建服务器记录
  272. function TreasureHouseView:UpdateRecordItemList( )
  273. -- 创建的时候要暂停动画
  274. self:StopRecordItemAction()
  275. local record_list = self.model:GetTreasureHouseRecordInfo()
  276. for k, v in pairs(self.record_item_list) do
  277. v:SetVisible(false)
  278. end
  279. -- 节点高度
  280. local max_item_num = 20 -- 最大节点数
  281. local node_height = self.record_scroll.sizeDelta.y
  282. local height = 0
  283. local item
  284. self.record_count = 0
  285. for k, v in ipairs(record_list) do
  286. if k > max_item_num then
  287. break
  288. end
  289. item = self.record_item_list[k]
  290. if not item then
  291. item = TreasureHouseRecordItem.New(self.record_con)
  292. self.record_item_list[k] = item
  293. end
  294. item:SetAnchoredPosition(2, -height)
  295. item:SetVisible(true)
  296. height = height + item:SetData(v, self.sub_type)
  297. self.record_count = self.record_count + 1
  298. end
  299. -- self.no_record_tmp.text = self.record_count == 0 and "暂无记录" or ""
  300. SetSizeDeltaY(self.record_con, height)
  301. -- 记录一下当前的节点数
  302. -- 生成节点的高度超过了容器高度,就需要展示轮播
  303. if height > node_height then
  304. self:StartRecordItemAction()
  305. end
  306. if #record_list == 0 then
  307. self.recordTips_tmp.text = "暂无全服记录"
  308. else
  309. self.recordTips_tmp.text = ""
  310. end
  311. end
  312. -- 招财记录动画相关
  313. -- 招财记录动画相关
  314. -- 招财记录动画相关
  315. -- 开始轮播招财记录动画
  316. function TreasureHouseView:StartRecordItemAction()
  317. self:StopRecordItemAction()
  318. local time = FortuneCatModel.RecordAnimDuration
  319. local function func()
  320. self:UpdateRecordItemPos()
  321. self:MoveRecordItem()
  322. end
  323. self.auto_record_item_anim_id = GlobalTimerQuest:AddPeriodQuest(func, time, -1)
  324. end
  325. function TreasureHouseView:StopRecordItemAction()
  326. if self.auto_record_item_anim_id then
  327. GlobalTimerQuest:CancelQuest(self.auto_record_item_anim_id)
  328. self.auto_record_item_anim_id = nil
  329. end
  330. self:StopRecordItemAnim()
  331. end
  332. -- 播放招财记录节点的动画
  333. function TreasureHouseView:MoveRecordItem()
  334. local first_text = self.record_item_list[1]
  335. local move_height = first_text:GetAnchoredPosition().y
  336. move_height = move_height > 0 and 0 or move_height
  337. for k,text in pairs(self.record_item_list) do
  338. text:StartAction(move_height)
  339. end
  340. end
  341. -- 停止招财记录节点的动画
  342. function TreasureHouseView:StopRecordItemAnim()
  343. for k,text in pairs(self.record_item_list) do
  344. text:StopAction()
  345. end
  346. end
  347. function TreasureHouseView:UpdateRecordItemPos()
  348. local delete_index = {}
  349. local height = 0
  350. local count = 0
  351. for i = 1, self.record_count do
  352. local text = self.record_item_list[i]
  353. if text then
  354. local vis = text:GetVisible()
  355. local h = text:GetRecordHeight()
  356. local y = text:GetAnchoredPosition().y
  357. height = height + (vis and h or 0)
  358. if y + h > 0.1 and vis then -- 将超出屏幕并显示中的节点保存到移动临时队列 0.1 由于浮点误差有可能出现不该隐藏的节点也添加到队列中,做加大误差处理
  359. table.insert(delete_index, i)
  360. end
  361. end
  362. end
  363. local del_num = 0
  364. local t = {}
  365. for i,v in ipairs(delete_index) do
  366. local index = v - del_num
  367. local text = table.remove(self.record_item_list, index)
  368. t[#t+1] = text
  369. del_num = del_num + 1
  370. end
  371. -- 将临时队列的节点存回去
  372. for i = 1, #t do
  373. t[i]:SetAnchoredPosition(2, -height)
  374. table.insert(self.record_item_list, t[i])
  375. end
  376. end
  377. function TreasureHouseView:OnDrawBtnClick( num )
  378. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
  379. local need_show = goods_num < num
  380. local str = ""
  381. local buy_price = GoodsModel:getInstance():GetGoodsPrice(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
  382. local cost_price = (num - goods_num) * buy_price
  383. local function ok_callback( ... )
  384. if GoodsModel:getInstance():IsJinEnough(cost_price) then
  385. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10401, num)
  386. else
  387. local qc_data = {
  388. price = cost_price,
  389. }
  390. GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
  391. end
  392. end
  393. local function toggle_function( flag )
  394. self.model.not_show_treasure_house_tip = flag
  395. end
  396. local price_asset, price_icon = WordManager:GetCommonMoneyIcon(1)
  397. local toggle_tip_data = {
  398. gold_ab_res = price_asset,
  399. gold_res = price_icon,
  400. price = cost_price,
  401. insufficientText = "",
  402. priceText = string.format("<color=#fdffc2>%s</color> 补足所需的珍宝阁秘钥。",cost_price),
  403. titleText = "提示",
  404. ok_callback = ok_callback,
  405. toggle_function = toggle_function,
  406. is_complex_ok_callback = true,
  407. }
  408. if not self.model.not_show_treasure_house_tip and cost_price > 0 then
  409. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  410. else
  411. ok_callback()
  412. end
  413. end
  414. function TreasureHouseView:DestroySuccess( )
  415. for i,v in ipairs(self.reward_item_list) do
  416. v:DeleteMe()
  417. v = nil
  418. end
  419. self.reward_item_list = {}
  420. for i,v in ipairs(self.reward_count_item_list) do
  421. v:DeleteMe()
  422. v = nil
  423. end
  424. self.reward_count_item_list = {}
  425. if self.money_view then
  426. self.money_view:DeleteMe()
  427. self.money_view = nil
  428. end
  429. if self.on_update_record_list_id then
  430. self.model:UnBind(self.on_update_record_list_id)
  431. self.on_update_record_list_id = nil
  432. end
  433. if self.on_update_base_info_id then
  434. self.model:UnBind(self.on_update_base_info_id)
  435. self.on_update_base_info_id = nil
  436. end
  437. if self.on_update_task_info_id then
  438. self.model:UnBind(self.on_update_task_info_id)
  439. self.on_update_task_info_id = nil
  440. end
  441. self:StopRecordItemAction()
  442. for i,v in ipairs(self.record_item_list) do
  443. v:DeleteMe()
  444. v = nil
  445. end
  446. self.record_item_list = {}
  447. end