Skip to content

Commit

Permalink
improve quicktools
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Jul 22, 2022
1 parent 139d819 commit a5ad995
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 23 deletions.
1 change: 1 addition & 0 deletions HandheldCompanion/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<!-- Other app resources here -->
<converters:InverseAppThemeConverter x:Key="InverseAppThemeConverter" />
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<converters:IsEnabledConverter x:Key="IsEnabledConverter" />

</ResourceDictionary>
</Application.Resources>
Expand Down
33 changes: 33 additions & 0 deletions HandheldCompanion/Converters/IsEnabledConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace HandheldCompanion.Converters
{
public sealed class IsEnabledConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
foreach (var value in values)
{
switch (value)
{
case bool b when !b:
case int i when i == 0:
return false;
}
}

return true;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
}
22 changes: 22 additions & 0 deletions HandheldCompanion/Managers/InputsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ private string GetTriggerFromName(string name)
return "";
}

public void KeyPress(VirtualKeyCode key)
{
TriggerLock = true;

m_InputSimulator.Keyboard.KeyPress(key);

TriggerLock = false;
}

public void KeyPress(VirtualKeyCode[] keys)
{
TriggerLock = true;

foreach (VirtualKeyCode key in keys)
m_InputSimulator.Keyboard.KeyDown(key);

foreach (VirtualKeyCode key in keys)
m_InputSimulator.Keyboard.KeyUp(key);

TriggerLock = false;
}

private void ReleaseBuffer(object? sender, EventArgs e)
{
if (TriggerBuffer.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
</Grid>
</ui:SimpleStackPanel>
</DockPanel>

</Border>
</ui:SimpleStackPanel>

Expand Down
76 changes: 60 additions & 16 deletions HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
<ui:FontIcon FontFamily="{DynamicResource SymbolThemeFontFamily}" Glyph="&#xE748;" Height="40" HorizontalAlignment="Center"/>

<ui:SimpleStackPanel VerticalAlignment="Center" Margin="12,0,0,0">
<TextBlock Name="ProcessName" FontSize="14"/>
<TextBlock Name="ProcessName" Text="Waiting for foreground process..." FontSize="14"/>
<TextBlock Name="ProcessPath" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" TextWrapping="Wrap"/>
</ui:SimpleStackPanel>
</DockPanel>
</Grid>
</Border>
</Grid>

<!-- Buttons -->
<Button Name="b_CreateProfile" Margin="12,2,15,2" Click="b_CreateProfile_Click" HorizontalAlignment="Stretch" Content="Create profile" Style="{DynamicResource AccentButtonStyle}" Visibility="Collapsed" />

<Button Name="b_UpdateProfile" Margin="15,2,15,2" Click="b_UpdateProfile_Click" HorizontalAlignment="Stretch" Content="Update profile" Style="{DynamicResource AccentButtonStyle}" Visibility="Collapsed" />

<ui:SimpleStackPanel Spacing="6" Name="GridProfile" Visibility="Collapsed">
<Grid Name="StackProfileToggle">
<!-- Header -->
Expand Down Expand Up @@ -95,13 +97,28 @@

<ui:ToggleSwitch Name="UMCToggle" Grid.Column="1" Toggled="UMCToggle_Toggled" />
</Grid>
</ui:SimpleStackPanel>
</Border>
</Grid>

<!-- Separator -->
<Separator BorderBrush="{DynamicResource SystemControlBackgroundChromeMediumBrush}" BorderThickness="0 1 0 0" />
<Grid Name="StackProfileUMCSettings">
<!-- Header -->
<Border
Padding="15,12,15,12"
CornerRadius="{DynamicResource ControlCornerRadius}"
Background="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}">

<Border.IsEnabled>
<MultiBinding Converter="{StaticResource IsEnabledConverter}">
<Binding ElementName="ProfileToggle" Path="IsOn"/>
<Binding ElementName="UMCToggle" Path="IsOn"/>
</MultiBinding>
</Border.IsEnabled>

<ui:SimpleStackPanel Spacing="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="380"></ColumnDefinition>
<ColumnDefinition MinWidth="420"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>

Expand All @@ -110,15 +127,16 @@
<TextBlock Name="Text_InputHint" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" TextWrapping="Wrap"/>
</StackPanel>
</Grid>

<ui:RadioButtons Margin="6,0,0,0" Name="cB_Input" Grid.Column="1" HorizontalAlignment="Left" MaxColumns="1" VerticalAlignment="Center" SelectedIndex="0" SelectionChanged="cB_Input_SelectionChanged"/>

<!-- Content -->
<ui:RadioButtons Margin="6,0,0,0" Name="cB_Input" Grid.Column="1" HorizontalAlignment="Left" MaxColumns="3" VerticalAlignment="Center" SelectedIndex="0" SelectionChanged="cB_Input_SelectionChanged"/>

<!-- Separator -->
<Separator BorderBrush="{DynamicResource SystemControlBackgroundChromeMediumBrush}" BorderThickness="0 1 0 0" />

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="380"></ColumnDefinition>
<ColumnDefinition MinWidth="420"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>

Expand All @@ -128,19 +146,47 @@
</StackPanel>

</Grid>

<ui:RadioButtons Margin="6,0,0,0" Name="cB_Output" Grid.Column="1" HorizontalAlignment="Left" MaxColumns="1" VerticalAlignment="Center" SelectedIndex="0" SelectionChanged="cB_Output_SelectionChanged"/>

<!-- Content -->
<ui:RadioButtons Margin="6,0,0,0" Name="cB_Output" Grid.Column="1" HorizontalAlignment="Left" MaxColumns="3" VerticalAlignment="Center" SelectedIndex="0" SelectionChanged="cB_Output_SelectionChanged"/>

<ui:SimpleStackPanel Spacing="10" Name="GridSensivity">
<!-- Separator -->
<Separator BorderBrush="{DynamicResource SystemControlBackgroundChromeMediumBrush}" BorderThickness="0 1 0 0" />

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="420"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>

<StackPanel Orientation="Vertical">
<TextBlock Text="{x:Static resx:Resources.ProfileSettingsMode0_Sensivity}" ToolTip="{x:Static resx:Resources.ProfilesPage_StyleofOutputTooltip}" FontSize="14"/>
<TextBlock Text="{x:Static resx:Resources.ProfileSettingsMode0_SensivityDesc}" Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}" FontSize="12" TextWrapping="Wrap"/>
</StackPanel>
</Grid>

<!-- Content -->
<DockPanel Grid.Column="1" Margin="0,0,0,0">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Value, StringFormat=N0, ElementName=SliderSensivity, Mode=OneWay}" />
<Slider Name="SliderSensivity" Width="350" HorizontalAlignment="Right" VerticalAlignment="Center" AutoToolTipPlacement="TopLeft" LargeChange="2" Maximum="20" Minimum="1" Value="1" TickPlacement="BottomRight" SmallChange="1" AutoToolTipPrecision="0" IsSnapToTickEnabled="True"
MouseEnter="Scrolllock_MouseEnter"
MouseLeave="Scrolllock_MouseLeave"/>
</DockPanel>
</ui:SimpleStackPanel>

</ui:SimpleStackPanel>
</Border>
</Grid>

<!-- Thermal Power (TDP) Limit -->
<ui:SimpleStackPanel Name="StackProfilePower" Spacing="2">
<!-- Header -->
<Border
Padding="15,12,15,12"
CornerRadius="{DynamicResource ControlCornerRadius}"
Background="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}">
<Border
Padding="15,12,15,12"
CornerRadius="{DynamicResource ControlCornerRadius}"
Background="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}"
IsEnabled="{Binding ElementName=ProfileToggle, Path=IsOn}">

<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -179,8 +225,6 @@

</Border>
</ui:SimpleStackPanel>

<Button Name="b_UpdateProfile" Margin="15,2,15,2" Click="b_UpdateProfile_Click" HorizontalAlignment="Stretch" Content="Update profile" Style="{DynamicResource AccentButtonStyle}" />
</ui:SimpleStackPanel>

</ui:SimpleStackPanel>
Expand Down
22 changes: 21 additions & 1 deletion HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public QuickProfilesPage()

private void ProfileDeleted(Profile profile)
{
if (currentProfile is null)
return;

if (profile.executable == currentProfile.executable)
{
currentProcess = null;
Expand All @@ -114,11 +117,15 @@ private void ProfileUpdated(Profile profile, bool backgroundtask)
if (currentProfile == null)
{
b_CreateProfile.Visibility = Visibility.Visible;

b_UpdateProfile.Visibility = Visibility.Collapsed;
GridProfile.Visibility = Visibility.Collapsed;
}
else if (profile.executable == currentProfile.executable)
{
b_CreateProfile.Visibility = Visibility.Collapsed;

b_UpdateProfile.Visibility = Visibility.Visible;
GridProfile.Visibility = Visibility.Visible;

ProfileToggle.IsEnabled = true;
Expand All @@ -129,9 +136,11 @@ private void ProfileUpdated(Profile profile, bool backgroundtask)

// Power settings
TDPToggle.IsOn = currentProfile.TDP_override;

double TDP = currentProfile.TDP_value != 0 ? currentProfile.TDP_value : MainWindow.handheldDevice.DefaultTDP;
TDPSlider.Value = TDP;

// Sensivity settings
SliderSensivity.Value = currentProfile.aiming_sensivity;
}
});
}
Expand Down Expand Up @@ -202,9 +211,11 @@ private void cB_Input_SelectionChanged(object sender, SelectionChangedEventArgs
case Input.PlayerSpace:
case Input.JoystickCamera:
cB_Output.SelectedIndex = (int)Output.RightStick;
GridSensivity.Visibility = Visibility.Visible;
break;
case Input.JoystickSteering:
cB_Output.SelectedIndex = (int)Output.LeftStick;
GridSensivity.Visibility = Visibility.Collapsed;
break;
}

Expand Down Expand Up @@ -259,5 +270,14 @@ private void TDPSlider_ValueChanged(object sender, RoutedPropertyChangedEventArg
// Power settings
currentProfile.TDP_value = (int)TDPSlider.Value;
}

private void SliderSensivity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (currentProfile is null)
return;

// Sensivity settings
currentProfile.aiming_sensivity = (float)SliderSensivity.Value;
}
}
}
6 changes: 3 additions & 3 deletions HandheldCompanion/Views/Windows/QuickTools.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
</ui:NavigationView.MenuItems>

<ui:NavigationView.FooterMenuItems>
<ui:NavigationViewItem Name="shortcutKeyboard" Tag="shortcutKeyboard" Background="{DynamicResource SystemControlHighlightAltListAccentLowBrush}" SelectsOnInvoked="False">
<ui:NavigationViewItem Name="shortcutKeyboard" Tag="shortcutKeyboard" Foreground="{DynamicResource AccentAAFillColorDefaultBrush}" SelectsOnInvoked="False">
<ui:NavigationViewItem.Icon>
<ui:FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE765;"></ui:FontIcon>
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Name="shortcutDesktop" Tag="shortcutDesktop" Background="{DynamicResource SystemControlHighlightAltListAccentLowBrush}" SelectsOnInvoked="False">
<ui:NavigationViewItem Name="shortcutDesktop" Tag="shortcutDesktop" Foreground="{DynamicResource AccentAAFillColorDefaultBrush}" SelectsOnInvoked="False">
<ui:NavigationViewItem.Icon>
<ui:FontIcon FontFamily="HoloLens MDL2 Assets" Glyph="&#xE782;"></ui:FontIcon>
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>
<ui:NavigationViewItem Name="shortcutESC" Tag="shortcutESC" Background="{DynamicResource SystemControlHighlightAltListAccentLowBrush}" SelectsOnInvoked="False">
<ui:NavigationViewItem Name="shortcutESC" Tag="shortcutESC" Foreground="{DynamicResource AccentAAFillColorDefaultBrush}" SelectsOnInvoked="False">
<ui:NavigationViewItem.Icon>
<ui:FontIcon FontFamily="SegoeUI" Glyph="ESC"></ui:FontIcon>
</ui:NavigationViewItem.Icon>
Expand Down
10 changes: 8 additions & 2 deletions HandheldCompanion/Views/Windows/QuickTools.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HandheldCompanion.Extensions;
using GregsStack.InputSimulatorStandard.Native;
using HandheldCompanion.Extensions;
using HandheldCompanion.Managers;
using HandheldCompanion.Views.QuickPages;
using ModernWpf.Controls;
Expand Down Expand Up @@ -120,10 +121,15 @@ private void navView_ItemInvoked(NavigationView sender, NavigationViewItemInvoke

switch (navItemTag)
{
// summon touch keyboard
case "shortcutKeyboard":
StartTabTip();
break;
case "shortcutDesktop":
MainWindow.inputsManager.KeyPress(new VirtualKeyCode[] { VirtualKeyCode.LWIN, VirtualKeyCode.VK_D });
break;
case "shortcutESC":
MainWindow.inputsManager.KeyPress(VirtualKeyCode.ESCAPE);
break;
default:
preNavItemTag = navItemTag;
break;
Expand Down

0 comments on commit a5ad995

Please sign in to comment.