Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            EllapsedTime += gameTime.ElapsedGameTime.TotalSeconds;

            if (EllapsedTime >= 10)
            {
                RemoveScreen(this);
                MultiplayerScreen Autoplay = new MultiplayerScreen();
                Autoplay.Load();
                Constants.ShowAnimation = false;
                PushScreen(Autoplay.LoadAutoplay());
            }

            if (InputHelper.InputUpPressed())
            {
                EllapsedTime = 0;

                SelectedChoice--;
                sndSelection.Play();

                if (SelectedChoice == -1)
                {
                    SelectedChoice = 4;
                }
            }
            else if (InputHelper.InputDownPressed())
            {
                EllapsedTime = 0;

                SelectedChoice++;
                sndSelection.Play();

                if (SelectedChoice == 5)
                {
                    SelectedChoice = 0;
                }
            }
            else if (InputHelper.InputConfirmPressed())
            {
                switch ((MenuChoices)SelectedChoice)
                {
                case MenuChoices.NewGame:
                    sndIntroSong.Stop();
                    sndConfirm.Play();

                    int           OldNumberOfGameScreen = ListGameScreen.Count;
                    StreamReader  BR     = new StreamReader("Content/Map path.ini");
                    DeathmatchMap NewMap = new DeathmatchMap(BR.ReadLine(), string.Empty, new Dictionary <string, List <Squad> >());
                    BR.Close();
                    NewMap.ListGameScreen = ListGameScreen;
                    NewMap.PlayerRoster   = new Roster();
                    NewMap.PlayerRoster.LoadRoster();
                    NewMap.Load();
                    NewMap.Init();
                    NewMap.TogglePreview(true);

                    //Remove any GameScreen created by the map so they don't show up immediately.
                    List <GameScreen> ListGameScreenCreatedByMap = new List <GameScreen>(ListGameScreen.Count - OldNumberOfGameScreen);
                    for (int S = ListGameScreen.Count - 1 - OldNumberOfGameScreen; S >= 0; --S)
                    {
                        ListGameScreenCreatedByMap.Add(ListGameScreen[S]);
                        ListGameScreen.RemoveAt(S);
                    }

                    RemoveAllScreens();
                    ListGameScreen.Insert(0, NewMap);
                    NewMap.Update(gameTime);

                    for (int S = 0; S < ListGameScreenCreatedByMap.Count; ++S)
                    {
                        ListGameScreen.Insert(0, ListGameScreenCreatedByMap[S]);
                        ListGameScreenCreatedByMap[S].Update(gameTime);
                    }

                    ListGameScreenCreatedByMap.Clear();
                    break;

                case MenuChoices.QuickLoad:
                    if (File.Exists("User Data/Saves/TempSave.sav"))
                    {
                        sndIntroSong.Stop();
                        sndConfirm.Play();
                        BattleMap QuickLoadMap = BattleMap.LoadTemporaryMap(ListGameScreen);
                        QuickLoadMap.TogglePreview(true);
                        ListGameScreen.Insert(0, QuickLoadMap);
                    }
                    else
                    {
                        sndDeny.Play();
                    }
                    break;

                case MenuChoices.Encyclopedia:
                    sndDeny.Play();
                    break;

                case MenuChoices.Option:
                    PushScreen(new OptionMenu());
                    sndConfirm.Play();
                    break;

                case MenuChoices.LoadGame:
                    if (File.Exists("User Data/Saves/SRWE Save.bin"))
                    {
                        sndIntroSong.Stop();
                        sndConfirm.Play();

                        Roster PlayerRoster = new Roster();
                        PlayerRoster.LoadRoster();
                        Dictionary <string, Unit> DicUnitType = Unit.LoadAllUnits();
                        Dictionary <string, BaseSkillRequirement>     DicRequirement          = BaseSkillRequirement.LoadAllRequirements();
                        Dictionary <string, BaseEffect>               DicEffect               = BaseEffect.LoadAllEffects();
                        Dictionary <string, AutomaticSkillTargetType> DicAutomaticSkillTarget = AutomaticSkillTargetType.LoadAllTargetTypes();
                        Dictionary <string, ManualSkillTarget>        DicManualSkillTarget    = ManualSkillTarget.LoadAllTargetTypes();
                        DataScreen.LoadProgression(PlayerRoster, DicUnitType, DicRequirement, DicEffect, DicAutomaticSkillTarget, DicManualSkillTarget);
                        PushScreen(new NewIntermissionScreen(PlayerRoster));
                    }
                    else
                    {
                        sndDeny.Play();
                    }
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            if (OnlinePlayers.IsHost)
            {
                OnlinePlayers.CheckForNewClient();
            }

            OnlinePlayers.Update();

            if (IsFrozen)
            {
                return;
            }

            switch (Stage)
            {
                #region None

            case MenuChoices.None:
                if (InputHelper.InputConfirmPressed())
                {
                    if (CurrentSelection == MenuChoices.StartGame && OnlinePlayers.IsHost)
                    {
                        PushScreen(NewMap);
                        NewMap.TogglePreview(false);
                        RemoveScreen(this);
                    }
                    else if (CurrentSelection == MenuChoices.JoinGame)
                    {
                        IPInputBox.Open();
                        Stage = CurrentSelection;
                    }
                    else
                    {
                        Stage = CurrentSelection;
                    }
                }
                else if (InputHelper.InputLeftPressed())
                {
                    if (CurrentSelection == MenuChoices.PlayerList)
                    {
                        CurrentSelection = MenuChoices.JoinGame;
                    }
                    else if (CurrentSelection == MenuChoices.Messenger)
                    {
                        CurrentSelection = MenuChoices.StartGame;
                    }
                    else if (CurrentSelection == MenuChoices.StartGame)
                    {
                        CurrentSelection = MenuChoices.Messenger;
                    }
                    else if (CurrentSelection == MenuChoices.ChangeMap || CurrentSelection == MenuChoices.JoinGame)
                    {
                        CurrentSelection = MenuChoices.PlayerList;
                    }
                }
                else if (InputHelper.InputRightPressed())
                {
                    if (CurrentSelection == MenuChoices.PlayerList)
                    {
                        CurrentSelection = MenuChoices.JoinGame;
                    }
                    else if (CurrentSelection == MenuChoices.Messenger)
                    {
                        CurrentSelection = MenuChoices.StartGame;
                    }
                    else if (CurrentSelection == MenuChoices.StartGame)
                    {
                        CurrentSelection = MenuChoices.Messenger;
                    }
                    else if (CurrentSelection == MenuChoices.ChangeMap || CurrentSelection == MenuChoices.JoinGame)
                    {
                        CurrentSelection = MenuChoices.PlayerList;
                    }
                }
                else if (InputHelper.InputUpPressed())
                {
                    if (CurrentSelection == MenuChoices.PlayerList)
                    {
                        CurrentSelection = MenuChoices.Messenger;
                    }
                    else if (CurrentSelection == MenuChoices.Messenger)
                    {
                        CurrentSelection = MenuChoices.PlayerList;
                    }
                    else if (CurrentSelection == MenuChoices.JoinGame)
                    {
                        CurrentSelection = MenuChoices.StartGame;
                    }
                    else if (CurrentSelection == MenuChoices.ChangeMap)
                    {
                        CurrentSelection = MenuChoices.JoinGame;
                    }
                    else if (CurrentSelection == MenuChoices.StartGame)
                    {
                        CurrentSelection = MenuChoices.ChangeMap;
                    }
                }
                else if (InputHelper.InputDownPressed())
                {
                    if (CurrentSelection == MenuChoices.PlayerList)
                    {
                        CurrentSelection = MenuChoices.Messenger;
                    }
                    else if (CurrentSelection == MenuChoices.Messenger)
                    {
                        CurrentSelection = MenuChoices.PlayerList;
                    }
                    else if (CurrentSelection == MenuChoices.JoinGame)
                    {
                        CurrentSelection = MenuChoices.ChangeMap;
                    }
                    else if (CurrentSelection == MenuChoices.ChangeMap)
                    {
                        CurrentSelection = MenuChoices.StartGame;
                    }
                    else if (CurrentSelection == MenuChoices.StartGame)
                    {
                        CurrentSelection = MenuChoices.JoinGame;
                    }
                }
                break;

                #endregion

                #region Messenger

            case MenuChoices.Messenger:
                Keys[] pressedKeys = KeyboardHelper.PlayerState.GetPressedKeys();
                //check if any of the previous update's keys are no longer pressed
                foreach (Keys key in lastPressedKeys)
                {
                    if (!pressedKeys.Contains(key))
                    {
                        switch (key)
                        {
                        case Keys.Enter:
                            OnlinePlayers­.ExecuteAndSend(new DeathmatchLobyScriptHolder.LobyMessageScript(this, Message));
                            Message     = "";
                            MessageDraw = Message;
                            UpdateMessengerCursor();
                            break;

                        case Keys.Escape:
                            Stage = MenuChoices.None;
                            break;

                        case Keys.Right:
                            if (MessageCursorIndex < Message.Length)
                            {
                                MessageCursorIndex++;
                            }
                            UpdateMessengerCursor();
                            break;

                        case Keys.Left:
                            if (MessageCursorIndex > 0)
                            {
                                MessageCursorIndex--;
                            }
                            UpdateMessengerCursor();
                            break;

                        case Keys.Space:
                            Message += " ";
                            break;

                        case Keys.Back:
                            if (MessageCursorIndex > 0)
                            {
                                Message = Message.Remove(--MessageCursorIndex, 1);
                            }
                            break;

                        case Keys.Delete:
                            if (MessageCursorIndex < Message.Length)
                            {
                                Message = Message.Remove(MessageCursorIndex, 1);
                            }
                            break;

                        default:
                            Message    += key;
                            MessageDraw = Message;
                            break;
                        }
                    }
                }
                lastPressedKeys = pressedKeys;
                break;

                #endregion

                #region Join Game

            case MenuChoices.JoinGame:
                if (IPInputBox.IsOpen)
                {
                    IPInputBox.Update(gameTime);
                }
                else
                {
                    if (OnlinePlayers.JoinHost(IPAddress.Loopback))
                    {
                        Messenger.Add("Connection Confirmed");
                    }

                    Stage = MenuChoices.None;
                }
                break;

                #endregion

                #region Change Map

            case MenuChoices.ChangeMap:
                if (InputHelper.InputConfirmPressed())
                {
                    NewMap.BattleMapPath = ListMap[CursorMap].Name;
                    MaxNumberOfPlayers   = ListMap[CursorMap].MaxNumberOfPlayers;
                    MapSizeX             = ListMap[CursorMap].MapSize.X;
                    MapSizeY             = ListMap[CursorMap].MapSize.Y;

                    if (NewMap.ListPlayer.Count > MaxNumberOfPlayers)
                    {
                        NewMap.ListPlayer.RemoveRange(MaxNumberOfPlayers, NewMap.ListPlayer.Count - MaxNumberOfPlayers);
                    }
                    else
                    {
                        while (NewMap.ListPlayer.Count < MaxNumberOfPlayers)
                        {
                            Player NewPlayer = new Player("Player " + (NewMap.ListPlayer.Count + 1), "Open", false, true, NewMap.ListPlayer.Count, Color.Blue);
                            NewPlayer.IsAlive = false;
                            NewMap.ListPlayer.Add(NewPlayer);
                        }
                    }

                    for (int P = 0; P < NewMap.ListPlayer.Count; P++)
                    {
                        NewMap.ListPlayer[P].ListSpawnPoint.Clear();
                        for (int S = 0; S < ListMap[CursorMap].ListSpawns.Count; S++)
                        {
                            if (Convert.ToInt32(ListMap[CursorMap].ListSpawns[S].Tag) == P + 1)
                            {
                                NewMap.ListPlayer[P].ListSpawnPoint.Add(ListMap[CursorMap].ListSpawns[S]);
                            }
                        }
                    }

                    Stage = MenuChoices.None;
                }
                else if (InputHelper.InputCancelPressed())
                {
                    Stage = MenuChoices.None;
                }
                else if (InputHelper.InputUpPressed())
                {
                    CursorMap--;
                    if (CursorMap < 0)
                    {
                        CursorMap = ListMap.Count - 1;
                    }
                }
                else if (InputHelper.InputDownPressed())
                {
                    CursorMap++;
                    if (CursorMap >= ListMap.Count)
                    {
                        CursorMap = 0;
                    }
                }
                break;

                #endregion

                #region Player List

            case MenuChoices.PlayerList:
                if (InputHelper.InputConfirmPressed())
                {
                    if ((OnlinePlayers.IsHost && NewMap.ListPlayer[ActivePlayerIndex].OnlinePlayerType != "Online") ||
                        (NewMap.ListPlayer[ActivePlayerIndex].IsOnline && NewMap.ListPlayer[ActivePlayerIndex].OnlinePlayerType == "Open"))
                    {
                        Stage            = MenuChoices.PlayerEdit;
                        CurrentSelection = MenuChoices.PlayerType;
                    }
                }
                else if (InputHelper.InputCancelPressed())
                {
                    Stage            = MenuChoices.None;
                    CurrentSelection = MenuChoices.PlayerList;
                }
                else if (InputHelper.InputUpPressed())
                {
                    ActivePlayerIndex--;
                    if (ActivePlayerIndex < 0)
                    {
                        ActivePlayerIndex = NewMap.ListPlayer.Count - 1;
                    }
                }
                else if (InputHelper.InputDownPressed())
                {
                    ActivePlayerIndex++;
                    if (ActivePlayerIndex >= NewMap.ListPlayer.Count)
                    {
                        ActivePlayerIndex = 0;
                    }
                }
                break;

                #endregion

                #region Player Edit

            case MenuChoices.PlayerEdit:
                if (InputHelper.InputConfirmPressed())
                {
                    Stage = CurrentSelection;
                    PlayerChoiceSubMenuIndex = 0;
                }
                else if (InputHelper.InputCancelPressed())
                {
                    Stage = MenuChoices.PlayerList;
                }
                else if (InputHelper.InputLeftPressed())
                {
                    if (CurrentSelection == MenuChoices.PlayerType)
                    {
                        CurrentSelection = MenuChoices.SquadSelection;
                    }
                    else
                    {
                        CurrentSelection--;
                    }
                }
                else if (InputHelper.InputRightPressed())
                {
                    if (CurrentSelection == MenuChoices.SquadSelection)
                    {
                        CurrentSelection = MenuChoices.PlayerType;
                    }
                    else
                    {
                        CurrentSelection++;
                    }
                }
                break;

                #endregion

                #region Player Type

            case MenuChoices.PlayerType:
                if (InputHelper.InputConfirmPressed())
                {
                    if (NewMap.ListPlayer[ActivePlayerIndex].OnlinePlayerType != ListPlayerType[PlayerChoiceSubMenuIndex])
                    {
                        NewMap.ListPlayer[ActivePlayerIndex].OnlinePlayerType = ListPlayerType[PlayerChoiceSubMenuIndex];
                        if (NewMap.ListPlayer[ActivePlayerIndex].OnlinePlayerType == "Human")
                        {
                            NewMap.ListPlayer[ActivePlayerIndex].IsPlayerControlled = true;
                        }

                        if (NewMap.ListPlayer[ActivePlayerIndex].OnlinePlayerType == "Online")
                        {
                            NewMap.ListPlayer[ActivePlayerIndex].IsOnline = true;
                        }
                        else
                        {
                            NewMap.ListPlayer[ActivePlayerIndex].IsOnline = false;
                        }

                        Stage = MenuChoices.PlayerEdit;
                    }
                }
                else if (InputHelper.InputCancelPressed())
                {
                    Stage = MenuChoices.PlayerEdit;
                }
                else if (InputHelper.InputUpPressed())
                {
                    PlayerChoiceSubMenuIndex--;
                    if (PlayerChoiceSubMenuIndex < 0)
                    {
                        PlayerChoiceSubMenuIndex = 3;
                    }
                }
                else if (InputHelper.InputDownPressed())
                {
                    PlayerChoiceSubMenuIndex++;
                    if (PlayerChoiceSubMenuIndex > 3)
                    {
                        PlayerChoiceSubMenuIndex = 0;
                    }
                }
                break;

                #endregion

                #region Squad Selection

            case MenuChoices.SquadSelection:
                if (InputHelper.InputConfirmPressed())
                {
                    Stage              = MenuChoices.UnitSelection;
                    ActiveUnitIndex    = 0;
                    ActiveUnitMinIndex = 0;
                }
                else if (InputHelper.InputCancelPressed())
                {
                    Stage = MenuChoices.PlayerEdit;
                }
                else if (InputHelper.InputUpPressed())
                {
                    ActiveSquadIndex--;
                    if (ActiveSquadIndex < 0)
                    {
                        ActiveSquadIndex = NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint.Count - 1;
                    }
                }
                else if (InputHelper.InputDownPressed())
                {
                    ActiveSquadIndex++;
                    if (ActiveSquadIndex >= NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint.Count)
                    {
                        ActiveSquadIndex = 0;
                    }
                }
                else if (InputHelper.InputLeftPressed())
                {
                    PlayerChoiceSubMenuIndex--;
                    if (PlayerChoiceSubMenuIndex < 0)
                    {
                        PlayerChoiceSubMenuIndex = 2;
                    }
                }
                else if (InputHelper.InputRightPressed())
                {
                    PlayerChoiceSubMenuIndex++;
                    if (PlayerChoiceSubMenuIndex > 2)
                    {
                        PlayerChoiceSubMenuIndex = 0;
                    }
                }
                break;

                #endregion

                #region Unit Selection

            case MenuChoices.UnitSelection:
                if (InputHelper.InputConfirmPressed())
                {
                    Stage               = MenuChoices.PilotSelection;
                    ActivePilotIndex    = 0;
                    ActivePilotMinIndex = 0;
                }
                else if (InputHelper.InputCancelPressed())
                {
                    Stage = MenuChoices.SquadSelection;
                }
                else if (InputHelper.InputUpPressed())
                {
                    ActiveUnitIndex--;
                    if (ActiveUnitIndex < 0)
                    {
                        ActiveUnitIndex    = ArrayUnit.Length - 1;
                        ActiveUnitMinIndex = Math.Max(0, ArrayUnit.Length - MaxItemToDraw);
                    }
                    else if (ActiveUnitIndex < ActiveUnitMinIndex)
                    {
                        ActiveUnitMinIndex = ActiveUnitIndex;
                    }
                }
                else if (InputHelper.InputDownPressed())
                {
                    ActiveUnitIndex++;
                    if (ActiveUnitIndex >= ArrayUnit.Length)
                    {
                        ActiveUnitIndex    = 0;
                        ActiveUnitMinIndex = 0;
                    }
                    else if (ActiveUnitIndex >= MaxItemToDraw + ActiveUnitMinIndex)
                    {
                        ActiveUnitMinIndex = ActiveUnitIndex - MaxItemToDraw + 1;
                    }
                }
                break;

                #endregion

                #region Pilot Selection

            case MenuChoices.PilotSelection:

                if (InputHelper.InputConfirmPressed())
                {
                    Stage = MenuChoices.SquadSelection;
                    if (PlayerChoiceSubMenuIndex == 0)
                    {
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].LeaderPilot    = ListPilot[ActivePilotIndex];
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].LeaderTypeName = ArrayUnit[ActiveUnitIndex].Item1;
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].LeaderName     = ArrayUnit[ActiveUnitIndex].Item2;
                    }
                    else if (PlayerChoiceSubMenuIndex == 1)
                    {
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].WingmanAPilot    = ListPilot[ActivePilotIndex];
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].WingmanATypeName = ArrayUnit[ActiveUnitIndex].Item1;
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].WingmanAName     = ArrayUnit[ActiveUnitIndex].Item2;
                    }
                    else if (PlayerChoiceSubMenuIndex == 2)
                    {
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].WingmanBPilot    = ListPilot[ActivePilotIndex];
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].WingmanBTypeName = ArrayUnit[ActiveUnitIndex].Item1;
                        NewMap.ListPlayer[ActivePlayerIndex].ListSpawnPoint[ActiveSquadIndex].WingmanBName     = ArrayUnit[ActiveUnitIndex].Item2;
                    }
                }
                else if (InputHelper.InputCancelPressed())
                {
                    Stage = MenuChoices.UnitSelection;
                }
                else if (InputHelper.InputUpPressed())
                {
                    ActivePilotIndex--;
                    if (ActivePilotIndex < 0)
                    {
                        ActivePilotIndex    = ListPilot.Count - 1;
                        ActivePilotMinIndex = Math.Max(0, ActivePilotIndex - ListPilot.Count);
                    }
                    else if (ActivePilotIndex < ActivePilotMinIndex)
                    {
                        ActivePilotMinIndex = ActivePilotIndex;
                    }
                }
                else if (InputHelper.InputDownPressed())
                {
                    ActivePilotIndex++;
                    if (ActivePilotIndex >= ListPilot.Count)
                    {
                        ActivePilotIndex    = 0;
                        ActivePilotMinIndex = 0;
                    }
                    else if (ActivePilotIndex >= MaxItemToDraw + ActivePilotMinIndex)
                    {
                        ActivePilotMinIndex = ActivePilotIndex - MaxItemToDraw + 1;
                    }
                }
                break;

                #endregion
            }

            if (KeyboardHelper.KeyPressed(Keys.Escape))
            {
                if (Stage == MenuChoices.None)
                {
                    RemoveScreen(this);
                }
                else
                {
                    Stage = MenuChoices.None;
                }
            }
        }