Exemplo n.º 1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Brush      brush1 = (Brush)null;
            ColorModel source = value as ColorModel;

            if (source != null)
            {
                ColorModel model = new ColorModel(source);
                model.ScA = 1f;
                this.UpdateModelForGradientMin(model);
                GradientStop gradientStop1 = new GradientStop(model.Color, 0.0);
                gradientStop1.Freeze();
                this.UpdateModelForGradientMax(model);
                GradientStop gradientStop2 = new GradientStop(model.Color, 1.0);
                gradientStop2.Freeze();
                GradientStopCollection gradientStopCollection = new GradientStopCollection(2);
                gradientStopCollection.Add(gradientStop1);
                gradientStopCollection.Add(gradientStop2);
                gradientStopCollection.Freeze();
                LinearGradientBrush linearGradientBrush = new LinearGradientBrush();
                linearGradientBrush.StartPoint    = new Point(0.0, 0.0);
                linearGradientBrush.EndPoint      = new Point(1.0, 0.0);
                linearGradientBrush.GradientStops = gradientStopCollection;
                linearGradientBrush.Freeze();
                brush1 = (Brush)linearGradientBrush;
                Brush brush2 = parameter as Brush;
                if (brush2 != null)
                {
                    brush2.Freeze();
                    RectangleGeometry rectangleGeometry = new RectangleGeometry(new Rect(0.0, 0.0, 100.0, 10.0));
                    rectangleGeometry.Freeze();
                    GeometryDrawing geometryDrawing1 = new GeometryDrawing(brush2, (Pen)null, (Geometry)rectangleGeometry);
                    brush2.Freeze();
                    GeometryDrawing geometryDrawing2 = new GeometryDrawing(brush1, (Pen)null, (Geometry)rectangleGeometry);
                    geometryDrawing2.Freeze();
                    DrawingGroup drawingGroup = new DrawingGroup();
                    drawingGroup.Children.Add((Drawing)geometryDrawing1);
                    drawingGroup.Children.Add((Drawing)geometryDrawing2);
                    drawingGroup.Freeze();
                    DrawingBrush drawingBrush = new DrawingBrush((Drawing)drawingGroup);
                    drawingBrush.Freeze();
                    brush1 = (Brush)drawingBrush;
                }
            }
            return((object)brush1);
        }
Exemplo n.º 2
0
        private Brush CreateBrush(double centerX, double centerY, double radiusX, double radiusY)
        {
            if (!base.Antialiased)
            {
                return(SolidColorBrushCache.Get((ColorRgba128Float)Colors.White));
            }
            GradientStopCollection gradientStopCollection = new GradientStopCollection(0x20);

            for (int i = 0; i < 0x20; i++)
            {
                double num2;
                switch (i)
                {
                case 0:
                    num2 = 0.0;
                    break;

                case 0x1f:
                    num2 = 1.0;
                    break;

                default:
                    num2 = ((double)i) / 31.0;
                    break;
                }
                double       gradientStopAlpha = this.GetGradientStopAlpha(num2);
                GradientStop item = new GradientStop(new ColorRgba128Float((ColorRgba128Float)Colors.White, (float)gradientStopAlpha), num2);
                gradientStopCollection.Add(item);
            }
            gradientStopCollection.Freeze();
            RadialGradientBrush brush = new RadialGradientBrush(gradientStopCollection)
            {
                ColorInterpolationMode = ColorInterpolationMode.ScRgbLinearInterpolation,
                GradientOrigin         = PointDouble.Zero,
                RadiusX = radiusX,
                RadiusY = radiusY,
                Center  = new PointDouble(centerX, centerY)
            };

            brush.Freeze();
            return(brush);
        }
Exemplo n.º 3
0
        private static GradientStopCollection CreateStops(System.Windows.Media.Color c, double cornerRadius)
        {
            double num = 1.0 / (cornerRadius + 5.0);
            GradientStopCollection stops = new GradientStopCollection {
                new GradientStop(c, (0.5 + cornerRadius) * num)
            };

            System.Windows.Media.Color color = c;
            color.A = (byte)(0.74336 * c.A);
            stops.Add(new GradientStop(color, (1.5 + cornerRadius) * num));
            color.A = (byte)(0.38053 * c.A);
            stops.Add(new GradientStop(color, (2.5 + cornerRadius) * num));
            color.A = (byte)(0.12389 * c.A);
            stops.Add(new GradientStop(color, (3.5 + cornerRadius) * num));
            color.A = (byte)(0.02654 * c.A);
            stops.Add(new GradientStop(color, (4.5 + cornerRadius) * num));
            color.A = 0;
            stops.Add(new GradientStop(color, (5.0 + cornerRadius) * num));
            stops.Freeze();
            return(stops);
        }
        private static GradientStopCollection CreateStops(Color c, double cornerRadius)
        {
            double num = 1.0 / (cornerRadius + 5.0);
            GradientStopCollection gradientStopCollection = new GradientStopCollection();

            gradientStopCollection.Add(new GradientStop(c, (0.5 + cornerRadius) * num));
            Color color = c;

            color.A = (byte)(0.74336 * (double)c.A);
            gradientStopCollection.Add(new GradientStop(color, (1.5 + cornerRadius) * num));
            color.A = (byte)(0.38053 * (double)c.A);
            gradientStopCollection.Add(new GradientStop(color, (2.5 + cornerRadius) * num));
            color.A = (byte)(0.12389 * (double)c.A);
            gradientStopCollection.Add(new GradientStop(color, (3.5 + cornerRadius) * num));
            color.A = (byte)(0.02654 * (double)c.A);
            gradientStopCollection.Add(new GradientStop(color, (4.5 + cornerRadius) * num));
            color.A = (byte)0;
            gradientStopCollection.Add(new GradientStop(color, (5.0 + cornerRadius) * num));
            gradientStopCollection.Freeze();
            return(gradientStopCollection);
        }
Exemplo n.º 5
0
        // *** Private static methods ***
        private static void CreateBrushes()
        {
            // Get the colors for the shadow
            Color shadowColor      = Color.FromArgb(128, 0, 0, 0);
            Color transparentColor = Color.FromArgb(16, 0, 0, 0);
            // Create a GradientStopCollection from these
            GradientStopCollection gradient = new GradientStopCollection(2);

            gradient.Add(new GradientStop(shadowColor, 0.5));
            gradient.Add(new GradientStop(transparentColor, 1.0));
            gradient.Freeze();
            // Create the background brush
            backgroundBrush = new SolidColorBrush(shadowColor);
            backgroundBrush.Freeze();
            // Create the LinearGradientBrushes
            rightBrush  = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(1.0, 0.0)); rightBrush.Freeze();
            bottomBrush = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(0.0, 1.0)); bottomBrush.Freeze();
            // Create the RadialGradientBrushes
            bottomRightBrush = new RadialGradientBrush(gradient);
            bottomRightBrush.GradientOrigin = new Point(0.0, 0.0);
            bottomRightBrush.Center         = new Point(0.0, 0.0);
            bottomRightBrush.RadiusX        = 1.0;
            bottomRightBrush.RadiusY        = 1.0;
            bottomRightBrush.Freeze();

            topRightBrush = new RadialGradientBrush(gradient);
            topRightBrush.GradientOrigin = new Point(0.0, 1.0);
            topRightBrush.Center         = new Point(0.0, 1.0);
            topRightBrush.RadiusX        = 1.0;
            topRightBrush.RadiusY        = 1.0;
            topRightBrush.Freeze();

            bottomLeftBrush = new RadialGradientBrush(gradient);
            bottomLeftBrush.GradientOrigin = new Point(1.0, 0.0);
            bottomLeftBrush.Center         = new Point(1.0, 0.0);
            bottomLeftBrush.RadiusX        = 1.0;
            bottomLeftBrush.RadiusY        = 1.0;
            bottomLeftBrush.Freeze();
        }
Exemplo n.º 6
0
        static HangarViewModel()
        {
            DefaultRegularArmorSpectrumStops = new GradientStopCollection
            {
                new GradientStop(Color.FromArgb(0xff, 0xc0, 0, 0), 0.0),
                new GradientStop(Color.FromArgb(0xff, 0xc0, 0x30, 0), 0.33),
                new GradientStop(Color.FromArgb(0xff, 0xc0, 0xc0, 0), 0.67),
                new GradientStop(Color.FromArgb(0xff, 0, 0xc0, 0), 1.0),
            };

            DefaultRegularArmorSpectrumStops.Freeze();

            DefaultSpacingArmorSpectrumStops = new GradientStopCollection
            {
                new GradientStop(Color.FromArgb(0xff, 0xc0, 0, 0xc0), 0.0),
                new GradientStop(Color.FromArgb(0xff, 0x30, 0, 0xc0), 0.33),
                new GradientStop(Color.FromArgb(0xff, 0, 0, 0xc0), 0.67),
                new GradientStop(Color.FromArgb(0xff, 0, 0xc0, 0xc0), 1.0),
            };

            DefaultSpacingArmorSpectrumStops.Freeze();
        }
Exemplo n.º 7
0
        // *** Private static methods ***
        private static void CreateBrushes()
        {
            // Get the colors for the shadow
            Color shadowColor = Color.FromArgb(128, 0, 0, 0);
            Color transparentColor = Color.FromArgb(16, 0, 0, 0);
            // Create a GradientStopCollection from these
            GradientStopCollection gradient = new GradientStopCollection(2);
            gradient.Add(new GradientStop(shadowColor, 0.5));
            gradient.Add(new GradientStop(transparentColor, 1.0));
            gradient.Freeze();
            // Create the background brush
            backgroundBrush = new SolidColorBrush(shadowColor);
            backgroundBrush.Freeze();
            // Create the LinearGradientBrushes
            rightBrush = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(1.0, 0.0)); rightBrush.Freeze();
            bottomBrush = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(0.0, 1.0)); bottomBrush.Freeze();
            // Create the RadialGradientBrushes
            bottomRightBrush = new RadialGradientBrush(gradient);
            bottomRightBrush.GradientOrigin = new Point(0.0, 0.0);
            bottomRightBrush.Center = new Point(0.0, 0.0);
            bottomRightBrush.RadiusX = 1.0;
            bottomRightBrush.RadiusY = 1.0;
            bottomRightBrush.Freeze();

            topRightBrush = new RadialGradientBrush(gradient);
            topRightBrush.GradientOrigin = new Point(0.0, 1.0);
            topRightBrush.Center = new Point(0.0, 1.0);
            topRightBrush.RadiusX = 1.0;
            topRightBrush.RadiusY = 1.0;
            topRightBrush.Freeze();

            bottomLeftBrush = new RadialGradientBrush(gradient);
            bottomLeftBrush.GradientOrigin = new Point(1.0, 0.0);
            bottomLeftBrush.Center = new Point(1.0, 0.0);
            bottomLeftBrush.RadiusX = 1.0;
            bottomLeftBrush.RadiusY = 1.0;
            bottomLeftBrush.Freeze();
        }
Exemplo n.º 8
0
        static GradientStopCollection CreateStops(Color c)
        {
            GradientStopCollection stops = new GradientStopCollection();
            Color stopColor = c;

            stopColor.A = (byte)(.45 * c.A);
            stops.Add(new GradientStop(stopColor, 0));

            stopColor.A = (byte)(.40 * c.A);
            stops.Add(new GradientStop(stopColor, .2));

            stopColor.A = (byte)(.25 * c.A);
            stops.Add(new GradientStop(stopColor, .45));

            stopColor.A = (byte)(.10 * c.A);
            stops.Add(new GradientStop(stopColor, .7));

            stopColor.A = (byte)(.05 * c.A);
            stops.Add(new GradientStop(stopColor, .85));

            stopColor.A = 0;
            stops.Add(new GradientStop(stopColor, 1));

            stops.Freeze();

            return stops;
        }
Exemplo n.º 9
0
        // Create common gradient stop collection for gradient brushes
        private static GradientStopCollection CreateStops(Color c, double cornerRadius)
        {
            // Scale stops to lie within 0 and 1
            double gradientScale = 1 / (cornerRadius + ShadowDepth);

            GradientStopCollection gsc = new GradientStopCollection();
            gsc.Add(new GradientStop(c, (0.5 + cornerRadius) * gradientScale));

            // Create gradient stops based on the Win32 dropshadow fall off
            Color stopColor = c;
            stopColor.A = (byte)(.74336 * c.A);
            gsc.Add(new GradientStop(stopColor, (1.5 + cornerRadius) * gradientScale));

            stopColor.A = (byte)(.38053 * c.A);
            gsc.Add(new GradientStop(stopColor, (2.5 + cornerRadius)* gradientScale));

            stopColor.A = (byte)(.12389 * c.A);
            gsc.Add(new GradientStop(stopColor, (3.5 + cornerRadius) * gradientScale));

            stopColor.A = (byte)(.02654 * c.A);
            gsc.Add(new GradientStop(stopColor, (4.5 + cornerRadius) * gradientScale));

            stopColor.A = 0;
            gsc.Add(new GradientStop(stopColor, (5 + cornerRadius) * gradientScale));

            gsc.Freeze();

            return gsc;
        }
Exemplo n.º 10
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            double distance   = Math.Max(0, ShadowDepth);
            double blurRadius = Math.Max(BlurRadius, 0);
            double angle      = Direction + 45; // Make it behave the same as DropShadowEffect

            Rect shadowBounds = new Rect(new Point(0, 0),
                                         new Size(RenderSize.Width, RenderSize.Height));

            shadowBounds.Inflate(blurRadius, blurRadius);

            Color color = Color;

            // Transform angle for "Direction"
            double angleRad = angle * Math.PI / 180.0;
            double xDispl   = distance;
            double yDispl   = distance;
            double newX     = xDispl * Math.Cos(angleRad) - yDispl * Math.Sin(angleRad);
            double newY     = yDispl * Math.Cos(angleRad) + xDispl * Math.Sin(angleRad);

            TranslateTransform translate = new TranslateTransform(newX, newY);
            Rect transformed             = translate.TransformBounds(shadowBounds);

            // Hint: you can make the blur radius consume more "centre"
            //       region of the bounding box by doubling this here
            // blurRadius = blurRadius * 2;

            // Build a set of rectangles for the shadow box
            Rect[] edges = new Rect[] {
                new Rect(new Point(transformed.X, transformed.Y), new Size(blurRadius, blurRadius)),                                                                                                          // TL
                new Rect(new Point(transformed.X + blurRadius, transformed.Y), new Size(Math.Max(transformed.Width - (blurRadius * 2), 0), blurRadius)),                                                      // T
                new Rect(new Point(transformed.Right - blurRadius, transformed.Y), new Size(blurRadius, blurRadius)),                                                                                         // TR
                new Rect(new Point(transformed.Right - blurRadius, transformed.Y + blurRadius), new Size(blurRadius, Math.Max(transformed.Height - (blurRadius * 2), 0))),                                    // R
                new Rect(new Point(transformed.Right - blurRadius, transformed.Bottom - blurRadius), new Size(blurRadius, blurRadius)),                                                                       // BR
                new Rect(new Point(transformed.X + blurRadius, transformed.Bottom - blurRadius), new Size(Math.Max(transformed.Width - (blurRadius * 2), 0), blurRadius)),                                    // B
                new Rect(new Point(transformed.X, transformed.Bottom - blurRadius), new Size(blurRadius, blurRadius)),                                                                                        // BL
                new Rect(new Point(transformed.X, transformed.Y + blurRadius), new Size(blurRadius, Math.Max(transformed.Height - (blurRadius * 2), 0))),                                                     // L
                new Rect(new Point(transformed.X + blurRadius, transformed.Y + blurRadius), new Size(Math.Max(transformed.Width - (blurRadius * 2), 0), Math.Max(transformed.Height - (blurRadius * 2), 0))), // C
            };

            // Gradient stops look a lot prettier than
            // a perfectly linear gradient..
            GradientStopCollection gsc = new GradientStopCollection();
            Color stopColor            = color;

            stopColor.A = (byte)(color.A);
            gsc.Add(new GradientStop(color, 0.0));
            stopColor.A = (byte)(.74336 * color.A);
            gsc.Add(new GradientStop(stopColor, 0.1));
            stopColor.A = (byte)(.38053 * color.A);
            gsc.Add(new GradientStop(stopColor, 0.3));
            stopColor.A = (byte)(.12389 * color.A);
            gsc.Add(new GradientStop(stopColor, 0.5));
            stopColor.A = (byte)(.02654 * color.A);
            gsc.Add(new GradientStop(stopColor, 0.7));
            stopColor.A = (byte)(0);
            gsc.Add(new GradientStop(stopColor, 0.9));

            gsc.Freeze();

            Brush[] colors = new Brush[] {
                // TL
                new RadialGradientBrush(gsc)
                {
                    Center = new Point(1, 1), GradientOrigin = new Point(1, 1), RadiusX = 1, RadiusY = 1
                },
                // T
                new LinearGradientBrush(gsc, 0)
                {
                    StartPoint = new Point(0, 1), EndPoint = new Point(0, 0)
                },
                // TR
                new RadialGradientBrush(gsc)
                {
                    Center = new Point(0, 1), GradientOrigin = new Point(0, 1), RadiusX = 1, RadiusY = 1
                },
                // R
                new LinearGradientBrush(gsc, 0)
                {
                    StartPoint = new Point(0, 0), EndPoint = new Point(1, 0)
                },
                // BR
                new RadialGradientBrush(gsc)
                {
                    Center = new Point(0, 0), GradientOrigin = new Point(0, 0), RadiusX = 1, RadiusY = 1
                },
                // B
                new LinearGradientBrush(gsc, 0)
                {
                    StartPoint = new Point(0, 0), EndPoint = new Point(0, 1)
                },
                // BL
                new RadialGradientBrush(gsc)
                {
                    Center = new Point(1, 0), GradientOrigin = new Point(1, 0), RadiusX = 1, RadiusY = 1
                },
                // L
                new LinearGradientBrush(gsc, 0)
                {
                    StartPoint = new Point(1, 0), EndPoint = new Point(0, 0)
                },
                // C
                new SolidColorBrush(color),
            };

            // This is a test pattern, uncomment to see how I'm drawing this
            //Brush[] colors = new Brush[]{
            //    Brushes.Red,
            //    Brushes.Green,
            //    Brushes.Blue,
            //    Brushes.Fuchsia,
            //    Brushes.Gainsboro,
            //    Brushes.LimeGreen,
            //    Brushes.Navy,
            //    Brushes.Orange,
            //    Brushes.White,
            //};
            double[] guidelineSetX = new double[] { transformed.X,
                                                    transformed.X + blurRadius,
                                                    transformed.Right - blurRadius,
                                                    transformed.Right };

            double[] guidelineSetY = new double[] { transformed.Y,
                                                    transformed.Y + blurRadius,
                                                    transformed.Bottom - blurRadius,
                                                    transformed.Bottom };

            drawingContext.PushGuidelineSet(new GuidelineSet(guidelineSetX, guidelineSetY));
            for (int i = 0; i < edges.Length; i++)
            {
                drawingContext.DrawRoundedRectangle(colors[i], null, edges[i], 0.0, 0.0);
            }
            drawingContext.Pop();
        }
Exemplo n.º 11
0
 private static GradientStopCollection CreateStops(System.Windows.Media.Color c, double cornerRadius)
 {
     double num = 1.0 / (cornerRadius + 5.0);
     GradientStopCollection stops = new GradientStopCollection {
         new GradientStop(c, (0.5 + cornerRadius) * num)
     };
     System.Windows.Media.Color color = c;
     color.A = (byte)(0.74336 * c.A);
     stops.Add(new GradientStop(color, (1.5 + cornerRadius) * num));
     color.A = (byte)(0.38053 * c.A);
     stops.Add(new GradientStop(color, (2.5 + cornerRadius) * num));
     color.A = (byte)(0.12389 * c.A);
     stops.Add(new GradientStop(color, (3.5 + cornerRadius) * num));
     color.A = (byte)(0.02654 * c.A);
     stops.Add(new GradientStop(color, (4.5 + cornerRadius) * num));
     color.A = 0;
     stops.Add(new GradientStop(color, (5.0 + cornerRadius) * num));
     stops.Freeze();
     return stops;
 }
Exemplo n.º 12
0
		private void AcceptGame()
		{
			game.AcceptCards();

			game.GameEndedEvent += new DominionBase.Game.GameEndedEventHandler(game_GameEndedEvent);

			wMain.Settings.PlayerSettings.ForEach(ps => glMain.AddPlayerColor(ps.Name, ps.UIColor));
			glMain.NewSection(String.Format("Game started with {0} players", game.Players.Count));

			game.Table.TokenPiles.TokenCollectionsChanged += new DominionBase.TokenCollections.TokenCollectionsChangedEventHandler(TokenPiles_TokenCollectionsChanged);
			game.Table.Trash.PileChanged += new DominionBase.Piles.Pile.PileChangedEventHandler(Trash_PileChanged);
			Trash_PileChanged(game.Table.Trash, new DominionBase.Piles.PileChangedEventArgs(DominionBase.Piles.PileChangedEventArgs.Operation.Reset));
			game.GameMessage += new DominionBase.Game.GameMessageEventHandler(game_GameMessage);

			foreach (DominionBase.Players.Player player in game.Players.FindAll(p => p.PlayerType == DominionBase.Players.PlayerType.Human))
				player.Choose = player_Choose;

			if (game.Players.Any(player => player.PlayerType == DominionBase.Players.PlayerType.Human))
				_Player = game.Players.OfType<DominionBase.Players.Human>().First();
			else
				_Player = null;

			String message = "Using the following cards";
			if (game.Settings.Preset != null)
				message = String.Format("{0} from the preset \"{1}\"", message, game.Settings.Preset.Name);
			glMain.Log(String.Format("{0}:", message));
			IEnumerable<DominionBase.Piles.Supply> kingdomSupplies = game.Table.Supplies.Where(kvp => kvp.Value.Randomizer.Location == DominionBase.Cards.Location.Kingdom).Select(kvp => kvp.Value).OrderBy(s => s.Name);
			glMain.Log("   ", kingdomSupplies.Take(5));
			glMain.Log("   ", kingdomSupplies.Skip(5));

			int prosperityPiles = game.Table.Supplies.Count(kvp => kvp.Value.Location == DominionBase.Cards.Location.Kingdom && kvp.Value.Source == DominionBase.Cards.Source.Prosperity);
			int darkAgesPiles = game.Table.Supplies.Count(kvp => kvp.Value.Location == DominionBase.Cards.Location.Kingdom && kvp.Value.Source == DominionBase.Cards.Source.DarkAges);
			int kingdomPiles = game.Table.Supplies.Count(kvp => kvp.Value.Location == DominionBase.Cards.Location.Kingdom && kvp.Value.Tokens.Count(t => t.GetType() == DominionBase.Cards.Cornucopia.TypeClass.BaneToken) == 0);
			glMain.Log(String.Format("Prosperity Kingdom card ratio is {0}/{1} = {2:P0}", 
				prosperityPiles,
				kingdomPiles,
				((float)prosperityPiles) / kingdomPiles
				));
			glMain.Log(String.Format("   Colony / Platinum {0}selected",
				game.Settings.ColonyPlatinumUsage == DominionBase.ColonyPlatinumUsage.Used ? "" : "<u>not</u> "
				));
			glMain.Log(String.Format("Dark Ages Kingdom card ratio is {0}/{1} = {2:P0}",
				darkAgesPiles,
				kingdomPiles,
				((float)darkAgesPiles) / kingdomPiles
				));
			glMain.Log(String.Format("   Shelters {0}selected",
				game.Settings.ShelterUsage == DominionBase.ShelterUsage.Used ? "" : "<u>not</u> "
				));

			glMain.Log("Turn order is: ", String.Join(", ", game.Players.Select(p => p == _Player ? String.Format("{0} (You)", p.Name) : p.Name)));


			Type[] specialTypes = new Type[] { 
				DominionBase.Cards.Promotional.TypeClass.BlackMarketSupply, 
				DominionBase.Cards.Cornucopia.TypeClass.PrizeSupply, 
				DominionBase.Cards.DarkAges.TypeClass.Madman,
				DominionBase.Cards.DarkAges.TypeClass.Mercenary,
				DominionBase.Cards.DarkAges.TypeClass.Spoils };

			foreach (Type specialType in specialTypes)
			{
				if (game.Table.SpecialPiles.ContainsKey(specialType))
				{
					_MatEventHandlers[specialType] = new DominionBase.Piles.Pile.PileChangedEventHandler(GamePile_PileChanged);
					game.Table.SpecialPiles[specialType].PileChanged += _MatEventHandlers[specialType];
					GamePile_PileChanged(game.Table.SpecialPiles[specialType], new DominionBase.Piles.PileChangedEventArgs(DominionBase.Piles.PileChangedEventArgs.Operation.Reset));
				}
			}

			if (game.Table.Supplies.ContainsKey(DominionBase.Cards.Prosperity.TypeClass.TradeRoute))
			{
				if (dpGameStuff.Children.Count > 0)
				{
					Border bDiv = new Border();
					bDiv.BorderThickness = new Thickness(2);
					bDiv.BorderBrush = Brushes.Black;
					Panel.SetZIndex(bDiv, 1);
					DockPanel.SetDock(bDiv, Dock.Left);
					dpGameStuff.Children.Add(bDiv);
				}

				Label lTradeRoute = new Label();
				lTradeRoute.Content = "Trade Route Tokens:";
				lTradeRoute.FontSize = 16d;
				lTradeRoute.FontWeight = FontWeights.Bold;
				lTradeRoute.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
				lTradeRoute.Background = Caching.BrushRepository.GetBackgroundBrush(DominionBase.Cards.Category.Treasure);
				DockPanel.SetDock(lTradeRoute, Dock.Left);
				dpGameStuff.Children.Add(lTradeRoute);

				_TradeRouteLabel = new Label();
				_TradeRouteLabel.Content = "0";
				_TradeRouteLabel.FontWeight = FontWeights.Bold;
				_TradeRouteLabel.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
				_TradeRouteLabel.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
				_TradeRouteLabel.Background = Caching.BrushRepository.GetBackgroundBrush(DominionBase.Cards.Category.Treasure);
				_TradeRouteLabel.Padding = new Thickness(0, 0, 5, 0);
				_TradeRouteLabel.BorderThickness = new Thickness(0, 0, 1, 0);
				DockPanel.SetDock(_TradeRouteLabel, Dock.Left);
				dpGameStuff.Children.Add(_TradeRouteLabel);
			}

			if (dpGameStuff.Children.Count > 0)
				bStuffDivider.Visibility = System.Windows.Visibility.Visible;
			else
				bStuffDivider.Visibility = System.Windows.Visibility.Collapsed;

			foreach (DominionBase.Players.Player player in game.Players)
			{
				TabItem tiPlayer = new TabItem();

				DockPanel dpHeader = new DockPanel();
				Image iHeader = new Image();
				iHeader.Stretch = Stretch.None;
				iHeader.Margin = new Thickness(0, 0, 5, 0);
				DockPanel.SetDock(iHeader, Dock.Left);
				switch (player.PlayerType)
				{
					case DominionBase.Players.PlayerType.Human:
						iHeader.Source = (BitmapImage)this.Resources["imHuman"];
						break;

					case DominionBase.Players.PlayerType.Computer:
						iHeader.Source = (BitmapImage)this.Resources["imComputer"];
						break;
				}
				dpHeader.Children.Add(iHeader);
				TextBlock tbHeader = new TextBlock();
				tbHeader.Text = player.Name;
				dpHeader.Children.Add(tbHeader);
				tiPlayer.Header = dpHeader;

				tcAreas.Items.Add(tiPlayer);
				Controls.ucPlayerDisplay ucpdPlayer = new Controls.ucPlayerDisplay();
				tiPlayer.Content = ucpdPlayer;
				ucpdPlayer.IsUIPlayer = (player.PlayerType == DominionBase.Players.PlayerType.Human);
				ucpdPlayer.Player = player;

				PlayerSettings playerSettings = _Settings.PlayerSettings.FirstOrDefault(ps => ps.Name == player.Name);
				if (playerSettings != null)
				{
					ColorHls hlsValue = HLSColor.RgbToHls(playerSettings.UIColor);
					Color cPlayer = HLSColor.HlsToRgb(hlsValue.H, Math.Min(1d, hlsValue.L * 1.125), hlsValue.S * 0.95, hlsValue.A);
					GradientStopCollection gsc = new GradientStopCollection();
					gsc.Add(new GradientStop(cPlayer, 0));
					gsc.Add(new GradientStop(playerSettings.UIColor, 0.25));
					gsc.Add(new GradientStop(playerSettings.UIColor, 0.75));
					gsc.Add(new GradientStop(cPlayer, 1));
					gsc.Freeze();
					tiPlayer.Background = new LinearGradientBrush(gsc, 0);
					//tiPlayer.Background = new SolidColorBrush(playerSettings.UIColor);
					ucpdPlayer.ColorFocus = playerSettings.UIColor;
				}

				ToolTip tt = new System.Windows.Controls.ToolTip();
				Controls.ucPlayerOverview ucpo = new Controls.ucPlayerOverview();
				ucpo.Player = player;
				tt.Content = ucpo;
				ToolTipService.SetToolTip(dpHeader, tt);
				if (Settings.ToolTipShowDuration == ToolTipShowDuration.Off)
					ToolTipService.SetIsEnabled(dpHeader, false);
				else
				{
					ToolTipService.SetIsEnabled(dpHeader, true);
					ToolTipService.SetShowDuration(dpHeader, (int)Settings.ToolTipShowDuration);
				}
				dpHeader.MouseDown += new MouseButtonEventHandler(tiPlayer_MouseDown);
				dpHeader.MouseUp += new MouseButtonEventHandler(tiPlayer_MouseUp);

				player.Revealed.PileChanged += new DominionBase.Piles.Pile.PileChangedEventHandler(Revealed_PileChanged);
				player.BenefitReceiving += new DominionBase.Players.Player.BenefitReceivingEventHandler(player_BenefitReceiving);
				//player.DiscardPile.PileChanged += new DominionBase.Pile.PileChangedEventHandler(DiscardPile_PileChanged);
				player.CardPlaying += new DominionBase.Players.Player.CardPlayingEventHandler(player_CardPlaying);
				player.CardPlayed += new DominionBase.Players.Player.CardPlayedEventHandler(player_CardPlayed);
				player.CardUndoPlaying += new DominionBase.Players.Player.CardUndoPlayingEventHandler(player_CardUndoPlaying);
				player.CardUndoPlayed += new DominionBase.Players.Player.CardUndoPlayedEventHandler(player_CardUndoPlayed);
				player.CardBuying += new DominionBase.Players.Player.CardBuyingEventHandler(player_CardBuying);
				player.CardBought += new DominionBase.Players.Player.CardBoughtEventHandler(player_CardBought);
				player.CardBuyFinished += new DominionBase.Players.Player.CardBuyFinishedEventHandler(player_CardBuyFinished);
				player.CardGaining += new DominionBase.Players.Player.CardGainingEventHandler(player_CardGaining);
				player.CardGainedInto += new DominionBase.Players.Player.CardGainedIntoEventHandler(player_CardGainedInto);
				player.CardGainFinished += new DominionBase.Players.Player.CardGainFinishedEventHandler(player_CardGainFinished);
				player.TokenPlaying += new DominionBase.Players.Player.TokenPlayingEventHandler(player_TokenPlaying);
				player.TokenPlayed += new DominionBase.Players.Player.TokenPlayedEventHandler(player_TokenPlayed);
				player.Trashing += new DominionBase.Players.Player.TrashingEventHandler(player_Trashing);
				player.TrashedFinished += new DominionBase.Players.Player.TrashedFinishedEventHandler(player_Trashed);
				player.PhaseChanged += new DominionBase.Players.Player.PhaseChangedEventHandler(player_PhaseChangedEvent);
				player.PlayerModeChanged += new DominionBase.Players.Player.PlayerModeChangedEventHandler(player_PlayerModeChangedEvent);
				player.CardsDrawn += new DominionBase.Players.Player.CardsDrawnEventHandler(player_CardsDrawn);
				player.TurnStarting += new DominionBase.Players.Player.TurnStartingEventHandler(player_TurnStarting);
				player.Shuffling += new DominionBase.Players.Player.ShufflingEventHandler(player_Shuffle);
				player.CardsAddedToDeck += new DominionBase.Players.Player.CardsAddedToDeckEventHandler(player_CardsAddedToDeck);
				player.CardsAddedToHand += new DominionBase.Players.Player.CardsAddedToHandEventHandler(player_CardsAddedToHand);
				player.CardsDiscarded += new DominionBase.Players.Player.CardsDiscardedEventHandler(player_CardsDiscarded);
				player.PlayerMats.CardMatsChanged += new DominionBase.Piles.CardMats.CardMatsChangedEventHandler(PlayerMats_DecksChanged);
				player.TokenPiles.TokenCollectionsChanged += new DominionBase.TokenCollections.TokenCollectionsChangedEventHandler(PlayerTokenPiles_TokenCollectionsChanged);
				player.BenefitsChanged += new DominionBase.Players.Player.BenefitsChangedEventHandler(player_BenefitsChanged);

				if (player == _Player)
				{
					tcAreas.SelectedItem = tiPlayer;
					player.CardReceived += new DominionBase.Players.Player.CardReceivedEventHandler(player_CardReceived);
				}
			}

			game.FinalizeSetup();

			LayoutSupplyPiles();

			miNewGame.IsEnabled = false;
			miLoadGame.IsEnabled = false;
			miEndGame.IsEnabled = true;
			miSaveGame.IsEnabled = false;

			gameThread = new Thread(game.StartAsync);
			gameThread.Start();

			UpdateDisplay();
		}
Exemplo n.º 13
0
		private void Game_Load_Click(object sender, RoutedEventArgs e)
		{
			Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
			ofd.DefaultExt = ".save";
			ofd.Filter = "Saved game files (.save)|*.save";
			Nullable<Boolean> dialogResult = ofd.ShowDialog(this);
			if (dialogResult != true)
				return;

			this.game = new DominionBase.Game();
			this.game.Load(ofd.FileName);

			// Clean out the Image Repository before starting a new game -- 
			// so we don't allocate too much memory for cards we're not even using
			Caching.ImageRepository.Reset();
			dpGameInfo.Visibility = System.Windows.Visibility.Visible;
			glMain.TearDown();
			glMain.Clear();

			LayoutSupplyPiles();
			while (tcAreas.Items.Count > 2)
				tcAreas.Items.RemoveAt(tcAreas.Items.Count - 1);
			dpMatsandPiles.Children.Clear();
			dpGameStuff.Children.Clear();
			_TradeRouteLabel = null;

			// Try to force garbage collection to save some memory
			GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

			// -------------------------------------------------------------------------------

			game.GameEndedEvent += new DominionBase.Game.GameEndedEventHandler(game_GameEndedEvent);

			wMain.Settings.PlayerSettings.ForEach(ps => glMain.AddPlayerColor(ps.Name, ps.UIColor));
			if (game.ActivePlayer != null)
			{
				glMain.NewSection(String.Format("Game loaded from {0}.", game.StartTime));
				glMain.Log("It's ", game.ActivePlayer, "'s turn");
			}

			game.Table.TokenPiles.TokenCollectionsChanged += new DominionBase.TokenCollections.TokenCollectionsChangedEventHandler(TokenPiles_TokenCollectionsChanged);
			game.Table.Trash.PileChanged += new DominionBase.Piles.Pile.PileChangedEventHandler(Trash_PileChanged);
			Trash_PileChanged(game.Table.Trash, new DominionBase.Piles.PileChangedEventArgs(DominionBase.Piles.PileChangedEventArgs.Operation.Reset));
			game.GameMessage += new DominionBase.Game.GameMessageEventHandler(game_GameMessage);

			foreach (DominionBase.Players.Player player in game.Players.FindAll(p => p.PlayerType == DominionBase.Players.PlayerType.Human))
				player.Choose = player_Choose;

			if (game.Players.Any(player => player.PlayerType == DominionBase.Players.PlayerType.Human))
				_Player = game.Players.OfType<DominionBase.Players.Human>().First();
			else
				_Player = null;

			// -------------------------------------------------------------------------------

			Type[] specialTypes = new Type[] { 
				DominionBase.Cards.Promotional.TypeClass.BlackMarketSupply, 
				DominionBase.Cards.Cornucopia.TypeClass.PrizeSupply, 
				DominionBase.Cards.DarkAges.TypeClass.Madman,
				DominionBase.Cards.DarkAges.TypeClass.Mercenary,
				DominionBase.Cards.DarkAges.TypeClass.Spoils };

			foreach (Type specialType in specialTypes)
			{
				if (game.Table.SpecialPiles.ContainsKey(specialType))
				{
					_MatEventHandlers[specialType] = new DominionBase.Piles.Pile.PileChangedEventHandler(GamePile_PileChanged);
					game.Table.SpecialPiles[specialType].PileChanged += _MatEventHandlers[specialType];
					GamePile_PileChanged(game.Table.SpecialPiles[specialType], new DominionBase.Piles.PileChangedEventArgs(DominionBase.Piles.PileChangedEventArgs.Operation.Reset));
				}
			}

			if (game.Table.Supplies.ContainsKey(DominionBase.Cards.Prosperity.TypeClass.TradeRoute))
			{
				if (dpGameStuff.Children.Count > 0)
				{
					Border bDiv = new Border();
					bDiv.BorderThickness = new Thickness(2);
					bDiv.BorderBrush = Brushes.Black;
					Panel.SetZIndex(bDiv, 1);
					DockPanel.SetDock(bDiv, Dock.Left);
					dpGameStuff.Children.Add(bDiv);
				}

				Label lTradeRoute = new Label();
				lTradeRoute.Content = "Trade Route Tokens:";
				lTradeRoute.FontSize = 16d;
				lTradeRoute.FontWeight = FontWeights.Bold;
				lTradeRoute.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
				lTradeRoute.Background = Caching.BrushRepository.GetBackgroundBrush(DominionBase.Cards.Category.Treasure);
				DockPanel.SetDock(lTradeRoute, Dock.Left);
				dpGameStuff.Children.Add(lTradeRoute);

				_TradeRouteLabel = new Label();
				_TradeRouteLabel.Content = game.Table.TokenPiles[DominionBase.Cards.Prosperity.TypeClass.TradeRouteToken].Count;
				_TradeRouteLabel.FontWeight = FontWeights.Bold;
				_TradeRouteLabel.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
				_TradeRouteLabel.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
				_TradeRouteLabel.Background = Caching.BrushRepository.GetBackgroundBrush(DominionBase.Cards.Category.Treasure);
				_TradeRouteLabel.Padding = new Thickness(0, 0, 5, 0);
				_TradeRouteLabel.BorderThickness = new Thickness(0, 0, 1, 0);
				DockPanel.SetDock(_TradeRouteLabel, Dock.Left);
				dpGameStuff.Children.Add(_TradeRouteLabel);
			}

			if (dpGameStuff.Children.Count > 0)
				bStuffDivider.Visibility = System.Windows.Visibility.Visible;
			else
				bStuffDivider.Visibility = System.Windows.Visibility.Collapsed;

			foreach (DominionBase.Players.Player player in game.Players)
			{
				TabItem tiPlayer = new TabItem();

				DockPanel dpHeader = new DockPanel();
				Image iHeader = new Image();
				iHeader.Stretch = Stretch.None;
				iHeader.Margin = new Thickness(0, 0, 5, 0);
				DockPanel.SetDock(iHeader, Dock.Left);
				switch (player.PlayerType)
				{
					case DominionBase.Players.PlayerType.Human:
						iHeader.Source = (BitmapImage)this.Resources["imHuman"];
						break;

					case DominionBase.Players.PlayerType.Computer:
						iHeader.Source = (BitmapImage)this.Resources["imComputer"];
						break;
				}
				dpHeader.Children.Add(iHeader);
				TextBlock tbHeader = new TextBlock();
				tbHeader.Text = player.Name;
				dpHeader.Children.Add(tbHeader);
				tiPlayer.Header = dpHeader;

				tcAreas.Items.Add(tiPlayer);
				Controls.ucPlayerDisplay ucpdPlayer = new Controls.ucPlayerDisplay();
				tiPlayer.Content = ucpdPlayer;
				ucpdPlayer.IsUIPlayer = (player == _Player);
				ucpdPlayer.Player = player;

				PlayerSettings playerSettings = _Settings.PlayerSettings.FirstOrDefault(ps => ps.Name == player.Name);
				if (playerSettings != null)
				{
					ColorHls hlsValue = HLSColor.RgbToHls(playerSettings.UIColor);
					Color cPlayer = HLSColor.HlsToRgb(hlsValue.H, Math.Min(1d, hlsValue.L * 1.125), hlsValue.S * 0.95, hlsValue.A);
					GradientStopCollection gsc = new GradientStopCollection();
					gsc.Add(new GradientStop(cPlayer, 0));
					gsc.Add(new GradientStop(playerSettings.UIColor, 0.25));
					gsc.Add(new GradientStop(playerSettings.UIColor, 0.75));
					gsc.Add(new GradientStop(cPlayer, 1));
					gsc.Freeze();
					tiPlayer.Background = new LinearGradientBrush(gsc, 0);
					//tiPlayer.Background = new SolidColorBrush(playerSettings.UIColor);
					ucpdPlayer.ColorFocus = playerSettings.UIColor;
				}

				ToolTip tt = new System.Windows.Controls.ToolTip();
				Controls.ucPlayerOverview ucpo = new Controls.ucPlayerOverview();
				ucpo.Player = player;
				tt.Content = ucpo;
				ToolTipService.SetToolTip(dpHeader, tt);
				if (Settings.ToolTipShowDuration == ToolTipShowDuration.Off)
					ToolTipService.SetIsEnabled(dpHeader, false);
				else
				{
					ToolTipService.SetIsEnabled(dpHeader, true);
					ToolTipService.SetShowDuration(dpHeader, (int)Settings.ToolTipShowDuration);
				}
				dpHeader.MouseDown += new MouseButtonEventHandler(tiPlayer_MouseDown);
				dpHeader.MouseUp += new MouseButtonEventHandler(tiPlayer_MouseUp);

				player.Revealed.PileChanged += new DominionBase.Piles.Pile.PileChangedEventHandler(Revealed_PileChanged);
				player.BenefitReceiving += new DominionBase.Players.Player.BenefitReceivingEventHandler(player_BenefitReceiving);
				//player.DiscardPile.PileChanged += new DominionBase.Pile.PileChangedEventHandler(DiscardPile_PileChanged);
				player.CardPlaying += new DominionBase.Players.Player.CardPlayingEventHandler(player_CardPlaying);
				player.CardPlayed += new DominionBase.Players.Player.CardPlayedEventHandler(player_CardPlayed);
				player.CardUndoPlaying += new DominionBase.Players.Player.CardUndoPlayingEventHandler(player_CardUndoPlaying);
				player.CardUndoPlayed += new DominionBase.Players.Player.CardUndoPlayedEventHandler(player_CardUndoPlayed);
				player.CardBuying += new DominionBase.Players.Player.CardBuyingEventHandler(player_CardBuying);
				player.CardBought += new DominionBase.Players.Player.CardBoughtEventHandler(player_CardBought);
				player.CardBuyFinished += new DominionBase.Players.Player.CardBuyFinishedEventHandler(player_CardBuyFinished);
				player.CardGaining += new DominionBase.Players.Player.CardGainingEventHandler(player_CardGaining);
				player.CardGainedInto += new DominionBase.Players.Player.CardGainedIntoEventHandler(player_CardGainedInto);
				player.CardGainFinished += new DominionBase.Players.Player.CardGainFinishedEventHandler(player_CardGainFinished);
				player.TokenPlaying += new DominionBase.Players.Player.TokenPlayingEventHandler(player_TokenPlaying);
				player.TokenPlayed += new DominionBase.Players.Player.TokenPlayedEventHandler(player_TokenPlayed);
				player.Trashing += new DominionBase.Players.Player.TrashingEventHandler(player_Trashing);
				player.TrashedFinished += new DominionBase.Players.Player.TrashedFinishedEventHandler(player_Trashed);
				player.PhaseChanged += new DominionBase.Players.Player.PhaseChangedEventHandler(player_PhaseChangedEvent);
				player.PlayerModeChanged += new DominionBase.Players.Player.PlayerModeChangedEventHandler(player_PlayerModeChangedEvent);
				player.CardsDrawn += new DominionBase.Players.Player.CardsDrawnEventHandler(player_CardsDrawn);
				player.TurnStarting += new DominionBase.Players.Player.TurnStartingEventHandler(player_TurnStarting);
				player.Shuffling += new DominionBase.Players.Player.ShufflingEventHandler(player_Shuffle);
				player.CardsAddedToDeck += new DominionBase.Players.Player.CardsAddedToDeckEventHandler(player_CardsAddedToDeck);
				player.CardsAddedToHand += new DominionBase.Players.Player.CardsAddedToHandEventHandler(player_CardsAddedToHand);
				player.CardsDiscarded += new DominionBase.Players.Player.CardsDiscardedEventHandler(player_CardsDiscarded);
				player.PlayerMats.CardMatsChanged += new DominionBase.Piles.CardMats.CardMatsChangedEventHandler(PlayerMats_DecksChanged);
				player.TokenPiles.TokenCollectionsChanged += new DominionBase.TokenCollections.TokenCollectionsChangedEventHandler(PlayerTokenPiles_TokenCollectionsChanged);
				player.BenefitsChanged += new DominionBase.Players.Player.BenefitsChangedEventHandler(player_BenefitsChanged);

				if (player == _Player)
				{
					tcAreas.SelectedItem = tiPlayer;
					player.CardReceived += new DominionBase.Players.Player.CardReceivedEventHandler(player_CardReceived);
				}
			}

			miNewGame.IsEnabled = false;
			miLoadGame.IsEnabled = false;
			miEndGame.IsEnabled = true;
			miSaveGame.IsEnabled = false;

			gameThread = new Thread(game.StartAsync);
			gameThread.Start();

			if (game.ActivePlayer != null)
			{
				if (game.Players[0] != game.ActivePlayer)
					glMain.NewTurn(game.TurnsTaken.TurnNumber(game.ActivePlayer));
				player_BenefitsChanged(game.ActivePlayer, new DominionBase.Players.BenefitsChangedEventArgs(game.ActivePlayer)
				{
					Actions = game.ActivePlayer.Actions,
					Buys = game.ActivePlayer.Buys,
					Currency = game.ActivePlayer.Currency,
					Player = game.ActivePlayer
				});
			}
			if (_Player.Phase == DominionBase.Players.PhaseEnum.Starting ||
					_Player.Phase == DominionBase.Players.PhaseEnum.Buy ||
					_Player.PlayerMode == DominionBase.Players.PlayerMode.Waiting)
				CheckBuyable(_Player);
			else
				ClearBuyable();
			UpdateDisplay();
		}
Exemplo n.º 14
0
 private GradientStopCollection _getGradientStops(double radius) {
    if (!_gradientStops.ContainsKey(radius)) {
       var stops = new GradientStopCollection();
       var color = Color;
       var delta = 1.0 / (radius + (7.5 - Softness*5.0));
       for (int i=0; i < _gradientOpacities.Length; i++) {
          color.A = (byte)(_gradientOpacities[i] * color.A);
          stops.Add(new GradientStop(color, (_gradientDistribution[i]+radius)*delta));
       }
       stops.Freeze();
       lock (_lock) {
          _gradientStops[radius] = stops;
       }
    }
    return _gradientStops[radius];
 }
        private GradientStopCollection CreateStops(Color c, double cornerRadius)
        {
            double stopPoint = 1.0 / (cornerRadius + ShadowDepth);

            var stops = new GradientStopCollection
            {
                new GradientStop(c, (ShadowDepth + cornerRadius) * stopPoint)
            };

            Color color = c;

            color.A = (byte)(0.74336 * c.A);
            stops.Add(new GradientStop(color, (1.5 + cornerRadius) * stopPoint));

            color.A = (byte)(0.38053 * c.A);
            stops.Add(new GradientStop(color, (2.5 + cornerRadius) * stopPoint));

            color.A = (byte)(0.12389 * c.A);
            stops.Add(new GradientStop(color, (3.5 + cornerRadius) * stopPoint));

            color.A = (byte)(0.02654 * c.A);
            stops.Add(new GradientStop(color, (4.5 + cornerRadius) * stopPoint));

            color.A = 0;
            stops.Add(new GradientStop(color, (5.0 + cornerRadius) * stopPoint));

            stops.Freeze();

            return stops;
        }