From de0e9a88cbe64c7081888a743054d1acab5f479f Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Wed, 26 Apr 2017 01:00:05 -0700 Subject: [PATCH] Change device removal event to only hide one device rather than refresh a list --- DS4Windows/DS4Control/ControlSerivce.cs | 16 ++++--- DS4Windows/DS4Control/ScpUtil.cs | 39 ++++++++++++++-- DS4Windows/DS4Forms/DS4Form.cs | 62 +++++++++++++++++++++---- DS4Windows/DS4Forms/DS4Form.resx | 61 ++++++++++++------------ DS4Windows/DS4Forms/Options.cs | 25 +++++++++- 5 files changed, 150 insertions(+), 53 deletions(-) diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs index 2979ef5..5b4b4f5 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlSerivce.cs @@ -276,7 +276,9 @@ namespace DS4Windows return false; })()) + { continue; + } for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++) { @@ -289,7 +291,7 @@ namespace DS4Windows device.Removal += this.On_DS4Removal; device.Removal += DS4Devices.On_Removal; touchPad[Index] = new Mouse(Index, device); - device.LightBarColor = MainColor[Index]; + device.LightBarColor = getMainColor(Index); device.Report += this.On_Report; if (!getDInputOnly(Index)) x360Bus.Plugin(Index); @@ -488,8 +490,10 @@ namespace DS4Windows DS4Device device = (DS4Device)sender; int ind = -1; for (int i = 0, arlength = DS4Controllers.Length; ind == -1 && i < arlength; i++) + { if (DS4Controllers[i] != null && device.getMacAddress() == DS4Controllers[i].getMacAddress()) ind = i; + } if (ind != -1) { @@ -520,7 +524,8 @@ namespace DS4Windows touchPad[ind] = null; lag[ind] = false; inWarnMonitor[ind] = false; - ControllerStatusChanged(this); + OnControllerRemoved(this, ind); + //ControllerStatusChanged(this); } } } @@ -570,9 +575,6 @@ namespace DS4Windows device.getPreviousState(PreviousState[ind]); DS4State pState = PreviousState[ind]; - // Change routine to be more specific to a device. - // Currently updates status of all devices in DS4Form when any battery - // state change occurs. if (pState.Battery != cState.Battery) OnBatteryStatusChange(this, ind, cState.Battery); //ControllerStatusChanged(this); @@ -623,7 +625,7 @@ namespace DS4Windows { lag[ind] = true; LogDebug(Properties.Resources.LatencyOverTen.Replace("*number*", (ind + 1).ToString()), true); - if (FlashWhenLate) + if (getFlashWhenLate()) { DS4Color color = new DS4Color { red = 50, green = 0, blue = 0 }; DS4LightBar.forcedColor[ind] = color; @@ -1068,7 +1070,7 @@ namespace DS4Windows //sets the rumble adjusted with rumble boost public virtual void setRumble(byte heavyMotor, byte lightMotor, int deviceNum) { - byte boost = RumbleBoost[deviceNum]; + byte boost = getRumbleBoost(deviceNum); uint lightBoosted = ((uint)lightMotor * (uint)boost) / 100; if (lightBoosted > 255) lightBoosted = 255; diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index e30ca6e..f84ee43 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -51,7 +51,7 @@ namespace DS4Windows shiftExtras = null; shiftKeyType = DS4KeyType.None; } - + internal void UpdateSettings(bool shift, object act, string exts, DS4KeyType kt, int trigger = 0) { if (!shift) @@ -142,7 +142,7 @@ namespace DS4Windows } } - public class BatteryReportArgs: EventArgs + public class BatteryReportArgs : EventArgs { private int index; private int level; @@ -164,6 +164,21 @@ namespace DS4Windows } } + public class ControllerRemovedArgs : EventArgs + { + private int index; + + public ControllerRemovedArgs(int index) + { + this.index = index; + } + + public int getIndex() + { + return this.index; + } + } + public class MultiValueDict : Dictionary> { public void Add(Key key, Value val) @@ -246,6 +261,16 @@ namespace DS4Windows } } + public static event EventHandler ControllerRemoved; + public static void OnControllerRemoved(object sender, int index) + { + if (ControllerRemoved != null) + { + ControllerRemovedArgs args = new ControllerRemovedArgs(index); + ControllerRemoved(sender, args); + } + } + //general values public static bool UseExclusiveMode { @@ -332,6 +357,10 @@ namespace DS4Windows set { m_Config.flashWhenLate = value; } get { return m_Config.flashWhenLate; } } + public static bool getFlashWhenLate() + { + return m_Config.flashWhenLate; + } public static int FlashWhenLateAt { set { m_Config.flashWhenLateAt = value; } @@ -349,7 +378,11 @@ namespace DS4Windows //controller/profile specfic values public static int[] ButtonMouseSensitivity => m_Config.buttonMouseSensitivity; - public static byte[] RumbleBoost => m_Config.rumble; + public static byte[] RumbleBoost => m_Config.rumble; + public static byte getRumbleBoost(int index) + { + return m_Config.rumble[index]; + } public static double[] Rainbow => m_Config.rainbow; public static double getRainbow(int index) { diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index bfd59db..eccd116 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -26,6 +26,7 @@ namespace DS4Windows delegate void LogDebugDelegate(DateTime Time, String Data, bool warning); delegate void NotificationDelegate(object sender, DebugEventArgs args); delegate void BatteryStatusDelegate(object sender, BatteryReportArgs args); + delegate void ControllerRemovedDelegate(object sender, ControllerRemovedArgs args); protected Label[] Pads, Batteries; protected ComboBox[] cbs; protected Button[] ebns; @@ -302,6 +303,7 @@ namespace DS4Windows LoadP(); Global.ControllerStatusChange += ControllerStatusChange; Global.BatteryStatusChange += BatteryStatusUpdate; + Global.ControllerRemoved += ControllerRemovedChange; Enable_Controls(0, false); Enable_Controls(1, false); Enable_Controls(2, false); @@ -919,14 +921,6 @@ namespace DS4Windows catch { } } - protected void ControllerStatusChange(object sender, EventArgs e) - { - if (InvokeRequired) - Invoke(new ControllerStatusChangedDelegate(ControllerStatusChange), new object[] { sender, e }); - else - ControllerStatusChanged(); - } - protected void BatteryStatusUpdate(object sender, BatteryReportArgs args) { if (this.InvokeRequired) @@ -951,6 +945,50 @@ namespace DS4Windows } } + protected void ControllerRemovedChange(object sender, ControllerRemovedArgs args) + { + if (this.InvokeRequired) + { + try + { + ControllerRemovedDelegate d = new ControllerRemovedDelegate(ControllerRemovedChange); + this.BeginInvoke(d, new object[] { sender, args }); + } + catch { } + } + else + { + int devIndex = args.getIndex(); + Pads[devIndex].Text = Properties.Resources.Disconnected; + Enable_Controls(devIndex, false); + statPB[devIndex].Visible = false; + toolTip1.SetToolTip(statPB[devIndex], ""); + + DS4Device[] devices = Program.rootHub.DS4Controllers; + int controllerLen = devices.Length; + bool nocontrollers = true; + for (Int32 i = 0, PadsLen = Pads.Length; nocontrollers && i < PadsLen; i++) + { + DS4Device d = devices[i]; + if (d != null) + { + nocontrollers = false; + } + } + + lbNoControllers.Visible = nocontrollers; + tLPControllers.Visible = !nocontrollers; + } + } + + protected void ControllerStatusChange(object sender, EventArgs e) + { + if (InvokeRequired) + Invoke(new ControllerStatusChangedDelegate(ControllerStatusChange), new object[] { sender, e }); + else + ControllerStatusChanged(); + } + protected void ControllerStatusChanged() { String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; @@ -1009,7 +1047,6 @@ namespace DS4Windows lbNoControllers.Visible = nocontrollers; tLPControllers.Visible = !nocontrollers; - btnClear.Enabled = lvDebug.Items.Count > 0; if (tooltip.Length > 63) notifyIcon1.Text = tooltip.Substring(0, 63); else @@ -1214,8 +1251,13 @@ namespace DS4Windows toolStrip1.Visible = true; toolStrip1.Enabled = true; lbLastMessage.ForeColor = SystemColors.GrayText; - lbLastMessage.Text = lvDebug.Items[lvDebug.Items.Count - 1].SubItems[1].Text; + int lvDebugItemCount = lvDebug.Items.Count; + if (lvDebugItemCount > 0) + { + lbLastMessage.Text = lvDebug.Items[lvDebugItemCount - 1].SubItems[1].Text; + } } + private void editButtons_Click(object sender, EventArgs e) { Button bn = (Button)sender; diff --git a/DS4Windows/DS4Forms/DS4Form.resx b/DS4Windows/DS4Forms/DS4Form.resx index 6c79bcd..acd08c5 100644 --- a/DS4Windows/DS4Forms/DS4Form.resx +++ b/DS4Windows/DS4Forms/DS4Form.resx @@ -318,9 +318,6 @@ Bottom - - False - NoControl @@ -475,10 +472,10 @@ NoControl - 826, 74 + 822, 74 - 67, 22 + 71, 22 50 @@ -502,7 +499,7 @@ NoControl - 394, 19 + 392, 19 39, 20 @@ -604,7 +601,7 @@ NoControl - 783, 74 + 779, 74 37, 22 @@ -634,7 +631,7 @@ NoControl - 783, 102 + 779, 102 37, 22 @@ -733,7 +730,7 @@ None - 666, 18 + 662, 18 111, 21 @@ -760,7 +757,7 @@ NoControl - 783, 46 + 779, 46 37, 22 @@ -787,7 +784,7 @@ None - 666, 46 + 662, 46 111, 21 @@ -811,7 +808,7 @@ None - 666, 74 + 662, 74 111, 21 @@ -838,7 +835,7 @@ NoControl - 783, 18 + 779, 18 37, 22 @@ -865,7 +862,7 @@ None - 666, 102 + 662, 102 111, 21 @@ -898,7 +895,7 @@ NoControl - 667, 0 + 663, 0 109, 15 @@ -970,7 +967,7 @@ NoControl - 390, 0 + 388, 0 47, 15 @@ -1006,7 +1003,7 @@ NoControl - 557, 0 + 554, 0 51, 15 @@ -1042,7 +1039,7 @@ NoControl - 563, 21 + 560, 21 39, 15 @@ -1078,7 +1075,7 @@ NoControl - 563, 49 + 560, 49 39, 15 @@ -1114,7 +1111,7 @@ NoControl - 563, 77 + 560, 77 39, 15 @@ -1150,7 +1147,7 @@ NoControl - 563, 105 + 560, 105 39, 15 @@ -1180,7 +1177,7 @@ NoControl - 394, 47 + 392, 47 39, 20 @@ -1210,7 +1207,7 @@ NoControl - 394, 75 + 392, 75 39, 20 @@ -1240,7 +1237,7 @@ NoControl - 394, 103 + 392, 103 39, 20 @@ -1273,10 +1270,10 @@ NoControl - 826, 18 + 822, 18 - 67, 22 + 71, 22 50 @@ -1303,10 +1300,10 @@ NoControl - 826, 46 + 822, 46 - 67, 22 + 71, 22 51 @@ -1333,10 +1330,10 @@ NoControl - 826, 102 + 822, 102 - 67, 22 + 71, 22 52 @@ -1381,7 +1378,7 @@ 1 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="bnLight3" Row="3" RowSpan="1" Column="5" ColumnSpan="1" /><Control Name="pBStatus1" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="lbPad1" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="lbPad2" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="bnEditC3" Row="3" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="bnEditC4" Row="4" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="lbPad3" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="lbPad4" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="cBController1" Row="1" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="bnEditC2" Row="2" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="cBController2" Row="2" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="cBController3" Row="3" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="bnEditC1" Row="1" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="cBController4" Row="4" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="lbSelectedProfile" Row="0" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="lbID" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="lbStatus" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="lbBattery" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt1" Row="1" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt2" Row="2" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt3" Row="3" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt4" Row="4" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="pBStatus2" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="pBStatus3" Row="3" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="pBStatus4" Row="4" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="bnLight1" Row="1" RowSpan="1" Column="5" ColumnSpan="1" /><Control Name="bnLight2" Row="2" RowSpan="1" Column="5" ColumnSpan="1" /><Control Name="bnLight4" Row="4" RowSpan="1" Column="5" ColumnSpan="1" /></Controls><Columns Styles="Percent,48.95498,Percent,26.82658,Percent,24.21844,AutoSize,0,AutoSize,0,Absolute,72" /><Rows Styles="AutoSize,0,Percent,25,Percent,25,Percent,25,Percent,25" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="bnLight3" Row="3" RowSpan="1" Column="5" ColumnSpan="1" /><Control Name="pBStatus1" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="lbPad1" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="lbPad2" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="bnEditC3" Row="3" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="bnEditC4" Row="4" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="lbPad3" Row="3" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="lbPad4" Row="4" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="cBController1" Row="1" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="bnEditC2" Row="2" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="cBController2" Row="2" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="cBController3" Row="3" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="bnEditC1" Row="1" RowSpan="1" Column="4" ColumnSpan="1" /><Control Name="cBController4" Row="4" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="lbSelectedProfile" Row="0" RowSpan="1" Column="3" ColumnSpan="1" /><Control Name="lbID" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="lbStatus" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="lbBattery" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt1" Row="1" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt2" Row="2" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt3" Row="3" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="lbBatt4" Row="4" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="pBStatus2" Row="2" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="pBStatus3" Row="3" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="pBStatus4" Row="4" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="bnLight1" Row="1" RowSpan="1" Column="5" ColumnSpan="1" /><Control Name="bnLight2" Row="2" RowSpan="1" Column="5" ColumnSpan="1" /><Control Name="bnLight4" Row="4" RowSpan="1" Column="5" ColumnSpan="1" /></Controls><Columns Styles="Percent,48.95498,Percent,26.82658,Percent,24.21844,AutoSize,0,AutoSize,0,Absolute,76" /><Rows Styles="AutoSize,0,Percent,25,Percent,25,Percent,25,Percent,25" /></TableLayoutSettings> Fill @@ -3205,7 +3202,7 @@ advColorDialog - DS4Windows.AdvancedColorDialog, DS4Windows, Version=1.4.63.0, Culture=neutral, PublicKeyToken=null + DS4Windows.AdvancedColorDialog, DS4Windows, Version=1.4.64.0, Culture=neutral, PublicKeyToken=null DS4Form diff --git a/DS4Windows/DS4Forms/Options.cs b/DS4Windows/DS4Forms/Options.cs index 15043a6..099f4d8 100644 --- a/DS4Windows/DS4Forms/Options.cs +++ b/DS4Windows/DS4Forms/Options.cs @@ -47,18 +47,31 @@ namespace DS4Windows colored = btnRainbow.Image; greyscale = GreyscaleImage((Bitmap)btnRainbow.Image); fLPSettings.FlowDirection = FlowDirection.TopDown; + foreach (Control control in tPControls.Controls) + { if (control is Button && !((Button)control).Name.Contains("btn")) buttons.Add((Button)control); + } + foreach (Control control in fLPTouchSwipe.Controls) + { if (control is Button && !((Button)control).Name.Contains("btn")) buttons.Add((Button)control); + } + foreach (Control control in fLPTiltControls.Controls) + { if (control is Button && !((Button)control).Name.Contains("btn")) buttons.Add((Button)control); + } + foreach (Control control in pnlController.Controls) + { if (control is Button && !((Button)control).Name.Contains("btn")) buttons.Add((Button)control); + } + foreach (Button b in buttons) { defaults.Add(b.Name, b.Text); @@ -68,18 +81,27 @@ namespace DS4Windows foreach (System.Windows.Forms.Control control in Controls) { if (control.HasChildren) + { foreach (System.Windows.Forms.Control ctrl in control.Controls) { if (ctrl.HasChildren) + { foreach (System.Windows.Forms.Control ctrl2 in ctrl.Controls) { if (ctrl2.HasChildren) + { foreach (System.Windows.Forms.Control ctrl3 in ctrl2.Controls) ctrl3.MouseHover += Items_MouseHover; + } + ctrl2.MouseHover += Items_MouseHover; } + } + ctrl.MouseHover += Items_MouseHover; } + } + control.MouseHover += Items_MouseHover; } @@ -88,6 +110,7 @@ namespace DS4Windows b.MouseHover += button_MouseHover; b.MouseLeave += button_MouseLeave; } + advColorDialog.OnUpdateColor += advColorDialog_OnUpdateColor; inputtimer.Tick += InputDS4; sixaxisTimer.Tick += ControllerReadout_Tick; @@ -357,7 +380,7 @@ namespace DS4Windows string[] satriggers = SATriggers[device].Split(','); List s = new List(); - for (int i = 0; i < satriggers.Length; i++) + for (int i = 0, satrigLen = satriggers.Length; i < satrigLen; i++) { int tr; if (int.TryParse(satriggers[i], out tr))