Пример #1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Change Default Contents" <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>OnChangeDefault</b> shows an error message if the current scenario does not define
        /// any background terrains.
        /// </para><para>
        /// Otherwise, <b>OnChangeDefault</b> displays a <see cref="Dialog.ChangeSite"/> dialog for
        /// the default terrain stack of the current <see cref="AreaSection"/>, and sets the <see
        /// cref="SectionTabItem.DataChanged"/> and <see cref="ScenarioChanged"/> flags and calls
        /// <see cref="Synchronize()"/> if the user made any changes.</para></remarks>

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

            // abort if there are no background terrains
            if (!AnyBackgroundTerrain())
            {
                MessageBox.Show(MainWindow.Instance,
                                Global.Strings.DialogBackgroundNone, Global.Strings.TitleAreaInvalid,
                                MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            // adopt pending user changes
            if (WorldChanged)
            {
                Synchronize();
            }

            // show dialog and let user make changes
            var dialog = new Dialog.ChangeSite(null, null, EntityCategory.Terrain);

            dialog.Owner = MainWindow.Instance;
            dialog.ShowDialog();

            // broadcast data changes, if any
            if (dialog.DataChanged)
            {
                SectionTab.DataChanged = true;
                ScenarioChanged        = true;
                Synchronize();
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Change Site Contents" <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"/> or <see cref="EventArgs{Boolean}"/> object containing
        /// event data.</param>
        /// <remarks><para>
        /// <b>OnChangeSite</b> shows an error message if the current scenario does not define any
        /// background terrains.
        /// </para><para>
        /// Otherwise, <b>OnChangeSite</b> displays a <see cref="Dialog.ChangeSite"/> dialog for the
        /// selected <see cref="Site"/>, and sets the <see cref="SectionTabItem.DataChanged"/> and
        /// <see cref="WorldChanged"/> flags if the user made any changes.
        /// </para><para>
        /// If <paramref name="args"/> is an <see cref="EventArgs{Boolean}"/> object whose <see
        /// cref="EventArgs{T}.Value"/> is <c>true</c>, the <see cref="Dialog.ChangeSite"/> dialog
        /// will default to the first <see cref="EntityCategory"/> whose site stack is not empty,
        /// rather than to <see cref="EntityCategory.Terrain"/>.</para></remarks>

        private void OnChangeSite(object sender, EventArgs args)
        {
            RoutedEventArgs routedArgs = args as RoutedEventArgs;

            if (routedArgs != null)
            {
                routedArgs.Handled = true;
            }

            // abort if no site selected
            if (this._selection == null)
            {
                return;
            }

            // abort if there are no background terrains
            if (!AnyBackgroundTerrain())
            {
                MessageBox.Show(MainWindow.Instance,
                                Global.Strings.DialogBackgroundNone, Global.Strings.TitleAreaInvalid,
                                MessageBoxButton.OK, MessageBoxImage.Information);

                return;
            }

            // determine initial tab page for dialog
            EntityCategory      category    = EntityCategory.Terrain;
            EventArgs <Boolean> booleanArgs = args as EventArgs <Boolean>;

            // select first non-empty category, if any
            if (booleanArgs != null && booleanArgs.Value)
            {
                if (this._selection.Units.Count > 0)
                {
                    category = EntityCategory.Unit;
                }
                else if (this._selection.Effects.Count > 0)
                {
                    category = EntityCategory.Effect;
                }
                else
                {
                    category = EntityCategory.Unit;
                }
            }

            // show "Change Site Contents" dialog
            var dialog = new Dialog.ChangeSite(this._selection, OwnerCombo.Items, category);

            dialog.Owner = MainWindow.Instance;
            dialog.ShowDialog();

            // broadcast data changes, if any
            if (dialog.DataChanged)
            {
                this._worldState.CreateSite(this._selection);
                WorldChanged           = true;
                SectionTab.DataChanged = true;
                MapView.Redraw();
            }
        }