Skip to content

Commit

Permalink
better settings menu (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpannella authored Sep 22, 2023
1 parent 0dd06ab commit 84c3121
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pocket_updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.35.0</Version>
<Version>2.36.0</Version>
<Description>Keep your Analogue Pocket up to date</Description>
<Copyright>2023 Matt Pannella</Copyright>
<Authors>Matt Pannella</Authors>
Expand Down
59 changes: 54 additions & 5 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,8 @@ private static async Task Main(string[] args)
Pause();
break;
case 7:
RunConfigWizard();
NewSettingsMenu();
SetUpdaterFlags();
Pause();
break;
case 8:
flag = false;
Expand Down Expand Up @@ -936,16 +935,66 @@ private static int DisplayMenu()
return 0;
}

private static async Task NewSettingsMenu()
{
Console.Clear();

var menuItems = new Dictionary<string, string>(){
{"download_firmware", "Download Firmware Updates during 'Update All'"},
{"download_assets", "Download Missing Assets (ROMs and BIOS Files) during 'Update All'"},
{"build_instance_jsons", "Build game JSON files for supported cores during 'Update All'"},
{"delete_skipped_cores", "Delete untracked cores during 'Update All'"},
{"fix_jt_names", "Automatically rename Jotego cores during 'Update All"},
{"crc_check", "Use CRC check when checking ROMs and BIOS files"},
{"preserve_platforms_folder", "Preserve 'Platforms' folder during 'Update All'"},
{"skip_alternative_assets", "Skip alternative roms when downloading assets"},
{"use_custom_archive", "Use custom asset archive"}
};

var type = typeof(Config);

var menu = new ConsoleMenu()
.Configure(config =>
{
config.Selector = "=>";
config.EnableWriteTitle = false;
config.WriteHeaderAction = () => Console.WriteLine("Settings");
config.SelectedItemBackgroundColor = Console.ForegroundColor;
config.SelectedItemForegroundColor = Console.BackgroundColor;
config.WriteItemAction = item => Console.Write("{1}", item.Index, item.Name);
});

foreach(var (name, text) in menuItems) {
var property = type.GetProperty(name);
var value = (bool)property.GetValue(settings.GetConfig());
var title = settingsMenuItem(text, value);
menu.Add(title, (thisMenu) => { property.SetValue(settings.GetConfig(), !value); thisMenu.CurrentItem.Name = settingsMenuItem(text, !value);});
}

menu.Add("Save", (thisMenu) => {thisMenu.CloseMenu();});

menu.Show();

settings.SaveSettings();
}

private static string settingsMenuItem(string title, bool value)
{
var x = " ";
if (value) {
x = "X";
}

return $"[{x}] {title}";
}

private static async Task ImagePackSelector(string path)
{
Console.Clear();
Console.WriteLine("Checking for image packs...\n");
ImagePack[] packs = await ImagePacksService.GetImagePacks();
if(packs.Length > 0) {


int choice = 0;

var menu = new ConsoleMenu()
.Configure(config =>
{
Expand Down

0 comments on commit 84c3121

Please sign in to comment.