diff --git a/LOLRLCG/ViewModels/MainWindowViewModel.cs b/LOLRLCG/ViewModels/MainWindowViewModel.cs index ef19a88..04ea404 100644 --- a/LOLRLCG/ViewModels/MainWindowViewModel.cs +++ b/LOLRLCG/ViewModels/MainWindowViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Net; using System.Net.Http; @@ -30,8 +31,9 @@ public class Champion : ObservableObject private string _name; public string Title { get; init; } public List Tags { get; init; } + public string? Uri { get; init; } public ImageInfo Image { get; set; } - private string? _uri; + private Bitmap? _imageBitmap; public string Name { @@ -39,10 +41,10 @@ public class Champion : ObservableObject set => SetProperty(ref _name, value); } - public string? Uri + public Bitmap? ImageBitmap { - get => _uri; - set => SetProperty(ref _uri, value); + get => _imageBitmap; + set => SetProperty(ref _imageBitmap, value); } public Champion(string id, string name, string title, List tags, ImageInfo image, string? uri = null) @@ -52,7 +54,6 @@ public class Champion : ObservableObject this.Title = title; this.Tags = tags; this.Image = image; - this.Uri = uri; } } @@ -60,8 +61,8 @@ public partial class MainWindowViewModel : ViewModelBase { private HttpClient httpClient = new HttpClient(); private List Lanes = new List(["Top", "Mid", "Bot", "Sup", "Jgl"]); - - private List? _championList = new List(); + + private List? _championList; private Champion? _selectedChampion; private string? _lane; @@ -71,6 +72,12 @@ public partial class MainWindowViewModel : ViewModelBase public RelayCommand getRandomChampionLaneComboCommand { get; private set; } + public List? ChampionList + { + get => _championList; + set => SetProperty(ref _championList, value); + } + public Champion? SelectedChampion { get => _selectedChampion; @@ -95,20 +102,21 @@ public partial class MainWindowViewModel : ViewModelBase set => SetProperty(ref _leagueClientVersion, value); } - private async Task LoadAndSetChampionImageAsync(Champion champ) + private async void LoadAndSetChampionImageAsync() { - champ.Uri = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{champ.Image.Full}"; - // champ.Uri = await LoadChampionImageAsync(champ); + // champ.Uri = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{champ.Image.Full}"; + if(SelectedChampion != null) + SelectedChampion.ImageBitmap = await LoadChampionImageAsync(); } - private async Task LoadChampionImageAsync(Champion? champ) + private async Task LoadChampionImageAsync() { - if(champ == null) return null; - var imageUrl = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{champ.Image.Full}"; + var imageUrl = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{SelectedChampion.Image.Full}"; try { - await using var stream = await httpClient.GetStreamAsync(imageUrl); - return new Bitmap(stream); + var bytes = await httpClient.GetByteArrayAsync(imageUrl); + using var ms = new MemoryStream(bytes); + return await Task.Run(() => new Bitmap(ms)); } catch { @@ -132,8 +140,6 @@ public partial class MainWindowViewModel : ViewModelBase private async Task getChampions() { - if (httpClient == null) httpClient = new HttpClient(); - LeagueClientVersion = await getClientVersion(); if (LeagueClientVersion == "Unavailable") return; @@ -152,22 +158,22 @@ public partial class MainWindowViewModel : ViewModelBase var wrapper = JsonSerializer.Deserialize(json, options); _championList = wrapper?.Data?.Values.ToList() ?? new List(); - } catch (Exception ex) { - Console.WriteLine("Fehler beim Laden der Champion-Daten: " + ex.Message); + Console.WriteLine("Failed to load Champions: " + ex.Message); } } private async void getRandomChampionLaneComboCommandExecute() { + if (_championList == null) await InitAsync(); var champ = _championList?[Random.Shared.Next(_championList.Count)]; if (champ != null) { - await LoadAndSetChampionImageAsync(champ); - // champ.ImageBitmap = await LoadChampionImageAsync(champ); + // champ.Image.Full = await LoadChampionImageAsync(champ); SelectedChampion = champ; + LoadAndSetChampionImageAsync(); } Lane = Lanes[Random.Shared.Next(Lanes.Count)]; } @@ -180,7 +186,7 @@ public partial class MainWindowViewModel : ViewModelBase public MainWindowViewModel() { - getRandomChampionLaneComboCommand = new RelayCommand(getRandomChampionLaneComboCommandExecute); _ = InitAsync(); + getRandomChampionLaneComboCommand = new RelayCommand(getRandomChampionLaneComboCommandExecute); } } \ No newline at end of file diff --git a/LOLRLCG/Views/MainWindow.axaml b/LOLRLCG/Views/MainWindow.axaml index c1dfb0e..4d5ee84 100644 --- a/LOLRLCG/Views/MainWindow.axaml +++ b/LOLRLCG/Views/MainWindow.axaml @@ -11,6 +11,11 @@ Title="LOLRLCG" Width="{StaticResource Width}" Height="{StaticResource Height}" + TransparencyLevelHint="Transparent" + Background="Transparent" + TransparencyBackgroundFallback="Black" + ExtendClientAreaToDecorationsHint="True" + CanResize="False" > @@ -25,22 +30,28 @@ - + - - - + + + + + + + + + - - -