UIPopGotSingleView.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. local UIPopGotSingleView = require("UIPOPGot/UIPopGotSingleView_Generate")
  2. --local UIMainCtr = require('UIMain/UIMainCtr')
  3. --local UIBattleCtr = require('UIBattle/UIBattleCtr')
  4. local UIMainCtr = ManagerContainer.LuaUIMgr:GetViewCtrById(Enum.UIPageName.UIMain)
  5. local UIBattleCtr = ManagerContainer.LuaUIMgr:GetViewCtrById(Enum.UIPageName.UIBattle)
  6. local DOTween = DG.Tweening.DOTween
  7. function UIPopGotSingleView:OnAwake(data)
  8. self.controller = require("UIPOPGot/UIPopGotSingleCtr"):new()
  9. self.controller:Init(self)
  10. self.controller:SetData(data)
  11. end
  12. function UIPopGotSingleView:AddEventListener()
  13. end
  14. function UIPopGotSingleView:FillContent(data, uiBase)
  15. self.uiBase = uiBase
  16. local gameObject = self.uiBase:GetRoot()
  17. if gameObject ~= nil then
  18. self.gameObject = gameObject
  19. self.transform = gameObject.transform
  20. end
  21. self:InitGenerate(self.transform, data)
  22. self:Init()
  23. end
  24. function UIPopGotSingleView:Init()
  25. local rectTransform = self.itemIcon.rectTransform
  26. self.defaultLocalPos = rectTransform.localPosition
  27. self.defaultLocalScale = rectTransform.localScale
  28. self:RefreshView()
  29. end
  30. function UIPopGotSingleView:RemoveEventListener()
  31. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  32. end
  33. function UIPopGotSingleView:AddUIEventListener()
  34. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  35. end
  36. function UIPopGotSingleView:OnHide()
  37. end
  38. function UIPopGotSingleView:OnShow(data)
  39. self.controller:SetData(data)
  40. end
  41. function UIPopGotSingleView:OnClose()
  42. end
  43. function UIPopGotSingleView:OnDispose()
  44. local rectTransform = self.itemIcon.rectTransform
  45. rectTransform.localPosition = self.defaultLocalPos
  46. rectTransform.localScale = self.defaultLocalScale
  47. local seq = self.doTweenSequence
  48. if seq then
  49. seq:Kill()
  50. seq = nil
  51. end
  52. self.controller:OnDispose()
  53. end
  54. function UIPopGotSingleView:RefreshView()
  55. local storySectionId = self.controller:GetStorySectionId()
  56. local storySectionData = ManagerContainer.CfgMgr:GetStorySectionById(storySectionId)
  57. if not storySectionData then return end
  58. local storySectionType = storySectionData.Type
  59. local iconPath
  60. if storySectionType == Enum.StorySectionEventType.UnlockHangBox then
  61. iconPath = storySectionData.ArtRes
  62. if storySectionData.Content then
  63. self.titleText.uILocalizeScript:SetContent(storySectionData.Content[1])
  64. self.nameText.uILocalizeScript:SetContent(storySectionData.Content[2])
  65. end
  66. elseif storySectionType == Enum.StorySectionEventType.UnlockTask then
  67. iconPath = storySectionData.ArtRes
  68. if storySectionData.Content then
  69. self.titleText.uILocalizeScript:SetContent(storySectionData.Content[1])
  70. self.nameText.uILocalizeScript:SetContent(storySectionData.Content[2])
  71. end
  72. elseif storySectionType == Enum.StorySectionEventType.GotItem then
  73. iconPath = storySectionData.ArtRes
  74. if storySectionData.Content then
  75. self.titleText.uILocalizeScript:SetContent(storySectionData.Content[2])
  76. if storySectionData.Content[3] then
  77. self.nameText.uILocalizeScript:SetContent(storySectionData.Content[3])
  78. else
  79. local itemCfgId = storySectionData.Content[1]
  80. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemCfgId)
  81. if itemCfgData then
  82. local quality = CommonUtil.GetItemQuality(itemCfgId)
  83. self.nameText.uILocalizeScript:SetContentAndValuesWithColor(itemCfgData.Name, nil, Constant.ColorTextArray[quality])
  84. end
  85. end
  86. end
  87. else
  88. return
  89. end
  90. self.icon.image.sprite = nil
  91. self.icon.image.enabled = false
  92. CommonUtil.LoadIcon(self, iconPath, function (sprite)
  93. self.icon.image.sprite = sprite
  94. self.icon.image.enabled = true
  95. end, self, 'ItemIconAsyncIdx')
  96. local seq = self.doTweenSequence
  97. if seq then
  98. seq:Kill()
  99. seq = nil
  100. end
  101. seq = DOTween.Sequence()
  102. self.doTweenSequence = seq
  103. local rectTransform = self.itemIcon.rectTransform
  104. rectTransform.localPosition = self.defaultLocalPos
  105. rectTransform.localScale = self.defaultLocalScale
  106. local startPos = self.controller:GetStartPos()
  107. rectTransform.localScale = Vector3.one
  108. rectTransform.position = startPos
  109. self.uIAnimator.animator:Play('PopGotSingleIn')
  110. seq:Append(rectTransform:DOLocalMove(self.defaultLocalPos, 0.5))
  111. seq:Join(rectTransform:DOScale(self.defaultLocalScale, 0.5))
  112. seq:AppendCallback(function()
  113. self.uIAnimator.animator:Play('PopGotSingleTextIn')
  114. end)
  115. seq:AppendInterval(3)
  116. seq:AppendCallback(function()
  117. self.uIAnimator.animator:Play('PopGotSingleOut')
  118. end)
  119. if storySectionType == Enum.StorySectionEventType.UnlockHangBox then
  120. if UIBattleCtr then
  121. seq:Append(rectTransform:DOMove(UIBattleCtr:GeAnchoredPosition3DByType(Enum.ItemType.Item), 0.5))
  122. seq:Join(rectTransform:DOScale(Vector3.one * 0.3, 0.5))
  123. end
  124. elseif storySectionType == Enum.StorySectionEventType.UnlockTask then
  125. if UIMainCtr then
  126. seq:Append(rectTransform:DOMove(UIMainCtr:GetTaskBtnPosition(), 0.5))
  127. seq:Join(rectTransform:DOScale(Vector3.one * 0.3, 0.5))
  128. end
  129. elseif storySectionType == Enum.StorySectionEventType.GotItem then
  130. if UIMainCtr then
  131. seq:Append(rectTransform:DOMove(UIMainCtr:GetGotAnimEndPosByType(Enum.ItemType.Item), 0.5))
  132. seq:Join(rectTransform:DOScale(Vector3.one * 0.3, 0.5))
  133. end
  134. end
  135. seq:AppendCallback(function()
  136. rectTransform.localPosition = self.defaultLocalPos
  137. rectTransform.localScale = self.defaultLocalScale
  138. self:UIClose()
  139. end)
  140. end
  141. return UIPopGotSingleView