private Ballz() { Graphics = new GraphicsDeviceManager(this); initSettings(); Content.RootDirectory = "Content"; Graphics.IsFullScreen = GameSettings.Fullscreen.Value; Graphics.PreferredBackBufferHeight = GameSettings.ScreenResolution.Value.Height; Graphics.PreferredBackBufferWidth = GameSettings.ScreenResolution.Value.Width; Window.AllowUserResizing = true; IsFixedTimeStep = false; Camera = new Camera(); // create the Game Components var menuRendering = new MenuRenderer(this, DefaultMenu()); //var physics = new PhysicsControl(this); var input = new InputTranslator(this); Network = new Network.Network(this); Components.Add(input); //Components.Add(physics); Components.Add(Network); Components.Add(menuRendering); Components.Add(new PerformanceRenderer(this)); MainMenu = DefaultMenu(); Logic = new LogicControl(this); Services.AddService(Logic); Services.AddService(input); Services.AddService(new SoundControl(this)); //add eventhandlers to events input.Input += Logic.HandleInputMessage; //input.Input += physics.HandleMessage; input.Input += Network.HandleMessage; //Logic.Message += physics.HandleMessage; Logic.Message += Network.HandleMessage; //Logic.Message += gameRendering.HandleMessage; Logic.Message += menuRendering.HandleMessage; Network.Message += Logic.HandleNetworkMessage; }
public void SetMainMenu(Composite menu) { activeMenu.Clear(); activeMenu.Push(menu); //TODO: uncast RegisterMenuEvents(menu); state = GameState.MenuState; }
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; }
private Composite DefaultMenu() { // Music! Ballz.The().Services.GetService<SoundControl>().StartMusic(SoundControl.MenuMusic); // 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())); optionsMenu.AddItem(new SpinBox("Multisampling: ", GameSettings.MSAASamples, 1, 16)); optionsMenu.AddItem(new SpinBox("MasterVolume: ", GameSettings.MasterVolume, 0, 100)); InputBox ipb = new InputBox("PlayerName: ", true); ipb.Setting = GameSettings.PlayerName; ipb.internalValue = false; optionsMenu.AddItem(ipb); optionsMenu.AddItem (new CheckBox ("Friendly Fire: ", GameSettings.FriendlyFire, true)); 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; //might be redundant as MSAA seems only to be changed before game is created (restart required) if(GameSettings.MSAASamples.Value > 1) { Graphics.PreferMultiSampling = true; Graphics.PreparingDeviceSettings -= msaaSettingsHandler; msaaSettingsHandler = (object sender, PreparingDeviceSettingsEventArgs args) => { args.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = GameSettings.MSAASamples.Value; }; Graphics.PreparingDeviceSettings += msaaSettingsHandler; } Graphics.ApplyChanges(); }; optionsMenu.AddItem(apply); // multiplayer menu var multiplayerMenu = new Composite("Multiplayer", true); // - connect to server var networkConnectToMenu = new Composite("Connect to", true); var networkHostInput = new InputBox("Host Name: ", true); networkHostInput.Value = "localhost"; 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 += () => { var currGameSettings = new GameSettings { //TODO: Let server select game mode GameMode = SessionFactory.SessionFactory.AvailableFactories .ElementAt(0) }; Network.StartNetworkGame(currGameSettings); }; networkServerMenu.AddItem(networkServerMenuStartGame); //TODO: abort button - close server etc. // - add items multiplayerMenu.AddItem(networkConnectToMenu); multiplayerMenu.AddItem(networkServerMenu); multiplayerMenu.AddItem(new Back()); // main menu var mainMenu = new Composite("Main Menu"); var continueLabel = new Label("Continue", true); continueLabel.OnSelect += () => { Logic.ContinueGame(); }; continueLabel.Visible = false; continueLabel.Selectable = false; mainMenu.AddItem(continueLabel); var singlePlayerMenu = new Composite("Singleplayer", true); { var currGameSettings = new GameSettings(); // hard-coded game settings //TODO(MS): Make a "build team, game-settings whatsoever" menu and store it in currGameSettings { // Player 1 { var team1 = new Team { ControlledByAI = false, Name = "Germoney", Country = "Germoney", NumberOfBallz = 2 }; currGameSettings.Teams.Add(team1); } // Player 2 { var team2 = new Team { ControlledByAI = false, Name = "Murica", Country = "Murica", NumberOfBallz = 2 }; currGameSettings.Teams.Add(team2); } } // Select GameMode 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; } currGameSettings.GameMode = factory; Logic.StartGame(currGameSettings); }; singlePlayerMenu.AddItem(factoryLabel); } } mainMenu.BackgroundTexture = Logo; mainMenu.AddItem(singlePlayerMenu); mainMenu.AddItem(multiplayerMenu); mainMenu.AddItem(optionsMenu); var controlsMenu = new Composite("Controls", true); controlsMenu.AddItem(new Back()); controlsMenu.BackgroundTexture = Content.Load<Texture2D>("Textures/Controls"); mainMenu.AddItem (controlsMenu); var quit = new Label("Quit", true); quit.OnSelect += Exit; mainMenu.AddItem(quit); mainMenu.SelectNext(); return mainMenu; }