Style the play buttons

This commit is contained in:
Timothy Baldridge 2021-11-08 06:32:51 -07:00
parent cec652864e
commit c9fe3ac627
11 changed files with 108 additions and 44 deletions

View File

@ -62,6 +62,22 @@
<Setter Property="CornerRadius" Value="4"></Setter>
</Style>
<Style Selector=".InstalledList Border">
<Setter Property="BorderThickness" Value="2"></Setter>
<Setter Property="BorderBrush" Value="DarkGray"></Setter>
<Setter Property="CornerRadius" Value="4"></Setter>
</Style>
<Style Selector=".InstalledList TextBlock">
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="Margin" Value="4"/>
</Style>
<Style Selector="Button.InstalledList">
<Setter Property="Margin" Value="4"></Setter>
</Style>
</Styles>

View File

@ -5,11 +5,15 @@
xmlns:i="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.InstalledListView">
<Grid RowDefinitions="Auto, Auto" ColumnDefinitions="*, Auto">
<TextBlock Grid.Row="0" Grid.Column="0" x:Name="Title" />
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="InstallationPath" />
<Button Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" x:Name="PlayButton">
<i:MaterialIcon Kind="PlayArrow" />
</Button>
</Grid>
<Button Name="ListButton" Classes="InstalledList" HorizontalAlignment="Stretch">
<Border Classes="InstalledList">
<Grid RowDefinitions="Auto, Auto Auto, Auto" ColumnDefinitions="Auto, *">
<Image x:Name="ListImage" Grid.RowSpan="4" Grid.Row="0" Grid.Column="0" Width="270" Height="150"></Image>
<TextBlock Grid.Row="0" Grid.Column="1" x:Name="Title" />
<TextBlock Grid.Row="1" Grid.Column="1" x:Name="Version" />
<TextBlock Grid.Row="2" Grid.Column="1" x:Name="Author"></TextBlock>
<TextBlock Grid.Row="3" Grid.Column="1" x:Name="InstallationPath" />
</Grid>
</Border>
</Button>
</UserControl>

View File

@ -12,14 +12,23 @@ public partial class InstalledListView : ReactiveUserControl<InstalledListViewMo
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.Image, view => view.ListImage.Source)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Name, view => view.Title.Text)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.InstallPath, view => view.Title.Text,
this.OneWayBind(ViewModel, vm => vm.Author, view => view.Author.Text)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Version, view => view.Version.Text)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.InstallPath, view => view.InstallationPath.Text,
p => p.ToString())
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.Play, view => view.PlayButton)
this.BindCommand(ViewModel, vm => vm.Play, view => view.ListButton)
.DisposeWith(disposables);
});
}

View File

@ -1,8 +1,14 @@
using System.Reactive;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Messages;
using Wabbajack.App.Models;
using Wabbajack.App.Screens;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.DTOs.SavedSettings;
using Wabbajack.Paths;
@ -12,7 +18,7 @@ public class InstalledListViewModel : ViewModelBase
{
private readonly InstallationConfigurationSetting _setting;
public InstalledListViewModel(InstallationConfigurationSetting setting)
public InstalledListViewModel(InstallationConfigurationSetting setting, ImageCache imageCache)
{
Activator = new ViewModelActivator();
_setting = setting;
@ -22,10 +28,28 @@ public class InstalledListViewModel : ViewModelBase
MessageBus.Current.SendMessage(new ConfigureLauncher(InstallPath));
MessageBus.Current.SendMessage(new NavigateTo(typeof(LauncherViewModel)));
});
LoadImage(imageCache).FireAndForget();
}
public async Task LoadImage(ImageCache cache)
{
var img = await cache.From(_setting.Install.Combine("modlist-image.png"), 270, 150);
Dispatcher.UIThread.Post(() =>
{
Image = img;
});
}
public AbsolutePath InstallPath => _setting.Install;
public string Name => _setting.Metadata?.Title ?? "";
public string Version => _setting.Metadata?.Version?.ToString() ?? "";
public string Author => _setting.Metadata?.Author ?? "";
public ReactiveCommand<Unit, Unit> Play { get; }
[Reactive]
public IBitmap Image { get; set; }
}

View File

@ -9,21 +9,16 @@
<Grid RowDefinitions="Auto, *, Auto" Classes="LogView">
<TextBlock Grid.Row="0" Classes="Title">Current Log Contents</TextBlock>
<Border Grid.Row="1">
<ScrollViewer ScrollChanged="ScrollViewer_OnScrollChanged" x:Name="ScrollViewer"
HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<ItemsControl x:Name="Messages">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:LogViewItem />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<ItemsRepeater x:Name="Messages">
<ItemsRepeater.Layout>
<StackLayout></StackLayout>
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<controls:LogViewItem />
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Border>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="CopyLog">

View File

@ -1,3 +1,4 @@
using System.Linq;
using Avalonia.Controls;
using Avalonia.Controls.Mixins;
using Avalonia.ReactiveUI;
@ -14,15 +15,11 @@ public partial class LogView : ReactiveUserControl<LogViewModel>
InitializeComponent();
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.Messages, view => view.Messages.Items)
this.OneWayBind(ViewModel, vm => vm.Messages, view => view.Messages.Items,
items => items.Reverse().ToArray())
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.CopyLogFile, view => view.CopyLog)
.DisposeWith(disposables);
});
}
private void ScrollViewer_OnScrollChanged(object? sender, ScrollChangedEventArgs e)
{
ScrollViewer.ScrollToEnd();
}
}

View File

@ -9,8 +9,10 @@ using Avalonia.Media;
using Avalonia.Media.Imaging;
using SkiaSharp;
using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.VFS;
namespace Wabbajack.App.Models;
@ -19,13 +21,15 @@ public class ImageCache
private readonly Configuration _configuration;
private readonly HttpClient _client;
private readonly IResource<HttpClient> _limiter;
private readonly FileHashCache _hashCache;
public ImageCache(Configuration configuration, HttpClient client, IResource<HttpClient> limiter)
public ImageCache(Configuration configuration, HttpClient client, IResource<HttpClient> limiter, FileHashCache hashCache)
{
_configuration = configuration;
_configuration.ImageCacheLocation.CreateDirectory();
_client = client;
_limiter = limiter;
_hashCache = hashCache;
}
public async Task<IBitmap> From(Uri uri, int width, int height)
@ -46,4 +50,18 @@ public class ImageCache
return new Bitmap(new MemoryStream(data));
}
public async Task<IBitmap> From(AbsolutePath image, int width, int height)
{
var hash = await _hashCache.FileHashCachedAsync(image, CancellationToken.None);
var file = _configuration.ImageCacheLocation.Combine(hash + $"_{width}_{height}");
if (!file.FileExists())
{
var resized = SKBitmap.Decode(image.ToString()).Resize(new SKSizeI(width, height), SKFilterQuality.High);
await file.WriteAllBytesAsync(resized.Encode(SKEncodedImageFormat.Webp, 90).ToArray());
}
var data = await file.ReadAllBytesAsync();
return new Bitmap(new MemoryStream(data));
}
}

View File

@ -62,7 +62,7 @@ public class CompilationViewModel : ViewModelBase
{
try
{
await _compiler.Begin(CancellationToken.None);
var result = await Task.Run(async () => await _compiler.Begin(CancellationToken.None));
}
catch (Exception ex)
{

View File

@ -6,17 +6,15 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Screens.PlaySelectView">
<Grid RowDefinitions="*">
<ItemsControl x:Name="Lists">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<ItemsRepeater x:Name="Lists">
<ItemsRepeater.Layout>
<StackLayout></StackLayout>
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<controls:InstalledListView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
</UserControl>

View File

@ -14,9 +14,11 @@ namespace Wabbajack.App.Screens;
public class PlaySelectViewModel : ViewModelBase, IActivatableViewModel
{
private readonly InstallationStateManager _manager;
private readonly ImageCache _imageCache;
public PlaySelectViewModel(InstallationStateManager manager)
public PlaySelectViewModel(InstallationStateManager manager, ImageCache imageCache)
{
_imageCache = imageCache;
_manager = manager;
Activator = new ViewModelActivator();
@ -32,6 +34,6 @@ public class PlaySelectViewModel : ViewModelBase, IActivatableViewModel
public async Task LoadAndSetItems()
{
var items = await _manager.GetAll();
Items = items.Settings.Select(a => new InstalledListViewModel(a)).ToArray();
Items = items.Settings.Select(a => new InstalledListViewModel(a, _imageCache)).ToArray();
}
}

View File

@ -20,4 +20,5 @@ public class InstallationConfigurationSetting
public ModlistMetadata? Metadata { get; set; }
public AbsolutePath Image { get; set; }
}