Virtual Pads - fix Updating when movie is playing, and by removing a lot more code than I wrote

This commit is contained in:
adelikat 2014-05-11 22:27:20 +00:00
parent 1ef04c0cb5
commit 0abaeebb9d
1 changed files with 87 additions and 127 deletions

View File

@ -16,7 +16,9 @@ namespace BizHawk.Client.EmuHawk
{
get
{
return ControllerBox.Controls.OfType<IVirtualPad>().ToList();
return ControllerBox.Controls
.OfType<IVirtualPad>()
.ToList();
}
}
@ -46,7 +48,7 @@ namespace BizHawk.Client.EmuHawk
}
ControllerBox.Controls.Clear();
LoadPads();
LoadStartingPads();
}
public void UpdateValues()
@ -59,63 +61,15 @@ namespace BizHawk.Client.EmuHawk
if (Global.MovieSession.Movie.IsPlaying && !Global.MovieSession.Movie.IsFinished)
{
var str = Global.MovieSession.Movie.GetInput(Global.Emulator.Frame);
if (Global.Config.VirtualPadsUpdatePads && str != string.Empty)
var sections = Global.MovieSession.Movie
.GetInput(Global.Emulator.Frame)
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
for (int i = 0; i < Pads.Count; i++)
{
switch (Global.Emulator.SystemId)
{
case "NES":
Pads[0].SetButtons(str.Substring(3, 8));
Pads[1].SetButtons(str.Substring(12, 8));
Pads[2].SetButtons(str[1].ToString());
break;
case "A26":
Pads[0].SetButtons(str.Substring(4, 5));
Pads[1].SetButtons(str.Substring(10, 5));
Pads[2].SetButtons(str.Substring(1, 2));
break;
case "SMS":
case "GG":
case "SG":
Pads[0].SetButtons(str.Substring(1, 6));
Pads[1].SetButtons(str.Substring(8, 6));
Pads[2].SetButtons(str.Substring(15, 2));
break;
case "PCE":
case "SGX":
Pads[0].SetButtons(str.Substring(3, 8));
Pads[1].SetButtons(str.Substring(12, 8));
Pads[2].SetButtons(str.Substring(21, 8));
Pads[3].SetButtons(str.Substring(30, 8));
break;
case "TI83":
Pads[0].SetButtons(str.Substring(2, 50));
break;
case "SNES":
Pads[0].SetButtons(str.Substring(3, 12));
Pads[1].SetButtons(str.Substring(16, 12));
Pads[2].SetButtons(str.Substring(29, 12));
Pads[3].SetButtons(str.Substring(42, 12));
break;
case "GEN":
Pads[0].SetButtons(str.Substring(3, 8));
Pads[1].SetButtons(str.Substring(12, 8));
break;
case "GB":
Pads[0].SetButtons(str.Substring(3, 8));
break;
case "Coleco":
Pads[0].SetButtons(str.Substring(1, 18));
Pads[1].SetButtons(str.Substring(20, 18));
break;
case "C64":
break;
case "N64":
Pads[0].SetButtons(str.Substring(3, 23));
Pads[1].SetButtons(str.Substring(27, 23));
Pads[2].SetButtons(str.Substring(51, 23));
Pads[3].SetButtons(str.Substring(75, 23));
break;
}
Pads[i].SetButtons(sections[i]);
}
}
else if (!Global.Config.VirtualPadSticky)
@ -136,7 +90,7 @@ namespace BizHawk.Client.EmuHawk
private void VirtualPadForm_Load(object sender, EventArgs e)
{
LoadConfigSettings();
LoadPads();
LoadStartingPads();
}
private void LoadConfigSettings()
@ -165,31 +119,32 @@ namespace BizHawk.Client.EmuHawk
Global.Config.VirtualPadSettings.Height = Bottom - Top;
}
private void LoadPads()
private void LoadStartingPads()
{
// Order matters! Add them in the of the mnemonics
switch (Global.Emulator.SystemId)
{
case "A26":
ControllerBox.Controls.Add(new VirtualPadA26 { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadA26Control { Location = new Point(8, 109) });
ControllerBox.Controls.Add(new VirtualPadA26 { Location = new Point(8, 19), Controller = "P1" });
break;
case "A78":
ControllerBox.Controls.Add(new VirtualPadA78 { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadA78Control { Location = new Point(8, 125) });
ControllerBox.Controls.Add(new VirtualPadA78 { Location = new Point(8, 19), Controller = "P1" });
break;
case "NES":
ControllerBox.Controls.Add(new VirtualPadNES { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadNESControl { Location = new Point(8, 109) });
ControllerBox.Controls.Add(new VirtualPadNES { Location = new Point(8, 19), Controller = "P1" });
break;
case "N64":
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadN64Control { Location = new Point(8, 350) });
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(8, 19), Controller = "P1" });
break;
case "SMS":
case "SG":
case "GG":
ControllerBox.Controls.Add(new VirtualPadSMSControl { Location = new Point(8, 109) });
ControllerBox.Controls.Add(new VirtualPadSMS { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadSMSControl { Location = new Point(8, 109) });
break;
case "PCE":
case "PCECD":
@ -197,32 +152,32 @@ namespace BizHawk.Client.EmuHawk
ControllerBox.Controls.Add(new VirtualPadPCE { Location = new Point(8, 19), Controller = "P1" });
break;
case "SNES":
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadSNESControl { Location = new Point(8, 170) });
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(8, 19), Controller = "P1" });
break;
case "GB":
case "GBC":
ControllerBox.Controls.Add(new VirtualPadGBControl { Location = new Point(8, 109) });
ControllerBox.Controls.Add(new VirtualPadGB { Location = new Point(8, 19), Controller = string.Empty });
ControllerBox.Controls.Add(new VirtualPadGBControl { Location = new Point(8, 109) });
break;
case "GBA":
ControllerBox.Controls.Add(new VirtualPadGBA { Location = new Point(8, 19), Controller = string.Empty });
break;
case "GEN":
ControllerBox.Controls.Add(new VirtualPadGen6Button { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadNESControl { Location = new Point(8, 105) });
ControllerBox.Controls.Add(new VirtualPadGen6Button { Location = new Point(8, 19), Controller = "P1" });
break;
case "Coleco":
var coleco1 = new VirtualPadColeco { Location = new Point(8, 19), Controller = "P1" };
ControllerBox.Controls.Add(coleco1);
break;
case "C64":
ControllerBox.Controls.Add(new VirtualPadC64Keyboard { Location = new Point(8, 19) });
ControllerBox.Controls.Add(new VirtualPadA26 { Location = new Point(8, 159), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadC64Keyboard { Location = new Point(8, 19) });
break;
case "SAT":
ControllerBox.Controls.Add(new VirtualPadSaturn { Location = new Point(8, 19), Controller = "P1" });
ControllerBox.Controls.Add(new VirtualPadSaturnControl { Location = new Point(8, 125) });
ControllerBox.Controls.Add(new VirtualPadSaturn { Location = new Point(8, 19), Controller = "P1" });
break;
}
@ -237,6 +192,67 @@ namespace BizHawk.Client.EmuHawk
}
}
private void LoadExtraPads()
{
switch (Global.Emulator.SystemId)
{
case "A26":
ControllerBox.Controls.Add(new VirtualPadA26 { Location = new Point(188, 19), Controller = "P2" });
break;
case "A78":
ControllerBox.Controls.Add(new VirtualPadA78 { Location = new Point(150, 19), Controller = "P2" });
break;
case "NES":
ControllerBox.Controls.Add(new VirtualPadNES { Location = new Point(188, 19), Controller = "P2" });
break;
case "N64":
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(208, 19), Controller = "P2" });
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(408, 19), Controller = "P3" });
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(608, 19), Controller = "P4" });
break;
case "SMS":
case "SG":
case "GG":
ControllerBox.Controls.Add(new VirtualPadSMS { Location = new Point(188, 19), Controller = "P2" });
break;
case "PCE":
case "PCECD":
case "SGX":
ControllerBox.Controls.Add(new VirtualPadPCE { Location = new Point(188, 19), Controller = "P2" });
ControllerBox.Controls.Add(new VirtualPadPCE { Location = new Point(8, 109), Controller = "P3" });
ControllerBox.Controls.Add(new VirtualPadPCE { Location = new Point(188, 109), Controller = "P4" });
break;
case "SNES":
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(188, 19), Controller = "P2" });
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(8, 95), Controller = "P3" });
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(188, 95), Controller = "P4" });
break;
case "GB":
case "GBC":
ControllerBox.Controls.Add(new VirtualPadGB { Location = new Point(8, 19), Controller = string.Empty });
ControllerBox.Controls.Add(new VirtualPadGBControl { Location = new Point(8, 109) });
break;
case "GBA":
ControllerBox.Controls.Add(new VirtualPadGBA { Location = new Point(8, 19), Controller = string.Empty });
break;
case "GEN":
ControllerBox.Controls.Add(new VirtualPadGen6Button { Location = new Point(195, 19), Controller = "P2" });
break;
case "Coleco":
var coleco2 = new VirtualPadColeco { Location = new Point(130, 19), Controller = "P2" };
ControllerBox.Controls.Add(coleco2);
break;
case "C64":
ControllerBox.Controls.Add(new VirtualPadA26 { Location = new Point(218, 159), Controller = "P2" });
break;
case "SAT":
ControllerBox.Controls.Add(new VirtualPadSaturn { Location = new Point(213, 19), Controller = "P2" });
break;
}
_multiplayerMode = true;
}
public void BumpAnalogValue(int? dx, int? dy) // TODO: multi-player
{
// TODO: make an analog flag in virtualpads that have it, and check the virtualpads loaded, instead of doing this hardcoded
@ -333,63 +349,7 @@ namespace BizHawk.Client.EmuHawk
private void MultiplayerModeMenuItem_Click(object sender, EventArgs e)
{
switch (Global.Emulator.SystemId)
{
case "A26":
ControllerBox.Controls.Add(new VirtualPadA26 { Location = new Point(188, 19), Controller = "P2" });
break;
case "A78":
ControllerBox.Controls.Add(new VirtualPadA78 { Location = new Point(150, 19), Controller = "P2" });
break;
case "NES":
ControllerBox.Controls.Add(new VirtualPadNES { Location = new Point(188, 19), Controller = "P2" });
break;
case "N64":
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(208, 19), Controller = "P2" });
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(408, 19), Controller = "P3" });
ControllerBox.Controls.Add(new VirtualPadN64 { Location = new Point(608, 19), Controller = "P4" });
break;
case "SMS":
case "SG":
case "GG":
ControllerBox.Controls.Add(new VirtualPadSMS { Location = new Point(188, 19), Controller = "P2" });
break;
case "PCE":
case "PCECD":
case "SGX":
ControllerBox.Controls.Add(new VirtualPadPCE { Location = new Point(188, 19), Controller = "P2" });
ControllerBox.Controls.Add(new VirtualPadPCE { Location = new Point(8, 109), Controller = "P3" });
ControllerBox.Controls.Add(new VirtualPadPCE { Location = new Point(188, 109), Controller = "P4" });
break;
case "SNES":
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(188, 19), Controller = "P2" });
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(8, 95), Controller = "P3" });
ControllerBox.Controls.Add(new VirtualPadSNES { Location = new Point(188, 95), Controller = "P4" });
break;
case "GB":
case "GBC":
ControllerBox.Controls.Add(new VirtualPadGB { Location = new Point(8, 19), Controller = string.Empty });
ControllerBox.Controls.Add(new VirtualPadGBControl { Location = new Point(8, 109) });
break;
case "GBA":
ControllerBox.Controls.Add(new VirtualPadGBA { Location = new Point(8, 19), Controller = string.Empty });
break;
case "GEN":
ControllerBox.Controls.Add(new VirtualPadGen6Button { Location = new Point(195, 19), Controller = "P2" });
break;
case "Coleco":
var coleco2 = new VirtualPadColeco { Location = new Point(130, 19), Controller = "P2" };
ControllerBox.Controls.Add(coleco2);
break;
case "C64":
ControllerBox.Controls.Add(new VirtualPadA26 { Location = new Point(218, 159), Controller = "P2" });
break;
case "SAT":
ControllerBox.Controls.Add(new VirtualPadSaturn { Location = new Point(213, 19), Controller = "P2" });
break;
}
_multiplayerMode = true;
LoadExtraPads();
}
private void PadsSubMenu_DropDownOpened(object sender, EventArgs e)