Skip to content

Commit

Permalink
add something
Browse files Browse the repository at this point in the history
  • Loading branch information
shoushou1106 committed Aug 29, 2023
1 parent 43403e9 commit f9c824e
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
42 changes: 42 additions & 0 deletions FrostyEditor/Utils/BitmapAssetValueConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Avalonia.Data.Converters;
using Avalonia;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using Avalonia.Platform;

namespace FrostyEditor.Utils
{
/// <summary>
/// <para>
/// Converts a string path to a bitmap asset.
/// </para>
/// <para>
/// The asset must be in the same assembly as the program. If it isn't,
/// specify "avares://<assemblynamehere>/" in front of the path to the asset.
/// </para>
/// </summary>
public class BitmapAssetValueConverter
{
public static BitmapAssetValueConverter Instance = new BitmapAssetValueConverter();

public object? Convert(string? rawUri)
{
if (rawUri is null)
{
return null;
}

Uri uri = new Uri(rawUri);

var asset = AssetLoader.Open(uri);

return new Bitmap(asset);
}
}
}
34 changes: 34 additions & 0 deletions FrostyEditor/ViewModels/Windows/ProfileSelectWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ProfileConfig
public string Name { get; set; }
public string Key { get; set; }
public string Path { get; set; }
public object? Icon { get; set; }

// if they would ever actually release non windows version we would need to change the extension here
public string FileName => System.IO.Path.Combine(Path, $"{Key}.exe");
Expand All @@ -31,6 +32,39 @@ public ProfileConfig(string inKey)
Key = inKey;
Path = Config.Get("GamePath", string.Empty, ConfigScope.Game, Key);
Name = ProfilesLibrary.GetDisplayName(Key) ?? Key;
Icon = BitmapAssetValueConverter.Instance.Convert($"avares://FrostyEditor/Assets/Profiles/Icons/{ProfilesLibrary.GetInternalName(inKey)}.png");
// TODO: Add image for these png, they are placeholder now
// Assets/Profiles/Icons/
// anthem.png
// bf1.png
// bf4.png
// bf2042.png
// bfh.png
// bfv.png
// deadspace.png
// dragonage.png
// fifa17.png
// fifa18.png
// fifa19.png
// fifa20.png
// fifa21.png
// fifa22.png
// fifa23.png
// madden19.png
// madden20.png
// madden21.png
// madden22.png
// madden23.png
// masseffect.png
// mirrorsedge.png
// nfs14.png
// nfs16.png
// nfs17.png
// nfsedge.png
// nfsheat.png
// nfsunbound.png
// starwars.png
// starwarsiii.png
}
}

Expand Down
5 changes: 3 additions & 2 deletions FrostyEditor/Views/Windows/ProfileSelectWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<Design.DataContext>
<vm:ProfileSelectWindowViewModel />
</Design.DataContext>
<Grid Background="Transparent" Margin="2">

<Grid Background="Transparent" Margin="2">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
Expand Down Expand Up @@ -72,6 +72,7 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding Icon}" Width="100" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Path}"/>
</StackPanel>
Expand Down
5 changes: 5 additions & 0 deletions FrostySdk/ProfilesLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ public static bool IsLoaded(params ProfileVersion[] versions)
{
return s_profiles.Find(a => a.Name.Equals(profileKey, StringComparison.OrdinalIgnoreCase))?.DisplayName;
}

public static string? GetInternalName(string profileKey)
{
return s_profiles.Find(a => a.Name.Equals(profileKey, StringComparison.OrdinalIgnoreCase))?.InternalName;
}
}

0 comments on commit f9c824e

Please sign in to comment.