Skip to content

Commit

Permalink
Update Navigator to work in prefab mode, add ShowOverlay and HideOverlay
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsarkar committed Oct 13, 2020
1 parent 377a2c8 commit 121f174
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Runtime/Navigation/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ void Start() {
VisitFirstScreen();
}

void OnDisable() {
if (canceler != null) {
canceler.Cancel();
canceler.Dispose();
}
canceler = null;
}

/// <summary>
/// Visit takes a <see cref="ScreenId"/> and transitions the menu to that scene.
/// </summary>
/// <param name="screenId"></param>
public async void Visit(ScreenId screenId) {
Violet.LogVerbose($"Visiting {screenId}");
if (!screens.ContainsKey(screenId)) {
throw new VioletException($"Tried to visit {screenId} but it doesn't exist in the current scene. You'll want to add the {screenId} prefab to this scene or to the MenuBuilder prefab. Or change the Home Screen to the screen you want.");
}
Expand Down Expand Up @@ -92,6 +101,12 @@ public async void Visit(ScreenId screenId) {
}
}

/// <summary>
/// Show another screen in addition to the current screen.
///
/// It fires <see cref="OnModalShow" /> prior to setting the screen to active
/// </summary>
/// <param name="screenId">Auto-generated id of screen to show as modal</param>
public void ShowModal(ScreenId screenId) {
// we have to call this before setting things to active because
// it causes all input listeners to unsubscribe
Expand All @@ -100,13 +115,34 @@ public void ShowModal(ScreenId screenId) {
currentModal = screenId;
}

/// <summary>
/// Hide the currently shown modal.
///
/// It fires <see cref="OnModalHide" /> after setting the modal to inactive.
/// </summary>
public void HideModal() {
if (currentModal == ScreenId.None) { return; }
if (currentModal == ScreenId.None) { Violet.LogWarning("Called HideModal but there is no current modal - check if HideModal is called twice or called before ShowModal"); return; }
screens[currentModal].gameObject.SetActive(false);
OnModalHide?.Invoke(currentModal);
currentModal = ScreenId.None;
}

/// <summary>
/// Show an overlay screen in addition to the current screen. Triggers no events.
/// </summary>
/// <param name="screenId">id of screen to set active</param>
public void ShowOverlay(ScreenId screenId) {
screens[screenId].gameObject.SetActive(true);
}

/// <summary>
/// Show an overlay screen in addition to the current screen. Triggers no events.
/// </summary>
/// <param name="screenId">id of screen to set inactive</param>
public void HideOverlay(ScreenId screenId) {
screens[screenId].gameObject.SetActive(false);
}

// Sigh.
// https://forum.unity.com/threads/ability-to-add-enum-argument-to-button-functions.270817/
/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions update.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cp -r ~/work/King_of_the_Hat/Packages/violetui .

0 comments on commit 121f174

Please sign in to comment.