源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

314 行
11 KiB

  1. CSMainBaseView = CSMainBaseView or BaseClass(BaseView)
  2. local CSMainBaseView = CSMainBaseView
  3. function CSMainBaseView:__init()
  4. self.base_file = "csMain"
  5. self.layout_file = "CSMainBaseView"
  6. self.layer_name = "UI"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.change_scene_close = true
  10. self.hide_maincancas = true --是否隐藏主界面
  11. self.append_to_ctl_queue = true --是否要添加进界面堆栈
  12. self.need_show_money = false --是否要显示顶部的金钱栏
  13. self.close_fog = true
  14. self.is_set_zdepth = true
  15. self.full_screen = true
  16. self.need_culling_mask_ground = true --打开界面是否需要摄像机剔除ground层
  17. -- self.fire_change_visible_event = true
  18. self.hide_clear_role_model = false
  19. self.model = CSMainModel:getInstance()
  20. self.current_index = nil
  21. self.anim_time = 0.3
  22. self.role_show_item_list = {}
  23. self.load_callback = function ()
  24. self:LoadSuccess()
  25. self:AddEvent()
  26. self.model:Fire(CSMainConst.REQUEST_CCMD_EVENT,60300)
  27. --切换背景音乐
  28. self.last_scene_sound = lua_soundM.cur_scene_sound
  29. if lua_soundM:StopBacksound() then
  30. lua_soundM.last_backgound_abName = false
  31. end
  32. lua_soundM:PlayBackgroundSound("field2", LuaSoundManager.SOUND_TYPE.SCENE, true)
  33. end
  34. self.open_callback = function ( )
  35. self:OpenSuccess()
  36. end
  37. self.destroy_callback = function ( )
  38. self:DestroySuccess()
  39. --恢复背景音乐
  40. local cur_scene_sound = self.last_scene_sound
  41. if cur_scene_sound then
  42. if lua_soundM:StopBacksound() then
  43. lua_soundM.last_backgound_abName = false
  44. end
  45. lua_soundM:PlayBackgroundSound(cur_scene_sound, LuaSoundManager.SOUND_TYPE.SCENE, true)
  46. end
  47. end
  48. end
  49. function CSMainBaseView:Open()
  50. BaseView.Open(self)
  51. end
  52. function CSMainBaseView:LoadSuccess()
  53. local nodes = {
  54. "helpBtn:obj", "rightBtnCon/taskBtn:obj", "closeBtn:obj", "modelCon", "rightBtnCon/militaryRanksBtn:obj", "bg:raw", "rightBtnCon/exploitBtn:obj", "rightBtnCon",
  55. "sandTableBtn:obj", "appointBtn:obj", "sandTableBtn/sanTableImg:img",
  56. "rightBtnCon/taskBtn/taskRed:obj", "rightBtnCon/exploitBtn/exploitRed:obj", "rightBtnCon/militaryRanksBtn/militaryRed:obj", "appointBtn/appointRed:obj",
  57. "sandTableBtn/sandRed:obj",
  58. "rightBtnCon/sandTableBtn2:obj", "rightBtnCon/sandTableBtn2/sandTableRed2:obj",
  59. "titleImg1", "titleLabel", "titleImg2", "roleLabel",
  60. "appointTitle:img",
  61. "con_money", "con_money/num_money:tmp", "con_money/add_btn_money:obj", "con_money/des_score:tmp", "con_money/di_money2", "con_money/di_money",
  62. }
  63. self:GetChildren(nodes)
  64. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("cs_main_command_bg"))
  65. lua_resM:setOutsideImageSprite(self, self.sanTableImg_img, GameResPath.GetCSMainImage("cs_main_command_sand_table"))
  66. lua_resM:setOutsideImageSprite(self, self.appointTitle_img, GameResPath.GetCSMainImage("cs_main_appoint_out_title"))
  67. SetSizeDelta(self.transform, ScreenWidth, ScreenHeight)
  68. self:SetIpxMode()
  69. -- SetLocalPositionZ(self.sandTableBtn,-1000)
  70. local function bg_back_func( ... )
  71. if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
  72. self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
  73. end
  74. -- self:MoveUIToBack(self.tabWindowComponent.win_bg)
  75. self:MoveUIToBack(self.bg_raw)
  76. end
  77. if self.background_wnd then
  78. bg_back_func()
  79. else
  80. self.bg_back_func = bg_back_func
  81. end
  82. end
  83. function CSMainBaseView:AddEvent()
  84. local on_click = function ( click_obj )
  85. if self.closeBtn_obj == click_obj then--关闭
  86. self:Close()
  87. elseif self.helpBtn_obj == click_obj then--规则
  88. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 60301)
  89. elseif self.taskBtn_obj == click_obj then--任务
  90. self.model:Fire(CSMainConst.OPEN_CS_MAIN_TASK_VIEW)
  91. -- self:OpenTaskView()
  92. elseif self.militaryRanksBtn_obj == click_obj then--军衔
  93. self.model:Fire(CSMainConst.OPEN_CS_MAIN_MILITARY_RANKS_BSAE_VIEW)
  94. elseif self.exploitBtn_obj == click_obj then--军功排行
  95. self.model:Fire(CSMainConst.OPEN_CS_MAIN_EXPLOIT_RANK_VIEW)
  96. elseif self.appointBtn_obj == click_obj then--任命界面
  97. self.model:Fire(CSMainConst.OPEN_CS_MAIN_APPOINT_VIEW)
  98. elseif self.sandTableBtn_obj == click_obj then--沙盘入口
  99. SandTableModel:getInstance():Fire(SandTableConst.OPEN_MAIN_VIEW)
  100. elseif self.sandTableBtn2_obj == click_obj then--沙盘入口
  101. SandTableModel:getInstance():Fire(SandTableConst.OPEN_MAIN_VIEW)
  102. elseif click_obj == self.add_btn_money_obj then
  103. UIToolTipMgr:getInstance():AppendGoodsTips(SandTableModel:getInstance().dungeon_cost_id, nil, nil,nil,nil,nil,nil,true)
  104. end
  105. end
  106. AddClickEvent(self.closeBtn_obj, on_click)
  107. AddClickEvent(self.helpBtn_obj, on_click)
  108. AddClickEvent(self.taskBtn_obj, on_click)
  109. AddClickEvent(self.militaryRanksBtn_obj, on_click)
  110. AddClickEvent(self.exploitBtn_obj, on_click)
  111. AddClickEvent(self.appointBtn_obj, on_click)
  112. AddClickEvent(self.sandTableBtn_obj, on_click)
  113. AddClickEvent(self.sandTableBtn2_obj, on_click)
  114. AddClickEvent(self.add_btn_money_obj,on_click)
  115. --60300后刷新指挥室角色展示
  116. local function on_update_role_show()
  117. self.has_got_figure_data = true
  118. self:UpdateRoleShowCon()
  119. end
  120. self:BindEvent(self.model, CSMainConst.UPDATE_CS_MAIN_BASE_VIEW, on_update_role_show)
  121. local function update_red_dot(tab_id)
  122. if not self.is_loaded then return end
  123. self:RefreshRed(tab_id)
  124. end
  125. self:BindEvent(self.model, CSMainConst.ANS_UPDATE_RED_DOT, update_red_dot)
  126. local function onOrientationChange()
  127. self:SetIpxMode()
  128. end
  129. self:BindEvent(GlobalEventSystem, EventName.ORIENTATION_DID_CHANGE, onOrientationChange)
  130. local function on_arms_num_change_var()
  131. self:ShowMoney()
  132. end
  133. self.on_arms_num_change_var_id = self.on_arms_num_change_var_id or self.model:BindOne("arms_num", on_arms_num_change_var)
  134. self:ShowMoney()
  135. local function on_exploit_rank_score_change_var()
  136. self:ShowScore()
  137. end
  138. self.on_exploit_rank_score_change_var_id = self.on_exploit_rank_score_change_var_id or self.model:BindOne("exploit_rank_score", on_exploit_rank_score_change_var)
  139. self:ShowScore()
  140. end
  141. function CSMainBaseView:ShowScore( )
  142. self.des_score_tmp.text = string.format( "我的战功 :%d", self.model:GetCSMainExploitRankScore( ))
  143. SetSizeDeltaX(self.di_money2.transform, self.des_score_tmp.preferredWidth + 20)
  144. end
  145. function CSMainBaseView:ShowMoney( )
  146. self.money_name = self.money_name or GoodsModel:getInstance():GetGoodsBasicByTypeId( SandTableModel:getInstance().dungeon_cost_id ).goods_name
  147. local cur = self.model:GetCSMainArmsNum( )
  148. self.num_money_tmp.text = string.format( "%s :%s" ,self.money_name, cur)
  149. SetSizeDeltaX(self.di_money.transform, self.num_money_tmp.preferredWidth + 40)
  150. end
  151. function CSMainBaseView:SetIpxMode( )
  152. if ClientConfig.iphone_x_model then
  153. self.titleImg1.anchoredPosition = Vector2(0+ClientConfig.iphone_x_offset_left, 333.5)
  154. self.titleLabel.anchoredPosition = Vector2(43+ClientConfig.iphone_x_offset_left, 333.5)
  155. self.titleImg2.anchoredPosition = Vector2(-115+ClientConfig.iphone_x_offset_left, 311)
  156. self.helpBtn.anchoredPosition = Vector2(10.5+ClientConfig.iphone_x_offset_left, -329.5)
  157. self.roleLabel.anchoredPosition = Vector2(61.5+ClientConfig.iphone_x_offset_left, -328)
  158. self.closeBtn.anchoredPosition = Vector2(0-ClientConfig.iphone_x_offset_right, 334)
  159. self.rightBtnCon.anchoredPosition = Vector2(0-ClientConfig.iphone_x_offset_right, 0)
  160. end
  161. end
  162. function CSMainBaseView:RefreshRed(tab_id)
  163. local bool = false
  164. if tab_id == CSMainConst.RedType.Task then
  165. bool = self.model:GetTaskRed() or self.model:GetActiveRed()
  166. self.taskRed_obj:SetActive(bool)
  167. elseif tab_id == CSMainConst.RedType.Active then
  168. bool = self.model:GetTaskRed() or self.model:GetActiveRed()
  169. self.taskRed_obj:SetActive(bool)
  170. elseif tab_id == CSMainConst.RedType.DailyReward then
  171. bool = self.model:GetDailyRewardRed() or self.model:GetWorShipRed()
  172. self.exploitRed_obj:SetActive(bool)
  173. elseif tab_id == CSMainConst.RedType.MilitaryRanks then
  174. bool = self.model:GetMilitaryRanksRed()
  175. self.militaryRed_obj:SetActive(bool)
  176. elseif tab_id == CSMainConst.RedType.SandTable then
  177. bool = self.model:GetSandTableRed()
  178. self.sandRed_obj:SetActive(bool)
  179. self.sandTableRed2_obj:SetActive(bool)
  180. elseif tab_id == CSMainConst.RedType.WorShip then
  181. bool = self.model:GetDailyRewardRed() or self.model:GetWorShipRed()
  182. self.exploitRed_obj:SetActive(bool)
  183. end
  184. end
  185. function CSMainBaseView:UpdateAllRed( )
  186. local taskRed = self.model:GetTaskRed() or self.model:GetActiveRed()
  187. self.taskRed_obj:SetActive(taskRed)
  188. local exploitRed = self.model:GetDailyRewardRed() or self.model:GetWorShipRed()
  189. self.exploitRed_obj:SetActive(exploitRed)
  190. local militaryRed = self.model:GetMilitaryRanksRed()
  191. self.militaryRed_obj:SetActive(militaryRed)
  192. local sandRed = self.model:GetSandTableRed()
  193. self.sandRed_obj:SetActive(sandRed)
  194. self.sandTableRed2_obj:SetActive(sandRed)
  195. end
  196. function CSMainBaseView:OpenTaskView( )
  197. self:StopAnim()
  198. local function onCompleted()
  199. local function delay_method( )
  200. self.model:Fire(CSMainConst.OPEN_CS_MAIN_TASK_VIEW)
  201. -- self.tween_lite_id_3 = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POS, Vector2(0,0), self.anim_time)
  202. -- self.tween_lite_id_4 = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.SCALE, Vector3.New(1,1,1), self.anim_time)
  203. SetAnchoredPosition(self.transform, 0, 0)
  204. SetLocalScale(self.transform, 1, 1, 1)
  205. end
  206. self.delay_open_id = setTimeout(delay_method, 0.1)
  207. end
  208. self.tween_lite_id_1 = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.ANCHORED_POS, Vector2(1854,-713), self.anim_time)
  209. self.tween_lite_id_2 = TweenLite.to(self, self.transform, TweenLite.UiAnimationType.SCALE, Vector3.New(4,4,4), self.anim_time, onCompleted)
  210. end
  211. function CSMainBaseView:UpdateRoleShowCon( )
  212. local role_data = {}
  213. for i=1,7 do
  214. role_data[i] = self.model:GetCSMainDirectorDataByPos(i)
  215. end
  216. for k,v in pairs(self.role_show_item_list) do
  217. v:SetVisible(false)
  218. end
  219. for i,v in ipairs(role_data) do
  220. local item = self.role_show_item_list[i]
  221. if not item then
  222. item = CSMainRoleModelItem.New(self.modelCon)
  223. self.role_show_item_list[i] = item
  224. end
  225. item:SetVisible(true)
  226. item:SetData(i,v)
  227. item:SetAnchoredPosition(CSMainConst.RoleModelPos[i].x, CSMainConst.RoleModelPos[i].y)
  228. end
  229. end
  230. function CSMainBaseView:OpenSuccess()
  231. -- self:UpdateRoleShowCon()
  232. self:UpdateAllRed()
  233. end
  234. function CSMainBaseView:StopAnim( )
  235. if self.delay_open_id then
  236. TimerQuest.CancelQuest(GlobalTimerQuest,self.delay_open_id)
  237. self.delay_open_id = nil
  238. end
  239. if self.tween_lite_id_1 then
  240. TweenLite.Stop(self.tween_lite_id_1)
  241. self.tween_lite_id_1 = nil
  242. end
  243. if self.tween_lite_id_2 then
  244. TweenLite.Stop(self.tween_lite_id_2)
  245. self.tween_lite_id_2 = nil
  246. end
  247. if self.tween_lite_id_3 then
  248. TweenLite.Stop(self.tween_lite_id_3)
  249. self.tween_lite_id_3 = nil
  250. end
  251. if self.tween_lite_id_4 then
  252. TweenLite.Stop(self.tween_lite_id_4)
  253. self.tween_lite_id_4 = nil
  254. end
  255. end
  256. function CSMainBaseView:DestroySuccess( )
  257. self:StopAnim()
  258. for i, v in ipairs(self.role_show_item_list) do
  259. v:DeleteMe()
  260. end
  261. self.role_show_item_list = {}
  262. if self.on_arms_num_change_var_id then
  263. self.model:UnBind(self.on_arms_num_change_var_id)
  264. self.on_arms_num_change_var_id = nil
  265. end
  266. if self.on_exploit_rank_score_change_var_id then
  267. self.model:UnBind(self.on_exploit_rank_score_change_var_id)
  268. self.on_exploit_rank_score_change_var_id = nil
  269. end
  270. end