@@ -6,6 +6,9 @@ namespace GHelper
6
6
public partial class Handheld : RForm
7
7
{
8
8
9
+ static string activeBinding = "" ;
10
+ static RButton ? activeButton ;
11
+
9
12
public Handheld ( )
10
13
{
11
14
InitializeComponent ( ) ;
@@ -41,80 +44,120 @@ public Handheld()
41
44
42
45
trackVibra . ValueChanged += Controller_Complete ;
43
46
44
- FillBinding ( "m1" , "M1" ) ;
45
- FillBinding ( "m2" , "M2" ) ;
47
+ ButtonBinding ( "m1" , "M1" , buttonM1 ) ;
48
+ ButtonBinding ( "m2" , "M2" , buttonM2 ) ;
46
49
47
- FillBinding ( "a" , "A" ) ;
48
- FillBinding ( "b" , "B" ) ;
49
- FillBinding ( "x" , "X" ) ;
50
- FillBinding ( "y" , "Y" ) ;
50
+ ButtonBinding ( "a" , "A" , buttonA ) ;
51
+ ButtonBinding ( "b" , "B" , buttonB ) ;
52
+ ButtonBinding ( "x" , "X" , buttonX ) ;
53
+ ButtonBinding ( "y" , "Y" , buttonY ) ;
51
54
52
- FillBinding ( "du" , "DPadUp" ) ;
53
- FillBinding ( "dd" , "DPadDown" ) ;
55
+ ButtonBinding ( "du" , "DPad Up" , buttonDPU ) ;
56
+ ButtonBinding ( "dd" , "DPad Down" , buttonDPD ) ;
54
57
55
- FillBinding ( "dl" , "DPadLeft" ) ;
56
- FillBinding ( "dr" , "DPadRight" ) ;
58
+ ButtonBinding ( "dl" , "DPad Left" , buttonDPL ) ;
59
+ ButtonBinding ( "dr" , "DPad Right" , buttonDPR ) ;
60
+
61
+ ButtonBinding ( "rt" , "Right Trigger" , buttonRT ) ;
62
+ ButtonBinding ( "lt" , "Left Trigger" , buttonLT ) ;
63
+
64
+ ButtonBinding ( "rb" , "Right Bumper" , buttonRB ) ;
65
+ ButtonBinding ( "lb" , "Left Bumper" , buttonLB ) ;
57
66
58
- FillBinding ( "rb ", "RBumper" ) ;
59
- FillBinding ( "lb ", "LBumper" ) ;
67
+ ButtonBinding ( "rs ", "Right Stick" , buttonRS ) ;
68
+ ButtonBinding ( "ll ", "Left Stick" , buttonLS ) ;
60
69
61
- FillBinding ( "rs" , "RStick" ) ;
62
- FillBinding ( "ll" , "LStick" ) ;
70
+ ButtonBinding ( "vb" , "View" , buttonView ) ;
71
+ ButtonBinding ( "mb" , "Menu" , buttonMenu ) ;
72
+
73
+ ComboBinding ( comboPrimary ) ;
74
+ ComboBinding ( comboSecondary ) ;
63
75
64
- FillBinding ( "vb" , "View" ) ;
65
- FillBinding ( "mb" , "Menu" ) ;
66
76
}
67
77
68
- private RComboBox ComboBinding ( string name , string value )
78
+ private void ComboBinding ( RComboBox combo )
69
79
{
70
- var combo = new RComboBox ( ) ;
71
- combo . BorderColor = Color . White ;
72
- combo . ButtonColor = Color . FromArgb ( 255 , 255 , 255 ) ;
73
- combo . Dock = DockStyle . Fill ;
74
- combo . Name = name ;
75
- combo . Margin = new Padding ( 5 , 5 , 5 , 5 ) ;
76
80
77
81
combo . DropDownStyle = ComboBoxStyle . DropDownList ;
78
82
combo . DisplayMember = "Value" ;
79
83
combo . ValueMember = "Key" ;
80
84
foreach ( var item in AllyControl . BindCodes )
81
- {
82
85
combo . Items . Add ( new KeyValuePair < string , string > ( item . Key , item . Value ) ) ;
83
- if ( item . Key == value ) combo . SelectedItem = item ;
84
- }
86
+
85
87
combo . SelectedValueChanged += Binding_SelectedValueChanged ;
86
88
87
- return combo ;
89
+ }
90
+
91
+ private void Binding_SelectedValueChanged ( object ? sender , EventArgs e )
92
+ {
93
+ if ( sender is null ) return ;
94
+ RComboBox combo = ( RComboBox ) sender ;
95
+
96
+ string value = ( ( KeyValuePair < string , string > ) combo . SelectedItem ) . Key ;
97
+ string binding = "bind" + ( combo . Name == "comboPrimary" ? "" : "2" ) + "_" + activeBinding ;
98
+
99
+ if ( value != "" ) AppConfig . Set ( binding , value ) ;
100
+ else AppConfig . Remove ( binding ) ;
101
+
102
+ VisualiseButton ( activeButton , activeBinding ) ;
88
103
104
+ AllyControl . ApplyMode ( ) ;
89
105
}
90
106
107
+ private void SetComboValue ( RComboBox combo , string value )
108
+ {
109
+ foreach ( var item in AllyControl . BindCodes )
110
+ if ( item . Key == value )
111
+ {
112
+ combo . SelectedItem = item ;
113
+ return ;
114
+ }
115
+
116
+ combo . SelectedIndex = 0 ;
117
+ }
91
118
92
- private void FillBinding ( string binding , string label )
119
+ private void VisualiseButton ( RButton button , string binding )
93
120
{
94
- tableBindings . RowStyles . Add ( new RowStyle ( SizeType . AutoSize ) ) ;
95
- tableBindings . Controls . Add ( new Label { Text = label , Anchor = AnchorStyles . Left , Dock = DockStyle . Fill , Padding = new Padding ( 5 , 5 , 5 , 5 ) } , 0 , tableBindings . RowCount ) ;
121
+ if ( button == null ) return ;
96
122
97
- tableBindings . Controls . Add ( ComboBinding ( "bind_" + binding , AppConfig . GetString ( "bind_" + binding , "" ) ) , 1 , tableBindings . RowCount ) ;
98
- tableBindings . Controls . Add ( ComboBinding ( "bind2_" + binding , AppConfig . GetString ( "bind2_" + binding , "" ) ) , 2 , tableBindings . RowCount ) ;
123
+ string primary = AppConfig . GetString ( "bind_" + binding , "" ) ;
124
+ string secondary = AppConfig . GetString ( "bind2_" + binding , "" ) ;
99
125
100
- tableBindings . RowCount ++ ;
126
+ if ( primary != "" || secondary != "" )
127
+ {
128
+ button . BorderColor = colorStandard ;
129
+ button . Activated = true ;
130
+ }
131
+ else
132
+ {
133
+ button . Activated = false ;
134
+ }
135
+ }
101
136
137
+ private void ButtonBinding ( string binding , string label , RButton button )
138
+ {
139
+ button . Click += ( sender , EventArgs ) => { buttonBinding_Click ( sender , EventArgs , binding , label ) ; } ;
140
+ VisualiseButton ( button , binding ) ;
102
141
}
103
142
104
- private void Binding_SelectedValueChanged ( object ? sender , EventArgs e )
143
+ void buttonBinding_Click ( object sender , EventArgs e , string binding , string label )
105
144
{
106
145
107
146
if ( sender is null ) return ;
108
- RComboBox combo = ( RComboBox ) sender ;
147
+ RButton button = ( RButton ) sender ;
109
148
110
- string value = ( ( KeyValuePair < string , string > ) combo . SelectedItem ) . Key ;
149
+ labelBinding . Text = "Binding: " + label ;
150
+ activeBinding = binding ;
111
151
112
- if ( value != "" ) AppConfig . Set ( combo . Name , value ) ;
113
- else AppConfig . Remove ( combo . Name ) ;
152
+ SetComboValue ( comboPrimary , AppConfig . GetString ( "bind_" + binding , "" ) ) ;
153
+ SetComboValue ( comboSecondary , AppConfig . GetString ( "bind2_" + binding , "" ) ) ;
114
154
115
- AllyControl . ApplyMode ( ) ;
155
+ panelBinding . Visible = true ;
156
+ activeButton = button ;
116
157
}
117
158
159
+
160
+
118
161
private void Controller_Complete ( object ? sender , EventArgs e )
119
162
{
120
163
AllyControl . SetDeadzones ( ) ;
0 commit comments