Skip to content

Commit

Permalink
Merge pull request #2696 from Nexus-Mods/open-library-on-loadout-create
Browse files Browse the repository at this point in the history
Open Library when managing game
  • Loading branch information
Al12rs authored Feb 20, 2025
2 parents d7f2507 + 743a7d3 commit 5ef3d49
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/NexusMods.App.UI/Pages/MyGames/MyGamesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using DynamicData.Aggregation;
using NexusMods.App.UI.Overlays;
using NexusMods.App.UI.Overlays.AlphaWarning;
using NexusMods.App.UI.Pages.LibraryPage;
using NexusMods.CrossPlatform.Process;
using NexusMods.Telemetry;

Expand Down Expand Up @@ -101,8 +102,10 @@ public MyGamesViewModel(
vm.State = GameWidgetState.AddingGame;
await Task.Run(async () => await ManageGame(installation));
vm.State = GameWidgetState.ManagedGame;

Tracking.AddEvent(Events.Game.AddGame, new EventMetadata(name: installation.Game.Name));

NavigateToFirstLoadoutLibrary(conn, installation);
});

vm.RemoveAllLoadoutsCommand = ReactiveCommand.CreateFromTask(async () =>
Expand All @@ -118,7 +121,7 @@ public MyGamesViewModel(

vm.ViewGameCommand = ReactiveCommand.Create(() =>
{
NavigateToFirstLoadout(conn, installation);
NavigateToFirstLoadoutLibrary(conn, installation);
Tracking.AddEvent(Events.Game.ViewGame, new EventMetadata(name: installation.Game.Name));
});

Expand Down Expand Up @@ -194,33 +197,34 @@ private async Task ManageGame(GameInstallation installation)
{
await installation.GetGame().Synchronizer.CreateLoadout(installation);
}

private void NavigateToFirstLoadout(IConnection conn, GameInstallation installation)
private Optional<LoadoutId> GetFirstLoadoutId(IConnection conn, GameInstallation installation)
{
var db = conn.Db;

var loadout = Loadout.All(db).FirstOrOptional(loadout => loadout.IsVisible()
&& loadout.InstallationInstance.Equals(installation)
);
if (!loadout.HasValue)
{
return;
}

var loadoutId = loadout.Value.LoadoutId;
var loadout = Loadout.All(db).FirstOrOptional(loadout =>
loadout.IsVisible() && loadout.InstallationInstance.Equals(installation));

return loadout.HasValue ? loadout.Value.LoadoutId : Optional<LoadoutId>.None;
}

private void NavigateToFirstLoadoutLibrary(IConnection conn, GameInstallation installation)
{
var fistLoadout = GetFirstLoadoutId(conn, installation);
if (!fistLoadout.HasValue) return;
var loadoutId = fistLoadout.Value;
Dispatcher.UIThread.Invoke(() =>
{
var workspaceController = _windowManager.ActiveWorkspaceController;

workspaceController.ChangeOrCreateWorkspaceByContext(
context => context.LoadoutId == loadoutId,
() => new PageData
{
FactoryId = LoadoutPageFactory.StaticId,
Context = new LoadoutPageContext
FactoryId = LibraryPageFactory.StaticId,
Context = new LibraryPageContext()
{
LoadoutId = loadoutId,
GroupScope = Optional<LoadoutItemGroupId>.None,
},
},
() => new LoadoutContext
Expand Down

0 comments on commit 5ef3d49

Please sign in to comment.