--[[ 神兽主界面 ]]-- local UIGodBeastEquip = UIViewClass() local showListArr = {} local BEAST_FORMATION_BG_IMG = ConstAssetPathConfig.BEAST_FORMATION_BG_IMG function UIGodBeastEquip:OnCreated() self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.model_Show) end function UIGodBeastEquip:OnOpened(context) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Godbeast) self:RegistSystemEvent(EventID.UI_GodBeast_FormationRefresh, self.RefreshPanel) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.GodBeast, self.OnRefreshBtnRp) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Formation_GodBeast, self.OnRefreshBtnRp) UIManager.ActiveUIModle(false, "UIGodBeastEquip") self.memberCells = {} self.slotToIds = { 0, 0, 0 } self.isEditorState = false UTL.UIRender.Create2DTextureBgScene(self.modelComponentDataHandle, BEAST_FORMATION_BG_IMG, nil, nil) CTL.GodBeast.SetFormationResolutionFov(self.modelComponentDataHandle) MDL.GodBeast.QueryGodBeastLineUp() self:OnRefreshBtnRp() end function UIGodBeastEquip:OnClosed() UIManager.ActiveUIModle(true, "UIGodBeastEquip") UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end function UIGodBeastEquip:OnRefreshBtnRp() self.btn_Develop:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.GodBeast)) self.btn_Paradise:SetRedPoint(MDL.GodBeast.IsParadiseHasDropItem()) end function UIGodBeastEquip:RefreshPanel(isSave, serverSlotList, showGSList) UIUtils.SetActive(self.group_TotalPower.gameObject, true) UIUtils.SetActive(self.group_Equip.gameObject, true) -- 总战力 if isSave then self.slotInfo = MDL.GodBeast.GetGodBeastSlotInfo() local total = 0 for i, v in ipairs(self.slotInfo) do self.slotToIds[i] = v.godBeastId or 0 if self.slotToIds[i] > 0 then total = total + v.showGS end end UIUtils.SetLabel(self.txt_PowerNumber, total) self:ExitEditor() else for i, v in ipairs(serverSlotList) do self.slotToIds[i] = v end local total = 0 for i, v in ipairs(showGSList) do total = total + v end UIUtils.SetLabel(self.txt_PowerNumber, total) end -- 刷新上阵位ID self:InitSlots() end function UIGodBeastEquip:RefreshBeastList() table.clearArray(showListArr) for i, v in ipairs(MDL.GodBeast.GetSortedList()) do local beastInfo = MDL.GodBeast.GetGodBeastInfoByID(v.ID) if beastInfo then table.insert(showListArr, v) end end self.loop_GodBeastEquip:ReloadAll(showListArr) end function UIGodBeastEquip:UpdateTotalGS(isSave) local total = 0 for i, v in ipairs(self.slotInfo) do total = total + v.showGS end UIUtils.SetLabel(self.txt_PowerNumber, total) end function UIGodBeastEquip:InitSlots() --先清空所有再创建 UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) UTL.UIRender.DisposeExtraEmptyObj(self.modelComponentDataHandle) for index, collection in ipairs(self.group_Equip) do local data = DataSheetManager.GodBeastEquip:GetDataByID(index) if not MDL.Unlock.IsTriggerIdComplete(data.TriggerID) then collection.state_Slot:SetState(0) local triggerData = DataSheetManager.TriggerID:GetDataByID(data.TriggerID) UIUtils.SetLabel(collection.txt_UNlockTip, MDL.Unlock.GetDesByTriggerID(triggerData.Unlock_Table[1], false)) else local beastID = self.slotToIds[index] local slotInfo = self.slotInfo[index] if beastID > 0 then collection.state_Slot:SetState(1) -- 神兽技能 CTL.GodBeast.SetSkillInfo(collection.img_GodBeastSkill, nil, nil, beastID) -- 修为年限 UIUtils.SetLabel(collection.txt_GodBeastAge, CTL.GodBeast.GetLevelUpYearText(slotInfo.raiseLevel)) -- 突破等级 CTL.GodBeast.SetStarLevelText(collection.txt_GodBeastBreak, MDL.GodBeast.GetGodBeastStarLevel(beastID)) -- 神兽名 CTL.GodBeast.SetGodBeastName(collection.txt_GodBeastName, beastID) -- 加载模型 UTL.UIRender.LoadGodBeastFormationModel(self.modelComponentDataHandle, beastID, CTL.GodBeast.GetFormationModelParam(beastID, index)) else collection.state_Slot:SetState(2) end end end end function UIGodBeastEquip:EnterEditor() self.isEditorState = true self.state_Equip:SetState(1) self:InitDropEvent() self:RefreshBeastList() self:InitSlots() end function UIGodBeastEquip:ExitEditor() self.isEditorState = false self.draggingIndex = nil self.state_Equip:SetState(0) UIUtils.SetActive(self.btn_BattleOrder.gameObject, MDL.GodBeast.IsSlotHasGodBeast()) for i, v in ipairs(self.group_Equip) do self:UnregistTriggerEvent(v.img_Drop) end end function UIGodBeastEquip:IsBeastInSlot(id) for i, v in ipairs(self.slotToIds) do if v == id then return true end end return false end function UIGodBeastEquip:InitDropEvent() self.dropSlots = {} for i, v in ipairs(self.group_Equip) do self:UnregistTriggerEvent(v.img_Drop, UIEventTriggerType.PointerClick) self:RegistTriggerEvent(v.img_Drop, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(v.img_Drop, UIEventTriggerType.Drag) self:RegistTriggerEvent(v.img_Drop, UIEventTriggerType.EndDrag) table.insert(self.dropSlots, v.img_Drop.gameObject) end for i, v in ipairs(self.group_Equip) do self:RegistDropEvent(v.img_Drop, self.dropSlots) end end function UIGodBeastEquip:GetSlotByDropComp(comp) for i, v in ipairs(self.group_Equip) do if comp.gameObject == v.img_Drop.gameObject then return true, i, v end end end -- 更新模型显示 -- self.modelShowList = {beastID = 0, modelPath = ""} function UIGodBeastEquip:UpdateModelShow() -- 每次更新清除三个模型 for i, info in ipairs(self.modelShowList) do if not string.isNilOrEmpty(info.modelPath) then self.model_Show:DisposeModelObject(info.modelPath) end end -- 修改模型展示数据 for i, beastID in ipairs(self.slotToIds) do if beastID > 0 then local godBeastModelID = DataSheetManager.GodBeastData:GetDataByID(beastID).GodBeastModelID local godBeastModelData = DataSheetManager.MonsterModelData:GetDataByID(godBeastModelID) self.modelShowList[i].beastID = beastID self.modelShowList[i].modelPath = godBeastModelData.Path else self.modelShowList[i].beastID = 0 self.modelShowList[i].modelPath = nil end end -- 更新三个模型和场景 UTL.UIRender.CreateGodBeastFormationModel(self.modelComponentDataHandle, self.modelShowList) end function UIGodBeastEquip:SlotExchange(slotIndex) if not self.draggingIndex or self.slotToIds[self.draggingIndex] == 0 then return end self.slotToIds[self.draggingIndex], self.slotToIds[slotIndex] = self.slotToIds[slotIndex], self.slotToIds[self.draggingIndex] self:InitSlots() end function UIGodBeastEquip:SetBeastOnLine(index) -- 拖拽的cell已经在阵上 for idx, ID in ipairs(self.slotToIds) do if ID == self.curDragData.data.ID and index ~= idx then self.slotToIds[idx], self.slotToIds[index] = self.slotToIds[index], self.slotToIds[idx] self:InitSlots() return end end -- 当前拖拽的不再阵上,直接上阵 local oldCellIndex = 0 for i, v in ipairs(showListArr) do if v.ID == self.slotToIds[index] then oldCellIndex = i - 1 break end end self.slotToIds[index] = self.curDragData.data.ID self.loop_GodBeastEquip:UpdateIndex(self.curDragData.index - 1) self.loop_GodBeastEquip:UpdateIndex(oldCellIndex) self:InitSlots() end function UIGodBeastEquip:RecoverCellToScroll() if self.drag_Cell then self.drag_Cell.transform:SetParent(self.loop_GodBeastEquip.content, false) self.drag_Cell.transform:SetSiblingIndex(self.curDragData.siblingIndex) self.drag_Cell = nil end end -- 点击上阵 function UIGodBeastEquip:ClickToLine(data) for i, v in ipairs(self.slotToIds) do if data.ID == v then return end end for i = 1, 3 do if self.slotToIds[i] <= 0 then if not MDL.Unlock.IsTriggerIdComplete(DataSheetManager.GodBeastEquip:GetDataByID(i).TriggerID) then return end CTL.Sound.PlayGameSound("UI_sound_liaotian") self.slotToIds[i] = data.ID break end end MDL.GodBeast.UpdateGodBeastLineUpReq(self.slotToIds, false) self:RefreshBeastList() end --region--------------------------------- 系统函数 ----------------------------------------------------------- function UIGodBeastEquip:Cell_OnPointerClick(scrollRect, index, target, eventData) self:ClickToLine(self.memberCells[index + 1][2]) end function UIGodBeastEquip:Cell_OnPointerDown(scrollRect, index, target, eventData) self.curPointerDownTime = Time.realtimeSinceStartup end function UIGodBeastEquip:Cell_OnBeginDrag(scrollRect, index, target, eventData) if math.abs(eventData.delta.y) > 3 then local cell = self.memberCells[index + 1] if cell then CTL.Sound.PlayGameSound("UI_sound_liaotian") self.drag_Cell = cell[1].cell.gameObject self.curDragData = { index = index + 1, data = cell[2], siblingIndex = self.drag_Cell.transform:GetSiblingIndex() } self.drag_Cell.transform:SetParent(self.dragParent.transform, false) self.curPointerDownTime = nil else logging.error(LTAG.XuQian, "重大错误 拖拽对象 越界 ", index, #self.memberCells) end else self.curDragObj = self.loop_GodBeastEquip.gameObject UIUtils.ExecuteBeginDrag(self.curDragObj, eventData) end end function UIGodBeastEquip:Cell_OnEndDrag(scrollRect, index, comp, eventData) if self.curDragObj then UIUtils.ExecuteEndDrag(self.curDragObj, eventData) self.curDragObj = nil end end function UIGodBeastEquip:Cell_OnDrag(scrollRect, index, target, eventData) if self.curDragObj then UIUtils.ExecuteDrag(self.curDragObj, eventData) else UIUtils.ScreenPointToWorldPointInRectangle(self.drag_Cell, eventData) end end function UIGodBeastEquip:Cell_OnDrop(scrollRect, index, target, eventData) self:RecoverCellToScroll() end function UIGodBeastEquip:OnBeginDrag(comp, eventData) local isSlot, slotIndex, collection = self:GetSlotByDropComp(comp) if self.slotToIds[slotIndex] == 0 or not isSlot then return end if isSlot then self.draggingIndex = slotIndex local ok, data = DataSheetManager.GodBeastData:TryGetDataByID(self.slotToIds[slotIndex]) CTL.Sound.PlayGameSound("UI_sound_liaotian") if ok then UIUtils.SetActive(self.img_DragShow.gameObject, true) UIUtils.SetImageByAssetBundle(self.img_DragShow, data.GodBeastIcon) end end end function UIGodBeastEquip:OnDrag(comp, eventData) UIUtils.ScreenPointToWorldPointInRectangle(self.dragParent.gameObject, eventData) end function UIGodBeastEquip:OnEndDrag() UIUtils.SetActive(self.img_DragShow.gameObject, false) end function UIGodBeastEquip:OnDrop(comp, eventData) if comp ~= nil then local isSlot, slotIndex, collection = self:GetSlotByDropComp(comp) if isSlot then if self.drag_Cell then -- cell拖到位置 self:SetBeastOnLine(slotIndex) else -- 上阵位拖到位置 self:SlotExchange(slotIndex) end self:RecoverCellToScroll() end MDL.GodBeast.UpdateGodBeastLineUpReq(self.slotToIds, false) self:RefreshBeastList() end end function UIGodBeastEquip:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIGodBeastEquip:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.btn_Set then self:EnterEditor() elseif comp == self.btn_Save then self:ExitEditor() MDL.GodBeast.UpdateGodBeastLineUpReq(self.slotToIds, true) elseif comp == self.btn_Develop then -- 养成主界面 UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGodBeastMainPanel) elseif comp == self.btn_Paradise then -- 进入神兽福地 UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGodBeastParadise) elseif comp == self.btn_BattleOrder then -- 出站顺序弹窗 UIManager.OpenView(Const_UI_Lua.UIEnum.UIGodBeastBattleOrder) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.GodBeast }) else for idx, v in ipairs(self.group_Equip) do if comp == v.img_Drop and self.slotToIds[idx] == 0 then if self.isEditorState == false then self:EnterEditor() return end end end end end function UIGodBeastEquip:OnCellInit(scrollRect, index, cellTable, data) self.memberCells[index + 1] = { cellTable, data } UIUtils.SetImageByAssetBundle(cellTable.img_GodBeastIcon, data.GodBeastIcon) UTL.Color.SetQualityImageByType(cellTable.img_QualityBg, data.GodBeastQuality, UTL.Color.QualityType.Square) -- 名字 UIUtils.SetLabelText(cellTable.txt_GodBeastName, Const_IDS[data.GodBeastName]) -- 上阵标 UIUtils.SetActive(cellTable.sprite_BgZhen, self:IsBeastInSlot(data.ID)) -- 突破 CTL.GodBeast.SetStarLevelText(cellTable.txt_GodBeastBreak, MDL.GodBeast.GetGodBeastStarLevel(data.ID)) if self.isEditorState then self.loop_GodBeastEquip:RegistTriggerEvent(cellTable.img_GodBeastIcon, UIEventTriggerType.BeginDrag, index) self.loop_GodBeastEquip:RegistTriggerEvent(cellTable.img_GodBeastIcon, UIEventTriggerType.Drag, index) self.loop_GodBeastEquip:RegistTriggerEvent(cellTable.img_GodBeastIcon, UIEventTriggerType.EndDrag, index) self.loop_GodBeastEquip:RegistTriggerEvent(cellTable.img_GodBeastIcon, UIEventTriggerType.PointerClick, index) self.loop_GodBeastEquip:RegistTriggerEvent(cellTable.img_GodBeastIcon, UIEventTriggerType.PointerDown, index) self:RegistDropEvent(cellTable.img_GodBeastIcon, self.dropSlots) end end --endregion return UIGodBeastEquip