//List<Sprite> _menuElements; public PauseMenu(TheGame game) { _background = new Sprite(this, "pause", new Vector2(0, 0), new Vector2(300, 400)); _resume = new Button("button", "Resume", Color.Cyan, new Vector2(0, 0), new Vector2(150, 40), this); _controls = new Button("button", "Controls", Color.Orange, new Vector2(0, 0), new Vector2(150, 40), this); _restart = new Button("button", "Restart", Color.Lime, new Vector2(0, 0), new Vector2(150, 40), this); _mainMenu = new Button("button", "Main Menu", Color.Yellow, new Vector2(0, 0), new Vector2(150, 40), this); _quit = new Button("button","Quit",Color.Red, new Vector2(0, 0), new Vector2(150, 40), this); MenuElements = new List<Sprite>(); MenuElements.Add(_background); MenuElements.Add(_resume); MenuElements.Add(_restart); MenuElements.Add(_mainMenu); MenuElements.Add(_controls); MenuElements.Add(_quit); _background.Color = Color.White; _resume.AddOnClickListener(Resume); _controls.AddOnClickListener(Menu.MainMenu.goToChildMenu, "mainControls"); _quit.AddOnClickListener(game.Exit); _restart.AddOnClickListener(game.LoadLevel); _mainMenu.AddOnClickListener(OpenMainMenu); Id = "pause"; InputManager.AddKeyboardCallback(Keys.Escape, Pause, InputManager.InputState.OnInputDown, null, true); InputManager.AddKeyboardCallback(Keys.Escape, Resume, InputManager.InputState.OnInputDown, this, true); Active = true; for (int i = 0; i < MenuElements.Count; i++) MenuElements[i].LayerDepth = 0.29f - i / 100; }
public void Add(Button child, Button.FunctionCall function) { if (child != null && _children != null) { child.AddOnClickListener(function); _children.Add(child); } }
private void createMenus() { TextureManager.LoadTexture("bgMainMenu"); TextureManager.LoadTexture("bgSelectLevel"); TextureManager.LoadTexture("bgControls"); TextureManager.LoadTexture("bgMainMenuText"); TextureManager.LoadTexture("bgSelectLevelText"); TextureManager.LoadTexture("bgControlsText"); //Main menu creation Menu.MainMenu = new Menu("mainmenu"); Menu.MainMenu.Background = new Sprite(Menu.MainMenu, "bgMainMenu"); Menu.MainMenu.Text = new Sprite(Menu.MainMenu, "bgMainMenuText"); Button startButton = new Button("button", "Start Game", Color.Cyan, new Vector2(200, 300), new Vector2(230, 40), Menu.MainMenu); Button levelSelectButton = new Button("button", "Select Level", Color.Lime, new Vector2(200, 360), new Vector2(230, 40), Menu.MainMenu); Button controlsButton = new Button("button", "Controls", Color.Orange, new Vector2(200, 420), new Vector2(230, 40), Menu.MainMenu); Button exitButton = new Button("button", "Quit", Color.Red, new Vector2(200, 480), new Vector2(230, 40), Menu.MainMenu); Menu.MainMenu.MenuElements.Add(startButton); Menu.MainMenu.MenuElements.Add(levelSelectButton); Menu.MainMenu.MenuElements.Add(controlsButton); Menu.MainMenu.MenuElements.Add(exitButton); //Levelselect menu creation Menu levelSelect = new Menu("mainSelectLevel", Menu.MainMenu); levelSelect.Background = new Sprite(levelSelect, "bgSelectLevel"); levelSelect.Text = new Sprite(Menu.MainMenu, "bgSelectLevelText"); Button levelSelectBack = new Button("button", "Back", Color.Lime, new Vector2(200, 100), new Vector2(230, 40), levelSelect); levelSelect.MenuElements.Add(levelSelectBack); //Controls menu Menu controlsMenu = new Menu("mainControls", Menu.MainMenu); controlsMenu.Background = new Sprite(controlsMenu, "bgControls"); controlsMenu.Text = new Sprite(controlsMenu, "bgControlsText"); Button controlsBack = new Button("button", "Back", Color.Orange, new Vector2(200, 100), new Vector2(230, 40), controlsMenu); controlsMenu.MenuElements.Add(controlsBack); string[] filePaths = System.IO.Directory.GetFiles("../../../../levels/", "*.xml"); string tmpFilename; Vector2 buttonPos = new Vector2(-50, 300); foreach (string fn in filePaths) { if (buttonPos.X >= 750) { buttonPos.X = 200; buttonPos.Y += 80; } else { buttonPos.X += 250; } tmpFilename = System.IO.Path.GetFileNameWithoutExtension(fn); levelList.Add(tmpFilename); Button loadLevelButton = new Button("button", tmpFilename, Color.Red, buttonPos, new Vector2(230, 40), levelSelect); loadLevelButton.AddOnClickListener(LoadLevel, tmpFilename); levelSelect.MenuElements.Add(loadLevelButton); } _pauseMenu = new PauseMenu(this); //Main menu button functions if (levelList.Count > 0) { startButton.AddOnClickListener(LoadLevel, levelList[0]); } levelSelectButton.AddOnClickListener(Menu.MainMenu.goToChildMenu, levelSelect.Id); controlsButton.AddOnClickListener(Menu.MainMenu.goToChildMenu, controlsMenu.Id); exitButton.AddOnClickListener(Exit); //back to main menu buttons levelSelectBack.AddOnClickListener(levelSelect.goToParentMenu); controlsBack.AddOnClickListener(CheckPauseBackButton); Menu.loadMenu(Menu.MainMenu); InputManager.AddKeyboardCallback(Keys.Escape, Exit, InputManager.InputState.OnInputDown, Menu.MainMenu, true); InputManager.AddKeyboardCallback(Keys.Escape, levelSelect.goToParentMenu, InputManager.InputState.OnInputDown, levelSelect, true); InputManager.AddKeyboardCallback(Keys.Escape, controlsMenu.goToParentMenu, InputManager.InputState.OnInputDown, controlsMenu, true); _pauseMenu.Initialize(); levelSelect.Initialize(); controlsMenu.Initialize(); Menu.MainMenu.Initialize(); }