From bf2ba0841ae0d54712485ad56d58b6eb3151361e Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 14 May 2014 22:04:47 +0000 Subject: [PATCH] make recent n64 plugin UI logic I added be more clever --- .../BizHawk.Client.EmuHawk.csproj | 1 + .../Extensions/ControlExtensions.cs | 28 +++++++++++++++++++ .../config/N64/N64VideoPluginconfig.cs | 16 ++--------- 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 94e90f6d2f..25e1a25eb9 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -439,6 +439,7 @@ + diff --git a/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs new file mode 100644 index 0000000000..6b71774ae3 --- /dev/null +++ b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +using BizHawk.Common; + +namespace BizHawk.Client.EmuHawk.ControlExtensions +{ + public static class ControlExtensions + { + public static void PopulateFromEnum(this ComboBox box, object enumVal) + where T : struct, IConvertible + { + if (!typeof(T).IsEnum) + { + throw new ArgumentException("T must be an enumerated type"); + } + + box.Items.Clear(); + box.Items.AddRange( + EnumHelper.GetDescriptions() + .ToArray()); + box.SelectedItem = EnumHelper.GetDescription(enumVal); + } + } +} diff --git a/BizHawk.Client.EmuHawk/config/N64/N64VideoPluginconfig.cs b/BizHawk.Client.EmuHawk/config/N64/N64VideoPluginconfig.cs index 20f60d268f..d0c0c1ec43 100644 --- a/BizHawk.Client.EmuHawk/config/N64/N64VideoPluginconfig.cs +++ b/BizHawk.Client.EmuHawk/config/N64/N64VideoPluginconfig.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Forms; +using BizHawk.Client.EmuHawk.ControlExtensions; using BizHawk.Client.Common; using BizHawk.Emulation.Cores.Nintendo.N64; using BizHawk.Common; @@ -308,19 +309,8 @@ namespace BizHawk.Client.EmuHawk { var s = GetS(); - CoreTypeDropdown.Items.Clear(); - CoreTypeDropdown.Items.AddRange( - EnumHelper.GetDescriptions() - .ToArray()); - CoreTypeDropdown.SelectedItem = EnumHelper.GetDescription(s.CoreType); - - RspTypeDropdown.Items.Clear(); - RspTypeDropdown.Items.AddRange( - EnumHelper.GetDescriptions() - .ToArray()); - RspTypeDropdown.SelectedItem = EnumHelper.GetDescription(s.RspType); - - + CoreTypeDropdown.PopulateFromEnum(s.CoreType); + RspTypeDropdown.PopulateFromEnum(s.RspType); //Load Variables //Global