示例#1
0
 public InputEventData(RLKeyPress keyboard, RLMouse mouse)
 {
     Keyboard = keyboard;
     Mouse    = mouse;
 }
        public void HandleMouseEvent(RLMouse mouse)
        {
            this.doRepaint = true;

            if (this.effectsSystem.HasEffects())
            {
                return;
            }

            if (mouse.LeftPressed)
            {
                bool action_performed = false;
                if (this.currentInputMode == InputMode.SelectMapPoint)
                {
                    if (this.currentInputSubMode == InputSubMode.SelectingDestination)
                    {
                        var pos = (PositionComponent)this.currentUnit.GetComponent(nameof(PositionComponent));
                        var md  = (MovementDataComponent)this.currentUnit.GetComponent(nameof(MovementDataComponent));
                        md.route = Misc.GetLine(pos.x, pos.y, mouse.X, mouse.Y, true);
                        this.gameLog.Add("Destination selected");
                        this.currentInputMode = InputMode.Normal;
                    }
                    else if (this.currentInputSubMode == InputSubMode.ThrowingItem)
                    {
                        var throwingSystem = (ThrowingSystem)this.ecs.GetSystem(nameof(ThrowingSystem));
                        throwingSystem.ThrowItem(this.currentUnit, mouse.X, mouse.Y);
                        this.currentInputMode = InputMode.Normal;
                        action_performed      = true;
                    }
                    else if (this.currentInputSubMode == InputSubMode.SelectShotTarget)
                    {
                        ShootingSystem   ss     = (ShootingSystem)this.ecs.GetSystem(nameof(ShootingSystem));
                        MobDataComponent att    = (MobDataComponent)this.currentUnit.GetComponent(nameof(MobDataComponent));
                        AbstractEntity   target = ss.GetTargetAt(this.mapData.map[mouse.X, mouse.Y], mouse.X, mouse.Y, att.side);
                        var pos = (PositionComponent)this.currentUnit.GetComponent(nameof(PositionComponent));
                        ss.EntityShootingAtEntity(this.currentUnit, new Point(pos.x, pos.y), target, new Point(mouse.X, mouse.Y));
                    }
                }
                else if (this.currentInputMode == InputMode.Normal)
                {
                    // Have they clicked on an adjacent square
                    var pos = (PositionComponent)this.currentUnit.GetComponent(nameof(PositionComponent));
                    if (GeometryFunctions.Distance(mouse.X, mouse.Y, pos.x, pos.y) < 2)
                    {
                        this.MouseClicked(mouse.X, mouse.Y);
                    }
                }

                if (action_performed)
                {
                    this.SingleGameLoop();
                }
            }
            else
            {
                this.hoverText = this.GetSquareDesc(mouse.X, mouse.Y);

                if (this.currentInputMode == InputMode.SelectMapPoint)
                {
                    var pos = (PositionComponent)this.currentUnit.GetComponent(nameof(PositionComponent));
                    this.line = Misc.GetLine(pos.x, pos.y, mouse.X, mouse.Y, true);
                }
                else
                {
                    this.line = null;
                }
            }
        }