public void UpdateLoopReceiverOnly(Vector2 mousePos) { foreach (var element in shownElements) { if (element.isShown) { anyReceiverHovered = anyReceiverHovered || element.receiverHovered; if (mouseUp) { if (element.receiverHovered) { receiver = element; break; } } } } DrawDraggedGUIs(mousePos); if (mouseUp) { if (receiver != null) { onDropCallback(receiver, trackedRange); receiver = null; } dragging = false; Clear(); } }
void CheckClickedElement(out bool selectionChanged, SelectionElement clickedElement, KeyboardListener k, out int goToDirID) { goToDirID = -1; selectionChanged = false; //right arrow movies fwd directory when one selected if (clickedElement == null) { if (k[KeyCode.RightArrow]) { if (selectionHandler.singleTracked) { if (firstSelected.isDirectory) { clickedElement = firstSelected; } } } } //left arrow goes back directory if (clickedElement == null) { if (k[KeyCode.LeftArrow]) { if (backButton != null) { clickedElement = backButton; } } } if (clickedElement == null) { return; } if (clickedElement.isDirectory) { //if not already there if (clickedElement.elementID != currentShownDirectoryID) { goToDirID = clickedElement.elementID; } } else //element select { selectionHandler.OnObjectSelection(clickedElement, k.shift); selectionChanged = true; } }
public void UpdateLoop(Vector2 mousePos, Vector2Int selectedRange) { foreach (var element in shownElements) { if (element.isShown) { anyReceiverHovered = anyReceiverHovered || element.receiverHovered; if (mouseDown) { if (element.isDraggable && element.hasMousePos) { newlyDragged = element; break; } } else if (mouseUp) { if (element.receiverHovered) { receiver = element; break; } } } } DrawDraggedGUIs(mousePos); if (newlyDragged != null) { if (newlyDragged.isSelected) { SetTracked(selectedRange); } else { lo = hi = newlyDragged.showIndex; } newlyDragged = null; } if (mouseUp) { if (receiver != null) { onDropCallback(receiver, trackedRange); receiver = null; } dragging = false; Clear(); } }
bool CheckElementParentRecursive(int parentCheckID, SelectionElement element) { if (parentCheckID == 0 || element.parentID == parentCheckID) { return(true); } if (element.elementID == 0) { return(false); } return(CheckElementParentRecursive(parentCheckID, directoryTreeElements[element.parentID])); }
//on directory change only void RebuildBackButton() { if (currentShownDirectoryID != 0) { int parentDirectoryID = directoryTreeElements[currentShownDirectoryID].parentID; backButton = new SelectionElement(false, true, parentDirectoryID, backButtonGUI, -1); backButton.InitializeInternal(0, this); } else { backButton = null; } }
string GetFullPath(string ourName, int fromStateID) { if (fromStateID == 0) { return(ourName); } int parentID = directoryTreeElements[fromStateID].parentID; SelectionElement parentDirectory = directoryTreeElements[parentID]; string parentName = parentDirectory.gui.text; if (parentID != 0) { ourName = parentName + "/" + ourName; } return(GetFullPath(ourName, parentID)); }
HashSet <int> _GetIDsInTrackedList(Vector2Int trackedRange, bool includeDirs, string dirCheckTitle, string dirCheckMsg) { if (trackedRange.x == -1) { return(null); } HashSet <int> r = new HashSet <int>(); bool checkedDirs = false; for (int i = trackedRange.x; i <= trackedRange.y; i++) { SelectionElement element = mainElements[i]; if (element.isDirectory) { if (!includeDirs) { continue; } if (!checkedDirs) { if (!EditorUtility.DisplayDialog(dirCheckTitle, dirCheckMsg, "Ok", "Cancel")) { return(null); } checkedDirs = true; } getElementsInDirectory(element.elementID, r); } else { r.Add(element.elementID); } } return(r); }
void OnDropReceive(SelectionElement receiver, Vector2Int draggedRange) //, HashSet<SelectionElement> droppedElements) { { HashSet <SelectionElement> draggedElements = draggedRange.Generate(i => mainElements[i]).ToHashSet(); foreach (var element in draggedElements) { // check if we're dragging a directory if (element.isDirectory) { //check if the receiving directory is a child of the dragged directory // if so, return out, so we dont have cyclical references... bool receiverIsChildOfElement = ElementIsChildOf(receiver, element); if (receiverIsChildOfElement) { Debug.LogError("avoiding cyclical drag drop, " + receiver.gui.text + " is child of " + element.gui.text); return; } } } onDirDragDrop(receiver, draggedElements); droppedOnReceiver = true; }
public bool IsTracked(SelectionElement element) { return(IsTracked(element.showIndex)); }
public void OnGUI() { multiSetParameterIndex = -1; if (CloseIfError()) { Close(); return; } GUIUtils.StartBox(1); if (!selectionSystem.hasSelection) { GUIUtils.Label(noAOsGUI); } else { bool drawingSingle = selectionSystem.singleSelected; SelectionElement firstSelected = selectionSystem.firstSelected; EditorProp assetObjectProp = drawingSingle ? AOStateMachineEditor.GetAOatPoolID(currentState, firstSelected.refIndex) : multiEditAssetObjectProp; if (assetObjectProp == null) { GUIUtils.Label(noAOsGUI); } else { // GUIUtils.Label(drawingSingle ? new GUIContent("<b>" + firstSelected.path + "</b>") : selectEditGUI); GUIUtils.Label(drawingSingle ? new GUIContent("<b>" + firstSelected.gui.text + "</b>") : selectEditGUI); GUILayout.FlexibleSpace(); GUIUtils.BeginIndent(); DrawAOParameters(drawingSingle, assetObjectProp); GUIUtils.EndIndent(); GUILayout.FlexibleSpace(); bool setMessages = DrawMessaging(AOStateMachineEditor.messageBlocksField, sendMessagesGUI, assetObjectProp, drawingSingle); bool setConditions = DrawMessaging(AOStateMachineEditor.conditionsBlockField, conditionsGUI, assetObjectProp, drawingSingle); if (!drawingSingle) { if (multiSetParameterIndex != -1) { CopyParameters( selectionSystem.GetReferenceIndiciesInSelectionOrAllShown(false).Generate(i => AOStateMachineEditor.GetAOatPoolID(currentState, i)), multiEditAssetObjectProp, multiSetParameterIndex ); } if (setMessages || setConditions) { CopyTextBlock( selectionSystem.GetReferenceIndiciesInSelectionOrAllShown(false).Generate(i => AOStateMachineEditor.GetAOatPoolID(currentState, i)), multiEditAssetObjectProp, setMessages ? AOStateMachineEditor.messageBlocksField : AOStateMachineEditor.conditionsBlockField ); } } } } GUILayout.FlexibleSpace(); if (GUIUtils.Button(closeGUI, GUIStyles.button, Colors.blue, Colors.black)) { Close(); } GUIUtils.EndBox(1); stateMachineEditor.so.SaveObject(); }
string GetCurrentDisplayPathText() { SelectionElement current = directoryTreeElements[currentShownDirectoryID]; return(GetFullPath(current.gui.text, current.elementID)); }
bool ElementIsChildOf(SelectionElement a, SelectionElement parentCheck) { return(CheckElementParentRecursive(parentCheck.elementID, directoryTreeElements[a.elementID])); }
public void DrawElements(Action <KeyboardListener> checkHotkeys) { UpdateDirectoryTreeWindow(true); KeyboardListener keyboardListener = new KeyboardListener(); bool mouseUp; dragDropHandler.InputListen(out mouseUp); bool searchChanged; // int pageOffset, Vector2 mousePosition = UnityEngine.Event.current.mousePosition; DrawElementsView( mousePosition, mouseUp, // pagination.pagesGUI, out searchChanged//, // out pageOffset, ); dragDropHandler.UpdateLoop(mousePosition, selectionHandler.trackedRange); // bool paginationSuccess = pageOffset != 0 && pagination.SwitchPage(pageOffset); //check clicked element int goToDirID; bool selectionChanged; CheckClickedElement(out selectionChanged, clickedElement, keyboardListener, out goToDirID); bool movedFolder = (goToDirID != -1 && MoveFolder(goToDirID)); selectionChanged = selectionHandler.HandleDirectionalSelection(keyboardListener[KeyCode.UpArrow], keyboardListener[KeyCode.DownArrow], keyboardListener.shift, mainElements.Length - 1) || selectionChanged; shouldRebuild = droppedOnReceiver || movedFolder || searchChanged;//|| paginationSuccess; shouldResetPage = movedFolder; if (!shouldRebuild && selectionChanged) { onSelectionChange(); } checkHotkeys(keyboardListener); clickedElement = null; droppedOnReceiver = false; }
// need to evaluate while drawing // and afterwards as well (for multi window drag drop capability) public void ElementDragDropValues(SelectionElement element, Vector2 mousePos, bool mouseUp, out bool beingDragged, out bool receiverHovered, out bool dropReceived) { beingDragged = dragging && IsTracked(element); receiverHovered = element.isDirectory && element.hasMousePos && dragging && !beingDragged; dropReceived = receiverHovered && mouseUp; }
public void AddShownElements(SelectionElement newElements) { shownElements.Add(newElements); }