Ballz.Menu.Composite.AddItem C# (CSharp) Method

AddItem() public method

public AddItem ( System.Item item, int index = -1 ) : void
item System.Item
index int
return void
        public void AddItem(Item item, int index = -1)
        {
            if (index >= 0)
                members.Insert(index, item);
            else
                members.Add(item);
        }

Usage Example

Example #1
0
        private Composite DefaultMenu()
        {
            // options menu
            var optionsMenu = new Composite ("Options", true);
            //optionsMenu.AddItem(new Label("Not Implemented", false));
            optionsMenu.AddItem (new CheckBox ("FullScreen: ", GameSettings.Fullscreen));
            optionsMenu.AddItem (new Choice<Settings.Resolution> ("Resolution: ", GameSettings.ScreenResolution, getResolutions ()));
            Label apply = new Label ("Apply", true);
            apply.OnSelect += () => {
                File.Delete ("Settings.xml");
                FileStream stream = new FileStream ("Settings.xml", FileMode.OpenOrCreate);
                storeSettings (stream);
                stream.Close ();
                Graphics.IsFullScreen = GameSettings.Fullscreen.Value;
                Graphics.PreferredBackBufferWidth = GameSettings.ScreenResolution.Value.Width;
                Graphics.PreferredBackBufferHeight = GameSettings.ScreenResolution.Value.Height;
                Graphics.ApplyChanges ();
            };
            optionsMenu.AddItem (apply);

            // multiplayer menu
            var networkMenu = new Composite ("Multiplayer", true);
            // - connect to server
            var networkConnectToMenu = new Composite ("Connect to", true);
            var networkHostInput = new InputBox ("Host Name: ", true);
            networkConnectToMenu.AddItem (networkHostInput);
            var networkConnectToLabel = new Label ("Connect", true);
            networkConnectToLabel.OnSelect += () => Network.ConnectToServer (networkHostInput.Value, 13337);
            networkConnectToMenu.AddItem (networkConnectToLabel);
            // - start server
            var networkServerMenu = new Composite("Start Server", true);

            networkServerMenu.OnSelect += () =>
            {
                Network.StartServer(13337); //TODO: port input
            };
            // network lobby
            networkServerMenu.AddItem(NetworkLobbyConnectedClients);
            var networkServerMenuStartGame = new Label ("Start Game", true);
            networkServerMenuStartGame.OnSelect += () =>
            {
                Logic.StartGame(new SessionFactory.Worms());
                Network.GameStarted();
            };
            networkServerMenu.AddItem(networkServerMenuStartGame);
            //TODO: abort button - close server etc.

            // - add items
            networkMenu.AddItem(networkConnectToMenu);
            networkMenu.AddItem(networkServerMenu);
            networkMenu.AddItem(new Back());

            // main menu
            var mainMenu = new Composite("Main Menu");

            var continueLabel = new Label("Continue", true);
            continueLabel.OnSelect += () =>
            {
                Logic.ContinueGame();
            };
            mainMenu.AddItem(continueLabel);

            Composite startGame = new Composite("Start New Game", true);
            foreach(var factory in SessionFactory.SessionFactory.AvailableFactories)
            {
                var factoryLabel = new Label(factory.Name, true);
                factoryLabel.OnSelect += () =>
                {
                    if(Match == null)
                    {
                        continueLabel.Visible = true;
                        continueLabel.Selectable = true;
                    }
                    Logic.StartGame(factory);
                };
                startGame.AddItem(factoryLabel);
            }

            mainMenu.AddItem(startGame);
            mainMenu.AddItem(optionsMenu);
            mainMenu.AddItem(networkMenu);

            mainMenu.SelectNext();
            continueLabel.Visible = false;
            continueLabel.Selectable = false;

            var quit = new Label("Quit", true);
            quit.OnSelect += Exit;
            mainMenu.AddItem(quit);

            return mainMenu;
        }
All Usage Examples Of Ballz.Menu.Composite::AddItem