Beispiel #1
0
        void HandleSingleClick(MouseButtonUpEventArgs e)
        {
            foreach (var result in input.CursorRaycast())
            {
                for (Node current = result.Node; current != Level.LevelNode && current != null; current = current.Parent)
                {
                    if (Level.TryGetEntity(current, out IEntity entity))
                    {
                        //Dispatch the click with the actual position of the click
                        var visitor = new ClickDispatcher(this, e, result.Position);
                        if (entity.Accept(visitor))
                        {
                            return;
                        }
                    }
                }

                var tile = Map.RaycastToTile(result);
                if (tile == null)
                {
                    return;
                }

                HandleTileClick(tile, e);

                return;
            }
        }
Beispiel #2
0
 void MouseUp(MouseButtonUpEventArgs args)
 {
     if (controllingMovement)
     {
         StopMovementControl();
     }
 }
        void Input_MouseButtonUp(MouseButtonUpEventArgs e)
        {
            if (prevSourceStaticModel != null && !prevSourceStaticModel.IsDeleted)
            {
                prevSourceStaticModel.Enabled = true;
                if (selectedStaticModel != null && !selectedStaticModel.IsDeleted)
                {
                    selectedStaticModel.Remove();
                }
            }

            var cursorPos = App.UI.CursorPosition;
            var cameraRay = App.Camera.GetScreenRay((float)cursorPos.X / App.Graphics.Width, (float)cursorPos.Y / App.Graphics.Height);
            var result    = Scene.GetComponent <Octree>().RaycastSingle(cameraRay, RayQueryLevel.Triangle, 10000, DrawableFlags.Geometry);

            if (result != null)
            {
                var geometry = result.Value.Drawable as StaticModel;
                if (geometry != null)
                {
                    prevSourceStaticModel     = geometry;
                    geometry.Enabled          = false;
                    selectedStaticModel       = geometry.Node.CreateComponent <StaticModel>();
                    selectedStaticModel.Model = geometry.Model;
                    selectedStaticModel.SetMaterial(CreateSelectionMaterial());
                    Editor?.HighlightXmlForNode(result.Value.Node);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Tries to handle a click on a building.
        /// </summary>
        /// <param name="building">The clicked building.</param>
        /// <param name="e">Event data.</param>
        /// <param name="worldPosition">Position of the intersection of raycast used for click and the building geometry.</param>
        /// <returns>True if the event was handled and should not be propagated to other things behind the clicked building.</returns>
        protected virtual bool HandleBuildingClick(IBuilding building, MouseButtonUpEventArgs e, Vector3 worldPosition)
        {
            //Right clicked enemy building
            if ((MouseButton)e.Button == MouseButton.Right)
            {
                if (building.Player == input.Player)
                {
                    return(false);
                }
                var executed = false;
                foreach (var selectedUnit in GetAllSelectedUnitSelectors())
                {
                    executed |= selectedUnit.Order(new AttackOrder(building));
                }
                return(executed);
            }

            var formationController = building.GetFormationController(worldPosition);

            if (formationController == null)
            {
                return(false);
            }

            formationController.MoveToFormation(new UnitGroup(GetAllSelectedUnitSelectors()));
            return(true);
        }
Beispiel #5
0
        private void HandleMouseButtonUp(MouseButtonUpEventArgs args)
        {
            if (args.Button == 1)
            {
                if (_mouseTouch != null)
                {
                    _mouseTouch = new TouchState {
                        ID = MouseTouchID, ScreenPosition = Input.MousePosition, Pressure = 0.0f
                    };
                    EndTouch(_mouseTouch);
                    _mouseTouch = null;
                }
            }

            if (args.Button == 4)
            {
                if (_potentialRightClick)
                {
                    AltClickComplete?.Invoke(this, new SimpleInteractionEventArgs(_environment.Raycast(Input.MousePosition)));
                    _potentialRightClick = false;
                }

                _rigthClick = null;
            }
        }
Beispiel #6
0
 public ClickDispatcher(UnitSelectorTool unitSelectorTool,
                        MouseButtonUpEventArgs args,
                        Vector3 worldPosition)
 {
     this.unitSelectorTool = unitSelectorTool;
     this.args             = args;
     this.worldPosition    = worldPosition;
 }
Beispiel #7
0
        void OnMouseUp(MouseButtonUpEventArgs args)
        {
            if (ui.UIHovering)
            {
                return;
            }

            manipulator?.OnMouseUp(args);
        }
Beispiel #8
0
 public override void OnMouseUp(MouseButtonUpEventArgs args)
 {
     if (centerTile != null)
     {
         input.ShowCursor(new Vector3(centerTile.Center.X, map.GetTerrainHeightAt(centerTile.Center), centerTile.Center.Y));
         mouseButtonDown = false;
         centerTile      = null;
         highlight.FreeHighlight();
     }
 }
Beispiel #9
0
 void InvokeSelected(IntVector2 topLeft, IntVector2 bottomRight, MouseButtonUpEventArgs args)
 {
     try {
         Selected?.Invoke(topLeft, bottomRight, args);
     }
     catch (Exception e) {
         Urho.IO.Log.Write(LogLevel.Warning,
                           $"There was an unexpected exception during the invocation of {nameof(Selected)}: {e.Message}");
     }
 }
Beispiel #10
0
 void InvokeSingleClick(MouseButtonUpEventArgs args)
 {
     try
     {
         SingleClick?.Invoke(args);
     }
     catch (Exception e)
     {
         Urho.IO.Log.Write(LogLevel.Warning,
                           $"There was an unexpected exception during the invocation of {nameof(SingleClick)}: {e.Message}");
     }
 }
        void HandleMouseButtonUp(MouseButtonUpEventArgs args)
        {
            if (pickedNode != null)
            {
                StaticSprite2D staticSprite = pickedNode.GetComponent <StaticSprite2D>();
                staticSprite.Color = (new Color(1.0f, 1.0f, 1.0f, 1.0f)); // Restore picked sprite color
                pickedNode.RemoveComponent <ConstraintMouse2D>();
                pickedNode = null;
            }

            mouseMoveEventToken?.Unsubscribe();
            mouseButtonUpToken?.Unsubscribe();
        }
Beispiel #12
0
        public override void OnMouseUp(MouseButtonUpEventArgs e)
        {
            if (e.Button != (int)MouseButton.Left || line == null)
            {
                return;
            }

            if (ui.UIHovering)
            {
                ClearSelection();
                return;
            }

            ITile endTile = input.GetTileUnderCursor();

            if (endTile == null)
            {
                ClearSelection();
                return;
            }

            if (endTile != line[line.Count - 1])
            {
                line = GetLine(line[0], endTile);
            }

            if (cost.HasResources(input.Player, line.Count) &&
                line.All((tile) => BuildingType.CanBuild(GetBuildingRectangle(tile, BuildingType).TopLeft(), input.Player, Level)))
            {
                foreach (var tile in line)
                {
                    IBuilding newBuilding = Level.BuildBuilding(BuildingType,
                                                                GetBuildingRectangle(tile, BuildingType).TopLeft(),
                                                                Quaternion.Identity,
                                                                input.Player);
                    if (newBuilding == null)
                    {
                        break;
                    }
                    else
                    {
                        cost.TakeFrom(input.Player);
                    }
                }
            }

            ClearSelection();
        }
Beispiel #13
0
        /// <summary>
        /// Tries to handle a click on a tile.
        /// </summary>
        /// <param name="tile">The clicked tile.</param>
        /// <param name="e">Event data.</param>
        /// <returns>True if the event was handled and should not be propagated to other things behind the clicked tile.</returns>
        protected virtual bool HandleTileClick(ITile tile, MouseButtonUpEventArgs e)
        {
            switch (e.Button)
            {
            case (int)MouseButton.Left:
                return(Map.GetFormationController(tile).MoveToFormation(new UnitGroup(GetAllSelectedUnitSelectors())));

            case (int)MouseButton.Right:
                bool executed = false;
                foreach (var unit in GetAllSelectedUnitSelectors())
                {
                    executed = unit.Order(new ShootOrder(Map.GetRangeTarget(tile.Center3)));
                }
                return(executed);
            }
            return(false);
        }
Beispiel #14
0
        void MouseUp(MouseButtonUpEventArgs e)
        {
            if (!validMouseDown)
            {
                return;
            }

            var tile = input.GetTileUnderCursor();

            if (!rectangle && tile != null)
            {
                InvokeSingleClick(e);
            }
            else
            {
                IntVector2 topLeft, bottomRight;
                if (tile != null)
                {
                    var endTilePos = tile.MapLocation;
                    topLeft = new IntVector2(Math.Min(mouseDownPos.X, endTilePos.X),
                                             Math.Min(mouseDownPos.Y, endTilePos.Y));
                    bottomRight = new IntVector2(Math.Max(mouseDownPos.X, endTilePos.X),
                                                 Math.Max(mouseDownPos.Y, endTilePos.Y));
                }
                else
                {
                    topLeft = new IntVector2(Math.Min(mouseDownPos.X, lastMousePos.X),
                                             Math.Min(mouseDownPos.Y, lastMousePos.Y));
                    bottomRight = new IntVector2(Math.Max(mouseDownPos.X, lastMousePos.X),
                                                 Math.Max(mouseDownPos.Y, lastMousePos.Y));
                }

                InvokeSelected(topLeft, bottomRight, e);
                Map.DisableHighlight();
            }



            validMouseDown = false;
        }
Beispiel #15
0
        /// <summary>
        /// Tries to handle a click on a unit.
        /// </summary>
        /// <param name="unit">The clicked unit.</param>
        /// <param name="e">Event data.</param>
        /// <returns>True if the event was handled and should not be propagated to other things behind the clicked unit.</returns>
        protected virtual bool HandleUnitClick(IUnit unit, MouseButtonUpEventArgs e)
        {
            if ((MouseButton)e.Button == MouseButton.Right)
            {
                Level.Camera.Follow(unit);
                return(true);
            }


            var selector = unit.GetDefaultComponent <UnitSelector>();

            //If the unit is selectable and owned by the clicking player
            if (selector != null && selector.Player == input.Player)
            {
                //Select if not selected, deselect if selected
                if (!selector.Selected)
                {
                    SelectUnit(selector);
                    //Executed an action, stop handling click
                    return(true);
                }
                else
                {
                    DeselectUnit(selector);
                    //Executed an action, stop handling click
                    return(true);
                }
            }
            else
            {
                //Either not selectable or enemy unit
                var executed = false;

                foreach (var selectedUnit in GetAllSelectedUnitSelectors())
                {
                    executed |= selectedUnit.Order(new AttackOrder(unit));
                }
                return(executed);
            }
        }
Beispiel #16
0
 void OnMouseUp(MouseButtonUpEventArgs e)
 {
     mouseButtonDown = false;
 }
Beispiel #17
0
 public virtual void OnMouseUp(MouseButtonUpEventArgs e)
 {
 }
        void HandleMouseButtonUp(MouseButtonUpEventArgs args)
        {
            if (pickedNode != null)
            {
                StaticSprite2D staticSprite = pickedNode.GetComponent<StaticSprite2D>();
                staticSprite.Color = (new Color(1.0f, 1.0f, 1.0f, 1.0f)); // Restore picked sprite color
                pickedNode.RemoveComponent<ConstraintMouse2D>();
                pickedNode = null;
            }

            mouseMoveEventToken?.Unsubscribe();
            mouseButtonUpToken?.Unsubscribe();
        }
Beispiel #19
0
 void OnMouseUp(MouseButtonUpEventArgs e)
 {
     currentBuilder?.OnMouseUp(e);
 }
Beispiel #20
0
 /// <summary>
 /// Handles the engine mouse button up event and translates it to platform mouse button released event.
 /// </summary>
 /// <param name="e">The engine mouse button up data.</param>
 protected override void MouseButtonUp(MouseButtonUpEventArgs e)
 {
     InvokeMouseUp(e);
     cachedTileUnderCursor = null;
 }
 public MouseButtonUpEventArguments(MouseButtonUpEventArgs args) : base(args)
 {
 }
 public override void OnMouseUp(MouseButtonUpEventArgs args)
 {
     mouseButtonDown = false;
 }
Beispiel #23
0
 public override void OnMouseUp(MouseButtonUpEventArgs args)
 {
     mouseDown = false;
     input.ShowCursor();
 }
 private void OnMouseButtonUp(MouseButtonUpEventArgs args)
 {
     _mouseButtonUp?.Invoke(this, new MouseButtonUpEventArguments(args));
 }
 public MouseButtonEventArguments(MouseButtonUpEventArgs args) : base(args)
 {
     Button = args.Button;
 }
Beispiel #26
0
 /// <summary>
 /// Invoked when a mouse button is released.
 /// </summary>
 /// <param name="e">Additional data of the button release event.</param>
 protected abstract void MouseButtonUp(MouseButtonUpEventArgs e);
Beispiel #27
0
 public MouseEventArguments(MouseButtonUpEventArgs args)
 {
     Qualifiers = args.Qualifiers;
     Buttons    = (MouseButton)args.Buttons;
 }
Beispiel #28
0
        protected virtual void HandleAreaSelection(IntVector2 topLeft, IntVector2 bottomRight, MouseButtonUpEventArgs e)
        {
            var unitSelectorsInRectangle = Map.GetTilesInRectangle(topLeft, bottomRight)
                                           .SelectMany((tile) => tile.Units)
                                           .Where((unit) => unit.Player == input.Player)
                                           .Select((unit) => unit.GetDefaultComponent <UnitSelector>())
                                           .Where((selector) => selector != null && !selector.Selected);

            foreach (var unitSelector in unitSelectorsInRectangle)
            {
                SelectUnit(unitSelector);
            }
        }
Beispiel #29
0
 void OnMouseUp(MouseButtonUpEventArgs e)
 {
     currentSpawner?.OnMouseUp(e);
 }