Ejemplo n.º 1
0
        /// <summary>
        /// Adds one row for each ability of the specified <see cref="EntityClass"/>.</summary>
        /// <param name="entityClass">
        /// The <see cref="EntityClass"/> whose abilities to show.</param>
        /// <remarks>
        /// <b>CreateAbilityRows</b> calls <see cref="CreateAbilityRow"/> for each ability of the
        /// specified <paramref name="entityClass"/>, if any.</remarks>

        private void CreateAbilityRows(EntityClass entityClass)
        {
            // effects & upgrades have no abilities
            if (entityClass.Category == EntityCategory.Effect ||
                entityClass.Category == EntityCategory.Upgrade)
            {
                return;
            }

            // insert separator if required
            if (Items.Count > 0)
            {
                ApplicationUtility.AddSeparator(this);
            }

            switch (entityClass.Category)
            {
            case EntityCategory.Unit:
                UnitClass unitClass = (UnitClass)entityClass;
                CreateAbilityRow(Global.Strings.LabelCapture, unitClass.CanCapture);
                break;

            case EntityCategory.Terrain:
                TerrainClass terrainClass = (TerrainClass)entityClass;
                CreateAbilityRow(Global.Strings.LabelCapturePassive, terrainClass.CanCapture);
                CreateAbilityRow(Global.Strings.LabelDestroyPassive, terrainClass.CanDestroy);
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the "Entity Class" <see cref="ListView"/> on the <see cref="ClassesTab"/> page
        /// with the current dialog selections.</summary>
        /// <remarks>
        /// <b>UpdateClasses</b> updates the the "Entity Class" list view and the "Show Placement
        /// Sites" button to reflect the selected <see cref="FactionClass"/> and the selected
        /// "Category" radio button.</remarks>

        private void UpdateClasses()
        {
            // clear entity classes list view
            ClassList.Items.Clear();
            ShowPlaceButton.IsEnabled = false;

            // quit if no faction instance available
            if (this._faction == null)
            {
                return;
            }

            // get available classes in selected category
            EntityCategory category         = CurrentCategory;
            var            availableClasses = this._faction.GetAvailableClasses(category);

            // quit if no available classes
            if (availableClasses == null)
            {
                return;
            }

            // get buildable classes in selected category
            var buildableClasses = this._faction.GetBuildableClasses(category);

            // show this faction's available classes
            foreach (EntityClass entityClass in availableClasses)
            {
                bool canBuild   = buildableClasses.ContainsKey(entityClass.Id);
                bool canCapture = false;

                UnitClass    unitClass    = entityClass as UnitClass;
                TerrainClass terrainClass = entityClass as TerrainClass;

                // determine abilities specific to subclasses
                if (unitClass != null)
                {
                    canCapture = unitClass.CanCapture;
                }
                else if (terrainClass != null)
                {
                    canCapture = terrainClass.CanCapture;
                }

                // create ability marker string
                string abilities = String.Format(ApplicationInfo.Culture, "{0}/{1}",
                                                 (canBuild ? _abbrBuild : "–"),
                                                 (canCapture ? _abbrCapture : "–"));

                ClassList.Items.Add(new ClassListItem(entityClass, abilities));
            }

            // select first available class by default
            if (ClassList.Items.Count > 0)
            {
                ClassList.SelectedIndex = 0;

                // enable Show Placements button
                ShowPlaceButton.IsEnabled = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeSite"/> class with the specified <see
        /// cref="Area"/> and <see cref="EntityCategory"/>.</summary>
        /// <param name="area"><para>
        /// The <see cref="Area"/> whose data to change.
        /// </para><para>-or-</para><para>
        /// A null reference to change the default terrain stack of the current <see
        /// cref="AreaSection"/>.</para></param>
        /// <param name="factions">
        /// An <see cref="IList"/> containing all faction identifiers in the current <see
        /// cref="FactionSection"/>, starting at index position one. Ignored if <paramref
        /// name="area"/> is a null reference.</param>
        /// <param name="category">
        /// A <see cref="EntityCategory"/> value indicating which entity stack to show initially.
        /// Ignored if <paramref name="area"/> is a null reference.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="area"/> is not a null reference and contains an empty <see
        /// cref="Area.Bounds"/> collection.</exception>
        /// <remarks><para>
        /// If <paramref name="area"/> is a null reference, <b>ChangeSite</b> may change the
        /// contents of the <see cref="AreaSection.Terrains"/> collection of the current <see
        /// cref="AreaSection"/>, i.e. the default terrain stack. Otherwise, the specified <paramref
        /// name="area"/> may be changed but the <b>AreaSection</b> will remain unchanged.
        /// </para><para>
        /// In either case, the value of the <see cref="DataChanged"/> property indicates whether
        /// any changes were made.</para></remarks>

        public ChangeSite(Area area, IList factions, EntityCategory category)
        {
            if (area != null && area.Bounds.Count == 0)
            {
                ThrowHelper.ThrowArgumentExceptionWithFormat(
                    "area", Tektosyne.Strings.ArgumentContainsEmpty, "Bounds");
            }

            this._area = area;
            InitializeComponent();

            if (area == null)
            {
                // hide Other tab when editing default contents
                OtherTab.Visibility = Visibility.Collapsed;
            }
            else
            {
                // show caption for editing site contents
                Title = Global.Strings.TitleContentsChange + Site.Format(area.Bounds[0].Location);

                // set initial tab selection as specified
                if (category == EntityCategory.Terrain)
                {
                    TerrainTab.IsSelected = true;
                }
                else
                {
                    OtherTab.IsSelected = true;
                }
            }

            #region TerrainTab

            // initialize stack control buttons
            AddTerrainButton.ShowSymbol(Symbols.BoxEmpty);
            ChangeTerrainButton.ShowSymbol(Symbols.Pencil);
            RemoveTerrainButton.ShowSymbol(Symbols.BoxCrossed);
            MoveTerrainUpButton.ShowSymbol(Symbols.ArrowUp);
            MoveTerrainDownButton.ShowSymbol(Symbols.ArrowDown);

            // initialize preview panel for stack images
            TerrainPreview.Polygon = MasterSection.Instance.Areas.MapGrid.Element;

            // create shallow copy of default or local terrain stack
            var terrainClasses = MasterSection.Instance.Entities.Terrains;
            this._terrains = new EntityTemplateList(area == null ?
                                                    MasterSection.Instance.Areas.Terrains : area.Terrains);

            // add "no background" entry to combo box
            if (area != null)
            {
                BackgroundCombo.Items.Add(Global.Strings.LabelTerrainBackgroundNone);
            }

            // add scenario terrains to appropriate controls
            foreach (var pair in terrainClasses)
            {
                TerrainClass terrain = (TerrainClass)pair.Value;

                // add background terrains to combo box
                if (terrain != null && terrain.IsBackground)
                {
                    BackgroundCombo.Items.Add(pair.Key);
                    continue;
                }

                // add other terrains to foreground list
                AvailableTerrainList.Items.Add(pair.Key);
            }

            // client must provide at least one background terrain
            Debug.Assert(BackgroundCombo.Items.Count > 0,
                         "Client failed to provide background terrains.");

            // select first background terrain entry
            BackgroundCombo.Tag           = null;
            BackgroundCombo.SelectedIndex = 0;

            // show terrain stack in appropriate controls
            foreach (EntityTemplate template in this._terrains)
            {
                EntityClass terrain;
                terrainClasses.TryGetValue(template.EntityClass, out terrain);

                // select background terrain in combo box
                if (terrain != null && ((TerrainClass)terrain).IsBackground)
                {
                    BackgroundCombo.Tag          = template;
                    BackgroundCombo.SelectedItem = template.EntityClass;
                    continue;
                }

                // add other terrains to editable list
                CreateEntityItem(TerrainList, template);
            }

            // create entity template for background terrain
            if (area == null && BackgroundCombo.Tag == null)
            {
                EntityTemplate template = new EntityTemplate(EntityCategory.Terrain);
                template.EntityClass = (string)BackgroundCombo.SelectedItem;
                BackgroundCombo.Tag  = template;
            }

            // determine "Change Terrain" button and change marker
            BackgroundChanged.Visibility     = Visibility.Hidden;
            ChangeBackgroundButton.IsEnabled = false;

            if (BackgroundCombo.Tag != null)
            {
                ChangeBackgroundButton.IsEnabled = true;
                if (((EntityTemplate)BackgroundCombo.Tag).IsModified)
                {
                    BackgroundChanged.Visibility = Visibility.Visible;
                }
            }

            // select first terrain class, if any
            bool anyClasses = (AvailableTerrainList.Items.Count > 0);
            if (anyClasses)
            {
                AvailableTerrainList.SelectedIndex = 0;
            }

            // select first terrain template, if any
            bool anyTerrains = (TerrainList.Items.Count > 0);
            if (anyTerrains)
            {
                TerrainList.SelectedIndex = 0;
            }

            // enable or disable terrain list controls
            AddTerrainButton.IsEnabled      = anyClasses;
            ChangeTerrainButton.IsEnabled   = anyTerrains;
            RemoveTerrainButton.IsEnabled   = anyTerrains;
            MoveTerrainDownButton.IsEnabled = anyTerrains;
            MoveTerrainUpButton.IsEnabled   = anyTerrains;

            // adjust column width of Terrain list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(TerrainList, OnTerrainWidthChanged);

            // adjust column width of Available Terrain list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(AvailableTerrainList, OnAvailableTerrainWidthChanged);

            // create terrain stack preview
            UpdatePreview(EntityCategory.Terrain);

            #endregion
            #region OtherTab

            if (area != null)
            {
                // initialize stack control buttons
                AddEntityButton.ShowSymbol(Symbols.BoxEmpty);
                ChangeEntityButton.ShowSymbol(Symbols.Pencil);
                RemoveEntityButton.ShowSymbol(Symbols.BoxCrossed);
                MoveEntityUpButton.ShowSymbol(Symbols.ArrowUp);
                MoveEntityDownButton.ShowSymbol(Symbols.ArrowDown);

                // initialize preview panel for stack images
                EntityPreview.Polygon = MasterSection.Instance.Areas.MapGrid.Element;

                // create shallow copies of non-terrain stacks
                this._units   = new EntityTemplateList(area.Units);
                this._effects = new EntityTemplateList(area.Effects);

                // add "same as site owner" entry to combo box
                UnitOwnerCombo.Items.Add(Global.Strings.LabelUnitOwnerNone);

                // add all faction identifiers to combo box
                for (int i = 1; i < factions.Count; i++)
                {
                    UnitOwnerCombo.Items.Add(factions[i]);
                }

                // select entry indicated by area's unit owner
                this._unitOwner = area.UnitOwner;
                if (this._unitOwner.Length == 0)
                {
                    // show "same as site owner" if unowned
                    UnitOwnerCombo.SelectedIndex = 0;
                }
                else
                {
                    // add unit owner ID if not among factions
                    if (!UnitOwnerCombo.Items.Contains(this._unitOwner))
                    {
                        UnitOwnerCombo.Items.Add(this._unitOwner);
                    }

                    UnitOwnerCombo.SelectedItem = this._unitOwner;
                }

                // adjust column width of Entity list view
                DependencyPropertyDescriptor.FromProperty(
                    ListView.ActualWidthProperty, typeof(ListView))
                .AddValueChanged(EntityList, OnEntityWidthChanged);

                // adjust column width of Available Entity list view
                DependencyPropertyDescriptor.FromProperty(
                    ListView.ActualWidthProperty, typeof(ListView))
                .AddValueChanged(AvailableEntityList, OnAvailableEntityWidthChanged);
            }

            #endregion

            // construction completed
            this._initialized = true;

            // Other tab: select specified entity stack
            if (area != null)
            {
                if (category == EntityCategory.Effect)
                {
                    EffectToggle.IsChecked = true;
                }
                else
                {
                    UnitToggle.IsChecked = true;
                }
            }
        }