local UIEquipmentRefineSetting = UIViewClass() function UIEquipmentRefineSetting:OnOpened(context) self:RegistSystemEvent(EventID.UI_RefreshEquipRefinePriority, self.RefreshPriority) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS["IDS_EquipRefine_Set1"]) self.prioritySetting = nil self:InitDatasAndEvents() MDL.Equipment.EquipGetRefinePriorityReq() end function UIEquipmentRefineSetting:RefreshPriority(priorityData) if priorityData then self.prioritySetting = priorityData end for equipType, attArr in ipairs(self.group_Arrays) do for i, collection in ipairs(attArr) do local attrConfig = DataSheetManager.AttrData:GetDataByID(self.prioritySetting[equipType][i]) UTL.Attr.SetAttrIconByAttrIcon(collection.ico, attrConfig.Icon) UIUtils.SetLabelText(collection.txt, Const_IDS[attrConfig.Name]) end end end function UIEquipmentRefineSetting:OnClosed() MDL.Equipment.EquipSetRefinePriorityReq() end function UIEquipmentRefineSetting:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end --region 拖拽相关 function UIEquipmentRefineSetting:InitDatasAndEvents() --六个大槽位的拖拽检测组 self.dropGroup = {} --注册拖拽事件 for slotIndex, collection in ipairs(self.group_Arrays) do for subIndex, subCollection in ipairs(collection) do self:RegistAllEvent(subCollection.bg_Attr) table.insert(self.dropGroup, subCollection.bg_Attr.gameObject) end end --注册释放事件 for slotIndex, collection in ipairs(self.group_Arrays) do for subIndex, subCollection in ipairs(collection) do self:RegistDropEvent(subCollection.bg_Attr, self.dropGroup) end end end function UIEquipmentRefineSetting:RegistAllEvent(comp) self:RegistTriggerEvent(comp, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(comp, UIEventTriggerType.Drag) self:RegistTriggerEvent(comp, UIEventTriggerType.EndDrag) end function UIEquipmentRefineSetting:OnBeginDrag(comp, eventData) -- 第一步,把拖拽父物体设置到点下的屏幕位置 UIUtils.ScreenPointToWorldPointInRectangle(self.drag_Parent.gameObject, eventData) -- 第二步,记录拖拽前的位置 self.draggingTrans = comp.transform.parent self.originParent = self.draggingTrans.parent self.originX, self.originY = comp.transform.parent:GetLocalPosition() -- 第三步,把响应拖拽的物体,移动节点到拖拽父物体下 self.draggingTrans:SetParent(self.drag_Parent.transform, true) end function UIEquipmentRefineSetting:OnDrag(comp, eventData) UIUtils.ScreenPointToWorldPointInRectangle(self.drag_Parent.gameObject, eventData) end function UIEquipmentRefineSetting:OnEndDrag(comp, eventData) --不作处理 end function UIEquipmentRefineSetting:OnDrop(comp, eventData) -- 第1步,计算交换后的数据 if comp and comp.transform ~= eventData.pointerDrag.transform then local originIndex, originSubIndex = self:GetDragGameObjectIndex(eventData.pointerDrag.transform.gameObject) local targetIndex, targetSubIndex = self:GetDragGameObjectIndex(comp.gameObject) if targetIndex ~= originIndex then -- 还原拖拽物体的位置 self.draggingTrans:SetParent(self.originParent, true) self.draggingTrans:SetLocalPosition(self.originX, self.originY, 0) return end local originData = self.prioritySetting[originIndex][originSubIndex] local targetData = self.prioritySetting[targetIndex][targetSubIndex] self.prioritySetting[targetIndex][targetSubIndex], self.prioritySetting[originIndex][originSubIndex] = originData, targetData end --第2步,刷新当前页签 self:RefreshPriority() --第3步,还原拖拽物体的位置 self.draggingTrans:SetParent(self.originParent, true) self.draggingTrans:SetLocalPosition(self.originX, self.originY, 0) end function UIEquipmentRefineSetting:GetDragGameObjectIndex(obj) for index, targetObj in ipairs(self.dropGroup) do if targetObj == obj then local mainIndex = math.ceil(index / 6) return mainIndex, index - (mainIndex - 1) * 6 end end return 0, 0 end --endregion return UIEquipmentRefineSetting