2011-01-29 00:10:08 +00:00
using System ;
using System.Collections.Generic ;
2011-02-19 20:31:32 +00:00
using System.Collections ;
2011-01-29 00:10:08 +00:00
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
2012-03-24 19:45:50 +00:00
using System.Reflection ;
2011-01-29 00:10:08 +00:00
using System.Text ;
using System.Windows.Forms ;
namespace BizHawk.MultiClient
{
2011-06-19 03:35:57 +00:00
public partial class InputConfig : Form
{
int prevWidth ;
int prevHeight ;
const string ControllerStr = "Configure Controllers - " ;
2012-03-24 19:45:50 +00:00
public static readonly Dictionary < string , string [ ] > CONTROLS = new Dictionary < string , string [ ] > ( )
{
2012-03-25 07:00:21 +00:00
{ "Atari" , new string [ 5 ] { "Up" , "Down" , "Left" , "Right" , "Button" } } ,
2012-03-30 22:03:08 +00:00
{ "AtariConsoleButtons" , new string [ 2 ] { "Reset" , "Select" } } ,
2012-03-25 07:10:11 +00:00
{ "Gameboy" , new string [ 8 ] { "Up" , "Down" , "Left" , "Right" , "A" , "B" , "Select" , "Start" } } ,
2012-03-24 19:45:50 +00:00
{ "NES" , new string [ 8 ] { "Up" , "Down" , "Left" , "Right" , "A" , "B" , "Select" , "Start" } } ,
2012-09-15 19:47:58 +00:00
{ "SNES" , new string [ ] { "Up" , "Down" , "Left" , "Right" , "B" , "A" , "X" , "Y" , "L" , "R" , "Select" , "Start" } } ,
2012-03-25 02:11:26 +00:00
{ "PC Engine / SuperGrafx" , new string [ 8 ] { "Up" , "Down" , "Left" , "Right" , "I" , "II" , "Run" , "Select" } } ,
2012-03-25 06:42:31 +00:00
{ "Sega Genesis" , new string [ 8 ] { "Up" , "Down" , "Left" , "Right" , "A" , "B" , "C" , "Start" } } ,
2012-03-25 01:32:44 +00:00
{ "SMS / GG / SG-1000" , new string [ 8 ] { "Up" , "Down" , "Left" , "Right" , "B1" , "B2" , "Pause" , "Reset" } } ,
2012-09-04 00:20:36 +00:00
2012-03-24 19:45:50 +00:00
{
// TODO: display shift / alpha names too, Also order these like on the calculator
2012-03-25 02:36:20 +00:00
"TI-83" , new string [ 50 ] { "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "." , "ON" ,
2012-03-24 19:45:50 +00:00
"ENTER" , "Up" , "Down" , "Left" , "Right" , "+" , "-" , "Multiply" , "Divide" , "CLEAR" , "^" , "-" , "(" , ")" , "TAN" ,
"VARS" , "COS" , "PRGM" , "STAT" , "Matrix" , "X" , "STO->" , "LN" , "LOG" , "^2" , "^-1" , "MATH" , "ALPHA" , "GRAPH" ,
"TRACE" , "ZOOM" , "WINDOW" , "Y" , "2nd" , "MODE" , "Del" , "," , "SIN" }
}
} ;
2012-03-25 06:05:13 +00:00
public static readonly string [ ] TI83CONTROLS = new string [ 50 ] {
"_0" , "_1" , "_2" , "_3" , "_4" , "_5" , "_6" , "_7" , "_8" , "_9" , "DOT" , "ON" , "ENTER" , "UP" , "DOWN" , "LEFT" , "RIGHT" ,
"PLUS" , "MINUS" , "MULTIPLY" , "DIVIDE" , "CLEAR" , "EXP" , "DASH" , "PARAOPEN" , "PARACLOSE" , "TAN" , "VARS" , "COS" ,
"PRGM" , "STAT" , "MATRIX" , "X" , "STO" , "LN" , "LOG" , "SQUARED" , "NEG1" , "MATH" , "ALPHA" , "GRAPH" , "TRACE" , "ZOOM" ,
"WINDOW" , "Y" , "SECOND" , "MODE" , "DEL" , "COMMA" , "SIN"
} ;
2012-03-25 01:32:44 +00:00
public static readonly Dictionary < string , int > PADS = new Dictionary < string , int > ( )
{
2012-09-04 00:20:36 +00:00
{ "Atari" , 2 } , { "Gameboy" , 1 } , { "NES" , 4 } , { "PC Engine / SuperGrafx" , 5 } , { "Sega Genesis" , 1 } , { "SMS / GG / SG-1000" , 2 } ,
{ "SNES" , 4 } ,
2012-03-25 06:42:31 +00:00
{ "TI-83" , 1 }
2012-03-25 01:32:44 +00:00
} ;
2012-09-10 17:49:33 +00:00
private List < KeyValuePair < string , string > > HotkeyMappingList = new List < KeyValuePair < string , string > > ( ) ; //A list of all button mappings and the hotkey they are assigned to
2011-06-19 03:35:57 +00:00
private ArrayList Labels ;
private ArrayList TextBoxes ;
private string CurSelectConsole ;
private int CurSelectController ;
private bool Changed ;
2012-03-25 00:39:51 +00:00
2011-06-19 03:35:57 +00:00
public InputConfig ( )
{
InitializeComponent ( ) ;
Labels = new ArrayList ( ) ;
TextBoxes = new ArrayList ( ) ;
Changed = false ;
}
2011-01-29 00:10:08 +00:00
2011-07-10 19:50:59 +00:00
protected override void OnShown ( EventArgs e )
{
Input . Instance . EnableIgnoreModifiers = true ;
base . OnShown ( e ) ;
}
protected override void OnClosed ( EventArgs e )
{
base . OnClosed ( e ) ;
Input . Instance . EnableIgnoreModifiers = false ;
}
2012-03-25 00:39:51 +00:00
private void Do ( string platform )
2011-06-19 03:35:57 +00:00
{
Label TempLabel ;
InputWidget TempTextBox ;
2012-03-25 00:39:51 +00:00
this . Text = ControllerStr + platform ;
object [ ] controller = null ;
object [ ] mainController = null ;
object [ ] autoController = null ;
switch ( platform )
{
2012-03-25 07:00:21 +00:00
case "Atari" :
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . atari_controller ;
controller = Global . Config . Atari2600Controller ;
autoController = Global . Config . Atari2600AutoController ;
break ;
2012-03-25 07:10:11 +00:00
case "Gameboy" :
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . GBController ;
2012-05-18 18:28:12 +00:00
controller = Global . Config . GBController ;
autoController = Global . Config . GBAutoController ;
2012-03-25 06:42:31 +00:00
break ;
2012-03-25 00:39:51 +00:00
case "NES" :
2012-09-15 17:33:21 +00:00
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . NES_Controller ;
2012-03-25 00:39:51 +00:00
controller = Global . Config . NESController ;
autoController = Global . Config . NESAutoController ;
break ;
2012-03-25 02:11:26 +00:00
case "PC Engine / SuperGrafx" :
2012-03-25 01:58:33 +00:00
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . PCEngineController ;
controller = Global . Config . PCEController ;
autoController = Global . Config . PCEAutoController ;
break ;
2012-03-25 07:10:11 +00:00
case "Sega Genesis" :
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . GENController ;
controller = Global . Config . GenesisController ;
autoController = Global . Config . GenesisAutoController ;
break ;
2012-03-25 01:32:44 +00:00
case "SMS / GG / SG-1000" :
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . SMSController ;
controller = Global . Config . SMSController ;
autoController = Global . Config . SMSAutoController ;
break ;
2012-03-25 02:36:20 +00:00
case "TI-83" :
2012-09-15 17:33:21 +00:00
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . TI83_Controller ;
2012-03-25 02:36:20 +00:00
controller = Global . Config . TI83Controller ;
break ;
2012-09-04 00:20:36 +00:00
case "SNES" :
2012-09-15 17:33:21 +00:00
ControllerImage . Image = BizHawk . MultiClient . Properties . Resources . SNES_Controller ;
2012-09-04 00:20:36 +00:00
controller = Global . Config . SNESController ;
2012-09-26 01:20:11 +00:00
autoController = Global . Config . SNESAutoController ;
2012-09-04 00:20:36 +00:00
break ;
2012-03-25 00:39:51 +00:00
default :
return ;
}
2012-03-25 01:58:33 +00:00
mainController = controller ;
2011-06-19 03:35:57 +00:00
int jpad = this . ControllComboBox . SelectedIndex ;
2012-03-30 22:03:08 +00:00
if ( jpad > = PADS [ platform ] * 2 ) //Not joypad or auto-joypad, must be special category (adelikat: I know this is hacky but so is the rest of this file)
2011-08-09 01:38:51 +00:00
{
2012-03-30 22:03:08 +00:00
switch ( platform )
{
case "Atari" :
IDX_CONTROLLERENABLED . Checked = Global . Config . Atari2600ConsoleButtons [ 0 ] . Enabled ;
controller = Global . Config . Atari2600ConsoleButtons ;
break ;
}
platform + = "ConsoleButtons" ;
2012-03-25 00:39:51 +00:00
}
2012-03-30 22:03:08 +00:00
else
2012-03-25 00:39:51 +00:00
{
2012-03-30 22:03:08 +00:00
if ( jpad > = PADS [ platform ] )
{
jpad - = PADS [ platform ] ;
controller = autoController ;
}
switch ( platform )
{
case "Atari" :
IDX_CONTROLLERENABLED . Checked = ( ( Atari2600ControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
case "Gameboy" :
2012-05-18 22:57:05 +00:00
IDX_CONTROLLERENABLED . Checked = ( ( GBControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
2012-03-30 22:03:08 +00:00
case "NES" :
IDX_CONTROLLERENABLED . Checked = ( ( NESControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
2012-09-04 00:20:36 +00:00
case "SNES" :
IDX_CONTROLLERENABLED . Checked = ( ( SNESControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
2012-03-30 22:03:08 +00:00
case "PC Engine / SuperGrafx" :
IDX_CONTROLLERENABLED . Checked = ( ( PCEControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
case "Sega Genesis" :
IDX_CONTROLLERENABLED . Checked = ( ( GenControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
case "SMS / GG / SG-1000" :
IDX_CONTROLLERENABLED . Checked = ( ( SMSControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
case "TI-83" :
IDX_CONTROLLERENABLED . Checked = ( ( TI83ControllerTemplate ) mainController [ jpad ] ) . Enabled ;
break ;
}
2011-08-09 01:38:51 +00:00
}
2011-06-19 03:35:57 +00:00
Labels . Clear ( ) ;
TextBoxes . Clear ( ) ;
2012-03-25 06:05:13 +00:00
int row = 0 ;
int col = 0 ;
2012-03-25 00:39:51 +00:00
for ( int button = 0 ; button < CONTROLS [ platform ] . Length ; button + + )
2011-06-19 03:35:57 +00:00
{
TempLabel = new Label ( ) ;
2012-03-25 00:39:51 +00:00
TempLabel . Text = CONTROLS [ platform ] [ button ] ;
2012-03-25 06:05:13 +00:00
int xoffset = ( col * 156 ) ;
int yoffset = ( row * 24 ) ;
TempLabel . Location = new Point ( 8 + xoffset , 20 + yoffset ) ;
2011-06-19 03:35:57 +00:00
Labels . Add ( TempLabel ) ;
2012-09-10 17:49:33 +00:00
TempTextBox = new InputWidget ( HotkeyMappingList ) ;
2012-03-25 06:05:13 +00:00
TempTextBox . Location = new Point ( 64 + xoffset , 20 + yoffset ) ;
2011-06-19 03:35:57 +00:00
TextBoxes . Add ( TempTextBox ) ;
2012-03-25 00:39:51 +00:00
object field = null ;
string fieldName = CONTROLS [ platform ] [ button ] ;
switch ( platform )
{
2012-03-30 22:03:08 +00:00
case "AtariConsoleButtons" :
Atari2600ConsoleButtonsTemplate o = ( Atari2600ConsoleButtonsTemplate ) controller [ 0 ] ;
field = o . GetType ( ) . GetField ( fieldName ) . GetValue ( o ) ;
break ;
2012-03-25 07:00:21 +00:00
case "Atari" :
{
Atari2600ControllerTemplate obj = ( Atari2600ControllerTemplate ) controller [ jpad ] ;
field = obj . GetType ( ) . GetField ( fieldName ) . GetValue ( obj ) ;
break ;
}
2012-03-25 07:10:11 +00:00
case "Gameboy" :
2012-05-18 22:57:05 +00:00
{
GBControllerTemplate obj = ( GBControllerTemplate ) controller [ jpad ] ;
field = obj . GetType ( ) . GetField ( fieldName ) . GetValue ( obj ) ;
break ;
}
2012-03-25 00:39:51 +00:00
case "NES" :
2012-03-25 01:32:44 +00:00
{
2012-03-25 00:39:51 +00:00
NESControllerTemplate obj = ( NESControllerTemplate ) controller [ jpad ] ;
field = obj . GetType ( ) . GetField ( fieldName ) . GetValue ( obj ) ;
break ;
2012-03-25 01:32:44 +00:00
}
2012-09-04 00:20:36 +00:00
case "SNES" :
{
SNESControllerTemplate obj = ( SNESControllerTemplate ) controller [ jpad ] ;
field = obj . GetType ( ) . GetField ( fieldName ) . GetValue ( obj ) ;
break ;
}
2012-03-25 02:11:26 +00:00
case "PC Engine / SuperGrafx" :
2012-03-25 01:58:33 +00:00
{
PCEControllerTemplate obj = ( PCEControllerTemplate ) controller [ jpad ] ;
field = obj . GetType ( ) . GetField ( fieldName ) . GetValue ( obj ) ;
break ;
}
2012-03-25 07:10:11 +00:00
case "Sega Genesis" :
{
GenControllerTemplate obj = ( GenControllerTemplate ) controller [ jpad ] ;
field = obj . GetType ( ) . GetField ( fieldName ) . GetValue ( obj ) ;
break ;
}
2012-03-25 01:32:44 +00:00
case "SMS / GG / SG-1000" :
{
if ( button < 6 )
{
SMSControllerTemplate obj = ( SMSControllerTemplate ) controller [ jpad ] ;
field = obj . GetType ( ) . GetField ( fieldName ) . GetValue ( obj ) ;
}
else if ( button = = 6 )
field = Global . Config . SmsPause ;
else
field = Global . Config . SmsReset ;
break ;
}
2012-03-25 02:36:20 +00:00
case "TI-83" :
{
TI83ControllerTemplate obj = ( TI83ControllerTemplate ) controller [ jpad ] ;
2012-03-25 06:05:13 +00:00
field = obj . GetType ( ) . GetField ( TI83CONTROLS [ button ] ) . GetValue ( obj ) ;
2012-03-25 02:36:20 +00:00
break ;
}
2012-03-25 00:39:51 +00:00
}
TempTextBox . SetBindings ( ( string ) field ) ;
2011-06-19 03:35:57 +00:00
ButtonsGroupBox . Controls . Add ( TempTextBox ) ;
ButtonsGroupBox . Controls . Add ( TempLabel ) ;
2012-03-25 06:05:13 +00:00
row + + ;
if ( row > 16 )
{
row = 0 ;
col + + ;
}
2011-06-19 03:35:57 +00:00
}
Changed = true ;
}
2011-09-11 04:23:35 +00:00
2012-03-25 00:39:51 +00:00
private void Update ( int prev , string platform )
2011-06-19 03:35:57 +00:00
{
2012-03-30 22:03:08 +00:00
if ( platform = = "Atari" & & prev = = 4 ) //adelikat: very hacky I know
platform + = "ConsoleButtons" ;
2011-06-19 03:35:57 +00:00
ButtonsGroupBox . Controls . Clear ( ) ;
2012-03-25 00:39:51 +00:00
object [ ] controller = null ;
object [ ] mainController = null ;
object [ ] autoController = null ;
switch ( platform )
2011-08-09 01:38:51 +00:00
{
2012-03-30 22:03:08 +00:00
case "AtariConsoleButtons" :
controller = Global . Config . Atari2600ConsoleButtons ;
break ;
2012-03-25 07:00:21 +00:00
case "Atari" :
controller = Global . Config . Atari2600Controller ;
autoController = Global . Config . Atari2600AutoController ;
break ;
2012-03-25 07:10:11 +00:00
case "Gameboy" :
2012-05-18 18:28:12 +00:00
controller = Global . Config . GBController ;
autoController = Global . Config . GBAutoController ;
2012-03-25 06:42:31 +00:00
break ;
2012-03-25 00:39:51 +00:00
case "NES" :
controller = Global . Config . NESController ;
autoController = Global . Config . NESAutoController ;
break ;
2012-09-04 00:20:36 +00:00
case "SNES" :
controller = Global . Config . SNESController ;
2012-09-26 01:20:11 +00:00
autoController = Global . Config . SNESAutoController ;
2012-09-04 00:20:36 +00:00
break ;
2012-03-25 02:11:26 +00:00
case "PC Engine / SuperGrafx" :
2012-03-25 01:58:33 +00:00
controller = Global . Config . PCEController ;
autoController = Global . Config . PCEAutoController ;
break ;
2012-03-25 07:10:11 +00:00
case "Sega Genesis" :
controller = Global . Config . GenesisController ;
autoController = Global . Config . GenesisAutoController ;
break ;
2012-03-25 01:32:44 +00:00
case "SMS / GG / SG-1000" :
controller = Global . Config . SMSController ;
autoController = Global . Config . SMSAutoController ;
break ;
2012-03-25 06:05:13 +00:00
case "TI-83" :
controller = Global . Config . TI83Controller ;
break ;
2012-03-25 00:39:51 +00:00
default :
return ;
}
2012-03-25 01:58:33 +00:00
mainController = controller ;
2012-03-30 23:34:38 +00:00
if ( platform = = "AtariConsoleButtons" )
{
prev = 0 ;
}
else if ( prev > = PADS [ platform ] )
2012-03-25 00:39:51 +00:00
{
2012-03-25 01:32:44 +00:00
prev - = PADS [ platform ] ;
2012-03-25 00:39:51 +00:00
controller = autoController ;
2011-08-09 01:38:51 +00:00
}
2012-03-25 01:32:44 +00:00
switch ( platform )
{
2012-03-30 23:34:38 +00:00
case "AtariConsoleButtons" :
( ( Atari2600ConsoleButtonsTemplate ) mainController [ 0 ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 07:00:21 +00:00
case "Atari" :
( ( Atari2600ControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 07:10:11 +00:00
case "Gameboy" :
2012-05-18 22:57:05 +00:00
( ( GBControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 01:32:44 +00:00
case "NES" :
( ( NESControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-09-04 00:20:36 +00:00
case "SNES" :
( ( SNESControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 02:11:26 +00:00
case "PC Engine / SuperGrafx" :
2012-03-25 01:58:33 +00:00
( ( PCEControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 07:10:11 +00:00
case "Sega Genesis" :
( ( GenControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 01:32:44 +00:00
case "SMS / GG / SG-1000" :
( ( SMSControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 06:05:13 +00:00
case "TI-83" :
( ( TI83ControllerTemplate ) mainController [ prev ] ) . Enabled = IDX_CONTROLLERENABLED . Checked ;
break ;
2012-03-25 01:32:44 +00:00
}
2012-03-25 00:39:51 +00:00
for ( int button = 0 ; button < CONTROLS [ platform ] . Length ; button + + )
2011-08-09 01:38:51 +00:00
{
2012-03-24 21:06:47 +00:00
InputWidget TempBox = TextBoxes [ button ] as InputWidget ;
2012-03-25 00:39:51 +00:00
object field = null ;
string fieldName = CONTROLS [ platform ] [ button ] ;
switch ( platform )
{
2012-03-30 22:03:08 +00:00
case "AtariConsoleButtons" :
Atari2600ConsoleButtonsTemplate o = ( Atari2600ConsoleButtonsTemplate ) controller [ 0 ] ;
FieldInfo buttonF = o . GetType ( ) . GetField ( fieldName ) ;
field = buttonF . GetValue ( o ) ;
2012-09-15 19:47:58 +00:00
buttonF . SetValue ( o , TempBox . Text ) ;
2012-03-30 22:03:08 +00:00
break ;
2012-03-25 07:00:21 +00:00
case "Atari" :
{
Atari2600ControllerTemplate obj = ( Atari2600ControllerTemplate ) controller [ prev ] ;
FieldInfo buttonField = obj . GetType ( ) . GetField ( fieldName ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-03-25 07:00:21 +00:00
break ;
}
2012-03-25 07:10:11 +00:00
case "Gameboy" :
2012-05-18 22:57:05 +00:00
{
GBControllerTemplate obj = ( GBControllerTemplate ) controller [ prev ] ;
FieldInfo buttonField = obj . GetType ( ) . GetField ( fieldName ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-05-18 22:57:05 +00:00
break ;
}
2012-03-25 07:10:11 +00:00
case "NES" :
2012-03-25 06:42:31 +00:00
{
2012-03-25 07:10:11 +00:00
NESControllerTemplate obj = ( NESControllerTemplate ) controller [ prev ] ;
2012-03-25 06:42:31 +00:00
FieldInfo buttonField = obj . GetType ( ) . GetField ( fieldName ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-03-25 06:42:31 +00:00
break ;
}
2012-09-04 00:20:36 +00:00
case "SNES" :
{
SNESControllerTemplate obj = ( SNESControllerTemplate ) controller [ prev ] ;
FieldInfo buttonField = obj . GetType ( ) . GetField ( fieldName ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-09-04 00:20:36 +00:00
break ;
}
2012-03-25 07:10:11 +00:00
case "PC Engine / SuperGrafx" :
2012-03-25 01:32:44 +00:00
{
2012-03-25 07:10:11 +00:00
PCEControllerTemplate obj = ( PCEControllerTemplate ) controller [ prev ] ;
2012-03-25 00:39:51 +00:00
FieldInfo buttonField = obj . GetType ( ) . GetField ( fieldName ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-03-25 00:39:51 +00:00
break ;
2012-03-25 01:32:44 +00:00
}
2012-03-25 07:10:11 +00:00
case "Sega Genesis" :
2012-03-25 01:58:33 +00:00
{
2012-03-25 07:10:11 +00:00
GenControllerTemplate obj = ( GenControllerTemplate ) controller [ prev ] ;
2012-03-25 01:58:33 +00:00
FieldInfo buttonField = obj . GetType ( ) . GetField ( fieldName ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-03-25 01:58:33 +00:00
break ;
}
2012-03-25 01:32:44 +00:00
case "SMS / GG / SG-1000" :
{
if ( button < 6 )
{
SMSControllerTemplate obj = ( SMSControllerTemplate ) controller [ prev ] ;
FieldInfo buttonField = obj . GetType ( ) . GetField ( fieldName ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-03-25 01:32:44 +00:00
}
else if ( button = = 6 )
2012-09-15 19:47:58 +00:00
Global . Config . SmsPause = TempBox . Text ;
2012-03-25 01:32:44 +00:00
else
2012-09-15 19:47:58 +00:00
Global . Config . SmsReset = TempBox . Text ;
2012-03-25 01:32:44 +00:00
break ;
}
2012-03-25 06:05:13 +00:00
case "TI-83" :
{
TI83ControllerTemplate obj = ( TI83ControllerTemplate ) controller [ prev ] ;
FieldInfo buttonField = obj . GetType ( ) . GetField ( TI83CONTROLS [ button ] ) ;
field = buttonField . GetValue ( obj ) ;
2012-09-15 19:47:58 +00:00
buttonField . SetValue ( obj , TempBox . Text ) ;
2012-03-25 06:05:13 +00:00
break ;
}
2012-03-25 00:39:51 +00:00
}
2011-08-09 01:38:51 +00:00
TempBox . Dispose ( ) ;
2012-03-24 21:06:47 +00:00
Label TempLabel = Labels [ button ] as Label ;
2011-06-19 03:35:57 +00:00
TempLabel . Dispose ( ) ;
}
2012-09-26 01:28:48 +00:00
Global . OSD . AddMessage ( "Controller settings saved" ) ;
2011-06-19 03:35:57 +00:00
}
2011-09-11 04:23:35 +00:00
2011-06-19 03:35:57 +00:00
private void InputConfig_Load ( object sender , EventArgs e )
{
2012-10-20 13:40:58 +00:00
SystemComboBox . Items . Add ( "Atari" ) ; //TODO: add this to the designer instead
2012-09-10 17:49:33 +00:00
HotkeyMappingList = Global . ClientControls . MappingList ( ) ;
2012-03-21 02:44:01 +00:00
2011-07-09 18:01:46 +00:00
AutoTab . Checked = Global . Config . InputConfigAutoTab ;
SetAutoTab ( ) ;
2011-06-19 03:35:57 +00:00
prevWidth = Size . Width ;
prevHeight = Size . Height ;
AllowLR . Checked = Global . Config . AllowUD_LR ;
2011-04-24 23:22:52 +00:00
2011-06-19 03:35:57 +00:00
if ( Global . Game ! = null )
2011-09-11 04:23:35 +00:00
{
2012-03-25 00:54:40 +00:00
Dictionary < string , string > systems = new Dictionary < string , string > ( )
2011-04-06 04:57:59 +00:00
{
2012-03-25 00:54:40 +00:00
{ "A26" , "Atari" } , { "GB" , "Gameboy" } , { "GEN" , "Sega Genesis" } , { "GG" , "SMS / GG / SG-1000" } , { "NES" , "NES" } ,
2012-10-07 14:52:03 +00:00
{ "SNES" , "SNES" } , { "GBC" , "Gameboy" } ,
2012-03-25 02:11:26 +00:00
{ "PCE" , "PC Engine / SuperGrafx" } , { "SG" , "SMS / GG / SG-1000" } , { "SGX" , "PC Engine / SuperGrafx" } ,
2012-03-25 01:58:33 +00:00
{ "SMS" , "SMS / GG / SG-1000" } , { "TI83" , "TI-83" }
2012-03-25 00:54:40 +00:00
} ;
if ( systems . ContainsKey ( Global . Game . System ) )
this . SystemComboBox . SelectedIndex = SystemComboBox . Items . IndexOf ( systems [ Global . Game . System ] ) ;
else
this . SystemComboBox . SelectedIndex = 0 ;
2011-09-11 04:23:35 +00:00
}
2011-06-19 03:35:57 +00:00
}
2011-09-11 04:23:35 +00:00
2011-06-19 03:35:57 +00:00
private void OK_Click ( object sender , EventArgs e )
{
if ( Changed )
{
UpdateAll ( ) ;
}
2011-04-06 05:43:59 +00:00
this . DialogResult = DialogResult . OK ;
2011-06-19 03:35:57 +00:00
Global . Config . AllowUD_LR = AllowLR . Checked ;
this . Close ( ) ;
}
2011-01-29 00:10:08 +00:00
2011-06-19 03:35:57 +00:00
private void Cancel_Click ( object sender , EventArgs e )
{
2012-09-27 00:14:51 +00:00
Global . OSD . AddMessage ( "Controller config aborted" ) ;
2011-06-19 03:35:57 +00:00
this . Close ( ) ;
}
2011-01-29 01:25:57 +00:00
2011-06-19 03:35:57 +00:00
private void SystemComboBox_SelectedIndexChanged ( object sender , EventArgs e )
{
if ( Changed )
{
UpdateAll ( ) ;
}
2012-03-25 06:42:31 +00:00
int joypads = PADS [ this . SystemComboBox . SelectedItem . ToString ( ) ] ;
if ( this . SystemComboBox . SelectedItem . ToString ( ) ! = "TI-83" )
2011-06-19 03:35:57 +00:00
{
2012-03-25 06:42:31 +00:00
this . Width = prevWidth ;
this . Height = prevHeight ;
}
else
{
if ( this . Width < 700 )
this . Width = 700 ;
if ( this . Height < 580 )
this . Height = 580 ;
2011-06-19 03:35:57 +00:00
}
ControllComboBox . Items . Clear ( ) ;
for ( int i = 0 ; i < joypads ; i + + )
{
ControllComboBox . Items . Add ( string . Format ( "Joypad {0}" , i + 1 ) ) ;
}
2011-08-09 01:38:51 +00:00
for ( int i = 0 ; i < joypads ; i + + )
{
2011-08-09 02:16:46 +00:00
if ( this . SystemComboBox . SelectedItem . ToString ( ) ! = "TI-83" )
ControllComboBox . Items . Add ( string . Format ( "Autofire Joypad {0}" , i + 1 ) ) ;
2011-08-09 01:38:51 +00:00
}
2012-03-30 22:03:08 +00:00
if ( this . SystemComboBox . SelectedItem . ToString ( ) = = "Atari" )
{
ControllComboBox . Items . Add ( "Console" ) ;
}
2011-06-19 03:35:57 +00:00
ControllComboBox . SelectedIndex = 0 ;
CurSelectConsole = this . SystemComboBox . SelectedItem . ToString ( ) ;
CurSelectController = 0 ;
2011-09-11 04:23:35 +00:00
SetFocus ( ) ;
2012-07-30 00:43:40 +00:00
SetAutoTab ( ) ;
2011-06-19 03:35:57 +00:00
}
private void ControllComboBox_SelectedIndexChanged ( object sender , EventArgs e )
{
if ( Changed )
{
UpdateAll ( ) ;
}
2012-03-25 07:10:11 +00:00
Do ( SystemComboBox . SelectedItem . ToString ( ) ) ;
2011-06-19 03:35:57 +00:00
CurSelectController = ControllComboBox . SelectedIndex ;
2011-09-11 04:23:35 +00:00
SetFocus ( ) ;
2012-07-30 00:43:40 +00:00
SetAutoTab ( ) ;
2011-06-19 03:35:57 +00:00
}
private void UpdateAll ( )
{
2012-03-25 07:10:11 +00:00
Update ( CurSelectController , CurSelectConsole ) ;
2011-06-19 03:35:57 +00:00
Changed = false ;
}
2011-07-09 18:01:46 +00:00
private void AutoTab_CheckedChanged ( object sender , EventArgs e )
{
Global . Config . HotkeyConfigAutoTab = AutoTab . Checked ;
SetAutoTab ( ) ;
}
2011-09-11 04:23:35 +00:00
private void SetFocus ( )
{
for ( int x = 0 ; x < ButtonsGroupBox . Controls . Count ; x + + )
{
if ( ButtonsGroupBox . Controls [ x ] is InputWidget )
{
ButtonsGroupBox . Controls [ x ] . Focus ( ) ;
return ;
}
}
}
2011-07-09 18:01:46 +00:00
private void SetAutoTab ( )
{
for ( int x = 0 ; x < ButtonsGroupBox . Controls . Count ; x + + )
{
if ( ButtonsGroupBox . Controls [ x ] is InputWidget )
{
InputWidget w = ButtonsGroupBox . Controls [ x ] as InputWidget ;
w . AutoTab = AutoTab . Checked ;
}
}
}
2012-09-17 22:43:42 +00:00
private void clearMappingsToolStripMenuItem_Click ( object sender , EventArgs e )
{
for ( int i = 0 ; i < ButtonsGroupBox . Controls . Count ; i + + )
{
if ( ButtonsGroupBox . Controls [ i ] is InputWidget )
{
InputWidget w = ButtonsGroupBox . Controls [ i ] as InputWidget ;
w . EraseMappings ( ) ;
}
}
}
2012-09-23 22:42:27 +00:00
private void InputConfig_Shown ( object sender , EventArgs e )
{
SetFocus ( ) ;
}
2011-06-19 03:35:57 +00:00
}
2012-03-24 19:45:50 +00:00
}