Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion SilkySouls3/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public MainWindow()
paramService, debugDrawService, chrInsService, spEffectService, eventService, reminderService,
itemService);
var itemViewModel = new ItemViewModel(itemService, _stateService);
var settingsViewModel = new SettingsViewModel(settingsService, hotkeyManager, _stateService);
var activateOnLaunchManager = new ActivateOnLaunchManager();
var activateOnLaunchViewModel = new ActivateOnLaunchViewModel(playerViewModel, targetViewModel,
utilityViewModel, travelViewModel, itemViewModel, activateOnLaunchManager, _stateService);
var settingsViewModel = new SettingsViewModel(settingsService, hotkeyManager, _stateService,
activateOnLaunchViewModel);

var playerTab = new PlayerTab(playerViewModel);
var utilityTab = new UtilityTab(utilityViewModel);
Expand All @@ -111,6 +115,9 @@ public MainWindow()
MainTabControl.Items.Add(new TabItem { Header = "Settings", Content = settingsTab });

settingsViewModel.ApplyStartUpOptions();

_stateService.Publish(State.AppStart);

Closing += MainWindow_Closing;

_gameLoadedTimer = new DispatcherTimer
Expand Down
6 changes: 6 additions & 0 deletions SilkySouls3/SilkySouls3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<Compile Include="Services\StateService.cs" />
<Compile Include="Services\TravelService.cs" />
<Compile Include="Services\UtilityService.cs" />
<Compile Include="Utilities\ActivateOnLaunchManager.cs" />
<Compile Include="Utilities\AsmHelper.cs" />
<Compile Include="Utilities\AsmLoader.cs" />
<Compile Include="Utilities\DataLoader.cs" />
Expand All @@ -211,6 +212,7 @@
<Compile Include="Utilities\UpDownHelper.cs" />
<Compile Include="Utilities\User32.cs" />
<Compile Include="Utilities\VersionChecker.cs" />
<Compile Include="ViewModels\ActivateOnLaunchViewModel.cs" />
<Compile Include="ViewModels\BaseViewModel.cs" />
<Compile Include="ViewModels\EnemyViewModel.cs" />
<Compile Include="ViewModels\SpEffectViewModel.cs" />
Expand All @@ -222,6 +224,9 @@
<Compile Include="ViewModels\SettingsViewModel.cs" />
<Compile Include="ViewModels\TravelViewModel.cs" />
<Compile Include="ViewModels\UtilityViewModel.cs" />
<Compile Include="Views\ActivateOnLaunchWindow.xaml.cs">
<DependentUpon>ActivateOnLaunchWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\CreateCustomWarpWindow.xaml.cs" />
<Compile Include="Views\CreateLoadoutWindow.xaml.cs">
<DependentUpon>CreateLoadoutWindow.xaml</DependentUpon>
Expand Down Expand Up @@ -275,6 +280,7 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Views\ActivateOnLaunchWindow.xaml" />
<Page Include="Views\CreateCustomWarpWindow.xaml" />
<Page Include="Views\CreateLoadoutWindow.xaml" />
<Page Include="Views\CustomMessageBox.xaml" />
Expand Down
72 changes: 72 additions & 0 deletions SilkySouls3/Utilities/ActivateOnLaunchManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace SilkySouls3.Utilities
{
public class ActivateOnLaunchManager
{
private readonly Dictionary<string, string> _values = new();

public ActivateOnLaunchManager()
{
Load();
}

public bool GetBool(string actionId)
{
return _values.TryGetValue(actionId, out var v) && bool.TryParse(v, out var b) && b;
}

public void SetBool(string actionId, bool value)
{
_values[actionId] = value.ToString();
Save();
}

public int GetInt(string actionId, int defaultValue = 0)
{
return _values.TryGetValue(actionId, out var v) && int.TryParse(v, out var i) ? i : defaultValue;
}

public void SetInt(string actionId, int value)
{
_values[actionId] = value.ToString();
Save();
}

public void Save()
{
try
{
SettingsManager.Default.ActivateOnLaunchActionIds = string.Join(",", _values.Select(kv => $"{kv.Key}:{kv.Value}"));
SettingsManager.Default.Save();
}
catch (Exception ex)
{
Console.WriteLine($@"Error saving activate on launch settings: {ex.Message}");
}
}

public void Load()
{
try
{
_values.Clear();
var raw = SettingsManager.Default.ActivateOnLaunchActionIds;
if (string.IsNullOrEmpty(raw)) return;

foreach (var token in raw.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
var separatorIndex = token.IndexOf(':');
if (separatorIndex <= 0) continue;
_values[token.Substring(0, separatorIndex)] = token.Substring(separatorIndex + 1);
}
}
catch (Exception ex)
{
Console.WriteLine($@"Error loading activate on launch settings: {ex.Message}");
}
}
}
}
3 changes: 3 additions & 0 deletions SilkySouls3/Utilities/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class SettingsManager
public double SpEffectWindowTop { get; set; }
public bool SpEffectAlwaysOnTop { get; set; }

public bool ActivateOnLaunchEnabled { get; set; }
public string ActivateOnLaunchActionIds { get; set; } = "";

private static string SettingsPath => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"SilkySouls3",
Expand Down
Loading