public override void HandleInput(InputState input)
 {
     if (input.IsNewKeyPress(Keys.Enter) || input.IsNewKeyPress(Keys.Escape) || input.IsNewKeyPress(Keys.Space))
     {
         screenManager.RemoveScreen(this);
     }
 }
예제 #2
0
        // handle key presses
        public override void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.Up))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }
            if (input.IsNewKeyPress(Keys.Down))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            if (input.IsNewKeyPress(Keys.Enter))
            {
                switch (selectedEntry)
                {
                    case (int)MainMenuEntry.Singleplayer:
                        screenManager.AddScreen(new ProfileScreen(this));
                        break;
                    case (int)MainMenuEntry.Multiplayer:
                        if (ClientOptions.Instance.Username.Equals("") || ClientOptions.Instance.Username.Equals(""))
                            screenManager.AddScreen(new PopUpWarningScreen(this, GameConstants.MissingUserKeyCombo));
                        else
                            screenManager.AddScreen(new IPInputScreen(this));
                        break;
                    case (int)MainMenuEntry.Options:
                        screenManager.AddScreen(new OptionsScreen(this));
                        break;
                    case (int)MainMenuEntry.Exit:
                        screenManager.Game.Exit();
                        break;
                }
            }
        }
        public override void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.Up))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }
            if (input.IsNewKeyPress(Keys.Down))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            if (input.IsNewKeyPress(Keys.Enter))
            {
                switch (selectedEntry)
                {
                    case (int)MainGameOptionsEntry.ExitMain:
                        NetworkManager.Instance.StopSingleplayerServer();
                        screenManager.AddScreen(new MainMenuScreen());
                        this.ExitScreen();
                        ParentScreen.ExitScreen();
                        break;
                    case (int)MainGameOptionsEntry.ExitDesktop:
                        NetworkManager.Instance.StopSingleplayerServer();
                        screenManager.Game.Exit();
                        break;
                    case (int)MainGameOptionsEntry.Cancel:
                        this.ExitScreen();
                        break;
                }
            }
        }
예제 #4
0
        public override void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.Up))
            {
                if (onProfiles)
                {
                    selectedProfileEntry--;

                    if (selectedProfileEntry < 0)
                    {
                        selectedProfileEntry = -1;
                        selectedMenuEntry = menuEntries.Count - 1;
                        onProfiles = false;
                        onMenu = true;
                    }
                }
                else if (onMenu)
                {
                    selectedMenuEntry--;

                    if (selectedMenuEntry < 0)
                    {
                        if (profileEntries.Count > 0)
                        {
                            selectedMenuEntry = -1;
                            selectedProfileEntry = profileEntries.Count - 1;
                            onProfiles = true;
                            onMenu = false;
                        }
                        else
                        {
                            selectedMenuEntry = menuEntries.Count - 1;
                        }
                    }
                }
            }
            if (input.IsNewKeyPress(Keys.Down))
            {
                if (onProfiles)
                {
                    selectedProfileEntry++;

                    if (selectedProfileEntry >= profileEntries.Count)
                    {
                        selectedProfileEntry = -1;
                        selectedMenuEntry = 0;
                        onProfiles = false;
                        onMenu = true;
                    }
                }
                else if (onMenu)
                {
                    selectedMenuEntry++;

                    if (selectedMenuEntry >= menuEntries.Count)
                    {
                        if (profileEntries.Count > 0)
                        {
                            selectedMenuEntry = -1;
                            selectedProfileEntry = 0;
                            onProfiles = true;
                            onMenu = false;
                        }
                        else
                        {
                            selectedMenuEntry = 0;
                        }
                    }
                }
            }
            if (input.IsNewKeyPress(Keys.Enter))
            {
                if (onMenu)
                {
                    switch (selectedMenuEntry)
                    {
                        case (int)ProfileEntry.New:
                            if (newProfileActive)
                            {
                                // done typing (save it)
                                string newProfileName = keyboardInput.ToString();
                                if (profileFiles != null && profileFiles.Length > 0)
                                {
                                    if (doesProfileExist(newProfileName))
                                    {
                                        screenManager.AddScreen(new PopUpWarningScreen(this, GameConstants.DuplicateProfile));
                                    }
                                    else
                                    {
                                        profileFiles.Concat(new string[] { newProfileName });
                                        FileGrabber.createNewProfile(newProfileName);
                                        profileEntries.Add(new MenuEntry(newProfileName));
                                    }
                                }
                                else
                                {
                                    profileFiles = new string[] { newProfileName };
                                    FileGrabber.createNewProfile(newProfileName);
                                    profileEntries.Add(new MenuEntry(newProfileName));
                                }
                                keyboardInput.Clear();
                                newProfileActive = false;
                            }
                            else if (!newProfileActive)
                            {
                                // start taking keystrokes
                                newProfileActive = true;
                            }
                            break;
                        case (int)ProfileEntry.Cancel:
                            screenManager.RemoveScreen(this);
                            ParentScreen.currentScreenState = ScreenState.Active;
                            break;
                    }
                }
                else if (onProfiles)
                {
                    NetworkManager.Instance.SingleplayerStart();

                    // time to send off profile name and "local" keyword
                    UsernameKeywordComboPacket packet = new UsernameKeywordComboPacket();
                    packet.username = Path.GetFileNameWithoutExtension(profileFiles[selectedProfileEntry]);
                    packet.keyword = "local";
                    Thread.Sleep(1000); // <--- need this else packet kicks off before server thread is ready
                    NetworkManager.Instance.SendReliableData(packet);

                    // stupid thing so we can stay at the same handshake process as multiplayer
                    while (NetworkManager.Instance.Verified.Equals("")) {}

                    screenManager.AddScreen(new MainGameScreen(packet.username));
                    screenManager.RemoveScreen(this);
                }
            }
            if (input.IsNewKeyPress(Keys.Escape))
            {
                if (newProfileActive)
                {
                    keyboardInput.Clear();
                    newProfileActive = false;
                }
                screenManager.RemoveScreen(this);
                ParentScreen.currentScreenState = ScreenState.Active;
            }
        }
예제 #5
0
        public override void HandleInput(InputState input)
        {
            inputs.resetStates();

            if (input.IsNewKeyPress(Keys.Enter))
            {
                if (!IsTypingMessage)
                    IsTypingMessage = true;
                else if (IsTypingMessage)
                {
                    IsTypingMessage = false;
                    string chat = keyboardInput.ToString();
                    if (!chat.Equals(""))  // no empty strings in chat
                    {
                        ChatMessagePacket msgPacket = new ChatMessagePacket();
                        msgPacket.message = chat;
                        NetworkManager.Instance.SendReliableData(msgPacket);
                        keyboardInput.Clear();
                    }
                }
            }
            if (input.IsNewKeyPress(Keys.Escape))
            {
                if (IsTypingMessage)
                {
                    IsTypingMessage = false;
                    keyboardInput.Clear();
                }
                else
                {
                    screenManager.AddScreen(new MainGameOptionsScreen(this));
                }
            }
            if (!IsTypingMessage)
            {
                inputs.Up = (input.CurrentKeyboardState.IsKeyDown(Keys.Up)) ? true : false;
                inputs.Down = (input.CurrentKeyboardState.IsKeyDown(Keys.Down)) ? true : false;
                inputs.Left = (input.CurrentKeyboardState.IsKeyDown(Keys.Left)) ? true : false;
                inputs.Right = (input.CurrentKeyboardState.IsKeyDown(Keys.Right)) ? true : false;
                inputs.Space = (input.CurrentKeyboardState.IsKeyDown(Keys.Space)) ? true : false;
            }
        }
예제 #6
0
 public override void HandleInput(InputState input)
 {
     if (input.IsNewKeyPress(Keys.Enter) && keyboardInput.Length > 0 && currentConnectionStatus == ConnectionStatus.NotStarted)
     {
         // accept ip and start connect ***
         String ip = keyboardInput.ToString();
         NetworkManager.Instance.Start(ip);
         currentConnectionStatus = ConnectionStatus.Connecting;
     }
     if (input.IsNewKeyPress(Keys.Escape))
     {
         if (currentConnectionStatus != ConnectionStatus.NotStarted)
         {
             // didn't find, just clear message
             if (currentConnectionStatus == ConnectionStatus.NotFound || currentConnectionStatus == ConnectionStatus.Stopped)
             {
                 currentConnectionStatus = ConnectionStatus.NotStarted;
             }
             else
             {
                 // stop trying to connect immediately if were trying
                 currentConnectionStatus = ConnectionStatus.Stopped;
             }
         }
         else if (currentConnectionStatus == ConnectionStatus.FailVerify)
         {
             currentConnectionStatus = ConnectionStatus.NotStarted;
             failmessage = "";
         }
         else
         {
             screenManager.RemoveScreen(this);
         }
     }
 }
예제 #7
0
        public override void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.Up))
            {
                if (!usernameActive && !keywordActive && !resolutionActive)
                {
                    selectedEntry--;

                    if (selectedEntry < 0)
                        selectedEntry = menuEntries.Count - 1;
                }
                else if (resolutionActive)
                {
                    resolutionSelectedEntry--;

                    if (resolutionSelectedEntry < 0)
                        resolutionSelectedEntry = resolutionEntries.Count - 1;
                }
            }
            if (input.IsNewKeyPress(Keys.Down))
            {
                if (!usernameActive && !keywordActive && !resolutionActive)
                {
                    selectedEntry++;

                    if (selectedEntry >= menuEntries.Count)
                        selectedEntry = 0;
                }
                else if (resolutionActive)
                {
                    resolutionSelectedEntry++;

                    if (resolutionSelectedEntry >= resolutionEntries.Count)
                        resolutionSelectedEntry = 0;
                }
            }
            if (input.IsNewKeyPress(Keys.Enter))
            {
                switch (selectedEntry)
                {
                    case (int)OptionsEntry.Username:
                        if (usernameActive)
                        {
                            // done typing
                            ClientOptions.Instance.setUsername(usernamekeyboardInput.ToString());
                            usernameActive = false;
                        }
                        else if (!usernameActive)
                        {
                            // start taking keystrokes
                            usernameActive = true;
                        }
                        break;
                    case (int)OptionsEntry.Keyword:
                        if (keywordActive)
                        {
                            // done typing
                            ClientOptions.Instance.setKeyword(keywordkeyboardInput.ToString());
                            keywordActive = false;
                        }
                        else if (!keywordActive)
                        {
                            // start taking keystrokes
                            keywordActive = true;
                        }
                        break;
                    case (int)OptionsEntry.Resolution:
                        if (resolutionActive)
                        {
                            Resolution res = resolutions[resolutionSelectedEntry];
                            this.screenManager.Graphics.PreferredBackBufferWidth = res.Width;
                            this.screenManager.Graphics.PreferredBackBufferHeight = res.Height;
                            ClientOptions.Instance.setResolution(res.Height, res.Width);

                            resolutionChanged = true;
                            resolutionActive = false;
                        }
                        else if (!resolutionActive)
                        {
                            resolutionActive = true;
                        }
                        break;
                    case (int)OptionsEntry.Fullscreen:
                        if (ClientOptions.Instance.Fullscreen)
                        {
                            this.screenManager.Graphics.ToggleFullScreen();
                            ClientOptions.Instance.setFullscreen(false);
                        }
                        else
                        {
                            this.screenManager.Graphics.ToggleFullScreen();
                            ClientOptions.Instance.setFullscreen(true);
                        }
                        fullscreenChanged = true;
                        break;
                    case (int)OptionsEntry.Exit:
                        ClientOptions.Instance.Save(); // save client options
                        screenManager.RemoveScreen(this);
                        ParentScreen.currentScreenState = ScreenState.Active;
                        break;
                }
            }
            if (input.IsNewKeyPress(Keys.Escape))
            {
                if (usernameActive)
                {
                    usernamekeyboardInput.Clear();
                    usernamekeyboardInput.Append(ClientOptions.Instance.Username);
                    usernameActive = false;
                }
                else if (keywordActive)
                {
                    keywordkeyboardInput.Clear();
                    keywordkeyboardInput.Append(ClientOptions.Instance.Keyword);
                    keywordActive = false;
                }
                else if (resolutionActive)
                {
                    resolutionActive = false;
                }
                else
                {
                    ClientOptions.Instance.Save();
                    screenManager.RemoveScreen(this);
                    ParentScreen.currentScreenState = ScreenState.Active;
                }
            }
        }