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

338 行
11 KiB

  1. --[[
  2. ]]
  3. NewModelOpenView = NewModelOpenView or BaseClass(BaseView)
  4. local NewModelOpenView = NewModelOpenView
  5. --模型资源图标ID
  6. NewModelOpenView.model_icon_res = {
  7. [1] = {ab_name = "mainRole_asset", res_name = "mainrole_level_btn"},
  8. [2] = {ab_name = "mainUI_asset", res_name = "icon_leftBottom_1"}, --巫女
  9. [3] = {ab_name = "mainUI_asset", res_name = "icon_leftBottom_32"}, --契兽
  10. [4] = {ab_name = "mainUI_asset", res_name = "guide_icon_xingpang"}, --星盘
  11. [5] = {ab_name = "mainUI_asset", res_name = "guide_icon_baoju"}, --宝具
  12. [6] = {ab_name = "mainUI_asset", res_name = "guide_icon_bingwu"}, --兵武
  13. [9] = {ab_name = "mainUI_asset", res_name = "icon_leftBottom_22"}, --宝宝
  14. }
  15. function NewModelOpenView:__init()
  16. self.base_file = "func"
  17. self.layout_file = "NewModelOpenView"
  18. self.layer_name = "Activity"
  19. self.destroy_imm = true
  20. self.change_scene_close = true
  21. self.open_guide_close = nil
  22. self.hide_maincancas = false --隐藏主界面
  23. self.click_bg_toClose = true
  24. self.use_background = true --不一定显示遮罩
  25. self.close_fog = true
  26. self.model = FuncOpenModel:getInstance()
  27. self.mainVo = RoleManager.Instance.mainRoleInfo
  28. self.time_diff = 10
  29. self.model.is_open_func_model_view = true
  30. self.load_callback = function ()
  31. self:LoadSuccess()
  32. self:AddEvent()
  33. end
  34. self.open_callback = function ( )
  35. self:OpenSuccess()
  36. end
  37. self.close_callback = function ()
  38. self:CloseSuccess()
  39. end
  40. self.destroy_callback = function ( )
  41. self:DestroySuccess()
  42. end
  43. end
  44. function NewModelOpenView:Open( voList )
  45. self.voList = voList
  46. self.cur_vo = self.voList[1] or {}
  47. BaseView.Open(self)
  48. end
  49. function NewModelOpenView:LoadSuccess()
  50. self.center_obj = self:GetChild("mid/center_cont").gameObject
  51. self.mask_obj = self:GetChild("mid/mask_img").gameObject
  52. self.mask_img = self:GetChild("mid/mask_img"):GetComponent("Image")
  53. self.title_img = self:GetChild("mid/center_cont/title_img"):GetComponent("Image")
  54. self.name_txt = self:GetChild("mid/center_cont/up_cont/name_txt"):GetComponent("TMPro.TextMeshProUGUI")
  55. self.desc_txt = self:GetChild("mid/center_cont/up_cont/desc_txt"):GetComponent("TMPro.TextMeshProUGUI")
  56. self.time_txt = self:GetChild("mid/center_cont/time_txt"):GetComponent("TMPro.TextMeshProUGUI")
  57. self.icon_cont = self:GetChild("icon_cont")
  58. self.model_cont = self:GetChild("icon_cont/model_cont")
  59. self.effect = self:GetChild("mid/center_cont/effect")
  60. self.effect2 = self:GetChild("mid/center_cont/effect2")
  61. self.up_cont = self:GetChild("mid/center_cont/up_cont").gameObject
  62. -- self:MoveUIToBack(self.effect)
  63. local function delay_method( )
  64. self:AddUIEffect("ui_jihuoxinxitong01", self.effect, self.layer_name, nil, 1, true,nil,nil, nil, nil,nil,UIPartical.RenderingOther_List.UIBackward)
  65. self:AddUIEffect("ui_jihuoxinxitong02", self.effect2, self.layer_name, nil, 1, true,nil,nil, nil, nil,nil,UIPartical.RenderingOther_List.UIBackward)
  66. end
  67. setTimeout(delay_method, 0.02) --延时0.02秒后再加载特效防止层级错乱
  68. local nodes = {
  69. "mid/center_cont/bg_img:img","mid/center_cont/up_cont/tipImg:img",
  70. }
  71. self:GetChildren(nodes)
  72. self.mask_img.alpha = 0
  73. self.mask_obj.transform.sizeDelta = Vector2(ScreenWidth,ScreenHeight)
  74. -- self.mask_obj:SetActive(true)
  75. local function bg_back_func( ... )
  76. if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
  77. self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
  78. end
  79. local function func( ... )
  80. self:MoveUIToBack(self.bg_img_img)
  81. end
  82. lua_resM:setOutsideImageSprite(self, self.bg_img_img, GameResPath.GetFuncIcon("open_func_model_bg"),false,func)
  83. end
  84. if self.background_wnd then
  85. bg_back_func()
  86. else
  87. self.bg_back_func = bg_back_func
  88. end
  89. self.transform:SetInsetAndSizeFromParentEdge(self.transform.EdgeLeft, 0, ScreenWidth)
  90. end
  91. function NewModelOpenView:AddEvent()
  92. local function on_click( target )
  93. if target == self.mask_obj then
  94. if Scene.Instance.main_role then
  95. local cfg = Scene.Instance.main_role:GetMainRoleStorycfg(PoseState.STORY)
  96. if cfg and cfg.ignore_click then
  97. return
  98. end
  99. end
  100. self:PlayAction()
  101. end
  102. end
  103. AddClickEvent(self.mask_obj, on_click)
  104. end
  105. function NewModelOpenView:OpenSuccess()
  106. GlobalEventSystem:Fire(SceneEventType.CLOSE_DIALOGUE_VIEW)
  107. GlobalEventSystem:Fire(EventName.STOP_AUTO_DO_TASK)
  108. GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
  109. self:UpdateView()
  110. self:PlaySound()
  111. end
  112. function NewModelOpenView:PlaySound( )
  113. if IsTableEmpty(self.cur_vo) then
  114. return
  115. end
  116. if self.cur_vo then
  117. lua_soundM:StopEffect(self, LuaSoundManager.SOUND_TYPE.FUNC, self.sound_id)
  118. -- lua_soundM:StopEffect(self, LuaSoundManager.SOUND_TYPE.FUNC, self.sound_id)
  119. if self.cur_vo.sound and Trim(self.cur_vo.sound) ~= "" then
  120. if lua_soundM then
  121. self.sound_id = lua_soundM:PlayEffect(self, Trim(self.cur_vo.sound),false,LuaSoundManager.SOUND_TYPE.FUNC)
  122. end
  123. end
  124. end
  125. end
  126. function NewModelOpenView:UpdateView()
  127. if IsTableEmpty(self.cur_vo) then
  128. return
  129. end
  130. if not self.cur_vo.fashion_type or self.cur_vo.fashion_type == 0 then
  131. return
  132. end
  133. lua_resM:setImageSprite(self, self.title_img, "func_asset", "open_func_title3", true)
  134. self:UpdateModelCon()
  135. --设置文本
  136. -- self.name_txt.text = self.cur_vo.saying
  137. self.desc_txt.text = "[ " .. self.cur_vo.saying .. " ]"
  138. --倒计时
  139. self:StartTimer()
  140. --创建图标
  141. self:CreateFlyIcon()
  142. lua_resM:setImageSprite(self, self.tipImg_img, "func_asset", "open_func_tip_"..self.cur_vo.fashion_type, true)
  143. end
  144. function NewModelOpenView:UpdateModelCon( )
  145. --ai娘、座驾的模型展示需要单独做一些位置调整(原则,尽量不调整模型的pos,能调con的位置就调con的参数,模型太大调整scale)
  146. local model_pos = nil
  147. local model_scale = nil
  148. local model_con_pos = Vector3(9,-10,0)
  149. local rotate = nil
  150. local can_rotate = nil
  151. if self.cur_vo.fashion_type == FuncOpenModel.TypeId.FHorse then--座驾
  152. -- model_pos = Vector3(0, 135, 0)
  153. -- model_scale = 160
  154. model_con_pos = Vector3(9,-120,350)
  155. rotate = Vector3(0, 160, 0)
  156. can_rotate = true
  157. elseif self.cur_vo.fashion_type == FuncOpenModel.TypeId.FJarvis then--ai娘
  158. -- model_pos = Vector3(0, 120, 0)
  159. model_scale = 240
  160. model_con_pos = Vector3(35,-30,150)
  161. elseif self.cur_vo.fashion_type == FuncOpenModel.TypeId.FPearl then--宝具
  162. -- model_pos = Vector3(0, 180, 0)
  163. -- model_scale = 220
  164. model_con_pos = Vector3(15,-20,0)
  165. elseif self.cur_vo.fashion_type == FuncOpenModel.TypeId.FWeapon then--武器
  166. -- model_pos = Vector3(0, 180, 0)
  167. -- model_scale = 200
  168. model_con_pos = Vector3(45,-10,280)
  169. elseif self.cur_vo.fashion_type == FuncOpenModel.TypeId.FCloud then--AI娘翅膀
  170. model_con_pos = Vector3(20,-10,0)
  171. elseif self.cur_vo.fashion_type == FuncOpenModel.TypeId.FWing then--翅膀
  172. model_con_pos = Vector3(20,-10,0)
  173. elseif self.cur_vo.fashion_type == FuncOpenModel.TypeId.Child then--宝宝
  174. model_con_pos = Vector3(20, -10, 0)
  175. model_scale = 500
  176. end
  177. self.model_cont.transform.localPosition = model_con_pos
  178. local res_data = {
  179. father_node = self,
  180. transform = self.model_cont,
  181. fashion_type = self.cur_vo.fashion_type,
  182. figure_id = self.cur_vo.figure_id,
  183. position = model_pos,
  184. scale = model_scale,
  185. figure_texture = 1,
  186. layer_name = self.layer_name,
  187. can_rotate = can_rotate,
  188. rotate = rotate,
  189. ui_model_type = UIModelCommon.ModelType.BackModel,
  190. }
  191. FuncOpenModel:getInstance():SetModelRes(res_data)
  192. if self.cur_vo.fashion_type == FuncOpenModel.TypeId.FHorse then--座驾
  193. lua_soundM:PlayEffect(self, "activate_moto", false, LuaSoundManager.SOUND_TYPE.UI, 1)
  194. end
  195. end
  196. function NewModelOpenView:StartTimer( )
  197. if self.time_id == nil then
  198. self.time_txt.text = HtmlColorTxt(self.time_diff, "#2cf86f") .. " 秒后自动关闭"
  199. local function onTimer()
  200. self.time_diff = self.time_diff - 1
  201. if self.time_diff >= 0 then
  202. self.time_txt.text = HtmlColorTxt(self.time_diff, "#2cf86f") .. " 秒后自动关闭"
  203. else
  204. if self.time_id then
  205. GlobalTimerQuest:CancelQuest(self.time_id)
  206. self.time_id = nil
  207. end
  208. self:PlayAction()
  209. end
  210. end
  211. self.time_id = GlobalTimerQuest:AddPeriodQuest(onTimer,1,-1)
  212. end
  213. end
  214. function NewModelOpenView:CreateFlyIcon( )
  215. if self.cur_vo then
  216. self.image_obj = UiFactory.createChild(self.icon_cont, UIType.ImageExtend)
  217. self.image_obj.transform.sizeDelta = Vector2(78, 78)
  218. self.image_icon = self.image_obj:GetComponent("ImageExtend")
  219. local ab_name, res_name = "activityIcon_asset", ""
  220. if self.cur_vo.winId and self.cur_vo.subId then
  221. local fun_vo = OpenFun.LinkWin[self.cur_vo.winId.."@"..self.cur_vo.subId]
  222. if fun_vo then
  223. res_name = fun_vo.icon_res
  224. end
  225. end
  226. if self.cur_vo.model_type and self.cur_vo.model_type ~= 0 and self.cur_vo.icon_res_name ~= nil then
  227. res_name = self.cur_vo.icon_res_name
  228. end
  229. self.center_obj:SetActive(true)
  230. self.image_obj:SetActive(false)
  231. local function callback( ... )
  232. if ab_name == "activityIcon_asset" then
  233. self.image_obj.transform.sizeDelta = Vector2(60, 60)
  234. end
  235. end
  236. if ab_name and ab_name ~= "" and res_name and res_name ~= "" then
  237. lua_resM:setImageSprite(self, self.image_icon, ab_name, res_name, true, callback)
  238. if ab_name == "activityIcon_asset" then
  239. self.image_obj.transform.sizeDelta = Vector2(60, 60)
  240. end
  241. end
  242. end
  243. end
  244. function NewModelOpenView:PlayAction( )
  245. local function callback( )
  246. GlobalEventSystem:Fire(EventName.SHOW_FUNC_OPEN_ICON,self.voList)
  247. self.image_obj:SetActive(false)
  248. self:Close()
  249. end
  250. if self.cur_vo and self.cur_vo.ignore_fly then
  251. callback()
  252. return
  253. end
  254. if not self.image_obj then
  255. callback()
  256. return
  257. end
  258. local pos = self.cur_vo.pos
  259. if self.cur_vo then
  260. pos = self.model:GetFlyPos(self.cur_vo)
  261. end
  262. self.center_obj:SetActive(false)
  263. self.image_obj:SetActive(true)
  264. self.model_cont.gameObject:SetActive(false)
  265. if pos ~= nil then
  266. self.tween_id = TweenLite.to(self, self.image_obj.transform, TweenLite.UiAnimationType.POS, pos, 0.8, callback)
  267. end
  268. end
  269. --关闭界面后做什么
  270. function NewModelOpenView:CloseSuccess( )
  271. --完成引导
  272. local main_role = Scene.Instance.main_role
  273. if main_role then
  274. main_role:ChangeState(PoseState.STAND)
  275. end
  276. local helpVo, endVo = GuideModel:getInstance():GetHelpVo(HelpType.TASK_ITEM_SHOW,1)
  277. if helpVo and not endVo then
  278. GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
  279. else
  280. --当前没有引导才继续做任务
  281. GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK)
  282. GlobalEventSystem:Fire(EventName.START_AUTO_DO_TASK)
  283. end
  284. -- if self.cur_vo.winId and self.cur_vo.subId then
  285. -- OpenFun.Open(self.cur_vo.winId, self.cur_vo.subId)
  286. -- else
  287. -- end
  288. if self.image_obj then
  289. self.image_obj:SetActive(false)
  290. end
  291. GlobalEventSystem:Fire(EventName.SHOW_FUNC_OPEN_ICON,self.voList)
  292. end
  293. function NewModelOpenView:DestroySuccess( )
  294. self.model.is_open_func_model_view = false
  295. self:ClearUIEffect(self.effect)
  296. self:ClearUIEffect(self.effect2)
  297. if self.time_id then
  298. GlobalTimerQuest:CancelQuest(self.time_id)
  299. self.time_id = nil
  300. end
  301. end