public SelectionState(ITextView view)
        {
            var selectionBroker = view.GetMultiSelectionBroker();
            var map             = SelectionState.EditToDataMap(view);

            if (selectionBroker.IsBoxSelection)
            {
                _primary = new SingleSelection(map, selectionBroker.BoxSelection);
                _isBox   = true;
            }
            else
            {
                if (selectionBroker.HasMultipleSelections)
                {
                    var selections = selectionBroker.AllSelections;
                    _selections = new SingleSelection[selections.Count];
                    for (int i = 0; (i < _selections.Length); ++i)
                    {
                        _selections[i] = new SingleSelection(map, selections[i]);
                    }
                }

                _primary = new SingleSelection(map, selectionBroker.PrimarySelection);
            }
        }
Example #2
0
        void PaintingMode()
        {
            Tools.current = Tool.None;
            hover         = GetSelectionAt(e.mousePosition);

            if (hover != null)
            {
                var block = tiler.At(hover.Tile);
                if (block != null)
                {
                    if (LeftButtonClick)
                    {
                        // paint single tile
                        if (paintMode == PaintModes.Brush)
                        {
                            if (SetBlockFace(block, hover.Face, brush))
                            {
                                tiler.Rebuild(rebuildCollision: false);
                            }
                        }
                        // paint bucket
                        else if (paintMode == PaintModes.Fill)
                        {
                            var face = GetBlockFace(block, hover.Face);
                            if (FillBlockFace(block, face))
                            {
                                tiler.Rebuild(rebuildCollision: false);
                            }
                        }
                    }
                }

                DrawSelection(hover, paintFaceColor, paintOutlineColor);
            }
        }
Example #3
0
            public void Add(SingleSelection selection)
            {
                if (IsEmpty)
                {
                    Face = selection.Face;
                }

                Tiles.Add(selection.Tile);
            }
Example #4
0
    void OnUndoRedo()
    {
        var tar = target as Tile3D;

        selected = null;
        hover    = null;
        // After an undo the underlying block dictionary is out of sync with
        // the blocks list. Blocks have been removed, dictionary hasn't been
        // updated yet which causes artifacts during rebuild. So - update it.
        tar.RebuildBlockMap();
        tar.Rebuild();
    }
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this);
     }
     mainCam = Camera.main;
 }
Example #6
0
    private void Start()
    {
        mainCam      = Camera.main;
        singleSelect = SingleSelection.instance;
        boxSelect    = BoxSelection.instance;
        singleSelect.OnAddSelection   += Select;
        singleSelect.OnClearSelection += Deselect;
        boxSelect.OnBoxSelection      += CheckBoxLocation;
        boxSelect.OnClearSelection    += Deselect;

        foreach (var marker in selectionMarkers)
        {
            marker.SetActive(false);
        }
    }
Example #7
0
        /// <summary>
        /// Sets a two-way binding between the value of the selected view model item and the specified selection. <para/>
        /// When the specified selection changes, the selected tree view model item will be adapted.
        /// Likewise, when the selection states of the tree view model item changes, the selection will be adapted. <para/>
        /// NOTE : If this tree view model already has a bound selection, then the selection binding must be broken first, otherwise an exception will be thrown. <para/>
        /// NOTE : A single selection binding can be set only if this tree view model item does not allow multiple selection.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="selection"></param>
        protected void SetSelectionBinding <T>(SingleSelection <T> selection)
        {
            selection.AssertParameterNotNull(nameof(selection));
            if (AllowMultipleSelection)
            {
                throw new Exception("Error : Attempting to set a selection binding between a single selection and a tree view model which doesn't support multiple selection.");
            }

            if (HasBoundSelection)
            {
                throw new Exception("Error : Cannot set a selection binding on this tree view model instance because one already exists. Break the current selection binding before setting a new one.");
            }

            SelectionBinding = new SingleTreeSelectionBinding <T>(selection);
            SelectionBinding.Initialize(this);
            SelectionBinding.SyncItems = SyncItems;
        }
Example #8
0
    //-----------------------------------------------------
    //  マウスの位置にあるタイルを取得
    //-----------------------------------------------------
    void ActiveHover()
    {
        if (!(e.type == EventType.MouseMove || e.type == EventType.MouseDrag))
        {
            return;
        }
        if (!interacting)
        {
            return;
        }
        if (draggingBlock)
        {
            return;
        }

        var next = GetSelectionAt(e.mousePosition);

        // 前回のタイルと違うならGizmoを表示し直す
        if ((hover == null && next != null) || (hover != null && next == null) || (hover != null && next != null && (hover.Tile != next.Tile || hover.Face != next.Face)))
        {
            invokeRepaint = true;
        }
        hover = next;
    }
 static public SingleSelection SetNearest(this SingleSelection selection, bool nearest)
 {
     selection.Nearest = nearest;
     return(selection);
 }
Example #10
0
    protected virtual void OnSceneGUI()
    {
        var e             = Event.current;
        var invokeRepaint = false;
        var draggingBlock = false;
        var interacting   = (!e.control && !e.alt && e.button == 0);

        // overlay gui
        Handles.BeginGUI();
        {
            // mode toolbar
            toolMode = (ToolModes)GUI.Toolbar(new Rect(10, 10, 200, 30), (int)toolMode, new[] { "Move", "Build", "Paint" });
            if (toolMode == ToolModes.Painting)
            {
                selected = null;
            }

            // tileset
            if (toolMode == ToolModes.Painting)
            {
                GUI.Window(0, new Rect(10, 70, 200, 400), PaintingWindow, "Tiles");
            }
        }
        Handles.EndGUI();

        // cancel everything if in "move" mode
        if (toolMode == ToolModes.Transform)
        {
            if (Tools.current == Tool.None)
            {
                Tools.current = Tool.Move;
            }
            return;
        }

        // override default control
        Tools.current = Tool.None;
        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

        // Selecting & Dragging Blocks
        if (toolMode == ToolModes.Building)
        {
            // drag block in / out
            if (selected != null)
            {
                Handles.color = Color.blue;
                EditorGUI.BeginChangeCheck();

                var start  = CenterOfSelection(selected) + selected.Face * 0.5f;
                var pulled = Handles.Slider(start, selected.Face);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(target, "EditMesh");

                    draggingBlock = true;
                    if (hover != null)
                    {
                        hover         = null;
                        invokeRepaint = true;
                    }

                    // get distance and direction
                    var distance = (pulled - start).magnitude;
                    var outwards = (int)Mathf.Sign(Vector3.Dot(pulled - start, selected.Face));

                    // create or destroy a block (depending on direction)
                    if (distance > 1f)
                    {
                        var newTiles = new List <Vector3Int>();
                        foreach (var tile in selected.Tiles)
                        {
                            var was  = tile;
                            var next = tile + selected.Face.Int() * outwards;

                            if (outwards > 0)
                            {
                                tiler.Create(next, was);
                            }
                            else
                            {
                                tiler.Destroy(was);
                            }
                            tiler.Rebuild();

                            newTiles.Add(next);
                        }

                        selected.Tiles = newTiles;
                        tiler.Rebuild();
                    }
                }
            }

            // select tiles
            if (!draggingBlock && interacting)
            {
                if (e.type == EventType.MouseDown && !e.shift)
                {
                    if (hover == null)
                    {
                        selected = null;
                    }
                    else
                    {
                        selected = new MultiSelection(hover);
                    }
                    invokeRepaint = true;
                }
                else if (e.type == EventType.MouseDrag && selected != null && hover != null && !selected.Tiles.Contains(hover.Tile))
                {
                    selected.Tiles.Add(hover.Tile);
                    invokeRepaint = true;
                }
            }
        }

        // active hover
        if ((e.type == EventType.MouseMove || e.type == EventType.MouseDrag) && interacting && !draggingBlock)
        {
            var next = GetSelectionAt(e.mousePosition);
            if ((hover == null && next != null) || (hover != null && next == null) || (hover != null && next != null && (hover.Tile != next.Tile || hover.Face != next.Face)))
            {
                invokeRepaint = true;
            }
            hover = next;
        }

        // painting
        if (toolMode == ToolModes.Painting && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && interacting && hover != null)
        {
            var block = tiler.At(hover.Tile);
            if (block != null)
            {
                // paint single tile
                if (paintMode == PaintModes.Brush)
                {
                    if (SetBlockFace(block, hover.Face, brush))
                    {
                        tiler.Rebuild();
                    }
                }
                // paint bucket
                else if (paintMode == PaintModes.Fill)
                {
                    var face = GetBlockFace(block, hover.Face);
                    if (FillBlockFace(block, face))
                    {
                        tiler.Rebuild();
                    }
                }
            }
        }

        // right-click to rotate face
        if (toolMode == ToolModes.Painting && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.button == 1 && !e.control && !e.alt && hover != null)
        {
            brush.Rotation = (brush.Rotation + 1) % 4;

            var cell = tiler.At(hover.Tile);
            if (cell != null && SetBlockFace(cell, hover.Face, brush))
            {
                tiler.Rebuild();
            }
        }

        // Drawing
        {
            // draw hovers / selected outlines
            if (hover != null)
            {
                DrawSelection(hover, Color.magenta);
            }
            if (selected != null)
            {
                DrawSelection(selected, Color.blue);
            }

            // force repaint
            if (invokeRepaint)
            {
                Repaint();
            }
        }

        // always keep the tiler selected for now
        // later should detect if something is being grabbed or hovered
        Selection.activeGameObject = tiler.transform.gameObject;
    }
Example #11
0
        private void DrawSelection(SingleSelection selection, Color faceColor, Color outlineColor)
        {
            var center = CenterOfSelection(selection);

            DrawSelection(center, selection.Face, faceColor, outlineColor);
        }
Example #12
0
 public MultiSelection(SingleSelection from)
 {
     Tiles.Add(from.Tile);
     Face = from.Face;
 }
Example #13
0
    private void DrawSelection(SingleSelection selection, Color color)
    {
        var center = CenterOfSelection(selection);

        DrawSelection(center, selection.Face, color);
    }
Example #14
0
 private Vector3 CenterOfSelection(SingleSelection selection)
 {
     return(CenterOfSelection(selection.Tile));
 }
Example #15
0
        void BuildingMode()
        {
            Tools.current = Tool.None;
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            Handles.color = Color.blue;
            hover         = GetSelectionAt(e.mousePosition);

            // Draw only
            if (hover != null)
            {
                DrawSelection(hover, hoverFaceColor, buildOutlineColor);
            }

            if (selected != null && !selected.IsEmpty)
            {
                DrawSelection(selected, selectFaceColor, Color.clear);
                EditorGUI.BeginChangeCheck();
                var start  = CenterOfSelection(selected);
                var pulled = Handles.Slider(start, selected.Face * 0.5f);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(target, "Edit Mesh");
                    MoveBlockAction(start, pulled);
                }
            }

            // only during hovering
            if (hover != null)
            {
                // mark tile as selected when clicked
                if (LeftButtonClick)
                {
                    if (e.shift)
                    {
                        var index = selected.Tiles.FindIndex(t => t == hover.Tile && selected.Face == hover.Face);
                        if (index >= 0)
                        {
                            selected.Tiles.RemoveAt(index);
                        }
                        else
                        {
                            if (selected.IsEmpty || hover.Face == selected.Face)
                            {
                                selected.Add(hover);
                            }
                            else
                            {
                                selected.Clear();
                                selected.Add(hover);
                            }
                        }
                    }
                    else
                    {
                        selected.Clear();
                        selected.Add(hover);
                    }
                }
            }
            else
            {
                if (LeftButtonClick)
                {
                    selected.Clear();
                }
            }

            Selection.activeGameObject = tiler.transform.gameObject;
        }
Example #16
0
 public SingleListSelectionBinding(SingleSelection <T> selection)
 {
     Selection = selection;
 }
Example #17
0
    //=========================================================================
    //
    //  MeshTool
    //
    //=========================================================================
    //-----------------------------------------------------
    // Building
    //-----------------------------------------------------
    void MeshToolBuild()
    {
        // 複数選択されている場合
        if (selected != null)
        {
            Handles.color = Color.blue;
            EditorGUI.BeginChangeCheck();

            var start  = CenterOfSelection(selected) + selected.Face * 0.5f;
            var pulled = Handles.Slider(start, selected.Face);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "EditMesh");

                draggingBlock = true;
                if (hover != null)
                {
                    hover         = null;
                    invokeRepaint = true;
                }

                // get distance and direction
                var distance = (pulled - start).magnitude;
                var outwards = (int)Mathf.Sign(Vector3.Dot(pulled - start, selected.Face));

                // create or destroy a block (depending on direction)
                if (distance > 1f)
                {
                    var newTiles = new List <Vector3Int>();
                    foreach (var tile in selected.Tiles)
                    {
                        var was  = tile;
                        var next = tile + selected.Face.Int() * outwards;

                        if (outwards > 0)
                        {
                            tiler.Create(next, was);
                        }
                        else
                        {
                            tiler.Destroy(was);
                        }
                        tiler.Rebuild();

                        newTiles.Add(next);
                    }

                    selected.Tiles = newTiles;
                    tiler.Rebuild();
                }
            }
        }
        // select tiles
        if (!draggingBlock && interacting)
        {
            if (e.type == EventType.MouseDown && !e.shift)
            {
                if (hover == null)
                {
                    selected = null;
                }
                else
                {
                    selected = new MultiSelection(hover);
                }
                invokeRepaint = true;
            }
            else if (e.type == EventType.MouseDrag && selected != null && hover != null && !selected.Tiles.Contains(hover.Tile))
            {
                selected.Tiles.Add(hover.Tile);
                invokeRepaint = true;
            }
        }

        ActiveHover();
    }
Example #18
0
 public bool Matches(SingleSelection other)
 {
     return(this.Anchor.Matches(other.Anchor) && this.Active.Matches(other.Active) && this.Insertion.Matches(other.Insertion) && (this.Affinity == other.Affinity));
 }
Example #19
0
 public SingleTreeSelectionBinding(SingleSelection <T> selection)
 {
     Selection = selection;
 }