Exemplo n.º 1
0
        /// <summary>
        /// Shows the specified winning faction and its controlling player.</summary>
        /// <param name="faction"><para>
        /// The <see cref="Faction"/> that won the game.
        /// </para><para>-or-</para><para>
        /// A null reference to indicate that all factions were defeated.</para></param>
        /// <exception cref="PropertyValueException">
        /// The current session <see cref="Session.State"/> is not <see
        /// cref="SessionState.Closed"/>.</exception>
        /// <remarks><para>
        /// <b>ShowWinner</b> displays a <see cref="Dialog.ShowEvent"/> dialog announcing total
        /// defeat if the specified <paramref name="faction"/> is a null reference, or the winning
        /// faction and its player otherwise.
        /// </para><para>
        /// <b>ShowWinner</b> then displays a <see cref="Dialog.ShowRanking"/> dialog, opened on the
        /// "Graphs" tab page.</para></remarks>

        public static void ShowWinner(Faction faction)
        {
            if (Session.State != SessionState.Closed)
            {
                ThrowHelper.ThrowPropertyValueExceptionWithFormat("Session.State",
                                                                  Session.State, Tektosyne.Strings.PropertyNotValue, SessionState.Closed);
            }

            if (faction == null)
            {
                // all factions were defeated
                Dialog.ShowEvent.Show(MainWindow.Instance,
                                      Global.Strings.DialogEventDefeatGlobal, Global.Strings.TitleEventDefeat);
            }
            else
            {
                Player player = PlayerManager.Instance.GetPlayer(faction);

                // show victorious faction and controlling player
                string message = String.Format(ApplicationInfo.Culture,
                                               Global.Strings.DialogEventVictory, player.Name);

                string caption = String.Format(ApplicationInfo.Culture,
                                               Global.Strings.TitleEventVictory, faction.Name);

                Dialog.ShowEvent.Show(MainWindow.Instance, message, caption);
            }

            // show history graph for entire game
            var dialog = new Dialog.ShowRanking(Session.MapView, true);

            dialog.Owner = MainWindow.Instance;
            dialog.ShowDialog();
        }
Exemplo n.º 2
0
            /// <summary>
            /// Renders the visual content of the <see cref="HistoryGraphRenderer"/>.</summary>
            /// <param name="context">
            /// The <see cref="DrawingContext"/> for the rendering.</param>
            /// <remarks>
            /// <b>OnRender</b> draws a history graph for the ranking criteria submitted to the last
            /// call to <see cref="DrawGraph"/>.</remarks>

            protected override void OnRender(DrawingContext context)
            {
                base.OnRender(context);
                if (this._criterion == null)
                {
                    return;
                }

                Color[]     colors;
                Point[][]   points;
                ShowRanking dialog = (ShowRanking)Window.GetWindow(this);

                if (this._history == null)
                {
                    // display sites or units for all factions
                    History history = dialog._worldState.History;
                    colors = new Color[history.Factions.Count];
                    points = new Point[history.Factions.Count][];

                    int faction = 0;
                    foreach (FactionHistory cursor in history.Factions.Values)
                    {
                        colors[faction] = cursor.FactionClass.Color;
                        points[faction] = new Point[cursor.Events.Length];

                        for (int i = 0; i < cursor.Events.Length; i++)
                        {
                            FactionHistory.FactionEvent factionEvent = cursor.Events[i];

                            int value = 0;
                            switch (this._criterion)
                            {
                            case "sites": value = factionEvent.Sites; break;

                            case "units": value = factionEvent.Units; break;

                            case "unit-strength": value = factionEvent.UnitStrength; break;
                            }

                            points[faction][i] = new Point(i, value);
                        }

                        ++faction;
                    }
                }
                else
                {
                    // display sites and units for specified faction
                    int count = this._history.Events.Length;
                    colors = new Color[] { Colors.Blue, Colors.Red };
                    points = new Point[][] { new Point[count], new Point[count] };

                    for (int i = 0; i < this._history.Events.Length; i++)
                    {
                        FactionHistory.FactionEvent factionEvent = this._history.Events[i];
                        points[0][i] = new Point(i, factionEvent.Sites);
                        points[1][i] = new Point(i, factionEvent.Units);
                    }
                }

                /*
                 * To ensure that the right and bottom division lines
                 * are visible, we shrink the drawing region by (2,2)
                 * relative to the actually available drawing area.
                 */

                Rect bounds = new Rect(1, 1, ActualWidth - 2, ActualHeight - 2);

                context.PushClip(new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight)));
                DrawGraph(context, bounds, colors, points, dialog.GetTypeface());
                context.Pop();
            }