Skip to content

Commit

Permalink
Added game background image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelo420 committed Sep 10, 2023
1 parent 9419822 commit 1e718ed
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added re-index button to Admin Console
- Email, First Name, and Last Name are not mandatory for registration anymore
- Download progress is now displayed in the taskbar
- It is now possible to upload images from the client

## 1.4.1
### Changes
Expand Down
19 changes: 12 additions & 7 deletions gamevault/UserControls/GameViewUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@
<Image Source="pack://application:,,,/gamevault;component/Resources/Images/gameView_Back.png" HorizontalAlignment="Left" VerticalAlignment="Top" Height="50" Margin="5" Cursor="Hand" ToolTip="Back" Panel.ZIndex="1" MouseLeftButtonUp="BackButton_Clicked"/>
<TextBlock Text="✏️" Cursor="Hand" ToolTip="Remap game" HorizontalAlignment="Right" Foreground="White" VerticalAlignment="Top" FontSize="20" Margin="5" Visibility="{Binding CanEditGame}" Panel.ZIndex="1" MouseLeftButtonUp="GameRemapPopup_Click"/>
<Grid Visibility="{Binding GameRemapPopupVisibillity}" Panel.ZIndex="1" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="x" FontWeight="Bold" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,-2,5,0" FontSize="15" Panel.ZIndex="1" MouseLeftButtonUp="GameRemapPopup_Click" Cursor="Hand"/>
<TextBlock Text="x" FontWeight="Bold" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,8,0" FontSize="17" Panel.ZIndex="1" MouseLeftButtonUp="GameRemapPopup_Click" Cursor="Hand"/>
<Border Background="{StaticResource DarkBackground}" CornerRadius="10" Width="300" BorderThickness="1" BorderBrush="White" Padding="10">
<StackPanel>
<Button Content="Game re-cache" Margin="0,0,5,5" Click="Recache_Click"/>
<StackPanel Orientation="Horizontal">
<!--<TextBox Text="{Binding Path=UpdatedBoxImage,UpdateSourceTrigger=PropertyChanged}" mah:TextBoxHelper.UseFloatingWatermark="True" mah:TextBoxHelper.Watermark="Game image url" Width="220" KeyDown="SaveBoxArtImage_KeyDown"/>-->
<Button Content="Game re-cache" Margin="0,0,58,5" Click="Recache_Click"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Button Content="BOX ART IMAGE" Width="220" Click="UploadBoxArtImage_Click"/>
<Button x:Name="uiBtnSaveBoxArtImage" Content="Save" Margin="5,0,0,0" Width="48" Click="BoxArtImageSave_Click"/>
</StackPanel>

<Button Content="Save" Margin="5,0,0,0" Width="48" Click="ImagesSave_Click"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="BACKGROUND IMAGE" Width="220" Click="UploadBackgroundImage_Click"/>
<Button Content="Save" Margin="5,0,0,0" Width="48" Click="ImagesSave_Click"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<TextBox Text="{Binding RawgSearchQuery,UpdateSourceTrigger=PropertyChanged}" mah:TextBoxHelper.UseFloatingWatermark="True" mah:TextBoxHelper.Watermark="Rawg game" Width="220" KeyDown="RawgGameSearch_KeyDown"/>
<Button x:Name="uiBtnRawgGameSearch" Content="Search" Click="RawgGameSearch_Click" Margin="5,0,0,0"/>
Expand Down Expand Up @@ -77,6 +79,9 @@
<Canvas x:Name="fileSelectionPopupPP" Visibility="Collapsed" Margin="0,40,0,0" HorizontalAlignment="Right">
<local:FileSelectorUserControl ImageId="{Binding Path=UpdatedBoxImageId,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ImageUrl="{Binding Path=UpdatedBoxImageUrl,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
</Canvas>
<Canvas x:Name="fileSelectionPopupBP" Visibility="Collapsed" Margin="0,70,0,0" HorizontalAlignment="Right">
<local:FileSelectorUserControl ImageId="{Binding Path=UpdatedBackgroundImageId,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ImageUrl="{Binding Path=UpdatedBackgroundImageUrl,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
</Canvas>
</Grid>
<local:CacheImage ImageCacheType="GameBackground" Data="{Binding Game}"/>
<Grid Background="#99000000"/>
Expand Down
84 changes: 48 additions & 36 deletions gamevault/UserControls/GameViewUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Navigation;


Expand Down Expand Up @@ -174,37 +175,6 @@ private async Task RawgGameSearch()
});
uiBtnRawgGameSearch.IsEnabled = true;
}
private async void BoxArtImageSave_Click(object sender, RoutedEventArgs e)
{
await SaveBoxArtImage();
this.Focus();//Bring back focus for the escape key
}
private async void SaveBoxArtImage_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
await SaveBoxArtImage();
this.Focus();//Bring back focus for the escape key
}
}
private async Task SaveBoxArtImage()
{
uiBtnSaveBoxArtImage.IsEnabled = false;
await Task.Run(() =>
{
try
{
WebHelper.Put($"{SettingsViewModel.Instance.ServerUrl}/api/v1/games/{m_GameId}", "{\n" + "\"box_image_id\": \"" + ViewModel.UpdatedBoxImageId + "\"" + ",\"box_image_url\": \"" + ViewModel.UpdatedBoxImageUrl + "\"\n}");
MainWindowViewModel.Instance.AppBarText = "Successfully updated box image";
}
catch (WebException ex)
{
string msg = WebExceptionHelper.GetServerMessage(ex);
MainWindowViewModel.Instance.AppBarText = msg;
}
});
uiBtnSaveBoxArtImage.IsEnabled = true;
}
private async void RawgGameRemap_Click(object sender, RoutedEventArgs e)
{
ViewModel.GameRemapPopupVisibillity = Visibility.Collapsed;
Expand All @@ -226,15 +196,15 @@ await Task.Run(() =>
}
private void GameRemapPopup_Click(object sender, MouseButtonEventArgs e)
{
if(ViewModel.GameRemapPopupVisibillity == Visibility.Visible)
if (ViewModel.GameRemapPopupVisibillity == Visibility.Visible)
{
ViewModel.GameRemapPopupVisibillity = Visibility.Collapsed;
}
else
{
ViewModel.GameRemapPopupVisibillity = Visibility.Visible;
}

}
private bool IsEnoughDriveSpaceAvailable(string path, long gameSize)
{
Expand Down Expand Up @@ -280,9 +250,9 @@ await Task.Run(() =>
});
((Button)sender).IsEnabled = true;
}

private void UploadBoxArtImage_Click(object sender, RoutedEventArgs e)
{
{
if (fileSelectionPopupPP.Visibility == Visibility.Visible)
{
fileSelectionPopupPP.Visibility = Visibility.Collapsed;
Expand All @@ -291,6 +261,48 @@ private void UploadBoxArtImage_Click(object sender, RoutedEventArgs e)
{
fileSelectionPopupPP.Visibility = Visibility.Visible;
}
}
fileSelectionPopupBP.Visibility = Visibility.Collapsed;
}

private void UploadBackgroundImage_Click(object sender, RoutedEventArgs e)
{
if (fileSelectionPopupBP.Visibility == Visibility.Visible)
{
fileSelectionPopupBP.Visibility = Visibility.Collapsed;
}
else
{
fileSelectionPopupBP.Visibility = Visibility.Visible;
}
fileSelectionPopupPP.Visibility = Visibility.Collapsed;
}
private async void ImagesSave_Click(object sender, RoutedEventArgs e)
{
((Button)sender).IsEnabled = false;
await Task.Run(() =>
{
try
{
dynamic updateObject = new System.Dynamic.ExpandoObject();
updateObject.box_image_id = ViewModel.UpdatedBoxImageId;
updateObject.box_image_url = ViewModel.UpdatedBoxImageUrl;
updateObject.background_image_id = ViewModel.UpdatedBackgroundImageId;
updateObject.background_image_url = ViewModel.UpdatedBackgroundImageUrl;
WebHelper.Put($"{SettingsViewModel.Instance.ServerUrl}/api/v1/games/{m_GameId}", JsonSerializer.Serialize(updateObject));
MainWindowViewModel.Instance.AppBarText = "Successfully updated image";
}
catch (WebException ex)
{
string msg = WebExceptionHelper.GetServerMessage(ex);
MainWindowViewModel.Instance.AppBarText = msg;
}
catch (Exception ex)
{
MainWindowViewModel.Instance.AppBarText = ex.Message;
}
});
((Button)sender).IsEnabled = true;
this.Focus();//Bring back focus for the escape key
}
}
}
12 changes: 12 additions & 0 deletions gamevault/ViewModels/GameViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal class GameViewViewModel : ViewModelBase
private string m_RawgSearchQuery { get; set; }
private string m_UpdatedBoxImageUrl { get; set; }
private long? m_UpdatedBoxImageId { get; set; }
private string m_UpdatedBackgroundImageUrl { get; set; }
private long? m_UpdatedBackgroundImageId { get; set; }
private Visibility m_GameRemapPopupVisibillity = Visibility.Collapsed;
private bool m_IsAlreadyInstalled { get; set; }

Expand Down Expand Up @@ -58,6 +60,16 @@ public long? UpdatedBoxImageId
get { return m_UpdatedBoxImageId; }
set { m_UpdatedBoxImageId = value; OnPropertyChanged(); }
}
public string? UpdatedBackgroundImageUrl
{
get { return m_UpdatedBackgroundImageUrl; }
set { m_UpdatedBackgroundImageUrl = value; OnPropertyChanged(); }
}
public long? UpdatedBackgroundImageId
{
get { return m_UpdatedBackgroundImageId; }
set { m_UpdatedBackgroundImageId = value; OnPropertyChanged(); }
}
public Visibility GameRemapPopupVisibillity
{
get { return m_GameRemapPopupVisibillity; }
Expand Down

0 comments on commit 1e718ed

Please sign in to comment.