/// <summary>
 /// Event handler for when the resolution setting is toggled.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event arguments.</param>
 void ResolutionMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     currentResolution = ((MenuEntry)sender).Text;
     string[] dimensions = currentResolution.Split(resolutionDelimiters);
     int width = int.Parse(dimensions[0]), height = int.Parse(dimensions[1]);
     Form gameWindow = Form.FromHandle(((OceanMars)ScreenManager.Game).Window.Handle).FindForm();
     gameWindow.Size = new Size(width, height); // Set the window size
     if (Screen.PrimaryScreen.Bounds.Width == width) // Set the new X coordinates
     {
         gameWindow.Left = 0;
     }
     else
     {
         gameWindow.Left = (Screen.PrimaryScreen.Bounds.Width - width) / 2;
     }
     if (Screen.PrimaryScreen.Bounds.Height == height) // Set the new Y coordinates
     {
         gameWindow.Top = 0;
     }
     else
     {
         gameWindow.Top = (Screen.PrimaryScreen.Bounds.Height - height) / 2;
     }
     return;
 }
        /// <summary>
        /// Event handler for when the Play Game menu entry is selected.
        /// </summary>
        void HostGameMenuEntrySelected(object sender, PlayerInputEventArgs e)
        {
            GameServer gs = new GameServer(9999);
            GameClient gc = new GameClient();
            gc.ConnectToGame("127.0.0.1", 9999);
            ScreenManager.AddScreen(new LobbyScreen(gc.Lobby));

            return;
        }
 /// <summary>
 /// Event handler for when the user selects ok on the "are you sure
 /// you want to exit" message box.
 /// </summary>
 void ConfirmExitMessageBoxAccepted(object sender, PlayerInputEventArgs e)
 {
     ScreenManager.Game.Exit();
     return;
 }
 /// <summary>
 /// Event handler for when the Options menu entry is selected.
 /// </summary>
 void OptionsMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     ScreenManager.AddScreen(new OptionsMenuScreen());
     return;
 }
 /// <summary>
 /// Event handler for when the user selects ok on the "are you sure
 /// you want to quit" message box. This uses the loading screen to
 /// transition from the game back to the main menu screen.
 /// </summary>
 void ConfirmQuitMessageBoxAccepted(object sender, PlayerInputEventArgs e)
 {
     LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(),
                                                    new MainMenuScreen());
     return;
 }
 /// <summary>
 /// Resume playback when cancelling.
 /// </summary>
 /// <param name="sender">Object sender.</param>
 /// <param name="e">Event arguments.</param>
 protected override void OnCancel(object sender, PlayerInputEventArgs e)
 {
     MediaPlayer.Resume();
     base.OnCancel(sender, e);
     return;
 }
 /// <summary>
 /// Event handler for when the Quit Game menu entry is selected.
 /// </summary>
 void QuitGameMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     const string message = "Quit to main menu?";
     MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);
     confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted;
     ScreenManager.AddScreen(confirmQuitMessageBox);
     return;
 }
 /// <summary>
 /// Event handler for when the fullscreen setting is toggled.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event arguments.</param>
 void FullScreenOnMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     if (e.ToggleDirection != 0)
     {
         ((OceanMars)ScreenManager.Game).GraphicsDeviceManager.ToggleFullScreen();
         fullScreenOn += e.ToggleDirection;
         if (fullScreenOn < OnOff.Off)
         {
             fullScreenOn = OnOff.On;
         }
         else if (fullScreenOn > OnOff.On)
         {
             fullScreenOn = OnOff.Off;
         }
         resolutionMenuEntry.Enabled = fullScreenOn == OnOff.Off;
         borderlessOnMenuEntry.Enabled = fullScreenOn == OnOff.Off;
         SetMenuEntryText();
     }
     return;
 }
 /// <summary>
 /// Event handler for when the SFX volume is turned up or down.
 /// </summary>
 void SoundFXVolumeMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     if (e.ToggleDirection != 0)
     {
         soundFXVolume += e.ToggleDirection * VOLUME_DELTA;
         if (soundFXVolume > MAX_VOLUME) // Toggle the volume
         {
             soundFXVolume = MIN_VOLUME;
         }
         else if (soundFXVolume < MIN_VOLUME)
         {
             soundFXVolume = MAX_VOLUME;
         }
         SoundEffect.MasterVolume = (float)soundFXVolume / (float)MAX_VOLUME;
         SetMenuEntryText();
     }
     return;
 }
 /// <summary>
 /// Event handler for when the vsync setting is toggled.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event arguments.</param>
 void VsyncOnMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     if (e.ToggleDirection != 0)
     {
         vsyncOn += e.ToggleDirection;
         if (vsyncOn < OnOff.Off)
         {
             vsyncOn = OnOff.On;
         }
         else if (vsyncOn > OnOff.On)
         {
             vsyncOn = OnOff.Off;
         }
         ((OceanMars)ScreenManager.Game).GraphicsDeviceManager.SynchronizeWithVerticalRetrace = vsyncOn == OnOff.On;
         SetMenuEntryText();
     }
     return;
 }
        /// <summary>
        /// Event handler for when the SFX are turned on or off.
        /// </summary>
        void SoundFXOnEntrySelected(object sender, PlayerInputEventArgs e)
        {
            if (e.ToggleDirection != 0)
            {
                soundFXOn += e.ToggleDirection;
                if (soundFXOn < OnOff.Off) // Toggle the values
                {
                    soundFXOn = OnOff.On;
                }
                else if (soundFXOn > OnOff.On)
                {
                    soundFXOn = OnOff.Off;
                }

                if (soundFXOn == OnOff.On) // Potentially re-enable or disable sound
                {
                    SoundEffect.MasterVolume = (float)soundFXVolume / (float)MAX_VOLUME;
                    soundFXVolumeMenuEntry.Enabled = true;
                }
                else
                {
                    SoundEffect.MasterVolume = 0;
                    soundFXVolumeMenuEntry.Enabled = false;
                }
                SetMenuEntryText();
            }
            return;
        }
 /// <summary>
 /// Event handler for when the music volume is turned up or down.
 /// </summary>
 void MusicVolumeMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     if (e.ToggleDirection != 0)
     {
         musicVolume += e.ToggleDirection * VOLUME_DELTA;
         if (musicVolume > MAX_VOLUME)
         {
             musicVolume = MIN_VOLUME;
         }
         else if (musicVolume < MIN_VOLUME)
         {
             musicVolume = MAX_VOLUME;
         }
         MediaPlayer.Volume = (float)musicVolume / (float)MAX_VOLUME;
         SetMenuEntryText();
     }
     return;
 }
        /// <summary>
        /// Event handler for when the music is turned on or off.
        /// </summary>
        void MusicOnMenuEntrySelected(object sender, PlayerInputEventArgs e)
        {
            if (e.ToggleDirection != 0)
            {
                musicOn += e.ToggleDirection;
                if (musicOn < OnOff.Off)
                {
                    musicOn = OnOff.On;
                }
                else if (musicOn > OnOff.On)
                {
                    musicOn = OnOff.Off;
                }

                if (musicOn == OnOff.On) // Toggle the muted values and associated menus
                {
                    MediaPlayer.IsMuted = false;
                    musicVolumeMenuEntry.Enabled = true;
                }
                else
                {
                    MediaPlayer.IsMuted = true;
                    musicVolumeMenuEntry.Enabled = false;
                }

                SetMenuEntryText();
            }
            return;
        }
 /// <summary>
 /// Event handler for when the Play Game menu entry is selected.
 /// </summary>
 void MultiplayerMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     ScreenManager.AddScreen(new MultiplayerMenuScreen());
     return;
 }
 /// <summary>
 /// Event handler for when the Play Game menu entry is selected.
 /// </summary>
 void JoinGameMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     ScreenManager.AddScreen(new HostSettingsMenuScreen());
     return;
 }
Exemple #16
0
 /// <summary>
 /// Helper overload makes it easy to use OnCancel as a MenuEntry event handler.
 /// </summary>
 protected virtual void OnCancel(object sender, PlayerInputEventArgs e)
 {
     OnCancel();
     return;
 }
 /// <summary>
 /// Event handler for when the borderless setting is toggled.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event arguments.</param>
 void BorderlessOnMenuEntrySelected(object sender, PlayerInputEventArgs e)
 {
     if (e.ToggleDirection != 0)
     {
         borderlessOn += e.ToggleDirection;
         if (borderlessOn < OnOff.Off)
         {
             borderlessOn = OnOff.On;
         }
         else if (borderlessOn > OnOff.On)
         {
             borderlessOn = OnOff.Off;
         }
         if (borderlessOn == OnOff.On) // Sneakily adjust the border through the handle
         {
             Form.FromHandle(((OceanMars)ScreenManager.Game).Window.Handle).FindForm().FormBorderStyle = FormBorderStyle.None;
         }
         else
         {
             Form.FromHandle(((OceanMars)ScreenManager.Game).Window.Handle).FindForm().FormBorderStyle = FormBorderStyle.FixedSingle;
         }
         SetMenuEntryText();
     }
     return;
 }