local UIGodBeastBattleOrder = UIViewClass() function UIGodBeastBattleOrder:OnOpened(context) UIUtils.SetActive(self.dragParent.gameObject, false) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_BeastRecast_NewHint1) self:RefreshGodBeastInfo() self:RefreshBeastList() self:RegistDragEvent() end function UIGodBeastBattleOrder:RefreshGodBeastInfo() self.godBeastBattleOrderList = MDL.GodBeast.GetGodBeastBattleOrderList() self.slotToIds = {} for i, v in ipairs(self.godBeastBattleOrderList) do self.slotToIds[i] = v.info end self.state_GodBeast:SetState(#self.slotToIds - 1) end function UIGodBeastBattleOrder:RefreshBeastList() for i, v in ipairs(self.slotToIds) do UIUtils.SetLabel(self.group_GodBeast[i].txt_Num, i) local godBeastIcon = DataSheetManager.GodBeastData:GetDataByID(v.godBeastId).GodBeastIcon UIUtils.SetImageByAssetBundle(self.group_GodBeast[i].icon_Head, godBeastIcon) end end function UIGodBeastBattleOrder:RegistDragEvent() self.dropSlots = {} for i, v in ipairs(self.group_GodBeast) do self:RegistTriggerEvent(v.group, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(v.group, UIEventTriggerType.Drag) self:RegistTriggerEvent(v.group, UIEventTriggerType.EndDrag) table.insert(self.dropSlots, v.group.gameObject) end for i, v in ipairs(self.group_GodBeast) do self:RegistDropEvent(v.group, self.dropSlots) end end function UIGodBeastBattleOrder:GetSlotByDropComp(comp) for i, v in ipairs(self.group_GodBeast) do if comp.gameObject == v.group.gameObject then return i end end return 0 end function UIGodBeastBattleOrder:OnBeginDrag(comp, eventData) local slotIndex = self:GetSlotByDropComp(comp) if slotIndex == 0 then return end self.draggingIndex = slotIndex UIUtils.SetActive(self.dragParent.gameObject, true) local data = DataSheetManager.GodBeastData:GetDataByID(self.slotToIds[slotIndex].godBeastId) UIUtils.SetImageByAssetBundle(self.img_DragShow, data.GodBeastIcon) end function UIGodBeastBattleOrder:OnDrag(comp, eventData) UIUtils.ScreenPointToWorldPointInRectangle(self.dragParent.gameObject, eventData) end function UIGodBeastBattleOrder:OnEndDrag() UIUtils.SetActive(self.dragParent.gameObject, false) end function UIGodBeastBattleOrder:OnDrop(comp, eventData) if comp ~= nil then local slotIndex = self:GetSlotByDropComp(comp) if slotIndex ~= 0 then -- 上阵位拖到位置 self:SlotExchange(slotIndex) end end end function UIGodBeastBattleOrder:SlotExchange(slotIndex) self.slotToIds[self.draggingIndex], self.slotToIds[slotIndex] = self.slotToIds[slotIndex], self.slotToIds[self.draggingIndex] self:RefreshBeastList() CTL.Tips.AddTipsMsg(Const_IDS.IDS_BeastRecast_NewHint3) end function UIGodBeastBattleOrder:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() local slotList = {} for i, v in ipairs(self.slotToIds) do table.insert(slotList, v.slotId) end MDL.GodBeast.GodBeastSetBattleOrderReq(slotList) end end return UIGodBeastBattleOrder