1- using System ;
1+ using Nefarius . ViGEm . Client . Targets ;
2+ using Nefarius . ViGEm . Client . Targets . Xbox360 ;
3+ using System ;
24using System . Collections . Generic ;
35using System . ComponentModel ;
46using System . Configuration ;
1214
1315namespace BetterJoyForCemu {
1416 public partial class MainForm : Form {
15- public List < Button > con ;
17+ public List < Button > con , loc ;
1618
1719 public MainForm ( ) {
1820 InitializeComponent ( ) ;
1921
2022 con = new List < Button > { con1 , con2 , con3 , con4 } ;
23+ loc = new List < Button > { loc1 , loc2 , loc3 , loc4 } ;
2124 }
2225
2326 private void MainForm_Resize ( object sender , EventArgs e ) {
@@ -52,7 +55,7 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
5255 } catch { }
5356 }
5457
55- private void exitToolStripMenuItem_Click ( object sender , EventArgs e ) {
58+ private void exitToolStripMenuItem_Click ( object sender , EventArgs e ) { // this does not work, for some reason. Fix before release
5659 try {
5760 Program . Stop ( ) ;
5861 Close ( ) ;
@@ -77,16 +80,107 @@ public void AppendTextBox(string value) { // https://stackoverflow.com/questions
7780 console . AppendText ( value ) ;
7881 }
7982
80- public void conBtnClick ( object sender , EventArgs e ) {
81- Button button = sender as Button ;
83+ bool toRumble = Boolean . Parse ( ConfigurationManager . AppSettings [ "EnableRumble" ] ) ;
84+ bool showAsXInput = Boolean . Parse ( ConfigurationManager . AppSettings [ "ShowAsXInput" ] ) ;
8285
83- if ( button . ClientRectangle . Contains ( PointToClient ( Control . MousePosition ) ) ) { // hacky but allows both l&r clicks
84- if ( button . Tag . GetType ( ) == typeof ( Joycon ) ) {
85- Joycon v = ( Joycon ) button . Tag ;
86+ public void locBtnClick ( object sender , EventArgs e ) {
87+ Button bb = sender as Button ;
88+
89+ if ( bb . Tag . GetType ( ) == typeof ( Button ) ) {
90+ Button button = bb . Tag as Button ;
8691
92+ if ( button . Tag . GetType ( ) == typeof ( Joycon ) ) {
93+ Joycon v = ( Joycon ) button . Tag ;
8794 v . SetRumble ( 20.0f , 400.0f , 1.0f , 300 ) ;
8895 }
8996 }
9097 }
98+
99+ public void conBtnClick ( object sender , EventArgs e ) {
100+ Button button = sender as Button ;
101+
102+ if ( button . Tag . GetType ( ) == typeof ( Joycon ) ) {
103+ Joycon v = ( Joycon ) button . Tag ;
104+
105+ if ( v . other == null && ! v . isPro ) { // needs connecting to other joycon (so messy omg)
106+
107+ int found = 0 ;
108+ int minPadID = 10 ;
109+ foreach ( Joycon jc in Program . mgr . j ) { // current system is designed for a maximum of two joycons connected to the PC
110+ if ( ! jc . isPro ) {
111+ found ++ ;
112+ minPadID = Math . Min ( jc . PadId , minPadID ) ;
113+ }
114+ jc . LED = ( byte ) ( 0x1 << jc . PadId ) ;
115+ }
116+
117+ if ( found == 2 ) {
118+ AppendTextBox ( "Both joycons successfully found.\r \n " ) ;
119+ Joycon temp = null ;
120+ foreach ( Joycon jc in Program . mgr . j ) {
121+ if ( ! jc . isPro ) {
122+ jc . LED = ( byte ) ( 0x1 << minPadID ) ;
123+
124+ if ( temp == null )
125+ temp = jc ;
126+ else {
127+ temp . other = jc ;
128+ jc . other = temp ;
129+
130+ temp . xin . Dispose ( ) ;
131+ temp . xin = null ;
132+ }
133+
134+ foreach ( Button b in con ) {
135+ if ( b . Tag == jc ) {
136+ if ( jc . isLeft )
137+ b . BackgroundImage = Properties . Resources . jc_left ;
138+ else
139+ b . BackgroundImage = Properties . Resources . jc_right ;
140+ }
141+ }
142+ }
143+ } // Join up the two joycons
144+ }
145+ } else if ( v . other != null && ! v . isPro ) { // needs disconnecting from other joycon
146+ if ( v . xin == null ) {
147+ ReenableXinput ( v ) ;
148+ v . xin . Connect ( ) ;
149+ }
150+
151+ if ( v . other . xin == null ) {
152+ ReenableXinput ( v . other ) ;
153+ v . other . xin . Connect ( ) ;
154+ }
155+
156+ if ( v . isLeft )
157+ button . BackgroundImage = Properties . Resources . jc_left_s ;
158+ else
159+ button . BackgroundImage = Properties . Resources . jc_right_s ;
160+
161+ foreach ( Button b in con ) {
162+ if ( b . Tag == v . other ) {
163+ if ( v . other . isLeft )
164+ b . BackgroundImage = Properties . Resources . jc_left_s ;
165+ else
166+ b . BackgroundImage = Properties . Resources . jc_right_s ;
167+ }
168+ }
169+
170+ v . other . other = null ;
171+ v . other = null ;
172+ }
173+ }
174+ }
175+
176+ void ReenableXinput ( Joycon v ) {
177+ if ( showAsXInput ) {
178+ v . xin = new Xbox360Controller ( Program . emClient ) ;
179+
180+ if ( toRumble )
181+ v . xin . FeedbackReceived += v . ReceiveRumble ;
182+ v . report = new Xbox360Report ( ) ;
183+ }
184+ }
91185 }
92186}
0 commit comments