Skip to content

Commit

Permalink
0.2.0-Beta
Browse files Browse the repository at this point in the history
- Fixed issue with KPlayerPrefs serialization.
- Lock whole UI while game is running to avoid setting de-sync
- Super secret tooltip for Aki
  • Loading branch information
romen-h committed Apr 10, 2022
1 parent 6bc9891 commit 2d1434a
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 56 deletions.
9 changes: 6 additions & 3 deletions src/ONIModLauncher/Configs/KPlayerPrefsYaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace ONIModLauncher.Configs
{
public class KPlayerPrefsYaml : ConfigBase
{
private const string PlayShortOnLaunchKey = @"PlayShortOnLaunch";
private const string SaveFilenameKey = @"SaveFilenameKey/";

private const string ResolutionWidthKey = @"ResolutionWidth";
Expand All @@ -25,13 +26,10 @@ public class KPlayerPrefsYaml : ConfigBase

private string filePath;

[YamlMember(Alias = "strings")]
public Dictionary<string, string> strings = new Dictionary<string, string>();

[YamlMember(Alias = "ints")]
public Dictionary<string, int> ints = new Dictionary<string, int>();

[YamlMember(Alias = "floats")]
public Dictionary<string, float> floats = new Dictionary<string, float>();

[YamlIgnore]
Expand Down Expand Up @@ -106,6 +104,7 @@ public bool DLC1Enabled
}
}

[YamlIgnore]
public float UIScale
{
get => floats.ContainsKey(UIScalePrefKey) ? floats[UIScalePrefKey] : float.NaN;
Expand All @@ -119,6 +118,10 @@ public float UIScale

public KPlayerPrefsYaml()
{
if (GamePaths.HasDLC1)
{
strings[PlayShortOnLaunchKey] = @"intro\Spaced_Out_Intro";
}
SaveFile = "";
ResolutionWidth = 1920;
ResolutionHeight = 1080;
Expand Down
36 changes: 0 additions & 36 deletions src/ONIModLauncher/LaunchSettings.cs

This file was deleted.

43 changes: 42 additions & 1 deletion src/ONIModLauncher/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Threading.Tasks;
using System.Windows;

using ONIModLauncher.Configs;

namespace ONIModLauncher
{
public class Launcher : INotifyPropertyChanged
Expand All @@ -25,11 +27,25 @@ public static Launcher Instance

private Process process = null;

public bool CanLaunch => !IsRunning && GamePaths.GameExecutablePath != null;
public bool HasBaseGame => GamePaths.GameExecutablePath != null;

public bool CanLaunch => HasBaseGame && !IsRunning;

public bool CanToggleDLC1 => GamePaths.HasDLC1 && !IsRunning;

public bool CanEditLastSave => !IsRunning && DebugPrefs.AutoResumeLastSave;

public bool IsRunning
{ get; private set; } = false;

public bool IsNotRunning => !IsRunning;

public KPlayerPrefsYaml PlayerPrefs
{ get; private set; }

public DebugSettingsYaml DebugPrefs
{ get; private set; }

public event PropertyChangedEventHandler PropertyChanged;
private void InvokePropertyChanged(string propertyName)
{
Expand All @@ -44,6 +60,14 @@ private Launcher()
gameMonitor.DoWork += GameMonitor_DoWork;
gameMonitor.RunWorkerCompleted += GameMonitor_RunWorkerCompleted;
gameMonitor.WorkerSupportsCancellation = true;

LoadLaunchConfigs();
}

public void LoadLaunchConfigs()
{
PlayerPrefs = KPlayerPrefsYaml.Load(GamePaths.PlayerPrefsFile);
DebugPrefs = DebugSettingsYaml.Load(GamePaths.DebugSettingsFile);
}

public void StartGameMonitor()
Expand Down Expand Up @@ -76,6 +100,7 @@ private void GameMonitor_DoWork(object sender, DoWorkEventArgs e)

process = processes[0];
IsRunning = true;
OnLaunched();
InvokePropertyChanged(null);
}
}
Expand All @@ -87,6 +112,7 @@ private void GameMonitor_DoWork(object sender, DoWorkEventArgs e)
process.Dispose();
process = null;
IsRunning = false;
OnExited();
InvokePropertyChanged(null);
}
}
Expand All @@ -97,6 +123,17 @@ private void GameMonitor_DoWork(object sender, DoWorkEventArgs e)
private void GameMonitor_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{ }

private void OnLaunched()
{

}

private void OnExited()
{
ModManager.Instance.LoadModList(GamePaths.ModsConfigFile);
LoadLaunchConfigs();
}

public void Launch()
{
if (IsRunning) return;
Expand All @@ -114,6 +151,10 @@ public void Launch()
{
MessageBox.Show($"{GamePaths.ONI_EXE_NAME} did not start. (Unknown Reason)", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
OnLaunched();
}
}
}
catch (Exception ex)
Expand Down
26 changes: 14 additions & 12 deletions src/ONIModLauncher/LauncherSidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,36 @@
</StackPanel>
</Button>
<CheckBox x:Name="baseGameCheckbox" Padding="20,5,0,5"
IsEnabled="False"
IsChecked="{Binding Path=IsGameInstalled, Mode=OneWay}">
IsEnabled="False"
IsChecked="{Binding Path=HasBaseGame, Mode=OneWay}">
<Border BorderThickness="1" BorderBrush="Black">
<Image Source="/Assets/vanilla.jpg" Height="50"/>
</Border>
</CheckBox>
<CheckBox x:Name="dlc1Checkbox" Padding="20,5,0,5"
IsEnabled="{Binding Path=HasDLC1, Mode=OneWay}"
IsChecked="{Binding Path=PlayerPrefs.DLC1Enabled}">
IsEnabled="{Binding Path=CanToggleDLC1}"
IsChecked="{Binding Path=PlayerPrefs.DLC1Enabled}">
<Border BorderThickness="1" BorderBrush="Black">
<Image Source="/Assets/dlc1.jpg" Height="50"/>
</Border>
</CheckBox>
<CheckBox x:Name="debugModeCheckbox" Padding="20,5,0,5" Height="62"
IsChecked="{Binding Path=Debug.EnableDebug}">Debug Mode</CheckBox>
IsEnabled="{Binding Path=IsNotRunning}"
IsChecked="{Binding Path=Debug.EnableDebug}">Debug Mode</CheckBox>
<Grid>
<CheckBox x:Name="loadLastSaveCheckbox" Padding="20,5,0,5" Height="62"
IsEnabled="{Binding Path=IsNotRunning}"
IsChecked="{Binding Path=Debug.AutoResumeLastSave}">Load Last Save</CheckBox>
<Button x:Name="pickSaveButton" HorizontalAlignment="Right" VerticalAlignment="Center" Padding="10"
IsEnabled="{Binding Path=Debug.AutoResumeLastSave}"
Style="{StaticResource BlueButton}" FontSize="10"
Click="pickSaveButton_Click">Select Save</Button>
IsEnabled="{Binding Path=CanEditLastSave}"
Style="{StaticResource BlueButton}" FontSize="10"
Click="pickSaveButton_Click">Select Save</Button>
</Grid>
<Button x:Name="modFolderButton" Margin="0,10,0,0" Height="50"
Style="{StaticResource BlueButton}" FontSize="20"
Click="modFolderButton_Click">&#x1F4C1; Open Mods Folder</Button>
Style="{StaticResource BlueButton}" FontSize="20"
Click="modFolderButton_Click">&#x1F4C1; Open Mods Folder</Button>
<Button x:Name="gameLogButton" Margin="0,10,0,0" Height="50"
Style="{StaticResource BlueButton}" FontSize="20"
Click="gameLogButton_Click">&#x1F4C3; Open Game Log</Button>
Style="{StaticResource BlueButton}" FontSize="20"
Click="gameLogButton_Click">&#x1F4C3; Open Game Log</Button>
</StackPanel>
</UserControl>
2 changes: 1 addition & 1 deletion src/ONIModLauncher/LauncherSidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void pickSaveButton_Click(object sender, RoutedEventArgs e)

if (dlg.ShowDialog() == true)
{
LaunchSettings.Instance.PlayerPrefs.SaveFile = dlg.FileName;
Launcher.Instance.PlayerPrefs.SaveFile = dlg.FileName;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/ONIModLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@

<local:ModListControl x:Name="modsList" Grid.Column="1" Margin="20,0,0,0"/>
</Grid>

<Rectangle Grid.Row="1" Width="5" Height="5" Fill="{StaticResource LightBlueBrush}" Margin="3" IsHitTestVisible="True"
HorizontalAlignment="Right" VerticalAlignment="Top"
ToolTip="SUPER ULTRA IMPORTANT SECRET SPECIAL TOOLTIP FOR AKI! Sorry this can't make any frost buns or call you beautiful."/>
</Grid>
</Border>
</Window>
3 changes: 1 addition & 2 deletions src/ONIModLauncher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ private void window_Loaded(object sender, RoutedEventArgs e)
if (GamePaths.Init())
{
Launcher.Instance.StartGameMonitor();
sideBar.DataContext = LaunchSettings.Instance;
sideBar.launchButton.DataContext = Launcher.Instance;
sideBar.DataContext = Launcher.Instance;
modsList.DataContext = ModManager.Instance;
}
else
Expand Down
6 changes: 6 additions & 0 deletions src/ONIModLauncher/ModListControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,11 @@
<Button x:Name="sortModsButton" Margin="10,10,0,0" Width="100" Height="30" FontSize="16" Style="{StaticResource BlueButton}"
Click="sortModsButton_Click">Sort Mods</Button>
</StackPanel>

<Border x:Name="modListLockScreen" Grid.RowSpan="2" Background="Black" Opacity="0.9">
<Label HorizontalAlignment="Center" VerticalAlignment="Center"
Foreground="White"
FontSize="20" FontFamily="{StaticResource ONIFont}">Mod list cannot be changed while the game is running.</Label>
</Border>
</Grid>
</UserControl>
17 changes: 17 additions & 0 deletions src/ONIModLauncher/ModListControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ public partial class ModListControl : UserControl
public ModListControl()
{
InitializeComponent();

Launcher.Instance.PropertyChanged += Launcher_PropertyChanged;

IsEnabled = Launcher.Instance.IsNotRunning;
modListLockScreen.Visibility = Visibility.Collapsed;
}

private void Launcher_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(() => Launcher_PropertyChanged(sender, e));
return;
}

IsEnabled = Launcher.Instance.IsNotRunning;
modListLockScreen.Visibility = Launcher.Instance.IsNotRunning ? Visibility.Collapsed : Visibility.Visible;
}

private void refreshModsButton_Click(object sender, RoutedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/ONIModLauncher/ONIModLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Description>A mod manager and launcher for Oxygen Not Included.</Description>
<PackageProjectUrl>https://github.com/romen-h/ONI-ModLauncher</PackageProjectUrl>
<RepositoryUrl>https://github.com/romen-h/ONI-ModLauncher</RepositoryUrl>
<Version>0.1.0</Version>
<Version>0.2.0</Version>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<StartupObject>ONIModLauncher.App</StartupObject>
<RootNamespace>ONIModLauncher</RootNamespace>
Expand Down

0 comments on commit 2d1434a

Please sign in to comment.