Beispiel #1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Reset Colors" <see
        /// cref="Button"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnColorsReset</b> resets the colors of all items in the "Faction" list view to the
        /// corresponding <see cref="FactionClass.DefaultColors"/>, and sets the <see
        /// cref="DataChanged"/> flag if any changes were made.</remarks>

        private void OnColorsReset(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            int count = FactionClass.DefaultColors.Length;

            for (int i = 0; i < FactionList.Items.Count; i++)
            {
                // retrieve next default color in sequence
                Color color = FactionClass.DefaultColors[i % count];

                // skip factions with default color
                FactionListItem item = (FactionListItem)FactionList.Items[i];
                if (color == item.Item2)
                {
                    continue;
                }

                // broadcast data changes
                FactionList.Items[i] = new FactionListItem(
                    item.Item1, color, new SolidColorBrush(color));

                DataChanged = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeColors"/> class.</summary>
        /// <remarks><para>
        /// <b>ChangeColors</b> may change the <see cref="FactionClass.Color"/> property of any <see
        /// cref="FactionClass"/> defined by the current <see cref="FactionSection"/>.
        /// </para><para>
        /// The value of the <see cref="DataChanged"/> property indicates whether any changes were
        /// made.</para></remarks>

        public ChangeColors()
        {
            InitializeComponent();

            // add factions to list view
            FactionSection factions = MasterSection.Instance.Factions;

            foreach (FactionClass faction in factions.Collection.Values)
            {
                // store faction ID with faction color
                FactionListItem item = new FactionListItem(
                    faction.Id, faction.Color, new SolidColorBrush(faction.Color));

                FactionList.Items.Add(item);
            }

            // adjust column widths of Faction list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(FactionList, OnFactionWidthChanged);

            // select first faction if present
            if (FactionList.Items.Count > 0)
            {
                FactionList.SelectedIndex = 0;
            }
            else
            {
                // disable buttons otherwise
                ChangeButton.IsEnabled = false;
                ResetButton.IsEnabled  = false;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Faction" <see
        /// cref="ListView"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnFactionSelected</b> calls <see cref="SelectSite"/> with the <see
        /// cref="FactionClass.HomeSite"/> associated with the first selected item in the "Faction"
        /// list view, if any.</remarks>

        private void OnFactionSelected(object sender, SelectionChangedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected faction, if any
            int index = FactionList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            FactionListItem item = (FactionListItem)FactionList.Items[index];

            // update controls for home site
            SelectSite(item.Item3, true);
        }
Beispiel #4
0
        /// <summary>
        /// Sets the <see cref="FactionClass.HomeSite"/> of the selected faction to the specified
        /// location.</summary>
        /// <param name="newHome">
        /// The new <see cref="FactionClass.HomeSite"/> for the selected faction.</param>
        /// <remarks>
        /// <b>SetHome</b> sets the <see cref="FactionClass.HomeSite"/> stored with the first
        /// selected item in the "Faction" list view, if any, to the specified <paramref
        /// name="newHome"/>, updates the dialog accordingly, and sets the <see cref="DataChanged"/>
        /// flag if the <b>HomeSite</b> has changed.</remarks>

        private void SetHome(PointI newHome)
        {
            // retrieve selected faction, if any
            int index = FactionList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            FactionListItem item = (FactionListItem)FactionList.Items[index];

            // quit if coordinates unchanged
            PointI oldHome = item.Item3;

            if (newHome == oldHome)
            {
                return;
            }

            // highlight new home site if valid
            if (Finder.MapGrid.Contains(newHome))
            {
                this._mapView.SelectedRegion[newHome.X, newHome.Y] = true;
            }

            // show new home site and store coordinates
            item = new FactionListItem(item.Item1, Site.Format(newHome), newHome);
            FactionList.Items[index] = item;
            FactionList.SelectAndShow(index);

            DataChanged = true;

            // remove highlight on old home site if not used by another faction
            if (!IsHomeSite(oldHome) && Finder.MapGrid.Contains(oldHome))
            {
                this._mapView.SelectedRegion[oldHome.X, oldHome.Y] = false;
            }

            // show or hide buttons
            ShowButtons(newHome, true);
            this._mapView.Redraw();
        }
Beispiel #5
0
        /// <summary>
        /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see
        /// cref="ListViewItem"/> of the "Faction" <see cref="ListView"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="MouseButtonEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnFactionActivate</b> displays a <see cref="ShowFactions"/> dialog containing
        /// information on the double-clicked item in the "Faction" list view.</remarks>

        private void OnFactionActivate(object sender, MouseButtonEventArgs args)
        {
            args.Handled = true;

            // retrieve double-clicked item, if any
            var source   = args.OriginalSource as DependencyObject;
            var listItem = ItemsControl.ContainerFromElement(FactionList, source) as ListViewItem;

            if (listItem == null)
            {
                return;
            }

            // show info dialog for faction class
            FactionListItem item   = (FactionListItem)listItem.Content;
            var             dialog = new ShowFactions(Session.MapView, item.Item1.FactionClass);

            dialog.Owner = this;
            dialog.ShowDialog();
        }
Beispiel #6
0
        /// <summary>
        /// Allows the user to change the <see cref="FactionClass"/> color associated with the item
        /// at the specified index in the "Faction" <see cref="ListView"/>.</summary>
        /// <param name="index">
        /// The index of the <see cref="FactionListItem"/> to change.</param>
        /// <remarks>
        /// <b>ChangeColor</b> displays a <see cref="CustomColorDialog"/>, allowing the user to
        /// change the <see cref="FactionClass"/> color associated with the specified <paramref
        /// name="index"/>, and sets the <see cref="DataChanged"/> flag if the user made any
        /// changes.</remarks>

        private void ChangeColor(int index)
        {
            if (index < 0)
            {
                return;
            }
            FactionListItem item = (FactionListItem)FactionList.Items[index];

            // retrieve item color and let user change it
            Color color  = item.Item2;
            bool  result = CustomColorDialog.Show(this, ref color);

            // update item and brodcast changes if confirmed
            if (result && color != item.Item2)
            {
                FactionList.Items[index] = new FactionListItem(
                    item.Item1, color, new SolidColorBrush(color));

                DataChanged = true;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeHomes"/> class.</summary>
        /// <remarks>
        /// The data of the current <see cref="AreaSection"/> may be changed in the dialog, as
        /// indicated by the value of the <see cref="DataChanged"/> property.</remarks>

        public ChangeHomes()
        {
            InitializeComponent();

            // get world state shown in Areas tab page
            var        areasContent = MainWindow.Instance.AreasTab.SectionContent;
            WorldState world        = ((AreasTabContent)areasContent).WorldState;

            // create map view with default properties
            this._mapView = MapViewManager.Instance.CreateView(
                "changeHomes", world, MapViewHost, OnMapMouseDown, null);

            // prepare to highlight home sites
            this._mapView.SelectedRegion = Finder.MapGrid.CreateArray <Boolean>();

            FactionSection factions = MasterSection.Instance.Factions;

            foreach (FactionClass faction in factions.Collection.Values)
            {
                // add faction and home site
                PointI          home = faction.HomeSite;
                FactionListItem item = new FactionListItem(faction.Id, Site.Format(home), home);
                FactionList.Items.Add(item);

                // highlight home site if valid
                if (Finder.MapGrid.Contains(home))
                {
                    this._mapView.SelectedRegion[home.X, home.Y] = true;
                }
            }

            // adjust column width of Faction list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(FactionList, OnFactionWidthChanged);
        }