/// <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; } }
/// <summary> /// Adds all factions in the current scenario to the "Owner" <see cref="ComboBox"/>. /// </summary> /// <remarks><para> /// <b>AddScenarioFactions</b> adds the <see cref="FactionClass.Id"/> strings of all <see /// cref="FactionClass"/> objects in the current scenario to the "Owner" combo box. /// </para><para> /// These identifiers are collected in three different locations: /// </para><list type="number"><item> /// All elements in the <see cref="FactionSection.Collection"/> of the current <see /// cref="FactionSection"/>. /// </item><item> /// Any <see cref="Area.Owner"/> identifiers of <see cref="Area"/> objects that were not /// encountered in step 1. /// </item><item> /// Any <see cref="Area.UnitOwner"/> identifiers of <b>Area</b> objects that were not /// encountered in steps 1 and 2.</item></list></remarks> private void AddScenarioFactions() { var items = OwnerCombo.Items; // add all scenario factions to combo box FactionSection factions = MasterSection.Instance.Factions; foreach (string id in factions.Collection.Keys) { items.Add(id); } // add any additional area owners AreaSection areas = MasterSection.Instance.Areas; foreach (Area area in areas.Collection) { string id = area.Owner; if (id.Length > 0 && !items.Contains(id)) { items.Add(id); } } // add any additional unit owners foreach (Area area in areas.Collection) { string id = area.UnitOwner; if (id.Length > 0 && id != area.Owner && !items.Contains(id)) { items.Add(id); } } }
/// <summary> /// Raises and handles the <see cref="Window.Closing"/> event.</summary> /// <param name="args"> /// A <see cref="CancelEventArgs"/> object containing event data.</param> /// <remarks><para> /// <b>OnClosing</b> raises the <see cref="Window.Closing"/> event by calling the base class /// implementation of <see cref="Window.OnClosing"/> with the specified <paramref /// name="args"/>. /// </para><para> /// If the event was not requested to <see cref="CancelEventArgs.Cancel"/>, <b>OnClosing</b> /// handles the <see cref="Window.Closing"/> event by clearing the <see cref="DataChanged"/> /// flag if the <see cref="Window.DialogResult"/> is not <c>true</c>, indicating that the /// user cancelled the dialog and wants to discard all changes. /// </para><para> /// Otherwise, <b>OnClosing</b> reads the control contents of this dialog into the current /// <see cref="FactionSection"/>.</para></remarks> protected override void OnClosing(CancelEventArgs args) { base.OnClosing(args); if (args.Cancel) { return; } // user cancelled dialog, ignore changes if (DialogResult != true) { DataChanged = false; return; } // store new faction colors FactionSection factions = MasterSection.Instance.Factions; foreach (FactionListItem item in FactionList.Items) { FactionClass faction = factions.Collection[item.Item1]; faction.Color = item.Item2; } }
/// <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); }
/// <summary> /// Raises and handles the <see cref="Window.Closing"/> event.</summary> /// <param name="args"> /// A <see cref="CancelEventArgs"/> object containing event data.</param> /// <remarks><para> /// <b>OnClosing</b> raises the <see cref="Window.Closing"/> event by calling the base class /// implementation of <see cref="Window.OnClosing"/> with the specified <paramref /// name="args"/>. /// </para><para> /// If the event was not requested to <see cref="CancelEventArgs.Cancel"/>, <b>OnClosing</b> /// handles the <see cref="Window.Closing"/> event by clearing the <see cref="DataChanged"/> /// flag if the <see cref="Window.DialogResult"/> is not <c>true</c>, indicating that the /// user cancelled the dialog and wants to discard all changes. /// </para><para> /// Otherwise, <b>OnClosing</b> reads the control contents of this dialog into the current /// <see cref="AreaSection"/>.</para></remarks> protected override void OnClosing(CancelEventArgs args) { base.OnClosing(args); if (args.Cancel) { return; } // user cancelled dialog, ignore changes if (DialogResult != true) { DataChanged = false; return; } // read coordinates stored in Faction list view FactionSection factions = MasterSection.Instance.Factions; foreach (FactionListItem item in FactionList.Items) { FactionClass faction = factions.Collection[item.Item1]; faction.HomeSite = item.Item3; } }