Skip to content

Commit

Permalink
Functionality to hide and show Alert and write to Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
insomnious committed Nov 27, 2024
1 parent 18f92aa commit 910ce07
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reactive;
using NexusMods.Abstractions.UI;
using NexusMods.App.UI.Controls;
using NexusMods.App.UI.Controls.Alerts;
using ReactiveUI;

namespace NexusMods.App.UI.Pages.Sorting;
Expand Down Expand Up @@ -71,4 +72,9 @@ public interface ILoadOrderViewModel : IViewModelInterface
/// Contents text for the empty state, in case there are no sortable items to display
/// </summary>
string EmptyStateMessageContents { get; }

/// <summary>
/// AlertSettings wrapper for the Alert so it can be shown\hidden based on the settings
/// </summary>
AlertSettingsWrapper AlertSettingsWrapper { get; }
}
24 changes: 15 additions & 9 deletions src/NexusMods.App.UI/Pages/Sorting/LoadOrder/LoadOrderView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,21 @@
</Border>

<StackPanel Grid.Row="1" Spacing="24" Margin="24">
<alerts:Alert
Severity="Info"
Title="Load Order for REDmod files in Cyberpunk 2077 - First Loaded Wins"
Body="Some Cyberpunk 2077 mods use REDmod files to alter core gameplay elements. If two REDmod files modify the same part of the game, the one loaded first will take priority and overwrite changes from those loaded later.\n\nFor example, the 1st position overwrites the 2nd, the 2nd overwrites the 3rd, and so on."
IsVisible="True"
ShowDismiss="False" />

<TextBlock Text="Last Loaded REDmod File Wins"
Theme="{StaticResource HeadingXSSemiTheme}" />
<alerts:Alert x:Name="LoadOrderAlert"
Severity="Info"
Title="{Binding InfoAlertTitle}"
Body="{Binding InfoAlertMessage}"
ShowDismiss="True" />

<StackPanel Orientation="Horizontal" Spacing="4">
<TextBlock Text="Last Loaded REDmod File Wins"
Theme="{StaticResource HeadingXSSemiTheme}" />
<controls:StandardButton ShowIcon="IconOnly"
LeftIcon="{x:Static icons:IconValues.Info}"
Type="Tertiary"
Fill="None"
Command="{Binding InfoAlertCommand}"/>
</StackPanel>
</StackPanel>

<Grid Grid.Row="2" ColumnDefinitions="32, *" Margin="24,0,24,24">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public LoadOrderView()
vm => vm.Adapter.IsSourceEmpty.Value,
view => view.EmptyState.IsActive)
.DisposeWith(disposables);
// alert
this.OneWayBind(ViewModel, vm => vm.AlertSettingsWrapper, view => view.LoadOrderAlert.AlertSettings)
.DisposeWith(disposables);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
using Avalonia.Controls.Models.TreeDataGrid;
using DynamicData;
using DynamicData.Binding;
using NexusMods.Abstractions.Settings;
using NexusMods.Abstractions.UI;
using NexusMods.App.UI.Controls;
using NexusMods.App.UI.Controls.Alerts;
using NexusMods.App.UI.Settings;
using ReactiveUI;

namespace NexusMods.App.UI.Pages.Sorting;
Expand All @@ -20,15 +23,16 @@ public class LoadOrderDesignViewModel : AViewModel<ILoadOrderViewModel>, ILoadOr
public string InfoAlertHeading { get; set;} = "Info Alert Heading";
public string InfoAlertMessage { get; set;} = "Info Alert Message";
public bool InfoAlertIsVisible { get; set; } = true;
public ReactiveCommand<Unit, Unit> InfoAlertCommand { get; } = ReactiveCommand.Create(() => { Console.WriteLine("InfoAlertCommand"); });
public ReactiveCommand<Unit, Unit> InfoAlertCommand { get; } = ReactiveCommand.Create(() => { });
public string TrophyToolTip { get; set;} = "Trophy Tool Tip";
public ListSortDirection SortDirectionCurrent { get; set; }
public bool IsWinnerTop { get; set;}
public string EmptyStateMessageTitle { get; } = "Empty State Message Title";
public string EmptyStateMessageContents { get; } = "Empty State Message Contents";
public AlertSettingsWrapper AlertSettingsWrapper { get; }

public LoadOrderDesignViewModel()
{
public LoadOrderDesignViewModel(ISettingsManager settingsManager)
{
Adapter = new LoadOrderTreeDataGridDesignAdapter();

this.WhenActivated(d =>
Expand All @@ -38,6 +42,8 @@ public LoadOrderDesignViewModel()
.DisposeWith(d);
}
);

AlertSettingsWrapper = new AlertSettingsWrapper(settingsManager, "cyberpunk2077 redmod load-order first-loaded-wins");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
using DynamicData.Binding;
using NexusMods.Abstractions.Games;
using NexusMods.Abstractions.Loadouts;
using NexusMods.Abstractions.Settings;
using NexusMods.Abstractions.UI;
using NexusMods.App.UI.Controls;
using NexusMods.App.UI.Controls.Alerts;
using NexusMods.App.UI.Settings;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

Expand All @@ -27,10 +30,12 @@ public class LoadOrderViewModel : AViewModel<ILoadOrderViewModel>, ILoadOrderVie
[Reactive] public bool IsWinnerTop { get; private set; }
public string EmptyStateMessageTitle { get; }
public string EmptyStateMessageContents { get; }

public AlertSettingsWrapper AlertSettingsWrapper { get; }

public TreeDataGridAdapter<ILoadOrderItemModel, Guid> Adapter { get; }

public LoadOrderViewModel(LoadoutId loadoutId, ISortableItemProviderFactory itemProviderFactory)
public LoadOrderViewModel(LoadoutId loadoutId, ISortableItemProviderFactory itemProviderFactory, ISettingsManager settingsManager)
{
var provider = itemProviderFactory.GetLoadoutSortableItemProvider(loadoutId);

Expand All @@ -52,6 +57,13 @@ public LoadOrderViewModel(LoadoutId loadoutId, ISortableItemProviderFactory item
var sortDirectionObservable = this.WhenAnyValue(vm => vm.SortDirectionCurrent);
Adapter = new LoadOrderTreeDataGridAdapter(provider, sortDirectionObservable);
Adapter.ViewHierarchical.Value = true;

AlertSettingsWrapper = new AlertSettingsWrapper(settingsManager, "cyberpunk2077 redmod load-order first-loaded-wins");

InfoAlertCommand = ReactiveCommand.Create(() =>
{
AlertSettingsWrapper.ShowAlert();
});

this.WhenActivated(d =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
using System.Collections.ObjectModel;
using NexusMods.Abstractions.UI;
using Microsoft.Extensions.DependencyInjection;
using NexusMods.Abstractions.Settings;

namespace NexusMods.App.UI.Pages.Sorting;

public class SortingSelectionDesignViewModel : AViewModel<ISortingSelectionViewModel>, ISortingSelectionViewModel
{
private readonly ISettingsManager _settingsManager;
public ReadOnlyObservableCollection<ILoadOrderViewModel> LoadOrderViewModels { get; }

public SortingSelectionDesignViewModel()
public SortingSelectionDesignViewModel(IServiceProvider serviceProvider)
{
_settingsManager = serviceProvider.GetRequiredService<ISettingsManager>();

var loadOrderViewModels = new ObservableCollection<ILoadOrderViewModel>
{
new LoadOrderDesignViewModel { SortOrderName = "Load order (RedMOD)",
new LoadOrderDesignViewModel(_settingsManager)
{
SortOrderName = "Load order (RedMOD)",
InfoAlertHeading = "Load Order for REDmod files in Cyberpunk 2077 - First Loaded Wins",
InfoAlertMessage = "Some Cyberpunk 2077 mods use REDmod files to alter core gameplay elements. If two REDmod files modify the same part of the game, the one loaded first will take priority and overwrite changes from those loaded later.\n\nFor example, the 1st position overwrites the 2nd, the 2nd overwrites the 3rd, and so on."
InfoAlertMessage =
"Some Cyberpunk 2077 mods use REDmod files to alter core gameplay elements. If two REDmod files modify the same part of the game, the one loaded first will take priority and overwrite changes from those loaded later.\n\nFor example, the 1st position overwrites the 2nd, the 2nd overwrites the 3rd, and so on."
},
new LoadOrderDesignViewModel { SortOrderName = "Load Order (Archive XL)" },
new LoadOrderDesignViewModel { SortOrderName = "File Overwrites" }
new LoadOrderDesignViewModel(_settingsManager) { SortOrderName = "Load Order (Archive XL)" },
new LoadOrderDesignViewModel(_settingsManager) { SortOrderName = "File Overwrites" }
};

LoadOrderViewModels = new ReadOnlyObservableCollection<ILoadOrderViewModel>(loadOrderViewModels);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using NexusMods.Abstractions.Games;
using NexusMods.Abstractions.Loadouts;
using NexusMods.Abstractions.Settings;
using NexusMods.Abstractions.UI;
using NexusMods.MnemonicDB.Abstractions;

Expand All @@ -11,12 +12,14 @@ public class SortingSelectionViewModel : AViewModel<ISortingSelectionViewModel>,
{
private readonly LoadoutId _loadoutId;
private readonly IConnection _connection;
private readonly ISettingsManager _settingsManager;
public ReadOnlyObservableCollection<ILoadOrderViewModel> LoadOrderViewModels { get; }

public SortingSelectionViewModel(IServiceProvider serviceProvider, LoadoutId loadutId)
{
_loadoutId = loadutId;
_connection = serviceProvider.GetRequiredService<IConnection>();
_settingsManager = serviceProvider.GetRequiredService<ISettingsManager>();

var loadout = Loadout.Load(_connection.Db, _loadoutId);
var sortableItemProviders = loadout
Expand All @@ -26,7 +29,7 @@ public SortingSelectionViewModel(IServiceProvider serviceProvider, LoadoutId loa

LoadOrderViewModels = new ReadOnlyObservableCollection<ILoadOrderViewModel>(
new ObservableCollection<ILoadOrderViewModel>(
sortableItemProviders.Select(provider => new LoadOrderViewModel(_loadoutId, provider))
sortableItemProviders.Select(provider => new LoadOrderViewModel(_loadoutId, provider, _settingsManager))
)
);
}
Expand Down

0 comments on commit 910ce07

Please sign in to comment.