Пример #1
0
        public static void DrawImage(this CellSurface surface, int x, int y, SymbolsImage image, Color defaultForeColor, Color defaultBackColor)
        {
            for (int posY = 0; posY < image.Height; posY++)
            {
                for (int posX = 0; posX < image.Width; posX++)
                {
                    var pixel     = image[posX, posY];
                    var backColor = pixel.BackgroundColor?.ToXna() ?? defaultBackColor;

                    var printX = x + posX;
                    var printY = y + posY;

                    if (pixel.Symbol.HasValue)
                    {
                        var foreColor = pixel.Color?.ToXna() ?? defaultForeColor;
                        surface.Print(printX, printY,
                                      new ColoredGlyph(pixel.Symbol.Value, foreColor, backColor));
                    }
                    else
                    {
                        surface.Print(printX, printY, new ColoredGlyph(' ', defaultForeColor, backColor));
                    }
                }
            }
        }
Пример #2
0
 private SymbolsImage LoadImage(string filePath)
 {
     using (var fileStream = File.OpenRead(filePath))
     {
         return(SymbolsImage.LoadFromFile(fileStream));
     }
 }
Пример #3
0
        public SymbolsImage GetWorldImage(IImagesStorage storage)
        {
            var templateImage = storage.GetImage("ItemsOnGround_Potion");
            var palette       = GetPotionPalette();

            return(SymbolsImage.Recolor(templateImage, palette));
        }
Пример #4
0
        public SymbolsImage LoadFromFile(Stream fileStream)
        {
            var serializer = new XmlSerializer(typeof(XmlImageType));
            var data       = serializer.Deserialize(fileStream) as XmlImageType;

            if (data == null)
            {
                throw new SerializationException("Unable to read image.");
            }

            var image = new SymbolsImage(data.Width, data.Height);

            for (var y = 0; y < data.Height; y++)
            {
                for (var x = 0; x < data.Width; x++)
                {
                    var pixel     = image[x, y];
                    var dataPixel = data.Rows[y].Pixels[x];

                    pixel.Symbol          = dataPixel.Glyph;
                    pixel.Color           = dataPixel.Color?.GetColor();
                    pixel.BackgroundColor = dataPixel.BackgroundColor?.GetColor();
                }
            }

            return(image);
        }
Пример #5
0
        public override SymbolsImage GetEffectImage(int width, int height, IImagesStorage imagesStorage)
        {
            var color      = TextHelper.GetElementColor(element);
            var damageText = value.ToString();

            var xShift = (int)Math.Floor((width - damageText.Length) / 2d);

            if (damageText.Length > width)
            {
                damageText = "XXX";
            }

            var yShift          = (int)Math.Floor(height / 2d);
            var damageTextImage = new SymbolsImage(width, height);

            for (int shift = 0; shift < damageText.Length; shift++)
            {
                var x = xShift + shift;
                if (x >= damageTextImage.Width)
                {
                    break;
                }

                damageTextImage.SetPixel(x, yShift, damageText[shift], color);
            }

            return(damageTextImage);
        }
Пример #6
0
        public static SymbolsImage RecolorSpellBookImage(SymbolsImage sourceImage, out Color mainColor)
        {
            var palette = RandomHelper.GetRandomElement(SpellBookColors);

            mainColor = palette.Color1;
            return(RecolorImage(sourceImage, palette));
        }
Пример #7
0
 protected HoldableDurableItemBase(SaveData data) : base(data)
 {
     inventoryImage     = data.GetObject <SymbolsImageSaveable>(SaveKeyInventoryImage)?.GetImage();
     worldImage         = data.GetObject <SymbolsImageSaveable>(SaveKeyWorldImage)?.GetImage();
     equippedImageRight = data.GetObject <SymbolsImageSaveable>(SaveKeyEquippedImageRight)?.GetImage();
     equippedImageLeft  = data.GetObject <SymbolsImageSaveable>(SaveKeyEquippedImageLeft)?.GetImage();
 }
Пример #8
0
 public static SymbolsImage RecolorImage(SymbolsImage sourceImage, Color mainColor)
 {
     return(SymbolsImage.Recolor(sourceImage, new Dictionary <Color, Color>
     {
         { ReplaceColor1, mainColor }
     }));
 }
Пример #9
0
        public SymbolsImage ApplyLightLevel(SymbolsImage image, LightLevel lightData)
        {
            var result = new SymbolsImage(image.Width, image.Height);

            for (int x = 0; x < image.Width; x++)
            {
                for (int y = 0; y < image.Height; y++)
                {
                    var originalCell = image[x, y];
                    var cell         = result[x, y];

                    cell.Symbol = originalCell.Symbol;

                    if (originalCell.Color.HasValue)
                    {
                        cell.Color = ApplyLightLevel(originalCell.Color.Value, lightData);
                    }

                    if (originalCell.BackgroundColor.HasValue)
                    {
                        cell.BackgroundColor = ApplyLightLevel(originalCell.BackgroundColor.Value, lightData);
                    }
                }
            }

            return(result);
        }
Пример #10
0
        private SymbolsImage GenerateImage(out Color mainColor)
        {
            var baseImageInit   = imagesStorage.GetImage(configuration.Template);
            var symbolImageInit = imagesStorage.GetImage(RandomHelper.GetRandomElement(configuration.SymbolImages));
            var imageInit       = SymbolsImage.Combine(baseImageInit, symbolImageInit);

            return(ItemRecolorHelper.RecolorSpellBookImage(imageInit, out mainColor));
        }
Пример #11
0
        public SymbolsImage GetWorldImage(IImagesStorage storage)
        {
            var body = storage.GetImage(configuration.Image);
            var directionImageName = GetWorldImageName();
            var directionImage     = storage.GetImage(directionImageName);

            return(SymbolsImage.Combine(body, directionImage));
        }
Пример #12
0
 protected HoldableDurableItemBase(HoldableItemConfiguration configuration)
     : base(configuration)
 {
     worldImage         = configuration.WorldImage;
     inventoryImage     = configuration.InventoryImage;
     equippedImageRight = configuration.EquippedImageRight;
     equippedImageLeft  = configuration.EquippedImageLeft;
 }
Пример #13
0
        public SymbolsImage GetInventoryImage(IImagesStorage storage)
        {
            var imageTemplateName = GetInventoryImageTemplateName();
            var templateImage     = storage.GetImage(imageTemplateName);
            var palette           = GetPotionPalette();

            return(SymbolsImage.Recolor(templateImage, palette));
        }
Пример #14
0
 public SpellBook(SpellBookConfiguration configuration)
     : base(configuration)
 {
     BookSize       = configuration.Size;
     Spells         = new BookSpell[BookSize];
     inventoryImage = configuration.InventoryImage;
     worldImage     = configuration.WorldImage;
 }
Пример #15
0
 public FoodItem(SaveData data)
     : base(data)
 {
     hungerDecrease = data.GetIntValue(SaveKeyHungerDecrease);
     description    = data.GetValuesCollection(SaveKeyDescription);
     inventoryImage = data.GetObject <SymbolsImageSaveable>(SaveKeyInventoryImage).GetImage();
     worldImage     = data.GetObject <SymbolsImageSaveable>(SaveKeyWorldImage).GetImage();
 }
Пример #16
0
 public FoodItem(FoodItemConfiguration configuration)
     : base(configuration)
 {
     hungerDecrease = configuration.HungerDecrease;
     description    = configuration.Description;
     inventoryImage = configuration.InventoryImage;
     worldImage     = configuration.WorldImage;
 }
Пример #17
0
        private SymbolsImage RecolorImage(SymbolsImage image)
        {
            var palette = new Dictionary <Color, Color>
            {
                { Color.FromArgb(255, 0, 0), Color.MediumVioletRed }
            };

            return(SymbolsImage.Recolor(image, palette));
        }
Пример #18
0
        public ArmorItem(ArmorItemConfiguration configuration)
            : base(configuration)
        {
            protection = configuration.Protection.ToDictionary(pair => pair.Key, pair => pair.Value);
            ArmorType  = configuration.ArmorType;

            inventoryImage = configuration.InventoryImage;
            worldImage     = configuration.WorldImage;
            equippedImage  = configuration.EquippedImage;
        }
Пример #19
0
        public ArmorItem(SaveData data) : base(data)
        {
            inventoryImage = data.GetObject <SymbolsImageSaveable>(SaveKeyInventoryImage)?.GetImage();
            worldImage     = data.GetObject <SymbolsImageSaveable>(SaveKeyWorldImage)?.GetImage();
            equippedImage  = data.GetObject <SymbolsImageSaveable>(SaveKeyEquippedImage)?.GetImage();

            protection = data.GetObject <DictionarySaveable>(SaveKeyProtection).Data.ToDictionary(pair =>
                                                                                                  (Element)int.Parse((string)pair.Key), pair => int.Parse((string)pair.Value));
            ArmorType = (ArmorType)data.GetIntValue(SaveKeyArmorType);
        }
Пример #20
0
        private static SymbolsImage RecolorImage(SymbolsImage sourceImage, ColorPalette palette)
        {
            var recolorPalette = new Dictionary <Color, Color>
            {
                { ReplaceColor1, palette.Color1 },
                { ReplaceColor2, palette.Color2 },
                { ReplaceColor3, palette.Color3 }
            };

            return(SymbolsImage.Recolor(sourceImage, recolorPalette));
        }
Пример #21
0
        private SymbolsImage GetDamagedIcon(DurableItem item)
        {
            var damageColor = TextHelper.GetDurabilityColor(item.Durability, item.MaxDurability);
            var iconName    = GetDamagedIconName(item);
            var image       = ImagesStorage.Current.GetImage(iconName);

            return(SymbolsImage.Recolor(image, new Dictionary <System.Drawing.Color, System.Drawing.Color> {
                {
                    System.Drawing.Color.FromArgb(255, 0, 0),
                    damageColor
                }
            }));
        }
Пример #22
0
        private SymbolsImage MergeImages(params SymbolsImage[] images)
        {
            if (images.Length == 0)
                throw new ArgumentException("No images to merge.");

            var result = images[0];
            for (int index = 1; index < images.Length; index++)
            {
                result = SymbolsImage.Combine(result, images[index]);
            }

            return result;
        }
Пример #23
0
        private void DrawDamagedIcons()
        {
            var image = new SymbolsImage(3, 7);

            var images = game.Player.Equipment.GetEquippedItems().OfType <DurableItem>().Where(ItemDamaged)
                         .Select(GetDamagedIcon);

            foreach (var damagedImage in images)
            {
                image = SymbolsImage.Combine(image, damagedImage);
            }

            Surface.DrawImage(Width - 4, Height - 8, image, DefaultForegroundColor, DefaultBackgroundColor);
        }
Пример #24
0
        public SpellBook(SaveData data) : base(data)
        {
            BookSize = data.GetIntValue(SaveKeySize);
            var spellsRaw = data.GetObjectsCollection <BookSpell>(SaveKeySpells);

            Spells = new BookSpell[BookSize];
            for (int index = 0; index < spellsRaw.Length; index++)
            {
                Spells[index] = spellsRaw[index];
            }

            inventoryImage = data.GetObject <SymbolsImageSaveable>(SaveKeyInventoryImage).GetImage();
            worldImage     = data.GetObject <SymbolsImageSaveable>(SaveKeyWorldImage).GetImage();
        }
Пример #25
0
        private void loadImageButton_Click(object sender, EventArgs args)
        {
            openDialog.ShowModal(result =>
            {
                if (result == DialogResult.Ok)
                {
                    using (var fileStream = File.OpenRead(openDialog.Path))
                    {
                        image = SymbolsImage.LoadFromFile(fileStream);
                    }

                    InitializeImageControl();
                }
            });
        }
Пример #26
0
        public SymbolsImageSaveable(SymbolsImage image)
        {
            width  = image.Width;
            height = image.Height;

            var pixelsArray = new object[height][];

            for (int y = 0; y < height; y++)
            {
                pixelsArray[y] = new object[width];
                for (int x = 0; x < width; x++)
                {
                    pixelsArray[y][x] = new PixelSaveable(image[x, y]);
                }
            }
            pixels = new GridSaveable(pixelsArray);
        }
Пример #27
0
        public SymbolsImage GetImage()
        {
            var result = new SymbolsImage(width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var pixel = (PixelSaveable)pixels.Rows[y][x];
                    result[x, y].Symbol          = pixel.Symbol;
                    result[x, y].Color           = pixel.Color;
                    result[x, y].BackgroundColor = pixel.BackColor;
                }
            }

            return(result);
        }
Пример #28
0
        public EditorWindow()
            : base(new NullLog(), Program.Width, Program.Height, Program.Font)
        {
            newImageWidth  = DefaultImageWidth;
            newImageHeight = DefaultImageHeight;

            IsFocused   = true;
            UseKeyboard = true;
            brush       = new Brush();
            image       = new SymbolsImage(DefaultImageWidth, DefaultImageHeight);

            DefaultBackground = Color.Black;
            DefaultForeground = Color.White;

            openDialog = new OpenImageDialog();

            InitializeControls();
        }
Пример #29
0
        private static SymbolsImage ApplyObjectEffects(IAreaMapCell cell, SymbolsImage image)
        {
            var bigObject = cell.Objects.OfType <IDestroyableObject>().FirstOrDefault(obj => obj.BlocksMovement);

            if (bigObject == null || !bigObject.ObjectEffects.Any())
            {
                return(image);
            }

            var latestEffect = bigObject.ObjectEffects
                               .OfType <ObjectEffect>()
                               .Where(rec => rec.CreatedAt + DamageMarksLifeTime > DateTime.Now)
                               .OrderByDescending(obj => obj.CreatedAt)
                               .FirstOrDefault();

            if (latestEffect == null)
            {
                return(image);
            }

            var effectImage = latestEffect.GetEffectImage(image.Width, image.Height, ImagesStorage.Current);

            return(SymbolsImage.Combine(image, effectImage));
        }
Пример #30
0
 private void newImageButton_Click(object sender, EventArgs e)
 {
     image = new SymbolsImage(newImageWidth, newImageHeight);
     InitializeImageControl();
 }