Skip to content

Commit

Permalink
Ability to edit game parameters before adding it
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed May 27, 2024
1 parent bcb695f commit 2a363f2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
7 changes: 3 additions & 4 deletions SightKeeper.Avalonia/Settings/Games/AddGameDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SightKeeper.Avalonia.Settings.Games"
xmlns:icons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:viewModels="clr-namespace:SightKeeper.Avalonia.ViewModels"
xmlns:root="clr-namespace:SightKeeper.Avalonia"
mc:Ignorable="d"
x:Class="SightKeeper.Avalonia.Settings.Games.AddGameDialog"
x:DataType="local:AddGameViewModel"
Expand All @@ -18,13 +16,14 @@
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid RowDefinitions="* Auto">
<Grid RowDefinitions="* 16 Auto Auto">
<ListBox Grid.Row="0"
Classes="compact"
ItemsSource="{Binding AvailableGames}"
ItemTemplate="{StaticResource GameTitleCellTemplate}"
SelectedItem="{Binding SelectedGame}"/>
<StackPanel Grid.Row="1"
<local:GameEditor Grid.Row="2" DataContext="{Binding GameToAdd}"/>
<StackPanel Grid.Row="3"
Orientation="Horizontal"
HorizontalAlignment="Right"
Spacing="8"
Expand Down
17 changes: 13 additions & 4 deletions SightKeeper.Avalonia/Settings/Games/AddGameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public AddGameViewModel(
private IReadOnlyCollection<GameViewModel> _availableGames;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
private GameViewModel? _selectedGame;
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
private GameViewModel? _gameToAdd;

[RelayCommand]
private void UpdateAvailableGames()
Expand All @@ -62,12 +63,20 @@ private GameViewModel CreateGameViewModel(Game game)
[RelayCommand(CanExecute = nameof(CanApply))]
private void Apply()
{
Guard.IsNotNull(SelectedGame);
Return(SelectedGame.Game);
Guard.IsNotNull(GameToAdd);
Return(GameToAdd.Game);
}

private bool CanApply()
{
return SelectedGame != null;
return GameToAdd != null;
}

partial void OnSelectedGameChanged(GameViewModel? value)
{
if (value == null)
GameToAdd = null;
else
GameToAdd = CreateGameViewModel(value.Game);
}
}
29 changes: 29 additions & 0 deletions SightKeeper.Avalonia/Settings/Games/GameEditor.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:SightKeeper.Avalonia.ViewModels"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SightKeeper.Avalonia.Settings.Games.GameEditor"
x:DataType="viewModels:GameViewModel">
<StackPanel Spacing="8">
<StackPanel.Resources>
<ResourceDictionary>
<system:Boolean x:Key="IsEnabledFallbackValue">False</system:Boolean>
</ResourceDictionary>
</StackPanel.Resources>
<HeaderedContentControl Header="Title">
<TextBox Text="{Binding Title}"
IsEnabled="{Binding Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue={StaticResource IsEnabledFallbackValue}}"/>
</HeaderedContentControl>
<HeaderedContentControl Header="Process name">
<TextBox Text="{Binding ProcessName}"
IsEnabled="{Binding Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue={StaticResource IsEnabledFallbackValue}}"/>
</HeaderedContentControl>
<HeaderedContentControl Header="Executable path">
<TextBox Text="{Binding ExecutablePath}"
IsEnabled="{Binding Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue={StaticResource IsEnabledFallbackValue}}"/>
</HeaderedContentControl>
</StackPanel>
</UserControl>
11 changes: 11 additions & 0 deletions SightKeeper.Avalonia/Settings/Games/GameEditor.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;

namespace SightKeeper.Avalonia.Settings.Games;

internal sealed partial class GameEditor : UserControl
{
public GameEditor()
{
InitializeComponent();
}
}

0 comments on commit 2a363f2

Please sign in to comment.