Inital Push
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/.idea.LOLRLCG.iml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/contentModel.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
@@ -0,0 +1,15 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="LOLRLCG.App"
|
||||
xmlns:local="using:LOLRLCG"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
<Application.DataTemplates>
|
||||
<local:ViewLocator/>
|
||||
</Application.DataTemplates>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -0,0 +1,33 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using LOLRLCG.ViewModels;
|
||||
using LOLRLCG.Views;
|
||||
|
||||
namespace LOLRLCG;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Line below is needed to remove Avalonia data validation.
|
||||
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||
BindingPlugins.DataValidators.RemoveAt(0);
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel(),
|
||||
};
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 172 KiB |
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\"/>
|
||||
<AvaloniaResource Include="Assets\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.1.0"/>
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.1.0"/>
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0"/>
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0"/>
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0"/>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Resources\background.png" />
|
||||
<AvaloniaResource Include="Resources\background.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</AvaloniaResource>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LOLRLCG", "LOLRLCG.csproj", "{59FCC5C4-5827-4EAA-BC9C-2078CC0C6113}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{59FCC5C4-5827-4EAA-BC9C-2078CC0C6113}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{59FCC5C4-5827-4EAA-BC9C-2078CC0C6113}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{59FCC5C4-5827-4EAA-BC9C-2078CC0C6113}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{59FCC5C4-5827-4EAA-BC9C-2078CC0C6113}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,21 @@
|
||||
using Avalonia;
|
||||
using System;
|
||||
|
||||
namespace LOLRLCG;
|
||||
|
||||
sealed class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
[STAThread]
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.WithInterFont()
|
||||
.LogToTrace();
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 MiB |
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using LOLRLCG.ViewModels;
|
||||
|
||||
namespace LOLRLCG;
|
||||
|
||||
public class ViewLocator : IDataTemplate
|
||||
{
|
||||
public Control? Build(object? data)
|
||||
{
|
||||
if (data is null)
|
||||
return null;
|
||||
|
||||
var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
||||
var type = Type.GetType(name);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
var control = (Control)Activator.CreateInstance(type)!;
|
||||
control.DataContext = data;
|
||||
return control;
|
||||
}
|
||||
|
||||
return new TextBlock { Text = "Not Found: " + name };
|
||||
}
|
||||
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return data is ViewModelBase;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace LOLRLCG.ViewModels;
|
||||
|
||||
public class ChampionWrapper
|
||||
{
|
||||
public Dictionary<string, Champion> Data { get; set; }
|
||||
}
|
||||
|
||||
public class ImageInfo
|
||||
{
|
||||
public string Full { get; set; }
|
||||
}
|
||||
|
||||
public class Champion : ObservableObject
|
||||
{
|
||||
public string Id { get; init; }
|
||||
private string _name;
|
||||
public string Title { get; init; }
|
||||
public List<string> Tags { get; init; }
|
||||
public ImageInfo Image { get; set; }
|
||||
private string? _uri;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => SetProperty(ref _name, value);
|
||||
}
|
||||
|
||||
public string? Uri
|
||||
{
|
||||
get => _uri;
|
||||
set => SetProperty(ref _uri, value);
|
||||
}
|
||||
|
||||
public Champion(string id, string name, string title, List<string> tags, ImageInfo image, string? uri = null)
|
||||
{
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.Title = title;
|
||||
this.Tags = tags;
|
||||
this.Image = image;
|
||||
this.Uri = uri;
|
||||
}
|
||||
}
|
||||
|
||||
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 Champion? _selectedChampion;
|
||||
|
||||
private string? _lane;
|
||||
private Bitmap? _laneImage;
|
||||
|
||||
private string? _leagueClientVersion;
|
||||
|
||||
public RelayCommand getRandomChampionLaneComboCommand { get; private set; }
|
||||
|
||||
public Champion? SelectedChampion
|
||||
{
|
||||
get => _selectedChampion;
|
||||
set => SetProperty(ref _selectedChampion, value);
|
||||
}
|
||||
|
||||
public string Lane
|
||||
{
|
||||
get => _lane;
|
||||
set => SetProperty(ref _lane, value);
|
||||
}
|
||||
|
||||
public Bitmap? LaneImage
|
||||
{
|
||||
get => _laneImage;
|
||||
set => SetProperty(ref _laneImage, value);
|
||||
}
|
||||
|
||||
public string? LeagueClientVersion
|
||||
{
|
||||
get => _leagueClientVersion;
|
||||
set => SetProperty(ref _leagueClientVersion, value);
|
||||
}
|
||||
|
||||
private async Task LoadAndSetChampionImageAsync(Champion champ)
|
||||
{
|
||||
champ.Uri = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{champ.Image.Full}";
|
||||
// champ.Uri = await LoadChampionImageAsync(champ);
|
||||
}
|
||||
|
||||
private async Task<Bitmap?> LoadChampionImageAsync(Champion? champ)
|
||||
{
|
||||
if(champ == null) return null;
|
||||
var imageUrl = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/img/champion/{champ.Image.Full}";
|
||||
try
|
||||
{
|
||||
await using var stream = await httpClient.GetStreamAsync(imageUrl);
|
||||
return new Bitmap(stream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> getClientVersion()
|
||||
{
|
||||
try
|
||||
{
|
||||
var versionStr = await httpClient.GetStringAsync("https://ddragon.leagueoflegends.com/api/versions.json");
|
||||
var versions = JsonSerializer.Deserialize<List<string>>(versionStr);
|
||||
return versions?[0] ?? "Unavailable";
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "Unavailable";
|
||||
}
|
||||
}
|
||||
|
||||
private async Task getChampions()
|
||||
{
|
||||
if (httpClient == null) httpClient = new HttpClient();
|
||||
|
||||
LeagueClientVersion = await getClientVersion();
|
||||
if (LeagueClientVersion == "Unavailable") return;
|
||||
|
||||
try
|
||||
{
|
||||
var url = $"http://ddragon.leagueoflegends.com/cdn/{LeagueClientVersion}/data/de_DE/champion.json";
|
||||
var json = await httpClient.GetStringAsync(url);
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
IgnoreReadOnlyProperties = true,
|
||||
AllowTrailingCommas = true,
|
||||
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private async void getRandomChampionLaneComboCommandExecute()
|
||||
{
|
||||
var champ = _championList?[Random.Shared.Next(_championList.Count)];
|
||||
if (champ != null)
|
||||
{
|
||||
await LoadAndSetChampionImageAsync(champ);
|
||||
// champ.ImageBitmap = await LoadChampionImageAsync(champ);
|
||||
SelectedChampion = champ;
|
||||
}
|
||||
Lane = Lanes[Random.Shared.Next(Lanes.Count)];
|
||||
}
|
||||
|
||||
public async Task InitAsync()
|
||||
{
|
||||
await getClientVersion();
|
||||
await getChampions();
|
||||
}
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
getRandomChampionLaneComboCommand = new RelayCommand(getRandomChampionLaneComboCommandExecute);
|
||||
_ = InitAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace LOLRLCG.ViewModels;
|
||||
|
||||
public class ViewModelBase : ObservableObject
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:LOLRLCG.ViewModels"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:system="clr-namespace:System;assembly=System.Runtime"
|
||||
mc:Ignorable="d" d:DesignWidth="{StaticResource Width}" d:DesignHeight="{StaticResource Height}"
|
||||
x:Class="LOLRLCG.Views.MainWindow"
|
||||
x:DataType="vm:MainWindowViewModel"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="LOLRLCG"
|
||||
Width="{StaticResource Width}"
|
||||
Height="{StaticResource Height}"
|
||||
>
|
||||
|
||||
<Window.Resources>
|
||||
<system:Double x:Key="Width">1280</system:Double>
|
||||
<system:Double x:Key="Height">720</system:Double>
|
||||
</Window.Resources>
|
||||
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||
<vm:MainWindowViewModel/>
|
||||
</Design.DataContext>
|
||||
<Panel>
|
||||
<Image Source="avares://LOLRLCG/Resources/background.png" Width="{StaticResource Width}" Height="{StaticResource Height}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
<Grid>
|
||||
<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>
|
||||
<!-- 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}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Panel>
|
||||
</Window>
|
||||
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace LOLRLCG.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<!-- This manifest is used on Windows only.
|
||||
Don't remove it as it might cause problems with window transparency and embedded controls.
|
||||
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
|
||||
<assemblyIdentity version="1.0.0.0" name="LOLRLCG.Desktop"/>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- A list of the Windows versions that this application has been tested on
|
||||
and is designed to work with. Uncomment the appropriate elements
|
||||
and Windows will automatically select the most compatible environment. -->
|
||||
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||
</application>
|
||||
</compatibility>
|
||||
</assembly>
|
||||
Reference in New Issue
Block a user