public static void LoadCampaign(string selectedSave)
        {
            SaveUtil.LoadGame(selectedSave);
            ((MultiPlayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
            GameMain.NetLobbyScreen.ToggleCampaignMode(true);
            GameMain.GameSession.Map.SelectRandomLocation(true);

            DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
            DebugConsole.NewMessage(GameMain.GameSession.Map.CurrentLocation.Name + " -> " + GameMain.GameSession.Map.SelectedLocation.Name, Color.Cyan);
        }
Esempio n. 2
0
        public bool LoadPrevious(GUIButton button, object obj)
        {
            Submarine.Unload();

            SaveUtil.LoadGame(saveFile);

            GameMain.LobbyScreen.Select();

            return(true);
        }
        public static void StartCampaignSetup()
        {
            DebugConsole.NewMessage("********* CAMPAIGN SETUP *********", Color.White);
            DebugConsole.ShowQuestionPrompt("Do you want to start a new campaign? Y/N", (string arg) =>
            {
                if (arg.ToLowerInvariant() == "y" || arg.ToLowerInvariant() == "yes")
                {
                    DebugConsole.ShowQuestionPrompt("Enter a save name for the campaign:", (string saveName) =>
                    {
                        if (string.IsNullOrWhiteSpace(saveName))
                        {
                            return;
                        }

                        string savePath      = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
                        GameMain.GameSession = new GameSession(new Submarine(GameMain.NetLobbyScreen.SelectedSub.FilePath, ""), savePath,
                                                               GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign"));
                        var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                        campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
                        campaign.SetDelegates();

                        GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                        GameMain.GameSession.Map.SelectRandomLocation(true);
                        SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                        campaign.LastSaveID++;

                        DebugConsole.NewMessage("Campaign started!", Color.Cyan);
                    });
                }
                else
                {
                    string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
                    DebugConsole.NewMessage("Saved campaigns:", Color.White);
                    for (int i = 0; i < saveFiles.Length; i++)
                    {
                        DebugConsole.NewMessage("   " + i + ". " + saveFiles[i], Color.White);
                    }
                    DebugConsole.ShowQuestionPrompt("Select a save file to load (0 - " + (saveFiles.Length - 1) + "):", (string selectedSave) =>
                    {
                        int saveIndex = -1;
                        if (!int.TryParse(selectedSave, out saveIndex))
                        {
                            return;
                        }

                        SaveUtil.LoadGame(saveFiles[saveIndex]);
                        ((MultiPlayerCampaign)GameMain.GameSession.GameMode).LastSaveID++;
                        GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                        GameMain.GameSession.Map.SelectRandomLocation(true);

                        DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
                    });
                }
            });
        }
 public static void LoadCampaign(string selectedSave)
 {
     GameMain.NetLobbyScreen.ToggleCampaignMode(true);
     SaveUtil.LoadGame(selectedSave);
     if (GameMain.GameSession.GameMode is MultiPlayerCampaign mpCampaign)
     {
         mpCampaign.LastSaveID++;
     }
     else
     {
         DebugConsole.ThrowError("Unexpected game mode: " + GameMain.GameSession.GameMode);
         return;
     }
     DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
     DebugConsole.NewMessage(
         GameMain.GameSession.Map.SelectedLocation == null ?
         GameMain.GameSession.Map.CurrentLocation.Name :
         GameMain.GameSession.Map.CurrentLocation.Name + " -> " + GameMain.GameSession.Map.SelectedLocation.Name, Color.Cyan);
 }
Esempio n. 5
0
        private void LoadGame(string saveFile)
        {
            if (string.IsNullOrWhiteSpace(saveFile))
            {
                return;
            }

            try
            {
                SaveUtil.LoadGame(saveFile);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Loading save \"" + saveFile + "\" failed", e);
                return;
            }


            GameMain.LobbyScreen.Select();
        }
Esempio n. 6
0
        private bool LoadGame(GUIButton button, object obj)
        {
            string saveFile = saveList.SelectedData as string;

            if (string.IsNullOrWhiteSpace(saveFile))
            {
                return(false);
            }

            try
            {
                SaveUtil.LoadGame(saveFile);
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Loading save \"" + saveFile + "\" failed", e);
                return(false);
            }


            GameMain.LobbyScreen.Select();

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            Timing.Accumulator += gameTime.ElapsedGameTime.TotalSeconds;
            int updateIterations = (int)Math.Floor(Timing.Accumulator / Timing.Step);

            if (Timing.Accumulator > Timing.Step * 6.0)
            {
                //if the game's running too slowly then we have no choice
                //but to skip a bunch of steps
                //otherwise it snowballs and becomes unplayable
                Timing.Accumulator = Timing.Step;
            }

            CrossThread.ProcessTasks();

            PlayerInput.UpdateVariable();

            if (SoundManager != null)
            {
                if (WindowActive || !Config.MuteOnFocusLost)
                {
                    SoundManager.ListenerGain = SoundManager.CompressionDynamicRangeGain;
                }
                else
                {
                    SoundManager.ListenerGain = 0.0f;
                }
            }

            while (Timing.Accumulator >= Timing.Step)
            {
                Timing.TotalTime += Timing.Step;

                Stopwatch sw = new Stopwatch();
                sw.Start();

                fixedTime.IsRunningSlowly = gameTime.IsRunningSlowly;
                TimeSpan addTime = new TimeSpan(0, 0, 0, 0, 16);
                fixedTime.ElapsedGameTime = addTime;
                fixedTime.TotalGameTime.Add(addTime);
                base.Update(fixedTime);

                PlayerInput.Update(Timing.Step);


                if (loadingScreenOpen)
                {
                    //reset accumulator if loading
                    // -> less choppy loading screens because the screen is rendered after each update
                    // -> no pause caused by leftover time in the accumulator when starting a new shift
                    ResetFrameTime();

                    if (!TitleScreen.PlayingSplashScreen)
                    {
                        SoundPlayer.Update((float)Timing.Step);
                    }

                    if (TitleScreen.LoadState >= 100.0f && !TitleScreen.PlayingSplashScreen &&
                        (!waitForKeyHit || ((PlayerInput.GetKeyboardState.GetPressedKeys().Length > 0 || PlayerInput.PrimaryMouseButtonClicked()) && WindowActive)))
                    {
                        loadingScreenOpen = false;
                    }

#if DEBUG
                    if (TitleScreen.LoadState >= 100.0f && !TitleScreen.PlayingSplashScreen && (Config.AutomaticQuickStartEnabled || Config.AutomaticCampaignLoadEnabled) && FirstLoad && !PlayerInput.KeyDown(Keys.LeftShift))
                    {
                        loadingScreenOpen = false;
                        FirstLoad         = false;

                        if (Config.AutomaticQuickStartEnabled)
                        {
                            MainMenuScreen.QuickStart();
                        }
                        else if (Config.AutomaticCampaignLoadEnabled)
                        {
                            IEnumerable <string> saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Singleplayer);

                            if (saveFiles.Count() > 0)
                            {
                                saveFiles = saveFiles.OrderBy(file => File.GetLastWriteTime(file));
                                try
                                {
                                    SaveUtil.LoadGame(saveFiles.Last());
                                }
                                catch (Exception e)
                                {
                                    DebugConsole.ThrowError("Loading save \"" + saveFiles.Last() + "\" failed", e);
                                    return;
                                }
                            }
                        }
                    }
#endif

                    if (!hasLoaded && !CoroutineManager.IsCoroutineRunning(loadingCoroutine))
                    {
                        throw new LoadingException(loadingCoroutine.Exception);
                    }
                }
                else if (hasLoaded)
                {
                    if (ConnectLobby != 0)
                    {
                        if (Client != null)
                        {
                            Client.Disconnect();
                            Client = null;

                            GameMain.MainMenuScreen.Select();
                        }
                        Steam.SteamManager.JoinLobby(ConnectLobby, true);

                        ConnectLobby    = 0;
                        ConnectEndpoint = null;
                        ConnectName     = null;
                    }
                    else if (!string.IsNullOrWhiteSpace(ConnectEndpoint))
                    {
                        if (Client != null)
                        {
                            Client.Disconnect();
                            Client = null;

                            GameMain.MainMenuScreen.Select();
                        }
                        UInt64 serverSteamId = SteamManager.SteamIDStringToUInt64(ConnectEndpoint);
                        Client = new GameClient(Config.PlayerName,
                                                serverSteamId != 0 ? null : ConnectEndpoint,
                                                serverSteamId,
                                                string.IsNullOrWhiteSpace(ConnectName) ? ConnectEndpoint : ConnectName);
                        ConnectLobby    = 0;
                        ConnectEndpoint = null;
                        ConnectName     = null;
                    }

                    SoundPlayer.Update((float)Timing.Step);

                    if (PlayerInput.KeyHit(Keys.Escape) && WindowActive)
                    {
                        // Check if a text input is selected.
                        if (GUI.KeyboardDispatcher.Subscriber != null)
                        {
                            if (GUI.KeyboardDispatcher.Subscriber is GUITextBox textBox)
                            {
                                textBox.Deselect();
                            }
                            GUI.KeyboardDispatcher.Subscriber = null;
                        }
                        //if a verification prompt (are you sure you want to x) is open, close it
                        else if (GUIMessageBox.VisibleBox as GUIMessageBox != null &&
                                 GUIMessageBox.VisibleBox.UserData as string == "verificationprompt")
                        {
                            ((GUIMessageBox)GUIMessageBox.VisibleBox).Close();
                        }
                        else if (GUIMessageBox.VisibleBox?.UserData is RoundSummary roundSummary &&
                                 roundSummary.ContinueButton != null &&
                                 roundSummary.ContinueButton.Visible)
                        {
                            GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox);
                        }
                        else if (Tutorial.Initialized && Tutorial.ContentRunning)
                        {
                            (GameSession.GameMode as TutorialMode).Tutorial.CloseActiveContentGUI();
                        }
                        else if (GameSession.IsTabMenuOpen)
                        {
                            gameSession.ToggleTabMenu();
                        }
                        else if (GUI.PauseMenuOpen)
                        {
                            GUI.TogglePauseMenu();
                        }
                        //open the pause menu if not controlling a character OR if the character has no UIs active that can be closed with ESC
                        else if ((Character.Controlled == null || !itemHudActive())
                                 //TODO: do we need to check Inventory.SelectedSlot?
                                 && Inventory.SelectedSlot == null && CharacterHealth.OpenHealthWindow == null &&
                                 !CrewManager.IsCommandInterfaceOpen &&
                                 !(Screen.Selected is SubEditorScreen editor && !editor.WiringMode && Character.Controlled?.SelectedConstruction != null))
                        {
                            // Otherwise toggle pausing, unless another window/interface is open.
                            GUI.TogglePauseMenu();
                        }
Esempio n. 8
0
 public void LoadPrevious()
 {
     Submarine.Unload();
     SaveUtil.LoadGame(savePath);
 }
        public override void End(string endMessage = "")
        {
            isRunning = false;

            if (GameMain.Client != null)
            {
                GameMain.GameSession.EndRound("");
#if CLIENT
                GameMain.GameSession.CrewManager.EndRound();
#endif
                return;
            }

            lastUpdateID++;

            bool success =
                (GameMain.Server.ConnectedClients.Any(c => c.InGame && c.Character != null && !c.Character.IsDead) ||
                 (GameMain.Server.Character != null && !GameMain.Server.Character.IsDead)) && (!GameMain.NilMod.RoundEnded || Submarine.MainSub.AtEndPosition);

            /*if (success)
             * {
             *  if (subsToLeaveBehind == null || leavingSub == null)
             *  {
             *      DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one");
             *
             *      leavingSub = GetLeavingSub();
             *
             *      subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub);
             *  }
             * }*/

            GameMain.GameSession.EndRound("");

            //TODO: save player inventories between mp campaign rounds

            //remove all items that are in someone's inventory
            foreach (Character c in Character.CharacterList)
            {
                if (c.Inventory == null)
                {
                    continue;
                }
                //Character is inside of a submarine and still alive in some form
                if (c.Submarine != null)
                {
                    CheckSubInventory(c.Inventory.Items);
                }
                //Not on the submarine or dead, just remove everything.
                else
                {
                    foreach (Item item in c.Inventory.Items)
                    {
                        if (item != null)
                        {
                            item.Remove();
                        }
                    }
                }
            }

            //Code for removing items from the level which started in a players inventory, makes a bit of a mess though.
            for (int i = Item.ItemList.ToArray().Length - 1; i >= 0; i--)
            {
                if (Item.ItemList[i] == null)
                {
                    continue;
                }
                if (Item.ItemList[i].Submarine == null)
                {
                    continue;
                }
                if (Item.ItemList[i] != null)
                {
                    if (Item.ItemList[i].HasTag("Starter_Item") && Item.ItemList[i].ContainedItems != null)
                    {
                        CheckSubInventory(Item.ItemList[i].ContainedItems);
                        Item.ItemList[i].Remove();
                    }
                    else if (Item.ItemList[i].HasTag("Starter_Item"))
                    {
                        Item.ItemList[i].Remove();
                    }
                }
            }

#if CLIENT
            GameMain.GameSession.CrewManager.EndRound();
            if (GameSession.inGameInfo != null)
            {
                GameSession.inGameInfo.ResetGUIListData();
            }
#endif

            if (success)
            {
                GameMain.NilMod.CampaignStart = false;
                //Make the save last longer if its being successful.
                if (GameMain.NilMod.CampaignFails > 0)
                {
                    GameMain.NilMod.CampaignFails -= GameMain.NilMod.CampaignSuccessFailReduction;
                    if (GameMain.NilMod.CampaignFails < 0)
                    {
                        GameMain.NilMod.CampaignFails = 0;
                    }
                }
                bool atEndPosition = Submarine.MainSub.AtEndPosition;

                /*if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
                 * {
                 *  Submarine.MainSub = leavingSub;
                 *
                 *  GameMain.GameSession.Submarine = leavingSub;
                 *
                 *  foreach (Submarine sub in subsToLeaveBehind)
                 *  {
                 *      MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
                 *      LinkedSubmarine.CreateDummy(leavingSub, sub);
                 *  }
                 * }*/

                if (atEndPosition)
                {
                    Map.MoveToNextLocation();

                    //select a random location to make sure we've got some destination
                    //to head towards even if the host/clients don't select anything
                    map.SelectRandomLocation(true);
                }

                //Repair submarine walls
                foreach (Structure w in Structure.WallList)
                {
                    for (int i = 0; i < w.SectionCount; i++)
                    {
                        w.AddDamage(i, -100000.0f);
                    }
                }

                //Remove water, replenish oxygen, Extinguish fires
                foreach (Hull hull in Hull.hullList)
                {
                    hull.OxygenPercentage = 100.0f;
                    hull.WaterVolume      = 0f;

                    for (int i = hull.FireSources.Count - 1; i >= 0; i--)
                    {
                        hull.FireSources[i].Remove();
                    }
                }

                //Repair devices, electricals and shutdown reactors.
                foreach (Item it in Item.ItemList)
                {
                    if (it.GetComponent <Barotrauma.Items.Components.Powered>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Reactor>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Engine>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Steering>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Radar>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.MiniMap>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.Door>() != null ||
                        it.GetComponent <Barotrauma.Items.Components.RelayComponent>() != null)
                    {
                        it.Condition = it.Prefab.Health;
                    }

                    if (it.GetComponent <Barotrauma.Items.Components.Reactor>() != null)
                    {
                        //Compatability for BTE.
                        if (it.Prefab.Name == "Diesel-Electric Generator")
                        {
                            continue;
                        }
                        Barotrauma.Items.Components.Reactor reactor = it.GetComponent <Barotrauma.Items.Components.Reactor>();
                        reactor.AutoTemp    = false;
                        reactor.FissionRate = 0;
                        reactor.CoolingRate = 100;
                        reactor.Temperature = 0;
                    }

                    if (it.GetComponent <Barotrauma.Items.Components.PowerContainer>() != null)
                    {
                        var powerContainer = it.GetComponent <Barotrauma.Items.Components.PowerContainer>();
                        powerContainer.Charge = Math.Min(powerContainer.Capacity * 0.9f, powerContainer.Charge);
                    }
                }

                Money += GameMain.NilMod.CampaignSurvivalReward;

                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                lastSaveID += 1;
            }
            else
            {
                GameMain.NilMod.CampaignFails += 1;

                if (GameMain.NilMod.CampaignDefaultSaveName != "" && GameMain.Client == null)
                {
                    if (GameMain.NilMod.CampaignFails > GameMain.NilMod.CampaignMaxFails)
                    {
                        GameMain.NilMod.CampaignFails = 0;
                        CoroutineManager.StartCoroutine(ResetCampaignMode(), "ResetCampaign");

                        foreach (Client c in GameMain.Server.ConnectedClients)
                        {
                            NilMod.NilModEventChatter.SendServerMessage("Campaign Info: No more chances remain, the campaign is lost!", c);
                            NilMod.NilModEventChatter.SendServerMessage("Starting a new campaign...", c);
                        }
                        GameMain.NetworkMember.AddChatMessage("Campaign Info: No more chances remain, the campaign is lost!", ChatMessageType.Server, "", null);
                        GameMain.NetworkMember.AddChatMessage("Starting a new campaign...", ChatMessageType.Server, "", null);
                    }
                    else
                    {
                        if ((GameMain.NilMod.CampaignMaxFails - GameMain.NilMod.CampaignFails) < 3)
                        {
                            foreach (Client c in GameMain.Server.ConnectedClients)
                            {
                                NilMod.NilModEventChatter.SendServerMessage("Campaign Info: There are " + (GameMain.NilMod.CampaignMaxFails - GameMain.NilMod.CampaignFails) + " Attempts remaining on this save unless you start pulling off some success!", c);
                            }
                            GameMain.NetworkMember.AddChatMessage("Campaign: There are " + (GameMain.NilMod.CampaignMaxFails - GameMain.NilMod.CampaignFails) + " Attempts remaining on this save unless you start pulling off some success!", ChatMessageType.Server, "", null);
                        }
                        //Reload the game and such
                        SaveUtil.LoadGame(GameMain.GameSession.SavePath);
#if CLIENT
                        GameMain.NetLobbyScreen.modeList.Select(2, true);
#endif
                        GameMain.GameSession.Map.SelectRandomLocation(true);
                        LastSaveID += 1;
                    }
                }
            }

            //If its campaign start, add the starter items to the buy menu
            if (GameMain.NilMod.CampaignAutoPurchase)
            {
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);

                if (GameMain.NilMod.CampaignStart)
                {
                    AutoPurchaseNew();
                }
                //If its a round that wasn't the first, buy the mid-round items!
                else
                {
                    AutoPurchaseExisting();
                }
            }
        }
Esempio n. 10
0
        public static void StartCampaignSetup()
        {
            var setupBox = new GUIMessageBox("Campaign Setup", "", new string [0], 500, 500);

            setupBox.InnerFrame.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);

            var newCampaignContainer  = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox.InnerFrame);
            var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox.InnerFrame);

            var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

            var newCampaignButton = new GUIButton(new Rectangle(0, 0, 120, 20), "New campaign", "", setupBox.InnerFrame);

            newCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = true;
                loadCampaignContainer.Visible = false;
                return(true);
            };

            var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox.InnerFrame);

            loadCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = false;
                loadCampaignContainer.Visible = true;
                return(true);
            };

            loadCampaignContainer.Visible = false;

            campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
            {
                GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
                var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
                campaign.GenerateMap(mapSeed);
                campaign.SetDelegates();

                setupBox.Close();

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                campaign.LastSaveID++;
            };

            campaignSetupUI.LoadGame = (string fileName) =>
            {
                SaveUtil.LoadGame(fileName);
                var campaign = ((MultiplayerCampaign)GameMain.GameSession.GameMode);
                campaign.LastSaveID++;

                setupBox.Close();

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
            };

            var cancelButton = new GUIButton(new Rectangle(0, 0, 120, 30), "Cancel", Alignment.BottomLeft, "", setupBox.InnerFrame);

            cancelButton.OnClicked += (btn, obj) =>
            {
                setupBox.Close();
                int otherModeIndex = 0;
                for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
                {
                    if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiplayerCampaign)
                    {
                        continue;
                    }
                    break;
                }

                GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                return(true);
            };
        }
Esempio n. 11
0
        public static GUIComponent StartCampaignSetup()
        {
            GUIFrame background = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: "GUIBackgroundBlocker");

            GUIFrame setupBox = new GUIFrame(new RectTransform(new Vector2(0.25f, 0.45f), background.RectTransform, Anchor.Center)
            {
                MinSize = new Point(500, 500)
            });
            var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), setupBox.RectTransform, Anchor.Center))
            {
                Stretch = true
            };

            new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), paddedFrame.RectTransform, Anchor.TopCenter),
                             TextManager.Get("CampaignSetup"), font: GUI.LargeFont);

            var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.07f), paddedFrame.RectTransform)
            {
                RelativeOffset = new Vector2(0.0f, 0.1f)
            }, isHorizontal: true)
            {
                RelativeSpacing = 0.02f
            };

            var campaignContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.8f), paddedFrame.RectTransform, Anchor.BottomLeft), style: null);

            var newCampaignContainer  = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);
            var loadCampaignContainer = new GUIFrame(new RectTransform(Vector2.One, campaignContainer.RectTransform, Anchor.BottomLeft), style: null);

            var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

            var newCampaignButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.0f), buttonContainer.RectTransform),
                                                  TextManager.Get("NewCampaign"))
            {
                OnClicked = (btn, obj) =>
                {
                    newCampaignContainer.Visible  = true;
                    loadCampaignContainer.Visible = false;
                    return(true);
                }
            };

            var loadCampaignButton = new GUIButton(new RectTransform(new Vector2(0.3f, 1.00f), buttonContainer.RectTransform),
                                                   TextManager.Get("LoadCampaign"))
            {
                OnClicked = (btn, obj) =>
                {
                    newCampaignContainer.Visible  = false;
                    loadCampaignContainer.Visible = true;
                    return(true);
                }
            };

            loadCampaignContainer.Visible = false;

            campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
            {
                GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName,
                                                       GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign"));
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.GenerateMap(mapSeed);
                campaign.SetDelegates();

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                campaign.LastSaveID++;
            };

            campaignSetupUI.LoadGame = (string fileName) =>
            {
                SaveUtil.LoadGame(fileName);
                if (!(GameMain.GameSession.GameMode is MultiPlayerCampaign))
                {
                    DebugConsole.ThrowError("Failed to load the campaign. The save file appears to be for a single player campaign.");
                    return;
                }

                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.LastSaveID++;

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
            };

            var cancelButton = new GUIButton(new RectTransform(new Vector2(0.2f, 0.05f), paddedFrame.RectTransform, Anchor.BottomLeft), TextManager.Get("Cancel"))
            {
                OnClicked = (btn, obj) =>
                {
                    //find the first mode that's not multiplayer campaign and switch to that
                    background.Visible = false;
                    int otherModeIndex = 0;
                    for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.Content.CountChildren; otherModeIndex++)
                    {
                        if (GameMain.NetLobbyScreen.ModeList.Content.GetChild(otherModeIndex).UserData is MultiPlayerCampaign)
                        {
                            continue;
                        }
                        break;
                    }

                    GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                    return(true);
                }
            };

            return(background);
        }
Esempio n. 12
0
        public static GUIComponent StartCampaignSetup()
        {
            GUIFrame background = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, null);

            GUIFrame setupBox = new GUIFrame(new Rectangle(0, 0, 500, 500), null, Alignment.Center, "", background);

            setupBox.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
            new GUITextBlock(new Rectangle(0, 0, 10, 10), "Campaign Setup", "", setupBox, GUI.LargeFont);
            setupBox.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);

            var newCampaignContainer  = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);
            var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);

            var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

            var newCampaignButton = new GUIButton(new Rectangle(0, 0, 120, 20), "New campaign", "", setupBox);

            newCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = true;
                loadCampaignContainer.Visible = false;
                return(true);
            };

            var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox);

            loadCampaignButton.OnClicked += (btn, obj) =>
            {
                newCampaignContainer.Visible  = false;
                loadCampaignContainer.Visible = true;
                return(true);
            };

            loadCampaignContainer.Visible = false;

            campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
            {
                GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.GenerateMap(mapSeed);
                campaign.SetDelegates();

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
                SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                campaign.LastSaveID++;
            };

            campaignSetupUI.LoadGame = (string fileName) =>
            {
                SaveUtil.LoadGame(fileName);
                var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                campaign.LastSaveID++;

                background.Visible = false;

                GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                campaign.Map.SelectRandomLocation(true);
            };

            var cancelButton = new GUIButton(new Rectangle(0, 0, 120, 30), "Cancel", Alignment.BottomLeft, "", setupBox);

            cancelButton.OnClicked += (btn, obj) =>
            {
                background.Visible = false;
                int otherModeIndex = 0;
                for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
                {
                    if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiPlayerCampaign)
                    {
                        continue;
                    }
                    break;
                }

                GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                return(true);
            };

            return(background);
        }
        public static void StartCampaignSetup(Boolean AutoSetup = false)
        {
            if (!AutoSetup)
            {
                DebugConsole.NewMessage("********* CAMPAIGN SETUP *********", Color.White);
                DebugConsole.ShowQuestionPrompt("Do you want to start a new campaign? Y/N", (string arg) =>
                {
                    if (arg.ToLowerInvariant() == "y" || arg.ToLowerInvariant() == "yes")
                    {
                        DebugConsole.ShowQuestionPrompt("Enter a save name for the campaign:", (string saveName) =>
                        {
                            if (string.IsNullOrWhiteSpace(saveName))
                            {
                                return;
                            }

                            string savePath      = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
                            GameMain.GameSession = new GameSession(new Submarine(GameMain.NetLobbyScreen.SelectedSub.FilePath, ""), savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
                            var campaign         = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                            campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
                            campaign.SetDelegates();

                            GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                            GameMain.GameSession.Map.SelectRandomLocation(true);
                            SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                            campaign.LastSaveID++;

                            campaign.AutoPurchaseNew();

                            DebugConsole.NewMessage("Campaign started!", Color.Cyan);
                        });
                    }
                    else
                    {
                        string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
                        DebugConsole.NewMessage("Saved campaigns:", Color.White);
                        for (int i = 0; i < saveFiles.Length; i++)
                        {
                            DebugConsole.NewMessage("   " + i + ". " + saveFiles[i], Color.White);
                        }
                        DebugConsole.ShowQuestionPrompt("Select a save file to load (0 - " + (saveFiles.Length - 1) + "):", (string selectedSave) =>
                        {
                            int saveIndex = -1;
                            if (!int.TryParse(selectedSave, out saveIndex))
                            {
                                return;
                            }

                            SaveUtil.LoadGame(saveFiles[saveIndex]);
                            var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                            campaign.LastSaveID++;
                            GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                            GameMain.GameSession.Map.SelectRandomLocation(true);

                            if (GameMain.NilMod.CampaignAutoPurchase)
                            {
                                //If money is exactly the same as what we start as, assume its actually a new game that was saved and reloaded!
                                if (campaign.Money == GameMain.NilMod.CampaignInitialMoney)
                                {
                                    campaign.AutoPurchaseNew();
                                }
                            }
                            //Money is not the default amount on loading, so its likely a game in progress
                            else
                            {
                                campaign.AutoPurchaseExisting();
                            }

                            DebugConsole.NewMessage("Campaign loaded!", Color.Cyan);
                        });
                    }
                });
            }
        }
        public static GUIComponent StartCampaignSetup(Boolean AutoSetup = false)
        {
            if (!AutoSetup)
            {
                GUIFrame background = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, null);

                GUIFrame setupBox = new GUIFrame(new Rectangle(0, 0, 500, 500), null, Alignment.Center, "", background);
                setupBox.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
                new GUITextBlock(new Rectangle(0, 0, 10, 10), "Campaign Setup", "", setupBox, GUI.LargeFont);
                setupBox.Padding = new Vector4(20.0f, 80.0f, 20.0f, 20.0f);

                var newCampaignContainer  = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);
                var loadCampaignContainer = new GUIFrame(new Rectangle(0, 40, 0, 0), null, setupBox);

                var campaignSetupUI = new CampaignSetupUI(true, newCampaignContainer, loadCampaignContainer);

                var newCampaignButton = new GUIButton(new Rectangle(0, 0, 120, 20), "New campaign", "", setupBox);
                newCampaignButton.OnClicked += (btn, obj) =>
                {
                    newCampaignContainer.Visible  = true;
                    loadCampaignContainer.Visible = false;
                    return(true);
                };

                var loadCampaignButton = new GUIButton(new Rectangle(130, 0, 120, 20), "Load campaign", "", setupBox);
                loadCampaignButton.OnClicked += (btn, obj) =>
                {
                    newCampaignContainer.Visible  = false;
                    loadCampaignContainer.Visible = true;
                    return(true);
                };

                loadCampaignContainer.Visible = false;

                campaignSetupUI.StartNewGame = (Submarine sub, string saveName, string mapSeed) =>
                {
                    GameMain.GameSession = new GameSession(new Submarine(sub.FilePath, ""), saveName, GameModePreset.list.Find(g => g.Name == "Campaign"));
                    var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                    campaign.GenerateMap(mapSeed);
                    campaign.SetDelegates();

                    background.Visible = false;

                    GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                    campaign.Map.SelectRandomLocation(true);
                    SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                    campaign.LastSaveID++;

                    campaign.AutoPurchaseNew();
                };

                campaignSetupUI.LoadGame = (string fileName) =>
                {
                    SaveUtil.LoadGame(fileName);
                    var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                    campaign.LastSaveID++;

                    background.Visible = false;

                    GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                    campaign.Map.SelectRandomLocation(true);

                    if (GameMain.NilMod.CampaignAutoPurchase)
                    {
                        //If money is exactly the same as what we start as, assume its actually a new game that was saved and reloaded!
                        if (campaign.Money == GameMain.NilMod.CampaignInitialMoney)
                        {
                            campaign.AutoPurchaseNew();
                        }
                    }
                    //Money is not the default amount on loading, so its likely a game in progress
                    else
                    {
                        campaign.AutoPurchaseExisting();
                    }
                };

                var cancelButton = new GUIButton(new Rectangle(0, 0, 120, 30), "Cancel", Alignment.BottomLeft, "", setupBox);
                cancelButton.OnClicked += (btn, obj) =>
                {
                    background.Visible = false;
                    int otherModeIndex = 0;
                    for (otherModeIndex = 0; otherModeIndex < GameMain.NetLobbyScreen.ModeList.children.Count; otherModeIndex++)
                    {
                        if (GameMain.NetLobbyScreen.ModeList.children[otherModeIndex].UserData is MultiPlayerCampaign)
                        {
                            continue;
                        }
                        break;
                    }

                    GameMain.NetLobbyScreen.SelectMode(otherModeIndex);
                    return(true);
                };

                return(background);
            }
            else
            {
                string[] saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Multiplayer);
                string   Savepath  = "Data" + System.IO.Path.DirectorySeparatorChar + "Saves" + System.IO.Path.DirectorySeparatorChar + "Multiplayer" + System.IO.Path.DirectorySeparatorChar + GameMain.NilMod.CampaignDefaultSaveName + ".save";
                if (saveFiles.Contains(Savepath))
                {
                    SaveUtil.LoadGame(Savepath);
                    var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                    campaign.LastSaveID++;
                    GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                    GameMain.GameSession.Map.SelectRandomLocation(true);

                    //If money is exactly the same as what we start as, assume its actually a new game that was saved and reloaded!
                    if (campaign.Money == GameMain.NilMod.CampaignInitialMoney)
                    {
                        campaign.AutoPurchaseNew();
                    }
                    //Money is not the default amount on loading, so its likely a game in progress
                    else
                    {
                        campaign.AutoPurchaseExisting();
                    }

                    DebugConsole.NewMessage(@"Campaign save """ + GameMain.NilMod.CampaignDefaultSaveName + @""" automatically loaded!", Color.Cyan);
                    DebugConsole.NewMessage("On Submarine: " + GameMain.GameSession.Submarine.Name, Color.Cyan);
                    DebugConsole.NewMessage("Using Level Seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
                    DebugConsole.NewMessage(GameMain.NetLobbyScreen.SelectedMode.Name, Color.Cyan);
                }
                else
                {
                    string    savePath    = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, GameMain.NilMod.CampaignDefaultSaveName);
                    Submarine CampaignSub = null;

                    var subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList <Submarine>();

                    if (!GameMain.NilMod.CampaignUseRandomSubmarine)
                    {
                        if (GameMain.NilMod.DefaultSubmarine != "" && subsToShow.Count >= 0)
                        {
                            CampaignSub = subsToShow.Find(s => s.Name.ToLowerInvariant() == GameMain.NilMod.DefaultSubmarine.ToLowerInvariant());

                            if (CampaignSub == null)
                            {
                                subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus) && !s.HasTag(SubmarineTag.Shuttle)).ToList <Submarine>();
                                if (subsToShow.Count > 0)
                                {
                                    CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                                }
                                else
                                {
                                    subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList <Submarine>();
                                    if (subsToShow.Count > 0)
                                    {
                                        DebugConsole.NewMessage("Error - No default submarine found in nilmodsettings, a random submarine has been chosen", Color.Red);
                                        CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                                    }
                                    else
                                    {
                                        DebugConsole.NewMessage("Error - No saved submarines to initialize campaign with.", Color.Red);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus) && !s.HasTag(SubmarineTag.Shuttle)).ToList <Submarine>();

                        if (subsToShow.Count >= 0)
                        {
                            CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                        }
                        else
                        {
                            subsToShow = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList <Submarine>();
                            if (subsToShow.Count >= 0)
                            {
                                CampaignSub = subsToShow[Rand.Range((int)0, subsToShow.Count())];
                            }
                        }
                    }

                    if (CampaignSub != null)
                    {
                        GameMain.NilMod.CampaignFails = 0;
                        GameMain.GameSession          = new GameSession(new Submarine(CampaignSub.FilePath, ""), savePath, GameModePreset.list.Find(g => g.Name == "Campaign"));
                        var campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode);
                        campaign.GenerateMap(GameMain.NetLobbyScreen.LevelSeed);
                        campaign.SetDelegates();

                        GameMain.NetLobbyScreen.ToggleCampaignMode(true);
                        GameMain.GameSession.Map.SelectRandomLocation(true);

                        GameMain.NilMod.CampaignStart = true;

                        SaveUtil.SaveGame(GameMain.GameSession.SavePath);
                        campaign.LastSaveID++;

                        campaign.AutoPurchaseNew();



                        DebugConsole.NewMessage(@"New campaign """ + GameMain.NilMod.CampaignDefaultSaveName + @""" automatically started!", Color.Cyan);
                        DebugConsole.NewMessage("On Submarine: " + CampaignSub.Name, Color.Cyan);
                        DebugConsole.NewMessage("Using Level Seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
                    }
                    else
                    {
                        GameMain.NetLobbyScreen.ToggleCampaignMode(false);
                        GameMain.NetLobbyScreen.SelectedModeIndex = 0;
                        GameMain.NetLobbyScreen.SelectMode(0);
                        //Cancel it here
                    }
                }
                return(null);
            }
        }