Skip to content

Commit

Permalink
Enhancement: Add some options, plus fixes when spellbook level is inv…
Browse files Browse the repository at this point in the history
…alid (drained)...
  • Loading branch information
cstamford committed Sep 26, 2021
1 parent f1ebaf3 commit 88f7cc6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
28 changes: 16 additions & 12 deletions EnhancedInventory/src/Controllers/SpellbookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void Awake()
metamagic_button.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "Show metamagic";
m_metamagic_checkbox = metamagic_button.GetComponent<ToggleWorkaround>();
m_metamagic_checkbox.onValueChanged.AddListener(delegate (bool _) { m_deferred_update = true; });
m_metamagic_checkbox.isOn = true;
m_metamagic_checkbox.isOn = Main.Settings.SpellbookShowMetamagicByDefault;

// Move the levels display (which is still used for displaying memorized spells).
// Also hide the metamagic option.
Expand Down Expand Up @@ -130,8 +130,9 @@ private void Update()
all.transform.Find("Active").gameObject.SetActive(state);
});

m_all_button.isOn = true;
m_all_button.isOn = Main.Settings.SpellbookShowAllSpellsByDefault;

Destroy(all.transform.Find("NotAccessible").gameObject);
Destroy(all.GetComponent<OwlcatMultiButton>());
Destroy(all.GetComponent<SpellbookLevelSwitcherEntityPCView>());

Expand Down Expand Up @@ -182,7 +183,7 @@ private void Update()
WidgetListMVVM widgets = transform.Find("MainContainer/KnownSpells").GetComponent<WidgetListMVVM>();
widgets.Clear();

if (m_spellbook.Value != null)
if (m_spellbook.Value != null && m_spellbook_level.Value != null)
{
SpellbookFilter filter = (SpellbookFilter)m_search_bar.Dropdown.value;
List<AbilityDataVM> spells_as_widget = new List<AbilityDataVM>();
Expand Down Expand Up @@ -250,19 +251,22 @@ private void Update()
.OrderBy(i => i.SpellLevel).ThenBy(i => i.DisplayName).ToArray(),
new List<IWidgetView> { m_known_spell_prefab });

foreach (SpellbookKnownSpellPCView spell in transform
.Find("MainContainer/KnownSpells/StandardScrollView/Viewport/Content")
.GetComponentsInChildren<SpellbookKnownSpellPCView>())
if (m_all_button.isOn)
{
// Event per slot in the prefab to change the selected option.
m_handlers.Add(spell.m_Button.OnLeftClickAsObservable().Subscribe(delegate (Unit _)
foreach (SpellbookKnownSpellPCView spell in transform
.Find("MainContainer/KnownSpells/StandardScrollView/Viewport/Content")
.GetComponentsInChildren<SpellbookKnownSpellPCView>())
{
SelectMemorisationLevel(spell.ViewModel.SpellLevel);
}));
// Event per slot in the prefab to change the selected option.
m_handlers.Add(spell.m_Button.OnLeftClickAsObservable().Subscribe(delegate (Unit _)
{
SelectMemorisationLevel(spell.ViewModel.SpellLevel);
}));
}
}

m_deferred_update = false;
}

m_deferred_update = false;
}
}

Expand Down
2 changes: 2 additions & 0 deletions EnhancedInventory/src/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public class Data : UnityModManager.ModSettings
public bool InventorySearchBarEnableCategoryButtons = false;

public bool SpellbookSearchBarFocusWhenOpening = true;
public bool SpellbookShowAllSpellsByDefault = true;
public bool SpellbookShowMetamagicByDefault = true;

public InventorySearchCriteria InventorySearchCriteria = InventorySearchCriteria.Default;
public SpellbookSearchCriteria SpellbookSearchCriteria = SpellbookSearchCriteria.Default;
Expand Down
10 changes: 9 additions & 1 deletion EnhancedInventory/src/Settings/SettingsGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ private static void DrawSpellbookSearchBarOptions()
if (!draw_search_bar) return;

GUILayout.BeginHorizontal();
Main.Settings.SpellbookSearchBarFocusWhenOpening = GUILayout.Toggle(Main.Settings.SpellbookSearchBarFocusWhenOpening, " Give the search bar focus when opening the spelbook screen");
Main.Settings.SpellbookSearchBarFocusWhenOpening = GUILayout.Toggle(Main.Settings.SpellbookSearchBarFocusWhenOpening, " Give the search bar focus when opening the spellbook screen");
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
Main.Settings.SpellbookShowAllSpellsByDefault = GUILayout.Toggle(Main.Settings.SpellbookShowAllSpellsByDefault, " Show all spells by default");
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
Main.Settings.SpellbookShowMetamagicByDefault = GUILayout.Toggle(Main.Settings.SpellbookShowMetamagicByDefault, " Show metamagic by default");
GUILayout.EndHorizontal();

GUILayout.Space(4);
Expand Down

0 comments on commit 88f7cc6

Please sign in to comment.