Exemple #1
0
        protected override void Update(GameTime gameTime)
        {
            if (Form.ActiveForm == parentForm)
            {
                if (CurrentMap != null)
                {
                    Viewport.Location = new Location(hscroll.Value, vscroll.Value);
                    Camera.Position   = new Vector2(hscroll.Value, vscroll.Value);
                    InputProvider.Update();
                    CurrentMap.Update(gameTime.ElapsedGameTime.Milliseconds);

                    MouseState ms = InputProvider.MouseState;
                    if ((ms.X > 0) && (ms.Y > 0) && (ms.X < Camera.ViewPortWidth) && (ms.Y < Camera.ViewPortHeight))
                    {
                        Vector2 mouseLoc = Camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
                        int     cellX    = (int)MathHelper.Clamp(TileMap.GetCellByPixelX((int)mouseLoc.X), 0, TileMap.MapWidth - 1);
                        int     cellY    = (int)MathHelper.Clamp(TileMap.GetCellByPixelY((int)mouseLoc.Y), 0, TileMap.MapHeight - 1);

                        if (Camera.WorldRectangle.Contains((int)mouseLoc.X, (int)mouseLoc.Y))
                        {
                            if (!RectangleMode)
                            {
                                if (ShortcutProvider.LeftButtonClicked())
                                {
                                    TileMap.GetMapSquareAtCell(cellX, cellY).Passable = Passable;
                                }
                                if (ShortcutProvider.RightButtonClicked())
                                {
                                    if (SetCode)
                                    {
                                        ((EditorForm)parentForm).SetCodeList(cellX, cellY);
                                    }
                                    else
                                    {
                                        ((EditorForm)parentForm).GetCodeList(TileMap.GetCellCodes(cellX, cellY));
                                    }
                                }
                            }
                            else
                            {
                                if (ShortcutProvider.LeftButtonClickedNowButNotLastFrame())
                                {
                                    if (!waitingForSecondClick)
                                    {
                                        startCell             = new Vector2(cellX, cellY);
                                        waitingForSecondClick = true;
                                    }
                                    else
                                    {
                                        Vector2 endCell = new Vector2(cellX, cellY);
                                        waitingForSecondClick = false;

                                        for (int cellx = (int)startCell.X; cellx <= endCell.X; ++cellx)
                                        {
                                            for (int celly = (int)startCell.Y; celly <= endCell.Y; ++celly)
                                            {
                                                TileMap.GetMapSquareAtCell(cellx, celly).Passable = Passable;
                                            }
                                        }
                                    }
                                }
                                else if (ShortcutProvider.RightButtonClickedButNotLastFrame())
                                {
                                    if (!waitingForSecondClick)
                                    {
                                        startCell             = new Vector2(cellX, cellY);
                                        waitingForSecondClick = true;
                                    }
                                    else
                                    {
                                        Vector2 endCell = new Vector2(cellX, cellY);
                                        waitingForSecondClick = false;

                                        for (int cellx = (int)startCell.X; cellx <= endCell.X; ++cellx)
                                        {
                                            for (int celly = (int)startCell.Y; celly <= endCell.Y; ++celly)
                                            {
                                                if (SetCode)
                                                {
                                                    ((EditorForm)parentForm).SetCodeList(cellx, celly);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            base.Update(gameTime);
        }