示例#1
0
        /// <summary>
        /// Handles the <see cref="ToggleButton.Checked"/> event for the "Category" <see
        /// cref="RadioButton"/> controls.</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>OnCategoryChecked</b> updates the "Entity Class" list view to reflect the selected
        /// "Category" radio button, and then selects the first item in that list view, if any.
        /// </remarks>

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

            // switch category (default to Unit)
            EntityCategory category = EntityCategory.Unit;

            if (UnitToggle.IsChecked == true)
            {
                category           = EntityCategory.Unit;
                this._classTargets = this._unitTargets;
            }
            else if (TerrainToggle.IsChecked == true)
            {
                category           = EntityCategory.Terrain;
                this._classTargets = this._terrainTargets;
            }
            else
            {
                Debug.Fail("ShowPlacements.OnCategoryChecked: No Category button checked.");
                category           = EntityCategory.Unit;
                this._classTargets = this._unitTargets;
            }

            // get all buildable classes of current category
            var           buildableClasses = this._faction.GetBuildableClasses(category);
            EntitySection entities         = MasterSection.Instance.Entities;

            ClassList.Items.Clear();
            foreach (var pair in this._classTargets)
            {
                // get entity class for current target, if any
                EntityClass entityClass = entities.GetEntity(pair.Key);
                if (entityClass == null)
                {
                    continue;
                }

                // check if specified faction can build entity class
                bool   canBuild = buildableClasses.ContainsKey(entityClass.Id);
                string check    = (canBuild ? CheckMark : "");

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

            // select first entity class, if any
            if (ClassList.Items.Count > 0)
            {
                ClassList.SelectedIndex = 0;
            }
        }
示例#2
0
        /// <summary>
        /// Copies all image frames for all entity classes to the bitmap catalog.</summary>
        /// <param name="copying">
        /// <c>true</c> to perform the actual copy; <c>false</c> to set catalog indices and count
        /// animation frames only.</param>
        /// <param name="frames">
        /// Returns the maximum number of animation frames (i.e. frames of animated images) copied
        /// for any single entity class.</param>
        /// <returns>
        /// The total number of catalog tiles used or required to hold all image frames for all
        /// entity classes, plus one tile for the "invalid" icon at index position zero.</returns>
        /// <remarks>
        /// <b>CopyEntityClasses</b> invokes <see cref="CopyEntityClass"/> for each entity class, of
        /// any category, defined in the current <see cref="EntitySection"/>. Please refer to
        /// <b>CopyEntityClass</b> for details on the copying process.</remarks>

        private int CopyEntityClasses(bool copying, out int frames)
        {
            // reset counters
            frames = 0;
            int index = (int)CatalogIndex.Images;

            // iterate through all entity categories
            EntitySection entitySection = MasterSection.Instance.Entities;

            foreach (EntityCategory category in EntitySection.AllCategories)
            {
                IList <EntityClass> entities = entitySection.GetEntities(category).Values;

                // copy all image frames for each entity class
                foreach (EntityClass entity in entities)
                {
                    int copied = CopyEntityClass(copying, entity, ref index);
                    frames = Math.Max(frames, copied);
                }
            }

            // return tile count
            return(index);
        }