mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Use Shadow's combined element model
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
using MPF.Utilities;
|
||||
using MPF.Web;
|
||||
|
||||
namespace MPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a single item in the Category combo box
|
||||
/// </summary>
|
||||
public class CategoryComboBoxItem
|
||||
{
|
||||
private object data;
|
||||
|
||||
public CategoryComboBoxItem(DiscCategory? category) => data = category;
|
||||
|
||||
public static implicit operator DiscCategory? (CategoryComboBoxItem item) => item.data as DiscCategory?;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return (data as DiscCategory?).LongName(); }
|
||||
}
|
||||
|
||||
public bool IsChecked { get; set; }
|
||||
|
||||
public DiscCategory? Value
|
||||
{
|
||||
get { return data as DiscCategory?; }
|
||||
}
|
||||
}
|
||||
}
|
||||
55
MPF/ComboBoxItems/Element.cs
Normal file
55
MPF/ComboBoxItems/Element.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace MPF
|
||||
{
|
||||
/// <summary>
|
||||
/// A generic combo box element
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Enum type representing the possible values</typeparam>
|
||||
public class Element<T> : IElement where T : struct, Enum
|
||||
{
|
||||
private readonly T Data;
|
||||
|
||||
public Element(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allow elements to be used as their internal enum type
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public static implicit operator T? (Element<T> item) => item.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Display name for the combo box element
|
||||
/// </summary>
|
||||
public string Name => new EnumDescriptionConverter().Convert(Data, null, null, CultureInfo.CurrentCulture) as string;
|
||||
|
||||
/// <summary>
|
||||
/// Internal enum value
|
||||
/// </summary>
|
||||
public T Value => Data;
|
||||
|
||||
/// <summary>
|
||||
/// Determine if the item is selected or not
|
||||
/// </summary>
|
||||
/// <remarks>Only applies to CheckBox type</remarks>
|
||||
public bool IsChecked { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generate all elements assocaited with the data enum type
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Element<T>> GenerateElements()
|
||||
{
|
||||
return Enum.GetValues(typeof(T))
|
||||
.OfType<T>()
|
||||
.Select(e => new Element<T>(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
7
MPF/ComboBoxItems/IElement.cs
Normal file
7
MPF/ComboBoxItems/IElement.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace MPF
|
||||
{
|
||||
public interface IElement
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using MPF.Data;
|
||||
using MPF.Utilities;
|
||||
|
||||
namespace MPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a single item in the Internal Program combo box
|
||||
/// </summary>
|
||||
public class InternalProgramComboBoxItem
|
||||
{
|
||||
private object data;
|
||||
|
||||
public InternalProgramComboBoxItem(InternalProgram? internalProgram) => data = internalProgram;
|
||||
|
||||
public static implicit operator InternalProgram? (InternalProgramComboBoxItem item) => item.data as InternalProgram?;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return (data as InternalProgram?).LongName();
|
||||
}
|
||||
}
|
||||
|
||||
public InternalProgram? Value
|
||||
{
|
||||
get { return data as InternalProgram?; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace MPF
|
||||
/// <summary>
|
||||
/// Represents a single item in the System combo box
|
||||
/// </summary>
|
||||
public class KnownSystemComboBoxItem
|
||||
public class KnownSystemComboBoxItem : IElement
|
||||
{
|
||||
private object data;
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using MPF.Utilities;
|
||||
using MPF.Web;
|
||||
|
||||
namespace MPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a single item in the Language combo box
|
||||
/// </summary>
|
||||
public class LanguageComboBoxItem
|
||||
{
|
||||
private object data;
|
||||
|
||||
public LanguageComboBoxItem(Language? region) => data = region;
|
||||
|
||||
public static implicit operator Language? (LanguageComboBoxItem item) => item.data as Language?;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return (data as Language?).LongName(); }
|
||||
}
|
||||
|
||||
public bool IsChecked { get; set; }
|
||||
|
||||
public Language? Value
|
||||
{
|
||||
get { return data as Language?; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using MPF.Data;
|
||||
using MPF.Utilities;
|
||||
|
||||
namespace MPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a single item in the MediaType combo box
|
||||
/// </summary>
|
||||
public class MediaTypeComboBoxItem
|
||||
{
|
||||
private MediaType? data;
|
||||
|
||||
public MediaTypeComboBoxItem(MediaType? mediaType) => data = mediaType;
|
||||
|
||||
public static implicit operator MediaType? (MediaTypeComboBoxItem item) => item.data;
|
||||
|
||||
public string Name { get { return data.LongName(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using MPF.Utilities;
|
||||
using MPF.Web;
|
||||
|
||||
namespace MPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a single item in the Region combo box
|
||||
/// </summary>
|
||||
public class RegionComboBoxItem
|
||||
{
|
||||
private object data;
|
||||
|
||||
public RegionComboBoxItem(Region? region) => data = region;
|
||||
|
||||
public static implicit operator Region? (RegionComboBoxItem item) => item.data as Region?;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return (data as Region?).LongName();
|
||||
}
|
||||
}
|
||||
|
||||
public Region? Value
|
||||
{
|
||||
get { return data as Region?; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace MPF.Windows
|
||||
/// <summary>
|
||||
/// List of available disc categories
|
||||
/// </summary>
|
||||
public List<CategoryComboBoxItem> Categories { get; private set; } = GenerateComboBoxItems<DiscCategory, CategoryComboBoxItem>().ToList();
|
||||
public List<Element<DiscCategory>> Categories { get; private set; } = Element<DiscCategory>.GenerateElements().ToList();
|
||||
|
||||
/// <summary>
|
||||
/// SubmissionInfo object to fill and save
|
||||
@@ -27,12 +27,12 @@ namespace MPF.Windows
|
||||
/// <summary>
|
||||
/// List of available regions
|
||||
/// </summary>
|
||||
public List<RegionComboBoxItem> Regions { get; private set; } = GenerateComboBoxItems<Region, RegionComboBoxItem>().ToList();
|
||||
public List<Element<Region>> Regions { get; private set; } = Element<Region>.GenerateElements().ToList();
|
||||
|
||||
/// <summary>
|
||||
/// List of available languages
|
||||
/// </summary>
|
||||
public List<LanguageComboBoxItem> Languages { get; private set; } = GenerateComboBoxItems<Language, LanguageComboBoxItem>().ToList();
|
||||
public List<Element<Language>> Languages { get; private set; } = Element<Language>.GenerateElements().ToList();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -45,20 +45,6 @@ namespace MPF.Windows
|
||||
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>
|
||||
@@ -242,8 +228,8 @@ namespace MPF.Windows
|
||||
SubmissionInfo.CommonDiscInfo.ForeignTitleNonLatin = ForeignTitle.Text ?? "";
|
||||
SubmissionInfo.CommonDiscInfo.DiscNumberLetter = DiscNumberLetter.Text ?? "";
|
||||
SubmissionInfo.CommonDiscInfo.DiscTitle = DiscTitle.Text ?? "";
|
||||
SubmissionInfo.CommonDiscInfo.Category = (CategoryComboBox.SelectedItem as CategoryComboBoxItem)?.Value ?? DiscCategory.Games;
|
||||
SubmissionInfo.CommonDiscInfo.Region = (RegionComboBox.SelectedItem as RegionComboBoxItem)?.Value ?? Region.World;
|
||||
SubmissionInfo.CommonDiscInfo.Category = (CategoryComboBox.SelectedItem as Element<DiscCategory>)?.Value ?? DiscCategory.Games;
|
||||
SubmissionInfo.CommonDiscInfo.Region = (RegionComboBox.SelectedItem as Element<Region>)?.Value ?? Region.World;
|
||||
var languages = new List<Language?>();
|
||||
foreach (var language in Languages)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace MPF.Windows
|
||||
/// <summary>
|
||||
/// List of available internal programs
|
||||
/// </summary>
|
||||
public List<InternalProgramComboBoxItem> InternalPrograms { get; private set; }
|
||||
public List<Element<InternalProgram>> InternalPrograms { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -65,10 +65,10 @@ namespace MPF.Windows
|
||||
{
|
||||
// We only support certain programs for dumping
|
||||
var internalPrograms = new List<InternalProgram> { InternalProgram.DiscImageCreator, InternalProgram.Aaru, InternalProgram.DD };
|
||||
InternalPrograms = new List<InternalProgramComboBoxItem>();
|
||||
InternalPrograms = new List<Element<InternalProgram>>();
|
||||
foreach (var internalProgram in internalPrograms)
|
||||
{
|
||||
InternalPrograms.Add(new InternalProgramComboBoxItem(internalProgram));
|
||||
InternalPrograms.Add(new Element<InternalProgram>(internalProgram));
|
||||
}
|
||||
|
||||
InternalProgramComboBox.ItemsSource = InternalPrograms;
|
||||
@@ -155,7 +155,7 @@ namespace MPF.Windows
|
||||
private void OnAcceptClick(object sender, EventArgs e)
|
||||
{
|
||||
// Handle non-bindable fields
|
||||
UIOptions.Options.InternalProgram = (InternalProgramComboBox.SelectedItem as InternalProgramComboBoxItem)?.Name ?? InternalProgram.DiscImageCreator.ToString();
|
||||
UIOptions.Options.InternalProgram = (InternalProgramComboBox.SelectedItem as Element<InternalProgram>)?.Name ?? InternalProgram.DiscImageCreator.ToString();
|
||||
UIOptions.Options.Password = RedumpPasswordBox.Password;
|
||||
|
||||
UIOptions.Save();
|
||||
|
||||
Reference in New Issue
Block a user