Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TopBar subtitle for displaying Loadout Name #1953

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/NexusMods.App.UI/Controls/TopBar/ITopBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace NexusMods.App.UI.Controls.TopBar;
public interface ITopBarViewModel : IViewModelInterface
{
public string ActiveWorkspaceTitle { get; }

public string ActiveWorkspaceSubtitle { get; }

public ReactiveCommand<NavigationInformation, Unit> OpenSettingsCommand { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TopBarDesignViewModel : AViewModel<ITopBarViewModel>, ITopBarViewMo
[Reactive] public bool IsPremium { get; set; } = true;
[Reactive] public IImage Avatar { get; set; } = new Bitmap(AssetLoader.Open(new Uri("avares://NexusMods.App.UI/Assets/DesignTime/cyberpunk_game.png")));
[Reactive] public string ActiveWorkspaceTitle { get; set; } = "Home";
[Reactive] public string ActiveWorkspaceSubtitle { get; set; } = "Loadout A";

[Reactive] public IAddPanelDropDownViewModel AddPanelDropDownViewModel { get; set; } = new AddPanelDropDownDesignViewModel();

Expand Down
19 changes: 14 additions & 5 deletions src/NexusMods.App.UI/Controls/TopBar/TopBarView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@

<Grid ColumnDefinitions="Auto, *, Auto" x:Name="MainGrid" Height="56" VerticalAlignment="Top">

<TextBlock Grid.Column="0"
Classes="HeadingXSSemi ForegroundSubdued"
VerticalAlignment="Center"
Margin="16,0"
x:Name="ActiveWorkspaceTitleTextBlock" />
<StackPanel Grid.Column="0"
Orientation="Horizontal"
Classes="Spacing-1_5"
Margin="16,0"
VerticalAlignment="Center">
<TextBlock Classes="HeadingXSSemi ForegroundSubdued"
x:Name="ActiveWorkspaceTitleTextBlock" />

<TextBlock Classes="BodyMDNormal ForegroundSubdued"
x:Name="ActiveWorkspaceSubtitleTextBlock"
VerticalAlignment="Center"/>
</StackPanel>



<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
<Button x:Name="GoBackInHistory" Classes="Action" Width="40" Height="40">
Expand Down
3 changes: 3 additions & 0 deletions src/NexusMods.App.UI/Controls/TopBar/TopBarView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public TopBarView()
{
this.OneWayBind(ViewModel, vm => vm.ActiveWorkspaceTitle, view => view.ActiveWorkspaceTitleTextBlock.Text)
.DisposeWith(d);

this.OneWayBind(ViewModel, vm => vm.ActiveWorkspaceSubtitle, view => view.ActiveWorkspaceSubtitleTextBlock.Text)
.DisposeWith(d);

this.BindCommand(ViewModel, vm => vm.SelectedTab!.GoBackInHistoryCommand, view => view.GoBackInHistory)
.DisposeWith(d);
Expand Down
5 changes: 5 additions & 0 deletions src/NexusMods.App.UI/Controls/TopBar/TopBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class TopBarViewModel : AViewModel<ITopBarViewModel>, ITopBarViewModel
private readonly ILogger<TopBarViewModel> _logger;

[Reactive] public string ActiveWorkspaceTitle { get; [UsedImplicitly] set; } = string.Empty;
[Reactive] public string ActiveWorkspaceSubtitle { get; [UsedImplicitly] set; } = string.Empty;

public ReactiveCommand<NavigationInformation, Unit> OpenSettingsCommand { get; }

Expand Down Expand Up @@ -153,6 +154,10 @@ public TopBarViewModel(
workspaceController.WhenAnyValue(controller => controller.ActiveWorkspace.Title)
.BindToVM(this, vm => vm.ActiveWorkspaceTitle)
.DisposeWith(d);

workspaceController.WhenAnyValue(controller => controller.ActiveWorkspace.Subtitle)
.BindToVM(this, vm => vm.ActiveWorkspaceSubtitle)
.DisposeWith(d);

workspaceController.WhenAnyValue(controller => controller.ActiveWorkspace.SelectedTab)
.BindToVM(this, vm => vm.SelectedTab)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public string CreateTitle(DownloadsContext context)
{
return Language.Downloads_WorkspaceTitle;
}

public string CreateSubtitle(DownloadsContext context)
{
return string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public string CreateTitle(HomeContext context)
{
return Language.HomeWorkspace_Title;
}

public string CreateSubtitle(HomeContext context)
{
return string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ public interface IWorkspaceAttachmentsFactory
/// <summary>
/// Returns whether the factory supports the given workspace context.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
bool IsSupported(IWorkspaceContext context);

/// <summary>
/// Returns the title for the workspace context, or null if the factory does not support the given context.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
string? CreateTitle(IWorkspaceContext context);

/// <summary>
/// Returns the subtitle for the workspace context, or null if the factory does not support the given context.
/// </summary>
string? CreateSubtitle(IWorkspaceContext context);
}


Expand All @@ -37,11 +38,21 @@ bool IWorkspaceAttachmentsFactory.IsSupported(IWorkspaceContext context)
{
return IsSupported(context) ? CreateTitle((TContext) context) : null;
}

/// <inheritdoc/>
string? IWorkspaceAttachmentsFactory.CreateSubtitle(IWorkspaceContext context)
{
return IsSupported(context) ? CreateSubtitle((TContext) context) : null;
}

/// <summary>
/// Generic version of <see cref="IWorkspaceAttachmentsFactory.CreateTitle"/>, that makes implementing factories easier.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
string CreateTitle(TContext context);

/// <summary>
/// Generic version of <see cref="IWorkspaceAttachmentsFactory.CreateSubtitle"/>, that makes implementing factories easier.
/// </summary>
string CreateSubtitle(TContext context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ public string CreateTitle(LoadoutContext context)
var loadout = Loadout.Load(conn.Db, context.LoadoutId);
return loadout.InstallationInstance.Game.Name;
}

public string CreateSubtitle(LoadoutContext context)
{
// Use the loadout name as the subtitle
var loadout = Loadout.Load(conn.Db, context.LoadoutId);
return loadout.Name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface IWorkspaceAttachmentsFactoryManager
public ILeftMenuViewModel? CreateLeftMenuFor(IWorkspaceContext context, WorkspaceId workspaceId, IWorkspaceController workspaceController);

public string CreateTitleFor(IWorkspaceContext context);

public string CreateSubtitleFor(IWorkspaceContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ public string CreateTitleFor(IWorkspaceContext context)
.Select(f => f.CreateTitle(context))
.FirstOrDefault(t => t != null) ?? string.Empty;
}

public string CreateSubtitleFor(IWorkspaceContext context)
{
return AttachmentsFactories
.Select(f => f.CreateSubtitle(context))
.FirstOrDefault(t => t != null) ?? string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public interface IWorkspaceViewModel : IViewModelInterface
/// A title for the workspace to be displayed in the window.
/// </summary>
public string Title { get; set; }

/// <summary>
/// A subtitle for the workspace to be displayed in the window.
/// </summary>
public string Subtitle { get; set; }

/// <summary>
/// Gets or sets the context of the workspace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class WorkspaceViewModel : AViewModel<IWorkspaceViewModel>, IWorkspaceVie
/// <inheritdoc/>
[Reactive] public string Title { get; set; } = string.Empty;

[Reactive] public string Subtitle { get; set; } = string.Empty;

/// <inheritdoc/>
public IWorkspaceContext Context { get; set; } = EmptyContext.Instance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public IWorkspaceViewModel CreateWorkspace(Optional<IWorkspaceContext> context,
};

vm.Title = _workspaceAttachmentsFactory.CreateTitleFor(vm.Context);
vm.Subtitle = _workspaceAttachmentsFactory.CreateSubtitleFor(vm.Context);

_workspaces.AddOrUpdate(vm);

Expand Down
Loading