コード例 #1
0
        /*/// <summary>
         * ///  Gets the category at the specified index in the category.
         * /// </summary>
         * /// <param name="index">The index of the category to get.</param>
         * /// <returns>The category at the specified index.</returns>
         * ISpriteCategory ISpriteCategoryContainer.this[int index] => (ISpriteCategory) this[index];
         *
         * /// <summary>
         * ///  Gets the category with the specified Id in the category.
         * /// </summary>
         * /// <param name="id">The Id of the category to get.</param>
         * /// <returns>The category with the specified Id.</returns>
         * ///
         * /// <exception cref="KeyNotFoundException">
         * ///  The element with the <paramref name="id"/> was not found.
         * /// </exception>
         * ISpriteCategory ISpriteCategoryContainer.Get(object id) => (ISpriteCategory) Get(id);
         * /// <summary>
         * ///  Gets if the category contains a category with the specified Id.
         * /// </summary>
         * /// <param name="id">The Id to check for a category with.</param>
         * /// <returns>True if a category exists with the specified Id, otherwise null.</returns>
         * bool ISpriteCategoryContainer.ContainsKey(object id) => ContainsKey(id);*/

        #endregion

        #region Part List Accessors

        /*/// <summary>
         * ///  Gets the part list at the specified index in the category.
         * /// </summary>
         * /// <param name="index">The index of the part list to get.</param>
         * /// <returns>The part list at the specified index.</returns>
         * ISpritePartList ISpritePartListContainer.this[int index] => (ISpritePartList) this[index];
         *
         * /// <summary>
         * ///  Gets the part list with the specified Id in the category.
         * /// </summary>
         * /// <param name="id">The Id of the part list to get.</param>
         * /// <returns>The part list with the specified Id.</returns>
         * ///
         * /// <exception cref="KeyNotFoundException">
         * ///  The element with the <paramref name="id"/> was not found.
         * /// </exception>
         * ISpritePartList ISpritePartListContainer.Get(int id) => (ISpritePartList) Get(id);
         * /// <summary>
         * ///  Gets if the category contains a part list with the specified Id.
         * /// </summary>
         * /// <param name="id">The Id to check for an part list with.</param>
         * /// <returns>True if a part list exists with the specified Id, otherwise null.</returns>
         * bool ISpritePartListContainer.ContainsKey(int id) => ContainsKey(id);*/

        #endregion

        #region Part Accessors

        /*/// <summary>
         * ///  Tries to get the part types that exist for this sprite selection for the specified sprite part group.
         * /// </summary>
         * /// <param name="group">The sprite part group whose sprite parts are being acquired.</param>
         * /// <param name="partId">The Id of the parts being used for the group.</param>
         * /// <param name="parts">The output sprite parts. This value should be ignored when false is returned.</param>
         * /// <returns>True if any parts were found for this group's part Id.</returns>
         * ///
         * /// <exception cref="ArgumentNullException">
         * ///  <paramref name="group"/> is null.
         * /// </exception>
         * public bool TryGetPartTypes(CharacterSpritePartGroupInfo group, int partId, out ISpritePart[] parts) {
         *      if (group == null)
         *              throw new ArgumentNullException(nameof(group));
         *      IReadOnlyList<int> typeIds = group.TypeIds;
         *      parts = new ISpritePart[typeIds.Count];
         *      bool found = false;
         *      for (int groupIndex = 0; groupIndex < typeIds.Count; groupIndex++) {
         *              int typeId = typeIds[groupIndex];
         *              if (TryGetValue(typeId, out var partTypesElement)) {
         *                      SpritePartList partTypes = (SpritePartList) partTypesElement;
         *                      if (partTypes.TryGetValue(partId, out parts[groupIndex]))
         *                              found = true; // Not a situation where we break after found, fill in the parts array.
         *              }
         *      }
         *      return found;
         * }
         * /// <summary>
         * ///  Tries to get the first part types that exist for this sprite selection for the specified part group.
         * /// </summary>
         * /// <param name="group">The sprite part group whose sprite parts are being acquired.</param>
         * /// <param name="partId">The output Id for the parts to use for this group.</param>
         * /// <param name="parts">The output sprite parts. This value should be ignored when false is returned.</param>
         * /// <returns>True if this sprite selection has any parts for this sprite part group.</returns>
         * ///
         * /// <exception cref="ArgumentNullException">
         * ///  <paramref name="group"/> is null.
         * /// </exception>
         * public bool TryGetFirstPartTypes(CharacterSpritePartGroupInfo group, out int partId, out ISpritePart[] parts) {
         *      if (group == null)
         *              throw new ArgumentNullException(nameof(group));
         *      IReadOnlyList<int> typeIds = group.TypeIds;
         *      parts = new ISpritePart[typeIds.Count];
         *      partId = int.MaxValue;
         *      bool found = false;
         *      for (int groupIndex = 0; groupIndex < typeIds.Count; groupIndex++) {
         *              int typeId = typeIds[groupIndex];
         *              if (TryGetValue(typeId, out var partTypesElement)) {
         *                      SpritePartList partTypes = (SpritePartList) partTypesElement;
         *                      if (partTypes.List.Count != 0) {
         *                              parts[groupIndex] = partTypes.List.First();
         *                              partId = Math.Min(parts[groupIndex].Id, partId);
         *                              found = true;
         *                      }
         *              }
         *      }
         *      if (found) {
         *              for (int groupIndex = 0; groupIndex < typeIds.Count; groupIndex++) {
         *                      if (parts[groupIndex] != null && parts[groupIndex].Id != partId)
         *                              parts[groupIndex] = null;
         *              }
         *      }
         *      else {
         *              partId = -1;
         *      }
         *      return found;
         * }*/

        #endregion

        #region CreateGroups

        /// <summary>
        ///  Creates sprite part groups used to categorize the sprite parts during selection.
        /// </summary>
        /// <param name="game">The game info associated with this sprite category.</param>
        /// <param name="character">The character info associated with this sprite category.</param>
        /// <returns>An array of sprite part groups for use in sprite part selection.</returns>
        ///
        /// <exception cref="ArgumentNullException">
        ///  <paramref name="game"/> or <paramref name="character"/> is null.
        /// </exception>
        public ISpritePartGroup[] CreateGroups(GameInfo game, CharacterInfo character)
        {
            CharacterSpritePartGroupInfo[] groupInfos = character.Database.GetPartGroups(game, character);
            ISpritePartGroup[]             groups     = new ISpritePartGroup[groupInfos.Length];
            for (int i = 0; i < groups.Length; i++)
            {
                CharacterSpritePartGroupInfo groupInfo = groupInfos[i];
                SpritePartGroup group = new SpritePartGroup {
                    Info       = groupInfo,
                    Index      = i,
                    TypeIds    = groupInfo.TypeIds.ToArray(),
                    GroupParts = new List <SpritePartGroupPart> {
                        SpritePartGroupPart.None
                    },
                };
                // Add sprite part group parts that contain sprite parts for each Type Id.
                for (int typeIndex = 0; typeIndex < groupInfo.TypeIds.Count; typeIndex++)
                {
                    int            typeId   = groupInfo.TypeIds[typeIndex];
                    SpritePartList partList = (SpritePartList)List.Find(e => e.Id.Equals(typeId));
                    if (partList != null)
                    {
                        foreach (ISpritePart part in partList.List)
                        {
                            SpritePartGroupPart groupPart = group.GroupParts.Find(gp => gp.Id == part.Id);
                            if (groupPart == null)
                            {
                                groupPart = new SpritePartGroupPart {
                                    Id    = part.Id,
                                    Parts = new SpritePart[groupInfo.TypeIds.Count],
                                };
                                group.GroupParts.Add(groupPart);
                            }
                            groupPart.Parts[typeIndex] = (SpritePart)part;
                        }
                    }
                }
                group.GroupParts.Sort();
                groups[i] = group;
            }
            return(groups);
        }
コード例 #2
0
        private void CoerceSelectedItem(ISpritePartGroupPart groupPart, [CallerMemberName] string callerName = null)
        {
            if (supressEvents)
            {
                return;
            }
            string propName = "null";

            if (GetBindingExpression(ItemsSourceProperty) != null)
            {
                propName = GetBindingExpression(ItemsSourceProperty).ResolvedSourcePropertyName;
            }
            Console.WriteLine($"{propName} SpritePartGroupComboBox.{callerName} coerce");
            supressEvents = true;
            ISpritePartGroup source = ItemsSource;

            if (source == null)
            {
                groupPart = null;
            }
            else if (groupPart != null && source.TryGetValue(groupPart.Id, out ISpritePartGroupPart newGroupPart))
            {
                groupPart = newGroupPart;
            }
            else if (source.IsEnabledByDefault && source.GroupParts.Count > 1)
            {
                groupPart = source.GroupParts[1];
            }
            else
            {
                groupPart = source.GroupParts[0];
            }
            SelectedItem         = groupPart;
            SelectedItemInternal = groupPart;
            supressEvents        = false;
        }