Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into docs-070
Browse files Browse the repository at this point in the history
  • Loading branch information
Pickysaurus committed Nov 26, 2024
2 parents c1f6b4a + fee4ee5 commit 0bf4cac
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 71 deletions.
9 changes: 9 additions & 0 deletions src/NexusMods.App.UI/NexusMods.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,15 @@
<Compile Update="Pages\Sorting\SortingSelection\SortingSelectionViewModel.cs">
<DependentUpon>ISortingSelectionViewModel.cs</DependentUpon>
</Compile>
<Compile Update="Pages\Sorting\LoadOrder\LoadOrderViewDesignViewModel.cs">
<DependentUpon>ILoadOrderViewModel.cs</DependentUpon>
</Compile>
<Compile Update="Pages\Sorting\SortingSelection\SortingSelectionDesignViewModel.cs">
<DependentUpon>ISortingSelectionViewModel.cs</DependentUpon>
</Compile>
<Compile Update="Pages\Sorting\LoadOrder\LoadOrderItemDesignModel.cs">
<DependentUpon>ILoadOrderItemModel.cs</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace NexusMods.App.UI.Pages.Sorting;

public interface ILoadOrderItemModel : ITreeDataGridItemModel<ILoadOrderItemModel, Guid>
{
public ISortableItem InnerItem { get; }
public ReactiveCommand<Unit, Unit> MoveUp { get; }
public ReactiveCommand<Unit, Unit> MoveDown { get; }
public int SortIndex { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Reactive;
using NexusMods.Abstractions.UI;
using NexusMods.App.UI.Controls;
using ReactiveUI;

namespace NexusMods.App.UI.Pages.Sorting;
Expand All @@ -10,7 +11,7 @@ public interface ILoadOrderViewModel : IViewModelInterface
/// <summary>
/// TreeDataGridAdapter for the Load Order, for setting up the TreeDataGrid
/// </summary>
LoadOrderTreeDataGridAdapter Adapter { get; }
TreeDataGridAdapter<ILoadOrderItemModel, Guid> Adapter { get; }

/// <summary>
/// Name of this sort order type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Reactive;
using NexusMods.Abstractions.Games;
using NexusMods.App.UI.Controls;
using ReactiveUI;

namespace NexusMods.App.UI.Pages.Sorting;

public class LoadOrderItemDesignModel : TreeDataGridItemModel<ILoadOrderItemModel, Guid>, ILoadOrderItemModel
{
public ReactiveCommand<Unit, Unit> MoveUp { get; } = ReactiveCommand.Create(() => { });
public ReactiveCommand<Unit, Unit> MoveDown { get; } = ReactiveCommand.Create(() => { });
public int SortIndex { get; set; }
public string DisplayName { get; set; } = "Display Name";
public string ModName { get; set; } = "Mod Name";
public bool IsActive { get; set; }
public Guid Guid { get; set; }
}
140 changes: 99 additions & 41 deletions src/NexusMods.App.UI/Pages/Sorting/LoadOrder/LoadOrderView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,107 @@
xmlns:controls="clr-namespace:NexusMods.App.UI.Controls"
xmlns:icons="clr-namespace:NexusMods.Icons;assembly=NexusMods.Icons"
xmlns:sorting="clr-namespace:NexusMods.App.UI.Pages.Sorting"
xmlns:alerts="clr-namespace:NexusMods.App.UI.Controls.Alerts"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="NexusMods.App.UI.Pages.Sorting.LoadOrderView">
<StackPanel Orientation="Vertical">
<TreeDataGrid x:Name="SortOrderTreeDataGrid"
AutoDragDropRows="False"
Margin="0,20"
CanUserResizeColumns="True"
CanUserSortColumns="False"
ShowColumnHeaders="True"
RowDrop="OnRowDrop">

<TreeDataGrid.Resources>

<DataTemplate x:Key="LoadOrderItemIndexColumnTemplate"
DataType="sorting:ILoadOrderItemModel">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ItemIndex"
Text="{CompiledBinding SortIndex}" />
<controls:StandardButton x:Name="UpButton"
Command="{CompiledBinding MoveDown}"
LeftIcon="{x:Static icons:IconValues.ArrowUp}"
ShowIcon="Left"
Text="" />
<controls:StandardButton x:Name="DownButton"
Command="{CompiledBinding MoveUp}"
LeftIcon="{x:Static icons:IconValues.ArrowDown}"
ShowIcon="Left"
Text="" />
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="LoadOrderItemNameColumnTemplate"
DataType="sorting:ILoadOrderItemModel">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ItemName"
Text="{CompiledBinding DisplayName}" />
</StackPanel>
</DataTemplate>

</TreeDataGrid.Resources>

</TreeDataGrid>
<Design.DataContext>
<sorting:LoadOrderDesignViewModel />
</Design.DataContext>

<Grid RowDefinitions="Auto, *">
<!-- <Border Background="Red"> -->
<!-- <TextBlock Text="{Binding SortOrderName}"/> -->
<!-- </Border> -->

<StackPanel Spacing="24"
Grid.Row="0">
<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 Grid.Row="1" Text="Last Loaded REDmod File Wins"
Theme="{StaticResource HeadingXSSemiTheme}" />
</StackPanel>

</StackPanel>

<Grid Grid.Row="1" ColumnDefinitions="50, *" Margin="0,24,0,0">

<Grid RowDefinitions="24, 8, *, 8, 24" Margin="0,60,0,0">
<icons:UnifiedIcon Grid.Row="0" Value="{x:Static icons:IconValues.Trophy}" />
<Border Grid.Row="2" Width="5">
<Border.Background>
<LinearGradientBrush StartPoint="0%,0%" EndPoint="0%,100%">
<GradientStop Color="#FFFFFFFF" Offset="0" />
<GradientStop Color="#32FFFFFF" Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
<icons:UnifiedIcon Grid.Row="4" Value="{x:Static icons:IconValues.ArrowDown}" Foreground="#32FFFFFF" />
</Grid>

<TreeDataGrid Grid.Column="1" x:Name="SortOrderTreeDataGrid"
AutoDragDropRows="False"
CanUserResizeColumns="True"
CanUserSortColumns="False"
ShowColumnHeaders="True"
RowDrop="OnRowDrop">

<TreeDataGrid.Resources>

<DataTemplate x:Key="LoadOrderItemIndexColumnTemplate"
DataType="sorting:ILoadOrderItemModel">

<StackPanel Orientation="Horizontal" Spacing="12">
<controls:StandardButton x:Name="UpButton"
Command="{CompiledBinding MoveDown}"
LeftIcon="{x:Static icons:IconValues.ArrowUp}"
ShowIcon="IconOnly"
Size="Medium"
Type="Tertiary"
Fill="None" />
<Border
Background="{StaticResource SurfaceLowBrush}"
BorderThickness="1"
BorderBrush="{StaticResource StrokeTranslucentSubduedBrush}"
CornerRadius="4"
Width="52"
Height="42">
<TextBlock x:Name="ItemIndex"
Text="{CompiledBinding SortIndex}"
Foreground="{StaticResource NeutralTranslucentStrongBrush}"
Theme="{StaticResource BodyMDBoldTheme}"
HorizontalAlignment="Center" />
</Border>
<controls:StandardButton x:Name="DownButton"
Command="{CompiledBinding MoveUp}"
LeftIcon="{x:Static icons:IconValues.ArrowDown}"
ShowIcon="IconOnly"
Size="Medium"
Type="Tertiary"
Fill="None" />
<Border
Background="{StaticResource SurfaceTranslucentMidBrush}"
Width="1"
Height="42"/>
</StackPanel>
</DataTemplate>

<DataTemplate x:Key="LoadOrderItemNameColumnTemplate"
DataType="sorting:ILoadOrderItemModel">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ItemName"
Text="{CompiledBinding DisplayName}" />
</StackPanel>
</DataTemplate>

</TreeDataGrid.Resources>

</TreeDataGrid>
</Grid>

</Grid>

</reactiveUi:ReactiveUserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Reactive;
using System.Reactive.Disposables;
using Avalonia.Controls.Models.TreeDataGrid;
using DynamicData;
using DynamicData.Binding;
using NexusMods.Abstractions.UI;
using NexusMods.App.UI.Controls;
using ReactiveUI;

namespace NexusMods.App.UI.Pages.Sorting;

public class LoadOrderDesignViewModel : AViewModel<ILoadOrderViewModel>, ILoadOrderViewModel
{
public TreeDataGridAdapter<ILoadOrderItemModel, Guid> Adapter { get; set; }
public string SortOrderName { get; set; } = "Sort Order Name";
public string InfoAlertTitle { get; set;} = "Info Alert Title";
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 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 LoadOrderDesignViewModel()
{
Adapter = new LoadOrderTreeDataGridDesignAdapter();

this.WhenActivated(d =>
{
Adapter.Activate();
Disposable.Create(() => Adapter.Deactivate())
.DisposeWith(d);
}
);
}
}


// adapter used for design view, based on the actual adapter LoadOrderViewModel.LoadOrderTreeDataGridAdapter
public class LoadOrderTreeDataGridDesignAdapter : TreeDataGridAdapter<ILoadOrderItemModel, Guid>
{
protected override IObservable<IChangeSet<ILoadOrderItemModel, Guid>> GetRootsObservable(bool viewHierarchical)
{
var items = new ObservableCollection<ILoadOrderItemModel>([
new LoadOrderItemDesignModel() { DisplayName = "Item 1", Guid = Guid.NewGuid(), SortIndex = 0 },
new LoadOrderItemDesignModel() { DisplayName = "Item 2", Guid = Guid.NewGuid(), SortIndex = 1 },
]
);

return items.ToObservableChangeSet(item => ((LoadOrderItemDesignModel)item).Guid);
}

protected override IColumn<ILoadOrderItemModel>[] CreateColumns(bool viewHierarchical)
{
return
[
// TODO: Use <see cref="ColumnCreator"/> to create the columns using interfaces
new HierarchicalExpanderColumn<ILoadOrderItemModel>(
inner: LoadOrderTreeDataGridAdapter.CreateIndexColumn("Index"),
childSelector: static model => model.Children,
hasChildrenSelector: static model => model.HasChildren.Value,
isExpandedSelector: static model => model.IsExpanded
)
{
Tag = "expander",
},
LoadOrderTreeDataGridAdapter.CreateNameColumn("Name"),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LoadOrderViewModel : AViewModel<ILoadOrderViewModel>, ILoadOrderVie
public string EmptyStateMessageTitle { get; }
public string EmptyStateMessageContents { get; }

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

public LoadOrderViewModel(LoadoutId loadoutId, ISortableItemProviderFactory itemProviderFactory)
{
Expand Down Expand Up @@ -89,37 +89,37 @@ protected override IColumn<ILoadOrderItemModel>[] CreateColumns(bool viewHierarc
isExpandedSelector: static model => model.IsExpanded
)
{
Tag = "expander",
Tag = "expander",
},
CreateNameColumn(_sortableItemsProvider.ParentFactory.NameColumnHeader),
];
}

private static IColumn<ILoadOrderItemModel> CreateIndexColumn(string headerName)
internal static IColumn<ILoadOrderItemModel> CreateIndexColumn(string headerName)
{
return new CustomTemplateColumn<ILoadOrderItemModel>(
header: headerName,
cellTemplateResourceKey: "LoadOrderItemIndexColumnTemplate",
options: new TemplateColumnOptions<ILoadOrderItemModel>
{
CanUserSortColumn = false,
CanUserResizeColumn = true,
CanUserResizeColumn = false,
}
)
{
Id = "Index",
};
}

private static IColumn<ILoadOrderItemModel> CreateNameColumn(string headerName)
internal static IColumn<ILoadOrderItemModel> CreateNameColumn(string headerName)
{
return new CustomTemplateColumn<ILoadOrderItemModel>(
header: headerName,
cellTemplateResourceKey: "LoadOrderItemNameColumnTemplate",
options: new TemplateColumnOptions<ILoadOrderItemModel>
{
CanUserSortColumn = false,
CanUserResizeColumn = true,
CanUserResizeColumn = false,
}
)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.ObjectModel;
using NexusMods.Abstractions.UI;

namespace NexusMods.App.UI.Pages.Sorting;

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

public SortingSelectionDesignViewModel()
{
var loadOrderViewModels = new ObservableCollection<ILoadOrderViewModel>
{
new LoadOrderDesignViewModel { 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."
},
new LoadOrderDesignViewModel { SortOrderName = "Load Order (Archive XL)" },
new LoadOrderDesignViewModel { SortOrderName = "File Overwrites" }
};

LoadOrderViewModels = new ReadOnlyObservableCollection<ILoadOrderViewModel>(loadOrderViewModels);
}
}
Loading

0 comments on commit 0bf4cac

Please sign in to comment.