UINewCreateRoleView.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. local UINewCreateRoleView = require("UICreateRole/UINewCreateRoleView_Generate")
  2. local RoleViewSystem = require("RoleViewSystem")
  3. local PreviewSystem = require("PreviewSystem")
  4. local BoxCollider = typeof(UnityEngine.BoxCollider)
  5. local maleViewSystem = nil
  6. local femaleViewSystem = nil
  7. function UINewCreateRoleView:OnAwake(data)
  8. self.controller = require("UICreateRole/UINewCreateRoleCtr"):new()
  9. self.controller:Init(self)
  10. self.controller:SetData(data)
  11. end
  12. function UINewCreateRoleView:AddEventListener()
  13. -- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_SELECT_ROLE,self,self.OnSelectRole);
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_USED_ACTIVATIONCODE,self,self.OnUsedActivationCode)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_CLOSED_ACTIVATIONCODE,self,self.OnCloseActivationCode)
  16. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_CREATE_ROLE_FAILED,self,self.OnCreateRoleFailed)
  17. end
  18. function UINewCreateRoleView:FillContent(data, uiBase)
  19. self.uiBase = uiBase
  20. local gameObject = self.uiBase:GetRoot()
  21. if gameObject ~= nil then
  22. self.gameObject = gameObject
  23. self.transform = gameObject.transform
  24. end
  25. self:InitGenerate(self.transform, data)
  26. self.firstSelected = true
  27. self:Init()
  28. self.rewardHideState = true
  29. self:InitComs(false)
  30. --self.notice:SetActive(false)
  31. self.createAnim.animator:Play("BannerKeepOut")
  32. --self.delayShowNoticeTimer = ManagerContainer.LuaTimerMgr:AddTimer(3000, 1, self, self.DelayHideNotice, nil)
  33. end
  34. function UINewCreateRoleView:DelayHideNotice()
  35. self.createAnim.animator:Play("BannerKeepOut")
  36. self.createAnim:SetActive(false)
  37. self.btnBox:SetActive(false)
  38. self.delayShowNoticeTimer = ManagerContainer.LuaTimerMgr:AddTimer(24000, 1, self, self.DelayShowNotice, nil)
  39. end
  40. function UINewCreateRoleView:DelayShowNotice()
  41. --self.notice:SetActive(true)
  42. self.delayShowNoticeTimer = ManagerContainer.LuaTimerMgr:AddTimer(3000, 1, self, self.DelayShowbtnBox, nil)
  43. end
  44. function UINewCreateRoleView:DelayShowbtnBox()
  45. self.btnBox:SetActive(true)
  46. self.delayShowNoticeTimer = ManagerContainer.LuaTimerMgr:AddTimer(3000, 1, self, self.DelayShowcreateAnim, nil)
  47. end
  48. function UINewCreateRoleView:DelayShowcreateAnim()
  49. self.createAnim:SetActive(true)
  50. self.createAnim.animator:Play("BannerKeepOut")
  51. end
  52. function UINewCreateRoleView:Init()
  53. LuaBattleBridge.SetCreateRoleLuaTable(self.controller)
  54. self.malePos = ManagerContainer.LuaGameMgr.CreateMaleRoot.transform.position
  55. self.femalePos = ManagerContainer.LuaGameMgr.CreateFemaleRoot.transform.position
  56. self.showPos = ManagerContainer.LuaGameMgr.CreateShowRoot.transform.position
  57. LuaBattleBridge.ShowCreateRoleCam()
  58. self.sendCreateRole = nil
  59. self.sendCreateRoleTime = nil
  60. self.IsOpeningActivationCodePage = false
  61. self.backBtn:SetActive(false)
  62. self:SetTexture()
  63. end
  64. function UINewCreateRoleView:SetLayer(trans, layer, enterChild)
  65. if not trans then return end
  66. trans.gameObject.layer = layer
  67. if not enterChild then return end
  68. for i = 0, trans.childCount - 1 do
  69. self:SetLayer(trans:GetChild(i), layer, enterChild)
  70. end
  71. end
  72. function UINewCreateRoleView:SetTexture()
  73. if not self.modeTexture then
  74. return
  75. end
  76. local w = UnityEngine.Screen.width
  77. local h = UnityEngine.Screen.height
  78. local texture = UnityEngine.RenderTexture(w,h,0)
  79. self.modeTexture.rawImage.texture = texture
  80. --self.modeTexture.rawImage:SetNativeSize()
  81. UnityEngine.Camera.main.targetTexture = texture
  82. self:SetLayer(self.FxObj.transform,10,true)
  83. end
  84. function UINewCreateRoleView:InitComs(vis)
  85. self.confirmBtn:SetActive(vis)
  86. -- self.backBtn:SetActive(vis)
  87. self.shadow:SetActive(vis)
  88. self.grass:SetActive(vis)
  89. self.notice:SetActive(not vis)
  90. end
  91. function UINewCreateRoleView:RemoveEventListener()
  92. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  93. end
  94. function UINewCreateRoleView:AddUIEventListener()
  95. self.uiBase:AddButtonEventListener(self.confirmBtn.button,self, self.OnClickCreateRole)
  96. -- self.uiBase:AddButtonEventListener(self.backBtn.button,self,self.OnClickBack)
  97. end
  98. function UINewCreateRoleView:OnHide()
  99. end
  100. function UINewCreateRoleView:OnShow(data)
  101. self.controller:SetData(data)
  102. self:Init()
  103. end
  104. function UINewCreateRoleView:OnClose()
  105. if self.delayCreateRoleTimer ~= nil then
  106. ManagerContainer.LuaTimerMgr:RemoveTimer(self.delayCreateRoleTimer)
  107. self.delayCreateRoleTimer = nil
  108. end
  109. if self.delayHideRoleTimer ~= nil then
  110. ManagerContainer.LuaTimerMgr:RemoveTimer(self.delayHideRoleTimer)
  111. self.delayHideRoleTimer = nil
  112. end
  113. if self.delayShowNoticeTimer ~= nil then
  114. ManagerContainer.LuaTimerMgr:RemoveTimer(self.delayShowNoticeTimer)
  115. self.delayShowNoticeTimer = nil
  116. end
  117. self.selectGo = nil
  118. ManagerContainer.LuaGameMgr:SetCreateRoleStatus(false)
  119. LuaBattleBridge.ClearCreateRole()
  120. end
  121. function UINewCreateRoleView:OnDispose()
  122. self.startAnimEnd = nil
  123. if self.rewardTimer then
  124. if self.rewardTimer.running then
  125. self.rewardTimer:Stop()
  126. end
  127. self.rewardTimer = nil
  128. end
  129. self.rewardHideState = nil
  130. end
  131. function UINewCreateRoleView:OnClickCreateRole()
  132. if self:IsSendCreating() then
  133. return
  134. end
  135. self.activationCode = nil
  136. if ManagerContainer.LuaGameMgr.IsActivationCodeMode then
  137. self:OnOpenActivationCodePage()
  138. else
  139. self:HandleCreateRole()
  140. end
  141. end
  142. function UINewCreateRoleView:OnCloseActivationCode()
  143. self.IsOpeningActivationCodePage = false
  144. end
  145. function UINewCreateRoleView:OnUsedActivationCode(code)
  146. self.IsOpeningActivationCodePage = false
  147. self.activationCode = code
  148. self:HandleCreateRole()
  149. end
  150. function UINewCreateRoleView:HandleCreateRole()
  151. if self.controller:GetSexType() == Enum.SexType.Man then
  152. if self.controller.maleAnimator ~= nil then
  153. -- self.controller.maleAnimator:Play("f_show")
  154. end
  155. else
  156. if self.controller.femaleAnimator ~= nil then
  157. -- self.controller.femaleAnimator:Play("f_show")
  158. end
  159. end
  160. if self:IsSendCreating() then return end
  161. self.sendCreateRole = true
  162. self.sendCreateRoleTime = ManagerContainer.LuaTimerMgr.GetTimeSecond()
  163. self.controller:OnCreateClick(self.activationCode)
  164. self:ChangeRewardState(true)
  165. end
  166. function UINewCreateRoleView:DelayCreateRole()
  167. ManagerContainer.DataMgr.UserData:StartEnterGame(true)
  168. end
  169. function UINewCreateRoleView:DelayHideRole()
  170. LuaBattleBridge.SetGameObjectLayerFrom(ManagerContainer.LuaGameMgr.CreateMaleRoot,"Fighter","Hide")
  171. LuaBattleBridge.SetGameObjectLayerFrom(ManagerContainer.LuaGameMgr.CreateFemaleRoot,"Fighter","Hide")
  172. end
  173. function UINewCreateRoleView:OnCreateRoleFailed(error)
  174. if error == Enum.NetErrorCode.ERROR_OK then
  175. self.sendCreateRoleTime = nil
  176. LuaBattleBridge.PlayCreateRoleTransferEffect()
  177. self.delayCreateRoleTimer = ManagerContainer.LuaTimerMgr:AddTimer(GlobalConfig.Instance:GetConfigFloatValue(135)*1000, 1, self, self.DelayCreateRole, nil)
  178. self.delayHideRoleTimer = ManagerContainer.LuaTimerMgr:AddTimer(GlobalConfig.Instance:GetConfigFloatValue(136)*1000, 1, self, self.DelayHideRole, nil)
  179. else
  180. self.sendCreateRole = nil
  181. self.sendCreateRoleTime = nil
  182. LuaBattleBridge.SetGameObjectLayerFrom(ManagerContainer.LuaGameMgr.CreateMaleRoot,"Hide","Fighter")
  183. LuaBattleBridge.SetGameObjectLayerFrom(ManagerContainer.LuaGameMgr.CreateFemaleRoot,"Hide","Fighter")
  184. -- 激活码错误
  185. if error == Enum.NetErrorCode.ERROR_ROLE_ACTIVE_CODE_ERROR or error == Enum.NetErrorCode.ERROR_ROLE_ACTIVECODE_USED then
  186. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("冒险码错误!")
  187. end
  188. end
  189. end
  190. function UINewCreateRoleView:OnOpenActivationCodePage()
  191. self.IsOpeningActivationCodePage = true
  192. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIActivationCodePage)
  193. end
  194. function UINewCreateRoleView:OnClickBack()
  195. -- if self.selectGo == nil then
  196. -- return
  197. -- end
  198. -- if self.controller:GetSexType() == Enum.SexType.Man then
  199. -- LuaBattleBridge.PlayCamAnim("CM_vcam5",false)
  200. -- if self.controller.maleAnimator ~= nil then
  201. -- self.controller.maleAnimator:Play("f_go")
  202. -- end
  203. -- if self.controller.femaleAnimator ~= nil then
  204. -- self.controller.femaleAnimator:Play("f_Ahead")
  205. -- end
  206. -- else
  207. -- LuaBattleBridge.PlayCamAnim("CM_vcam4",false)
  208. -- if self.controller.femaleAnimator ~= nil then
  209. -- self.controller.femaleAnimator:Play("f_go")
  210. -- end
  211. -- if self.controller.maleAnimator ~= nil then
  212. -- self.controller.maleAnimator:Play("f_Ahead")
  213. -- end
  214. -- end
  215. -- self.controller:SetSexType(nil)
  216. -- self:InitComs(false)
  217. -- LuaBattleBridge.CloseDof()
  218. end
  219. function UINewCreateRoleView:OnSelectRole(isMale,go)
  220. if self.IsOpeningActivationCodePage then
  221. return false
  222. end
  223. if self:IsSendCreating() then
  224. return false
  225. end
  226. if not self.startAnimEnd then
  227. if LuaBattleBridge.IsPlayCamAnimEnd("CM_vcam1") then
  228. self.startAnimEnd = true
  229. else
  230. return false
  231. end
  232. end
  233. -- if self.controller:GetSexType() ~= nil then
  234. -- self:CancelSelected()
  235. -- return
  236. -- end
  237. -- LogError("OnSelectRole = " .. tostring(isMale) .." type=" .. tostring(self.controller:GetSexType()))
  238. if self.controller:GetSexType() == Enum.SexType.Man and isMale then
  239. return false
  240. end
  241. if self.controller:GetSexType() == Enum.SexType.Woman and isMale == false then
  242. return false
  243. end
  244. self.selectGo = go
  245. if isMale then
  246. self.controller:SetSexType(Enum.SexType.Man)
  247. if self.firstSelected then
  248. LuaBattleBridge.PlayCamAnim("CM_vcam3",true)
  249. if self.controller.maleAnimator ~= nil then
  250. self.controller.maleAnimator:Play("f_Ahead_down")
  251. end
  252. if self.controller.femaleAnimator ~= nil then
  253. self.controller.femaleAnimator:Play("f_Ahead_go")
  254. end
  255. else
  256. LuaBattleBridge.PlayCamAnim("CM_vcam5",true)
  257. if self.controller.maleAnimator ~= nil then
  258. self.controller.maleAnimator:Play("f_back")
  259. end
  260. if self.controller.femaleAnimator ~= nil then
  261. self.controller.femaleAnimator:Play("f_Ahead_go")
  262. end
  263. end
  264. else
  265. self.controller:SetSexType(Enum.SexType.Woman)
  266. if self.firstSelected then
  267. LuaBattleBridge.PlayCamAnim("CM_vcam2",true)
  268. if self.controller.maleAnimator ~= nil then
  269. self.controller.maleAnimator:Play("f_Ahead_go")
  270. end
  271. if self.controller.femaleAnimator ~= nil then
  272. self.controller.femaleAnimator:Play("f_Ahead_down")
  273. end
  274. else
  275. LuaBattleBridge.PlayCamAnim("CM_vcam4",true)
  276. if self.controller.femaleAnimator ~= nil then
  277. self.controller.femaleAnimator:Play("f_back")
  278. end
  279. if self.controller.maleAnimator ~= nil then
  280. self.controller.maleAnimator:Play("f_Ahead_go")
  281. end
  282. end
  283. end
  284. self:InitComs(true)
  285. self.firstSelected = false
  286. self:ChangeRewardState(true)
  287. if self.rewardTimer then
  288. self.rewardTimer.time = 1.8
  289. self.rewardTimer.loop = 1
  290. else
  291. self.rewardTimer = Timer.New(slot(self.ChangeRewardState, self), 1.8, 1)
  292. end
  293. if not self.rewardTimer.running then
  294. self.rewardTimer:Start()
  295. end
  296. return true
  297. end
  298. function UINewCreateRoleView:CancelSelected()
  299. if self.IsOpeningActivationCodePage then
  300. return
  301. end
  302. self:OnClickBack()
  303. end
  304. function UINewCreateRoleView:IsSendCreating()
  305. if not self.sendCreateRole then
  306. return false
  307. end
  308. if self.sendCreateRoleTime then
  309. if ManagerContainer.LuaTimerMgr.GetTimeSecond() - self.sendCreateRoleTime > 10 then
  310. return false
  311. end
  312. end
  313. return true
  314. end
  315. function UINewCreateRoleView:ChangeRewardState(hide)
  316. if self.rewardHideState == hide then
  317. return
  318. end
  319. self.rewardHideState = hide
  320. if not hide then
  321. self.createAnim.animator:CrossFade("BannerIn", 0.2)
  322. else
  323. self.createAnim.animator:CrossFade("BannerOut", 0.2)
  324. end
  325. end
  326. return UINewCreateRoleView