From 4346504e2408af44187a3ade785a6a3c7461b10c Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 29 Jul 2014 01:11:57 +0000 Subject: [PATCH] Make some extension methods for doing the icon and text logic for the core statusbar item, makes for some prettier syntax, but also makes it easier to use this logic elsewhere --- .../BizHawk.Client.EmuHawk.csproj | 1 + .../Extensions/CoreExtensions.cs | 88 +++++++++++++++++++ BizHawk.Client.EmuHawk/MainForm.cs | 62 +------------ 3 files changed, 93 insertions(+), 58 deletions(-) create mode 100644 BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 9a7aa2f8b2..ba4645f2f1 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -498,6 +498,7 @@ + diff --git a/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs b/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs new file mode 100644 index 0000000000..3b88af5018 --- /dev/null +++ b/BizHawk.Client.EmuHawk/Extensions/CoreExtensions.cs @@ -0,0 +1,88 @@ +using System.Drawing; + +using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; + +using BizHawk.Emulation.Cores.Atari.Atari7800; +using BizHawk.Emulation.Cores.Nintendo.GBA; +using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; +using BizHawk.Emulation.Cores.Nintendo.SNES; +using BizHawk.Emulation.Cores.Nintendo.Gameboy; +using BizHawk.Emulation.Cores.Nintendo.SNES9X; +using BizHawk.Emulation.Cores.Sega.Saturn; +using BizHawk.Emulation.Cores.Consoles.Sega.gpgx; +using BizHawk.Emulation.Cores.Sony.PSP; + +using BizHawk.Client.Common; + +namespace BizHawk.Client.EmuHawk.CoreExtensions +{ + public static class CoreExtensions + { + public static Bitmap Icon(this IEmulator core) + { + var attributes = Global.Emulator.Attributes(); + + if (!attributes.Ported) + { + return Properties.Resources.CorpHawkSmall; + } + + if (Global.Emulator is QuickNES) + { + return Properties.Resources.QuickNes; + } + else if (Global.Emulator is LibsnesCore) + { + return Properties.Resources.bsnes; + } + else if (Global.Emulator is Yabause) + { + return Properties.Resources.yabause; + } + else if (Global.Emulator is Atari7800) + { + return Properties.Resources.emu7800; + } + else if (Global.Emulator is GBA) + { + return Properties.Resources.meteor; + } + else if (Global.Emulator is GPGX) + { + return Properties.Resources.genplus; + } + else if (Global.Emulator is PSP) + { + return Properties.Resources.ppsspp; + } + else if (Global.Emulator is Gameboy) + { + return Properties.Resources.gambatte; + } + else if (Global.Emulator is Snes9x) + { + return Properties.Resources.snes9x; + } + else + { + return null; + } + } + + public static string DisplayName(this IEmulator core) + { + var attributes = Global.Emulator.Attributes(); + + var str = (!attributes.Released ? "(Experimental) " : string.Empty) + + attributes.CoreName; + + if (Global.Emulator is LibsnesCore) + { + str += " (" + ((LibsnesCore.SnesSyncSettings)Global.Emulator.GetSyncSettings()).Profile + ")"; + } + + return str; + } + } +} diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index cac70f210c..195fa65bc6 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -18,7 +18,6 @@ using BizHawk.Bizware.BizwareGL; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Cores.Atari.Atari2600; -using BizHawk.Emulation.Cores.Atari.Atari7800; using BizHawk.Emulation.Cores.Calculators; using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; using BizHawk.Emulation.Cores.Consoles.Sega.gpgx; @@ -28,14 +27,12 @@ using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.Nintendo.SNES; using BizHawk.Emulation.Cores.PCEngine; using BizHawk.Emulation.Cores.Sega.MasterSystem; -using BizHawk.Emulation.Cores.Sega.Saturn; -using BizHawk.Emulation.Cores.Sony.PSP; using BizHawk.Emulation.DiscSystem; using BizHawk.Emulation.Cores.Nintendo.N64; using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.ToolExtensions; -using BizHawk.Emulation.Cores.Nintendo.SNES9X; +using BizHawk.Client.EmuHawk.CoreExtensions; namespace BizHawk.Client.EmuHawk { @@ -2450,62 +2447,11 @@ namespace BizHawk.Client.EmuHawk } CoreNameStatusBarButton.Visible = true; - CoreAttributes attributes = Global.Emulator.Attributes(); - - CoreNameStatusBarButton.Text = - (!attributes.Released ? "(Experimental) " : string.Empty) + - attributes.CoreName; + var attributes = Global.Emulator.Attributes(); + CoreNameStatusBarButton.Text = Global.Emulator.DisplayName(); + CoreNameStatusBarButton.Image = Global.Emulator.Icon(); CoreNameStatusBarButton.ToolTipText = attributes.Ported ? "(ported) " : string.Empty; - - if (!attributes.Ported) - { - CoreNameStatusBarButton.Image = Properties.Resources.CorpHawkSmall; - } - else - { - if (Global.Emulator is QuickNES) - { - CoreNameStatusBarButton.Image = Properties.Resources.QuickNes; - } - else if (Global.Emulator is LibsnesCore) - { - CoreNameStatusBarButton.Image = Properties.Resources.bsnes; - CoreNameStatusBarButton.Text += " (" + ((LibsnesCore.SnesSyncSettings)Global.Emulator.GetSyncSettings()).Profile + ")"; - } - else if (Global.Emulator is Yabause) - { - CoreNameStatusBarButton.Image = Properties.Resources.yabause; - } - else if (Global.Emulator is Atari7800) - { - CoreNameStatusBarButton.Image = Properties.Resources.emu7800; - } - else if (Global.Emulator is GBA) - { - CoreNameStatusBarButton.Image = Properties.Resources.meteor; - } - else if (Global.Emulator is GPGX) - { - CoreNameStatusBarButton.Image = Properties.Resources.genplus; - } - else if (Global.Emulator is PSP) - { - CoreNameStatusBarButton.Image = Properties.Resources.ppsspp; - } - else if (Global.Emulator is Gameboy) - { - CoreNameStatusBarButton.Image = Properties.Resources.gambatte; - } - else if (Global.Emulator is Snes9x) - { - CoreNameStatusBarButton.Image = Properties.Resources.snes9x; - } - else - { - CoreNameStatusBarButton.Image = null; - } - } } #endregion