源战役客户端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

536 righe
16 KiB

  1. TaskAnnounceView = TaskAnnounceView or BaseClass(BaseView)
  2. local TaskAnnounceView = TaskAnnounceView
  3. function TaskAnnounceView:__init()
  4. self.base_file = "taskAnnounce"
  5. self.layout_file = "TaskAnnounceView"
  6. self.layer_name = "UI"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.hide_maincancas = false
  10. self.change_scene_close = true
  11. self.cur_select = false
  12. self.data_list = false
  13. -- self.use_local_view = true
  14. self.is_set_zdepth = false
  15. self.blur_activity_bg = true
  16. self.use_show_anim = true
  17. self.use_hide_anim = true
  18. self.item_list = false
  19. self.reward_item_list = {}
  20. self.model = TaskAnnounceModel:getInstance()
  21. self.mainVo = RoleManager:getInstance():GetMainRoleVo()
  22. self.loop_mgr = LoopScrowViewMgr.New()
  23. self.column_num = 1 --一行多少个图标
  24. self.show_count = 7
  25. self.data_list_num = false
  26. self.ui_effect = false
  27. self.open_id = false
  28. self.load_callback = function()
  29. self:LoadSuccess()
  30. self:InitEvent()
  31. end
  32. self.open_callback = function()
  33. self:UpdateView()
  34. end
  35. self.close_callback = function( )
  36. end
  37. self.destroy_callback = function()
  38. self:Clear()
  39. end
  40. end
  41. function TaskAnnounceView:Open(open_id)
  42. self.open_id = open_id
  43. BaseView.Open(self)
  44. end
  45. function TaskAnnounceView:LoadSuccess()
  46. local nodes = {
  47. "bg:raw",
  48. "reward_con/jum_btn:obj",
  49. "right_red_dot:obj",
  50. "rt_item:raw:obj",
  51. "desc:tmp",
  52. "right:obj",
  53. "reward_con/tips:tmp",
  54. "title_img:img",
  55. "left_red_dot:obj",
  56. "reward_con/get_btn:obj",
  57. "ScrollView/Viewport:img",
  58. "ScrollView/Viewport/Content",
  59. "ScrollView/Viewport/Content/parent",
  60. "reward_con/item_con:obj",
  61. "left:obj",
  62. "close_btn:obj",
  63. "ScrollView:scroll:obj",
  64. "icon:img:obj",
  65. "reward_con/get_btn/get_btn_red_dot:obj",
  66. "reward_con/get_done:obj",
  67. "continue_btn:obj",
  68. "continue_btn/continue_btn_txt:tmp",
  69. "continue_tips:tmp:obj",
  70. "reward_con:obj",
  71. }
  72. self:GetChildren(nodes)
  73. self.task_tip_table = {}
  74. for i=1,2 do
  75. self.task_tip_table[i] = {}
  76. self.task_tip_table[i].dot = self:GetChild("task_con/task_dot_" .. i).gameObject
  77. self.task_tip_table[i].txt = self:GetChild("task_con/task_tps_" .. i):GetComponent("TMPro.TextMeshProUGUI")
  78. end
  79. self.continue_btn_txt_tmp.text = "立即开启"
  80. self.continue_tips_tmp.text = HtmlColorTxt("产出大量高级战魂", "#2cf86f")
  81. self.right_obj:SetActive(true)
  82. self.right_red_dot_obj:SetActive(true)
  83. self.left_obj:SetActive(true)
  84. self.left_red_dot_obj:SetActive(true)
  85. self.ScrollView_obj:SetActive(true)
  86. local function bg_back_func( ... )
  87. if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
  88. self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
  89. end
  90. self:MoveUIToBack(self.bg_raw)
  91. lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("task_announce_bg_988_458"))
  92. end
  93. if self.background_wnd then
  94. bg_back_func()
  95. else
  96. self.bg_back_func = bg_back_func
  97. end
  98. self.mask_id = self:RegisterMask(self.Viewport_img)
  99. end
  100. function TaskAnnounceView:InitEvent()
  101. local function onBtnClickHandler(target)
  102. if target == self.left_obj then
  103. self:OnClickLeft()
  104. elseif target == self.right_obj then
  105. self:OnClickRight()
  106. elseif target == self.close_btn_obj then
  107. self:Close()
  108. elseif target == self.continue_btn_obj then
  109. self:Close()
  110. elseif target == self.get_btn_obj then
  111. if self.data then
  112. self.model:Fire(TaskAnnounceModel.REQUEST_CCMD_EVENT, 18201, self.data.id)
  113. end
  114. elseif target == self.jum_btn_obj then
  115. if self.data then
  116. local jump_info = self.data and self.data.jump or ""
  117. local jump_info = stringtotable(jump_info)
  118. if jump_info and jump_info[1] and jump_info[2] then
  119. self:Close()
  120. OpenFun.Open(tonumber(jump_info[1]), tonumber(jump_info[2]))
  121. end
  122. end
  123. end
  124. end
  125. AddClickEvent(self.close_btn_obj,onBtnClickHandler)
  126. AddClickEvent(self.left_obj,onBtnClickHandler)
  127. AddClickEvent(self.right_obj,onBtnClickHandler)
  128. AddClickEvent(self.get_btn_obj,onBtnClickHandler)
  129. AddClickEvent(self.jum_btn_obj,onBtnClickHandler)
  130. AddClickEvent(self.continue_btn_obj,onBtnClickHandler)
  131. local function onUpdateView()
  132. if self._use_delete_method then return end
  133. self.has_open = false
  134. self:UpdateView()
  135. self:UpdateCenter()
  136. self.model:GetRewardByIndexSide(nil,nil, true)
  137. end
  138. self.update_view_id = self.model:Bind(TaskAnnounceModel.UPDATE_ANNOUNCE_VIEW, onUpdateView)
  139. end
  140. function TaskAnnounceView:UpdateView()
  141. self.model:GetRewardByIndexSide(nil,nil, true)
  142. local list = self.model:GetTaskAnnounceListInView()
  143. local open_day = ServerTimeModel:getInstance():GetOpenServerDay()
  144. self.continue_btn_obj:SetActive(false)
  145. self.continue_tips_obj:SetActive(false)
  146. self.reward_con_obj:SetActive(true)
  147. --只展示一个特殊的样式
  148. if self.open_id and list and #list > 0 then
  149. local t = false
  150. for i,v in ipairs(list) do
  151. if v.id == self.open_id then
  152. t = v
  153. break
  154. end
  155. end
  156. if t then
  157. self.data_list = {[1] = t}
  158. self.data_list_num = 1
  159. self.right_obj:SetActive(false)
  160. self.right_red_dot_obj:SetActive(false)
  161. self.left_obj:SetActive(false)
  162. self.left_red_dot_obj:SetActive(false)
  163. self.ScrollView_obj:SetActive(false)
  164. self.reward_con_obj:SetActive(false)
  165. self.continue_btn_obj:SetActive(true)
  166. self.continue_tips_obj:SetActive(true)
  167. else
  168. self.data_list = list
  169. self.data_list_num = #list or 0
  170. end
  171. else
  172. self.data_list = list
  173. self.data_list_num = #list or 0
  174. end
  175. -- self.data_list = list
  176. -- self.data_list_num = #list or 0
  177. if list then
  178. if not self.item_list then
  179. self.item_list = {}
  180. local click_call_back = function (idx)
  181. self:SelectItem(idx)
  182. end
  183. for i = 1, self.show_count do
  184. local item = self.item_list[i]
  185. if item == nil then
  186. item = TaskAnnounceItem.New(self.parent)
  187. item:SetClickCallBack(click_call_back)
  188. self.item_list[i] = item
  189. end
  190. end
  191. end
  192. local function wrap_callback()
  193. self:WrapContent()
  194. end
  195. self.loop_mgr:Init(self.ScrollView, self.Content, self.column_num, 230 , 130, function(item,index,realIndex)
  196. if item and realIndex > 0 and realIndex <= #list then
  197. item:SetData(realIndex, list[realIndex], self.mask_id)
  198. item:SetSelect(realIndex == self.cur_select)
  199. end
  200. end, nil,nil,nil, wrap_callback)
  201. if not self.has_open then
  202. self.loop_mgr:InitChildren(self.item_list, #list)
  203. self.loop_mgr:RestToBeginning()
  204. self.loop_mgr:SetContentSizeData()
  205. local index
  206. local is_open = false
  207. for k,v in pairs(list) do
  208. if v and v.has_open and ((not index) or (index and k >= index)) then
  209. index = k
  210. if self.model:GetRewardData(v.id) == 1 then
  211. break
  212. end
  213. end
  214. if v and not v.has_open then
  215. index = k
  216. break
  217. else
  218. is_open = true
  219. end
  220. end
  221. if not index then
  222. index = is_open and #self.data_list_num - 3 or 1
  223. end
  224. if index then
  225. index = index > (self.data_list_num - 3) and self.data_list_num - 3 or index
  226. index = index < 1 and 1 or index
  227. self.loop_mgr:JumpToChild(index - 1)
  228. self:SelectItem(index)
  229. end
  230. else
  231. self.loop_mgr:InitChildren(self.item_list, #list)
  232. self.loop_mgr:ForceUpdateCurrentItems()
  233. self.loop_mgr:SetContentSizeData()
  234. end
  235. self.has_open = true
  236. end
  237. end
  238. function TaskAnnounceView:Clear()
  239. if self.item_list then
  240. for k,v in pairs(self.item_list) do
  241. v:DeleteMe()
  242. v = nil
  243. end
  244. self.item_list = false
  245. end
  246. for k,v in pairs(self.reward_item_list) do
  247. v:ReleaseObj()
  248. end
  249. self.reward_item_list = {}
  250. if self.loop_mgr then
  251. self.loop_mgr:DeleteMe()
  252. self.loop_mgr = nil
  253. end
  254. if self.update_view_id then
  255. self.model:UnBind(self.update_view_id)
  256. self.update_view_id = nil
  257. end
  258. self:ClearUIEffect(self.rt_item)
  259. lua_resM:clearRoleMode(self)
  260. end
  261. function TaskAnnounceView:SelectItem(idx)
  262. if self.cur_select ~= idx then
  263. self.cur_select = idx
  264. for i,v in ipairs(self.item_list) do
  265. v:SetSelect(v:GetItemIdx() == self.cur_select)
  266. end
  267. self:UpdateCenter()
  268. end
  269. end
  270. function TaskAnnounceView:WrapContent()
  271. if self.data_list_num and self.data_list_num >= 4 then
  272. local x = GetAnchoredPosition(self.Content)
  273. local left_b = x < -229
  274. local right_b = x > -229 * (self.data_list_num - 5)
  275. self.left_obj:SetActive(left_b)
  276. self.right_obj:SetActive(right_b)
  277. local idx = math.ceil(math.abs( x / 229))
  278. local left_idx = idx
  279. local right_idx = idx + 4
  280. self.left_red_dot_obj:SetActive(left_b and self.model:GetRewardByIndexSide(left_idx, true))
  281. self.right_red_dot_obj:SetActive(right_b and self.model:GetRewardByIndexSide(right_idx))
  282. end
  283. end
  284. function TaskAnnounceView:OnClickLeft()
  285. local x = GetAnchoredPosition(self.Content)
  286. if x >= -229 * 4 then
  287. self.loop_mgr:JumpToChild(1)
  288. else
  289. local index = math.ceil(- x / 229 )
  290. index = index - 4
  291. self.loop_mgr:JumpToChild(index)
  292. end
  293. end
  294. function TaskAnnounceView:OnClickRight()
  295. local x = GetAnchoredPosition(self.Content)
  296. if x <= -229 * (self.data_list_num - 4) then
  297. self.loop_mgr:JumpToChild((self.data_list_num - 4))
  298. else
  299. local index = math.floor(- x / 229 )
  300. index = index + 5
  301. self.loop_mgr:JumpToChild(index)
  302. end
  303. end
  304. function TaskAnnounceView:CancelHide()
  305. BaseView.CancelHide(self)
  306. self:UpdateCenter()
  307. end
  308. function TaskAnnounceView:UpdateCenter()
  309. if self.data_list and self.cur_select then
  310. self.data = self.data_list[self.cur_select]
  311. self:StopOpenFunTweenAnimation()
  312. if self.data then
  313. self.desc_tmp.text = Trim(self.data.func_desc)
  314. self.tips_tmp.text = self.data.has_open and HtmlColorTxt("已开放", "#2cf86f") or Trim(self.data.con_desc)
  315. local task_tip = {}
  316. task_tip[1] = Trim(self.data.mod_desc1)
  317. task_tip[2] = Trim(self.data.mod_desc2)
  318. for i,v in ipairs(task_tip) do
  319. if v == "" then
  320. self.task_tip_table[i].dot:SetActive(false)
  321. self.task_tip_table[i].txt.text = ""
  322. else
  323. self.task_tip_table[i].dot:SetActive(true)
  324. self.task_tip_table[i].txt.text = v
  325. end
  326. end
  327. local icon_res = Trim(self.data.title_pic)
  328. lua_resM:setOutsideImageSprite(self, self.title_img_img, GameResPath.GetTaskAnnounce(icon_res), true)
  329. if self.data.reward and self.data.reward ~= "" then
  330. local reward = ErlangParser:GetInstance():Parse(self.data.reward)
  331. for k,v in pairs(reward) do
  332. local item = self.reward_item_list[k]
  333. if item == nil then
  334. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_con, nil, self.layer_name)
  335. self.reward_item_list[k] = item
  336. end
  337. item:SetData(v[2], v[3], nil, nil, nil, nil, nil, self.mask_id)
  338. item:SetVisible(true)
  339. item:SetItemSize(62,62)
  340. end
  341. else
  342. for k,v in pairs(self.reward_item_list) do
  343. if v then
  344. v:SetVisible(false)
  345. end
  346. end
  347. end
  348. if self.data.icon and self.data.icon ~= 0 then
  349. self:StartOpenFunTweenAnimation()
  350. local call_back = function ( ... )
  351. local size_x, size_y = GetSizeDeltaXY(self.icon.transform)
  352. if size_x < 100 or size_y < 100 then
  353. SetLocalScale(self.icon.transform, 1.4, 1.4, 1.4)
  354. else
  355. --SetLocalScale(self.icon.transform, 1, 1, 1)
  356. SetLocalScale(self.icon.transform, 0.7, 0.7, 0.7)
  357. end
  358. end
  359. -- SetAnchoredPosition(self.icon.transform, -144, 39)
  360. self.icon.gameObject:SetActive(true)
  361. lua_resM:setOutsideImageSprite(self, self.icon_img, GameResPath.GetTaskAnnounce("task_announce_icon_" .. self.data.icon), true, call_back)
  362. else
  363. self.icon.gameObject:SetActive(false)
  364. end
  365. self:ClearUIEffect(self.rt_item)
  366. lua_resM:clearRoleMode(self)
  367. local fashion_type
  368. if self.data.model_res and self.data.model_res ~= 0 and Trim(self.data.model_res) ~= "" then
  369. self.rt_item_obj:SetActive(true)
  370. local model_data = stringtotable(Trim(self.data.model_res))
  371. fashion_type = tonumber(model_data[1])
  372. local figure_id = tonumber(model_data[2])
  373. local position = Vector3(0,0,0)
  374. local scale = 1
  375. local action_name_list = {"show"}
  376. if fashion_type == 1004 then -- 武器
  377. action_name_list = {"show3"}
  378. end
  379. local style
  380. --武器要根据每个职业自己的位置
  381. if fashion_type == 1004 then
  382. local career = RoleManager.Instance.mainRoleInfo.career
  383. style = TaskAnnounceModel.WeaponUIStyle[career]
  384. --如果是龙神宝库,虽然也是坐骑类型,但是这个坐骑比较大,特殊设置把
  385. elseif self.data.id == 47 then
  386. style = TaskAnnounceModel.TAViewUIStyle[9999]
  387. else
  388. style = TaskAnnounceModel.TAViewUIStyle[fashion_type]
  389. end
  390. if style then
  391. scale = tonumber(style[1])
  392. position = Vector3(style[2],style[3],style[4])
  393. else
  394. print("功能预告没有设置模型展示参数 类型 ", fashion_type)
  395. scale = 300
  396. position = Vector3(0,0, 0)
  397. end
  398. if fashion_type == 1301 then
  399. self.rt_item.localRotation = Quaternion.Euler(-25, 0, 0)
  400. else
  401. self.rt_item.localRotation = Quaternion.Euler(0, 0, 0)
  402. end
  403. SetLocalPositionZ(self.rt_item, -2000)
  404. local res_data = {
  405. father_node = self,
  406. transform = self.rt_item,
  407. fashion_type = fashion_type,
  408. figure_id = figure_id,
  409. action_name_list = action_name_list,
  410. size = Vector2(1280,720),
  411. scale = scale,
  412. position = position,
  413. show_shadow = true,
  414. rotate = 0,
  415. ui_model_type = UIModelCommon.ModelType.BackModel,
  416. }
  417. FuncOpenModel:getInstance():SetModelRes(res_data)
  418. else
  419. self.rt_item_obj:SetActive(false)
  420. end
  421. self:UpdateState()
  422. end
  423. end
  424. end
  425. function TaskAnnounceView:StartOpenFunTweenAnimation()
  426. local call_fun = function ()
  427. local function onCompleted()
  428. self:StartOpenFunTweenAnimation()
  429. end
  430. self.oepn_func_tween_id2 =TweenLite.to(self, self.icon.transform,TweenLite.UiAnimationType.POSY, 73+ 10,1,onCompleted)
  431. end
  432. self.oepn_func_tween_id1 =TweenLite.to(self, self.icon.transform,TweenLite.UiAnimationType.POSY, 73 - 10, 1, call_fun)
  433. end
  434. function TaskAnnounceView:StopOpenFunTweenAnimation()
  435. if self.oepn_func_tween_id1 then
  436. TweenLite.Stop(self.oepn_func_tween_id1)
  437. self.oepn_func_tween_id1 = nil
  438. end
  439. if self.oepn_func_tween_id2 then
  440. TweenLite.Stop(self.oepn_func_tween_id2)
  441. self.oepn_func_tween_id2 = nil
  442. end
  443. end
  444. function TaskAnnounceView:UpdateState()
  445. if self.data then
  446. local state = self.model:GetRewardData(self.data.id)
  447. self.get_btn_red_dot_obj:SetActive(state == 1)
  448. self.get_btn_obj:SetActive(state == 1)
  449. self.get_done_obj:SetActive(state == 2)
  450. self.jum_btn_obj:SetActive(state == 2)
  451. -- for i,v in ipairs(self.reward_item_list) do
  452. -- v:SetGray(not self.data.has_open or state ~= 1)
  453. -- end
  454. -- if state and self.item_list[1] then
  455. -- local callback = function()
  456. -- self.model:Fire(TaskAnnounceModel.REQUEST_CCMD_EVENT, 18201, self.data.id)
  457. -- end
  458. -- if state == 0 or not has_open then --不可领取
  459. -- self.item_list[1]:SetEnableClick(false)
  460. -- self.item_list[1]:SetRedDot(false)
  461. -- self.item_list[1]:SetCallBack(nil)
  462. -- elseif state == 1 then --未领取
  463. -- self.item_list[1]:SetEnableClick(true)
  464. -- self.item_list[1]:SetRedDot(true)
  465. -- self.item_list[1]:SetCallBack(callback)
  466. -- elseif state == 2 then --已领取
  467. -- self.item_list[1]:SetEnableClick(true)
  468. -- self.item_list[1]:SetStatueTips(true, "tyui_ylq", nil, true)
  469. -- self.item_list[1]:SetRedDot(false)
  470. -- self.item_list[1]:SetCallBack(nil)
  471. -- end
  472. -- else
  473. -- end
  474. end
  475. end
  476. function TaskAnnounceView:Close()
  477. BaseView.Close(self)
  478. end