private static void CreateButton(MainMenuButton ent) { const int offset = 10; ent.CreateButton(new Rectangle(offset, offset, (int)ent.Size.X - 2 * offset, (int)ent.Size.Y - 2 * offset)); }
public MainMenuButton(MainMenu menu, string textureName) : base(menu) { theMenu = menu; isSelected = false; isPressed = false; prevButton = this; nextButton = this; Texture = menu.contentManager.Load <Texture2D>(textureName); OnMouseOver += () => { if (!isSelected) { menu.unSelectCurrentButton(); menu.selectButton(this); } }; OnMouseDown += () => { isPressed = true; theMenu.buttonPressed = true; }; OnMouseOut += () => { if (isPressed) { isPressed = false; menu.selectButton(this); theMenu.buttonPressed = false; } }; }
internal void selectButton(MainMenuButton button) { if (!buttonPressed) { button.isSelected = true; currentButton = button; } }
public MainMenu(Controller cntl) : base(cntl) { Sound.StopAll(); Sound.PlayCue("music_title"); Controller.IsMouseVisible = true; menuBackground = new MainMenuButton(this, "main-menu"); menuBackground.Registration = menuBackground.Size / 2; menuBackground.PositionPercent = new Vector2(0.5f, 0.5f); menuBackground.Zindex = 0.6f; AddChild(menuBackground); Fader = new FaderOuter(this); Fader.resetOpaque(); Fader.fadeIn(1.0f); //The buttons: playButton = new MainMenuButton(this, "buttons\\introButton1"); instructionButton = new MainMenuButton(this, "buttons\\introButton2"); creditsButton = new MainMenuButton(this, "buttons\\introButton3"); quitButton = new MainMenuButton(this, "buttons\\introButton4"); playButton.nextButton = instructionButton; instructionButton.nextButton = creditsButton; creditsButton.nextButton = quitButton; quitButton.nextButton = playButton; float distanceBetweenButtons = 0.12f; float prevButton = 0.4f; float xPercentage = 0.52f; playButton.PositionPercent = new Vector2(xPercentage, prevButton); playButton.Registration = playButton.Size / 2; CreateButton(playButton); playButton.Zindex = 0.4f; playButton.OnActivate += () => { onPressPlay(); }; AddChild(playButton); prevButton += distanceBetweenButtons; instructionButton.PositionPercent = new Vector2(xPercentage, prevButton); instructionButton.Registration = instructionButton.Size / 2; CreateButton(instructionButton); instructionButton.Zindex = 0.5f; instructionButton.OnActivate += () => { onPressInstructions(); }; AddChild(instructionButton); prevButton += distanceBetweenButtons; creditsButton.PositionPercent = new Vector2(xPercentage, prevButton); creditsButton.Registration = creditsButton.Size / 2; CreateButton(creditsButton); creditsButton.Zindex = 0.55f; creditsButton.OnActivate += () => { onPressCredits(); }; AddChild(creditsButton); prevButton += distanceBetweenButtons; quitButton.PositionPercent = new Vector2(xPercentage, prevButton); quitButton.Registration = quitButton.Size / 2; CreateButton(quitButton); quitButton.Zindex = 0.56f; quitButton.OnActivate += () => { onPressQuit(); }; AddChild(quitButton); selectButton(playButton); }