Пример #1
0
        public MapEditorPage()
        {
            for (int i = 0; i < 3; i++)
            {
                layers[i] = new EditorLayer();
            }
            ActiveLayer = layers[0];
            #region Buttons

            for (int i = 0; i < 3; i++)
            {
                buttons.Add(new SmallButton("Layer " + (i + 1)));
                buttons[i].Position = new Vector2(95 * i, 10);
            }
            buttons[0].selected  = true;
            TileSelector         = new TileSelection();
            colorButton          = new SmallButton("Color");
            colorButton.Position = new Vector2(Game1.WindowWidth / 2 - colorButton.Width / 2, Game1.WindowHeight - colorButton.Height - 10);
            buttons.Add(colorButton);

            tileSetBounds = new Rectangle(0, 0, 32 * EditorLayer.numberOfTiles, 32 * EditorLayer.numberOfTiles);
            #endregion

            #region Graphics

            tileset = new System.Drawing.Bitmap(path + "Content/terrain.png");
            Texture2D gridtexture = Game1.Content.Load <Texture2D>(path + "Content/grid");
            cameraspeed = 10;

            // Initialisation de la grille de base
            grid = new Texture2D[HauteurEnTiles, LargeurEnTiles];
            for (int i = 0; i < HauteurEnTiles; i++)
            {
                for (int j = 0; j < LargeurEnTiles; j++)
                {
                    grid[j, i] = gridtexture;
                }
            }

            InitializeTiles();
            tiles_by_closest_color_list = new Dictionary <System.Drawing.Color, List <int> >();
            InitializeMostClosestColorsList();

            #endregion
        }
Пример #2
0
        public override void Update()
        {
            ms = Mouse.GetState();

            #region updating buttons
            for (int i = 0; i < 3; i++)
            {
                Button button = buttons[i];
                if (button.leftClick() && !button.selected)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        Button button2 = buttons[j];
                        button2.selected = false;
                    }
                    button.selected = true;
                    ActiveLayer     = layers[i];
                }
            }

            #region affichage du colorpicker
            bool tab = Keyboard.GetState().IsKeyDown(Keys.Tab);

            if (colorButton.leftClick() || tab && oldState != tab)
            {
                if (!colorButton.selected)
                {
                    colorButton.selected = true;
                }
                else
                {
                    colorButton.selected = false;
                }

                oldState = tab;

                ColorPicker.IsActive = colorButton.selected;
            }

            if (!tab)
            {
                oldState = false;
            }
            #endregion

            #endregion

            #region Update keyboard
            KeyboardState kb = Keyboard.GetState();

            if (kb.IsKeyDown(Keys.Left))
            {
                camera.Position = new Vector2(camera.Position.X - cameraspeed, camera.Position.Y);
            }
            if (kb.IsKeyDown(Keys.Right))
            {
                camera.Position = new Vector2(camera.Position.X + cameraspeed, camera.Position.Y);
            }
            if (kb.IsKeyDown(Keys.Up))
            {
                camera.Position = new Vector2(camera.Position.X, camera.Position.Y - cameraspeed);
            }
            if (kb.IsKeyDown(Keys.Down))
            {
                camera.Position = new Vector2(camera.Position.X, camera.Position.Y + cameraspeed);
            }
            if (kb.IsKeyDown(Keys.P)) // DEBUG
            {
                foreach (var entry in tiles_by_closest_color_list)
                {
                    Console.WriteLine(entry.Key);
                }
            }
            #endregion

            if (ms.LeftButton == ButtonState.Pressed && !ColorPicker.IsActive && !TileSelection.sourceRectangle.Contains(ms.Position) && !colorButton.Bounds.Contains(ms.Position))
            {
                DrawTile();
            }
        }