UIFashionView.lua 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. local UIFashionView = require("UIFashion/UIFashionView_Generate")
  2. local RoleViewSystem = require("RoleViewSystem")
  3. local PreviewSystem = require("PreviewSystem")
  4. local MirrorPreviewSystem = require("MirrorPreviewSystem")
  5. local DOTween = DG.Tweening.DOTween
  6. local roleViewSystem = nil
  7. local previewSystem = nil
  8. local mirrorPreviewSystem = nil
  9. local SaveInterval = 1
  10. local LastSaveTime = nil
  11. local SwitchInterval = 0.5
  12. local LastSwitchTime = nil
  13. local userSex
  14. local lvUpState
  15. local washState
  16. --- 提示换装窗口结束后,下一步操作
  17. local NoticeNextType =
  18. {
  19. EnterRoleView = 1,
  20. EnterBookView = 2,
  21. }
  22. function UIFashionView:OnAwake(data)
  23. self.controller = require("UIFashion/UIFashionCtr"):new()
  24. self.controller:Init(self)
  25. self.controller:SetData(data)
  26. end
  27. function UIFashionView:AddEventListener()
  28. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  29. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.HERO_JOB_CHANGE_SUCCESS, self, self.RefreshShowModel)
  30. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.FASHION_LIST_CHANGE, self, self.RefreshFashionDataAndShow)
  31. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.FASHION_WEAR_CHANGE, self, self.RefreshFashionWearChange)
  32. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.FASHION_LV_UP_CHANGE, self, self.RefreshFashionDataAndShow)
  33. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.FASHION_WASH_CHANGE, self, self.RefreshDetailView)
  34. end
  35. function UIFashionView:FillContent(data, uiBase)
  36. self.uiBase = uiBase
  37. local gameObject = self.uiBase:GetRoot()
  38. if gameObject ~= nil then
  39. self.gameObject = gameObject
  40. self.transform = gameObject.transform
  41. end
  42. self:InitGenerate(self.transform, data)
  43. self:Init()
  44. end
  45. function UIFashionView:Init()
  46. lvUpState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(68)
  47. washState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(69)
  48. userSex = ManagerContainer.DataMgr.UserData:GetSex()
  49. self:InitFashionChangeView()
  50. self:OnToggleChangeSwitch(nil, nil, true)
  51. self:InitShowModel()
  52. end
  53. function UIFashionView:RemoveEventListener()
  54. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  55. end
  56. function UIFashionView:AddUIEventListener()
  57. self.model.uIEventTriggerListener.onDrag = function()
  58. local deltaX = self.model.uIEventTriggerListener.currentEventData.delta.x
  59. if roleViewSystem then
  60. local go = roleViewSystem:GetGameObject()
  61. if go then
  62. go.transform:Rotate(Vector3.New(0, deltaX > 0 and -7 or 7, 0))
  63. end
  64. end
  65. end
  66. self.uiBase:AddToggleEventListener(self.switch.toggle, self, self.OnToggleChangeSwitch, nil)
  67. -- 换时装
  68. self.uiBase:AddToggleEventListener(self.toggleScrollView.togAll.toggle, self, self.OnToggleChangeFashionToggle, nil)
  69. self.uiBase:AddToggleEventListener(self.toggleScrollView.togHeadTop.toggle, self, self.OnToggleChangeFashionToggle, Enum.FashionSlotType.HeadTop)
  70. self.uiBase:AddToggleEventListener(self.toggleScrollView.togHeadMiddle.toggle, self, self.OnToggleChangeFashionToggle, Enum.FashionSlotType.HeadMiddle)
  71. self.uiBase:AddToggleEventListener(self.toggleScrollView.togHeadMiddle.toggle, self, self.OnToggleChangeFashionToggle, Enum.FashionSlotType.HeadMiddle)
  72. self.uiBase:AddToggleEventListener(self.toggleScrollView.togHeadBottom.toggle, self, self.OnToggleChangeFashionToggle, Enum.FashionSlotType.HeadBottom)
  73. self.uiBase:AddToggleEventListener(self.toggleScrollView.togClothes.toggle, self, self.OnToggleChangeFashionToggle, Enum.FashionSlotType.Cloth)
  74. self.uiBase:AddToggleEventListener(self.toggleScrollView.togWeapon.toggle, self, self.OnToggleChangeFashionToggle, Enum.FashionSlotType.Weapon)
  75. self.uiBase:AddToggleEventListener(self.toggleScrollView.togBack.toggle, self, self.OnToggleChangeFashionToggle, Enum.FashionSlotType.BodyBack)
  76. self.uiBase:AddButtonEventListener(self.btnGoto.button, self, self.OnClickFashionGotoBtn)
  77. self.uiBase:AddButtonEventListener(self.btnAllAttr.button, self, self.OnClickFashionAllAttrBtn)
  78. self.uiBase:AddButtonEventListener(self.btnSave.button, self, self.OnClickFashionSaveBtn)
  79. self.uiBase:AddButtonEventListener(self.uIBook.btnUpgrade.button, self, self.OnClickUpgradeBtn)
  80. self.uiBase:AddButtonEventListener(self.uIBook.btnWash.button, self, self.OnClickWashBtn)
  81. self.uiBase:AddButtonEventListener(self.btnSuites.button, self, self.OnClickSuitesBtn)
  82. end
  83. function UIFashionView:OnHide()
  84. if self.pageSequence then
  85. self.pageSequence:Kill()
  86. self.pageSequence = nil
  87. end
  88. if previewSystem then
  89. previewSystem:Dispose()
  90. end
  91. previewSystem = nil
  92. if mirrorPreviewSystem then
  93. mirrorPreviewSystem:Dispose()
  94. end
  95. mirrorPreviewSystem = nil
  96. if roleViewSystem then
  97. roleViewSystem:Dispose()
  98. end
  99. roleViewSystem = nil
  100. end
  101. function UIFashionView:OnShow(data)
  102. self.controller:SetData(data)
  103. self.uIBook:SetActive(false)
  104. self:OnToggleChangeSwitch(nil, nil, true)
  105. self:InitShowModel()
  106. end
  107. function UIFashionView:OnClose()
  108. end
  109. function UIFashionView:OnDispose()
  110. self.controller:OnDispose()
  111. self.model.uIEventTriggerListener.onDrag = nil
  112. self.scrollView.loopGridView:Dispose()
  113. self:DisposeJobOnly()
  114. if self.pageSequence then
  115. self.pageSequence:Kill()
  116. self.pageSequence = nil
  117. end
  118. if previewSystem then
  119. previewSystem:Dispose()
  120. end
  121. previewSystem = nil
  122. if mirrorPreviewSystem then
  123. mirrorPreviewSystem:Dispose()
  124. end
  125. mirrorPreviewSystem = nil
  126. if roleViewSystem then
  127. roleViewSystem:Dispose()
  128. end
  129. roleViewSystem = nil
  130. end
  131. function UIFashionView:InitShowModel()
  132. if not roleViewSystem then
  133. roleViewSystem = RoleViewSystem:new()
  134. end
  135. if not previewSystem then
  136. previewSystem = PreviewSystem:new("Preview")
  137. previewSystem:SetView(Vector3(-0.116, 1.649, 2.5), Quaternion.Euler(12.174, -182.628, 0.085))
  138. end
  139. if not mirrorPreviewSystem then
  140. mirrorPreviewSystem = MirrorPreviewSystem:new("MirrorPreview", nil, nil, nil, previewSystem:GetCamera())
  141. end
  142. self.model:SetActive(true)
  143. self.model.rawImage.texture = previewSystem:GetRenderTexture()
  144. self.mirrorModel:SetActive(true)
  145. self.mirrorModel.rawImage.texture = mirrorPreviewSystem:GetRenderTexture()
  146. self:RefreshShowModel()
  147. end
  148. function UIFashionView:RefreshShowModel()
  149. roleViewSystem:RefreshView(Enum.RoleInEnvType.FashionView, self.controller:GetRoleCfgId(), self.controller:GetViewData(), nil, self, self.RefreshShowComplete)
  150. end
  151. function UIFashionView:RefreshShowComplete(go, isNewGo)
  152. local ViewPageType = self.controller:GetViewPageType()
  153. local curViewPageType = self.controller:GetCurViewPageType()
  154. if curViewPageType ~= ViewPageType.Change then return end
  155. if previewSystem then
  156. previewSystem:UpdateGo(go)
  157. end
  158. if mirrorPreviewSystem then
  159. mirrorPreviewSystem:UpdateGo(go)
  160. end
  161. end
  162. function UIFashionView:InitFashionChangeView()
  163. self.scrollView.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  164. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  165. end, nil)
  166. end
  167. function UIFashionView:GetItemByRowColumn(gridView, itemIndex, row, column)
  168. -- local length = self.controller:GetShowDataLength()
  169. -- if (itemIndex < 0 or itemIndex >= length) then
  170. -- return nil
  171. -- end
  172. local fashionCfgData = self.controller:GetShowData(itemIndex)
  173. local item
  174. if fashionCfgData then
  175. item = gridView:NewListViewItem('FashionWearItem')
  176. local itemlua = CommonUtil.BindGridViewItem2Lua(self, 'FashionWearItem', item.gameObject)
  177. CommonUtil.CloseUIClearAsyncSeqIds(itemlua)
  178. itemlua.icon.image.sprite = nil
  179. itemlua.icon.image.enabled = false
  180. itemlua.frame.image.sprite = nil
  181. itemlua.frame.image.enabled = false
  182. local cfgId = fashionCfgData.FashionId
  183. CommonUtil.LoadIcon(self, fashionCfgData.FashionIcon, function (sprite)
  184. itemlua.icon.image.sprite = sprite
  185. itemlua.icon.image.enabled = true
  186. end, itemlua, "FashionWearItemIconAsyncIdx")
  187. CommonUtil.LoadIcon(self, Constant.Quality_Frame_Icons[fashionCfgData.FashionQuality], function (sprite)
  188. itemlua.frame.image.sprite = sprite
  189. itemlua.frame.image.enabled = true
  190. end, itemlua, "FashionWearItemFrameAsyncIdx")
  191. local ViewPageType = self.controller:GetViewPageType()
  192. local curViewPageType = self.controller:GetCurViewPageType()
  193. local seleced = false
  194. local seleced2 = false
  195. local disable = false
  196. if (curViewPageType == ViewPageType.Change) then
  197. seleced2 = false
  198. seleced = self.controller:IsWear(cfgId)
  199. if seleced then
  200. self.controller:SetCurSelectItemIndex(itemIndex)
  201. end
  202. disable = not self.controller:CanWear(fashionCfgData)
  203. CommonUtil.SetTotalChildrenGray(itemlua.group, false)
  204. itemlua.group.canvasGroup.alpha = 1
  205. itemlua.redPoint:SetActive(ManagerContainer.DataMgr.FashionData:IsNew(cfgId))
  206. else
  207. seleced = false
  208. local curItemIndex = self.controller:GetCurSelectItemIndex()
  209. seleced2 = (curItemIndex == itemIndex)
  210. CommonUtil.SetTotalChildrenGray(itemlua.group, not self.controller:IsOwner(cfgId))
  211. itemlua.group.canvasGroup.alpha = self.controller:IsOwner(cfgId) and 1 or 0.6
  212. itemlua.redPoint:SetActive(ManagerContainer.DataMgr.FashionData:CanLvUp(cfgId))
  213. if seleced2 then
  214. self.uIBook.btnUpgrade.uIRedPointRP:SetActive(lvUpState and ManagerContainer.DataMgr.FashionData:CanLvUp(cfgId))
  215. end
  216. end
  217. itemlua.icon:SetActive(true)
  218. itemlua.bg:SetActive(true)
  219. itemlua.frame:SetActive(true)
  220. itemlua.selected:SetActive(seleced)
  221. itemlua.selected2:SetActive(seleced2)
  222. itemlua.disable:SetActive(disable)
  223. itemlua.bg.button.onClick:RemoveAllListeners()
  224. itemlua.bg.button.onClick:AddListener(function()
  225. self:OnClickItem(fashionCfgData, itemIndex)
  226. end)
  227. local fashionLogicData = self.controller:GetFashionLogicData(fashionCfgData.FashionId)
  228. itemlua.num.text.text = "Lv "..(fashionLogicData and fashionLogicData.lv or 1)
  229. else
  230. item = gridView:NewListViewItem('IconEmptyItem')
  231. end
  232. return item
  233. end
  234. function UIFashionView:OnClickItem(fashionCfgData, itemIndex)
  235. local ViewPageType = self.controller:GetViewPageType()
  236. local curViewPageType = self.controller:GetCurViewPageType()
  237. local cfgId = fashionCfgData.FashionId
  238. if (curViewPageType == ViewPageType.Change) then
  239. local loopGridView = self:GetLoopGridView()
  240. local changed = ManagerContainer.DataMgr.FashionData:CancelNewState(cfgId)
  241. local errorCode, lastCfgId = self.controller:ChangeWear(fashionCfgData)
  242. if errorCode == 2 then
  243. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('WeaponfashionTip_3')
  244. if changed then
  245. loopGridView:RefreshItemByItemIndex(itemIndex)
  246. end
  247. return
  248. elseif errorCode ~= 0 then
  249. if changed then
  250. loopGridView:RefreshItemByItemIndex(itemIndex)
  251. end
  252. return
  253. end
  254. self.controller:SetCurSelectItemIndex(itemIndex)
  255. local lastItemIndex = self.controller:GetItemIndexByCfgId(lastCfgId)
  256. if lastItemIndex then
  257. loopGridView:RefreshItemByItemIndex(lastItemIndex)
  258. end
  259. loopGridView:RefreshItemByItemIndex(itemIndex)
  260. self:RefreshShowModel()
  261. local curSelectFashionSlotType = self.controller:GetCurSelectFashionSlotType()
  262. if self.controller:RefreshRPInfo(curSelectFashionSlotType) then
  263. self:RefreshToggleView()
  264. end
  265. else
  266. local curItemIndex = self.controller:GetCurSelectItemIndex()
  267. if not self.controller:SetCurSelectItemIndex(itemIndex) then return end
  268. local loopGridView = self:GetLoopGridView()
  269. if curItemIndex then
  270. loopGridView:RefreshItemByItemIndex(curItemIndex)
  271. end
  272. loopGridView:RefreshItemByItemIndex(itemIndex)
  273. self:RefreshDetailView()
  274. self.uIBook.btnUpgrade.uIRedPointRP:SetActive(ManagerContainer.DataMgr.FashionData:CanLvUp(cfgId))
  275. end
  276. end
  277. function UIFashionView:RefreshFashionDataAndShow()
  278. self.controller:RefreshShowData()
  279. self:RefreshGridView(false)
  280. self:RefreshToggleView()
  281. self:RefreshDetailView()
  282. end
  283. function UIFashionView:RefreshFashionWearChange()
  284. if self.controller:IsSaveFashionSuccess() then
  285. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(100006)
  286. end
  287. end
  288. function UIFashionView:RefreshView(resetPos)
  289. --self:RefreshPageView()
  290. self:RefreshGridView(resetPos)
  291. self:RefreshToggleView()
  292. self:RefreshDetailView()
  293. end
  294. function UIFashionView:RefreshPageView()
  295. local ViewPageType = self.controller:GetViewPageType()
  296. local curViewPageType = self.controller:GetCurViewPageType()
  297. if curViewPageType == ViewPageType.Change then
  298. self.model:SetActive(true)
  299. self.mirrorModel:SetActive(true)
  300. if mirrorPreviewSystem and roleViewSystem then
  301. mirrorPreviewSystem:AddGo(roleViewSystem:GetGameObject())
  302. end
  303. if previewSystem and roleViewSystem then
  304. previewSystem:AddGo(roleViewSystem:GetGameObject())
  305. end
  306. else
  307. if mirrorPreviewSystem and roleViewSystem then
  308. mirrorPreviewSystem:RemoveGo(roleViewSystem:GetGameObject())
  309. end
  310. if previewSystem and roleViewSystem then
  311. previewSystem:RemoveGo(roleViewSystem:GetGameObject())
  312. end
  313. self.model:SetActive(false)
  314. self.mirrorModel:SetActive(false)
  315. end
  316. self.controller:SetCurSelectItemIndex(0)
  317. --if self.pageSequence then
  318. -- self.pageSequence:Kill()
  319. -- self.pageSequence = nil
  320. --end
  321. --local seq = nil
  322. --if self.uIBook.activeSelf then
  323. -- seq = DOTween.Sequence()
  324. -- seq:AppendCallback(function()
  325. -- self.uIFashionAnim.animator:Play('BookIn')
  326. -- end)
  327. --else
  328. -- seq = DOTween.Sequence()
  329. -- seq:AppendCallback(function()
  330. -- self.uIFashionAnim.animator:Play('FashionIn')
  331. -- end)
  332. --end
  333. --self.pageSequence = seq
  334. self:RefreshSwitchToggleView()
  335. end
  336. function UIFashionView:RefreshSwitchToggleView()
  337. local ViewPageType = self.controller:GetViewPageType()
  338. local curViewPageType = self.controller:GetCurViewPageType()
  339. if curViewPageType == ViewPageType.Change then
  340. self.switch.animator:CrossFade('SwitchToFashion', 0.1)
  341. self.switch.toggle.isOn = true
  342. self.uIFashionAnim.animator:Play('FashionIn')
  343. else
  344. self.switch.animator:CrossFade('SwitchToBook', 0.1)
  345. self.switch.toggle.isOn = false
  346. self.uIFashionAnim.animator:Play('BookIn')
  347. end
  348. self.btnSave:SetActive(curViewPageType == ViewPageType.Change)
  349. end
  350. function UIFashionView:RefreshToggleView()
  351. local togglelua = self:GetToggleLua()
  352. if not togglelua then return end
  353. local ViewPageType = self.controller:GetViewPageType()
  354. local curViewPageType = self.controller:GetCurViewPageType()
  355. local isNeedPoint = (curViewPageType == ViewPageType.Change)
  356. togglelua.togAll.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus())
  357. togglelua.togHeadTop.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.HeadTop))
  358. togglelua.togHeadMiddle.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.HeadMiddle))
  359. togglelua.togHeadBottom.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.HeadBottom))
  360. togglelua.togClothes.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.Cloth))
  361. togglelua.togWeapon.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.Weapon))
  362. togglelua.togBack.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.BodyBack))
  363. -- togglelua.togHair.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.HairStyle))
  364. -- togglelua.togEye.redPoint:SetActive(isNeedPoint and self.controller:GetRPStatus(Enum.FashionSlotType.Pupil))
  365. -- CommonUtil.SetTotalChildrenGray(togglelua.togWeapon, self.controller:IsBeginner())
  366. self:RefreshSelectToggleView()
  367. end
  368. function UIFashionView:RefreshSelectToggleView()
  369. local togglelua = self:GetToggleLua()
  370. if not togglelua then return end
  371. local curSelectFashionSlotType = self.controller:GetCurSelectFashionSlotType()
  372. if togglelua then
  373. local toggleGroup = togglelua.content.toggleGroup
  374. local oldAllowSwitchOff = toggleGroup.allowSwitchOff
  375. toggleGroup.allowSwitchOff = true
  376. togglelua.togAll.toggle.isOn = (curSelectFashionSlotType == nil)
  377. togglelua.togHeadTop.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.HeadTop)
  378. togglelua.togHeadMiddle.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.HeadMiddle)
  379. togglelua.togHeadBottom.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.HeadBottom)
  380. togglelua.togClothes.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.Cloth)
  381. togglelua.togWeapon.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.Weapon)
  382. togglelua.togBack.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.BodyBack)
  383. -- togglelua.togHair.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.HairStyle)
  384. -- togglelua.togEye.toggle.isOn = (curSelectFashionSlotType == Enum.FashionSlotType.Pupil)
  385. toggleGroup.allowSwitchOff = oldAllowSwitchOff
  386. end
  387. end
  388. function UIFashionView:RefreshGridView(resetPos)
  389. local loopGridView = self:GetLoopGridView()
  390. local length = self.controller:GetShowDataLength()
  391. if resetPos then
  392. loopGridView:RefreshListByIndex(length, 0)
  393. else
  394. loopGridView:RefreshListByIndex(length)
  395. end
  396. end
  397. function UIFashionView:RefreshDetailView()
  398. local ViewPageType = self.controller:GetViewPageType()
  399. local curViewPageType = self.controller:GetCurViewPageType()
  400. if curViewPageType ~= ViewPageType.Book then
  401. return
  402. end
  403. local curSelectItemIndex = self.controller:GetCurSelectItemIndex()
  404. local fashionCfgData = self.controller:GetShowData(curSelectItemIndex)
  405. if not fashionCfgData then
  406. local curSelectItemIndex = 1
  407. fashionCfgData = self.controller:GetShowData(curSelectItemIndex)
  408. if not fashionCfgData then
  409. return
  410. end
  411. self:OnClickItem(fashionCfgData, curSelectItemIndex - 1)
  412. return
  413. end
  414. local maxLv = ManagerContainer.CfgMgr:GetFashionMaxLv()
  415. local isOwned = self.controller:IsOwner(fashionCfgData.FashionId)
  416. local curLv = 0
  417. local detail = self.uIBook.detail
  418. local suites = self.suites
  419. detail.icon.image.sprite = nil
  420. detail.itemName:SetActive(fashionCfgData ~= nil)
  421. detail.slotPosName:SetActive(fashionCfgData ~= nil)
  422. detail.describe:SetActive(fashionCfgData ~= nil)
  423. detail.icon:SetActive(fashionCfgData ~= nil)
  424. if fashionCfgData then
  425. local fashionLogicData = self.controller:GetFashionLogicData(fashionCfgData.FashionId)
  426. curLv = fashionLogicData and fashionLogicData.lv or 1
  427. detail.itemName.text.text = I18N.SetLanguageValue(fashionCfgData.FashionName)
  428. detail.lv.text.text = curLv .. "/"..maxLv
  429. detail.slotPosName.text.text = I18N.SetLanguageValue('FashionSlot_' .. tostring(fashionCfgData.FashionLocation))
  430. detail.describe.text.text = I18N.SetLanguageValue(fashionCfgData.FashionDepict)
  431. CommonUtil.LoadIcon(self, fashionCfgData.FashionIcon, function (sprite)
  432. detail.icon.image.sprite = sprite
  433. end, self, "DetailIconAsyncIdx")
  434. self:RefreshJobOnly(fashionCfgData.FashionUseJob)
  435. if fashionLogicData then
  436. local attrs = fashionLogicData.attrs
  437. table.sort(attrs, function (a,b)
  438. if a.jobType == b.jobType then
  439. return a.attrId < b.attrId
  440. else
  441. local posA = ManagerContainer.CfgMgr:GetPartnerPostIdByJobType(a.jobType)
  442. local posB = ManagerContainer.CfgMgr:GetPartnerPostIdByJobType(b.jobType)
  443. return posA < posB
  444. end
  445. end)
  446. for i = 1, 5 do
  447. local propertyItem = detail['propertyItem' .. i]
  448. if propertyItem then
  449. local fashionAttr = attrs[i]
  450. if fashionAttr then
  451. local jobType = fashionAttr.jobType
  452. local attrId = fashionAttr.attrId
  453. local attrValue = fashionAttr.value
  454. local jobName = self.controller:GetJobTypeName(jobType)
  455. propertyItem.prName.text.text = jobName..I18N.SetLanguageValue(CommonUtil.HeroAttrFormatName(attrId, attrValue))
  456. propertyItem.number.text.text = "+"..attrValue
  457. propertyItem:SetActive(true)
  458. else
  459. propertyItem:SetActive(false)
  460. end
  461. end
  462. end
  463. else
  464. for i = 1, 5 do
  465. local propertyItem = detail['propertyItem' .. i]
  466. if propertyItem then
  467. propertyItem:SetActive(i <= fashionCfgData.AttrNum)
  468. if i <= fashionCfgData.AttrNum then
  469. propertyItem.prName.text.text = I18N.T("RandomAttr1")
  470. propertyItem.number.text.text = I18N.T("RandomAttr2")
  471. end
  472. end
  473. end
  474. end
  475. CommonUtil.SetTotalChildrenGray(self.uIBook.btnUpgrade, not lvUpState or not isOwned)
  476. CommonUtil.SetTotalChildrenGray(self.uIBook.btnWash, not washState or not isOwned)
  477. self.uIBook.btnUpgrade.button.enabled = isOwned
  478. self.uIBook.btnWash.button.enabled = isOwned
  479. if isOwned then
  480. if lvUpState then
  481. self.uIBook.btnUpgrade:SetActive(curLv < maxLv)
  482. self.uIBook.labelMax:SetActive(curLv >= maxLv)
  483. else
  484. self.uIBook.labelMax:SetActive(false)
  485. end
  486. end
  487. for i = 1, 4 do
  488. local suitesLvItem = suites['suitesLvItem' .. i]
  489. if suitesLvItem then
  490. suitesLvItem:SetActive(false)
  491. end
  492. end
  493. local suitIds = fashionCfgData.SuitId
  494. local idx = 0
  495. for i = 1, #suitIds do
  496. idx = idx + 1
  497. if idx > 4 then
  498. break
  499. end
  500. local suitesLvItem = suites['suitesLvItem' .. idx]
  501. local suitId = suitIds and suitIds[i] or nil
  502. if suitesLvItem then
  503. local suitCfgData = ManagerContainer.CfgMgr:GetFashionSuitDataById(suitId)
  504. local state = suitCfgData and (suitCfgData.SuitSex == 0 or suitCfgData.SuitSex == userSex)
  505. suitesLvItem:SetActive(state)
  506. if state then
  507. suitesLvItem.suitesName.text.text = I18N.T(suitCfgData.SuitName)
  508. local lv = self.controller:GetFashionSuitLv(suitId)
  509. suitesLvItem.activity:SetActive(lv > 0)
  510. suitesLvItem.numlv.text.text = lv > 0 and lv or 1
  511. else
  512. idx = idx - 1
  513. end
  514. end
  515. end
  516. else
  517. for i = 1, 5 do
  518. local propertyItem = detail['propertyItem' .. i]
  519. if propertyItem then
  520. propertyItem:SetActive(false)
  521. end
  522. end
  523. for i = 1, 4 do
  524. local suitesLvItem = suites['suitesLvItem' .. i]
  525. if suitesLvItem then
  526. suitesLvItem:SetActive(false)
  527. end
  528. end
  529. end
  530. end
  531. function UIFashionView:RefreshJobOnly(jobIds)
  532. if not jobIds then
  533. self.uIBook.detail.noJob:SetActive(true)
  534. self.uIBook.detail.jobBox:SetActive(false)
  535. return
  536. end
  537. local len1 = #jobIds
  538. if len1 <= 0 then
  539. self.uIBook.detail.noJob:SetActive(true)
  540. self.uIBook.detail.jobBox:SetActive(false)
  541. return
  542. end
  543. local len2
  544. if not self.jobBoxIcons then
  545. self.jobBoxIcons = {}
  546. len2 = 0
  547. else
  548. len2 = #self.jobBoxIcons
  549. end
  550. self.uIBook.detail.noJob:SetActive(false)
  551. self.uIBook.detail.jobBox:SetActive(true)
  552. self.uIBook.detail.jobBox.icon:SetActive(false)
  553. local parent = self.uIBook.detail.jobBox.icon.transform.parent
  554. for i = 1, len1 do
  555. local jobBoxIcon
  556. if i <= len2 then
  557. jobBoxIcon = self.jobBoxIcons[i]
  558. else
  559. jobBoxIcon = {}
  560. local go = CommonUtil.Instantiate(self.uIBook.detail.jobBox.icon, parent)
  561. jobBoxIcon.go = go
  562. jobBoxIcon.image = go:GetComponent(Enum.TypeInfo.Image)
  563. self.jobBoxIcons[i] = jobBoxIcon
  564. end
  565. local jobCfgData = ManagerContainer.CfgMgr:GetJobDataById(jobIds[i])
  566. jobBoxIcon.go:SetActive(true)
  567. jobBoxIcon.image.enabled = false
  568. jobBoxIcon.image.sprite = nil
  569. CommonUtil.CloseUIClearAsyncSeqIds(jobBoxIcon)
  570. if jobCfgData then
  571. CommonUtil.LoadIcon(self, jobCfgData.JobIcon, function(sprite)
  572. jobBoxIcon.image.enabled = true
  573. jobBoxIcon.image.sprite = sprite
  574. end, jobBoxIcon, 'JobIcon')
  575. end
  576. end
  577. for i = len1 + 1, len2 do
  578. local jobBoxIcon = self.jobBoxIcons[i]
  579. jobBoxIcon.go:SetActive(false)
  580. jobBoxIcon.image.sprite = nil
  581. end
  582. end
  583. function UIFashionView:DisposeJobOnly()
  584. if self.jobBoxIcons then
  585. for _, jobBoxIcon in pairs(self.jobBoxIcons) do
  586. CommonUtil.CloseUIClearAsyncSeqIds(jobBoxIcon)
  587. CommonUtil.DestroyGO(jobBoxIcon.go)
  588. jobBoxIcon.go = nil
  589. jobBoxIcon.image = nil
  590. end
  591. self.jobBoxIcons = nil
  592. end
  593. end
  594. function UIFashionView:GetToggleLua()
  595. return self.toggleScrollView
  596. end
  597. function UIFashionView:GetLoopGridView()
  598. return self.scrollView.loopGridView
  599. end
  600. function UIFashionView:OnToggleChangeSwitch(toggle, params, value)
  601. -- 在一帧内不重复刷新
  602. if self:IsSomeFrameCount('lastSwitchChange') then
  603. return
  604. end
  605. local timeStamp = Time.GetTimestamp()
  606. if LastSwitchTime and (LastSwitchTime + SwitchInterval) >= timeStamp then
  607. self:RefreshSwitchToggleView()
  608. return
  609. end
  610. LastSwitchTime = timeStamp
  611. local ViewPageType = self.controller:GetViewPageType()
  612. local curViewPageType = self.controller:GetCurViewPageType()
  613. if curViewPageType == ViewPageType.Change then
  614. if not value then
  615. if self.controller:IsChangeFashion() then
  616. local data = {"ChangeFashionSure", nil, NoticeNextType.EnterBookView, self, self.SureChangeFashion, self.CancelChangeFashion}
  617. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  618. --self:RefreshSwitchToggleView()
  619. return
  620. end
  621. end
  622. end
  623. local newViewPageType = value and ViewPageType.Change or ViewPageType.Book
  624. if not self.controller:ChangeViewPage(newViewPageType) then
  625. return
  626. end
  627. self:RefreshPageView()
  628. self:RefreshView(true)
  629. end
  630. function UIFashionView:OnToggleChangeFashionToggle(toggle, params, value)
  631. if not value then return end
  632. -- 在一帧内不重复刷新
  633. if self:IsSomeFrameCount(toggle.name .. '_LastChange') then
  634. return
  635. end
  636. local fashionSlotType = params
  637. local curSelectFashionSlotType = self.controller:GetCurSelectFashionSlotType()
  638. if curSelectFashionSlotType == fashionSlotType then return end
  639. -- if fashionSlotType == Enum.FashionSlotType.Weapon then
  640. -- if self.controller:IsBeginner() then
  641. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('FashionTabLockTips')
  642. -- self:RefreshSelectToggleView()
  643. -- return
  644. -- end
  645. -- end
  646. self.controller:RefreshShowDataType(fashionSlotType)
  647. self:RefreshView(true)
  648. end
  649. function UIFashionView:OnClickFashionGotoBtn()
  650. local ViewPageType = self.controller:GetViewPageType()
  651. local curViewPageType = self.controller:GetCurViewPageType()
  652. if curViewPageType == ViewPageType.Change then
  653. if self.controller:IsChangeFashion() then
  654. local data = {"ChangeFashionSure", nil, NoticeNextType.EnterRoleView, self, self.SureChangeFashion, self.CancelChangeFashion}
  655. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  656. return
  657. end
  658. end
  659. self:SureChangeFashion(NoticeNextType.EnterRoleView)
  660. end
  661. function UIFashionView:OnClickFashionAllAttrBtn()
  662. local attrs, attrs1 = self.controller:GetAllFashionAttr()
  663. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFashionTotal, {title="TitleFashionSuitAttrAll", title1 = "TitleFashionAttrAll", attrs=attrs, attrs1 = attrs1})
  664. end
  665. function UIFashionView:SureChangeFashion(nextType)
  666. self.controller:SendFashionChange()
  667. if nextType == NoticeNextType.EnterRoleView then
  668. ManagerContainer.LuaUIMgr:OpenSourceUI(self, self.controller:GetHeroId())
  669. --ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRoleMain1, self.controller:GetHeroId())
  670. elseif nextType == NoticeNextType.EnterBookView then
  671. self:SetCurFrameCount('lastSwitchChange')
  672. local ViewPageType = self.controller:GetViewPageType()
  673. if not self.controller:ChangeViewPage(ViewPageType.Book) then
  674. return
  675. end
  676. self:RefreshPageView()
  677. self:RefreshView(true)
  678. end
  679. end
  680. function UIFashionView:CancelChangeFashion(nextType)
  681. self.controller:CacheViewData()
  682. self:RefreshShowModel()
  683. if nextType == NoticeNextType.EnterRoleView then
  684. ManagerContainer.LuaUIMgr:OpenSourceUI(self, self.controller:GetHeroId())
  685. -- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRoleMain1, self.controller:GetHeroId())
  686. elseif nextType == NoticeNextType.EnterBookView then
  687. self:SetCurFrameCount('lastSwitchChange')
  688. local ViewPageType = self.controller:GetViewPageType()
  689. if not self.controller:ChangeViewPage(ViewPageType.Book) then
  690. return
  691. end
  692. self:RefreshPageView()
  693. self:RefreshView(true)
  694. end
  695. end
  696. function UIFashionView:OnClickFashionSaveBtn()
  697. if LastSaveTime and (LastSaveTime + SaveInterval) >= Time.GetTimestamp() then
  698. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay(100007)
  699. return
  700. end
  701. LastSaveTime = Time.GetTimestamp()
  702. self.controller:SendFashionChange()
  703. end
  704. function UIFashionView:OnClickFashionShopBtn()
  705. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay('FunctionLock')
  706. end
  707. function UIFashionView:SetCurFrameCount(keyName)
  708. self[keyName] = Time.frameCount
  709. end
  710. function UIFashionView:IsSomeFrameCount(keyName)
  711. local value = self[keyName]
  712. if value and value >= Time.frameCount then
  713. return true
  714. end
  715. self[keyName] = Time.frameCount
  716. return false
  717. end
  718. function UIFashionView:OnClickUpgradeBtn()
  719. local curSelectItemIndex = self.controller:GetCurSelectItemIndex()
  720. local fashionCfgData = self.controller:GetShowData(curSelectItemIndex)
  721. if fashionCfgData then
  722. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFashionLvUp, fashionCfgData.FashionId)
  723. end
  724. end
  725. function UIFashionView:OnClickWashBtn()
  726. local curSelectItemIndex = self.controller:GetCurSelectItemIndex()
  727. local fashionCfgData = self.controller:GetShowData(curSelectItemIndex)
  728. if fashionCfgData then
  729. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFashionWash, fashionCfgData.FashionId)
  730. end
  731. end
  732. function UIFashionView:OnClickSuitesBtn()
  733. local curSelectItemIndex = self.controller:GetCurSelectItemIndex()
  734. local fashionCfgData = self.controller:GetShowData(curSelectItemIndex)
  735. if fashionCfgData then
  736. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFashionSuitesTips, fashionCfgData.FashionId)
  737. end
  738. end
  739. return UIFashionView