Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Knossos.NET/AppStyles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@
<Setter Property="Background" Value="{StaticResource QuaternaryColorMouseOver}"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundColorMouseOver}"/>
</Style>

<!--Transparent-->
<Style Selector="Button.Transparent">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource ForegroundColor}"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<Style Selector="Button.Transparent:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent"/>
</Style>
<!--END BUTTONS-->

<!--Generic Progress Bar-->
Expand Down
81 changes: 38 additions & 43 deletions Knossos.NET/ViewModels/Windows/ModDetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,41 @@ namespace Knossos.NET.ViewModels
/// </summary>
public class ScreenshotItem
{
public Bitmap image { get; set; }
public string image { get; set; }
public bool video { get; set; } = false;

public string url { get; set; }

public ScreenshotItem(Bitmap image, bool isVideo = false)
public ScreenshotItem(string image, bool isVideo = false)
{
this.image = image;
this.video = isVideo;
this.url = string.Empty;
}

internal void OpenVideo(object url)
internal void OpenVideo()
{
try
{
KnUtils.OpenBrowserURL((string)url);
KnUtils.OpenBrowserURL(url);
}
catch (Exception ex)
{
Log.Add(Log.LogSeverity.Error, "ScreenshotItem.OpenVideo", ex);
}
}

internal void OpenImage()
{
try
{
KnUtils.OpenBrowserURL(image);
}
catch (Exception ex)
{
Log.Add(Log.LogSeverity.Error, "ScreenshotItem.OpenImage", ex);
}
}
}

/// <summary>
Expand All @@ -72,7 +84,7 @@ public partial class ModDetailsViewModel : ViewModelBase
[ObservableProperty]
internal string? description = string.Empty;
[ObservableProperty]
internal Bitmap? banner = null;
internal string? banner = null;
[ObservableProperty]
internal bool forumAvailable = false;
[ObservableProperty]
Expand Down Expand Up @@ -271,24 +283,19 @@ private void LoadBanner(int selectedIndex)
HasBanner = true;
if (System.IO.File.Exists(modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + modVersions[selectedIndex].banner))
{
Banner = new Bitmap(modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + modVersions[selectedIndex].banner);
Banner = modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + modVersions[selectedIndex].banner;
}
else
{
var url = modVersions[selectedIndex].banner;
if (url != null && url.ToLower().Contains("http"))
if (url != null && url.ToLower().StartsWith("http"))
{
Banner?.Dispose();
Banner = new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/general/loading.png")));
Task.Run(async () =>
{
using (var fs = await KnUtils.GetRemoteResourceStream(url).ConfigureAwait(false))
{
Dispatcher.UIThread.Invoke(() => {
if (fs != null)
Banner = new Bitmap(fs);
});
}
var fs = await KnUtils.GetRemoteResource(url).ConfigureAwait(false);
Dispatcher.UIThread.Invoke(() => {
Banner = fs;
});
}).ConfigureAwait(false);
}
}
Expand Down Expand Up @@ -338,24 +345,21 @@ private void LoadScreenshots(int selectedIndex)
if (System.IO.File.Exists(modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + scn))
{
Dispatcher.UIThread.Invoke(() => {
var bitmap = new Bitmap(modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + scn);
var item = new ScreenshotItem(bitmap);
var item = new ScreenshotItem(modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + scn);
Screenshots.Add(item);
});
}
else
{
Task.Run(async () =>
{
using (var fs = await KnUtils.GetRemoteResourceStream(scn))
var fs = await KnUtils.GetRemoteResource(scn);
if (fs != null)
{
if (fs != null)
{
Dispatcher.UIThread.Invoke(() => {
var item = new ScreenshotItem(new Bitmap(fs));
Screenshots.Add(item);
});
}
Dispatcher.UIThread.Invoke(() => {
var item = new ScreenshotItem(fs);
Screenshots.Add(item);
});
}
}).ConfigureAwait(false);
}
Expand Down Expand Up @@ -392,33 +396,24 @@ private async void DownloadVideoThumbnail(string url)

if (imageUrl != string.Empty)
{
HttpResponseMessage response = await KnUtils.GetHttpClient().GetAsync(imageUrl).ConfigureAwait(false);
byte[] content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
Stream stream = new MemoryStream(content);
var item = new ScreenshotItem(new Bitmap(stream), true);
item.url = url;
Dispatcher.UIThread.Invoke(() => {
Screenshots.Add(item);
});
}
else
{
var item = new ScreenshotItem(new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/general/loading.png"))), true);
var img = await KnUtils.GetRemoteResource(imageUrl);
var item = new ScreenshotItem(img != null? img : "avares://Knossos.NET/Assets/general/loading.png", true);
item.url = url;
Dispatcher.UIThread.Invoke(() => {
Screenshots.Add(item);
});
return;
}
}
catch (Exception ex)
{
var item = new ScreenshotItem(new Bitmap(AssetLoader.Open(new Uri("avares://Knossos.NET/Assets/general/loading.png"))), true);
item.url = url;
Dispatcher.UIThread.Invoke(() => {
Screenshots.Add(item);
});
Log.Add(Log.LogSeverity.Warning, "ModDetailsViewModel.DownloadVideoThumbnail", ex);
}
var itemFail = new ScreenshotItem("avares://Knossos.NET/Assets/general/loading.png", true);
itemFail.url = url;
Dispatcher.UIThread.Invoke(() => {
Screenshots.Add(itemFail);
});
}

/// <summary>
Expand Down
39 changes: 20 additions & 19 deletions Knossos.NET/Views/Templates/DevModDetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<Border Margin="45,5,5,5" BorderBrush="Gray" CornerRadius="2" BorderThickness="1">
<Image Width="535" Height="150" Source="{Binding BannerImage}"></Image>
</Border>
<Label HorizontalAlignment="Center" Margin="0,5,0,0" Foreground="Yellow" FontSize="12">This image should be 1070x300 pixels large. 10MB max, 1MB or less recommended.</Label>
<Label HorizontalAlignment="Center" Margin="0,5,0,0" Foreground="Yellow" FontSize="12">This image should be 1070x300 pixels large. 10MB max, 1MB or less recommended. APNG is supported.</Label>
<WrapPanel HorizontalAlignment="Center">
<Button Command="{Binding ChangeBannerImage}" Width="100" Classes="Quaternary" Margin="5">Browse</Button>
<Button Command="{Binding RemoveBannerImage}" Width="100" Classes="Cancel" Margin="5">Remove</Button>
Expand All @@ -88,25 +88,26 @@
</WrapPanel>
<!--Screenshots-->
<WrapPanel Margin="0,15,0,0" HorizontalAlignment="Left">
<Label Width="150" HorizontalContentAlignment="Right" Margin="5" FontWeight="Bold" FontSize="18">Screenshots</Label>
<StackPanel>
<Button Command="{Binding NewScreenShot}" Classes="Option" Margin="10">Add</Button>
<ListBox ItemsSource="{Binding Screenshots}" Margin="5,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel>
<Button Command="{Binding ScUp}">↑</Button>
<Button Command="{Binding ScDown}">↓</Button>
<Button Command="{Binding ScDel}" Classes="Cancel">
<Image Height="14" Width="14" Source="/Assets/general/x.png"></Image>
</Button>
<Image Margin="5,0,0,0" Width="320" Height="180" Source="{Binding Bitmap}"></Image>
</WrapPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<Label Width="150" VerticalAlignment="Center" Margin="5" FontWeight="Bold" FontSize="18">Screenshots</Label>
<Button Command="{Binding NewScreenShot}" Classes="Option" Margin="10">Add</Button>
</WrapPanel>
<Label HorizontalAlignment="Left" Margin="5,0,0,0" Foreground="Yellow" FontSize="12">This images will be displayed at 640x360 (16:9). 10MB max, 1MB or less recommended. APNG is supported.</Label>
<StackPanel>
<ListBox ItemsSource="{Binding Screenshots}" Margin="5,0,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel>
<Button Command="{Binding ScUp}">↑</Button>
<Button Command="{Binding ScDown}">↓</Button>
<Button Command="{Binding ScDel}" Classes="Cancel">
<Image Height="14" Width="14" Source="/Assets/general/x.png"></Image>
</Button>
<Image Margin="5,0,0,0" Width="320" Height="180" Source="{Binding Bitmap}"></Image>
</WrapPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<Button Command="{Binding Save}" Classes="Accept" HorizontalAlignment="Center" Margin="5">Save Changes</Button>
</StackPanel>
</ScrollViewer>
Expand Down
22 changes: 15 additions & 7 deletions Knossos.NET/Views/Windows/ModDetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
Width="1070"
WindowStartupLocation="CenterOwner"
Title="{Binding Name}"
CanResize="True">
CanResize="True"
xmlns:anim="https://github.com/whistyun/AnimatedImage.Avalonia"
xmlns:cvt="clr-namespace:Knossos.NET.Converters;assembly=Knossos.NET">

<Design.DataContext>
<vm:ModDetailsViewModel/>
</Design.DataContext>

<Window.Resources>
<cvt:BitmapAssetValueConverter x:Key="imageConverter"/>
</Window.Resources>

<ScrollViewer Background="{StaticResource BackgroundColorPrimary}">
<Grid RowDefinitions="Auto,Auto,*,Auto">
<StackPanel Grid.Row="0" Margin="25">
<Image Source="{Binding Banner}" HorizontalAlignment="Stretch" Height="300" IsVisible="{Binding HasBanner}"></Image>
<Image Source="{Binding Banner, Converter={StaticResource imageConverter}}" anim:ImageBehavior.AnimatedSource="{Binding Banner}" HorizontalAlignment="Stretch" Height="300" IsVisible="{Binding HasBanner}"></Image>
<Label Content="{Binding Name, Converter={StaticResource escapeUnderscoresConverter}}" FontWeight="Bold" FontSize="24" VerticalContentAlignment="Top" HorizontalContentAlignment="Center" Foreground="White"/>

<!--Buttons and Mod info-->
Expand Down Expand Up @@ -78,8 +84,8 @@
</ScrollViewer>

<!--Screenshots/Video-->
<Grid MaxWidth="1600" ColumnDefinitions="Auto,*,Auto" Grid.Row="3" Margin="20" IsVisible="{Binding Screenshots.Count}">
<Button Name="left" Grid.Column="0" VerticalAlignment="Center" Padding="10,20" Margin="4">
<Grid HorizontalAlignment="Center" ColumnDefinitions="Auto,*,Auto" Grid.Row="3" Margin="50" IsVisible="{Binding Screenshots.Count}">
<Button Name="left" Grid.Column="0" VerticalAlignment="Center" Margin="4">
<Path Data="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" Fill="White"/>
</Button>
<Carousel Name="carousel" Grid.Column="1" ItemsSource="{Binding Screenshots}">
Expand All @@ -89,15 +95,17 @@
<Carousel.DataTemplates>
<DataTemplate DataType="vm:ScreenshotItem">
<Grid>
<Image ZIndex="0" Source="{Binding image}"/>
<Button IsVisible="{Binding video}" ZIndex="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent" Command="{Binding OpenVideo}" CommandParameter="{Binding url}" >
<Button Command="{Binding OpenImage}" Classes="Transparent">
<Image Width="640" Height="360" Source="{Binding image, Converter={StaticResource imageConverter}}" anim:ImageBehavior.AnimatedSource="{Binding image}"/>
</Button>
<Button IsVisible="{Binding video}" Classes="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Command="{Binding OpenVideo}">
<Image HorizontalAlignment="Center" VerticalAlignment="Center" Height="125" Width="125" Source="/Assets/general/play-button.png"/>
</Button>
</Grid>
</DataTemplate>
</Carousel.DataTemplates>
</Carousel>
<Button Name="right" Grid.Column="2" VerticalAlignment="Center" Padding="10,20" Margin="4">
<Button Name="right" Grid.Column="2" VerticalAlignment="Center" Margin="4">
<Path Data="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" Fill="White"/>
</Button>
</Grid>
Expand Down