Added visualization image for random picked champion
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -30,8 +31,9 @@ public class Champion : ObservableObject
|
|||||||
private string _name;
|
private string _name;
|
||||||
public string Title { get; init; }
|
public string Title { get; init; }
|
||||||
public List<string> Tags { get; init; }
|
public List<string> Tags { get; init; }
|
||||||
|
public string? Uri { get; init; }
|
||||||
public ImageInfo Image { get; set; }
|
public ImageInfo Image { get; set; }
|
||||||
private string? _uri;
|
private Bitmap? _imageBitmap;
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
@@ -39,10 +41,10 @@ public class Champion : ObservableObject
|
|||||||
set => SetProperty(ref _name, value);
|
set => SetProperty(ref _name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? Uri
|
public Bitmap? ImageBitmap
|
||||||
{
|
{
|
||||||
get => _uri;
|
get => _imageBitmap;
|
||||||
set => SetProperty(ref _uri, value);
|
set => SetProperty(ref _imageBitmap, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Champion(string id, string name, string title, List<string> tags, ImageInfo image, string? uri = null)
|
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.Title = title;
|
||||||
this.Tags = tags;
|
this.Tags = tags;
|
||||||
this.Image = image;
|
this.Image = image;
|
||||||
this.Uri = uri;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
private HttpClient httpClient = new HttpClient();
|
private HttpClient httpClient = new HttpClient();
|
||||||
private List<string> Lanes = new List<string>(["Top", "Mid", "Bot", "Sup", "Jgl"]);
|
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 Champion? _selectedChampion;
|
||||||
|
|
||||||
private string? _lane;
|
private string? _lane;
|
||||||
@@ -71,6 +72,12 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
public RelayCommand getRandomChampionLaneComboCommand { get; private set; }
|
public RelayCommand getRandomChampionLaneComboCommand { get; private set; }
|
||||||
|
|
||||||
|
public List<Champion>? ChampionList
|
||||||
|
{
|
||||||
|
get => _championList;
|
||||||
|
set => SetProperty(ref _championList, value);
|
||||||
|
}
|
||||||
|
|
||||||
public Champion? SelectedChampion
|
public Champion? SelectedChampion
|
||||||
{
|
{
|
||||||
get => _selectedChampion;
|
get => _selectedChampion;
|
||||||
@@ -95,20 +102,21 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
set => SetProperty(ref _leagueClientVersion, value);
|
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 = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{champ.Image.Full}";
|
||||||
// champ.Uri = await LoadChampionImageAsync(champ);
|
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/{SelectedChampion.Image.Full}";
|
||||||
var imageUrl = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{champ.Image.Full}";
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var stream = await httpClient.GetStreamAsync(imageUrl);
|
var bytes = await httpClient.GetByteArrayAsync(imageUrl);
|
||||||
return new Bitmap(stream);
|
using var ms = new MemoryStream(bytes);
|
||||||
|
return await Task.Run(() => new Bitmap(ms));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -132,8 +140,6 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
private async Task getChampions()
|
private async Task getChampions()
|
||||||
{
|
{
|
||||||
if (httpClient == null) httpClient = new HttpClient();
|
|
||||||
|
|
||||||
LeagueClientVersion = await getClientVersion();
|
LeagueClientVersion = await getClientVersion();
|
||||||
if (LeagueClientVersion == "Unavailable") return;
|
if (LeagueClientVersion == "Unavailable") return;
|
||||||
|
|
||||||
@@ -152,22 +158,22 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
var wrapper = JsonSerializer.Deserialize<ChampionWrapper>(json, options);
|
var wrapper = JsonSerializer.Deserialize<ChampionWrapper>(json, options);
|
||||||
|
|
||||||
_championList = wrapper?.Data?.Values.ToList() ?? new List<Champion>();
|
_championList = wrapper?.Data?.Values.ToList() ?? new List<Champion>();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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()
|
private async void getRandomChampionLaneComboCommandExecute()
|
||||||
{
|
{
|
||||||
|
if (_championList == null) await InitAsync();
|
||||||
var champ = _championList?[Random.Shared.Next(_championList.Count)];
|
var champ = _championList?[Random.Shared.Next(_championList.Count)];
|
||||||
if (champ != null)
|
if (champ != null)
|
||||||
{
|
{
|
||||||
await LoadAndSetChampionImageAsync(champ);
|
// champ.Image.Full = await LoadChampionImageAsync(champ);
|
||||||
// champ.ImageBitmap = await LoadChampionImageAsync(champ);
|
|
||||||
SelectedChampion = champ;
|
SelectedChampion = champ;
|
||||||
|
LoadAndSetChampionImageAsync();
|
||||||
}
|
}
|
||||||
Lane = Lanes[Random.Shared.Next(Lanes.Count)];
|
Lane = Lanes[Random.Shared.Next(Lanes.Count)];
|
||||||
}
|
}
|
||||||
@@ -180,7 +186,7 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
public MainWindowViewModel()
|
public MainWindowViewModel()
|
||||||
{
|
{
|
||||||
getRandomChampionLaneComboCommand = new RelayCommand(getRandomChampionLaneComboCommandExecute);
|
|
||||||
_ = InitAsync();
|
_ = InitAsync();
|
||||||
|
getRandomChampionLaneComboCommand = new RelayCommand(getRandomChampionLaneComboCommandExecute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,11 @@
|
|||||||
Title="LOLRLCG"
|
Title="LOLRLCG"
|
||||||
Width="{StaticResource Width}"
|
Width="{StaticResource Width}"
|
||||||
Height="{StaticResource Height}"
|
Height="{StaticResource Height}"
|
||||||
|
TransparencyLevelHint="Transparent"
|
||||||
|
Background="Transparent"
|
||||||
|
TransparencyBackgroundFallback="Black"
|
||||||
|
ExtendClientAreaToDecorationsHint="True"
|
||||||
|
CanResize="False"
|
||||||
>
|
>
|
||||||
|
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
@@ -25,22 +30,28 @@
|
|||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
<Panel>
|
<Panel>
|
||||||
<Image Source="avares://LOLRLCG/Resources/background.png" Width="{StaticResource Width}" Height="{StaticResource Height}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
<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>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<!-- Champion Visualisation -->
|
<!-- Champion Visualisation -->
|
||||||
<StackPanel Grid.Column="0">
|
<StackPanel Grid.Column="0">
|
||||||
<TextBlock Text="{Binding SelectedChampion.Name}"></TextBlock>
|
<StackPanel Background="#000000ff">
|
||||||
<Image Source="{Binding SelectedChampion.Image.Full}"></Image>
|
<TextBlock Foreground="White" Text="Champion: "></TextBlock>
|
||||||
<TextBlock Text="{Binding Lane}"></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>
|
</StackPanel>
|
||||||
<!-- Possibility Settings -->
|
<!-- Possibility Settings -->
|
||||||
<StackPanel Grid.Column="1">
|
<StackPanel Grid.Column="1">
|
||||||
<TextBlock Text="League Client Version: "></TextBlock>
|
<TextBlock Foreground="White" Text="League Client Version: "></TextBlock>
|
||||||
<TextBlock Text="{Binding LeagueClientVersion}"></TextBlock>
|
<TextBlock Foreground="White" Text="{Binding LeagueClientVersion}"></TextBlock>
|
||||||
<Button Content="Get Random Champion" Command="{Binding getRandomChampionLaneComboCommand}"/>
|
<Button Foreground="White" Content="Get Random Champion" Command="{Binding getRandomChampionLaneComboCommand}" IsEnabled="{Binding ChampionList.Count}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|||||||
Reference in New Issue
Block a user