UIArtifactStarUpView.lua 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. local UIArtifactStarUpView = require("UIArtifactTips/UIArtifactStarUpView_Generate")
  2. local IconItemCtr = require ("Common.IconItemCtr")
  3. local RectOffset = UnityEngine.RectOffset
  4. function UIArtifactStarUpView:OnAwake(data)
  5. self.controller = require("UIArtifactTips/UIArtifactStarUpCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UIArtifactStarUpView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.SKILL_EQUIP_LV_UP_REFRESH, self, self.StarUpSuccess)
  12. end
  13. function UIArtifactStarUpView:FillContent(data, uiBase)
  14. self.uiBase = uiBase
  15. local gameObject = self.uiBase:GetRoot()
  16. if gameObject ~= nil then
  17. self.gameObject = gameObject
  18. self.transform = gameObject.transform
  19. end
  20. self:InitGenerate(self.transform, data)
  21. self:Init()
  22. end
  23. function UIArtifactStarUpView:Init()
  24. self.fx_ui_refine_success.uIParticle:PlayCachedParticalSystem(false)
  25. self:InitGrid()
  26. self:Refresh()
  27. end
  28. function UIArtifactStarUpView:StarUpSuccess()
  29. self.controller:ClearSelected()
  30. self:RefreshTop()
  31. self:RefreshStarInfo()
  32. self:RefreshCostGrid()
  33. self.fx_ui_refine_success.uIParticle:PlayCachedParticalSystem(true)
  34. end
  35. function UIArtifactStarUpView:OnPageInEnd()
  36. self.super.OnPageInEnd(self)
  37. self:RefreshCostGrid()
  38. end
  39. function UIArtifactStarUpView:InitGrid()
  40. self.scrollView.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  41. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  42. end, nil)
  43. self:InitGridData()
  44. --self.delayTimer = FrameTimer.New(function()
  45. -- self:InitData()
  46. --end, 1)
  47. --self.delayTimer:Start()
  48. end
  49. function UIArtifactStarUpView:InitGridData()
  50. local loopGridView = self.scrollView.loopGridView
  51. local itemSize = loopGridView.ItemSize
  52. local itemPadding = loopGridView.ItemPadding
  53. local padding = loopGridView.Padding
  54. local itemSizeWithPadding = itemPadding + itemSize
  55. local width = loopGridView.ViewPortWidth - padding.left - padding.right + itemPadding.x
  56. local height = loopGridView.ViewPortHeight - padding.top
  57. local row = Mathf.Floor(width / (itemSizeWithPadding.x))
  58. local column = Mathf.Ceil(height / (itemSizeWithPadding.y))
  59. local realWidth = row * itemSizeWithPadding.x
  60. local offset = width - realWidth
  61. if offset > 0 then
  62. offset = offset * 0.5
  63. local newPadding = RectOffset(offset + padding.left, offset + padding.right, padding.top, padding.bottom)
  64. loopGridView:SetPadding(newPadding)
  65. end
  66. loopGridView:SetGridFixedGroupCount(SuperScrollView.GridFixedType.ColumnCountFixed, row)
  67. self.controller:SetGridRowColumn(row, column)
  68. --if self.startCB then
  69. -- self.startCB(self.root)
  70. --end
  71. end
  72. function UIArtifactStarUpView:Refresh()
  73. self:RefreshTop()
  74. self:RefreshJobInfo()
  75. self:RefreshStarInfo()
  76. end
  77. function UIArtifactStarUpView:RefreshTop()
  78. local skillEquipData = self.controller:GetSkillEquipData()
  79. local cfgId = skillEquipData.cfgId
  80. local cfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(cfgId)
  81. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  82. IconItemCtr:SetData(self, self.skillEquipSlot.iconItem, skillEquipData, Enum.ItemIEnterType.HeroSq)
  83. self.skillEquipSlot.iconItem:SetActive(true)
  84. self.textName.text.text = I18N.T(cfgData.Name)
  85. end
  86. function UIArtifactStarUpView:RefreshJobInfo()
  87. local heroId = self.controller:GetHeroId()
  88. local heroCfgId = self.controller:GetHeroCfgId()
  89. local nickname = self.controller:GetHeroNickname()
  90. local jobIcon
  91. if heroId == 1 then
  92. local jobData = ManagerContainer.CfgMgr:GetJobDataById(heroCfgId)
  93. jobIcon = jobData.JobIcon
  94. else
  95. local heroCfgData = ManagerContainer.CfgMgr:GetPartnerDataById(heroCfgId)
  96. jobIcon = heroCfgData.JobIcon
  97. end
  98. CommonUtil.LoadIcon(self, jobIcon, function (sprite)
  99. self.jobIcon.image.sprite = sprite
  100. end)
  101. local name
  102. if heroId == 1 then
  103. local cfgData = ManagerContainer.CfgMgr:GetJobDataById(heroCfgId)
  104. if nickname == nil then
  105. name = CommonUtil.GetHeroJobAndNameByUid(heroId, heroCfgId)
  106. else
  107. if cfgData == nil then
  108. name = nickname
  109. else
  110. name = I18N.T(cfgData.JobName) .. nickname
  111. end
  112. end
  113. else
  114. name = CommonUtil.GetHeroJobAndNameByUid(heroId, heroCfgId)
  115. end
  116. self.heroName.text.text = name
  117. end
  118. local function IsTheJob(heroId, skillEquipCfgData)
  119. local jobData = CommonUtil.GetHeroJobCfgDataByUid(heroId)
  120. return jobData.JobType == skillEquipCfgData.JobType and jobData.JobBranch == skillEquipCfgData.JobBranch and jobData.JobStage == skillEquipCfgData.JobStage
  121. end
  122. local resLackState
  123. function UIArtifactStarUpView:RefreshStarInfo()
  124. resLackState = nil
  125. local heroId = self.controller:GetHeroId()
  126. local skillEquipData = self.controller:GetSkillEquipData()
  127. local curStarLv = skillEquipData.starLv
  128. local nextStartLv = curStarLv + 1
  129. local limit = skillEquipData.maxStarLv
  130. local state = nextStartLv <= limit
  131. self.starGrp2:SetActive(state)
  132. self.costDsc.uILocalizeScript:SetContentAndValues("ArtifactStartips", {nextStartLv})
  133. self.costDsc:SetActive(state)
  134. for i = 1, Constant.SkillEquipMaxStarLimit do
  135. local item = self.starGrp1["star"..i]
  136. item:SetActive(false)
  137. local item = self.starGrp2["star"..i]
  138. item:SetActive(false)
  139. end
  140. for i = 1, limit do
  141. local item = self.starGrp1["star"..i]
  142. item:SetActive(true)
  143. if item then
  144. item.star:SetActive(i <= curStarLv)
  145. end
  146. end
  147. if state then
  148. for i = 1, limit do
  149. local item = self.starGrp2["star"..i]
  150. item:SetActive(true)
  151. if item then
  152. item.star:SetActive(i <= nextStartLv)
  153. end
  154. end
  155. end
  156. local cfgData = ManagerContainer.CfgMgr:GetArtifactCfgDataByCfgId(skillEquipData.cfgId)
  157. local content = string.format(Constant.GreenColorText,I18N.T(limit and cfgData.FuncDesc[nextStartLv] or cfgData.FuncDesc[curStarLv]))
  158. if not IsTheJob(heroId, cfgData) then
  159. content = content..I18N.SetLanguageValue("ArtifactEmployTips", I18N.T(cfgData.JobName))
  160. end
  161. self.upDsc.text.text = content
  162. self.btnRefine:SetActive(state)
  163. if state then
  164. local condition = cfgData.Condition[nextStartLv]
  165. local key = condition[2][1]
  166. local num = condition[2][2]
  167. local ownNum = CommonUtil.GetOwnResCountByItemId(key)
  168. if ownNum < num then
  169. resLackState = {key, true}
  170. self.number.text.text = string.format(Constant.PinkColorText,num)
  171. else
  172. resLackState = {key, false}
  173. self.number.text.text = num
  174. end
  175. end
  176. self.scrollView:SetActive(state)
  177. end
  178. function UIArtifactStarUpView:RefreshCostGrid(resetPos)
  179. self.controller:RefreshShowDatas()
  180. local loopGridView = self.scrollView.loopGridView
  181. local length = self.controller:GetShowDataLength()
  182. if resetPos then
  183. loopGridView:RefreshListByIndex(length, 0)
  184. else
  185. loopGridView:RefreshListByIndex(length)
  186. end
  187. end
  188. function UIArtifactStarUpView:GetItemByRowColumn(gridView, itemIndex, row, column)
  189. local length = self.controller:GetShowDataLength()
  190. if (itemIndex < 0 or itemIndex >= length) then
  191. return nil
  192. end
  193. local showData = self.controller:GetShowData(itemIndex)
  194. local item = nil
  195. if showData then
  196. item = gridView:NewListViewItem("IconItem")
  197. item.gameObject.name = itemIndex
  198. local itemlua = CommonUtil.BindGridViewItem2Lua(self, "IconItem", item.gameObject)
  199. CommonUtil.UpdateItemPrefab(self, itemlua, showData, Enum.ItemIEnterType.Bag, self, self.OnItemClick, itemIndex)
  200. else
  201. item = gridView:NewListViewItem('IconEmptyItem')
  202. end
  203. return item
  204. end
  205. function UIArtifactStarUpView:OnItemClick(button, params)
  206. local data = params[0]
  207. local idx = params[2]
  208. local oldIdx = self.controller:SelectSkillEquip(data)
  209. if oldIdx then
  210. local itemlua = self:GetShowItemByIdx(oldIdx - 1)
  211. if itemlua then
  212. itemlua.selected:SetActive(false)
  213. end
  214. end
  215. local itemlua = self:GetShowItemByIdx(idx)
  216. if itemlua then
  217. itemlua.selected:SetActive(data.selected == 1)
  218. end
  219. end
  220. function UIArtifactStarUpView:GetShowItemByIdx(idx)
  221. local item = self.scrollView.loopGridView:GetShownItemByItemIndex(idx)
  222. if item then
  223. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self, "IconItem", item.gameObject)
  224. return itemlua
  225. end
  226. end
  227. function UIArtifactStarUpView:RemoveEventListener()
  228. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  229. end
  230. function UIArtifactStarUpView:OnCloseClick()
  231. self:UIClose()
  232. end
  233. function UIArtifactStarUpView:OnStarUpClick()
  234. local selectedCount = self.controller:GetSelectedCostCount()
  235. if selectedCount == 0 then
  236. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ArtifactSmeltButtonTips4")
  237. return
  238. end
  239. local enough = self.controller:IsCostSkillEuipEnough()
  240. if not enough then
  241. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("TitleArtifactStarUpTips")
  242. return
  243. end
  244. if resLackState and resLackState[2] then
  245. CommonUtil.ItemNotEnoughHandle(resLackState[1])
  246. return
  247. end
  248. self.controller:SendStarUpReq()
  249. end
  250. function UIArtifactStarUpView:AddUIEventListener()
  251. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
  252. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnCloseClick)
  253. self.uiBase:AddButtonEventListener(self.btnRefine.button, self, self.OnStarUpClick)
  254. end
  255. function UIArtifactStarUpView:OnHide()
  256. end
  257. function UIArtifactStarUpView:OnShow(data)
  258. self.controller:SetData(data)
  259. end
  260. function UIArtifactStarUpView:OnClose()
  261. self.scrollView.loopGridView:Dispose()
  262. end
  263. function UIArtifactStarUpView:OnDispose()
  264. self.controller:OnDispose()
  265. end
  266. return UIArtifactStarUpView