Skip to content

Commit

Permalink
Merge pull request Jarno458#85 from TriumphantBass/feature/settings-d…
Browse files Browse the repository at this point in the history
…efaults

Add individual settings menu resets
  • Loading branch information
Jarno458 authored Jun 7, 2022
2 parents b225290 + e6a3a1d commit a7762be
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions TsRandomizer/Screens/GameSettingsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,45 +87,48 @@ void Noop()
return (GameScreen)Activator.CreateInstance(JournalMenuType, GameSave.DemoSave, gcm, (Action)Noop);
}

object CreateDefaultsMenu()
object CreateDefaultsMenu(GameSettingCategoryInfo[] menusToClear, bool isSubmenu)
{
var defaultsMenu = MenuEntry.Create("Defaults", OnDefaultsSelected).AsTimeSpinnerMenuEntry();
var defaultsMenu = MenuEntry.Create("Defaults", () => OnDefaultsSelected(menusToClear, isSubmenu)).AsTimeSpinnerMenuEntry();

defaultsMenu.AsDynamic().Description = "Restore all values to their defaults";
string menuDescription = isSubmenu ? menusToClear[0].Name : "all";
defaultsMenu.AsDynamic().Description = $"Restore {menuDescription} settings to their defaults";
defaultsMenu.AsDynamic().IsCenterAligned = false;

return defaultsMenu;
}

void OnDefaultsSelected()
void OnDefaultsSelected(GameSettingCategoryInfo[] menusToClear, bool isSubmenu)
{
if (!IsInGame)
// Clear the root menu
if (!IsInGame && !isSubmenu)
{
var defaultSettings = new SettingCollection();

GameSettingsLoader.WriteSettingsToFile(defaultSettings);

settings = defaultSettings;
settings = new SettingCollection();
}
else
{
foreach (var category in SettingCollection.Categories)
foreach (var category in menusToClear)
{
foreach (var settingsFunc in category.SettingsPerCategory)
{
var setting = settingsFunc(settings);

if(!setting.CanBeChangedInGame)
if(IsInGame && !setting.CanBeChangedInGame)
continue;

setting.SetDefault();
}
}
}

if (IsInGame)
save.SetSettings(settings);
}
else
GameSettingsLoader.WriteSettingsToFile(settings);

ResetMenu();
if (isSubmenu)
Dynamic.GoToPreviousMenuCollection();
}

void ResetMenu()
Expand All @@ -144,7 +147,7 @@ void ResetMenu()
menuEntryList.Add(submenu.AsTimeSpinnerMenuEntry());
}

menuEntryList.Add(CreateDefaultsMenu());
menuEntryList.Add(CreateDefaultsMenu(SettingCollection.Categories, false));

((object)Dynamic._primaryMenuCollection).AsDynamic()._entries = menuEntryList;
((object)Dynamic._selectedMenuCollection).AsDynamic().SetSelectedIndex(0);
Expand Down Expand Up @@ -173,8 +176,7 @@ void CreateMenuForCategory(GameSettingCategoryInfo category)
foreach (var settingFunc in category.SettingsPerCategory)
submenu.Add(CreateMenuForSetting(settingFunc(settings)).AsTimeSpinnerMenuEntry());

// Exclude submenu defaults for now, enable when they don't wipe the current view
// submenu.Add(CreateDefaultsMenu(category.Settings));
submenu.Add(CreateDefaultsMenu(new GameSettingCategoryInfo[] { category }, true));
Dynamic.ChangeMenuCollection(collection, true);

((object)Dynamic._selectedMenuCollection).AsDynamic().SetSelectedIndex(0);
Expand All @@ -189,6 +191,9 @@ object FetchCollection(string submenu)
{
// Currently using quest layout for most, other layouts may be useful for other menus
// Leaving as switch to easily add new menus as Memories, Letters, Files, Quests, Bestiary, Feats
case "Archipelago":
collection = Dynamic._bestiaryInventory;
break;
case "Sprite":
collection = Dynamic._featsInventory;
break;
Expand Down

0 comments on commit a7762be

Please sign in to comment.