public MainMenu(ETalisman eTalisman) : base(eTalisman) { this.eTalisman = eTalisman; spriteBatch = eTalisman.spriteBatch; //spriteBatch = (SpriteBatch)eTalisman.Services.GetService(typeof(SpriteBatch)); choiceBackground = eTalisman.Content.Load<Texture2D>(@"gfx\menu_item_background-300x100"); optionBackground = eTalisman.Content.Load<Texture2D>(@"gfx\menu_item_background2_selected-300x100"); spriteFont = eTalisman.Content.Load<SpriteFont>(@"font\arial"); width = eTalisman.graphics.PreferredBackBufferWidth; height = eTalisman.graphics.PreferredBackBufferHeight; SubMenu root = new SubMenu(this, null, null); currentMenu = root; root.AddChild(new CloseMenu(this, "Resume")); SubMenu options = new SubMenu(this, root, "Options"); options.AddChild(new ExitETalisman(this, "exit again..", eTalisman)); root.AddChild(options); root.AddChild(new ExitETalisman(this, "Exit", eTalisman)); }
internal void SetCurrentMenu(SubMenu subMenu) { currentMenu = subMenu; selected = 0; }
public SubMenu(MainMenu menu, SubMenu parent, String label) : base(menu, label) { this.menu = menu; this.parent = parent; children = new List<Option>(); }
// ??? Does this work? It didn't for me... //protected override void LoadContent() //{ // base.LoadContent(); //} public override void Update(GameTime gameTime) { //Console.WriteLine("MainMenu.Update(...):"); // Allow closing menu. // TODO: Use gameTime to not disable if we just enabled (when using same key)? if (eTalisman.keyboardState.IsKeyDown(Keys.Escape) && !eTalisman.lastKeyboardState.IsKeyDown(Keys.Escape)) { Visible = false; Enabled = false; } if (eTalisman.keyboardState.IsKeyDown(Keys.Back) && !eTalisman.lastKeyboardState.IsKeyDown(Keys.Back) && currentMenu.GetParent() != null) currentMenu = currentMenu.GetParent(); if (currentMenu.OptionCount > 0) { if (eTalisman.keyboardState.IsKeyDown(Keys.Up) && !eTalisman.lastKeyboardState.IsKeyDown(Keys.Up)) { if (selected == 0) selected = currentMenu.OptionCount - 1; else selected--; } if (eTalisman.keyboardState.IsKeyDown(Keys.Down) && !eTalisman.lastKeyboardState.IsKeyDown(Keys.Down)) { if (selected == currentMenu.OptionCount - 1) selected = 0; else selected++; } if (eTalisman.keyboardState.IsKeyDown(Keys.Enter) && !eTalisman.lastKeyboardState.IsKeyDown(Keys.Enter)) { currentMenu.GetChildren()[selected].Action(); //switch ((Options)selected) //{ // case (Options.NEW_GAME): // Console.WriteLine("New game!"); // break; // case (Options.OPTIONS): // Console.WriteLine("Options!"); // break; // case (Options.EXIT): // Console.WriteLine("Exit!"); // eTalisman.ExitGame(); // break; // default: // break; //} } } base.Update(gameTime); }