Class MenuManager
- Namespace
- AshesOfVelsingrad.Managers
- Assembly
- Ashes of Velsingrad.dll
Manages menu navigation and state. Coordinates between different menus following the Manager Pattern.
[ScriptPath("res://scripts/managers/MenuManager.cs")]
public class MenuManager : BaseManager, IDisposable
- Inheritance
-
GodotObjectNodeMenuManager
- Implements
- Inherited Members
-
Node.NotificationEnterTreeNode.NotificationExitTreeNode.NotificationMovedInParentNode.NotificationReadyNode.NotificationPausedNode.NotificationUnpausedNode.NotificationPhysicsProcessNode.NotificationProcessNode.NotificationParentedNode.NotificationUnparentedNode.NotificationSceneInstantiatedNode.NotificationDragBeginNode.NotificationDragEndNode.NotificationPathRenamedNode.NotificationChildOrderChangedNode.NotificationInternalProcessNode.NotificationInternalPhysicsProcessNode.NotificationPostEnterTreeNode.NotificationDisabledNode.NotificationEnabledNode.NotificationResetPhysicsInterpolationNode.NotificationEditorPreSaveNode.NotificationEditorPostSaveNode.NotificationWMMouseEnterNode.NotificationWMMouseExitNode.NotificationWMWindowFocusInNode.NotificationWMWindowFocusOutNode.NotificationWMCloseRequestNode.NotificationWMGoBackRequestNode.NotificationWMSizeChangedNode.NotificationWMDpiChangeNode.NotificationVpMouseEnterNode.NotificationVpMouseExitNode.NotificationWMPositionChangedNode.NotificationOsMemoryWarningNode.NotificationTranslationChangedNode.NotificationWMAboutNode.NotificationCrashNode.NotificationOsImeUpdateNode.NotificationApplicationResumedNode.NotificationApplicationPausedNode.NotificationApplicationFocusInNode.NotificationApplicationFocusOutNode.NotificationTextServerChangedNode.NotificationAccessibilityUpdateNode.NotificationAccessibilityInvalidateNode.GetNode<T>(NodePath)Node.GetNodeOrNull<T>(NodePath)Node.GetOwner<T>()Node.GetOwnerOrNull<T>()Node.GetParent<T>()Node.GetParentOrNull<T>()Node._EnterTree()Node._GetAccessibilityConfigurationWarnings()Node._GetConfigurationWarnings()Node._GetFocusedAccessibilityElement()Node._Input(InputEvent)Node._ShortcutInput(InputEvent)Node._UnhandledInput(InputEvent)Node._UnhandledKeyInput(InputEvent)Node.PrintOrphanNodes()Node.GetOrphanNodeIds()Node.RemoveChild(Node)Node.HasNode(NodePath)Node.GetNode(NodePath)Node.GetNodeOrNull(NodePath)Node.GetParent()Node.HasNodeAndResource(NodePath)Node.GetNodeAndResource(NodePath)Node.IsInsideTree()Node.IsPartOfEditedScene()Node.IsAncestorOf(Node)Node.IsGreaterThan(Node)Node.GetPath()Node.RemoveFromGroup(StringName)Node.IsInGroup(StringName)Node.GetGroups()Node.PrintTree()Node.PrintTreePretty()Node.GetTreeString()Node.GetTreeStringPretty()Node.GetPhysicsProcessDeltaTime()Node.IsPhysicsProcessing()Node.GetProcessDeltaTime()Node.IsProcessing()Node.IsProcessingInput()Node.IsProcessingShortcutInput()Node.IsProcessingUnhandledInput()Node.IsProcessingUnhandledKeyInput()Node.CanProcess()Node.QueueAccessibilityUpdate()Node.GetAccessibilityElement()Node.IsDisplayedFolded()Node.IsProcessingInternal()Node.IsPhysicsProcessingInternal()Node.IsPhysicsInterpolated()Node.IsPhysicsInterpolatedAndEnabled()Node.ResetPhysicsInterpolation()Node.CanAutoTranslate()Node.SetTranslationDomainInherited()Node.GetWindow()Node.GetLastExclusiveWindow()Node.GetTree()Node.CreateTween()Node.GetSceneInstanceLoadPlaceholder()Node.IsEditableInstance(Node)Node.GetViewport()Node.QueueFree()Node.RequestReady()Node.IsNodeReady()Node.GetMultiplayerAuthority()Node.IsMultiplayerAuthority()Node.RpcConfig(StringName, Variant)Node.GetNodeRpcConfig()Node.Rpc(StringName, params Variant[])Node.UpdateConfigurationWarnings()Node.CallDeferredThreadGroup(StringName, params Variant[])Node.SetDeferredThreadGroup(StringName, Variant)Node.CallThreadSafe(StringName, params Variant[])Node.SetThreadSafe(StringName, Variant)Node.EmitSignalReady()Node.EmitSignalRenamed()Node.EmitSignalTreeEntered()Node.EmitSignalTreeExiting()Node.EmitSignalTreeExited()Node.EmitSignalChildEnteredTree(Node)Node.EmitSignalChildExitingTree(Node)Node.EmitSignalChildOrderChanged()Node.EmitSignalReplacingBy(Node)Node.EmitSignalEditorDescriptionChanged(Node)Node.EmitSignalEditorStateChanged()Node.InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)Node.HasGodotClassMethod(in godot_string_name)Node.HasGodotClassSignal(in godot_string_name)Node.NameNode.UniqueNameInOwnerNode.SceneFilePathNode.OwnerNode.MultiplayerNode.ProcessModeNode.ProcessPriorityNode.ProcessPhysicsPriorityNode.ProcessThreadGroupNode.ProcessThreadGroupOrderNode.ProcessThreadMessagesNode.PhysicsInterpolationModeNode.AutoTranslateModeNode.EditorDescriptionNode.ReadyNode.RenamedNode.TreeEnteredNode.TreeExitingNode.TreeExitedNode.ChildEnteredTreeNode.ChildExitingTreeNode.ChildOrderChangedNode.ReplacingByNode.EditorDescriptionChangedNode.EditorStateChangedGodotObject.NotificationPostinitializeGodotObject.NotificationPredeleteGodotObject.NotificationExtensionReloadedGodotObject.IsInstanceValid(GodotObject)GodotObject.WeakRef(GodotObject)GodotObject.Dispose()GodotObject.ToString()GodotObject.ToSignal(GodotObject, StringName)GodotObject._Get(StringName)GodotObject._GetPropertyList()GodotObject._IterGet(Variant)GodotObject._IterInit(Array)GodotObject._IterNext(Array)GodotObject._PropertyCanRevert(StringName)GodotObject._PropertyGetRevert(StringName)GodotObject._Set(StringName, Variant)GodotObject._ValidateProperty(Dictionary)GodotObject.Free()GodotObject.GetClass()GodotObject.Set(StringName, Variant)GodotObject.Get(StringName)GodotObject.SetIndexed(NodePath, Variant)GodotObject.GetIndexed(NodePath)GodotObject.GetPropertyList()GodotObject.GetMethodList()GodotObject.PropertyCanRevert(StringName)GodotObject.PropertyGetRevert(StringName)GodotObject.GetInstanceId()GodotObject.SetScript(Variant)GodotObject.GetScript()GodotObject.SetMeta(StringName, Variant)GodotObject.RemoveMeta(StringName)GodotObject.GetMeta(StringName, Variant)GodotObject.HasMeta(StringName)GodotObject.GetMetaList()GodotObject.HasUserSignal(StringName)GodotObject.RemoveUserSignal(StringName)GodotObject.EmitSignal(StringName, params Variant[])GodotObject.Call(StringName, params Variant[])GodotObject.CallDeferred(StringName, params Variant[])GodotObject.SetDeferred(StringName, Variant)GodotObject.Callv(StringName, Array)GodotObject.HasMethod(StringName)GodotObject.GetMethodArgumentCount(StringName)GodotObject.HasSignal(StringName)GodotObject.GetSignalList()GodotObject.GetSignalConnectionList(StringName)GodotObject.GetIncomingConnections()GodotObject.Disconnect(StringName, Callable)GodotObject.IsConnected(StringName, Callable)GodotObject.HasConnections(StringName)GodotObject.IsBlockingSignals()GodotObject.NotifyPropertyListChanged()GodotObject.CanTranslateMessages()GodotObject.Tr(StringName, StringName)GodotObject.GetTranslationDomain()GodotObject.SetTranslationDomain(StringName)GodotObject.IsQueuedForDeletion()GodotObject.CancelFree()GodotObject.EmitSignalScriptChanged()GodotObject.EmitSignalPropertyListChanged()GodotObject.NativeInstanceGodotObject.ScriptChangedGodotObject.PropertyListChanged
Remarks
This class is responsible for showing, hiding, and navigating between menus. It maintains a history of menus for back navigation and provides methods to register and unregister menus. It also emits signals when the current menu changes.
Fields
MAIN_MENU
public const string MAIN_MENU = "main_menu"
Field Value
OPTIONS_MENU
public const string OPTIONS_MENU = "options_menu"
Field Value
PAUSE_MENU
public const string PAUSE_MENU = "pause_menu"
Field Value
Properties
Instance
public static MenuManager? Instance { get; protected set; }
Property Value
Methods
ClearHistory()
Clears the menu history stack. This method removes all entries from the history stack, effectively resetting it.
public void ClearHistory()
Remarks
This method is useful when you want to reset the menu navigation state. It clears the history stack, so there are no previous menus to go back to.
EmitSignalMenuChanged(string)
protected void EmitSignalMenuChanged(string menuName)
Parameters
menuNamestring
GetCurrentMenu()
Gets the name of the current active menu.
public string? GetCurrentMenu()
Returns
- string
The name of the current menu, or null if no menu is active.
Remarks
This method returns the name of the currently active menu. If no menu is currently active, it returns null. This can be useful for checking the current state of the menu system.
GoBack()
Goes back to the previous menu in the history stack. If there is no previous menu, it prints a message indicating that.
public void GoBack()
Remarks
This method pops the last menu from the history stack and shows it. If the history stack is empty, it prints a message indicating that there is no previous menu to go back to. It does not add the previous menu back to the history stack when going back.
Initialize()
Initializes the MenuManager singleton instance. Ensures only one instance exists and sets up the initial state.
protected override void Initialize()
Remarks
This method is called automatically by Godot when the node is ready. It checks for duplicate instances and initializes the menu system. If a duplicate instance is found, it removes the duplicate.
IsMenuActive(string)
Checks if a specific menu is currently active.
public bool IsMenuActive(string menuName)
Parameters
menuNamestringThe unique name of the menu to check.
Returns
- bool
True if the specified menu is active, otherwise false.
Remarks
This method checks if the specified menu is currently the active menu. It compares the provided menu name with the current active menu name. This can be useful for UI logic that needs to know if a specific menu is currently displayed.
RegisterMenu(string, Control)
Registers a menu with the MenuManager. Adds the menu to the internal dictionary and hides it by default.
public virtual void RegisterMenu(string menuName, Control menuControl)
Parameters
menuNamestringThe unique name of the menu to register.
menuControlControlThe Control instance representing the menu.
Remarks
This method checks if the menu is already registered to avoid duplicates. If the menu is already registered, it prints an error message and does not add it again. It also connects back signals for navigation menus, such as OptionsMenu, to handle back navigation.
SetInstanceForTesting(MenuManager?)
FOR TESTING ONLY: Manually sets the singleton instance. This method should only be used in unit tests.
public static void SetInstanceForTesting(MenuManager? instance)
Parameters
instanceMenuManagerThe instance to set as the singleton.
ShowMenu(string, bool)
Shows a menu by its name. Hides the current menu and shows the specified menu.
public virtual void ShowMenu(string menuName, bool addToHistory = true)
Parameters
menuNamestringThe unique name of the menu to show.
addToHistoryboolWhether to add the current menu to the history stack for back navigation.
Remarks
This method checks if the specified menu exists in the registered menus. If it does, it hides the current menu and shows the specified menu. If the current menu is not empty, it adds it to the history stack for back navigation. If the specified menu is not found, it prints an error message.
UnregisterMenu(string)
Unregisters a menu from the MenuManager. Removes the menu from the internal dictionary.
public void UnregisterMenu(string menuName)
Parameters
menuNamestringThe unique name of the menu to unregister.
Remarks
This method checks if the menu exists before attempting to remove it. If the menu is currently active, it will hide it before removing.
Events
MenuChanged
public event MenuManager.MenuChangedEventHandler MenuChanged