コード例 #1
0
ファイル: SampleBrowser.cs プロジェクト: royosherove/cthru
 /// <summary>
 /// Updates the Sample Name and the Level labels.
 /// </summary>
 /// <param name="item">SampleBrowserItem containing Sample related
 /// information.</param>
 private void UpdateDifficultyLevel(SampleBrowserItem item)
 {
     Color SampleDifficultyLevelColor = Colors.Gray;
     SampleDifficultyLevel.Visibility = Visibility.Visible;
     if (SampleDifficultyLevel != null)
     {
         if (item.SampleLevel == DifficultyLevel.Basic)
         {
             SampleDifficultyLevelColor = Colors.Green;
         }
         else if (item.SampleLevel == DifficultyLevel.Scenario)
         {
             SampleDifficultyLevelColor = Colors.Orange;
         }
         else if (item.SampleLevel == DifficultyLevel.Advanced)
         {
             SampleDifficultyLevelColor = Colors.Red;
         }
         else if (item.SampleLevel == DifficultyLevel.Scenario)
         {
             SampleDifficultyLevelColor = Colors.DarkGray;
         }
         else if (item.SampleLevel == DifficultyLevel.None)
         {
             SampleDifficultyLevel.Visibility = Visibility.Collapsed;
         }
         SampleDifficultyLevel.Background = new SolidColorBrush(SampleDifficultyLevelColor);
         SampleDifficultyLevel.Content = item.SampleLevel.ToString();
     }
 }
コード例 #2
0
        /// <summary>
        /// Create a SampleBrowserItem and inserts into the right location.
        /// </summary>
        /// <param name="Samples">Collections of Samples.</param>
        /// <param name="type">Type of Sample.</param>
        /// <param name="attribute">Attributes for the Sample.</param>
        internal static void AddSample(IList<SampleBrowserItem> Samples, Type type, SampleAttribute attribute)
        {
            string name = attribute.Name;
            // Find any existing item
            SampleBrowserItem item = null;
            if (Samples != null)
            {
                foreach (SampleBrowserItem other in Samples)
                {
                    if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        item = other;
                        break;
                    }
                }
            }
            // Escape any name sorting
            string escapedName = name;
            if (name[0] == '(')
            {
                int index = name.IndexOf(')');
                if (index > 0)
                {
                    escapedName = name.Substring(index + 1, name.Length - index - 1);
                }
            }

            item = new SampleBrowserItem { Name = escapedName, OriginalName = name, SampleType = type, SampleLevel = attribute.DifficultyLevel };

            // Insert the item into the list in sorted order (linearly
            // because no item should have very many children)
            int sortedIndex = 0;
            foreach (SampleBrowserItem other in Samples)
            {
                if (string.Compare(other.OriginalName, name, StringComparison.OrdinalIgnoreCase) > 0)
                {
                    break;
                }
                else
                {
                    sortedIndex++;
                }
            }
            Samples.Insert(sortedIndex, item);
        }