Exemplo n.º 1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Faction" <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><para>
        /// <b>OnFactionAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed by
        /// a <see cref="Dialog.ChangeFaction"/> dialog, allowing the user to define a new faction.
        /// The new faction copies the properties of the first selected item in the "Faction" list
        /// view, if any; otherwise, it is created with default properties.
        /// </para><para>
        /// If the user confirmed both dialogs, <b>OnFactionAdd</b> adds the new faction to the
        /// "Faction" list view and to the current <see cref="FactionSection"/>, and sets the <see
        /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

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

            // ask user for new faction ID
            var factions = MasterSection.Instance.Factions.Collection;
            var dialog   = new Dialog.ChangeIdentifier("faction-id",
                                                       Global.Strings.TitleFactionIdEnter, factions.ContainsKey, false);

            dialog.Owner = MainWindow.Instance;
            if (dialog.ShowDialog() != true)
            {
                return;
            }

            // retrieve new faction ID
            string id = String.Intern(dialog.Identifier);

            // create new faction based on selected faction, if any
            FactionClass faction, selection = FactionList.SelectedItem as FactionClass;

            if (selection == null)
            {
                faction = new FactionClass(id);
                // add default defeat condition (site loss)
                faction.DefeatConditions.Add(new Condition());
            }
            else
            {
                faction    = (FactionClass)selection.Clone();
                faction.Id = id;
            }

            // let user make changes to new faction
            var factionDialog = new Dialog.ChangeFaction(faction)
            {
                Owner = MainWindow.Instance
            };

            if (factionDialog.ShowDialog() != true)
            {
                return;
            }

            // add faction to section table
            factions.Add(id, faction);

            // update list view and select new item
            FactionList.Items.Refresh();
            FactionList.SelectAndShow(faction);

            // broadcast data changes
            EnableListButtons();
            SectionTab.DataChanged = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the user to change the specified <see cref="FactionClass"/>.</summary>
        /// <param name="faction">
        /// The <see cref="FactionClass"/> to change.</param>
        /// <remarks><para>
        /// <b>ChangeFaction</b> displays a <see cref="Dialog.ChangeFaction"/> dialog for the
        /// specified <paramref name="faction"/>.
        /// </para><para>
        /// If the user made any changes, <b>ChangeFaction</b> propagates them to the faction
        /// collection of the current <see cref="FactionSection"/> and sets the <see
        /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

        private void ChangeFaction(FactionClass faction)
        {
            if (faction == null)
            {
                return;
            }

            // show dialog and let user make changes
            var dialog = new Dialog.ChangeFaction(faction)
            {
                Owner = MainWindow.Instance
            };

            dialog.ShowDialog();

            // broadcast data changes, if any
            if (dialog.DataChanged)
            {
                FactionList.Items.Refresh();
                SectionTab.DataChanged = true;
            }
        }