Added preset context menu back in

This commit is contained in:
Travis Nickles 2020-03-06 14:11:59 -06:00
parent df16c25932
commit 79ddb2a5a3
3 changed files with 413 additions and 14 deletions

View File

@ -32,6 +32,41 @@
<SolidColorBrush Color="DimGray"/>
</DockPanel.Background>
<Canvas x:Name="conCanvas" Width="440" Height="240" Margin="0,10,0,0" DockPanel.Dock="Top" >
<Canvas.Resources>
<ContextMenu x:Key="presetMenu">
<MenuItem x:Name="controlNameItem" Header="Name" IsEnabled="False" />
<Separator />
<MenuItem Header="Default" Tag="0" Click="PresetMenuItem_Click" />
<MenuItem Header="DPad">
<MenuItem Header="Normal" Tag="1" CommandParameter="0" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted" Tag="1" CommandParameter="1" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted X" Tag="1" CommandParameter="2" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted Y" Tag="1" CommandParameter="3" Click="PresetMenuItem_Click" />
</MenuItem>
<MenuItem Header="Left Stick">
<MenuItem Header="Normal" Tag="2" CommandParameter="0" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted" Tag="2" CommandParameter="1" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted X" Tag="2" CommandParameter="2" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted Y" Tag="2" CommandParameter="3" Click="PresetMenuItem_Click" />
</MenuItem>
<MenuItem Header="Right Stick">
<MenuItem Header="Normal" Tag="3" CommandParameter="0" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted" Tag="3" CommandParameter="1" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted X" Tag="3" CommandParameter="2" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted Y" Tag="3" CommandParameter="3" Click="PresetMenuItem_Click" />
</MenuItem>
<MenuItem Header="Face Buttons" Tag="4" Click="PresetMenuItem_Click" />
<MenuItem Header="WASD" Tag="5" Click="PresetMenuItem_Click" />
<MenuItem Header="Arrow Keys" Tag="6" Click="PresetMenuItem_Click" />
<MenuItem Header="Mouse">
<MenuItem Header="Normal" Tag="7" CommandParameter="0" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted" Tag="7" CommandParameter="1" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted X" Tag="7" CommandParameter="2" Click="PresetMenuItem_Click" />
<MenuItem Header="Inverted Y" Tag="7" CommandParameter="3" Click="PresetMenuItem_Click" />
</MenuItem>
</ContextMenu>
</Canvas.Resources>
<Image Source="/DS4Windows;component/Resources/DS4 Config.png" Width="440" Height="220" Stretch="Uniform"/>
<Image x:Name="picBoxHover" IsEnabled="False" Source="/DS4Windows;component/Resources/DS4-Config_RS.png" Height="48" Width="48" Canvas.Left="447" Canvas.Top="5" />
@ -56,22 +91,36 @@
<Button Content="Right Touch" x:Name="rightTouchConBtn" Canvas.Left="251" Canvas.Top="70" Width="32" Height="53" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="Top Touch" x:Name="topTouchConBtn" Canvas.Left="157" Canvas.Top="46" Width="125" Height="23" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="L3" x:Name="l3ConBtn" Canvas.Left="138" Canvas.Top="147" Width="42" Height="42" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="LSU" x:Name="lsuConBtn" Canvas.Left="150" Canvas.Top="140" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="LSR" x:Name="lsrConBtn" Canvas.Left="172" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="LSD" x:Name="lsdConBtn" Canvas.Left="150" Canvas.Top="180" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="LSL" x:Name="lslConBtn" Canvas.Left="126" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="L3" x:Name="l3ConBtn" Canvas.Left="138" Canvas.Top="147" Width="42" Height="42" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="LSU" x:Name="lsuConBtn" Canvas.Left="150" Canvas.Top="140" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="LSR" x:Name="lsrConBtn" Canvas.Left="172" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="LSD" x:Name="lsdConBtn" Canvas.Left="150" Canvas.Top="180" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="LSL" x:Name="lslConBtn" Canvas.Left="126" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="R3" x:Name="r3ConBtn" Canvas.Left="262" Canvas.Top="149" Width="42" Height="42" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="RSU" x:Name="rsuConBtn" Canvas.Left="275" Canvas.Top="142" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="RSR" x:Name="rsrConBtn" Canvas.Left="298" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="RSD" x:Name="rsdConBtn" Canvas.Left="275" Canvas.Top="180" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="RSL" x:Name="rslConBtn" Canvas.Left="248" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="R3" x:Name="r3ConBtn" Canvas.Left="262" Canvas.Top="149" Width="42" Height="42" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="RSU" x:Name="rsuConBtn" Canvas.Left="275" Canvas.Top="142" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="RSR" x:Name="rsrConBtn" Canvas.Left="298" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="RSD" x:Name="rsdConBtn" Canvas.Left="275" Canvas.Top="180" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="RSL" x:Name="rslConBtn" Canvas.Left="248" Canvas.Top="162" Width="17" Height="15" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="Up" x:Name="upConBtn" Canvas.Left="88" Canvas.Top="74" Width="20" Height="35" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="Right" x:Name="rightConBtn" Canvas.Left="103" Canvas.Top="103" Width="35" Height="20" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="Down" x:Name="downConBtn" Canvas.Left="88" Canvas.Top="114" Width="20" Height="35" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="Left" x:Name="leftConBtn" Canvas.Left="56" Canvas.Top="103" Width="35" Height="20" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" />
<Button Content="Up" x:Name="upConBtn" Canvas.Left="88" Canvas.Top="74" Width="20" Height="35" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="Right" x:Name="rightConBtn" Canvas.Left="103" Canvas.Top="103" Width="35" Height="20" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="Down" x:Name="downConBtn" Canvas.Left="88" Canvas.Top="114" Width="20" Height="35" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="Left" x:Name="leftConBtn" Canvas.Left="56" Canvas.Top="103" Width="35" Height="20" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave"
MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Label x:Name="highlightControlDisplayLb" Content="" Canvas.Left="150" Canvas.Top="208" MinWidth="150"
HorizontalContentAlignment="Center">

View File

@ -1270,5 +1270,36 @@ namespace DS4WinWPF.DS4Forms
mpControl.UpdateMappingName();
UpdateHighlightLabel(mpControl);
}
private void ConBtn_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
Button btn = sender as Button;
MappedControl mpControl = mappingListVM.Mappings[mappingListVM.SelectedIndex];
profileSettingsVM.PresetMenuUtil.SetHighlightControl(mpControl.Control);
ContextMenu cm = conCanvas.FindResource("presetMenu") as ContextMenu;
MenuItem temp = cm.Items[0] as MenuItem;
temp.Header = profileSettingsVM.PresetMenuUtil.PresetInputLabel;
cm.PlacementTarget = btn;
cm.IsOpen = true;
}
private void PresetMenuItem_Click(object sender, RoutedEventArgs e)
{
MenuItem item = sender as MenuItem;
int baseTag = Convert.ToInt32(item.Tag);
int subTag = Convert.ToInt32(item.CommandParameter);
if (baseTag >= 0 && subTag >= 0)
{
List<DS4Controls> controls =
profileSettingsVM.PresetMenuUtil.ModifySettingWithPreset(baseTag, subTag);
foreach(DS4Controls control in controls)
{
MappedControl mpControl = mappingListVM.ControlMap[control];
mpControl.UpdateMappingName();
}
highlightControlDisplayLb.Content = "";
}
}
}
}

View File

@ -6,6 +6,7 @@ using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@ -1502,6 +1503,13 @@ namespace DS4WinWPF.DS4Forms.ViewModels
public event EventHandler GyroMouseStickTrigDisplayChanged;
private PresetMenuHelper presetMenuUtil;
public PresetMenuHelper PresetMenuUtil
{
get => presetMenuUtil;
}
public ProfileSettingsViewModel(int device)
{
this.device = device;
@ -1517,6 +1525,8 @@ namespace DS4WinWPF.DS4Forms.ViewModels
ConvertFromString("pack://application:,,,/DS4Windows;component/Resources/rainbowCCrop.png") as ImageSource;
lightbarImgBrush.ImageSource = temp.Clone();
presetMenuUtil = new PresetMenuHelper(device);
MainColorChanged += ProfileSettingsViewModel_MainColorChanged;
MainColorRChanged += (sender, args) =>
{
@ -1920,4 +1930,313 @@ namespace DS4WinWPF.DS4Forms.ViewModels
outputMouseSpeed = CalculateOutputMouseSpeed(ButtonMouseSensitivity);
}
}
public class PresetMenuHelper
{
public enum ControlSelection : uint
{
None,
LeftStick,
RightStick,
DPad,
}
private Dictionary<ControlSelection, string> presetInputLabelDict =
new Dictionary<ControlSelection, string>()
{
[ControlSelection.None] = "None",
[ControlSelection.DPad] = "DPad",
[ControlSelection.LeftStick] = "Left Stick",
[ControlSelection.RightStick] = "Right Stick",
};
public Dictionary<ControlSelection, string> PresetInputLabelDict
{
get => presetInputLabelDict;
}
public string PresetInputLabel
{
get => presetInputLabelDict[highlightControl];
}
private ControlSelection highlightControl = ControlSelection.None;
public ControlSelection HighlightControl {
get => highlightControl;
}
private int deviceNum;
public PresetMenuHelper(int device)
{
deviceNum = device;
}
public ControlSelection PresetTagIndex(DS4Controls control)
{
ControlSelection controlInput = ControlSelection.None;
switch (control)
{
case DS4Controls.DpadUp:
case DS4Controls.DpadDown:
case DS4Controls.DpadLeft:
case DS4Controls.DpadRight:
controlInput = ControlSelection.DPad;
break;
case DS4Controls.LXNeg:
case DS4Controls.LXPos:
case DS4Controls.LYNeg:
case DS4Controls.LYPos:
controlInput = ControlSelection.LeftStick;
break;
case DS4Controls.RXNeg:
case DS4Controls.RXPos:
case DS4Controls.RYNeg:
case DS4Controls.RYPos:
controlInput = ControlSelection.RightStick;
break;
default:
break;
}
return controlInput;
}
public void SetHighlightControl(DS4Controls control)
{
ControlSelection controlInput = PresetTagIndex(control);
highlightControl = controlInput;
}
public List<DS4Controls> ModifySettingWithPreset(int baseTag, int subTag)
{
List<object> actionBtns = new List<object>(5);
List<DS4Controls> inputControls = new List<DS4Controls>(5);
if (baseTag == 0)
{
actionBtns.AddRange(new object[5]
{
null, null, null, null, null,
});
}
else if (baseTag == 1)
{
switch(subTag)
{
case 0:
actionBtns.AddRange(new object[4]
{
X360Controls.DpadUp, X360Controls.DpadDown,
X360Controls.DpadLeft, X360Controls.DpadRight,
});
break;
case 1:
actionBtns.AddRange(new object[4]
{
X360Controls.DpadDown, X360Controls.DpadUp,
X360Controls.DpadRight, X360Controls.DpadLeft,
});
break;
case 2:
actionBtns.AddRange(new object[4]
{
X360Controls.DpadUp, X360Controls.DpadDown,
X360Controls.DpadRight, X360Controls.DpadLeft,
});
break;
case 3:
actionBtns.AddRange(new object[4]
{
X360Controls.DpadDown, X360Controls.DpadUp,
X360Controls.DpadLeft, X360Controls.DpadRight,
});
break;
default:
break;
}
}
else if (baseTag == 2)
{
switch (subTag)
{
case 0:
actionBtns.AddRange(new object[5]
{
X360Controls.LYNeg, X360Controls.LYPos,
X360Controls.LXNeg, X360Controls.LXPos, X360Controls.LS,
});
break;
case 1:
actionBtns.AddRange(new object[5]
{
X360Controls.LYPos, X360Controls.LYNeg,
X360Controls.LXPos, X360Controls.LXNeg, X360Controls.LS,
});
break;
case 2:
actionBtns.AddRange(new object[5]
{
X360Controls.LYNeg, X360Controls.LYPos,
X360Controls.LXPos, X360Controls.LXNeg, X360Controls.LS,
});
break;
case 3:
actionBtns.AddRange(new object[5]
{
X360Controls.LYPos, X360Controls.LYNeg,
X360Controls.LXNeg, X360Controls.LXPos, X360Controls.LS,
});
break;
default:
break;
}
}
else if (baseTag == 3)
{
switch (subTag)
{
case 0:
actionBtns.AddRange(new object[5]
{
X360Controls.RYNeg, X360Controls.RYPos,
X360Controls.RXNeg, X360Controls.RXPos, X360Controls.RS,
});
break;
case 1:
actionBtns.AddRange(new object[5]
{
X360Controls.RYPos, X360Controls.RYNeg,
X360Controls.RXPos, X360Controls.RXNeg, X360Controls.RS,
});
break;
case 2:
actionBtns.AddRange(new object[5]
{
X360Controls.RYNeg, X360Controls.RYPos,
X360Controls.RXPos, X360Controls.RXNeg, X360Controls.RS,
});
break;
case 3:
actionBtns.AddRange(new object[5]
{
X360Controls.RYPos, X360Controls.RYNeg,
X360Controls.RXNeg, X360Controls.RXPos, X360Controls.RS,
});
break;
default:
break;
}
}
else if (baseTag == 4)
{
actionBtns.AddRange(new object[4]
{
X360Controls.Y, X360Controls.A, X360Controls.X, X360Controls.B,
});
}
else if (baseTag == 5)
{
actionBtns.AddRange(new object[4]
{
KeyInterop.VirtualKeyFromKey(Key.W), KeyInterop.VirtualKeyFromKey(Key.S),
KeyInterop.VirtualKeyFromKey(Key.A), KeyInterop.VirtualKeyFromKey(Key.D),
});
}
else if (baseTag == 6)
{
actionBtns.AddRange(new object[4]
{
KeyInterop.VirtualKeyFromKey(Key.Up), KeyInterop.VirtualKeyFromKey(Key.Down),
KeyInterop.VirtualKeyFromKey(Key.Left), KeyInterop.VirtualKeyFromKey(Key.Right),
});
}
else if (baseTag == 7)
{
switch (subTag)
{
case 0:
actionBtns.AddRange(new object[4]
{
X360Controls.MouseUp, X360Controls.MouseDown,
X360Controls.MouseLeft, X360Controls.MouseRight,
});
break;
case 1:
actionBtns.AddRange(new object[4]
{
X360Controls.MouseDown, X360Controls.MouseUp,
X360Controls.MouseRight, X360Controls.MouseLeft,
});
break;
case 2:
actionBtns.AddRange(new object[4]
{
X360Controls.MouseUp, X360Controls.MouseDown,
X360Controls.MouseRight, X360Controls.MouseLeft,
});
break;
case 3:
actionBtns.AddRange(new object[4]
{
X360Controls.MouseDown, X360Controls.MouseUp,
X360Controls.MouseLeft, X360Controls.MouseRight,
});
break;
default:
break;
}
}
switch (highlightControl)
{
case ControlSelection.DPad:
inputControls.AddRange(new DS4Controls[4]
{
DS4Controls.DpadUp, DS4Controls.DpadDown,
DS4Controls.DpadLeft, DS4Controls.DpadRight,
});
break;
case ControlSelection.LeftStick:
inputControls.AddRange(new DS4Controls[5]
{
DS4Controls.LYNeg, DS4Controls.LYPos,
DS4Controls.LXNeg, DS4Controls.LXPos, DS4Controls.L3,
});
break;
case ControlSelection.RightStick:
inputControls.AddRange(new DS4Controls[5]
{
DS4Controls.RYNeg, DS4Controls.RYPos,
DS4Controls.RXNeg, DS4Controls.RXPos, DS4Controls.R3,
});
break;
case ControlSelection.None:
default:
break;
}
int idx = 0;
foreach(DS4Controls dsControl in inputControls)
{
DS4ControlSettings setting = Global.getDS4CSetting(deviceNum, dsControl);
setting.Reset();
if (idx < actionBtns.Count && actionBtns[idx] != null)
{
object outAct = actionBtns[idx];
X360Controls defaultControl = Global.defaultButtonMapping[(int)dsControl];
if (!(outAct is X360Controls) || defaultControl != (X360Controls)outAct)
{
setting.UpdateSettings(false, outAct, null, DS4KeyType.None);
}
}
idx++;
}
return inputControls;
}
}
}