public void TraverseMenu() { //if I am in a submenu, no matter how many levels deep, clicking on the menu button //acts as a "Back" button and goes to the menu one level up if (menuPath.Count > 0) { crMenu lastMenu = menuPath[menuPath.Count - 1]; menuPath.RemoveAt(menuPath.Count - 1); ShowMenu(lastMenu.MenuName, false); } else //if there is no menu currently active, show the first one in the list. { if (activeMenu != null) { ShowMenu("", false); } else if (Menus != null) { if (Menus.Length > 0) { ShowMenu(Menus[0].MenuName, true); } } } }
bool ShowMenu(string named, bool addToPath) { if (named != "") { //see if the menu we want to display exists for (int i = 0; i < Menus.Length; i++) { if (Menus[i].MenuName == named) { //if a menu is already active, make it fade away if (activeMenu != null) { deactivatingMenu = activeMenu; activeMenu.Deactivate(); if (addToPath) { menuPath.Add(activeMenu); } } //fade in the new menu activeMenu = Menus[i]; activeMenu.Activate(); return(true); } } } else // if menu to show is empty, deactivate all menus { menuPath.Clear(); if (activeMenu != null) { deactivatingMenu = activeMenu; activeMenu.Deactivate(); activeMenu = null; } } //if the code reached here then we can safely assume that a new menu was not loaded //the only time the return value is checked is to determine wether a menu exists //or not. so since it wasn't found, return false return(false); }