disable alpha channel

This commit is contained in:
iAmAsval 2021-07-28 18:10:33 +02:00
parent 7ee52508ea
commit ec5e84a73e
5 changed files with 55 additions and 10 deletions

View File

@ -24,6 +24,7 @@ namespace FModel.ViewModels.ApiEndpoints
private News _news;
private Info _infos;
private Backup[] _backups;
private Game _game;
private readonly IDictionary<string, CommunityDesign> _communityDesigns = new Dictionary<string, CommunityDesign>();
private ApplicationViewModel _applicationView => ApplicationService.ApplicationView;
@ -69,6 +70,19 @@ namespace FModel.ViewModels.ApiEndpoints
{
return _backups ??= GetBackupsAsync(token, gameName).GetAwaiter().GetResult();
}
public async Task<Game> GetGamesAsync(CancellationToken token, string gameName)
{
var request = new RestRequest($"https://api.fmodel.app/v1/games/{gameName}", Method.GET);
var response = await _client.ExecuteAsync<Game>(request, token).ConfigureAwait(false);
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, request.Resource);
return response.Data;
}
public Game GetGames(CancellationToken token, string gameName)
{
return _game ??= GetGamesAsync(token, gameName).GetAwaiter().GetResult();
}
public async Task<CommunityDesign> GetDesignAsync(string designName)
{
@ -109,15 +123,15 @@ namespace FModel.ViewModels.ApiEndpoints
}
}
private async void CheckForUpdateEvent(UpdateInfoEventArgs args)
private void CheckForUpdateEvent(UpdateInfoEventArgs args)
{
if (args is {CurrentVersion: { }})
{
var currentVersion = new Version(args.CurrentVersion);
var currentVersion = new System.Version(args.CurrentVersion);
if (currentVersion == args.InstalledVersion)
{
if (UserSettings.Default.ShowChangelog)
await ShowChangelog(args);
ShowChangelog(args);
return;
}
@ -156,10 +170,10 @@ namespace FModel.ViewModels.ApiEndpoints
}
}
private async Task ShowChangelog(UpdateInfoEventArgs args)
private void ShowChangelog(UpdateInfoEventArgs args)
{
var request = new RestRequest(args.ChangelogURL, Method.GET);
var response = await _client.ExecuteAsync(request).ConfigureAwait(false);
var response = _client.Execute(request);
if (string.IsNullOrEmpty(response.Content)) return;
_applicationView.CUE4Parse.TabControl.AddTab($"Release Notes: {args.CurrentVersion}");

View File

@ -24,6 +24,22 @@ namespace FModel.ViewModels.ApiEndpoints.Models
[J] public string DownloadUrl { get; private set; }
[J] public long FileSize { get; private set; }
}
[DebuggerDisplay("{" + nameof(DisplayName) + "}")]
public class Game
{
[J] public string DisplayName { get; private set; }
[J] public Dictionary<string, Version> Versions { get; private set; }
}
[DebuggerDisplay("{" + nameof(GameEnum) + "}")]
public class Version
{
[J("game")] public string GameEnum { get; private set; }
[J] public int UeVer { get; private set; }
[J] public Dictionary<string, int> CustomVersions { get; private set; }
[J] public Dictionary<string, bool> Options { get; private set; }
}
[DebuggerDisplay("{" + nameof(Mode) + "}")]
public class Info

View File

@ -1,9 +1,7 @@
using AdonisUI.Controls;
using FModel.Extensions;
using FModel.Framework;
using FModel.Views.Resources.Controls;
using System.IO;
using System.Windows;
using System.Windows.Media;

View File

@ -119,8 +119,9 @@ namespace FModel.ViewModels
SetProperty(ref _highlighter, value);
}
}
public byte[] ImageBuffer { get; private set; }
public byte[] ImageBuffer { get; set; }
private BitmapImage _image;
public BitmapImage Image
{
@ -132,6 +133,17 @@ namespace FModel.ViewModels
RaisePropertyChanged("HasImage");
}
}
private bool _noAlpha;
public bool NoAlpha
{
get => _noAlpha;
set
{
SetProperty(ref _noAlpha, value);
ResetImage();
}
}
private BitmapScalingMode _imageRender = BitmapScalingMode.Linear;
public BitmapScalingMode ImageRender
@ -204,10 +216,14 @@ namespace FModel.ViewModels
Application.Current.Dispatcher.Invoke(() => File.WriteAllText(directory, Document.Text));
SaveCheck(directory, fileName);
}
private SKImage _img;
public void ResetImage() => SetImage(_img);
public void SetImage(SKImage img)
{
using var data = img.Encode(SKEncodedImageFormat.Png, 100);
_img = img;
using var data = _img.Encode(NoAlpha ? SKEncodedImageFormat.Jpeg : SKEncodedImageFormat.Png, 100);
using var stream = new MemoryStream(ImageBuffer = data.ToArray(), false);
var image = new BitmapImage();
image.BeginInit();

View File

@ -654,6 +654,7 @@
</Image.InputBindings>
<Image.ContextMenu>
<ContextMenu DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
<MenuItem Header="Disable Alpha Channel" IsCheckable="True" IsChecked="{Binding DataContext.NoAlpha}" />
<MenuItem Header="Open Image" Command="{Binding DataContext.ImageCommand}" CommandParameter="Open">
<MenuItem.Icon>
<Viewbox Width="16" Height="16">