| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- local UIPetMatsView = require("UIPet/UIPetMatsView_Generate")
- local PetMatsGridView = require("UIPet/PetMatsGridView")
- local petMatsGridView
- function UIPetMatsView:OnAwake(data)
- self.controller = require("UIPet/UIPetMatsCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
- end
- function UIPetMatsView:AddEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_PAGE_IN_END_NTF, self, self.OnUIPageInEndNtf)
- end
- function UIPetMatsView:FillContent(data, uiBase)
- self.uiBase = uiBase
- local gameObject = self.uiBase:GetRoot()
- if gameObject ~= nil then
- self.gameObject = gameObject
- self.transform = gameObject.transform
- end
- self:InitGenerate(self.transform, data)
- self:Init()
- end
- function UIPetMatsView:Init()
- local fromUIId = self.controller:GetFromUIId()
- if fromUIId == Enum.UIPageName.UIPetLvUp then
- self.textTitle.uILocalizeScript:SetContent("TitleChooseMet")
- self.mats.text.uILocalizeScript:SetContent("DscChooseSillUpMet")
- elseif fromUIId == Enum.UIPageName.UIPetRelations then
- self.textTitle.uILocalizeScript:SetContent("TitlePetRelations")
- self.mats.text.uILocalizeScript:SetContent("DscPetChooseSupport")
- elseif fromUIId == Enum.UIPageName.UIPetMySupport then
- self.textTitle.uILocalizeScript:SetContent("TitleChooseSupport")
- self.mats.text.uILocalizeScript:SetContent("DscChooseSupport")
- end
- end
- function UIPetMatsView:OnUIPageInEndNtf()
- if not petMatsGridView then
- petMatsGridView = PetMatsGridView:new()
- petMatsGridView:Init(self.controller:GetEnterType(), self, self.mats.loopGridView)
- end
- self:Refresh()
- end
- function UIPetMatsView:Refresh(resetPos)
- if petMatsGridView then
- petMatsGridView:Refresh(resetPos)
- end
- local selectedData, idx = self.controller:GetCurSelectedIdx()
- if selectedData then
- self.lastSelectedData = selectedData
- self.lastSelectedItemlua = petMatsGridView:GetShowItemByIdx(idx)
- end
- end
- function UIPetMatsView:OnItemClick(button, params)
- local data = params[0]
- local fromUIId = self.controller:GetFromUIId()
- if fromUIId == Enum.UIPageName.UIPetLvUp then
- if data.isBattle then
- return
- end
- elseif fromUIId == Enum.UIPageName.UIPetRelations then
- if not data.canUse then
- return
- end
- elseif fromUIId == Enum.UIPageName.UIPetMySupport then
- if data.isUsed then
- return
- end
- end
- self.selectedIdx = data.idx
- self.curSelectedData = data
- if not self.lastSelectedData or self.lastSelectedData ~= self.curSelectedData then
- if data and data.isRelevant and fromUIId == Enum.UIPageName.UIPetLvUp then
- local data = {"PetCostNotify8", nil, nil, self, self.PetClickSure}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
- return
- end
- if data and (data.level > 1 or self.controller:WasSkillUp(data)) and self.controller:GetEnterType() == Enum.ItemIEnterType.PetMats then
- local data = {"PetCostNotify4", nil, nil, self, self.PetClickSure}
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
- return
- end
- end
- self:PetClickSure()
- end
- function UIPetMatsView:PetClickSure()
- if self.selectedIdx then
- local sameItem = false
- if self.curSelectedData and self.lastSelectedData and self.curSelectedData.idx == self.lastSelectedData.idx then
- sameItem = true
- self.controller:SetSelectedData(nil)
- self.curSelectedData.selected = 0
- else
- self.controller:SetSelectedData(self.selectedIdx)
- self.curSelectedData.selected = 1
- if self.lastSelectedData then
- self.lastSelectedData.selected = 0
- if petMatsGridView then
- local luaitem = petMatsGridView:GetShowItemByIdx(self.lastSelectedData.idx)
- if luaitem then
- luaitem.selected:SetActive(false)
- end
- end
- end
- end
- if petMatsGridView then
- local luaitem = petMatsGridView:GetShowItemByIdx(self.selectedIdx)
- if luaitem then
- luaitem.selected:SetActive(self.curSelectedData.selected > 0)
- end
- end
- self.lastSelectedData = (sameItem and {nil} or {self.curSelectedData})[1]
- self.selectedIdx = nil
- end
- end
- function UIPetMatsView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- end
- function UIPetMatsView:AddUIEventListener()
- self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
- self.uiBase:AddButtonEventListener(self.btnCancel.button, self, self.OnCancelClick)
- self.uiBase:AddButtonEventListener(self.btnSure.button, self, self.OnSureClick)
- end
- function UIPetMatsView:OnCloseClick()
- self:UIClose()
- end
- function UIPetMatsView:OnCancelClick()
- self.controller:SetSelectedData(nil)
- self:OnCloseClick()
- end
- function UIPetMatsView:OnSureClick()
- self:OnCloseClick()
- local fromUIId = self.controller:GetFromUIId()
- if fromUIId == Enum.UIPageName.UIPetLvUp then
- local id = self.controller:GetCurSelectedIdByIdx()
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_SKILLUP_REFRESH_NTF, id)
- elseif fromUIId == Enum.UIPageName.UIPetRelations then
- local relationCfgId = self.controller:GetRelationCfgId()
- local data = self.controller:GetCurSelectedDataByIdx()
- if not relationCfgId or not data then
- return
- end
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_RELATION_CHANGE_NTF, {relationCfgId = relationCfgId, petData = data})
- elseif fromUIId == Enum.UIPageName.UIPetMySupport then
- local id = self.controller:GetCurSelectedIdByIdx()
- local idx = self.controller:GetSupportIdx()
- if not id or not idx then
- return
- end
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.PET_MY_SUPPORT_CHANGE_NTF, {id, idx})
- end
- end
- function UIPetMatsView:OnHide()
- if petMatsGridView then
- petMatsGridView:OnHide()
- end
- end
- function UIPetMatsView:OnShow(data)
- self.controller:SetData(data)
- end
- function UIPetMatsView:OnClose()
- end
- function UIPetMatsView:OnDispose()
- if petMatsGridView then
- petMatsGridView:OnDispose()
- petMatsGridView = nil
- end
- self.lastSelectedItemlua = nil
- self.lastSelectedData = nil
- self.selectedIdx = nil
- self.curSelectedData = nil
- self.curSelectedItemlua = nil
- self.controller:OnDispose()
- end
- return UIPetMatsView
|