Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
add cheat manager
Browse files Browse the repository at this point in the history
  • Loading branch information
emmauss committed Jan 3, 2022
1 parent 25a1632 commit a4a3682
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 58 deletions.
4 changes: 3 additions & 1 deletion Ryujinx.Ava/Assets/Locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,5 +491,7 @@
"SettingsTabSystemAudioVolume": "Volume: ",
"AudioVolumeTooltip": "Change Audio Volume",
"SettingsTabSystemEnableInternetAccess": "Enable Guest Internet Access",
"EnableInternetAccessTooltip": "Enables guest Internet access. If enabled, the application will behave as if the emulated Switch console was connected to the Internet. Note that in some cases, applications may still access the Internet even with this option disabled"
"EnableInternetAccessTooltip": "Enables guest Internet access. If enabled, the application will behave as if the emulated Switch console was connected to the Internet. Note that in some cases, applications may still access the Internet even with this option disabled",
"GameListContextMenuManageCheatToolTip" : "Manage Cheats",
"GameListContextMenuManageCheat" : "Manage Cheats"
}
4 changes: 4 additions & 0 deletions Ryujinx.Ava/Ui/Controls/GameGridView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
Command="{Binding OpenDlcManager}"
Header="{locale:Locale GameListContextMenuManageDlc}"
ToolTip.Tip="{locale:Locale GameListContextMenuManageDlcToolTip}" />
<MenuItem
Command="{Binding OpenCheatManager}"
Header="{locale:Locale GameListContextMenuManageCheat}"
ToolTip.Tip="{locale:Locale GameListContextMenuManageCheatToolTip}" />
<MenuItem
Command="{Binding OpenModsDirectory}"
Header="{locale:Locale GameListContextMenuOpenModsDirectory}"
Expand Down
36 changes: 36 additions & 0 deletions Ryujinx.Ava/Ui/Models/CheatModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Ryujinx.Ava.Ui.ViewModels;
using System;

namespace Ryujinx.Ava.Ui.Models
{
public class CheatModel : BaseModel
{
private bool _isEnabled;

public event EventHandler<bool> EnableToggled;

public CheatModel(string name, string buildId, bool isEnabled)
{
Name = name;
BuildId = buildId;
IsEnabled = isEnabled;
}

public bool IsEnabled
{
get => _isEnabled; set
{
_isEnabled = value;
EnableToggled?.Invoke(this, _isEnabled);
OnPropertyChanged();
}
}

public string BuildId { get; }

public string BuildIdKey => $"{BuildId}-{Name}";
public string Name { get; }

public string CleanName => Name.Substring(1, Name.Length - 8);
}
}
51 changes: 51 additions & 0 deletions Ryujinx.Ava/Ui/Models/CheatsList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Avalonia.Collections;
using DynamicData.Binding;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;

namespace Ryujinx.Ava.Ui.Models
{
public class CheatsList : ObservableCollection<CheatModel>
{
public CheatsList(string buildId, string path)
{
BuildId = buildId;
Path = path;
this.CollectionChanged += CheatsList_CollectionChanged;
}

private void CheatsList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if(e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
(e.NewItems[0] as CheatModel).EnableToggled += Item_EnableToggled;
}
}

private void Item_EnableToggled(object sender, bool e)
{
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsEnabled)));
}

public string BuildId { get; }
public string Path { get; }

public bool IsEnabled
{
get
{
return this.ToList().TrueForAll(x => x.IsEnabled);
}
set
{
foreach (var cheat in this)
{
cheat.IsEnabled = value;
}

OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsEnabled)));
}
}
}
}
39 changes: 36 additions & 3 deletions Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Ryujinx.HLE;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.FileSystem.Content;
using Ryujinx.HLE.HOS;
using Ryujinx.Modules;
using System;
using System.Collections;
Expand Down Expand Up @@ -49,7 +50,7 @@ public class MainWindowViewModel : BaseModel
private string _fifoStatusText;
private string _gameStatusText;
private string _gpuStatusText;
private ViewMode _viewMode = Controls.ViewMode.Grid;
private ViewMode _viewMode;
private bool _isAmiiboRequested;
private bool _isGameRunning;
private bool _isLoading;
Expand Down Expand Up @@ -83,6 +84,8 @@ public MainWindowViewModel(MainWindow owner) : this()
public MainWindowViewModel()
{
Applications = new ObservableCollection<ApplicationData>();

ViewMode = ViewMode.Grid;

Applications.ToObservableChangeSet()
.Filter(Filter)
Expand All @@ -106,9 +109,9 @@ public MainWindowViewModel()
ShowUiKey = KeyGesture.Parse(ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi.ToString());
ScreenshotKey = KeyGesture.Parse(ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot.ToString());
PauseKey = KeyGesture.Parse(ConfigurationState.Instance.Hid.Hotkeys.Value.Pause.ToString());
}

Volume = ConfigurationState.Instance.System.AudioVolume;
Volume = ConfigurationState.Instance.System.AudioVolume;
}
}

public string SearchText
Expand Down Expand Up @@ -1298,6 +1301,36 @@ public async void OpenDlcManager()
}
}

public async void OpenCheatManager()
{
var selection = SelectedApplication;

if (selection != null)
{
CheatWindow cheatManager = new(_owner.VirtualFileSystem, selection.TitleId, selection.TitleName);

await cheatManager.ShowDialog(_owner);
}
}

public async void OpenCheatManagerForCurrentApp()
{
if (!IsGameRunning)
{
return;
}

var application = _owner.AppHost.Device.Application;

if (application != null)
{
CheatWindow cheatManager = new(_owner.VirtualFileSystem, application.TitleIdText, application.TitleName);

await cheatManager.ShowDialog(_owner);

_owner.AppHost.Device.EnableCheats();
}
}

public void OpenDeviceSaveDirectory()
{
Expand Down
90 changes: 90 additions & 0 deletions Ryujinx.Ava/Ui/Windows/CheatWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<Window 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:locale="clr-namespace:Ryujinx.Ava.Common.Locale"
xmlns:model="clr-namespace:Ryujinx.Ava.Ui.Models"
mc:Ignorable="d"
x:Class="Ryujinx.Ava.Ui.Windows.CheatWindow"
Width="550"
Height="640"
MinWidth="550"
MinHeight="250"
d:DesignHeight="640"
d:DesignWidth="550"
CanResize="False"
WindowStartupLocation="CenterOwner"
Title="CheatWindow">
<Window.Styles>
<Style Selector="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
</Style>
</Window.Styles>
<Grid Name="DlcGrid" Margin="15">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Margin="20,15,20,20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Heading}"
TextAlignment="Center" />
<Border
Grid.Row="1"
Margin="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="Gray"
BorderThickness="1">
<TreeView Items="{Binding LoadedCheats}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Name="CheatsView"
MinHeight="300">
<TreeView.DataTemplates>
<TreeDataTemplate DataType="model:CheatsList" ItemsSource="{Binding}">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsEnabled}" MinWidth="20" />
<TextBlock Width="150"
Text="{Binding BuildId}" />
<TextBlock
Text="{Binding Path}" />
</StackPanel>
</TreeDataTemplate>
<DataTemplate x:DataType="model:CheatModel">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<CheckBox IsChecked="{Binding IsEnabled}" MinWidth="20" />
<TextBlock Text="{Binding CleanName}" />
</StackPanel>
</DataTemplate>
</TreeView.DataTemplates>
</TreeView>
</Border>
<DockPanel
Grid.Row="2"
Margin="0"
HorizontalAlignment="Stretch">
<DockPanel Margin="0" HorizontalAlignment="Right">
<Button
Name="SaveButton"
MinWidth="90"
Margin="5"
IsVisible="{Binding !NoCheatsFound}"
Command="{Binding Save}">
<TextBlock Text="{locale:Locale SettingsButtonSave}" />
</Button>
<Button
Name="CancelButton"
MinWidth="90"
Margin="5"
Command="{Binding Close}">
<TextBlock Text="{locale:Locale InputDialogCancel}" />
</Button>
</DockPanel>
</DockPanel>
</Grid>
</Window>
Loading

0 comments on commit a4a3682

Please sign in to comment.