Skip to content

Commit

Permalink
Added the "stores" section in "GameInfo" page (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed May 9, 2021
1 parent 6246abc commit f27171d
Show file tree
Hide file tree
Showing 23 changed files with 299 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gavilya.SDK/Gavilya.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.1.0.2104</Version>
<Version>1.2.0.2105</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://leo-corporation.github.io/Gavilya-Web/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/Gavilya</RepositoryUrl>
Expand Down
7 changes: 6 additions & 1 deletion Gavilya.SDK/RAWG/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Game
public string description_raw { get; set; }
public int playtime { get; set; }
public List<ReturnedPlatforms> platforms { get; set; }
public List<Store> stores { get; set; }
public List<ParentStore> stores { get; set; }
public string released { get; set; }
public bool tba { get; set; }
public string background_image { get; set; }
Expand Down Expand Up @@ -133,6 +133,11 @@ public class Short_Screenshot
public string image { get; set; }
}

public class ParentStore
{
public Store store { get; set; }
}

public class Store
{
public int id { get; set; }
Expand Down
Binary file added Gavilya/Assets/AppStore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/EpicGames.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/GOG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/GooglePlay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/Itchio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/Nintendo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/PlayStation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/Steam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Gavilya/Assets/Xbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Gavilya/Classes/GameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ public class GameInfo
/// The game available platforms.
/// </summary>
public List<SDK.RAWG.Platform> Platforms { get; set; }

/// <summary>
/// The stores where the game is available on.
/// </summary>
public List<SDK.RAWG.Store> Stores { get; set; }
}
}
28 changes: 28 additions & 0 deletions Gavilya/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,34 @@ internal static int GetTotalTimePlayed()
}
}

/// <summary>
/// Gets a game stores asynchronously.
/// </summary>
/// <param name="id">The id of the game.</param>
/// <returns></returns>
public static async Task<List<Store>> GetStoresAsync(int id)
{
try
{
var client = new RestClient(); // Create a REST Client
client.BaseUrl = new Uri($"https://api.rawg.io/api/games/{id}"); // Configure the client
var request = new RestRequest(Method.GET); // Create a request
request.AddQueryParameter("key", APIKeys.RAWGAPIKey);
var response = await client.ExecuteAsync(request); // Execute the request and store the result

var game = JsonSerializer.Deserialize<Game>(response.Content); // Deserialize the content of the reponse
List<Store> stores = new();

game.stores.ForEach(parent => stores.Add(parent.store));
return stores;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Properties.Resources.MainWindowTitle, MessageBoxButton.OK, MessageBoxImage.Error); // Error
return new List<Store>();
}
}

public static string UserName => Environment.UserName;
}
}
36 changes: 36 additions & 0 deletions Gavilya/Gavilya.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@
<ItemGroup>
<None Remove="Assets\addGame.png" />
<None Remove="Assets\addGamesWelcome.png" />
<None Remove="Assets\AppStore.png" />
<None Remove="Assets\check.png" />
<None Remove="Assets\computer-rocket.png" />
<None Remove="Assets\DefaultPP.png" />
<None Remove="Assets\EpicGames.png" />
<None Remove="Assets\GOG.png" />
<None Remove="Assets\GooglePlay.png" />
<None Remove="Assets\importGames.png" />
<None Remove="Assets\Itchio.png" />
<None Remove="Assets\Nintendo.png" />
<None Remove="Assets\PlayStation.png" />
<None Remove="Assets\recentGames.png" />
<None Remove="Assets\searchRAWG.png" />
<None Remove="Assets\selectGames.png" />
<None Remove="Assets\Steam.png" />
<None Remove="Assets\Xbox.png" />
<None Remove="Fonts\FluentlyIcons.ttf" />
<None Remove="Fonts\Montserrat-Bold.ttf" />
<None Remove="Fonts\Montserrat-Regular.ttf" />
Expand All @@ -55,6 +64,9 @@
<Resource Include="Assets\addGamesWelcome.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\AppStore.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\check.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
Expand All @@ -64,9 +76,27 @@
<Resource Include="Assets\DefaultPP.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\EpicGames.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\GOG.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\GooglePlay.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\importGames.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\Itchio.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\Nintendo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\PlayStation.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\recentGames.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
Expand All @@ -76,6 +106,12 @@
<Resource Include="Assets\selectGames.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\Steam.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\Xbox.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Fonts\FluentlyIcons.ttf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
Expand Down
Binary file modified Gavilya/Lib/Gavilya.SDK.dll
Binary file not shown.
18 changes: 14 additions & 4 deletions Gavilya/Pages/GameInfoPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,20 @@
<TextBlock Name="DescriptionTxt" Foreground="White" TextWrapping="Wrap"/>
</StackPanel>

<StackPanel Grid.Row="1" Name="PlatformDisplayer" Grid.Column="1" Margin="10">
<TextBlock Margin="1" Text="{x:Static lang:Resources.Platforms}" FontSize="20" FontWeight="Bold" Foreground="White"/>
</StackPanel>
</Grid>
<Grid Grid.Row="1" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<StackPanel Grid.Row="0" Name="PlatformDisplayer" Grid.Column="1" Margin="10">
<TextBlock Margin="1" Text="{x:Static lang:Resources.Platforms}" FontSize="20" FontWeight="Bold" Foreground="White"/>
</StackPanel>
<StackPanel Grid.Row="1" Name="StoreDisplayer" Grid.Column="1" Margin="10">
<TextBlock Margin="1" Text="{x:Static lang:Resources.Platforms}" FontSize="20" FontWeight="Bold" Foreground="White"/>
</StackPanel>
</Grid>
</Grid>

<Grid x:Name="RatingsPage" Grid.Row="1" Visibility="Collapsed">

Expand Down
26 changes: 25 additions & 1 deletion Gavilya/Pages/GameInfoPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public GameInfoPage()
/// </summary>
/// <param name="gameInfo">The game to load informations.</param>
/// <param name="parent">The parent element.</param>
public void InitializeUI(GameInfo gameInfo, UIElement parent = null)
public async void InitializeUI(GameInfo gameInfo, UIElement parent = null)
{
// Var
gameLocation = gameInfo.FileLocation;
Expand Down Expand Up @@ -147,6 +147,30 @@ public void InitializeUI(GameInfo gameInfo, UIElement parent = null)
PlatformDisplayer.Children.Add(new TextBlock { Foreground = new SolidColorBrush { Color = Colors.White }, Margin = new Thickness { Left = 1, Bottom = 1, Right = 1, Top = 1 }, Text = platform.name }); // New textblock
}

// Stores
StoreDisplayer.Children.Clear(); // Clear
StoreDisplayer.Children.Add(
new TextBlock
{
Foreground = new SolidColorBrush { Color = Colors.White }, // Set the foreground to white
Margin = new Thickness { Left = 1, Bottom = 1, Right = 1, Top = 1 }, // Set the the margin
FontSize = 20, // Set the font size
FontWeight = FontWeights.Bold, // Set the font weight
Text = Properties.Resources.AvailableOn // Set the text
}
); // Add the textblock

if (gameInfo.Stores.Count == 0)
{
gameInfo.Stores = await Global.GetStoresAsync(gameInfo.RAWGID);
new GameSaver().Save(Definitions.Games); // Save
}

for (int i = 0; i < gameInfo.Stores.Count; i++)
{
StoreDisplayer.Children.Add(new StoreItem(gameInfo.Stores[i])); // Add
}

// Ratings
LoadRatings();

Expand Down
45 changes: 45 additions & 0 deletions Gavilya/Properties/Resources.Designer.cs

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

15 changes: 15 additions & 0 deletions Gavilya/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,19 @@
<data name="LeastPlayed" xml:space="preserve">
<value>Least played</value>
</data>
<data name="Stores" xml:space="preserve">
<value>Stores</value>
</data>
<data name="AvailableOn" xml:space="preserve">
<value>Available on</value>
</data>
<data name="Steam" xml:space="preserve">
<value>Steam</value>
</data>
<data name="EpicGamesStore" xml:space="preserve">
<value>Epic Games Store</value>
</data>
<data name="MicrosoftStore" xml:space="preserve">
<value>Microsoft Store</value>
</data>
</root>
15 changes: 15 additions & 0 deletions Gavilya/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,19 @@
<data name="LeastPlayed" xml:space="preserve">
<value>Les moins joués</value>
</data>
<data name="Stores" xml:space="preserve">
<value>Stores</value>
</data>
<data name="AvailableOn" xml:space="preserve">
<value>Disponible sur</value>
</data>
<data name="Steam" xml:space="preserve">
<value>Steam</value>
</data>
<data name="EpicGamesStore" xml:space="preserve">
<value>Epic Games Store</value>
</data>
<data name="MicrosoftStore" xml:space="preserve">
<value>Microsoft Store</value>
</data>
</root>
15 changes: 15 additions & 0 deletions Gavilya/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,19 @@
<data name="LeastPlayed" xml:space="preserve">
<value>Least played</value>
</data>
<data name="Stores" xml:space="preserve">
<value>Stores</value>
</data>
<data name="AvailableOn" xml:space="preserve">
<value>Available on</value>
</data>
<data name="Steam" xml:space="preserve">
<value>Steam</value>
</data>
<data name="EpicGamesStore" xml:space="preserve">
<value>Epic Games Store</value>
</data>
<data name="MicrosoftStore" xml:space="preserve">
<value>Microsoft Store</value>
</data>
</root>
16 changes: 16 additions & 0 deletions Gavilya/UserControls/StoreItem.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<UserControl x:Class="Gavilya.UserControls.StoreItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Gavilya.UserControls"
mc:Ignorable="d" Foreground="#FFF"
FontFamily="..\Fonts\#Montserrat"
Height="40" Width="200">
<Border CornerRadius="5" Margin="5 2 5 2" Background="#FF1E1E32">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Image x:Name="IconImg" d:Source="..\Assets\Xbox.png" Height="25" Width="25" Margin="5,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
<TextBlock x:Name="StoreNameTxt" d:Text="Xbox Store" FontWeight="Bold" FontSize="14" VerticalAlignment="Center" Margin="10,0,0,0"/>
</StackPanel>
</Border>
</UserControl>
Loading

0 comments on commit f27171d

Please sign in to comment.