Added visualization image for random picked champion
This commit is contained in:
@@ -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<string> 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<string> 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<string> Lanes = new List<string>(["Top", "Mid", "Bot", "Sup", "Jgl"]);
|
||||
|
||||
private List<Champion>? _championList = new List<Champion>();
|
||||
|
||||
private List<Champion>? _championList;
|
||||
private Champion? _selectedChampion;
|
||||
|
||||
private string? _lane;
|
||||
@@ -71,6 +72,12 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
|
||||
public RelayCommand getRandomChampionLaneComboCommand { get; private set; }
|
||||
|
||||
public List<Champion>? 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<Bitmap?> LoadChampionImageAsync(Champion? champ)
|
||||
private async Task<Bitmap?> 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<ChampionWrapper>(json, options);
|
||||
|
||||
_championList = wrapper?.Data?.Values.ToList() ?? new List<Champion>();
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,11 @@
|
||||
Title="LOLRLCG"
|
||||
Width="{StaticResource Width}"
|
||||
Height="{StaticResource Height}"
|
||||
TransparencyLevelHint="Transparent"
|
||||
Background="Transparent"
|
||||
TransparencyBackgroundFallback="Black"
|
||||
ExtendClientAreaToDecorationsHint="True"
|
||||
CanResize="False"
|
||||
>
|
||||
|
||||
<Window.Resources>
|
||||
@@ -25,22 +30,28 @@
|
||||
</Design.DataContext>
|
||||
<Panel>
|
||||
<Image Source="avares://LOLRLCG/Resources/background.png" Width="{StaticResource Width}" Height="{StaticResource Height}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
<Grid>
|
||||
<Grid Margin="20, 40" Background="#000000ff">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Champion Visualisation -->
|
||||
<StackPanel Grid.Column="0">
|
||||
<TextBlock Text="{Binding SelectedChampion.Name}"></TextBlock>
|
||||
<Image Source="{Binding SelectedChampion.Image.Full}"></Image>
|
||||
<TextBlock Text="{Binding Lane}"></TextBlock>
|
||||
<StackPanel Background="#000000ff">
|
||||
<TextBlock Foreground="White" Text="Champion: "></TextBlock>
|
||||
<TextBlock Foreground="White" Text="{Binding SelectedChampion.Name}"></TextBlock>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Foreground="White" Text="Lane: "></TextBlock>
|
||||
<TextBlock Foreground="White" Text="{Binding Lane}"></TextBlock>
|
||||
</StackPanel>
|
||||
<Image Source="{Binding SelectedChampion.ImageBitmap}" Width="200" Height="400"></Image>
|
||||
</StackPanel>
|
||||
<!-- Possibility Settings -->
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="League Client Version: "></TextBlock>
|
||||
<TextBlock Text="{Binding LeagueClientVersion}"></TextBlock>
|
||||
<Button Content="Get Random Champion" Command="{Binding getRandomChampionLaneComboCommand}"/>
|
||||
<TextBlock Foreground="White" Text="League Client Version: "></TextBlock>
|
||||
<TextBlock Foreground="White" Text="{Binding LeagueClientVersion}"></TextBlock>
|
||||
<Button Foreground="White" Content="Get Random Champion" Command="{Binding getRandomChampionLaneComboCommand}" IsEnabled="{Binding ChampionList.Count}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Panel>
|
||||
|
||||
Reference in New Issue
Block a user