Example #1
0
        public override void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (Ui.UIHovering)
            {
                return;
            }

            if (e.Button != (int)MouseButton.Left)
            {
                return;
            }

            ITile tile = Input.GetTileUnderCursor();

            if (tile == null)
            {
                return;
            }

            IntRect rect = GetBuildingRectangle(tile, BuildingType);

            if (BuildingType.CanBuild(rect.TopLeft(), Input.Player, Level) && cost.HasResources(Input.Player))
            {
                if (Level.BuildBuilding(BuildingType, rect.TopLeft(), Quaternion.Identity, Input.Player) != null)
                {
                    cost.TakeFrom(Input.Player);
                }
            }
        }
Example #2
0
        void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (currentBuilder == null)
            {
                if (ui.UIHovering)
                {
                    return;
                }

                var raycast = input.CursorRaycast();
                foreach (var result in raycast)
                {
                    for (Node current = result.Node; current != Level.LevelNode && current != null; current = current.Parent)
                    {
                        if (!Level.TryGetBuilding(current, out IBuilding building))
                        {
                            continue;
                        }

                        Clicker clicker = null;
                        if ((clicker = building.GetDefaultComponent <Clicker>()) != null)
                        {
                            clicker.Click(e.Button, e.Buttons, e.Qualifiers);
                            return;
                        }
                    }
                }
            }
            else
            {
                currentBuilder.OnMouseDown(e);
            }
        }
Example #3
0
        public override void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (ui.UIHovering)
            {
                return;
            }


            foreach (var result in input.CursorRaycast())
            {
                if (Level.Map.IsRaycastToMap(result))
                {
                    //Try spawn at the map position, don't raycast through map
                    SpawnAt(Map.GetContainingTile(result.Position), input.Player);
                    return;
                }

                for (Node current = result.Node; current != Level.LevelNode && current != null; current = current.Parent)
                {
                    //If it is part of a building
                    if (Level.TryGetBuilding(current, out IBuilding building))
                    {
                        //Try spawn at the building hit, if successfully spawned, return
                        if (SpawnAt(Map.GetContainingTile(result.Position), input.Player) != null)
                        {
                            return;
                        }
                    }
                }
            }
        }
        void HandleMouseButtonDown(MouseButtonDownEventArgs args)
        {
            Input          input        = Input;
            PhysicsWorld2D physicsWorld = scene.GetComponent <PhysicsWorld2D>();
            RigidBody2D    rigidBody    = physicsWorld.GetRigidBody(input.MousePosition.X, input.MousePosition.Y, uint.MaxValue); // Raycast for RigidBody2Ds to pick

            if (rigidBody != null)
            {
                pickedNode = rigidBody.Node;
                //log.Info(pickedNode.name);
                StaticSprite2D staticSprite = pickedNode.GetComponent <StaticSprite2D>();
                staticSprite.Color = (new Color(1.0f, 0.0f, 0.0f, 1.0f)); // Temporary modify color of the picked sprite

                // Create a ConstraintMouse2D - Temporary apply this constraint to the pickedNode to allow grasping and moving with the mouse
                ConstraintMouse2D constraintMouse = pickedNode.CreateComponent <ConstraintMouse2D>();
                constraintMouse.Target           = GetMousePositionXY();
                constraintMouse.MaxForce         = 1000 * rigidBody.Mass;
                constraintMouse.CollideConnected = true;
                constraintMouse.OtherBody        = dummyBody; // Use dummy body instead of rigidBody. It's better to create a dummy body automatically in ConstraintMouse2D
                constraintMouse.DampingRatio     = 0.0f;
            }

            mouseMoveEventToken = Input.SubscribeToMouseMoved(HandleMouseMove);
            mouseButtonUpToken  = Input.SubscribeToMouseButtonUp(HandleMouseButtonUp);
        }
Example #5
0
        void OnMouseDown(MouseButtonDownEventArgs args)
        {
            if (ui.UIHovering)
            {
                return;
            }

            manipulator?.OnMouseDown(args);
        }
 public override void OnMouseDown(MouseButtonDownEventArgs args)
 {
     mouseButtonDown = true;
     smoothedCenter  = input.GetTileUnderCursor();
     if (smoothedCenter != null)
     {
         map.ChangeTileHeight(smoothedCenter, highlight.Size, CalculateTileHeight);
     }
 }
Example #7
0
 public override void OnMouseDown(MouseButtonDownEventArgs args)
 {
     centerTile = input.GetTileUnderCursor();
     if (centerTile != null)
     {
         input.HideCursor();
         mouseButtonDown = true;
         highlight.FixHighlight(centerTile);
     }
 }
Example #8
0
 /// <summary>
 /// Safely invokes the <see cref="MouseDown"/> event with the given <paramref name="args"/>.
 /// Protects against plugin thrown exceptions.
 /// </summary>
 /// <param name="args">The arguments to invoke the event with</param>
 void InvokeMouseDown(MouseButtonDownEventArgs args)
 {
     try
     {
         MouseDown?.Invoke(args);
     }
     catch (Exception e)
     {
         Urho.IO.Log.Write(LogLevel.Warning,
                           $"There was an unexpected exception during the invocation of {nameof(MouseDown)}: {e.Message}");
     }
 }
Example #9
0
        public override void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (ui.UIHovering)
            {
                return;
            }

            if (e.Button == (int)MouseButton.Left)
            {
                ITile startTile = input.GetTileUnderCursor();
                if (startTile != null)
                {
                    line = new List <ITile> {
                        startTile
                    };
                }
            }
        }
Example #10
0
        void OnMouseDown(MouseButtonDownEventArgs e)
        {
            mouseButtonDown = true;

            if (ui.UIHovering)
            {
                return;
            }

            if (checkBoxes.Selected != null)
            {
                var centerTile = input.GetTileUnderCursor();
                if (centerTile != null)
                {
                    Map.ChangeTileType(centerTile, highlight.Size, tileTypes[checkBoxes.Selected]);
                }
            }
        }
Example #11
0
        void MouseDown(MouseButtonDownEventArgs e)
        {
            if (ui.UIHovering)
            {
                return;
            }

            var tile = input.GetTileUnderCursor();

            //NOTE: Add raycast into a plane and get point even outside the map
            if (tile != null)
            {
                mouseDownPos   = tile.MapLocation;
                lastMousePos   = tile.MapLocation;
                validMouseDown = true;
                rectangle      = false;
            }
        }
Example #12
0
        public override void OnMouseDown(MouseButtonDownEventArgs args)
        {
            List <RayQueryResult> raycastResult = input.CursorRaycast();
            IntVector2?           vertex        = map.RaycastToVertex(raycastResult);

            if (!vertex.HasValue)
            {
                return;
            }

            //NOTE: this is slow, make it faster
            if (!verticies.Remove(vertex.Value))
            {
                verticies.Add(vertex.Value);
            }

            map.HighlightCornerList(SelectedVerticies, Color.Green);
        }
Example #13
0
        void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (ui.UIHovering)
            {
                return;
            }

            if (checkBoxes.Selected != null)
            {
                foreach (var result in input.CursorRaycast())
                {
                    if (Level.Map.IsRaycastToMap(result))
                    {
                        //Try spawn
                        Level.SpawnUnit(unitTypes[checkBoxes.Selected],
                                        Map.GetContainingTile(result.Position),
                                        Quaternion.Identity,
                                        input.Player);
                        return;
                    }

                    //Spawn only at buildings or map, not units, projectiles etc.
                    for (Node current = result.Node; current != Level.LevelNode && current != null; current = current.Parent)
                    {
                        if (!Level.TryGetBuilding(current, out IBuilding dontCare))
                        {
                            continue;
                        }

                        if (Level.SpawnUnit(unitTypes[checkBoxes.Selected],
                                            Map.GetContainingTile(result.Position),
                                            Quaternion.Identity,
                                            input.Player) != null)
                        {
                            //Spawned
                            return;
                        }
                    }
                }
            }
        }
Example #14
0
        public override void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (e.Button != (int)MouseButton.Left)
            {
                return;
            }

            var raycast = Input.CursorRaycast();

            foreach (var result in raycast)
            {
                for (Node current = result.Node; current != Level.LevelNode && current != null; current = current.Parent)
                {
                    if (Level.TryGetBuilding(current, out IBuilding building))
                    {
                        building.RemoveFromLevel();
                        return;
                    }
                }
            }
        }
Example #15
0
        public override void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (e.Button != (int)MouseButton.Left)
            {
                return;
            }

            var raycast = input.CursorRaycast();

            foreach (var result in raycast)
            {
                for (Node currentNode = result.Node; currentNode != Level.LevelNode && currentNode != null; currentNode = currentNode.Parent)
                {
                    if (Level.TryGetUnit(currentNode, out IUnit unit))
                    {
                        unit.RemoveFromLevel();
                        return;
                    }
                }
            }
        }
Example #16
0
        private void HandleMouseButtonDown(MouseButtonDownEventArgs args)
        {
            if (args.Button == 1)
            {
                if (_mouseTouch == null)
                {
                    _mouseTouch = new TouchState {
                        ID = MouseTouchID, ScreenPosition = Input.MousePosition, Pressure = 1.0f
                    };
                    StartTouch(_mouseTouch);
                }
            }

            if (args.Button == 4)
            {
                _rigthClick = new TouchState {
                    ID = MouseTouchID, ScreenPosition = Input.MousePosition, Pressure = 1.0f
                };
                _rightClickStart     = _environment.Raycast(Input.MousePosition);
                _potentialRightClick = true;
            }
        }
Example #17
0
            public override void OnMouseDown(MouseButtonDownEventArgs e)
            {
                if (e.Button != (int)MouseButton.Left || Ui.UIHovering)
                {
                    return;
                }

                ITile tile = Input.GetTileUnderCursor();

                if (tile == null)
                {
                    return;
                }

                IntRect rect = GetBuildingRectangle(tile, BuildingType);

                if (BuildingType.CanBuild(rect.TopLeft(), Input.Player, Level))
                {
                    IBuilding building = Level.BuildBuilding(BuildingType, rect.TopLeft(), Quaternion.Identity, Input.Player);
                    Tree      tree     = (Tree)building.BuildingPlugin;
                    tree.SetSize((sizeSlider.Value / sizeSlider.Range) + startSize);
                }
            }
Example #18
0
        void OnMouseDown(MouseButtonDownEventArgs e)
        {
            if (checkBoxes.Selected == null || ui.UIHovering)
            {
                return;
            }

            var tile = input.GetTileUnderCursor();

            if (tile == null)
            {
                return;
            }

            var buildingType = buildingTypes[checkBoxes.Selected];

            GetBuildingRectangle(tile, buildingType, out IntVector2 topLeft, out IntVector2 bottomRight);

            if (buildingType.CanBuild(topLeft, input.Player, Level))
            {
                LevelManager.CurrentLevel.BuildBuilding(buildingTypes[checkBoxes.Selected], topLeft, Quaternion.Identity, input.Player);
            }
        }
Example #19
0
 public virtual void OnMouseDown(MouseButtonDownEventArgs e)
 {
 }
        void HandleMouseButtonDown(MouseButtonDownEventArgs args)
        {
            Input input = Input;
            PhysicsWorld2D physicsWorld = scene.GetComponent<PhysicsWorld2D>();
            RigidBody2D rigidBody = physicsWorld.GetRigidBody(input.MousePosition.X, input.MousePosition.Y, uint.MaxValue); // Raycast for RigidBody2Ds to pick
            if (rigidBody != null)
            {
                pickedNode = rigidBody.Node;
                //log.Info(pickedNode.name);
                StaticSprite2D staticSprite = pickedNode.GetComponent<StaticSprite2D>();
                staticSprite.Color = (new Color(1.0f, 0.0f, 0.0f, 1.0f)); // Temporary modify color of the picked sprite

                // Create a ConstraintMouse2D - Temporary apply this constraint to the pickedNode to allow grasping and moving with the mouse
                ConstraintMouse2D constraintMouse = pickedNode.CreateComponent<ConstraintMouse2D>();
                constraintMouse.Target= GetMousePositionXY();
                constraintMouse.MaxForce=1000 * rigidBody.Mass;
                constraintMouse.CollideConnected=true;
                constraintMouse.OtherBody=dummyBody;  // Use dummy body instead of rigidBody. It's better to create a dummy body automatically in ConstraintMouse2D
                constraintMouse.DampingRatio=0.0f;
            }

            mouseMoveEventToken = Input.SubscribeToMouseMoved(HandleMouseMove);
            mouseButtonUpToken = Input.SubscribeToMouseButtonUp(HandleMouseButtonUp);
        }
Example #21
0
 public MouseEventArguments(MouseButtonDownEventArgs args)
 {
     Qualifiers = args.Qualifiers;
     Buttons    = (MouseButton)args.Buttons;
 }
Example #22
0
 public override void OnMouseDown(MouseButtonDownEventArgs args)
 {
     mouseDown = true;
     input.HideCursor();
 }
 private void OnMouseButtonDown(MouseButtonDownEventArgs args)
 {
     _mouseButtonDown?.Invoke(this, new MouseButtonDownEventArguments(args));
 }
Example #24
0
 void OnMouseDown(MouseButtonDownEventArgs e)
 {
     currentSpawner?.OnMouseDown(e);
 }
Example #25
0
 /// <summary>
 /// Handles the engine mouse button down event and translates it to platform mouse button pressed event.
 /// </summary>
 /// <param name="e">The engine mouse button down data.</param>
 protected override void MouseButtonDown(MouseButtonDownEventArgs e)
 {
     InvokeMouseDown(e);
     cachedTileUnderCursor = null;
 }
Example #26
0
 /// <summary>
 /// Invoked when a mouse button is pressed down.
 /// </summary>
 /// <param name="e">Additional data of the button press event.</param>
 protected abstract void MouseButtonDown(MouseButtonDownEventArgs e);
Example #27
0
 void InputOnMouseButtonDown(MouseButtonDownEventArgs mouseButtonDownEventArgs)
 {
 }
 public MouseButtonDownEventArguments(MouseButtonDownEventArgs args) : base(args)
 {
 }
 void HandleMouseButtonDown(MouseButtonDownEventArgs args)
 {
     System.Console.WriteLine("button pressed");
 }