Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add download feature #1

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TrimuiSmartHub.Application/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="10" Padding="10">
<StackPanel Orientation="Horizontal">
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Margin="5,0,10,0" Text="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="18" Margin="5,0,10,0" Text="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
<ContentPresenter VerticalAlignment="Center"/>
</StackPanel>
</Border>
Expand Down
34 changes: 34 additions & 0 deletions TrimuiSmartHub.Application/Frames/GameDownloader.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Page x:Class="TrimuiSmartHub.Application.Frames.GameDownloader"
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:TrimuiSmartHub.Application.Frames"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
xmlns:li="clr-namespace:LoadingIndicators.WPF;assembly=LoadingIndicators.WPF"
Title="GameDownloader">

<Grid>
<StackPanel x:Name="LoadingIndicator" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,25,100">
<TextBlock FontSize="18" FontWeight="SemiBold" Foreground="#AAB8C2" Text="Loading Emulators" Margin="25"/>
<li:LoadingIndicator SpeedRatio="1" IsActive="True" Style="{DynamicResource LoadingIndicatorThreeDotsStyle}" Foreground="#2d607f" RenderTransformOrigin="0.5,0.5" >
<li:LoadingIndicator.RenderTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</li:LoadingIndicator.RenderTransform>
</li:LoadingIndicator>
</StackPanel>
<StackPanel x:Name="RomsPanel" Visibility="Collapsed" Orientation="Vertical" Margin="0,25">
<TextBlock Text="Select a Emulator" Foreground="#AAB8C2" FontSize="16" FontWeight="SemiBold"/>
<Separator Width="Auto" Margin="5, 20, 20,20" Background="#AAB8C2"/>

<ScrollViewer VerticalScrollBarVisibility="Auto" Style="{StaticResource CustomScrollViewer}" >
<WrapPanel Orientation="Horizontal" Margin="10" x:Name="RomsContainer">


</WrapPanel>
</ScrollViewer>

</StackPanel>
</Grid>
</Page>
162 changes: 162 additions & 0 deletions TrimuiSmartHub.Application/Frames/GameDownloader.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using TrimuiSmartHub.Application.Repository;
using TrimuiSmartHub.Application.Services.LibRetro;
using TrimuiSmartHub.Application.Services.Trimui;
using TrimuiSmartHub.Application.Helpers;
using TrimuiSmartHub.Application.Services;
using CsQuery.Implementation;
using MahApps.Metro.Controls.Dialogs;
using MahApps.Metro.Controls;
using System.Linq;
using TrimuiSmartHub.Application.Pages;
using CsQuery.Engine.PseudoClassSelectors;

namespace TrimuiSmartHub.Application.Frames
{
public partial class GameDownloader : Page
{
private SmartProHub Parent { get; set; }
public GameDownloader(SmartProHub parent)
{
InitializeComponent();

Parent = parent;

PopulateEmulators();
}

private void PopulateEmulators()
{
Task.Run(() =>
{
var emulatorList = TrimuiService.New().GetEmulators();

foreach (var emulator in emulatorList)
{

Dispatcher.Invoke(() =>
{
var emulatorCard = CreateGameComponent(emulator);

if (emulatorCard != null)
{
RomsContainer.Children.Add(emulatorCard);
}
});
}

Dispatcher.Invoke(() =>
{
RomsPanel.Visibility = Visibility.Visible;
LoadingIndicator.Visibility = Visibility.Collapsed;
});
});
}
private Button? CreateGameComponent(string emulator)
{
string emulatorDescription;

EmulatorDictionary.EmulatorMapRetrostic.TryGetValue(emulator, out emulatorDescription);

if (emulatorDescription.IsNullOrEmpty()) return null;

Border border = new Border
{
Background = new LinearGradientBrush
{
StartPoint = new Point(0.5, 0),
EndPoint = new Point(0.5, 1),
GradientStops = new GradientStopCollection
{
new GradientStop(Color.FromArgb(35, 25, 84, 112), 1),
new GradientStop(Color.FromArgb(75, 45, 84, 112), 1)
}
},
CornerRadius = new CornerRadius(10),
Width = 120,
Height = 120,
Margin = new Thickness(5),
BorderThickness = new Thickness(1),
BorderBrush = new SolidColorBrush(Color.FromArgb(75, 45, 84, 112)),
};

StackPanel stackPanel = new StackPanel
{
Orientation = Orientation.Vertical,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center
};

try
{
var imgSource = new BitmapImage(new Uri($"pack://application:,,,/Resources/Images/Emulators/{emulator}.png"));
Image image = new Image
{
Source = imgSource,
Width = 70,
Height = 60,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(0, 0, 0, 0)
};

RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality);

stackPanel.Children.Add(image);
}
catch (Exception)
{
//
}


TextBlock titleBlock = new TextBlock
{
Text = emulator,
FontSize = 14,
FontWeight = FontWeights.Bold,
Foreground = Brushes.LightGray,
HorizontalAlignment = HorizontalAlignment.Center
};

stackPanel.Children.Add(titleBlock);

border.Child = stackPanel;

Button button = new Button
{
Content = border,
Style = (Style)System.Windows.Application.Current.FindResource("GameButtonStyle"),
Background = Brushes.Transparent,
BorderThickness = new Thickness(0),
};

button.Click += async (sender, e) =>
{
//await Loading(true, $"Downloading games boxart...");

var count = 0;

Task.Run(async () =>
{
//var download = RetrosticService.New().DownloadGame(emulator, "Street Fighter");

Dispatcher.Invoke(() =>
{
Parent.NavigationFrame.Navigate(new GameDownloaderSearch(emulator));
});

});

//await Loading(false);

//await ShowMessageAsync("Download Completed!", (count > 0) ? $"{count} Files was updated!" : "The boxarts already updated!");
};

return button;
}
}
}
141 changes: 141 additions & 0 deletions TrimuiSmartHub.Application/Frames/GameDownloaderSearch.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<Page x:Class="TrimuiSmartHub.Application.Frames.GameDownloaderSearch"
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:TrimuiSmartHub.Application.Frames"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
xmlns:li="clr-namespace:LoadingIndicators.WPF;assembly=LoadingIndicators.WPF"
Title="GameDownloaderSearch">

<Grid>
<StackPanel x:Name="LoadingComponent" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,25,100">
<TextBlock FontSize="18" FontWeight="SemiBold" Foreground="#AAB8C2" Text="Searching Games..." Margin="25"/>
<li:LoadingIndicator SpeedRatio="1" IsActive="True" Style="{DynamicResource LoadingIndicatorThreeDotsStyle}" Foreground="#2d607f" RenderTransformOrigin="0.5,0.5" >
<li:LoadingIndicator.RenderTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</li:LoadingIndicator.RenderTransform>
</li:LoadingIndicator>
</StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="ConsoleName" Margin="35,0,15,0" Text="Console Name" FontSize="16" FontWeight="SemiBold"
Foreground="#AAB8C2" />
<Border Margin="30,15,15,0"
Background="#4DF0F0F0"
BorderBrush="Transparent"
BorderThickness="1"
CornerRadius="5"
HorizontalAlignment="Stretch"
Height="35">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>

<TextBlock Text="&#xE721;"
FontFamily="Segoe MDL2 Assets"
VerticalAlignment="Center"
Margin="10,0,0,0"
FontSize="16"
Foreground="#AAB8C2"/>

<!--<TextBox x:Name="searchTextBox"
Grid.Column="1"
Margin="10,0,10,0"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
FontSize="14"
Foreground="Black"
Text="Search ROMs..."
/>-->
<Grid Grid.Column="1">
<TextBox Width="250" FontSize="14" Foreground="#AAB8C2" Background="Transparent" BorderThickness="0" VerticalAlignment="Center" HorizontalAlignment="Left" x:Name="SearchTermTextBox" Margin="5"/>
<TextBlock IsHitTestVisible="False"
FontSize="14"
Text="Enter the game name to search..."
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="10,0,0,0"
Foreground="#AAB8C2" >
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Text, ElementName=SearchTermTextBox}" Value="">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
</Grid>
</Border>
<Button Background="#22384f" Height="33" Margin="0, 15,20,0" Grid.Column="1" Cursor="Hand" Click="Search_Button_Click">
<Button.Content>
<TextBlock Text="Search" Foreground="#AAB8C2" FontSize="14" FontWeight="Medium" />
</Button.Content>
</Button>
</Grid>

<StackPanel Grid.Row="1" Margin="10">
<Border Padding="5" Background="#B31c2e41" CornerRadius="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>


<TextBlock Text="Image"
Foreground="#AAB8C2"
VerticalAlignment="Center"
FontSize="14"
FontWeight="Bold"
HorizontalAlignment="Center"
Grid.Column="0"
Margin="10,0"/>

<TextBlock Text="Name"
Foreground="#AAB8C2"
FontWeight="Bold"
FontSize="14"
VerticalAlignment="Center"
Grid.Column="1"
Margin="20,0"/>
<TextBlock Text="Region"
Foreground="#AAB8C2"
FontWeight="Bold"
FontSize="14"
VerticalAlignment="Center"
Grid.Column="2"
Margin="20,0"/>
</Grid>
</Border>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" Height="580">
<WrapPanel Orientation="Vertical" x:Name="Container" Margin="0,10,0,0" Visibility="Collapsed">

</WrapPanel>
</ScrollViewer>
</StackPanel>
</Grid>
</Grid>
</Page>
Loading