Skip to content

Commit

Permalink
Add UI explanation and toggle for launching games
Browse files Browse the repository at this point in the history
Adds 'autostart game' toggle. User can turn it off and `--launch=` will
be ignored.

When `--launch=` option is passed explanation dialog will appear with
option to launch game or not and hide the dialog on subsequent runs.

This allows launchers like Rai Pal to always pass `--launch=` along with
`--attach=`.
  • Loading branch information
keton committed Jan 23, 2024
1 parent 952754b commit f861467
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
26 changes: 26 additions & 0 deletions UEVR/GameAutoStartExplanationDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Window x:Class="UEVR.GameAutoStartExplanationDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UEVR"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
FontFamily="{DynamicResource MaterialDesignFont}"
Background="#FF1A1B1C"
SizeToContent="WidthAndHeight" ResizeMode="NoResize" Icon="/UEVR2.png"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
Title="Game autostart" Height="200" Width="400">
<StackPanel>
<TextBlock Text="Game auto start attempt detected.&#x0a;You can configure autostart by toggling 'Autostart game' in settings" Margin="10" />
<CheckBox x:Name="chkRememberChoice" Content="Remember my choice" Margin="10" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="10">
<Button x:Name="btnStartGame" Content="Start game" Width="125" Margin="5" Click="btnStartGame_Click"/>
<Button x:Name="btnWaitForGameStart" Content="I'll start it myself" Width="140" Margin="5" Click="btnWaitForGameStart_Click"/>
</StackPanel>
</StackPanel>
</Window>
29 changes: 29 additions & 0 deletions UEVR/GameAutoStartExplanationDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace UEVR {
public partial class GameAutoStartExplanationDialog : Window {
public bool HideAutostartWarning { get; private set; }
public bool DialogResultStartGame { get; private set; }

public GameAutoStartExplanationDialog() {
InitializeComponent();
}

private void btnStartGame_Click(object sender, RoutedEventArgs e) {
HideAutostartWarning = chkRememberChoice.IsChecked == true;
DialogResultStartGame = true;
this.Close();
}

private void btnWaitForGameStart_Click(object sender, RoutedEventArgs e) {
HideAutostartWarning = chkRememberChoice.IsChecked == true;
DialogResultStartGame = false;
this.Close();
}
}
}
4 changes: 4 additions & 0 deletions UEVR/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
<ToggleButton x:Name="m_focusGameOnInjectionCheckbox" HorizontalAlignment="Left" IsChecked="True"/>
<TextBlock TextWrapping="Wrap" Text="Focus game on injection"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<ToggleButton x:Name="m_gameAutoStartCheckbox" HorizontalAlignment="Left" IsChecked="True"/>
<TextBlock TextWrapping="Wrap" Text="Autostart game"/>
</StackPanel>
</StackPanel>
<TextBlock x:Name="m_connectionStatus" TextWrapping="Wrap" Text="Unknown status"/>
</StackPanel>
Expand Down
24 changes: 24 additions & 0 deletions UEVR/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public partial class MainWindow : Window {
private string? m_commandLineLaunchArgs = null;
private int m_commandLineDelayInjection = 0;
private bool m_ignoreFutureVDWarnings = false;
private bool m_gameAutostartExplanationShown = false;

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
Expand Down Expand Up @@ -238,6 +239,8 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
m_nullifyVRPluginsCheckbox.IsChecked = m_mainWindowSettings.NullifyVRPluginsCheckbox;
m_ignoreFutureVDWarnings = m_mainWindowSettings.IgnoreFutureVDWarnings;
m_focusGameOnInjectionCheckbox.IsChecked = m_mainWindowSettings.FocusGameOnInjection;
m_gameAutoStartCheckbox.IsChecked = m_mainWindowSettings.GameAutoStart;
m_gameAutostartExplanationShown = m_mainWindowSettings.GameAutoStartExplanationShown;

m_updateTimer.Tick += (sender, e) => Dispatcher.Invoke(MainWindow_Update);
m_updateTimer.Start();
Expand Down Expand Up @@ -293,6 +296,25 @@ private void Update_InjectStatus() {
TimeSpan oneSecond = TimeSpan.FromSeconds(1);

if (m_commandLineLaunchExe != null && !m_launchExeDone) {
if(m_gameAutostartExplanationShown == false) {
var dialog = new GameAutoStartExplanationDialog();
dialog.ShowDialog();

m_gameAutostartExplanationShown = dialog.HideAutostartWarning;

if(m_gameAutostartExplanationShown) {
m_gameAutoStartCheckbox.IsChecked = dialog.DialogResultStartGame;
}

if(!dialog.DialogResultStartGame) {
m_launchExeDone = true;
return;
}
} else if(m_gameAutoStartCheckbox.IsChecked == false) {
m_launchExeDone = true;
return;
}

if(m_commandLineAttachExePath != null && m_commandLineAttachExe != null) {
if(!IsUnrealEngineGame(m_commandLineAttachExePath, m_commandLineAttachExe)) {
var result = MessageBox.Show(m_lastSelectedProcessName + " does not appear to be an Unreal Engine title.\n" +
Expand Down Expand Up @@ -678,6 +700,8 @@ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEvent
m_mainWindowSettings.NullifyVRPluginsCheckbox = m_nullifyVRPluginsCheckbox.IsChecked == true;
m_mainWindowSettings.IgnoreFutureVDWarnings = m_ignoreFutureVDWarnings;
m_mainWindowSettings.FocusGameOnInjection = m_focusGameOnInjectionCheckbox.IsChecked == true;
m_mainWindowSettings.GameAutoStart = m_gameAutoStartCheckbox.IsChecked == true;
m_mainWindowSettings.GameAutoStartExplanationShown = m_gameAutostartExplanationShown;

m_mainWindowSettings.Save();
}
Expand Down
14 changes: 14 additions & 0 deletions UEVR/MainWindowSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,19 @@ public bool FocusGameOnInjection
get { return (bool)this["FocusGameOnInjection"]; }
set { this["FocusGameOnInjection"] = value; }
}

[UserScopedSettingAttribute()]
[DefaultSettingValueAttribute("true")]
public bool GameAutoStart {
get { return (bool)this["GameAutoStart"]; }
set { this["GameAutoStart"] = value; }
}

[UserScopedSettingAttribute()]
[DefaultSettingValueAttribute("false")]
public bool GameAutoStartExplanationShown {
get { return (bool)this["GameAutoStartExplanationShown"]; }
set { this["GameAutoStartExplanationShown"] = value; }
}
}
}

0 comments on commit f861467

Please sign in to comment.