// '' <summary> // '' Handles input for the specified menu. // '' </summary> // '' <param name="menu">the identifier of the menu being processed</param> // '' <param name="level">the vertical level of the menu</param> // '' <param name="xOffset">the xoffset of the menu</param> // '' <returns>false if a clicked missed the buttons. This can be used to check prior menus.</returns> private static bool HandleMenuInput(int menu, int level, int xOffset) { if (SwinGame.KeyTyped(KeyCode.EscapeKey)) { GameController.EndCurrentState(); return(true); } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { int i; for (i = 0; (i <= (_menuStructure[menu].Length - 1)); i++) { // IsMouseOver the i'th button of the menu if (MenuController.IsMouseOverMenu(i, level, xOffset)) { MenuController.PerformMenuAction(menu, i); return(true); } } if ((level > 0)) { // none clicked - so end this sub menu GameController.EndCurrentState(); } } return(false); }
// '' <summary> // '' Draws the menu at the indicated level. // '' </summary> // '' <param name="menu">the menu to draw</param> // '' <param name="level">the level (height) of the menu</param> // '' <param name="xOffset">the offset of the menu</param> // '' <remarks> // '' The menu text comes from the _menuStructure field. The level indicates the height // '' of the menu, to enable sub menus. The xOffset repositions the menu horizontally // '' to allow the submenus to be positioned correctly. // '' </remarks> private static void DrawButtons(int menu, int level, int xOffset) { int btnTop; Rectangle toDraw = new Rectangle(); btnTop = (MENU_TOP - ((MENU_GAP + BUTTON_HEIGHT) * level)); int i; for (i = 0; (i <= (_menuStructure[menu].Length - 1)); i++) { int btnLeft; btnLeft = (MENU_LEFT + (BUTTON_SEP * (i + xOffset))); toDraw.X = (btnLeft + TEXT_OFFSET); toDraw.Y = (btnTop + TEXT_OFFSET); toDraw.Width = BUTTON_WIDTH; toDraw.Height = BUTTON_HEIGHT; SwinGame.DrawText(_menuStructure[menu][i], MENU_COLOR, SwinGame.RGBColor(86, 111, 131), GameResources.GameFont("Menu"), FontAlignment.AlignCenter, toDraw); if ((SwinGame.MouseDown(MouseButton.LeftButton) && MenuController.IsMouseOverMenu(i, level, xOffset))) { SwinGame.DrawRectangle(HIGHLIGHT_COLOR, btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT); } } }
// '' <summary> // '' Determined if the mouse is over one of the button in the main menu. // '' </summary> // '' <param name="button">the index of the button to check</param> // '' <returns>true if the mouse is over that button</returns> private static bool IsMouseOverButton(int button) { return(MenuController.IsMouseOverMenu(button, 0, 0)); }