Removed the internal Manifest Viewer

This commit is contained in:
erri120 2020-11-09 12:26:07 +01:00
parent fd74b1b4dc
commit ad1a0843de
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
6 changed files with 1 additions and 421 deletions

View File

@ -313,7 +313,7 @@ namespace Wabbajack
ShowManifestCommand = ReactiveCommand.Create(() =>
{
new ManifestWindow(ModList.SourceModList).Show();
Utils.OpenWebsite(new Uri("https://www.wabbajack.org/#/modlists/manifest"));
}, this.WhenAny(x => x.ModList)
.Select(x => x?.SourceModList != null)
.ObserveOnGuiThread());

View File

@ -1,102 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack
{
public enum SortBy { Name, Size }
public class ManifestVM : ViewModel
{
public Manifest Manifest { get; set; }
public string Name => !string.IsNullOrWhiteSpace(Manifest.Name) ? Manifest.Name : "Wabbajack Modlist";
public string Author => !string.IsNullOrWhiteSpace(Manifest.Author) ? $"Created by {Manifest.Author}" : "Created by Jyggalag";
public string Description => !string.IsNullOrWhiteSpace(Manifest.Description) ? Manifest.Description : "";
public string InstallSize => $"Install Size: {Manifest.InstallSize.ToFileSizeString()}";
public string DownloadSize => $"Download Size: {Manifest.DownloadSize.ToFileSizeString()}";
public IEnumerable<Archive> Archives => Manifest.Archives;
[Reactive]
public string SearchTerm { get; set; }
private readonly ObservableAsPropertyHelper<IEnumerable<Archive>> _searchResults;
public IEnumerable<Archive> SearchResults => _searchResults.Value;
[Reactive]
public bool SortAscending { get; set; } = true;
[Reactive]
public SortBy SortEnum { get; set; } = SortBy.Name;
public ReactiveCommand<Unit, Unit> SortByNameCommand;
public ReactiveCommand<Unit, Unit> SortBySizeCommand;
private IEnumerable<Archive> Order(IEnumerable<Archive> list)
{
if (SortAscending)
{
return SortEnum switch
{
SortBy.Name => list.OrderBy(x => x.Name),
SortBy.Size => list.OrderBy(x => x.Size),
_ => throw new ArgumentOutOfRangeException()
};
}
return SortEnum switch
{
SortBy.Name => list.OrderByDescending(x => x.Name),
SortBy.Size => list.OrderByDescending(x => x.Size),
_ => throw new ArgumentOutOfRangeException()
};
}
private void Swap(SortBy to)
{
if (SortEnum != to)
SortEnum = to;
else
SortAscending = !SortAscending;
}
public ManifestVM(Manifest manifest)
{
Manifest = manifest;
SortByNameCommand = ReactiveCommand.Create(() => Swap(SortBy.Name));
SortBySizeCommand = ReactiveCommand.Create(() => Swap(SortBy.Size));
_searchResults =
this.WhenAnyValue(x => x.SearchTerm)
.CombineLatest(
this.WhenAnyValue(x => x.SortAscending),
this.WhenAnyValue(x => x.SortEnum),
(term, ascending, sort) => term)
.Throttle(TimeSpan.FromMilliseconds(800))
.Select(term => term?.Trim())
//.DistinctUntilChanged()
.Select(term =>
{
if (string.IsNullOrWhiteSpace(term))
return Order(Archives);
return Order(Archives.Where(x =>
{
if (term.StartsWith("hash:"))
return x.Hash.ToString().StartsWith(term.Replace("hash:", ""));
return x.Name.StartsWith(term);
}));
})
.ToGuiProperty(this, nameof(SearchResults), Order(Archives));
}
}
}

View File

@ -1,131 +0,0 @@
<reactiveUi:ReactiveUserControl
x:Class="Wabbajack.ManifestView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wabbajack"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveUi="http://reactiveui.net"
d:DesignHeight="450"
d:DesignWidth="800"
x:TypeArguments="local:ManifestVM"
mc:Ignorable="d">
<Grid>
<ScrollViewer
MouseDown="ScrollViewer_MouseDown"
MouseMove="ScrollViewer_MouseMove"
MouseUp="ScrollViewer_MouseUp">
<ScrollViewer.Resources>
<Style x:Key="HeaderStyle" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#03DAC6" />
</Style>
<Style x:Key="HyperlinkStyle" TargetType="{x:Type Hyperlink}">
<Setter Property="Foreground" Value="#BB76FC" />
</Style>
<Style x:Key="ModTitleStyle" TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="#C7FC86" />
<Setter Property="Background" Value="Transparent" />
</Style>
<SolidColorBrush
x:Key="SearchBarBrush"
Opacity="50"
Color="White" />
</ScrollViewer.Resources>
<StackPanel x:Name="DynamicStackPanel" Margin="8">
<TextBlock
x:Name="Name"
HorizontalAlignment="Center"
FontSize="32"
Style="{StaticResource HeaderStyle}" />
<TextBlock
x:Name="Version"
Padding="0,12,0,3"
FontSize="14" />
<TextBlock
x:Name="Author"
Padding="0,3,0,3"
FontSize="14" />
<TextBlock
x:Name="Description"
FontSize="18"
TextWrapping="Wrap" />
<TextBlock
x:Name="InstallSize"
Padding="0,24,0,0"
FontSize="24" />
<TextBlock
x:Name="DownloadSize"
Padding="0,0,0,12"
FontSize="24" />
<TextBlock
Padding="6,0,0,0"
FontSize="20"
Text="Search:" />
<TextBox
x:Name="SearchBar"
BorderBrush="{StaticResource SearchBarBrush}"
BorderThickness="2"
FontSize="16"
MaxLength="100" />
<StackPanel Margin="6,6,0,0" Orientation="Horizontal">
<TextBlock Padding="0,1,0,0" FontSize="14">Order by:</TextBlock>
<Button x:Name="OrderByNameButton" Padding="4,0,4,0">
<TextBlock FontSize="14">Name</TextBlock>
</Button>
<Button x:Name="OrderBySizeButton">
<TextBlock FontSize="14">Size</TextBlock>
</Button>
</StackPanel>
<ItemsControl x:Name="ModsList" Padding="0,3,0,6">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,6,0,6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Grid.Column="0"
Padding="6,0,0,0"
BorderThickness="0"
FontSize="18"
IsReadOnly="True"
Style="{StaticResource ModTitleStyle}"
Text="{Binding Path=Name}" />
<TextBlock Grid.Row="0" Grid.Column="1"
Padding="3,0,0,0"
FontSize="18">
<Hyperlink
NavigateUri="{Binding Path=Name}"
RequestNavigate="Hyperlink_OnRequestNavigate"
Style="{StaticResource HyperlinkStyle}">
Link
</Hyperlink>
</TextBlock>
<TextBox Grid.Row="1" Grid.Column="0"
Padding="6,0,0,0"
FontSize="15"
IsReadOnly="True"
Text="{Binding Path=Hash}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
<Canvas x:Name="TopLayer" IsHitTestVisible="False" />
</Grid>
</reactiveUi:ReactiveUserControl>

View File

@ -1,143 +0,0 @@
using System;
using System.Diagnostics;
using System.Reactive.Disposables;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
using ReactiveUI;
using Wabbajack.Lib;
namespace Wabbajack
{
public partial class ManifestView
{
public ModList Modlist { get; set; }
public ManifestView(ModList modlist)
{
Modlist = modlist;
var manifest = new Manifest(modlist);
ViewModel ??= new ManifestVM(manifest);
InitializeComponent();
this.WhenActivated(disposable =>
{
this.OneWayBind(ViewModel, x => x.Name, x => x.Name.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Manifest.Version, x => x.Version.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Author, x => x.Author.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Description, x => x.Description.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.SearchResults, x => x.ModsList.ItemsSource)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.InstallSize, x => x.InstallSize.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.DownloadSize, x => x.DownloadSize.Text)
.DisposeWith(disposable);
this.Bind(ViewModel, x => x.SearchTerm, x => x.SearchBar.Text)
.DisposeWith(disposable);
this.BindCommand(ViewModel, x => x.SortByNameCommand, x => x.OrderByNameButton)
.DisposeWith(disposable);
this.BindCommand(ViewModel, x => x.SortBySizeCommand, x => x.OrderBySizeButton)
.DisposeWith(disposable);
});
}
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
{
if (!(sender is Hyperlink hyperlink)) return;
if (!(hyperlink.DataContext is Archive archive)) return;
var url = archive.State.GetManifestURL(archive);
if (string.IsNullOrWhiteSpace(url)) return;
if (url.StartsWith("https://github.com/"))
url = url.Substring(0, url.IndexOf("release", StringComparison.Ordinal));
//url = url.Replace("&", "^&");
url = url.Replace(" ", "%20");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") {CreateNoWindow = true});
e.Handled = true;
}
//solution from https://stackoverflow.com/questions/5426232/how-can-i-make-wpf-scrollviewer-middle-click-scroll/5446307#5446307
private bool _isMoving; //False - ignore mouse movements and don't scroll
private bool _isDeferredMovingStarted; //True - Mouse down -> Mouse up without moving -> Move; False - Mouse down -> Move
private Point? _startPosition;
private const double Slowdown = 10; //smaller = faster
private void ScrollViewer_MouseDown(object sender, MouseButtonEventArgs e)
{
if (_isMoving)
CancelScrolling();
else if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed)
{
if (_isMoving) return;
_isMoving = true;
_startPosition = e.GetPosition(sender as IInputElement);
_isDeferredMovingStarted = true;
AddScrollSign(e.GetPosition(TopLayer).X, e.GetPosition(TopLayer).Y);
}
}
private void ScrollViewer_MouseUp(object sender, MouseButtonEventArgs e)
{
if(e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Released && _isDeferredMovingStarted != true)
CancelScrolling();
}
private void ScrollViewer_MouseMove(object sender, MouseEventArgs e)
{
if (!_isMoving || !(sender is ScrollViewer sv))
return;
_isDeferredMovingStarted = false;
var currentPosition = e.GetPosition(sv);
if (_startPosition == null)
return;
var offset = currentPosition - _startPosition.Value;
offset.Y /= Slowdown;
offset.X /= Slowdown;
sv.ScrollToVerticalOffset(sv.VerticalOffset + offset.Y);
sv.ScrollToHorizontalOffset(sv.HorizontalOffset + offset.X);
}
private void CancelScrolling()
{
_isMoving = false;
_startPosition = null;
_isDeferredMovingStarted = false;
RemoveScrollSign();
}
private void AddScrollSign(double x, double y)
{
const double size = 50.0;
var img = ResourceLinks.MiddleMouseButton.Value;
var icon = new Image {Source = img, Width = size, Height = size};
//var icon = new Ellipse { Stroke = Brushes.Red, StrokeThickness = 2.0, Width = 20, Height = 20 };
TopLayer.Children.Add(icon);
Canvas.SetLeft(icon, x - size / 2);
Canvas.SetTop(icon, y - size / 2);
}
private void RemoveScrollSign()
{
TopLayer.Children.Clear();
}
}
}

View File

@ -1,22 +0,0 @@
<mah:MetroWindow
x:Class="Wabbajack.ManifestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wabbajack"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Manifest"
Width="1280"
Height="960"
MinWidth="850"
MinHeight="650"
d:DataContext="{d:DesignInstance local:ManifestWindow}"
ResizeMode="CanResize"
Style="{StaticResource {x:Type Window}}"
TitleBarHeight="25"
UseLayoutRounding="True"
WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}"
mc:Ignorable="d">
<Grid x:Name="Grid" />
</mah:MetroWindow>

View File

@ -1,22 +0,0 @@
using Wabbajack.Lib;
namespace Wabbajack
{
public partial class ManifestWindow
{
public ModList Modlist { get; set; }
public ManifestWindow(ModList modlist)
{
Modlist = modlist;
InitializeComponent();
var manifestView = new ManifestView(Modlist);
Grid.Children.Add(manifestView);
Title = $"{Modlist.Name} by {Modlist.Author}";
}
}
}