2018-08-23 15:48:19 +03:00
|
|
|
|
using Nefarius.ViGEm.Client.Targets;
|
|
|
|
|
using Nefarius.ViGEm.Client.Targets.Xbox360;
|
|
|
|
|
using System;
|
2018-05-02 18:57:47 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
2018-08-18 14:21:20 +03:00
|
|
|
|
using System.Configuration;
|
2018-05-02 18:57:47 +01:00
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2018-08-18 14:21:20 +03:00
|
|
|
|
using System.Xml.Linq;
|
2018-05-02 18:57:47 +01:00
|
|
|
|
|
|
|
|
|
namespace BetterJoyForCemu {
|
|
|
|
|
public partial class MainForm : Form {
|
2018-08-23 15:48:19 +03:00
|
|
|
|
public List<Button> con, loc;
|
2018-08-22 12:52:41 +03:00
|
|
|
|
|
2018-05-02 18:57:47 +01:00
|
|
|
|
public MainForm() {
|
|
|
|
|
InitializeComponent();
|
2018-08-22 12:52:41 +03:00
|
|
|
|
|
|
|
|
|
con = new List<Button> { con1, con2, con3, con4 };
|
2018-08-23 15:48:19 +03:00
|
|
|
|
loc = new List<Button> { loc1, loc2, loc3, loc4 };
|
2019-01-12 12:00:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 12:02:39 +00:00
|
|
|
|
private void HideToTray() {
|
2019-01-12 12:00:15 +00:00
|
|
|
|
this.WindowState = FormWindowState.Minimized;
|
|
|
|
|
notifyIcon.Visible = true;
|
|
|
|
|
notifyIcon.ShowBalloonTip(1);
|
2019-04-12 19:42:16 +01:00
|
|
|
|
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
|
2019-01-12 12:00:15 +00:00
|
|
|
|
this.ShowInTaskbar = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 12:02:39 +00:00
|
|
|
|
private void ShowFromTray() {
|
2019-01-12 12:00:15 +00:00
|
|
|
|
this.WindowState = FormWindowState.Normal;
|
|
|
|
|
this.ShowInTaskbar = true;
|
2019-04-12 19:42:16 +01:00
|
|
|
|
this.FormBorderStyle = FormBorderStyle.FixedSingle;
|
|
|
|
|
this.Icon = Properties.Resources.betterjoyforcemu_icon;
|
2019-01-12 12:00:15 +00:00
|
|
|
|
notifyIcon.Visible = false;
|
|
|
|
|
}
|
2018-05-02 18:57:47 +01:00
|
|
|
|
|
|
|
|
|
private void MainForm_Resize(object sender, EventArgs e) {
|
|
|
|
|
if (this.WindowState == FormWindowState.Minimized) {
|
2019-01-12 12:00:15 +00:00
|
|
|
|
HideToTray();
|
2018-05-02 18:57:47 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) {
|
2019-01-12 12:00:15 +00:00
|
|
|
|
ShowFromTray();
|
2018-05-02 18:57:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainForm_Load(object sender, EventArgs e) {
|
2018-08-14 10:42:00 +03:00
|
|
|
|
Program.Start();
|
2018-08-18 14:21:20 +03:00
|
|
|
|
|
|
|
|
|
Config.Init();
|
|
|
|
|
|
|
|
|
|
passiveScanBox.Checked = Config.Value("ProgressiveScan");
|
2019-01-12 12:00:15 +00:00
|
|
|
|
startInTrayBox.Checked = Config.Value("StartInTray");
|
|
|
|
|
|
2019-01-12 12:02:39 +00:00
|
|
|
|
if (Config.Value("StartInTray")) {
|
2019-01-12 12:00:15 +00:00
|
|
|
|
HideToTray();
|
|
|
|
|
}
|
2019-01-12 12:02:39 +00:00
|
|
|
|
else {
|
2019-01-12 12:00:15 +00:00
|
|
|
|
ShowFromTray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-02 18:57:47 +01:00
|
|
|
|
|
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
|
2018-07-27 09:54:08 +03:00
|
|
|
|
try {
|
|
|
|
|
Program.Stop();
|
2018-08-18 14:21:20 +03:00
|
|
|
|
Environment.Exit(0);
|
2018-07-27 09:54:08 +03:00
|
|
|
|
} catch { }
|
2018-07-16 22:03:51 +03:00
|
|
|
|
}
|
2018-05-02 18:57:47 +01:00
|
|
|
|
|
2018-08-23 15:48:19 +03:00
|
|
|
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { // this does not work, for some reason. Fix before release
|
2018-07-27 09:54:08 +03:00
|
|
|
|
try {
|
|
|
|
|
Program.Stop();
|
2018-08-22 12:52:41 +03:00
|
|
|
|
Close();
|
2018-08-18 14:21:20 +03:00
|
|
|
|
Environment.Exit(0);
|
2018-07-27 09:54:08 +03:00
|
|
|
|
} catch { }
|
2018-05-02 18:57:47 +01:00
|
|
|
|
}
|
2018-07-16 22:03:51 +03:00
|
|
|
|
|
|
|
|
|
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
|
|
|
|
|
linkLabel1.LinkVisited = true;
|
|
|
|
|
System.Diagnostics.Process.Start("http://paypal.me/DavidKhachaturov/5");
|
|
|
|
|
}
|
2018-08-18 14:21:20 +03:00
|
|
|
|
|
|
|
|
|
private void passiveScanBox_CheckedChanged(object sender, EventArgs e) {
|
|
|
|
|
Config.Save("ProgressiveScan", passiveScanBox.Checked);
|
|
|
|
|
}
|
2018-08-18 20:52:34 +03:00
|
|
|
|
|
|
|
|
|
public void AppendTextBox(string value) { // https://stackoverflow.com/questions/519233/writing-to-a-textbox-from-another-thread
|
|
|
|
|
if (InvokeRequired) {
|
|
|
|
|
this.Invoke(new Action<string>(AppendTextBox), new object[] { value });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.AppendText(value);
|
|
|
|
|
}
|
2018-08-22 12:52:41 +03:00
|
|
|
|
|
2018-08-23 15:48:19 +03:00
|
|
|
|
bool toRumble = Boolean.Parse(ConfigurationManager.AppSettings["EnableRumble"]);
|
|
|
|
|
bool showAsXInput = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]);
|
2018-08-22 12:52:41 +03:00
|
|
|
|
|
2018-08-23 15:48:19 +03:00
|
|
|
|
public void locBtnClick(object sender, EventArgs e) {
|
|
|
|
|
Button bb = sender as Button;
|
|
|
|
|
|
|
|
|
|
if (bb.Tag.GetType() == typeof(Button)) {
|
|
|
|
|
Button button = bb.Tag as Button;
|
2018-08-22 12:52:41 +03:00
|
|
|
|
|
2018-08-23 15:48:19 +03:00
|
|
|
|
if (button.Tag.GetType() == typeof(Joycon)) {
|
|
|
|
|
Joycon v = (Joycon) button.Tag;
|
2018-08-22 12:52:41 +03:00
|
|
|
|
v.SetRumble(20.0f, 400.0f, 1.0f, 300);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-23 15:48:19 +03:00
|
|
|
|
|
|
|
|
|
public void conBtnClick(object sender, EventArgs e) {
|
|
|
|
|
Button button = sender as Button;
|
|
|
|
|
|
|
|
|
|
if (button.Tag.GetType() == typeof(Joycon)) {
|
|
|
|
|
Joycon v = (Joycon)button.Tag;
|
|
|
|
|
|
|
|
|
|
if (v.other == null && !v.isPro) { // needs connecting to other joycon (so messy omg)
|
2019-02-02 15:19:03 +00:00
|
|
|
|
bool succ = false;
|
|
|
|
|
foreach (Joycon jc in Program.mgr.j) {
|
|
|
|
|
if (!jc.isPro && jc.isLeft != v.isLeft && jc != v && jc.other == null) {
|
|
|
|
|
v.other = jc;
|
|
|
|
|
jc.other = v;
|
2018-08-23 15:48:19 +03:00
|
|
|
|
|
2019-02-02 15:19:03 +00:00
|
|
|
|
v.xin.Dispose();
|
|
|
|
|
v.xin = null;
|
|
|
|
|
|
|
|
|
|
foreach (Button b in con)
|
|
|
|
|
if (b.Tag == jc)
|
|
|
|
|
b.BackgroundImage = jc.isLeft ? Properties.Resources.jc_left : Properties.Resources.jc_right;
|
|
|
|
|
|
|
|
|
|
succ = true;
|
|
|
|
|
break;
|
2018-08-23 15:48:19 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-02 15:19:03 +00:00
|
|
|
|
if (succ)
|
|
|
|
|
foreach (Button b in con)
|
|
|
|
|
if (b.Tag == v)
|
|
|
|
|
b.BackgroundImage = v.isLeft ? Properties.Resources.jc_left : Properties.Resources.jc_right;
|
2018-08-23 15:48:19 +03:00
|
|
|
|
} else if (v.other != null && !v.isPro) { // needs disconnecting from other joycon
|
|
|
|
|
if (v.xin == null) {
|
|
|
|
|
ReenableXinput(v);
|
|
|
|
|
v.xin.Connect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (v.other.xin == null) {
|
|
|
|
|
ReenableXinput(v.other);
|
|
|
|
|
v.other.xin.Connect();
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-02 15:19:03 +00:00
|
|
|
|
button.BackgroundImage = v.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s;
|
|
|
|
|
|
|
|
|
|
foreach (Button b in con)
|
|
|
|
|
if (b.Tag == v.other)
|
|
|
|
|
b.BackgroundImage = v.other.isLeft ? Properties.Resources.jc_left_s : Properties.Resources.jc_right_s;
|
2018-08-23 15:48:19 +03:00
|
|
|
|
|
|
|
|
|
v.other.other = null;
|
|
|
|
|
v.other = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 12:00:15 +00:00
|
|
|
|
private void startInTrayBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Config.Save("StartInTray", startInTrayBox.Checked);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-03 16:16:00 +00:00
|
|
|
|
private void btn_open3rdP_Click(object sender, EventArgs e) {
|
|
|
|
|
_3rdPartyControllers partyForm = new _3rdPartyControllers();
|
|
|
|
|
partyForm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 15:48:19 +03:00
|
|
|
|
void ReenableXinput(Joycon v) {
|
|
|
|
|
if (showAsXInput) {
|
|
|
|
|
v.xin = new Xbox360Controller(Program.emClient);
|
|
|
|
|
|
|
|
|
|
if (toRumble)
|
|
|
|
|
v.xin.FeedbackReceived += v.ReceiveRumble;
|
|
|
|
|
v.report = new Xbox360Report();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-16 22:03:51 +03:00
|
|
|
|
}
|
2018-05-02 18:57:47 +01:00
|
|
|
|
}
|