예제 #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (this.currentUI != null && this.currentUI.Visible)
            {
                if (KeyboardHelper.KeyPressed(Keys.Escape))
                {
                    this.ShowUI(null);
                }
            }
            else
            {
                // show UI
                if (KeyboardHelper.KeyPressed(Keys.Escape))
                {
                    this.ShowUI(this.mainMenu);
                }

                // debug mode
                if (KeyboardHelper.KeyPressed(Keys.F12))
                {
                    AbstractObject.DebugInfo = !AbstractObject.DebugInfo;
                }

                // pick layer
                var asTilePlacement = this.mode as TilePlacement;
                if (asTilePlacement != null)
                {
                    if (KeyboardHelper.KeyPressed(Keys.D1))
                    {
                        this.lastLayer = TileStencil.Layer.Background;
                    }
                    if (KeyboardHelper.KeyPressed(Keys.D2))
                    {
                        this.lastLayer = TileStencil.Layer.Foreground;
                    }
                    if (KeyboardHelper.KeyPressed(Keys.D3))
                    {
                        this.lastLayer = TileStencil.Layer.Blocking;
                    }
                    asTilePlacement.Layer = this.lastLayer;
                }

                // pan camera
                if (MouseHelper.ButtonDown(GameEngine.Helpers.MouseButton.Middle))
                {
                    var mousePos = this.MouseToWorld;
                    if (this.pan.HasValue)
                    {
                        this.Camera.Position = this.pan.Value - (mousePos - this.Camera.Position);
                    }
                    else
                    {
                        this.pan = mousePos;
                    }
                }
                else
                {
                    this.pan = null;
                }

                // zoom camera
                var scroll = MouseHelper.ScrollDirection;
                this.Camera.Zoom = MathHelper.Max(0.1f, this.Camera.Zoom + (float)(scroll * gameTime.ElapsedGameTime.TotalSeconds * 10));

                // tile placement
                if (this.mode != null)
                {
                    var mouse      = Mouse.GetState();
                    var mouseWorld = this.MouseToWorld;
                    var mouseTile  = this.Context.WorldToTile(mouseWorld);
                    var last       = this.lastPlacement;
                    if (mouse.LeftButton == ButtonState.Pressed && (!last.HasValue || last.Value.Location != mouseTile || last.Value.Button != GameEngine.Helpers.MouseButton.Left))
                    {
                        if (KeyboardHelper.KeyDown(Keys.F) && asTilePlacement != null)
                        {
                            PaintOperations.FloodFill(this.Context, mouseTile, asTilePlacement);
                        }
                        else
                        {
                            this.mode.Stamp(this.Context, mouseWorld);
                        }
                        this.lastPlacement = new Placement {
                            Location = mouseTile, Button = GameEngine.Helpers.MouseButton.Left
                        };
                    }
                    if (mouse.RightButton == ButtonState.Pressed && (!last.HasValue || last.Value.Location != mouseTile || last.Value.Button != GameEngine.Helpers.MouseButton.Right))
                    {
                        if (KeyboardHelper.KeyDown(Keys.LeftShift))
                        {
                            var menu = this.mode.ContextMenu(this.Context, mouseWorld);
                            if (menu != null)
                            {
                                UserInterface.Active.AddEntity(menu);
                                this.ShowUI(menu);
                                this.contextMenu = menu;
                            }
                        }
                        else
                        {
                            this.mode.Clear(this.Context, mouseWorld);
                            this.lastPlacement = new Placement {
                                Location = mouseTile, Button = GameEngine.Helpers.MouseButton.Right
                            };
                        }
                    }
                    if (!MouseHelper.ButtonDown(GameEngine.Helpers.MouseButton.Left) && !MouseHelper.ButtonDown(GameEngine.Helpers.MouseButton.Right))
                    {
                        this.lastPlacement = null;
                    }
                }
                else
                {
                    this.lastPlacement = null;
                }
            }
        }