源战役客户端
Você não pode selecionar mais de 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.

390 linhas
13 KiB

4 semanas atrás
  1. EscortSceneView = EscortSceneView or BaseClass(BaseView)
  2. local EscortSceneView = EscortSceneView
  3. --[[
  4. EscortSceneView.TabData = {
  5. [1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
  6. }
  7. --]]
  8. local table_sort = table.sort
  9. function EscortSceneView:__init()
  10. self.base_file = "escort"
  11. self.layout_file = "EscortSceneView"
  12. self.layer_name = "Main"
  13. self.destroy_imm = true
  14. self.use_background = false --全屏界面默认使用这个参数
  15. --self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  16. self.change_scene_close = true
  17. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  18. self.need_show_money = false --是否要显示顶部的金钱栏
  19. self.model = EscortModel:getInstance()
  20. self.cur_index = 1
  21. self.is_hide = false
  22. self.escort_reward_item = {}
  23. self.kill_info_list = {}
  24. self.load_callback = function ()
  25. self:LoadSuccess()
  26. self:AddEvent()
  27. end
  28. self.open_callback = function ( )
  29. self:OpenSuccess()
  30. end
  31. self.switch_callback = function(index)
  32. self:SwitchTab(index)
  33. end
  34. self.destroy_callback = function ( )
  35. self:DestroySuccess()
  36. end
  37. end
  38. function EscortSceneView:Open( )
  39. --self.data = data
  40. BaseView.Open(self)
  41. end
  42. function EscortSceneView:LoadSuccess()
  43. local nodes = {
  44. "base_con", "base_con/escort_btn:obj:img", "arrow_image",
  45. "hide_btn:obj","base_con/escort_btn/escort_btn_image:img",
  46. "downCon:obj", "downCon/go_btn:obj:img",
  47. "tip_con:obj",
  48. --运送con
  49. "base_con/escort_con/name_text:tmp", "base_con/escort_con/time_text:tmp", "base_con/escort_con/iconImg:img",
  50. "base_con/escort_con/escort_reward_con1", "base_con/escort_con/have_times_text:tmp",
  51. "base_con/escort_con:obj", "base_con/escort_con/lb1:tmp", "base_con/escort_con/desc_text:tmp",
  52. }
  53. self:GetChildren(nodes)
  54. -- self.time_limit = Config.Convoykv["convoy_overtime"].value_content
  55. self.lb1_tmp.text = "外送奖励"
  56. self.desc_text_tmp.text = "勤奋的外送员从不偷懒!\n外送至目的地可获得奖励"
  57. self.transform.sizeDelta = Vector3(ScreenWidth, ScreenHeight)
  58. SetAnchoredPosition(self.transform, 0, 0)
  59. self:ChangeUiPosition()
  60. self.model:SetEscortSceneViewOpen(true)
  61. ExpDunModel:getInstance():Fire(ExpDunModel.UPDATE_EXP_DUN_BTN)
  62. if not self.init_exit_btn then
  63. self.init_exit_btn = true
  64. local function call_back( ... )
  65. local is_escort = self.model:IsEscortState()
  66. local is_in_dun = SceneManager.Instance:IsEscortPVEDunScene()
  67. local function ok( ... )
  68. if is_escort then
  69. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50008)
  70. elseif is_in_dun then
  71. BaseDungeonModel:getInstance():Fire(BaseDungeonModel.REQUEST_CCMD_EVENT, 61002)
  72. else
  73. self.model:FlyToNpc()
  74. end
  75. end
  76. local ask_str = (is_escort or is_in_dun) and "\n放弃运送将会损失大量经验,确定吗?" or "即将返回主城,确定吗?"
  77. Alert.show(ask_str,Alert.Type.Two,ok,nil,"确定","取消")
  78. end
  79. local data = {call_back = call_back, pos = {x = 240,y = 310}} -- pos 为左侧侧边栏的长度
  80. GlobalEventSystem:Fire(EventName.SHOW_EXIT_BTN_STATE, data)
  81. end
  82. if self.model:GetEscortSceneLeftHideState() then--代表是展示了左边的东西 所以这里要隐藏
  83. self:SetHideState(true)
  84. end
  85. end
  86. function EscortSceneView:AddEvent()
  87. --适配刘海屏
  88. local function onOrientationChange()
  89. self:ChangeUiPosition()
  90. end
  91. self:BindEvent(GlobalEventSystem, EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
  92. local function on_update_stage_info( )
  93. self:UpdateView()
  94. end
  95. self.on_update_stage_info_id = self.model:BindOne("escort_stage_info", on_update_stage_info)
  96. local function on_ans_basic_info()
  97. -- print("Lizhijian:EscortSceneView [start:105]")
  98. if self.model:IsEscortState() and SceneManager.Instance:IsEscortAllScene() then
  99. self:UpdateReward()
  100. end
  101. end
  102. self:BindEvent(self.model, EscortConst.ANS_BASIC_INFO, on_ans_basic_info)
  103. self:BindEvent(self.model, EscortConst.CHANGE_LAST_DOUBLE, on_ans_basic_info)
  104. local function on_update_escort_state( ... )
  105. self:SetBtnState()
  106. end
  107. self.on_update_escort_state_id = self.model:BindOne("escort_base_info", on_update_escort_state)
  108. -- local function on_update_escort_btn( )
  109. -- self:UpdateEscortBtnState()
  110. -- end
  111. -- self:BindEvent(self.model, EscortConst.UPDATE_BUTTON_STATE, on_update_escort_btn)
  112. local function on_hide_left()
  113. self:SetHideState(self.model:GetEscortSceneLeftHideState())
  114. end
  115. self:BindEvent(self.model, EscortConst.UPDATE_ESCORT_LEFT_SHOW, on_hide_left)
  116. local function on_close_tip( ... )
  117. self:ShowEscortCarTip(false)
  118. end
  119. self:BindEvent(self.model, EscortConst.RUN_NEAR_CAR, on_close_tip)
  120. local function on_change_btn_state( )
  121. print("HWR:EscortSceneView [125]2323232: ",2323232)
  122. self:UpdateEscortBtnState()
  123. end
  124. self:BindEvent(GlobalEventSystem, AutoFightManager.CHANGE_AUTO_FIND_WAY_STATE, on_change_btn_state)
  125. local function on_click( target )
  126. if target == self.escort_btn_obj then
  127. if self.model:IsEscortState() or SceneManager.Instance:IsEscortPVEDunScene() then
  128. self:SwitchView(1)
  129. else
  130. Message.show("您目前没有在运送中哦~")
  131. self:SwitchView(2)
  132. end
  133. elseif target == self.hide_btn_obj then
  134. self:SetHideState(not self.is_hide)
  135. elseif target == self.go_btn_obj then
  136. if not self.model:IsFollowEscortCar() then
  137. self.model:GoEscortNpc()
  138. else
  139. self.model:SetEscortCarFollow(false)
  140. end
  141. end
  142. end
  143. AddClickEvent(self.escort_btn_obj, on_click)
  144. AddClickEvent(self.hide_btn_obj, on_click)
  145. AddClickEvent(self.go_btn_obj, on_click)
  146. -- self:BindLittleMove(self.go_btn, BaseView.LittleMoveDir.Bottom, -206.5)
  147. self:BindLittleMove(self.tip_con, BaseView.LittleMoveDir.Bottom, -98)
  148. self:BindLittleMove(self.downCon, BaseView.LittleMoveDir.Bottom, 310)
  149. self:BindLittleMove(self.base_con, BaseView.LittleMoveDir.Left, 0)
  150. self:BindLittleMove(self.hide_btn, BaseView.LittleMoveDir.Left, 0)
  151. self:BindLittleMove(self.arrow_image, BaseView.LittleMoveDir.Left, 20)
  152. -- 主界面聊天展开事件
  153. self:BindMainUIExpandEvent(self.downCon)
  154. end
  155. function EscortSceneView:SetHideState(bool)
  156. if self.is_do_action then
  157. return
  158. end
  159. if bool == self.is_hide then return end
  160. self.is_hide = bool
  161. self:DoMoveAnimation()
  162. end
  163. function EscortSceneView:DoMoveAnimation()
  164. if self.is_hide then
  165. self.is_do_action = true
  166. local function moveComplete()
  167. self:MoveOutOfScreen(self.base_con.transform)
  168. self.is_do_action = false
  169. end
  170. TweenLite.to(self, self.base_con, TweenLite.UiAnimationType.ANCHORED_POSX, -200, 0.2, moveComplete)
  171. self.arrow_image.transform.localRotation = Quaternion.Euler(0,0,180)
  172. else
  173. self.is_do_action = true
  174. local function moveComplete()
  175. self.is_do_action = false
  176. end
  177. TweenLite.to(self, self.base_con, TweenLite.UiAnimationType.ANCHORED_POSX, ClientConfig.iphone_x_offset_left, 0.2, moveComplete)
  178. self.arrow_image.transform.localRotation = Quaternion.Euler(0,0,0)
  179. self:MoveInToScreen(self.base_con.transform)
  180. end
  181. end
  182. function EscortSceneView:OpenSuccess()
  183. self:UpdateView()
  184. end
  185. function EscortSceneView:UpdateView()
  186. self:UpdateEscortTime()
  187. self:UpdateReward()
  188. self:SwitchView(self.cur_index)
  189. self:SetBtnState()
  190. self:UpdateEscortBtnState()
  191. end
  192. function EscortSceneView:UpdateDunInfo( )
  193. local dun_id = SceneManager:getInstance():GetCurrDunId()
  194. local wave_cfg = BaseDungeonModel:getInstance():GetDunWaveCfg(dun_id)
  195. local temp_mon_list = {}
  196. for i,v in ipairs(wave_cfg) do
  197. local mon_list = stringtotable(v.mon_list)
  198. local sort_func = function ( a, b )
  199. return a[1] < b[1]
  200. end
  201. table_sort(mon_list, sort_func)
  202. for kk, vv in ipairs(mon_list) do -- 一条数据就是一个怪
  203. temp_mon_list[vv[1]] = temp_mon_list[vv[1]] or 0
  204. temp_mon_list[vv[1]] = temp_mon_list[vv[1]] + 1
  205. end
  206. end
  207. local temp_one_mon_id = nil
  208. for i,v in pairs(temp_mon_list) do
  209. temp_one_mon_id = i
  210. break
  211. end
  212. end
  213. function EscortSceneView:SwitchView( index )
  214. self.cur_index = index
  215. if index == 1 then
  216. self.escort_con_obj:SetActive(true)
  217. lua_resM:setImageSprite(self, self.escort_btn_image_img, "escort_asset", "escort_icon6", true)
  218. self:UpdateReward()
  219. else
  220. self.escort_con_obj:SetActive(false)
  221. lua_resM:setImageSprite(self, self.escort_btn_image_img, "escort_asset", "escort_item7", true)
  222. end
  223. end
  224. function EscortSceneView:SetBtnState( )
  225. local is_escort = self.model:IsEscortState()
  226. self.go_btn_obj:SetActive(is_escort)
  227. local base_info = self.model:GetEscortBaseInfo()
  228. if TableSize(base_info) > 0 then
  229. self.have_times_text_tmp.text = string.format("剩余可接外送次数:<color=%s>%s次</color>",ColorUtil.YELLOW_DARK,self.model:GetMaxEscortTimes() - base_info.convoy_counts)
  230. lua_resM:setImageSprite(self, self.iconImg_img, "escort_asset", "escort_"..base_info.object_id)
  231. local cfg = Config.Convoyobject
  232. if cfg[base_info.object_id] then
  233. self.name_text_tmp.text = Trim(cfg[base_info.object_id].name)
  234. end
  235. end
  236. end
  237. function EscortSceneView:UpdateEscortTime( )
  238. if self.escort_timer_id then
  239. GlobalTimerQuest:CancelQuest(self.escort_timer_id)
  240. self.escort_timer_id = nil
  241. end
  242. local data = self.model:GetEscortBaseInfo()
  243. if TableSize(data) == 0 then return end
  244. self.end_time = data.end_time
  245. local left_time = math.max(0,self.end_time - TimeUtil:getServerTime())
  246. if left_time <= 0 then
  247. else
  248. local function onExitTimer()
  249. left_time = self.end_time - TimeUtil:getServerTime()
  250. if left_time > 0 then
  251. self.time_text_tmp.text = string.format("外送限时 <size=115%%>%s</size>",HtmlColorTxt(TimeUtil:timeConvert8(left_time), ColorUtil.GREEN_DARK))
  252. else
  253. GlobalTimerQuest:CancelQuest(self.escort_timer_id)
  254. self.escort_timer_id = nil
  255. end
  256. end
  257. self.escort_timer_id = GlobalTimerQuest:AddPeriodQuest(onExitTimer, 1, -1)
  258. end
  259. end
  260. function EscortSceneView:UpdateReward( )
  261. local data = self.model:GetStageRewardByType("escort")
  262. -- print("Lizhijian:EscortSceneView [start:280] ")
  263. -- PrintTable(data)
  264. -- PrintTable(self.model:GetEscortBaseInfo())
  265. -- print("Lizhijian:EscortSceneView [end:280] ")
  266. if TableSize(data) == 0 then
  267. return
  268. end
  269. local count = 1
  270. for i=1,1 do
  271. if data[i] then
  272. for ii,vv in ipairs(data[i]) do
  273. local item = self.escort_reward_item[count]
  274. if not item then
  275. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self["escort_reward_con1"])
  276. item:SetItemSize(62,62)
  277. item:SetNumForceShow(true)
  278. item:SetPosition((count-1)*80, 0)
  279. self.escort_reward_item[count] = item
  280. end
  281. item:SetData(vv[2],vv[3])
  282. count = count + 1
  283. end
  284. end
  285. end
  286. end
  287. function EscortSceneView:UpdateEscortBtnState( )
  288. if AutoFightManager:getInstance():GetAutoFindWayState() then
  289. lua_resM:setImageSprite(self, self.go_btn_img, "escort_asset", "escort_icon9")
  290. else
  291. lua_resM:setImageSprite(self, self.go_btn_img, "escort_asset", "escort_icon4")
  292. end
  293. end
  294. function EscortSceneView:ChangeUiPosition( )
  295. SetAnchoredPositionX(self.base_con.transform, ClientConfig.iphone_x_offset_left)
  296. SetAnchoredPositionX(self.arrow_image.transform, 19 + ClientConfig.iphone_x_offset_left)
  297. SetAnchoredPositionX(self.hide_btn.transform, -1 + ClientConfig.iphone_x_offset_left)
  298. end
  299. function EscortSceneView:ShowEscortCarTip( bool )
  300. if bool then
  301. self.tip_con_obj:SetActive(true)
  302. if self.delay_tip_id then
  303. TimerQuest.CancelQuest(GlobalTimerQuest,self.delay_tip_id)
  304. self.delay_tip_id = nil
  305. end
  306. local function delay_method( )
  307. self:ShowEscortCarTip(false)
  308. end
  309. self.delay_tip_id = setTimeout(delay_method, 15)--倒数15秒消失
  310. else
  311. self.tip_con_obj:SetActive(false)
  312. if self.delay_tip_id then
  313. TimerQuest.CancelQuest(GlobalTimerQuest,self.delay_tip_id)
  314. self.delay_tip_id = nil
  315. end
  316. end
  317. end
  318. function EscortSceneView:DestroySuccess( )
  319. GlobalEventSystem:Fire(EventName.HIDE_EXIT_BTN_STATE)
  320. if self.kill_update_id then
  321. BaseDungeonModel:getInstance():UnBind(self.kill_update_id)
  322. self.kill_update_id = nil
  323. end
  324. if self.escort_timer_id then
  325. GlobalTimerQuest:CancelQuest(self.escort_timer_id)
  326. self.escort_timer_id = nil
  327. end
  328. if self.on_update_stage_info_id then
  329. self.model:UnBind(self.on_update_stage_info_id)
  330. self.on_update_stage_info_id = nil
  331. end
  332. if self.on_update_blood_id then
  333. self.model:UnBind(self.on_update_blood_id)
  334. self.on_update_blood_id = nil
  335. end
  336. if self.on_update_escort_state_id then
  337. self.model:UnBind(self.on_update_escort_state_id)
  338. self.on_update_escort_state_id = nil
  339. end
  340. if self.on_update_skill_btn_id then
  341. self.model:UnBind(self.on_update_skill_btn_id)
  342. self.on_update_skill_btn_id = nil
  343. end
  344. if self.change_icon_event_id then
  345. GlobalEventSystem:UnBind(self.change_icon_event_id)
  346. self.change_icon_event_id = nil
  347. end
  348. for i,v in ipairs(self.escort_reward_item) do
  349. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v)
  350. end
  351. self.escort_reward_item = {}
  352. self.model:SetEscortSceneViewOpen(false)
  353. ExpDunModel:getInstance():Fire(ExpDunModel.UPDATE_EXP_DUN_BTN)
  354. end