protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) this.dragStartPoint = null; if (this.dragStartPoint.HasValue) { // XamlWriter.Save() has limitations in exactly what is serialized, // see SDK documentation; short term solution only; //string xamlString = XamlWriter.Save(this.Content); DragObject dataObject = new DragObject(); dataObject.BusinessObject = this.DataContext; //StackPanel panel = VisualTreeHelper.GetParent(this) as StackPanel; //if (panel != null) //{ // // desired size for DesignerCanvas is the stretched Toolbox item size // double scale = 1.3; // dataObject.DesiredSize = new Size(50 * scale, 50 * scale); //} DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); e.Handled = true; } }
//Drag the object public void OnMouseDown() { if (locked) { return; } //this is for when the object's parent should be dragged instead targetScript = target.GetComponent <DragObject>(); targetScript.dragged = true; //if it's draggable if (draggable) { target = this.gameObject; } //if not, if it has a draggable parent else if (gameObject.transform.parent != null && gameObject.transform.parent.gameObject.GetComponent <DragObject>() != null && !draggable) { target = gameObject.transform.parent.gameObject; } //so if it's not and neither is the parent else { } //keep track of snapped object if (targetScript.snappedObject != null) { SnapTo snappedTo = targetScript.snappedObject.GetComponent <SnapTo>(); snappedTo.holdingObject = false; snappedObject = null; } screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position); offset = target.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); }
//Called by a BaseInputModule when a drag is ended. public virtual void OnEndDrag(PointerEventData eventData) { RaycastHit hit; if (!UnityTools.IsPointerOverUI() && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { if (Container.CanDropItems) { DropItem(); } else if (Container.UseReferences && Container.CanDragOut) { Container.RemoveItem(Index); } } dragObject = null; if (this.m_ParentScrollRect != null) { this.m_ParentScrollRect.OnEndDrag(eventData); } //Repaint the slot Repaint(); }
private static void Fe_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { Point?dragStartPoint = GetDragStartPoint((DependencyObject)sender); if (e.LeftButton != MouseButtonState.Pressed) { dragStartPoint = null; } if (dragStartPoint.HasValue) { DragObject dataObject = new DragObject(); if (((FrameworkElement)sender).DataContext is ToolBoxData d) { dataObject.ObjectInstance = (object)d.CreateShapeCommand; DragDrop.DoDragDrop((DependencyObject)sender, dataObject, DragDropEffects.Copy); e.Handled = true; } } }
private static Boolean ProcessRightMouseButton(ABBGHUD __instance, DragObject dragObject) { if (!Configuration.Bombagan.RightClickToDiscardCard) { return(HarmonyPrefixResult.CallOriginal); } var main = __instance.Main; if (main.Board.Mode == ABBG.ABBG.Mode.Tutorial) { return(HarmonyPrefixResult.CallOriginal); } Selection selectedCards = main.Board.SelectedCards; // Discard cards mode if (selectedCards.IsMultiselectMode()) { return(HarmonyPrefixResult.CallOriginal); } if (main.Board.GetAblilityToDrawCards() != Board.PlayerType.Hero) { return(HarmonyPrefixResult.CallOriginal); } if (dragObject is CardHUD card) { main.AddCommand(new DrawCardsModeCommand(Board.LocationType.PlayerHand)); main.Board.SelectedCards.Toggle(card.Item); main.AddCommand(new DrawCardsCommand()); } return(HarmonyPrefixResult.SkipOriginal); }
private void radScheduler1_DragEnter(object sender, DragEventArgs e) { DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; e.Effect = dragObject == null ? DragDropEffects.None : DragDropEffects.Copy; }
private void DrawSplitIndicator(Point newPoint) { if (DrawMoveIndicator) { if (newPoint == _nullPoint) { DragObject.Hide(); } else { if (_movementPoint == _nullPoint) { // If there is nothing old to remove... if (newPoint != _nullPoint) { DragObject.Show(Target, SplitRectangleFromPoint(newPoint)); } } else { DragObject.Show(Target, SplitRectangleFromPoint(newPoint)); } /* if (_drawIndicator) * { * if (_movementPoint == _nullPoint) * { * // If there is nothing old to remove... * if (newPoint != _nullPoint) * { * // And there is something new to show, then just draw it * DrawSplitIndicator(SplitRectangleFromPoint(newPoint)); * } * } * else if (newPoint == _nullPoint) * { * // If there is nothing new to draw... * if (_movementPoint != _nullPoint) * { * // And there is something old still showing, then remove it * DrawSplitIndicator(SplitRectangleFromPoint(_movementPoint)); * } * } * else if (_movementPoint != newPoint) * { * // There is a delta change to draw based on the orientation * if (_separatorOrientation == Orientation.Vertical) * { * // Find the absolute different in positions * int delta = Math.Abs(_movementPoint.X - newPoint.X); * * // If they do not actually overlap... * if (delta >= Target.ClientWidth) * { * // Then we just remove the old indicator and draw the new one * DrawSplitIndicator(SplitRectangleFromPoint(_movementPoint)); * DrawSplitIndicator(SplitRectangleFromPoint(newPoint)); * } * else * { * // Draw the areas that do not overlap * DrawSplitIndicator(SplitRectangleFromPoint(_movementPoint, newPoint.X - _movementPoint.X)); * DrawSplitIndicator(SplitRectangleFromPoint(new Point(_movementPoint.X + Target.ClientWidth, _movementPoint.Y), newPoint.X - _movementPoint.X)); * } * } * else * { * // Find the absolute different in positions * int delta = Math.Abs(_movementPoint.Y - newPoint.Y); * * // If they do not actually overlap... * if (delta >= Target.ClientHeight) * { * // Then we just remove the old indicator and draw the new one * DrawSplitIndicator(SplitRectangleFromPoint(_movementPoint)); * DrawSplitIndicator(SplitRectangleFromPoint(newPoint)); * } * else * { * // Draw the areas that do not overlap * DrawSplitIndicator(SplitRectangleFromPoint(_movementPoint, newPoint.Y - _movementPoint.Y)); * DrawSplitIndicator(SplitRectangleFromPoint(new Point(_movementPoint.X, _movementPoint.Y + Target.ClientHeight), newPoint.Y - _movementPoint.Y)); * } * } * } * } */ } } // Remember the point used for last draw cycle _movementPoint = newPoint; }
public void OnEndDrag() { currentDrag = null; dragIcon.gameObject.SetActive(false); }
// Use this for initialization void Start() { drag = GetComponent <DragObject>(); // get the sprite of this object m_Image = GetComponent <Image>(); }
public static Boolean Prefix(ABBGHUD __instance, DragObject dragObject, Boolean leftButton) { return(leftButton ? ProcessLeftMouseButton(__instance, dragObject) : ProcessRightMouseButton(__instance, dragObject)); }
// 位置を元に戻す private void ResetToInitialPosition(DragObject dragObject) { dragObject.contentRectTrans.anchoredPosition = dragObject.initialAnchoredPosition; }
void Update() { if (Input.GetMouseButtonDown(0) && Manager <UIManager> .Instance.showingText) { ContinueClick.Invoke(); } //Debug code to removing inventory objects if (Input.GetKeyDown(KeyCode.Delete)) { Manager <InventoryManager> .Instance.RemoveInventoryObjectByIndex(0); } //Allow player to hold button to show all objects that can be interacted with if (Input.GetKey(KeyCode.Return) && !Manager <UIManager> .Instance.showingText && !Manager <UIManager> .Instance.awaitingResponse) { //Trigger event that all clickable objects subscribe to turn them highlighted StartHighlightOverride.Invoke(); } else if (Input.GetKeyUp(KeyCode.Return)) { //Trigger event that tells all hightable objects to go back to normal StopHighlightOverride.Invoke(); } #region Raycasting //Perform raycast to mouse position along Z axis Vector3 mousePos = cameraMain.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D raycastHit = Physics2D.Raycast(mousePos + new Vector3(0, 0, -10), mousePos - cameraMain.transform.position); //If raycast hits check if the object has an highlight sprite or show text component if (raycastHit) { GameObject objectHit = raycastHit.collider.gameObject; //Check if mouse has entered or left an object with a highlight sprite component HighlightSprite highlightSprite = objectHit.GetComponent <HighlightSprite>(); if (highlightSprite == null) { //another object is at top but does not have a highlight sprite component so tell currently highlighted object to be un-highlighted if (currentHighlightSprite != null) { currentHighlightSprite.MouseLeave(); currentHighlightSprite = null; } } else { //Object on top has a highlight sprite component so un-highlight any currently highlighted object, highlight new one and store it for future reference if (currentHighlightSprite != null) { currentHighlightSprite.MouseLeave(); } highlightSprite.MouseOver(); currentHighlightSprite = highlightSprite; } //Check if mouse has entered an object with a show text component and if the left mouse button is clicked ShowText showText = objectHit.GetComponent <ShowText>(); if (showText != null && Input.GetMouseButtonDown(0)) { showText.ShowTextClicked(); } //Check if mouse has entered an object with a Drag Object component, left mouse has been clicked this frame and UI manager isn't busy set state ofdrag object to being dragged DragObject dragObject = objectHit.GetComponent <DragObject>(); if (dragObject != null && Input.GetMouseButtonDown(0) && !Manager <UIManager> .Instance.showingText && !Manager <UIManager> .Instance.awaitingResponse) { dragObject.StartDrag(); } } else { //If raycast doesn't hit tell current highlighted object to un-highlight if (currentHighlightSprite != null) { currentHighlightSprite.MouseLeave(); currentHighlightSprite = null; } } #endregion }
private void StopDrag() { _dragObject.StopDrag(); _isDraggingObject = false; _dragObject = null; }
private void StartDrag(DragObject target) { _isDraggingObject = true; _dragObject = target; _dragReferencePoint = target.StartDrag(); }
// 檢查物件是否超過邊界 private void CheckObjectPostion(Vector3 pos) { DragObject dragObject = null; // 取得檢查物件 switch (direction) { case Direction.VERTICAL: if (pos.y > 0) { dragObject = dragObjectArray[0]; // 向上滑動,檢察第一個 } else if (pos.y < 0) { dragObject = dragObjectArray[dragObjectArray.Count - 1]; // 向下滑動,檢查最後一個 } else { return; } break; case Direction.HORIZONTAL: if (pos.x > 0) { dragObject = dragObjectArray[dragObjectArray.Count - 1]; // 向右滑動,檢查最後一個 } else if (pos.x < 0) { dragObject = dragObjectArray[0]; // 向左滑動,檢察第一個 } else { return; } break; } Vector3 checkPos = dragObject.transform.localPosition; // 檢查物件是否超過邊界 switch (direction) { case Direction.VERTICAL: // 向上滑動,檢查上邊界 if (pos.y > 0 && checkPos.y - dragObjectBound.y > uperBoundPos.y) { Vector3 down = dragObjectArray[dragObjectArray.Count - 1].transform.localPosition; dragObject.transform.localPosition = new Vector3(checkPos.x, down.y - dragObjectBound.y * 2 - spaceing, checkPos.z); OffsetX(dragObject); // 第一個物件移至最後一個 dragObjectArray.RemoveAt(0); dragObjectArray.Add(dragObject); } // 向下滑動,檢查下邊界 else if (pos.y < 0 && checkPos.y + dragObjectBound.y < lowerBoundPos.y) { Vector3 up = dragObjectArray[0].transform.localPosition; dragObject.transform.localPosition = new Vector3(checkPos.x, up.y + dragObjectBound.y * 2 + spaceing, checkPos.z); OffsetX(dragObject); // 最後物件移至一個 dragObjectArray.RemoveAt(dragObjectArray.Count - 1); dragObjectArray.Insert(0, dragObject); } break; case Direction.HORIZONTAL: if (pos.x > 0 && checkPos.x - dragObjectBound.x > uperBoundPos.x) { Vector3 right = dragObjectArray[0].transform.localPosition; dragObject.transform.localPosition = new Vector3( right.x - dragObjectBound.x * 2 - spaceing, checkPos.y, checkPos.z); OffsetY(dragObject); // 最後物件移至一個 dragObjectArray.RemoveAt(dragObjectArray.Count - 1); dragObjectArray.Insert(0, dragObject); } else if (pos.x < 0 && checkPos.x + dragObjectBound.x < lowerBoundPos.x) { Vector3 left = dragObjectArray[dragObjectArray.Count - 1].transform.localPosition; dragObject.transform.localPosition = new Vector3( left.x + dragObjectBound.x * 2 + spaceing, checkPos.y, checkPos.z); OffsetY(dragObject); // 第一個物件移至最後一個 dragObjectArray.RemoveAt(0); dragObjectArray.Add(dragObject); } break; } }
private void Start() { DO = GetComponentInParent <DragObject>(); paddle = GetComponentInParent <Paddle>(); }
private void SetToNone() { state = DragState.NONE; dragObject = null; currentAgent = null; }
public void OnGUI() { GUI.Label(new Rect(boxWidth + 50, 0, 500, 500), "Dragging String = " + draggingString + "\n strings.Count " + strings.Count + "\n" + strings.ListToString <String>()); accumulatedHeight = gap; // Draw DropAreas for (int i = 0; i < strings.Count; i++) { if (dragNDrop.DropAreaBegin(i.ToString())) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Orangeish); //GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i); dragNDrop.ThisDropArea.Rect = new Rect(gap, accumulatedHeight, boxWidth, boxHeight); accumulatedHeight += gap + boxHeight; dragNDrop.SetObject(i.ToString(), strings[i]); dragNDrop.DropAreaEnd(i.ToString()); } } accumulatedHeight = gap; List <String> concurrentStrings = new List <string>(strings); int currentItem = 0; foreach (String str in concurrentStrings) { DragObject currentstr = dragNDrop.TryGetDragObject(str); int i = concurrentStrings.IndexOf(str); if (currentstr.IsDragging) { draggingStringOldIndex = i; draggingString = strings[i]; strings.RemoveAt(i); Debug.Log("Dragging String = " + draggingString + "\n" + strings.ListToString <String>()); } if (dragNDrop.DragObjectBegin(concurrentStrings[i])) { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, concurrentStrings[i].ToString()); Rect icon = new Rect(dragNDrop.CurrentDragObject.CurrentRect); icon.width = icon.height; GUI.DrawTexture(icon, DefaultIconSet.Device); dragNDrop.DragObjectEnd(concurrentStrings[i]); } currentItem++; } if (draggingString != null) { for (int i = 0; i < strings.Count; i++) { DropArea dropArea; if (dragNDrop.dropAreas.TryGetValue(i.ToString(), out dropArea)) { dragNDrop.TryCreateDropArea("before" + i, null, new Rect(dropArea.Rect.x, dropArea.Rect.y, dropArea.Rect.width, dropArea.Rect.height / 2f), dropArea.Types.ToArray()); dragNDrop.TryCreateDropArea("after" + i, null, new Rect(dropArea.Rect.x, dropArea.Rect.y + dropArea.Rect.height / 2f, dropArea.Rect.width, dropArea.Rect.height / 2f), dropArea.Types.ToArray()); if (dragNDrop.DropAreaBegin("before" + i)) { if (dragNDrop.ThisDropArea.ContainsMouse()) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Greenish); //GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); GUI.Label(dragNDrop.ThisDropArea.Rect, "before " + i); } dragNDrop.DropAreaEnd("before" + i); } if (dragNDrop.DropAreaBegin("after" + i)) { //CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Greenish); ////GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); //GUI.Label(dragNDrop.ThisDropArea.Rect, "after " + i); if (dragNDrop.ThisDropArea.ContainsMouse()) { CustomGUIUtils.DrawBox(dragNDrop.ThisDropArea.Rect, XKCDColors.Greenish); //GUI.Label(dragNDrop.ThisDropArea.Rect, " " + i + ". " + dragNDrop.ThisDropArea.ToString()); GUI.Label(dragNDrop.ThisDropArea.Rect, "after " + i); } dragNDrop.DropAreaEnd("after" + i); } } } bool newDropArea = false; if (dragNDrop.DragObjectBegin(draggingString)) { CustomGUIUtils.DrawBox(dragNDrop.CurrentDragObject.CurrentRect, myGrey); GUI.Label(dragNDrop.CurrentDragObject.CurrentRect, draggingString.ToString()); Rect icon = new Rect(dragNDrop.CurrentDragObject.CurrentRect); icon.width = icon.height; GUI.DrawTexture(icon, DefaultIconSet.Device); newDropArea = dragNDrop.DragObjectEnd(draggingString); } //if (newDropArea) //{ //} DragObject currentstr = dragNDrop.TryGetDragObject(draggingString); if (!currentstr.IsDragging) { Debug.Log(currentstr.DropArea.Id); if (currentstr.DropArea.Id.StartsWith("before") || currentstr.DropArea.Id.StartsWith("after")) { if (currentstr.DropArea.Id.StartsWith("before")) { int newIndex = int.Parse(currentstr.DropArea.Id.Replace("before", "")); strings.Insert(newIndex, draggingString); } else if (currentstr.DropArea.Id.StartsWith("after")) { int newIndex = int.Parse(currentstr.DropArea.Id.Replace("after", "")) + 1; strings.Insert(newIndex, draggingString); currentstr.t = 0f; currentstr.Ease = true; currentstr.EaseEndRect = dragNDrop.dropAreas[newIndex.ToString()].Rect; } } else { //strings.Capacity += 1; Debug.Log("old Index" + draggingStringOldIndex); strings.Insert(draggingStringOldIndex, draggingString); } draggingString = null; draggingStringOldIndex = -1; } } }
// 目的地に移動させる private void SetToTargetPosition(DragObject dragObject, Vector2 targetPoint) { dragObject.contentRectTrans.anchoredPosition = targetPoint; }
public ContentArea() { AfterSet = () => { ViewX = GX; ViewY = GY; ViewW = W; ViewH = H; Scroller.Set(W - 10, 0, 10, H); if (Contents.Count > 0) { var lo = Contents[Contents.Count - 1]; Scroller.SetMax(lo.Y + 55); } }; Resized = () => { }; Scroller = new ScrollBarV(); Add(Scroller); Scroller.ValueChange = (v) => { YDif = -(int)v; }; if (FileTex == null) { FileTex = new Texture2D("data/ui/file1.png", LoadMethod.Single, true); FolderTex = new Texture2D("data/nxUI/content/folder.png", LoadMethod.Single, true); ScriptTex = new Texture2D("data/nxUI/content/script.png", LoadMethod.Single, true); MusicTex = new Texture2D("data/nxUI/content/music.png", LoadMethod.Single, true); ImgTex = new Texture2D("data/nxUI/content/texture.png", LoadMethod.Single, true); } Draw = () => { DrawFormSolid(new OpenTK.Vector4(0.2f, 0.2f, 0.2f, 0.9f)); foreach (var ce in Contents) { if (ce == Over) { DrawFormSolid(new OpenTK.Vector4(0.7f, 0.7f, 0.7f, 0.7f), ce.X, ce.Y + YDif, 64, 64); } if (ce.IsFolder) { DrawForm(FolderTex, ce.X + 5, ce.Y + 5 + YDif, 54, 54); } else { DrawForm(FileTex, ce.X, ce.Y + YDif, 64, 64); var ext = new FileInfo(ce.FullPath).Extension; switch (ext) { case ".cs": DrawForm(ScriptTex, ce.X, ce.Y + 24 + YDif, 64, 44); break; case ".jpg": case ".png": case ".bmp": DrawForm(ImgTex, ce.X, ce.Y + 24 + YDif, 64, 44); break; case ".mp3": case ".wav": case ".ogg": DrawForm(MusicTex, ce.X, ce.Y + 24 + YDif, 64, 44); break; } } if (ce == Over) { DrawFormSolid(new OpenTK.Vector4(0.9f, 0.9f, 0.9f, 0.8f), ce.X - 5, ce.Y + 58 + YDif, 120, 25); DrawText(ce.Name, ce.X, ce.Y + 58 + YDif, new OpenTK.Vector4(0.1f, 0.1f, 0.1f, 0.8f)); } else { DrawText(ce.Name, ce.X, ce.Y + 58 + YDif, new OpenTK.Vector4(1, 1, 1, 0.8f)); } } }; MouseLeave = () => { Over = null; }; MouseMove = (x, y, mx, my) => { Over = null; foreach (var ce in Contents) { if (x > ce.X && y > (ce.Y + YDif) && x < ce.X + 64 && y < ce.Y + 64) { Over = ce; } } if (DragEntry != null) { DragEntry.X += mx; DragEntry.Y += my; if (DragEntry.X < 12) { DragEntry.X = 12; } if (DragEntry.Y < 12) { DragEntry.Y = 12; } } }; MouseUp = (b) => { if (b == 0) { DragEntry = null; if (UI.CurUI.DragObj == null) { return; } UI.CurUI.CompleteDrag(); UI.CurUI.DragObj = null; } }; MouseDown = (b) => { if (b == 0) { var ce = GetContent(); // DragEntry = ce; if (ce != null) { if (ce.IsFolder) { return; } var dragObj = new DragObject(); dragObj.DragImg = FileTex; UI.CurUI.DragObj = dragObj; var item = new LabelForm().Set(-10, 50, 120, 25, ce.Name); dragObj.Add(item); dragObj.DragObj = ce; dragObj.DragSubObj = this; DragEntry = null; } } if (b == 2) { GoBack(); } }; DoubleClick = (b) => { var ce = GetContent(); if (ce == null) { return; } if (ce.IsFolder) { Root.SetPath(ce.FullPath); return; } else { Root.LoadAsset(ce.FullPath); } }; }