Skip to content

Commit

Permalink
Merge pull request #534 from erri120/issue-475
Browse files Browse the repository at this point in the history
Better Manifest
  • Loading branch information
halgari authored Feb 15, 2020
2 parents d61cb7d + bef6901 commit e327f86
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 16 deletions.
1 change: 1 addition & 0 deletions Branding/SVGs/MiddleMouseButton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Wabbajack/Resources/ResourceLinks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media.Imaging;

Expand All @@ -18,5 +16,7 @@ public static class ResourceLinks
UIUtils.BitmapImageFromStream(Application.GetResourceStream(new Uri("pack://application:,,,/Resources/MO2Button.png")).Stream));
public static Lazy<BitmapImage> VortexButton { get; } = new Lazy<BitmapImage>(() =>
UIUtils.BitmapImageFromStream(Application.GetResourceStream(new Uri("pack://application:,,,/Resources/VortexButton.png")).Stream));
public static Lazy<BitmapImage> MiddleMouseButton { get; } = new Lazy<BitmapImage>(() =>
UIUtils.BitmapImageFromStream(Application.GetResourceStream(new Uri("pack://application:,,,/Resources/middle_mouse_button.png")).Stream));
}
}
Binary file added Wabbajack/Resources/middle_mouse_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 31 additions & 1 deletion Wabbajack/View Models/ManifestVM.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.Lib;

Expand All @@ -16,9 +21,34 @@ public class ManifestVM : ViewModel

public IEnumerable<Archive> Archives => Manifest.Archives;

[Reactive]
public string SearchTerm { get; set; }

private readonly ObservableAsPropertyHelper<IEnumerable<Archive>> _searchResults;
public IEnumerable<Archive> SearchResults => _searchResults.Value;

public ManifestVM(Manifest manifest)
{
Manifest = manifest;

_searchResults =
this.WhenAnyValue(x => x.SearchTerm)
.Throttle(TimeSpan.FromMilliseconds(800))
.Select(term => term?.Trim())
.DistinctUntilChanged()
.Select(term =>
{
if (string.IsNullOrWhiteSpace(term))
return Archives;

return Archives.Where(x =>
{
if (term.StartsWith("hash:"))
return x.Hash.StartsWith(term.Replace("hash:", ""));
return x.Name.StartsWith(term);
});
})
.ToGuiProperty(this, nameof(SearchResults), Archives);
}
}
}
31 changes: 19 additions & 12 deletions Wabbajack/Views/ManifestView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@
xmlns:reactiveUi="http://reactiveui.net"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ScrollViewer>
<Grid>
<ScrollViewer MouseDown="ScrollViewer_MouseDown" MouseUp="ScrollViewer_MouseUp" MouseMove="ScrollViewer_MouseMove">
<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 TextBlock}">
<Style x:Key="ModTitleStyle" TargetType="{x:Type TextBox}">
<Setter Property="Foreground" Value="#C7FC86"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
<SolidColorBrush x:Key="SearchBarBrush" Color="White" Opacity="50"/>
</ScrollViewer.Resources>
<StackPanel Margin="8">
<StackPanel Margin="8" x:Name="DynamicStackPanel">
<TextBlock x:Name="Name" FontSize="32" HorizontalAlignment="Center" Style="{StaticResource HeaderStyle}"/>
<TextBlock x:Name="Author" FontSize="14" Padding="0 3 0 3"/>
<TextBlock x:Name="Description" FontSize="14" TextWrapping="Wrap"/>
<TextBlock x:Name="Author" FontSize="14" Padding="0 12 0 3"/>
<TextBlock x:Name="Description" FontSize="18" TextWrapping="Wrap"/>

<TextBlock FontSize="26" Padding="0 6 0 0" Text="Mods"/>
<TextBlock x:Name="InstallSize" FontSize="20"/>
<TextBlock x:Name="DownloadSize" FontSize="20" Padding="0 0 0 3"/>
<TextBlock x:Name="InstallSize" Padding="0 24 0 0" FontSize="24"/>
<TextBlock x:Name="DownloadSize" FontSize="24" Padding="0 0 0 12"/>

<TextBlock Padding="6 0 0 0" FontSize="20" Text="Search:"/>
<TextBox x:Name="SearchBar" BorderThickness="2" BorderBrush="{StaticResource SearchBarBrush}" FontSize="16" MaxLength="100"/>

<ItemsControl Padding="0 3 0 6" x:Name="ModsList">
<ItemsControl.ItemsPanel>
Expand All @@ -37,7 +42,7 @@

<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0 3 0 3">
<Grid Margin="0 6 0 6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
Expand All @@ -46,15 +51,17 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Padding="6 0 0 0" Grid.Column="0" Grid.Row="0" FontSize="16" Text="{Binding Path=Name}" Style="{StaticResource ModTitleStyle}"/>
<TextBlock Padding="3 0 0 0" Grid.Column="1" Grid.Row="0" FontSize="16">
<TextBox Padding="6 0 0 0" Grid.Column="0" Grid.Row="0" FontSize="18" Text="{Binding Path=Name}" Style="{StaticResource ModTitleStyle}" IsReadOnly="True" BorderThickness="0"/>
<TextBlock Padding="3 0 0 0" Grid.Column="1" Grid.Row="0" FontSize="18">
<Hyperlink NavigateUri="{Binding Path=Name}" Style="{StaticResource HyperlinkStyle}" RequestNavigate="Hyperlink_OnRequestNavigate">Link</Hyperlink>
</TextBlock>
<TextBlock Padding="6 0 0 0" Grid.Column="0" Grid.Row="1" FontSize="12" Text="{Binding Path=Hash}"/>
<TextBox Padding="6 0 0 0" Grid.Column="0" Grid.Row="1" FontSize="15" Text="{Binding Path=Hash}" IsReadOnly="True"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
<Canvas x:Name="TopLayer" IsHitTestVisible="False"/>
</Grid>
</reactiveUi:ReactiveUserControl>
83 changes: 82 additions & 1 deletion Wabbajack/Views/ManifestView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
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.Media;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ReactiveUI;
using Wabbajack.Common;
using Wabbajack.Lib;

namespace Wabbajack
Expand All @@ -30,12 +36,14 @@ public ManifestView(ModList modlist)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Description, x => x.Description.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Archives, x => x.ModsList.ItemsSource)
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);
});
}

Expand All @@ -55,5 +63,78 @@ private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs

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();
}
}
}
2 changes: 2 additions & 0 deletions Wabbajack/Wabbajack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<None Remove="Readme.md" />
<None Remove="Resources\GameGridIcons\Fallout4.png" />
<None Remove="Resources\GameGridIcons\SkyrimSpecialEdition.png" />
<None Remove="Resources\Icons\middle_mouse_button.png" />
<None Remove="Resources\MO2Button.png" />
<None Remove="Resources\VortexButton.png" />
<None Remove="Resources\Wabba_Ded.png" />
Expand Down Expand Up @@ -81,6 +82,7 @@
<ItemGroup>
<Resource Include="Resources\GameGridIcons\Fallout4.png" />
<Resource Include="Resources\GameGridIcons\SkyrimSpecialEdition.png" />
<Resource Include="Resources\middle_mouse_button.png" />
<Resource Include="Resources\MO2Button.png" />
<Resource Include="Resources\VortexButton.png" />
<Resource Include="Resources\Wabba_Ded.png" />
Expand Down

0 comments on commit e327f86

Please sign in to comment.