Skip to content

Commit

Permalink
Add warning modal dialog (#1390)
Browse files Browse the repository at this point in the history
* Add warning modal dialog

* Show warning overlay when clicking help button

* Hide useless top bar buttons
  • Loading branch information
erri120 authored May 21, 2024
1 parent 7fe5043 commit c2a7369
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 36 deletions.
12 changes: 4 additions & 8 deletions src/NexusMods.App.UI/Controls/TopBar/TopBarView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,19 @@
Margin="16,0"
x:Name="ActionStackPanel">

<Button Classes="Action"
x:Name="HistoryActionButton">
<Button Classes="Action" x:Name="HistoryActionButton" IsVisible="False">
<icons:UnifiedIcon Classes="History ForegroundSubdued" />
</Button>

<Button Classes="Action"
x:Name="UndoActionButton">
<Button Classes="Action" x:Name="UndoActionButton" IsVisible="False">
<icons:UnifiedIcon Classes="Undo ForegroundSubdued" />
</Button>

<Button Classes="Action"
x:Name="RedoActionButton">
<Button Classes="Action" x:Name="RedoActionButton" IsVisible="False">
<icons:UnifiedIcon Classes="Redo ForegroundSubdued" />
</Button>

<Button Classes="Action"
x:Name="HelpActionButton">
<Button Classes="Action" x:Name="HelpActionButton">
<icons:UnifiedIcon Classes="Help ForegroundSubdued" />
</Button>

Expand Down
21 changes: 18 additions & 3 deletions src/NexusMods.App.UI/Controls/TopBar/TopBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
using Avalonia.Media.Imaging;
using DynamicData.Kernel;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.NexusWebApi;
using NexusMods.App.UI.Controls.Navigation;
using NexusMods.App.UI.Overlays;
using NexusMods.App.UI.Overlays.AlphaWarning;
using NexusMods.App.UI.Pages.Settings;
using NexusMods.App.UI.Windows;
using NexusMods.App.UI.WorkspaceSystem;
Expand All @@ -22,7 +25,12 @@ public class TopBarViewModel : AViewModel<ITopBarViewModel>, ITopBarViewModel
private readonly ILoginManager _loginManager;
private readonly ILogger<TopBarViewModel> _logger;

public TopBarViewModel(ILogger<TopBarViewModel> logger, ILoginManager loginManager, IWindowManager windowManager)
public TopBarViewModel(
IServiceProvider serviceProvider,
ILogger<TopBarViewModel> logger,
ILoginManager loginManager,
IWindowManager windowManager,
IOverlayController overlayController)
{
_logger = logger;
_loginManager = loginManager;
Expand All @@ -46,6 +54,14 @@ public TopBarViewModel(ILogger<TopBarViewModel> logger, ILoginManager loginManag
workspaceController.OpenPage(workspaceController.ActiveWorkspace!.Id, page, behavior);
});

HelpActionCommand = ReactiveCommand.Create(() =>
{
var alphaWarningViewModel = serviceProvider.GetRequiredService<IAlphaWarningViewModel>();
alphaWarningViewModel.WorkspaceController = workspaceController;

overlayController.SetOverlayContent(new SetOverlayItem(alphaWarningViewModel));
});

this.WhenActivated(d =>
{
var canLogin = this.WhenAnyValue(x => x.IsLoggedIn).Select(isLoggedIn => !isLoggedIn);
Expand Down Expand Up @@ -138,8 +154,7 @@ private async Task Logout()
public ReactiveCommand<Unit, Unit> RedoActionCommand { get; } =
ReactiveCommand.Create(() => { }, Observable.Return(false));

public ReactiveCommand<Unit, Unit> HelpActionCommand { get; } =
ReactiveCommand.Create(() => { }, Observable.Return(false));
public ReactiveCommand<Unit, Unit> HelpActionCommand { get; }

public ReactiveCommand<NavigationInformation, Unit> SettingsActionCommand { get; }
}
3 changes: 3 additions & 0 deletions src/NexusMods.App.UI/NexusMods.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@
<Compile Update="Pages\TextEdit\TextEditorPageViewModel.cs">
<DependentUpon>ITextEditorPageViewModel.cs</DependentUpon>
</Compile>
<Compile Update="Overlays\AlphaWarning\AlphaWarningViewModel.cs">
<DependentUpon>IAlphaWarningViewModel.cs</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
83 changes: 83 additions & 0 deletions src/NexusMods.App.UI/Overlays/AlphaWarning/AlphaWarningView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<reactive:ReactiveUserControl
x:TypeArguments="local:IAlphaWarningViewModel"
xmlns="https://github.com/avaloniaui"
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:reactive="http://reactiveui.net"
xmlns:local="clr-namespace:NexusMods.App.UI.Overlays.AlphaWarning"
xmlns:base="clr-namespace:NexusMods.App.UI.Overlays.Generic.MessageBox.Base"
xmlns:icons="clr-namespace:NexusMods.Icons;assembly=NexusMods.Icons"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600"
x:Class="NexusMods.App.UI.Overlays.AlphaWarning.AlphaWarningView">

<base:MessageBoxBackground MinWidth="576" MaxWidth="576" MinHeight="523" MaxHeight="523">
<base:MessageBoxBackground.TopContent>
<StackPanel Orientation="Vertical" Margin="16, 24, 24, 24" Classes="Spacing-3_5">
<StackPanel Classes="Spacing-4">
<TextBlock Classes="HeadingXSSemi">Thank you for joining the Nexus Mods App alpha test</TextBlock>

<Border Classes="Rounded-lg WarningSubdued20" Padding="16">
<StackPanel Spacing="8">
<StackPanel Orientation="Horizontal" Spacing="2">
<icons:UnifiedIcon Size="20" Classes="Alert"/>
<TextBlock Classes="BodyLGBold">Important</TextBlock>
</StackPanel>

<TextBlock Classes="BodyMDNormal" TextWrapping="Wrap">This app is still very early in development and currently only supports Stardew Valley. Please ensure no mods are installed in your game folder before testing.</TextBlock>
</StackPanel>

</Border>

<StackPanel Spacing="20">
<TextBlock Classes="BodyMDNormal ForegroundModerate" TextWrapping="Wrap">Congratulations on being one of the first to dive into the Alpha test version of the Nexus Mods App!</TextBlock>

<Button x:Name="ViewChangelogButton" Classes="Hyperlink Secondary">
<TextBlock Classes="ForegroundModerate">View the changelog</TextBlock>
</Button>

<TextBlock Classes="BodyMDNormal ForegroundModerate" TextWrapping="Wrap">Your feedback is our compass. So, if you encounter any bugs, quirks, or have suggestions for improvement, don't hesitate to reach out.</TextBlock>
</StackPanel>

<Grid ColumnDefinitions="*, *, *">
<Button Grid.Column="0" Width="165" x:Name="OpenDiscordButton" Classes="Rounded" HorizontalAlignment="Left">
<StackPanel HorizontalAlignment="Center">
<icons:UnifiedIcon Classes="Discord" />
<TextBlock Classes="ForegroundStrong">App Discord</TextBlock>
</StackPanel>
</Button>

<Button Grid.Column="1" Width="165" x:Name="OpenForumsButton" Classes="Rounded" HorizontalAlignment="Center">
<StackPanel HorizontalAlignment="Center">
<icons:UnifiedIcon Classes="Forum" />
<TextBlock Classes="ForegroundStrong">Forums</TextBlock>
</StackPanel>
</Button>

<Button Grid.Column="2" Width="165" x:Name="OpenGitHubButton" Classes="Rounded" HorizontalAlignment="Right">
<StackPanel HorizontalAlignment="Center">
<icons:UnifiedIcon Classes="Code" />
<TextBlock Classes="ForegroundStrong">GitHub</TextBlock>
</StackPanel>
</Button>
</Grid>

<TextBlock Classes="BodyMDNormal ForegroundModerate">Thank you for embarking on this exciting journey with us. Happy modding!</TextBlock>

</StackPanel>
</StackPanel>

</base:MessageBoxBackground.TopContent>

<base:MessageBoxBackground.BottomContent>
<StackPanel Orientation="Horizontal" Margin="24" HorizontalAlignment="Right" Classes="Spacing-2">
<Button x:Name="DoneButton" Classes="Standard Primary">
<TextBlock>LET'S GO!</TextBlock>
</Button>
</StackPanel>

</base:MessageBoxBackground.BottomContent>
</base:MessageBoxBackground>

</reactive:ReactiveUserControl>

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Reactive.Disposables;
using Avalonia.ReactiveUI;
using JetBrains.Annotations;
using ReactiveUI;

namespace NexusMods.App.UI.Overlays.AlphaWarning;

[UsedImplicitly]
public partial class AlphaWarningView : ReactiveUserControl<IAlphaWarningViewModel>
{
public AlphaWarningView()
{
InitializeComponent();

this.WhenActivated(disposables =>
{
this.BindCommand(ViewModel, vm => vm.OpenDiscordCommand, view => view.OpenDiscordButton)
.DisposeWith(disposables);

this.BindCommand(ViewModel, vm => vm.OpenForumsCommand, view => view.OpenForumsButton)
.DisposeWith(disposables);

this.BindCommand(ViewModel, vm => vm.OpenGitHubCommand, view => view.OpenGitHubButton)
.DisposeWith(disposables);

this.BindCommand(ViewModel, vm => vm.ViewChangelogCommand, view => view.ViewChangelogButton)
.DisposeWith(disposables);

this.BindCommand(ViewModel, vm => vm.CloseCommand, view => view.DoneButton)
.DisposeWith(disposables);
});
}
}

100 changes: 100 additions & 0 deletions src/NexusMods.App.UI/Overlays/AlphaWarning/AlphaWarningViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Reactive;
using System.Reactive.Disposables;
using DynamicData.Kernel;
using NexusMods.Abstractions.Settings;
using NexusMods.App.UI.Controls.Navigation;
using NexusMods.App.UI.Pages.Changelog;
using NexusMods.App.UI.Settings;
using NexusMods.App.UI.WorkspaceSystem;
using NexusMods.CrossPlatform.Process;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace NexusMods.App.UI.Overlays.AlphaWarning;

public class AlphaWarningViewModel : AViewModel<IAlphaWarningViewModel>, IAlphaWarningViewModel
{
[Reactive] public bool IsActive { get; set; }

// NOTE(erri120): from https://github.com/Nexus-Mods/NexusMods.App/issues/1376
private static readonly Uri DiscordUri = new("https://discord.gg/y7NfQWyRkj");
private static readonly Uri ForumsUri = new("https://forums.nexusmods.com/forum/9052-nexus-mods-app/");
private static readonly Uri GitHubUri = new("https://github.com/Nexus-Mods/NexusMods.App");

public ReactiveCommand<Unit, Unit> ViewChangelogCommand { get; }
public ReactiveCommand<Unit, Uri> OpenDiscordCommand { get; }
public ReactiveCommand<Unit, Uri> OpenForumsCommand { get; }
public ReactiveCommand<Unit, Uri> OpenGitHubCommand { get; }

public ReactiveCommand<Unit, Unit> CloseCommand { get; }

public IWorkspaceController? WorkspaceController { get; set; }

private readonly ISettingsManager _settingsManager;
private readonly IOverlayController _overlayController;

public AlphaWarningViewModel(
IOSInterop osInterop,
ISettingsManager settingsManager,
IOverlayController overlayController)
{
_settingsManager = settingsManager;
_overlayController = overlayController;

OpenDiscordCommand = ReactiveCommand.Create(() => DiscordUri);
OpenForumsCommand = ReactiveCommand.Create(() => ForumsUri);
OpenGitHubCommand = ReactiveCommand.Create(() => GitHubUri);

ViewChangelogCommand = ReactiveCommand.Create(() =>
{
var workspaceController = WorkspaceController;
if (workspaceController is null) return;

var pageData = new PageData
{
Context = new ChangelogPageContext
{
TargetVersion = null,
},
FactoryId = ChangelogPageFactory.StaticId,
};

var behavior = workspaceController.GetOpenPageBehavior(pageData, new NavigationInformation(NavigationInput.Default, Optional<OpenPageBehaviorType>.None), Optional<PageIdBundle>.None);
workspaceController.OpenPage(workspaceController.ActiveWorkspace!.Id, pageData, behavior);
});

CloseCommand = ReactiveCommand.Create(() =>
{
_settingsManager.Update<AlphaSettings>(settings => settings with
{
HasShownModal = true,
});

IsActive = false;
});

this.WhenActivated(disposables =>
{
this.WhenAnyObservable(
vm => vm.OpenDiscordCommand,
vm => vm.OpenForumsCommand,
vm => vm.OpenGitHubCommand)
.SubscribeWithErrorLogging(uri =>
{
_ = Task.Run(async () =>
{
await osInterop.OpenUrl(uri);
});
})
.DisposeWith(disposables);
});
}

public bool MaybeShow()
{
if (_settingsManager.Get<AlphaSettings>().HasShownModal) return false;

_overlayController.SetOverlayContent(new SetOverlayItem(this));
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Reactive;
using NexusMods.App.UI.WorkspaceSystem;
using ReactiveUI;

namespace NexusMods.App.UI.Overlays.AlphaWarning;

public interface IAlphaWarningViewModel : IOverlayViewModel
{
public ReactiveCommand<Unit, Unit> ViewChangelogCommand { get; }

public ReactiveCommand<Unit, Uri> OpenDiscordCommand { get; }

public ReactiveCommand<Unit, Uri> OpenForumsCommand { get; }

public ReactiveCommand<Unit, Uri> OpenGitHubCommand { get; }

public ReactiveCommand<Unit, Unit> CloseCommand { get; }

public IWorkspaceController? WorkspaceController { get; set; }

public bool MaybeShow();
}
4 changes: 4 additions & 0 deletions src/NexusMods.App.UI/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using NexusMods.App.UI.LeftMenu.Items;
using NexusMods.App.UI.LeftMenu.Loadout;
using NexusMods.App.UI.Overlays;
using NexusMods.App.UI.Overlays.AlphaWarning;
using NexusMods.App.UI.Overlays.Download.Cancel;
using NexusMods.App.UI.Overlays.Generic.MessageBox.OkCancel;
using NexusMods.App.UI.Overlays.Login;
Expand Down Expand Up @@ -209,6 +210,9 @@ public static IServiceCollection AddUI(this IServiceCollection c)
.AddView<TextEditorPageView, ITextEditorPageViewModel>()
.AddViewModel<TextEditorPageViewModel, ITextEditorPageViewModel>()

.AddView<AlphaWarningView, IAlphaWarningViewModel>()
.AddViewModel<AlphaWarningViewModel, IAlphaWarningViewModel>()

// workspace system
.AddSingleton<IWindowManager, WindowManager>()
.AddRepository<WindowDataAttributes.Model>([WindowDataAttributes.Data])
Expand Down
13 changes: 13 additions & 0 deletions src/NexusMods.App.UI/Settings/AlphaSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using NexusMods.Abstractions.Settings;

namespace NexusMods.App.UI.Settings;

public record AlphaSettings : ISettings
{
public bool HasShownModal { get; set; }

public static ISettingsBuilder Configure(ISettingsBuilder settingsBuilder)
{
return settingsBuilder;
}
}
3 changes: 2 additions & 1 deletion src/NexusMods.App.UI/Settings/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static IServiceCollection AddUISettings(this IServiceCollection serviceCo
return serviceCollection
.AddSettings<LoadoutGridSettings>()
.AddSettings<LanguageSettings>()
.AddSettings<TextEditorSettings>();
.AddSettings<TextEditorSettings>()
.AddSettings<AlphaSettings>();
}
}
Loading

0 comments on commit c2a7369

Please sign in to comment.