Пример #1
0
 private void SyncWithoutBackup(Tile?tile, Sprite sprite, Point index)
 {
     if (tile == null)
     {
         SyncWithoutBackup(index);
         return;
     }
     tiles[index.X, index.Y] = tile;
     Ground.CastSprite(tile.Value, sprite);
     OnSpriteChanged(new SpriteChangedEventArgs(index, sprite));
 }
Пример #2
0
        private void Sync(Tile?tile, Sprite sprite, Point index, out Tile?prevTile, out Sprite prevSprite, out Point prevIndex)
        {
            prevSprite = sprite;
            prevTile   = tiles[index.X, index.Y];
            prevIndex  = index;
            if (tile == null)
            {
                Sync(index, out prevTile, out prevSprite, out prevIndex);
                return;
            }
            //prevSprite = sprite;
            //prevTile = tiles[index.X, index.Y];
            //prevIndex = index;

            tiles[index.X, index.Y] = tile;
            Ground.CastSprite(tile.Value, sprite);
            OnSpriteChanged(new SpriteChangedEventArgs(index, sprite));
        }
Пример #3
0
        protected override void KeyboardHandler(KeyboardState kbs, KeyboardState okbs)
        {
            if (kbs.IsKeyDown(Keys.Enter) && !okbs.IsKeyDown(Keys.Enter))
            {
                GC.Collect();
            }
            if (kbs.IsKeyDown(Keys.Left))
            {
                camera.MoveOn(new Vector2(-cameraSpeed, 0));
            }
            if (kbs.IsKeyDown(Keys.Right))
            {
                camera.MoveOn(new Vector2(cameraSpeed, 0));
            }
            if (kbs.IsKeyDown(Keys.Up))
            {
                camera.MoveOn(new Vector2(0, -cameraSpeed));
            }
            if (kbs.IsKeyDown(Keys.Down))
            {
                camera.MoveOn(new Vector2(0, cameraSpeed));
            }

            if (kbs.IsKeyDown(Keys.LeftControl))
            {
                ctrl = true;
            }
            if (kbs.IsKeyUp(Keys.LeftControl))
            {
                ctrl = false;
            }

            if (ctrl)
            {
                if (kbs.IsKeyDown(Keys.Z) && !okbs.IsKeyDown(Keys.Z))
                {
                    if (backups.Count != 0)
                    {
                        BackUp(backups.Pop());
                    }
                }
            }
            if (kbs.IsKeyDown(Keys.R) && !okbs.IsKeyDown(Keys.R))
            {
                RenderMinimap(ground.Sprites);
            }
            if (kbs.IsKeyDown(Keys.Space) && !okbs.IsKeyDown(Keys.Space))
            {
                Point index = FromPosToIndex(MousePosition(MS), World.TileW);
                panel.SetCurrentPrev(tiles[index.X, index.Y]);
            }

            #region Сохранение выбранного тайла в .png с добавлением оттенка. Путь = "Customs\*.png". (DEBUG only)

#if DEBUG       //ctrl + S
            if (ctrl)
            {
                if (kbs.IsKeyDown(Keys.S) && !okbs.IsKeyDown(Keys.S))
                {
                    if (CurrentTile != null && CurrentTile.HasValue)
                    {
                        Tile      ctile   = CurrentTile.Value;
                        Texture2D texture = new Texture2D(GraphicsDevice, World.TileW, World.TileW);
                        Color[]   data    = new Color[World.TileW * World.TileW];
                        Sprite    sprite  = new Sprite(Content);
                        Ground.CastSprite(ctile, sprite);
                        sprite.GetTexture().GetData <Color>(data);
                        Color tint     = ctile.Color;
                        long  fnameGen = 0;                        //Имя генерируется исходя из цвета текстуры
                        for (int i = 0; i < data.Length; i++)
                        {
                            data[i]   = new Color(data[i].R * tint.R / 255, data[i].G * tint.G / 255, data[i].B * tint.B / 255, data[i].A);
                            fnameGen += (long)data[i].R + (long)data[i].G + (long)data[i].B;
                        }
                        texture.SetData <Color>(data);
                        string dir   = @"Customs";
                        string fname = fnameGen.ToString() + ".png";
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        if (File.Exists(Path.Combine(dir, fname)))
                        {
                            throw new InvalidOperationException("Имя совпало");
                        }
                        using (FileStream fs = File.Create(Path.Combine(dir, fname))) {
                            texture.SaveAsPng(fs, World.TileW, World.TileW);
                        }
                    }
                }
            }
#endif

            #endregion
        }