From 9b0e0ab278e90d5f3c95eeb6a9b86100b01446fa Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 11 Apr 2019 18:26:26 +0300 Subject: [PATCH] (ec990ac7c) Save chatbox & crew menu toggle state between rounds --- .../BarotraumaClient/Source/GUI/ChatBox.cs | 6 +-- .../Source/GameSession/CrewManager.cs | 4 +- .../Source/Networking/GameClient.cs | 4 +- .../Source/Networking/GameServer.cs | 13 +++---- .../Source/Characters/AI/LatchOntoAI.cs | 4 +- .../Source/Events/MonsterEvent.cs | 37 ++++++++----------- .../BarotraumaShared/Source/GameSettings.cs | 10 ++++- .../Source/Screens/GameScreen.cs | 1 + 8 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GUI/ChatBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/ChatBox.cs index 26afe00a0..490c0d21a 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/ChatBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/ChatBox.cs @@ -33,7 +33,7 @@ namespace Barotrauma set { if (_toggleOpen == value) { return; } - _toggleOpen = value; + _toggleOpen = GameMain.Config.ChatOpen = value; foreach (GUIComponent child in ToggleButton.Children) { child.SpriteEffects = _toggleOpen == (HUDLayoutSettings.ChatBoxAlignment == Alignment.Right) ? @@ -133,6 +133,8 @@ namespace Barotrauma } return true; }; + + ToggleOpen = GameMain.Config.ChatOpen; } public bool TypingChatMessage(GUITextBox textBox, string text) @@ -322,8 +324,6 @@ namespace Barotrauma prevUIScale = GUI.Scale; } - - if (ToggleOpen || (inputBox != null && inputBox.Selected)) { openState += deltaTime * 5.0f; diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs index 32eea4f1d..8f0eb0d56 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -56,7 +56,7 @@ namespace Barotrauma set { if (toggleCrewAreaOpen == value) { return; } - toggleCrewAreaOpen = value; + toggleCrewAreaOpen = GameMain.Config.CrewMenuOpen = value; foreach (GUIComponent child in toggleCrewButton.Children) { child.SpriteEffects = toggleCrewAreaOpen ? SpriteEffects.None : SpriteEffects.FlipHorizontally; @@ -215,6 +215,8 @@ namespace Barotrauma screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight); prevUIScale = GUI.Scale; + + ToggleCrewAreaOpen = GameMain.Config.CrewMenuOpen; } diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index 636cd27d4..fa4a2d3b4 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -1114,7 +1114,9 @@ namespace Barotrauma.Networking if (campaign == null) { - GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, missionIndex < 0 ? null : MissionPrefab.List[missionIndex]); + GameMain.GameSession = missionIndex < 0 ? + new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, MissionType.None) : + new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, MissionPrefab.List[missionIndex]); GameMain.GameSession.StartRound(levelSeed, levelDifficulty, loadSecondSub); } else diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs index 60d7c1e95..d9137afc7 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs @@ -1754,11 +1754,10 @@ namespace Barotrauma.Networking Log("Game mode: " + selectedMode.Name, ServerLog.MessageType.ServerMessage); Log("Submarine: " + selectedSub.Name, ServerLog.MessageType.ServerMessage); Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, ServerLog.MessageType.ServerMessage); - } + } - bool missionAllowRespawn = campaign == null && - (!(GameMain.GameSession.GameMode is MissionMode) || - ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn); + MissionMode missionMode = GameMain.GameSession.GameMode as MissionMode; + bool missionAllowRespawn = campaign == null && (missionMode?.Mission == null || missionMode.Mission.AllowRespawn); if (serverSettings.AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, usingShuttle ? selectedShuttle : null); @@ -1941,10 +1940,8 @@ namespace Barotrauma.Networking MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign; - bool missionAllowRespawn = campaign == null && - (!(GameMain.GameSession.GameMode is MissionMode) || - ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn); - + MissionMode missionMode = GameMain.GameSession.GameMode as MissionMode; + bool missionAllowRespawn = campaign == null && (missionMode?.Mission == null || missionMode.Mission.AllowRespawn); msg.Write(serverSettings.AllowRespawn && missionAllowRespawn); msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs index 8670544d6..fe5304a4c 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs @@ -207,10 +207,10 @@ namespace Barotrauma break; } - if (IsAttached && attachTargetBody != null && deattachTimer < 0.0f) + if (attachTargetBody != null && deattachTimer < 0.0f) { Entity entity = attachTargetBody.UserData as Entity; - Submarine attachedSub = entity is Submarine sub ? sub : entity?.Submarine; + Submarine attachedSub = entity is Submarine ? (Submarine)entity : entity?.Submarine; if (attachedSub != null) { float velocity = attachedSub.Velocity == Vector2.Zero ? 0.0f : attachedSub.Velocity.Length(); diff --git a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs index c5db6fa09..e8b6d528a 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs @@ -209,7 +209,6 @@ namespace Barotrauma //isActive = false; - bool spawnReady = false; if (spawnPending) { //wait until there are no submarines at the spawnpos @@ -220,30 +219,24 @@ namespace Barotrauma if (Vector2.DistanceSquared(submarine.WorldPosition, spawnPos) < minDist * minDist) return; } - spawnPending = false; - //+1 because Range returns an integer less than the max value int amount = Rand.Range(minAmount, maxAmount + 1, Rand.RandSync.Server); - monsters = new List(); - float offsetAmount = spawnPosType == Level.PositionType.MainPath ? 1000 : 100; - for (int i = 0; i < amount; i++) - { - CoroutineManager.InvokeAfter(() => - { - bool isClient = false; -#if CLIENT - isClient = GameMain.Client != null; -#endif - monsters.Add(Character.Create(characterFile, spawnPos + Rand.Vector(offsetAmount, Rand.RandSync.Server), i.ToString(), null, isClient, true, true)); - if (monsters.Count == amount) - { - spawnReady = true; - } - }, Rand.Range(0f, amount / 2, Rand.RandSync.Server)); - } - } + monsters = new Character[amount]; - if (!spawnReady) { return; } + for (int i = 0; i < amount; i++) + { + bool isClient = false; +#if CLIENT + isClient = GameMain.Client != null; +#endif + + monsters[i] = Character.Create( + characterFile, spawnPos + Rand.Vector(100.0f, Rand.RandSync.Server), + i.ToString(), null, isClient, true, true); + } + + spawnPending = false; + } Entity targetEntity = Submarine.FindClosest(GameMain.GameScreen.Cam.WorldViewCenter); #if CLIENT diff --git a/Barotrauma/BarotraumaShared/Source/GameSettings.cs b/Barotrauma/BarotraumaShared/Source/GameSettings.cs index 2a40edb8a..c555982f3 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSettings.cs @@ -150,6 +150,9 @@ namespace Barotrauma public bool EnableMouseLook { get; set; } = true; + public bool CrewMenuOpen { get; set; } = true; + public bool ChatOpen { get; set; } = true; + private bool unsavedSettings; public bool UnsavedSettings { @@ -847,6 +850,9 @@ namespace Barotrauma AimAssistAmount = doc.Root.GetAttributeFloat("aimassistamount", AimAssistAmount); EnableMouseLook = doc.Root.GetAttributeBool("enablemouselook", EnableMouseLook); + CrewMenuOpen = doc.Root.GetAttributeBool("crewmenuopen", CrewMenuOpen); + ChatOpen = doc.Root.GetAttributeBool("chatopen", ChatOpen); + foreach (XElement subElement in doc.Root.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) @@ -1022,7 +1028,9 @@ namespace Barotrauma new XAttribute("requiresteamauthentication", requireSteamAuthentication), new XAttribute("autoupdateworkshopitems", AutoUpdateWorkshopItems), new XAttribute("aimassistamount", aimAssistAmount), - new XAttribute("enablemouselook", EnableMouseLook)); + new XAttribute("enablemouselook", EnableMouseLook), + new XAttribute("chatopen", ChatOpen), + new XAttribute("crewmenuopen", CrewMenuOpen)); if (!ShowUserStatisticsPrompt) { diff --git a/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs b/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs index 72bec4a5e..e7a5815ad 100644 --- a/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaShared/Source/Screens/GameScreen.cs @@ -44,6 +44,7 @@ namespace Barotrauma base.Deselect(); #if CLIENT + GameMain.Config.SaveNewPlayerConfig(); GameMain.SoundManager.SetCategoryMuffle("default", false); GUI.ClearMessages(); #endif