/// <summary> /// Called after we draw the last servo in a group /// </summary> /// <param name="groupID">What Group was it</param> internal static void EndDrawGroup(int groupID) { if (Disabled) { return; //If the Drag and Drop is Disabled then just go back } //Only do this if there is a group that contains Servos if (Groups.Count < 1 || Servos.Count < 1 || Servos.All(x => x.GroupID != groupID)) { return; } try { //Set the height of the group to contain all the servos var newRect = new Rect(Groups[groupID].GroupRect) { height = Servos.Last(x => x.GroupID == groupID).ServoRect.y + Servos.Last(x => x.GroupID == groupID).ServoRect.height - Groups[groupID].GroupRect.y }; Groups[groupID].GroupRect = newRect; } catch (Exception ex) // Intentional Pokemon { Logger.Log(ex.Message, Logger.Level.Fatal); } }
internal static void WindowEnd() { if (Disabled) { return; //If the Drag and Drop is Disabled then just go back } // Draw the Yellow insertion strip Rect insertRect; if (DraggingItem && ServoDragging != null && ServoOver != null) { //What is the insert position of the dragged servo int insertIndex = ServoOver.ID + (ServoOverUpper ? 0 : 1); if ((ServoDragging.GroupID != ServoOver.GroupID) || (ServoDragging.ID != insertIndex && (ServoDragging.ID + 1) != insertIndex)) { //Only in here if the drop will cause the list to change float rectResMoveY; //is it dropping in the list or at the end if (insertIndex < Servos.Where(x => x.GroupID == ServoOver.GroupID).ToList().Count) { rectResMoveY = Servos.Where(x => x.GroupID == ServoOver.GroupID).ToList()[insertIndex].ServoRect.y; } else { rectResMoveY = Servos.Where(x => x.GroupID == ServoOver.GroupID).ToList().Last().ServoRect.y + Servos.Where(x => x.GroupID == ServoOver.GroupID) .ToList() .Last() .ServoRect.height; } //calculate and draw the graphic insertRect = new Rect(12, rectResMoveY + 26 - ScrollPosition.y, WindowRect.width - 34, 9); GUI.Box(insertRect, "", StyleDragInsert); } } else if (DraggingItem && GroupDragging != null && GroupOver != null) { //What is the insert position of the dragged group int insertIndex = GroupOver.ID + (GroupOverUpper ? 0 : 1); if (GroupDragging.ID != insertIndex && (GroupDragging.ID + 1) != insertIndex) { //Only in here if the drop will cause the list to change float rectResMoveY; //is it dropping in the list or at the end if (insertIndex < Groups.Count) { rectResMoveY = Groups[insertIndex].GroupRect.y; } else { rectResMoveY = Groups.Last().GroupRect.y + Groups.Last().GroupRect.height; } //calculate and draw the graphic insertRect = new Rect(12, rectResMoveY + 26 - ScrollPosition.y, WindowRect.width - 34, 9); GUI.Box(insertRect, "", StyleDragInsert); } } else if (DraggingItem && ServoDragging != null && GroupOver != null && Servos.All(x => x.GroupID != GroupOver.ID)) { //This is the case for an empty Group //is it dropping in the list or at the end float rectResMoveY = GroupOver.GroupRect.y + GroupOver.GroupRect.height; //calculate and draw the graphic insertRect = new Rect(12, rectResMoveY + 26 - ScrollPosition.y, WindowRect.width - 34, 9); GUI.Box(insertRect, "", StyleDragInsert); } //What is the mouse over if (MousePosition.y > 32 && MousePosition.y < WindowRect.height - 8) { //inside the scrollview //check what group GroupOver = Groups.FirstOrDefault(x => x.GroupRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); GroupIconOver = Groups.FirstOrDefault(x => x.IconRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); if (GroupOver != null) { GroupOverUpper = ((MousePosition + ScrollPosition - new Vector2(8, 29)).y - GroupOver.GroupRect.y) < GroupOver.GroupRect.height / 2; } //or servo ServoOver = Servos.FirstOrDefault(x => x.ServoRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); ServoIconOver = Servos.FirstOrDefault(x => x.IconRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 29))); if (ServoOver != null) { ServoOverUpper = ((MousePosition + ScrollPosition - new Vector2(8, 29)).y - ServoOver.ServoRect.y) < ServoOver.ServoRect.height / 2; } } else { //Otherwise empty the variables GroupOver = null; ServoOver = null; GroupIconOver = null; ServoIconOver = null; } //MouseDown - left mouse button if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { if (GroupIconOver != null) { //If we click on the drag icon then start the drag GroupDragging = GroupOver; DraggingItem = true; } else if (ServoIconOver != null) { //If we click on the drag icon then start the drag ServoDragging = ServoOver; DraggingItem = true; } } //did we release the mouse if (Event.current.type == EventType.mouseUp && Event.current.button == 0) { if (GroupDragging != null && GroupOver != null) { //were we dragging a group if (GroupDragging.ID != (GroupOver.ID + (GroupOverUpper ? 0 : 1))) { //And it will cause a reorder Logger.Log(string.Format("Reordering:{0}-{1}", GroupDragging.ID, (GroupOver.ID - (GroupOverUpper ? 1 : 0)))); //where are we inserting the dragged item int insertAt = (GroupOver.ID - (GroupOverUpper ? 1 : 0)); if (GroupOver.ID < GroupDragging.ID) { insertAt += 1; } //move em around ServoController.ControlGroup g = ServoController.Instance.ServoGroups[GroupDragging.ID]; ServoController.Instance.ServoGroups.RemoveAt(GroupDragging.ID); ServoController.Instance.ServoGroups.Insert(insertAt, g); } } else if (ServoDragging != null && ServoOver != null) { //were we dragging a servo //where are we inserting the dragged item int insertAt = (ServoOver.ID + (ServoOverUpper ? 0 : 1)); if (ServoOver.GroupID == ServoDragging.GroupID && ServoDragging.ID < ServoOver.ID) { insertAt -= 1; } Logger.Log(string.Format("Reordering:({0}-{1})->({2}-{3})", ServoDragging.GroupID, ServoDragging.ID, ServoOver.GroupID, insertAt)); //move em around IServo s = ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos[ServoDragging.ID]; ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos.RemoveAt(ServoDragging.ID); ServoController.Instance.ServoGroups[ServoOver.GroupID].Servos.Insert(insertAt, s); } else if (ServoDragging != null && GroupOver != null && Servos.All(x => x.GroupID != GroupOver.ID)) { //dragging a servo to an empty group const int INSERT_AT = 0; IServo s = ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos[ServoDragging.ID]; ServoController.Instance.ServoGroups[ServoDragging.GroupID].Servos.RemoveAt(ServoDragging.ID); ServoController.Instance.ServoGroups[GroupOver.ID].Servos.Insert(INSERT_AT, s); } //reset the dragging stuff DraggingItem = false; GroupDragging = null; ServoDragging = null; } //If we are dragging and in the bottom or top area then scrtoll the list if (DraggingItem && RectScrollBottom.Contains(MousePosition)) { ControlsGUI.SetEditorScrollYPosition(ScrollPosition.y + (Time.deltaTime * 40)); } if (DraggingItem && RectScrollTop.Contains(MousePosition)) { ControlsGUI.SetEditorScrollYPosition(ScrollPosition.y - (Time.deltaTime * 40)); } }