Take Shadow's advice about lists

This commit is contained in:
Matt Nadareski
2021-03-01 22:58:55 -08:00
parent 432a9dda16
commit 03fe5ce8a5
2 changed files with 29 additions and 60 deletions

View File

@@ -14,7 +14,7 @@
<TabControl>
<TabItem x:Name="CommonInfo" Header="Common Info">
<StackPanel Orientation="Vertical">
<Expander Margin="5,5,5,5" BorderThickness="1" BorderBrush="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Header="Common Disc Information" IsExpanded="True">
<Expander Margin="5" Padding="5" BorderThickness="1" BorderBrush="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Header="Common Disc Information" IsExpanded="True">
<StackPanel Orientation="Vertical">
<controls:UserInput x:Name="GameTitle" Label="Title"/>
<controls:UserInput x:Name="ForeignTitle" Label="Foreign Title (Non-Latin)"/>
@@ -28,7 +28,8 @@
</Grid.ColumnDefinitions>
<Label x:Name="CategoryLabel" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Category" />
<ComboBox x:Name="CategoryComboBox" Grid.Row="0" Grid.Column="1" Height="22" HorizontalAlignment="Stretch" >
<ComboBox x:Name="CategoryComboBox" Grid.Row="0" Grid.Column="1" Height="22" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=Categories}" SelectedIndex="0">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
@@ -44,7 +45,8 @@
</Grid.ColumnDefinitions>
<Label x:Name="RegionLabel" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Region" />
<ComboBox x:Name="RegionComboBox" Grid.Row="0" Grid.Column="1" Height="22" HorizontalAlignment="Stretch" >
<ComboBox x:Name="RegionComboBox" Grid.Row="0" Grid.Column="1" Height="22" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=Regions}" SelectedIndex="0">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
@@ -60,7 +62,8 @@
</Grid.ColumnDefinitions>
<Label x:Name="LanguagesLabel" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Languages" />
<ComboBox x:Name="LanguagesComboBox" Grid.Row="0" Grid.Column="1" Height="24" HorizontalAlignment="Stretch" >
<ComboBox x:Name="LanguagesComboBox" Grid.Row="0" Grid.Column="1" Height="24" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=Languages}" SelectedIndex="0">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked}" Content="{Binding Path=Name}" />
@@ -75,7 +78,7 @@
<controls:UserInput x:Name="Contents" Label="Contents" TextHeight="50" Tab="True" Enter="True" TextWrapping="Wrap"/>
</StackPanel>
</Expander>
<Expander Margin="5,5,5,5" BorderThickness="1" BorderBrush="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Header="Version and Editions" IsExpanded="True">
<Expander Margin="5" Padding="5" BorderThickness="1" BorderBrush="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Header="Version and Editions" IsExpanded="True">
<StackPanel Orientation="Vertical">
<controls:UserInput x:Name="Version" Grid.Row="0" Label="Version"/>
<controls:UserInput x:Name="Edition" Grid.Row="1" Label="Edition"/>
@@ -124,8 +127,10 @@
<!-- Accept / Cancel -->
<GroupBox Margin="5,5,5,5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<UniformGrid Columns="4" Margin="5,5,5,5" Height="28">
<Label/>
<Button Name="AcceptButton" Grid.Row="0" Grid.Column="1" Height="25" Width="80" Content="Accept" Click="OnAcceptClick" />
<Button Name="CancelButton" Grid.Row="0" Grid.Column="2" Height="25" Width="80" Content="Cancel" Click="OnCancelClick" />
<Label/>
</UniformGrid>
</GroupBox>
</StackPanel>

View File

@@ -17,7 +17,7 @@ namespace MPF.Windows
/// <summary>
/// List of available disc categories
/// </summary>
public List<CategoryComboBoxItem> Categories { get; private set; }
public List<CategoryComboBoxItem> Categories { get; private set; } = GenerateComboBoxItems<DiscCategory, CategoryComboBoxItem>().ToList();
/// <summary>
/// SubmissionInfo object to fill and save
@@ -27,26 +27,38 @@ namespace MPF.Windows
/// <summary>
/// List of available regions
/// </summary>
public List<RegionComboBoxItem> Regions { get; private set; }
public List<RegionComboBoxItem> Regions { get; private set; } = GenerateComboBoxItems<Region, RegionComboBoxItem>().ToList();
/// <summary>
/// List of available languages
/// </summary>
public List<LanguageComboBoxItem> Languages { get; private set; }
public List<LanguageComboBoxItem> Languages { get; private set; } = GenerateComboBoxItems<Language, LanguageComboBoxItem>().ToList();
#endregion
public DiscInformationWindow(SubmissionInfo submissionInfo)
{
this.SubmissionInfo = submissionInfo;
InitializeComponent();
DataContext = this;
PopulateCategories();
PopulateRegions();
PopulateLanguages();
this.SubmissionInfo = submissionInfo;
ManipulateFields();
}
/// <summary>
/// Generate a set of combo box items for a given set of types
/// </summary>
/// <typeparam name="T">Base enum value to create combo box items for</typeparam>
/// <typeparam name="K">Combo box wrapper type for the base enum value</typeparam>
/// <returns>IEnumerable representing the generated combo box items</returns>
private static IEnumerable<K> GenerateComboBoxItems<T, K>()
{
return Enum.GetValues(typeof(T))
.OfType<T>()
.Select(e => Activator.CreateInstance(typeof(K), e))
.OfType<K>();
}
/// <summary>
/// Manipulate fields based on the current disc
/// </summary>
@@ -221,54 +233,6 @@ namespace MPF.Windows
Edition.Text = SubmissionInfo.VersionAndEditions.OtherEditions ?? "";
}
/// <summary>
/// Get a complete list of categories and fill the combo box
/// </summary>
private void PopulateCategories()
{
var categories = Enum.GetValues(typeof(DiscCategory)).OfType<DiscCategory?>().ToList();
Categories = new List<CategoryComboBoxItem>();
foreach (var category in categories)
{
Categories.Add(new CategoryComboBoxItem(category));
}
CategoryComboBox.ItemsSource = Categories;
CategoryComboBox.SelectedIndex = 0;
}
/// <summary>
/// Get a complete list of languages and fill the combo box
/// </summary>
private void PopulateLanguages()
{
var languages = Enum.GetValues(typeof(Language)).OfType<Language?>().ToList();
Languages = new List<LanguageComboBoxItem>();
foreach (var language in languages)
{
Languages.Add(new LanguageComboBoxItem(language));
}
LanguagesComboBox.ItemsSource = Languages;
LanguagesComboBox.SelectedIndex = 0;
}
/// <summary>
/// Get a complete list of regions and fill the combo box
/// </summary>
private void PopulateRegions()
{
var regions = Enum.GetValues(typeof(Region)).OfType<Region?>().ToList();
Regions = new List<RegionComboBoxItem>();
foreach (var region in regions)
{
Regions.Add(new RegionComboBoxItem(region));
}
RegionComboBox.ItemsSource = Regions;
RegionComboBox.SelectedIndex = 0;
}
/// <summary>
/// Save the current contents of the UI to the base SubmissionInfo
/// </summary>