Skip to content

Commit

Permalink
库存游戏图片编辑功能新增Steam库横版与竖版封面的自定义
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Apr 26, 2022
1 parent 31f6c4c commit fe31908
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 34 deletions.
2 changes: 1 addition & 1 deletion references/AvaloniaGif
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,25 @@
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:SteamGridItem}">
<StackPanel Margin="0 0 0 15" Spacing="6">
<StackPanel.ContextFlyout>
<MenuFlyout>
<MenuItem Header="{ReflectionBinding Path=Res.OpenImageInBrowser,Mode=OneWay,Source={x:Static resx:R.Current}}"
Command="{ReflectionBinding #u.DataContext.OpenSteamGridDBImageUrl}"
CommandParameter="{Binding}"/>
<MenuItem Header="{ReflectionBinding Path=Res.OpenSteamGridDBInBrowser,Mode=OneWay,Source={x:Static resx:R.Current}}"
Command="{ReflectionBinding #u.DataContext.OpenSteamGridDBAppUrl}"
CommandParameter="{Binding}"/>
<MenuItem Header="{ReflectionBinding Path=Res.OpenTheAuthorPageInBrowser,Mode=OneWay,Source={x:Static resx:R.Current}}"
Command="{ReflectionBinding #u.DataContext.OpenSteamGridDBAuthorUrl}"
CommandParameter="{Binding}"/>
</MenuFlyout>
</StackPanel.ContextFlyout>
<Panel Width="150"
MinHeight="150">
<gif:Image2 Width="150"
DecodeWidth="150"
Stretch="Uniform"
Source="{Binding Thumb}" />
<Panel.ContextFlyout>
<MenuFlyout>
<MenuItem Header="{ReflectionBinding Path=Res.OpenImageInBrowser,Mode=OneWay,Source={x:Static resx:R.Current}}"
Command="{ReflectionBinding #u.DataContext.OpenSteamGridDBImageUrl}"
CommandParameter="{Binding}"/>
<MenuItem Header="{ReflectionBinding Path=Res.OpenSteamGridDBInBrowser,Mode=OneWay,Source={x:Static resx:R.Current}}"
Command="{ReflectionBinding #u.DataContext.OpenSteamGridDBAppUrl}"
CommandParameter="{Binding}"/>
<MenuItem Header="{ReflectionBinding Path=Res.OpenTheAuthorPageInBrowser,Mode=OneWay,Source={x:Static resx:R.Current}}"
Command="{ReflectionBinding #u.DataContext.OpenSteamGridDBAuthorUrl}"
CommandParameter="{Binding}"/>
</MenuFlyout>
</Panel.ContextFlyout>
</Panel>
<!--<TextBlock MaxWidth="150"
TextWrapping="Wrap"
Expand All @@ -190,7 +190,33 @@
<Border Classes="Item">
<DockPanel>
<StackPanel Margin="0">
<TextBlock Text="{ReflectionBinding Path=Res.TitlePage,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<TextBlock Text="{ReflectionBinding Path=Res.HorizontalTitlePage,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<Button Classes="Hyperlink"
FontSize="12"
Content="{ReflectionBinding Path=Res.GetImageFromSteamGridDB,Mode=OneWay,Source={x:Static resx:R.Current}}"
Tag="{x:Static models:SteamGridItemType.Header}"
Click="ShowGridDialog_Click"/>

<TextBlock Classes="prompt h8"
Text="{ReflectionBinding Path=Res.RecommendedResolution,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<TextBlock Classes="prompt h8"
Text="460 x 215 px"/>
</StackPanel>

<controls:CustomFilePicker Margin="50 0 0 0"
MaxHeight="260"
FileStream="{Binding App.EditHeaderLogoStream,Mode=TwoWay}"
HorizontalAlignment="Right">
<gif:Image2 DecodeHeight="260"
Stretch="Uniform"
Source="{Binding App.EditHeaderLogoStream}"/>
</controls:CustomFilePicker>
</DockPanel>
</Border>
<Border Classes="Item">
<DockPanel>
<StackPanel Margin="0">
<TextBlock Text="{ReflectionBinding Path=Res.VerticalTitlePage,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<Button Classes="Hyperlink"
FontSize="12"
Content="{ReflectionBinding Path=Res.GetImageFromSteamGridDB,Mode=OneWay,Source={x:Static resx:R.Current}}"
Expand All @@ -200,7 +226,7 @@
<TextBlock Classes="prompt h8"
Text="{ReflectionBinding Path=Res.RecommendedResolution,Mode=OneWay,Source={x:Static resx:R.Current}}"/>
<TextBlock Classes="prompt h8"
Text="300 x 450 px"/>
Text="600 x 900 px"/>
</StackPanel>

<controls:CustomFilePicker Margin="50 0 0 0"
Expand Down Expand Up @@ -230,10 +256,10 @@
</StackPanel>

<controls:CustomFilePicker Margin="50 0 0 0"
MaxHeight="160"
MaxHeight="260"
FileStream="{Binding App.EditLibraryHeroStream,Mode=TwoWay}"
HorizontalAlignment="Right">
<gif:Image2 DecodeHeight="160"
<gif:Image2 DecodeHeight="260"
Stretch="Uniform"
Source="{Binding App.EditLibraryHeroStream}"/>
</controls:CustomFilePicker>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ public uint[] GetInstalledAppIds()

var fileName = type switch
{
SteamApp.LibCacheType.Header => $"{appId}.png",
SteamApp.LibCacheType.Library_Grid => $"{appId}p.png",
SteamApp.LibCacheType.Library_Hero => $"{appId}_hero.png",
SteamApp.LibCacheType.Logo => $"{appId}_logo.png",
Expand Down Expand Up @@ -714,8 +715,8 @@ public async Task<bool> SaveAppImageToSteamFile(object? imageObject, SteamUser u
{
SteamGridItemType.Hero => Path.Combine(path, $"{appId}_hero.png"),
SteamGridItemType.Logo => Path.Combine(path, $"{appId}_logo.png"),
//SteamGridItemType.Icon => Path.Combine(path, $"{appId}.ico"),
_ => Path.Combine(path, $"{appId}p.png"),
SteamGridItemType.Grid => Path.Combine(path, $"{appId}p.png"),
_ => Path.Combine(path, $"{appId}.png"),
};
try
{
Expand Down
11 changes: 11 additions & 0 deletions src/ST.Client/Models/Steam/SteamApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,16 @@ public Stream? EditLibraryLogoStream

public string HeaderLogoUrl => string.Format(STEAMAPP_HEADIMAGE_URL, AppId);

public Task<string> HeaderLogoStream => ISteamService.Instance.GetAppImageAsync(this, LibCacheType.Header);

private Stream? _EditHeaderLogoStream;

public Stream? EditHeaderLogoStream
{
get => _EditHeaderLogoStream;
set => this.RaiseAndSetIfChanged(ref _EditHeaderLogoStream, value);
}

public string CAPSULELogoUrl => string.Format(STEAMAPP_CAPSULE_URL, AppId);

public string? IconUrl => string.IsNullOrEmpty(Icon) ? null :
Expand Down Expand Up @@ -881,6 +891,7 @@ public async void RefreshEditImage()
this.EditLibraryGridStream = IOPath.OpenRead(await this.LibraryGridStream);
this.EditLibraryHeroStream = IOPath.OpenRead(await this.LibraryHeroStream);
this.EditLibraryLogoStream = IOPath.OpenRead(await this.LibraryLogoStream);
this.EditHeaderLogoStream = IOPath.OpenRead(await this.HeaderLogoStream);
}

public enum LibCacheType : byte
Expand Down
3 changes: 2 additions & 1 deletion src/ST.Client/Models/SteamGridDB/SteamGridItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum SteamGridItemType
Grid,
Hero,
Logo,
Icon
Icon,
Header,
}
}
2 changes: 1 addition & 1 deletion src/ST.Client/Services/Implementation/HttpServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace System.Application.Services.Implementation
{
internal sealed class HttpServiceImpl : GeneralHttpClientFactory, IHttpService
public sealed class HttpServiceImpl : GeneralHttpClientFactory, IHttpService
{
readonly JsonSerializer jsonSerializer = new();
//readonly Lazy<ICloudServiceClient> _csc = new(() => DI.Get<ICloudServiceClient>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,23 @@ public SteamGridDBWebApiServiceImpl(IHttpService s)
SteamGridItemType.Hero => string.Format(SteamGridDBApiUrls.RetrieveHeros_Url, gameId),
SteamGridItemType.Logo => string.Format(SteamGridDBApiUrls.RetrieveLogos_Url, gameId),
SteamGridItemType.Icon => string.Format(SteamGridDBApiUrls.RetrieveIcons_Url, gameId),
SteamGridItemType.Header => string.Format(SteamGridDBApiUrls.RetrieveGrids_Url, gameId),
_ => string.Format(SteamGridDBApiUrls.RetrieveGrids_Url, gameId),
};
url += $"nsfw=any&humor=any";

//url += "?nsfw=any&humor=any";

url += "?types=static,animated";

if (type == SteamGridItemType.Header)
{
url += "&dimensions=460x215,920x430";
}
else if (type == SteamGridItemType.Grid)
{
url += "&dimensions=600x900";
}

var rsp = await s.SendAsync<SteamGridItemData>
(url, () =>
{
Expand Down
27 changes: 18 additions & 9 deletions src/ST.Client/UI/Resx/AppResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/ST.Client/UI/Resx/AppResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2179,8 +2179,11 @@ AAAAA-BBBBB-CCCC3</value>
<data name="GetImageFromSteamGridDB" xml:space="preserve">
<value>从 SteamGridDB 获取</value>
</data>
<data name="TitlePage" xml:space="preserve">
<value>封面</value>
<data name="HorizontalTitlePage" xml:space="preserve">
<value>横版封面</value>
</data>
<data name="VerticalTitlePage" xml:space="preserve">
<value>竖版封面</value>
</data>
<data name="Background" xml:space="preserve">
<value>背景</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,17 @@ public async void SaveEditAppInfo()
{
#region 自定义图片保存
var mostRecentUser = ISteamService.Instance.GetRememberUserList().Where(s => s.MostRecent).FirstOrDefault();
if (!(App.EditHeaderLogoStream is FileStream fs3 && fs3.Name == await App.HeaderLogoStream))
{
if (!CheckCurrentSteamUserStats(mostRecentUser))
return;

if (await ISteamService.Instance.SaveAppImageToSteamFile(App.EditHeaderLogoStream,
mostRecentUser, App.AppId, SteamGridItemType.Header) == false)
{
Toast.Show(string.Format(AppResources.SaveImageFileFailed, nameof(SteamGridItemType.Logo)));
}
}
if (!(App.EditLibraryLogoStream is FileStream fs && fs.Name == await App.LibraryLogoStream))
{
if (!CheckCurrentSteamUserStats(mostRecentUser))
Expand Down Expand Up @@ -238,6 +248,9 @@ public async void ApplyCustomImageToApp(SteamGridItemType type)
var stream = await IHttpService.Instance.GetImageStreamAsync(SelectGrid.Url, default);
switch (type)
{
case SteamGridItemType.Header:
App.EditHeaderLogoStream = stream;
break;
case SteamGridItemType.Grid:
App.EditLibraryGridStream = stream;
break;
Expand All @@ -257,6 +270,7 @@ public override void OnClosing(object? sender, CancelEventArgs e)
App.EditLibraryGridStream = null;
App.EditLibraryHeroStream = null;
App.EditLibraryLogoStream = null;
App.EditHeaderLogoStream = null;
}

_SteamGridItemSourceList.Dispose();
Expand All @@ -272,6 +286,7 @@ public async void OpenSteamGridDBAppUrl(SteamGridItem item)
var url = item.GridType switch
{
SteamGridItemType.Grid => string.Format(SteamGridDBApiUrls.SteamGridDBUrl_Grid, item.Id),
SteamGridItemType.Header => string.Format(SteamGridDBApiUrls.SteamGridDBUrl_Grid, item.Id),
SteamGridItemType.Hero => string.Format(SteamGridDBApiUrls.SteamGridDBUrl_Hero, item.Id),
SteamGridItemType.Icon => string.Format(SteamGridDBApiUrls.SteamGridDBUrl_Icon, item.Id),
SteamGridItemType.Logo => string.Format(SteamGridDBApiUrls.SteamGridDBUrl_Logo, item.Id),
Expand Down

0 comments on commit fe31908

Please sign in to comment.