Пример #1
0
        internal static BitmapImage GetUnitBitmap(UnitPivot unit)
        {
            var cacheKey = string.Concat(unit.Name.ToLowerInvariant(), "_", CIVILIZATION_COLORS[unit.Player.Civilization.Name]);

            if (_imagedSourcesCache.ContainsKey(cacheKey))
            {
                return(_imagedSourcesCache[cacheKey]);
            }

            var resourceStream =
                System.Reflection.Assembly
                .GetEntryAssembly()
                .GetManifestResourceStream(string.Format(UNIT_RESOURCE_FORMAT, unit.Name.ToLowerInvariant()));

            var scrBitmap = new System.Drawing.Bitmap(resourceStream);

            var newColor = System.Drawing.ColorTranslator.FromHtml(CIVILIZATION_COLORS[unit.Player.Civilization.Name]);

            var newBitmap = new System.Drawing.Bitmap(scrBitmap.Width, scrBitmap.Height);

            for (var i = 0; i < scrBitmap.Width; i++)
            {
                for (var j = 0; j < scrBitmap.Height; j++)
                {
                    var actualColor = scrBitmap.GetPixel(i, j);
                    if (actualColor.G == DEFAULT_PIXEL_COLOR_VALUE_G &&
                        actualColor.B == DEFAULT_PIXEL_COLOR_VALUE_B &&
                        actualColor.R == DEFAULT_PIXEL_COLOR_VALUE_R)
                    {
                        newBitmap.SetPixel(i, j, newColor);
                    }
                    else
                    {
                        newBitmap.SetPixel(i, j, actualColor);
                    }
                }
            }

            BitmapImage bitmapImage;

            using (var memory = new System.IO.MemoryStream())
            {
                newBitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
                memory.Position = 0;
                bitmapImage     = StreamToBitmapImage(memory);
            }

            _imagedSourcesCache.Add(cacheKey, bitmapImage);

            return(bitmapImage);
        }
Пример #2
0
        internal static void DrawUnit(this Panel panel, UnitPivot unit, double defaultDim, int zIndex, bool blinkAndZindex, bool cleanBefore)
        {
            if (panel == null)
            {
                return;
            }

            if (cleanBefore)
            {
                panel.CleanPreviousChildrenByTag(unit);
            }

            Image img = new Image
            {
                Width   = defaultDim,
                Height  = defaultDim,
                Source  = GetUnitBitmap(unit),
                Stretch = Stretch.Uniform
            };

            img.SetValue(Grid.RowProperty, unit.MapSquareLocation.Row);
            img.SetValue(Grid.ColumnProperty, unit.MapSquareLocation.Column);
            img.SetValue(Panel.ZIndexProperty, zIndex);
            img.Tag = unit;
            if (blinkAndZindex)
            {
                img.SetValue(Panel.ZIndexProperty, zIndex + 1);

                var blinkingAnimation = new DoubleAnimation
                {
                    From           = 1.0,
                    To             = 0.0,
                    RepeatBehavior = RepeatBehavior.Forever,
                    AutoReverse    = true,
                    Duration       = new Duration(TimeSpan.FromMilliseconds(500))
                };

                var blinkingStoryboard = new Storyboard();
                blinkingStoryboard.Children.Add(blinkingAnimation);
                Storyboard.SetTargetProperty(blinkingAnimation, new PropertyPath("(Image.Opacity)"));

                Storyboard.SetTarget(blinkingAnimation, img);
                blinkingStoryboard.Begin();
            }
            panel.Children.Add(img);
        }
Пример #3
0
 private void ButtonValidate_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(TextBoxCityName.Text))
     {
         UnitUsed = _engine.HumanPlayer.CurrentUnit; // important because "BuildCity()" changes the "CurrentUnit" value !
         City     = _engine.BuildCity(TextBoxCityName.Text.Trim(), out bool nonUniquenameError);
         if (nonUniquenameError)
         {
             MessageBox.Show("Please specify a unique city name.", "ErsatzCiv");
         }
         else
         {
             Close();
         }
     }
     else
     {
         MessageBox.Show("Please specify a non-empty city name.", "ErsatzCiv");
     }
 }
Пример #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="unit">The <see cref="Units"/> value, when a single unit is killed.</param>
 /// <param name="killer">The <see cref="Killer"/> value.</param>
 internal KilledUnitEventArgs(UnitPivot unit, PlayerPivot killer) : this(new[] { unit }, killer)
 {
 }