源战役客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

455 строки
14 KiB

4 недель назад
  1. CSGWarSceneView = CSGWarSceneView or BaseClass(BaseView)
  2. local CSGWarSceneView = CSGWarSceneView
  3. --[[
  4. CSGWarSceneView.TabData = {
  5. [1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
  6. }
  7. --]]
  8. function CSGWarSceneView:__init()
  9. self.base_file = "CSGWar"
  10. self.layout_file = "CSGWarSceneView"
  11. self.layer_name = "Main"
  12. self.destroy_imm = true
  13. self.use_background = false --全屏界面默认使用这个参数
  14. --self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  15. self.change_scene_close = false
  16. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  17. self.need_show_money = false --是否要显示顶部的金钱栏
  18. self.is_first = true
  19. self.is_show_order = false
  20. self.model = CSGWarModel:getInstance()
  21. self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60110)
  22. self.buff_item = {}
  23. self.has_show_dialog = false
  24. self.is_show_left_time = false
  25. self.city_list = {}
  26. self.order_list = {}
  27. self.load_callback = function ()
  28. self:LoadSuccess()
  29. end
  30. self.open_callback = function ( )
  31. self:OpenSuccess()
  32. end
  33. self.switch_callback = function(index)
  34. self:SwitchTab(index)
  35. end
  36. self.destroy_callback = function ( )
  37. self:DestroySuccess()
  38. end
  39. end
  40. function CSGWarSceneView:Open( )
  41. --self.data = data
  42. BaseView.Open(self)
  43. end
  44. function CSGWarSceneView:LoadSuccess()
  45. local nodes = {
  46. "left_con/time_text:tmp", "left_con/city_con", "left_con", "right_con",
  47. "middle_con/order_con:obj", "middle_con:obj", "middle_con/btnCon/order_btn:obj", "middle_con/btnCon/defend_btn:obj", "middle_con/btnCon/attack_btn:obj",
  48. "right_con/instruction_btn:obj", "right_con/exit_btn:obj",
  49. }
  50. self:GetChildren(nodes)
  51. self:AddEvent()
  52. self.country = KfWorldModel:GetInstance():GetMyCountryId()
  53. SetAnchoredPosition(self.transform, 0, 0)
  54. self.transform.sizeDelta = Vector3(ScreenWidth, ScreenHeight)
  55. SetAnchoredPositionX(self.instruction_btn, -134)
  56. self:ChangeUiPosition()
  57. self.model:Fire(CSGWarConst.OPEN_CSGWAR_INSTRUCTION_VIEW, true)
  58. self.exit_btn_obj:SetActive(false)
  59. if not self.init_exit_btn then
  60. self.init_exit_btn = true
  61. local function call_back( ... )
  62. local ok = function ( )
  63. self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60109)
  64. end
  65. Alert.show("即将退出跨国团战,是否确定?",Alert.Type.Two,ok)
  66. end
  67. local data = {call_back = call_back, pos = {x = 196,y = 275}} -- pos 为左侧侧边栏的长度
  68. GlobalEventSystem:Fire(EventName.SHOW_EXIT_BTN_STATE, data)
  69. end
  70. end
  71. function CSGWarSceneView:AddEvent()
  72. --适配刘海屏
  73. local function onOrientationChange()
  74. self:ChangeUiPosition()
  75. end
  76. self.orientation_change_id = GlobalEventSystem:Bind(EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
  77. local function changeFunc(is_hide)
  78. -- self.exit_btn_obj:SetActive(is_hide)
  79. self.instruction_btn_obj:SetActive(is_hide)
  80. end
  81. self.change_icon_event_id = GlobalEventSystem:Bind(EventName.CHANGE_RIGHT_TIP_ICON, changeFunc)
  82. local function on_update_blood( )
  83. self:UpdateCityBlood()
  84. end
  85. self.on_update_blood_id = self.model:Bind(CSGWarConst.UPDATE_CSGWAR_CITY_INFO, on_update_blood)
  86. local function on_update_btn_state( )
  87. self:UpdateOrderBtn()
  88. end
  89. self.on_update_btn_state_id = self.model:BindOne("CSGWar_sign_info", on_update_btn_state)
  90. local function on_show_command( id )
  91. if id then
  92. local cfg = Config.Crossguildwarscene[id]
  93. local str = string.format("团长下令:请火速赶往%s", cfg.name)
  94. local special_tip_data = {
  95. type = SpecialTipType.Middle,
  96. sepeical_str = str,
  97. need_flash = true,
  98. show_time = 10,
  99. }
  100. CommonController.Instance:Fire(EventName.OPEN_SPECIALTIPVIEW, special_tip_data)
  101. local temp_head_name = RoleManager.Instance.mainRoleInfo.name
  102. -- local str = string.format("团长下令全员前往%s!", cfg.name)
  103. -- local data = {
  104. -- head_type = 1004,
  105. -- desc = str,
  106. -- head_name = temp_head_name or "",
  107. -- hide_time = 15,
  108. -- dalay_time = 1,
  109. -- is_task_type = true,
  110. -- pos = Vector3(230,0,0),
  111. -- }
  112. -- GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
  113. end
  114. end
  115. self.on_show_command_id = self.model:Bind(CSGWarConst.SHOW_CSGWAR_COMMAND, on_show_command)
  116. local function on_click( target )
  117. if self.order_btn_obj == target then
  118. self.is_show_order = not self.is_show_order
  119. self:ShowOrderCon(self.is_show_order)
  120. elseif self.exit_btn_obj == target then
  121. local ok = function ( )
  122. self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60109)
  123. end
  124. Alert.show("即将退出跨国团战,是否确定?",Alert.Type.Two,ok)
  125. elseif self.defend_btn_obj == target then
  126. self:GoNearestCity(false,1)
  127. elseif self.attack_btn_obj == target then
  128. self:GoNearestCity(true,2)
  129. elseif self.instruction_btn_obj == target then
  130. self.model:Fire(CSGWarConst.OPEN_CSGWAR_INSTRUCTION_VIEW)
  131. end
  132. end
  133. AddClickEvent(self.order_btn_obj, on_click)
  134. AddClickEvent(self.exit_btn_obj, on_click)
  135. AddClickEvent(self.defend_btn_obj, on_click)
  136. AddClickEvent(self.attack_btn_obj, on_click)
  137. AddClickEvent(self.instruction_btn_obj, on_click)
  138. self:BindLittleMove(self.middle_con, BaseView.LittleMoveDir.Bottom, 147.5)
  139. self:BindLittleMove(self.left_con, BaseView.LittleMoveDir.Left, 0)
  140. self:BindLittleMove(self.right_con, BaseView.LittleMoveDir.Right, 0)
  141. -- 主界面聊天展开事件
  142. self:BindMainUIExpandEvent( self.middle_con )
  143. end
  144. --寻路到最近的城
  145. function CSGWarSceneView:GoNearestCity( is_attack,go_type )
  146. local data = self.model:GetCSGWarCityInfo()
  147. local has_city = self:HasOccupy(data)
  148. local near_index = nil
  149. local cfg = Config.Crossguildwarscene
  150. local main_role = Scene.Instance:GetMainRole()
  151. local main_role_pos = CoVector2.New(main_role.real_pos.x,main_role.real_pos.y)
  152. local near_pos = 9999999
  153. local dis = 0
  154. local city_pos = CoVector2.New(0,0)
  155. local temp_pos = {}
  156. for i,v in ipairs(cfg) do
  157. --如果没有占领城 就不去核心城了
  158. if not has_city and i == 1 then
  159. else
  160. local need_cal = false
  161. local city_data = data[i]
  162. if city_data then
  163. if self.country == city_data.group and city_data.group ~= 0 then
  164. --如果是自己的城 且不是攻击才参与计算距离
  165. need_cal = not is_attack
  166. else
  167. --如果不是自己的城 且是攻击才参与计算距离
  168. need_cal = is_attack
  169. end
  170. end
  171. if need_cal then--经过上面的判断才知道符不符合条件
  172. temp_pos = stringtotable(v.flag)
  173. city_pos.x = temp_pos[2]
  174. city_pos.y = temp_pos[3]
  175. dis = CoVector2.distance(main_role_pos,city_pos)
  176. if dis < near_pos then
  177. near_pos = dis
  178. near_index = i
  179. end
  180. end
  181. end
  182. end
  183. if near_index then
  184. local city_pos = cfg[near_index].city_pos
  185. if not city_pos then
  186. city_pos = stringtotable(cfg[near_index].flag)
  187. end
  188. local function call_back( ... )
  189. GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
  190. end
  191. local findVo = FindVo.New()
  192. findVo.sceneId = SceneManager.Instance:GetSceneId()
  193. findVo.type = FindVo.POINT
  194. findVo.x = city_pos[2]/ SceneObj.LogicRealRatio.x
  195. findVo.y = city_pos[3]/ SceneObj.LogicRealRatio.y
  196. findVo.call_back = call_back
  197. GlobalEventSystem:Fire(EventName.FIND,findVo)
  198. if go_type == 1 then
  199. Message.show("准备前往我方城池进行守卫!")
  200. elseif go_type == 2 then
  201. Message.show("准备前往敌方城池进行攻击!")
  202. end
  203. else
  204. local str = ""
  205. if is_attack then
  206. str = "太厉害了!您已经占领了全部地区!"
  207. else
  208. str = "您现在没有占领任何地区!"
  209. end
  210. Message.show(str)
  211. end
  212. end
  213. function CSGWarSceneView:ChangeUiPosition( )
  214. SetAnchoredPositionX(self.right_con.transform, -ClientConfig.iphone_x_offset_right)
  215. SetAnchoredPosition(self.left_con.transform, ClientConfig.iphone_x_offset_left, -169)
  216. end
  217. function CSGWarSceneView:OpenSuccess()
  218. self:UpdateView()
  219. end
  220. function CSGWarSceneView:UpdateView()
  221. self:UpdateCityBlood()
  222. self:UpdateOrderBtn()
  223. self:StartLeftTime()
  224. self:UpdateOccupyBuff()
  225. end
  226. function CSGWarSceneView:SwitchTab( index )
  227. end
  228. function CSGWarSceneView:UpdateCityBlood( )
  229. local near_index = nil
  230. if self.is_first then
  231. self.is_first = false
  232. local cfg = Config.Crossguildwarscene
  233. local main_role = Scene.Instance:GetMainRole()
  234. local main_role_pos = CoVector2.New(main_role.real_pos.x,main_role.real_pos.y)
  235. local near_pos = 9999999
  236. local dis = 0
  237. local city_pos = CoVector2.New(0,0)
  238. local temp_pos = {}
  239. for i,v in ipairs(cfg) do
  240. temp_pos = stringtotable(v.flag)
  241. city_pos.x = temp_pos[2]
  242. city_pos.y = temp_pos[3]
  243. dis = CoVector2.distance(main_role_pos,city_pos)
  244. if dis < near_pos then
  245. near_pos = dis
  246. near_index = i
  247. end
  248. end
  249. end
  250. local select_callback = function( index )
  251. for i,v in ipairs(self.city_list) do
  252. v:SetSelected(i == index)
  253. end
  254. end
  255. local data = self.model:GetCSGWarCityInfo()
  256. local has_city = self:HasOccupy(data)
  257. local y_offset = 48
  258. for i=1,5 do
  259. local item = self.city_list[i]
  260. if not item then
  261. item = CSGWarCityItem.New(self.city_con)
  262. item:SetPosition(0, -(i-1)*y_offset)
  263. self.city_list[i] = item
  264. end
  265. item:SetData(data[i], i, has_city, near_index, select_callback)
  266. end
  267. end
  268. --获取本阵营是否有占领某一个副城
  269. function CSGWarSceneView:HasOccupy( data )
  270. local bool = false
  271. for i=1,5 do
  272. if data[i] then
  273. if data[i].group ~= 0 and data[i].group == self.country then
  274. bool = true
  275. break
  276. end
  277. end
  278. end
  279. return bool
  280. end
  281. function CSGWarSceneView:StartLeftTime()
  282. if self.exit_timer_id then
  283. GlobalTimerQuest:CancelQuest(self.exit_timer_id)
  284. self.exit_timer_id = nil
  285. end
  286. local data = self.model:GetCSGWarBaseInfo()
  287. if TableSize(data) == 0 then return end
  288. local left_time = math.max(0,data.etime - TimeUtil:getServerTime())
  289. if left_time <= 0 then
  290. else
  291. local function onExitTimer()
  292. left_time = data.etime - TimeUtil:getServerTimeMs() / 1000
  293. if left_time <= 300 and not self.has_show_dialog then
  294. self:ShowTimeDialog()
  295. end
  296. if left_time <= 15 then
  297. self:ShowLeftTime(left_time)
  298. end
  299. if left_time > 0 then
  300. self.time_text_tmp.text = string.format("活动剩余时间:%s",HtmlColorTxt(TimeUtil:convertMillisecondTime(left_time), ColorUtil.GREEN_DARK))
  301. else
  302. if self.exit_timer_id then
  303. GlobalTimerQuest:CancelQuest(self.exit_timer_id)
  304. self.exit_timer_id = nil
  305. end
  306. end
  307. end
  308. onExitTimer()
  309. self.exit_timer_id = GlobalTimerQuest:AddPeriodQuest(onExitTimer, 0.03, -1)
  310. end
  311. end
  312. function CSGWarSceneView:ShowLeftTime( left_time )
  313. if self.is_show_left_time then
  314. return
  315. end
  316. self.is_show_left_time = true
  317. left_time = math.floor(left_time)
  318. local data = {
  319. time = left_time,
  320. time_str = "秒后",
  321. exit_desc = "自动退出",
  322. }
  323. GlobalEventSystem:Fire(EventName.OPEN_EXIT_TIME_TIP, data, true)
  324. end
  325. function CSGWarSceneView:ShowTimeDialog( )
  326. if self.has_show_dialog then
  327. return
  328. end
  329. local temp_head_name = RoleManager.Instance.mainRoleInfo.name
  330. local str = "这是最后的时刻了!一定要拿下核心区!"
  331. local data = {
  332. head_type = 1004,
  333. desc = str,
  334. head_name = temp_head_name or "",
  335. hide_time = 15,
  336. dalay_time = 1,
  337. is_task_type = true,
  338. pos = Vector3(230,0,0),
  339. }
  340. GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
  341. self.has_show_dialog = true
  342. end
  343. function CSGWarSceneView:UpdateOrderBtn( )
  344. local my_guild_id = RoleManager.Instance.mainRoleInfo.guild_id
  345. local is_fight_guild = self.model:IsCSGWarFightGuild(my_guild_id)
  346. local is_leader = RoleManager.Instance.mainRoleInfo.position == GuildModel.GuildPosition.Leader or RoleManager.Instance.mainRoleInfo.position == GuildModel.GuildPosition.ViceLeader
  347. self.order_btn_obj:SetActive(is_fight_guild and is_leader)
  348. if is_fight_guild and is_leader then
  349. else
  350. self:ShowOrderCon(false)
  351. end
  352. end
  353. function CSGWarSceneView:ShowOrderCon( bool )
  354. self.order_con_obj:SetActive(bool)
  355. if bool and TableSize(self.order_list) == 0 then
  356. local y_offset = 36
  357. for i=1,5 do
  358. local item = self.order_list[i]
  359. if not item then
  360. item = CSGWarOrderItem.New(self.order_con)
  361. item:SetPosition(0, -y_offset*(i-1))
  362. item:SetData(i)
  363. self.order_list[i] = item
  364. end
  365. end
  366. end
  367. end
  368. function CSGWarSceneView:UpdateOccupyBuff( )
  369. local data = SandTableModel:getInstance():GetBuffListByFaction(self.country)
  370. local x_offset = 114
  371. local y_offset = 120
  372. for i,v in ipairs(data) do
  373. local item = self.buff_item[i]
  374. if not item then
  375. item = CSGWarBuffItem.New(self.right_con)
  376. item:SetPosition(-((i-1)%2)*x_offset,math.floor((i-1)/2)*y_offset)
  377. self.buff_item[i] = item
  378. end
  379. item:SetData(i,v)
  380. end
  381. -- print("HWR:CSGWarSceneView [start:357] data:", data)
  382. -- PrintTable(data)
  383. -- print("HWR:CSGWarSceneView [end]")
  384. end
  385. function CSGWarSceneView:DestroySuccess( )
  386. GlobalEventSystem:Fire(EventName.HIDE_EXIT_BTN_STATE)
  387. if self.orientation_change_id then
  388. GlobalEventSystem:UnBind(self.orientation_change_id)
  389. self.orientation_change_id = nil
  390. end
  391. if self.change_icon_event_id then
  392. GlobalEventSystem:UnBind(self.change_icon_event_id)
  393. self.change_icon_event_id = nil
  394. end
  395. if self.exit_timer_id then
  396. GlobalTimerQuest:CancelQuest(self.exit_timer_id)
  397. self.exit_timer_id = nil
  398. end
  399. if self.on_update_blood_id then
  400. self.model:UnBind(self.on_update_blood_id)
  401. self.on_update_blood_id = nil
  402. end
  403. if self.on_show_command_id then
  404. self.model:UnBind(self.on_show_command_id)
  405. self.on_show_command_id = nil
  406. end
  407. for i,v in ipairs(self.city_list) do
  408. v:DeleteMe()
  409. v = nil
  410. end
  411. self.city_list = {}
  412. for i,v in ipairs(self.order_list) do
  413. v:DeleteMe()
  414. v = nil
  415. end
  416. self.order_list = {}
  417. if self.on_update_btn_state_id then
  418. self.model:UnBind(self.on_update_btn_state_id)
  419. self.on_update_btn_state_id = nil
  420. end
  421. for i,v in ipairs(self.buff_item) do
  422. v:DeleteMe()
  423. v = nil
  424. end
  425. self.buff_item = {}
  426. -- 清除横幅
  427. GlobalEventSystem:Fire(EventName.OPEN_EXIT_TIME_TIP, nil, false)
  428. CommonController.Instance:Fire(EventName.CLOSE_SPECIALTIPVIEW)
  429. end