From a9d8c14b050418e3150e654ec45fd3c7d2308fa2 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 18 Mar 2019 22:29:57 +0200 Subject: [PATCH] 3ea33fb...bbc4a31 commit bbc4a31aa83572258226f303ab767f8546de64fb Author: Joonas Rikkonen Date: Tue Mar 5 13:08:38 2019 +0200 Fixed missing item names in the extra cargo menu. Closes #1218 commit dd18bd163e05e8ba4718c0e98083e50ef0a0157e Author: Joonas Rikkonen Date: Tue Mar 5 13:04:54 2019 +0200 Fixed a compiler error in RespawnManager commit 904700eda3e4da5468208bd7553a803e9f41234e Author: Joonas Rikkonen Date: Tue Mar 5 12:56:29 2019 +0200 Autorestart/spectating fixes (closes #1219): - The server owner and spectators don't trigger autorestart. - The owner is allowed to spectate even if spectating is disallowed in server settings. - Fixed "play yourself" always toggling to true when a round ends. commit 9710612256875d5a788fb34371ca8ea6dd61b749 Author: ezjamsen Date: Tue Mar 5 10:10:25 2019 +0200 dropped the point at which damage sprites appear slightly. --- .../BarotraumaClient/Source/DebugConsole.cs | 183 ++++++++++++++++++ .../Source/GameSession/CrewManager.cs | 130 ++++++++----- .../BarotraumaClient/Source/GameSettings.cs | 22 --- .../Source/Items/Components/ItemComponent.cs | 57 ------ .../BarotraumaClient/Source/Items/Item.cs | 28 +-- .../Source/Networking/GameClient.cs | 15 +- .../Source/Networking/ServerSettings.cs | 9 +- .../Source/Screens/CharacterEditorScreen.cs | 37 ++++ .../Source/Screens/NetLobbyScreen.cs | 13 +- .../Source/Networking/GameServer.cs | 42 +++- .../Source/Networking/RespawnManager.cs | 9 +- .../Source/Characters/AI/HumanAIController.cs | 9 - .../Animation/FishAnimController.cs | 12 -- .../Source/Characters/Character.cs | 87 +++++++++ .../BarotraumaShared/Source/DebugConsole.cs | 2 +- .../BarotraumaShared/Source/GameSettings.cs | 74 ++++++- .../Source/Items/Components/ItemContainer.cs | 18 ++ .../BarotraumaShared/Source/Map/Map/Map.cs | 7 - .../BarotraumaShared/Source/Map/Submarine.cs | 24 +++ .../BarotraumaShared/Source/PlayerInput.cs | 5 - 20 files changed, 562 insertions(+), 221 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs index f4a5ce9cd..9c6563b8f 100644 --- a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs @@ -1050,6 +1050,189 @@ namespace Barotrauma TextManager.WriteToCSV(); NPCConversation.WriteToCSV(); })); +#endif + + commands.Add(new Command("cleanbuild", "", (string[] args) => + { + GameMain.Config.MusicVolume = 0.5f; + GameMain.Config.SoundVolume = 0.5f; + NewMessage("Music and sound volume set to 0.5", Color.Green); + + commands.Add(new Command("camerasettings", "camerasettings [defaultzoom] [zoomsmoothness] [movesmoothness] [minzoom] [maxzoom]: debug command for testing camera settings. The values default to 1.1, 8.0, 8.0, 0.1 and 2.0.", (string[] args) => + { + float defaultZoom = Screen.Selected.Cam.DefaultZoom; + if (args.Length > 0) float.TryParse(args[0], NumberStyles.Number, CultureInfo.InvariantCulture, out defaultZoom); + + float zoomSmoothness = Screen.Selected.Cam.ZoomSmoothness; + if (args.Length > 1) float.TryParse(args[1], NumberStyles.Number, CultureInfo.InvariantCulture, out zoomSmoothness); + float moveSmoothness = Screen.Selected.Cam.MoveSmoothness; + if (args.Length > 2) float.TryParse(args[2], NumberStyles.Number, CultureInfo.InvariantCulture, out moveSmoothness); + + float minZoom = Screen.Selected.Cam.MinZoom; + if (args.Length > 3) float.TryParse(args[3], NumberStyles.Number, CultureInfo.InvariantCulture, out minZoom); + float maxZoom = Screen.Selected.Cam.MaxZoom; + if (args.Length > 4) float.TryParse(args[4], NumberStyles.Number, CultureInfo.InvariantCulture, out maxZoom); + + Screen.Selected.Cam.DefaultZoom = defaultZoom; + Screen.Selected.Cam.ZoomSmoothness = zoomSmoothness; + Screen.Selected.Cam.MoveSmoothness = moveSmoothness; + Screen.Selected.Cam.MinZoom = minZoom; + Screen.Selected.Cam.MaxZoom = maxZoom; + })); + + commands.Add(new Command("waterparams", "waterparams [distortionscalex] [distortionscaley] [distortionstrengthx] [distortionstrengthy] [bluramount]: default 0.5 0.5 0.5 0.5 1", (string[] args) => + { + float distortScaleX = 0.5f, distortScaleY = 0.5f; + float distortStrengthX = 0.5f, distortStrengthY = 0.5f; + float blurAmount = 0.0f; + if (args.Length > 0) float.TryParse(args[0], NumberStyles.Number, CultureInfo.InvariantCulture, out distortScaleX); + if (args.Length > 1) float.TryParse(args[1], NumberStyles.Number, CultureInfo.InvariantCulture, out distortScaleY); + if (args.Length > 2) float.TryParse(args[2], NumberStyles.Number, CultureInfo.InvariantCulture, out distortStrengthX); + if (args.Length > 3) float.TryParse(args[3], NumberStyles.Number, CultureInfo.InvariantCulture, out distortStrengthY); + if (args.Length > 4) float.TryParse(args[4], NumberStyles.Number, CultureInfo.InvariantCulture, out blurAmount); + WaterRenderer.DistortionScale = new Vector2(distortScaleX, distortScaleY); + WaterRenderer.DistortionStrength = new Vector2(distortStrengthX, distortStrengthY); + WaterRenderer.BlurAmount = blurAmount; + })); + + + commands.Add(new Command("refreshrect", "Updates the dimensions of the selected items to match the ones defined in the prefab. Applied only in the subeditor.", (string[] args) => + { + //TODO: maybe do this automatically during loading when possible? + if (Screen.Selected == GameMain.SubEditorScreen) + { + if (!MapEntity.SelectedAny) + { + ThrowError("You have to select item(s) first!"); + } + else + { + foreach (var mapEntity in MapEntity.SelectedList) + { + if (mapEntity is Item item) + { + item.Rect = new Rectangle(item.Rect.X, item.Rect.Y, + (int)(item.Prefab.sprite.size.X * item.Prefab.Scale), + (int)(item.Prefab.sprite.size.Y * item.Prefab.Scale)); + } + else if (mapEntity is Structure structure) + { + if (!structure.ResizeHorizontal) + { + structure.Rect = new Rectangle(structure.Rect.X, structure.Rect.Y, + (int)structure.Prefab.ScaledSize.X, + structure.Rect.Height); + } + if (!structure.ResizeVertical) + { + structure.Rect = new Rectangle(structure.Rect.X, structure.Rect.Y, + structure.Rect.Width, + (int)structure.Prefab.ScaledSize.Y); + } + } + } + } + } + }, isCheat: false)); +#endif + + GameMain.Config.SaveNewPlayerConfig(); + + commands.Add(new Command("loadtexts", "loadtexts [sourcefile] [destinationfile]: Loads all lines of text from a given .txt file and inserts them sequientially into the elements of an xml file. If the file paths are omitted, EnglishVanilla.txt and EnglishVanilla.xml are used.", (string[] args) => + { + string sourcePath = args.Length > 0 ? args[0] : "Content/Texts/EnglishVanilla.txt"; + string destinationPath = args.Length > 1 ? args[1] : "Content/Texts/EnglishVanilla.xml"; + + string[] lines; + try + { + lines = File.ReadAllLines(sourcePath); + } + catch (Exception e) + { + ThrowError("Reading the file \"" + sourcePath + "\" failed.", e); + return; + } + var doc = XMLExtensions.TryLoadXml(destinationPath); + int i = 0; + foreach (XElement element in doc.Root.Elements()) + { + if (i >= lines.Length) + { + ThrowError("Error while loading texts to the xml file. The xml has more elements than the number of lines in the text file."); + return; + } + element.Value = lines[i]; + i++; + } + doc.Save(destinationPath); + }, + () => + { + var files = TextManager.GetTextFiles().Select(f => f.Replace("\\", "/")); + return new string[][] + { + files.Where(f => Path.GetExtension(f)==".txt").ToArray(), + files.Where(f => Path.GetExtension(f)==".xml").ToArray() + }; + })); + + commands.Add(new Command("updatetextfile", "updatetextfile [sourcefile] [destinationfile]: Inserts all the xml elements that are only present in the source file into the destination file. Can be used to update outdated translation files more easily.", (string[] args) => + { + if (args.Length < 2) return; + string sourcePath = args[0]; + string destinationPath = args[1]; + + var sourceDoc = XMLExtensions.TryLoadXml(sourcePath); + var destinationDoc = XMLExtensions.TryLoadXml(destinationPath); + + XElement destinationElement = destinationDoc.Root.Elements().First(); + foreach (XElement element in sourceDoc.Root.Elements()) + { + if (destinationDoc.Root.Element(element.Name) == null) + { + element.Value = "!!!!!!!!!!!!!" + element.Value; + destinationElement.AddAfterSelf(element); + } + XNode nextNode = destinationElement.NextNode; + while ((!(nextNode is XElement) || nextNode == element) && nextNode != null) nextNode = nextNode.NextNode; + destinationElement = nextNode as XElement; + } + destinationDoc.Save(destinationPath); + }, + () => + { + var files = TextManager.GetTextFiles().Where(f => Path.GetExtension(f) == ".xml").Select(f => f.Replace("\\", "/")).ToArray(); + return new string[][] + { + files, + files + }; + })); + + commands.Add(new Command("dumpentitytexts", "dumpentitytexts [filepath]: gets the names and descriptions of all entity prefabs and writes them into a file along with xml tags that can be used in translation files. If the filepath is omitted, the file is written to Content/Texts/EntityTexts.txt", (string[] args) => + { + string filePath = args.Length > 0 ? args[0] : "Content/Texts/EntityTexts.txt"; + List lines = new List(); + foreach (MapEntityPrefab me in MapEntityPrefab.List) + { + lines.Add("" + me.Name + ""); + lines.Add("" + me.Description + ""); + } + File.WriteAllLines(filePath, lines); + })); +#if DEBUG + commands.Add(new Command("checkduplicates", "Checks the given language for duplicate translation keys and writes to file.", (string[] args) => + { + if (args.Length != 1) return; + TextManager.CheckForDuplicates(args[0]); + })); + + commands.Add(new Command("writetocsv", "Writes the default language (English) to a .csv file.", (string[] args) => + { + TextManager.WriteToCSV(); + NPCConversation.WriteToCSV(); + })); commands.Add(new Command("loadtexts", "loadtexts [sourcefile] [destinationfile]: Loads all lines of text from a given .txt file and inserts them sequientially into the elements of an xml file. If the file paths are omitted, EnglishVanilla.txt and EnglishVanilla.xml are used.", (string[] args) => { diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs index 1755c22cd..e17fe0dc9 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -60,11 +60,6 @@ namespace Barotrauma public CrewManager(XElement element, bool isSinglePlayer) : this(isSinglePlayer) - { - return characterListBox.Rect; - } - - partial void InitProjectSpecific() { guiFrame = new GUIFrame(new RectTransform(Vector2.One, GUICanvas.Instance), null, Color.Transparent) { @@ -90,14 +85,59 @@ namespace Barotrauma return true; }; - var characterInfo = new CharacterInfo(subElement); - characterInfos.Add(characterInfo); - foreach (XElement invElement in subElement.Elements()) + characterListBox = new GUIListBox(new RectTransform(new Point(100, (int)(crewArea.Rect.Height - scrollButtonSize.Y * 1.6f)), crewArea.RectTransform, Anchor.CenterLeft), false, Color.Transparent, null) + { + //Spacing = (int)(3 * GUI.Scale), + ScrollBarEnabled = false, + ScrollBarVisible = false, + CanBeFocused = false + }; + + scrollButtonUp = new GUIButton(new RectTransform(scrollButtonSize, crewArea.RectTransform, Anchor.TopLeft, Pivot.TopLeft), "", Alignment.Center, "GUIButtonVerticalArrow") + { + Visible = false, + UserData = -1, + OnClicked = ScrollCharacterList + }; + scrollButtonDown = new GUIButton(new RectTransform(scrollButtonSize, crewArea.RectTransform, Anchor.BottomLeft, Pivot.BottomLeft), "", Alignment.Center, "GUIButtonVerticalArrow") + { + Visible = false, + UserData = 1, + OnClicked = ScrollCharacterList + }; + scrollButtonDown.Children.ForEach(c => c.SpriteEffects = SpriteEffects.FlipVertically); + + if (isSinglePlayer) + { + chatBox = new ChatBox(guiFrame, isSinglePlayer: true) { - if (invElement.Name.ToString().ToLowerInvariant() != "inventory") continue; - characterInfo.InventoryData = invElement; - break; - } + OnEnterMessage = (textbox, text) => + { + if (Character.Controlled == null) { return true; } + + textbox.TextColor = ChatMessage.MessageColor[(int)ChatMessageType.Default]; + + if (!string.IsNullOrWhiteSpace(text)) + { + string msgCommand = ChatMessage.GetChatMessageCommand(text, out string msg); + AddSinglePlayerChatMessage( + Character.Controlled.Info.Name, + msg, + ((msgCommand == "r" || msgCommand == "radio") && ChatMessage.CanUseRadio(Character.Controlled)) ? ChatMessageType.Radio : ChatMessageType.Default, + Character.Controlled); + var headset = GetHeadset(Character.Controlled, true); + if (headset != null && headset.CanTransmit()) + { + headset.TransmitSignal(stepsTaken: 0, signal: msg, source: headset.Item, sender: Character.Controlled, sendToChat: false); + } + } + textbox.Deselect(); + textbox.Text = ""; + return true; + } + }; + + chatBox.InputBox.OnTextChanged += chatBox.TypingChatMessage; } var reports = Order.PrefabList.FindAll(o => o.TargetAllCharacters && o.SymbolSprite != null); @@ -109,38 +149,14 @@ namespace Barotrauma CanBeFocused = false }; - //report buttons - foreach (Order order in reports) - { - if (!order.TargetAllCharacters || order.SymbolSprite == null) continue; - var btn = new GUIButton(new RectTransform(new Point(reportButtonFrame.Rect.Width), reportButtonFrame.RectTransform), style: null) + var characterInfo = new CharacterInfo(subElement); + characterInfos.Add(characterInfo); + foreach (XElement invElement in subElement.Elements()) { - OnClicked = (GUIButton button, object userData) => - { - if (Character.Controlled == null || Character.Controlled.SpeechImpediment >= 100.0f) return false; - SetCharacterOrder(null, order, null, Character.Controlled); - return true; - }, - UserData = order, - ToolTip = order.Name - }; - - new GUIFrame(new RectTransform(new Vector2(1.5f), btn.RectTransform, Anchor.Center), "OuterGlow") - { - Color = Color.Red * 0.8f, - HoverColor = Color.Red * 1.0f, - PressedColor = Color.Red * 0.6f, - UserData = "highlighted", - CanBeFocused = false, - Visible = false - }; - - var img = new GUIImage(new RectTransform(Vector2.One, btn.RectTransform), order.Prefab.SymbolSprite, scaleToFit: true) - { - Color = order.Color, - HoverColor = Color.Lerp(order.Color, Color.White, 0.5f), - ToolTip = order.Name - }; + if (invElement.Name.ToString().ToLowerInvariant() != "inventory") continue; + characterInfo.InventoryData = invElement; + break; + } } screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight); @@ -148,6 +164,16 @@ namespace Barotrauma prevUIScale = GUI.Scale; } + + #endregion + + #region Character list management + + public Rectangle GetCharacterListArea() + { + return characterListBox.Rect; + } + partial void InitProjectSpecific() { guiFrame = new GUIFrame(new RectTransform(Vector2.One, GUICanvas.Instance), null, Color.Transparent) @@ -338,6 +364,7 @@ namespace Barotrauma DebugConsole.ThrowError("Tried to add the same character info to CrewManager twice.\n" + Environment.StackTrace); return; } + if (characterInfos.Contains(revivedCharacter.Info)) AddCharacter(revivedCharacter); } characterInfos.Add(characterInfo); @@ -660,15 +687,7 @@ namespace Barotrauma characterListBox.BarScroll -= characterListBox.BarScroll % step; characterListBox.BarScroll += dir * step; - private IEnumerable KillCharacterAnim(GUIComponent component) - { - List components = component.GetAllChildren().ToList(); - components.Add(component); - foreach (GUIComponent comp in components) - { - comp.Color = Color.DarkRed; - } - if (characterInfos.Contains(revivedCharacter.Info)) AddCharacter(revivedCharacter); + return radioItem.GetComponent(); } private IEnumerable KillCharacterAnim(GUIComponent component) @@ -681,7 +700,12 @@ namespace Barotrauma { comp.Color = Color.DarkRed; } - if (string.IsNullOrEmpty(text)) { return; } + List availableSpeakers = Character.CharacterList.FindAll(c => + c.AIController is HumanAIController && + !c.IsDead && + c.SpeechImpediment <= 100.0f); + pendingConversationLines.AddRange(NPCConversation.CreateRandom(availableSpeakers)); + } yield return new WaitForSeconds(1.0f); diff --git a/Barotrauma/BarotraumaClient/Source/GameSettings.cs b/Barotrauma/BarotraumaClient/Source/GameSettings.cs index a111ddc03..00085898f 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSettings.cs @@ -626,28 +626,6 @@ namespace Barotrauma new GUIMessageBox(TextManager.Get("RestartRequiredLabel"), TextManager.Get("RestartRequiredLanguage")); - return true; - }; - - //spacing - new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null); - - new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomLeft), - TextManager.Get("Cancel")) - { - IgnoreLayoutGroups = true, - OnClicked = (x, y) => - { - if (UnsavedSettings) - { - LoadPlayerConfig(); - } - if (Screen.Selected == GameMain.MainMenuScreen) GameMain.MainMenuScreen.ReturnToMainMenu(null, null); - GUI.SettingsMenuOpen = false; - return true; - } - }; - //spacing new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null); diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs index 94a9eee32..72589ccf5 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs @@ -184,63 +184,6 @@ namespace Barotrauma.Items.Components } } } - - public void ApplyTo(RectTransform target) - { - if (RelativeOffset.HasValue) - { - target.RelativeOffset = RelativeOffset.Value; - } - else if (AbsoluteOffset.HasValue) - { - target.AbsoluteOffset = AbsoluteOffset.Value; - } - if (RelativeSize.HasValue) - { - target.RelativeSize = RelativeSize.Value; - } - else if (AbsoluteSize.HasValue) - { - target.NonScaledSize = AbsoluteSize.Value; - } - if (Anchor.HasValue) - { - target.Anchor = Anchor.Value; - } - if (Pivot.HasValue) - { - target.Pivot = Pivot.Value; - } - else - { - target.Pivot = RectTransform.MatchPivotToAnchor(target.Anchor); - } - target.RecalculateChildren(true, true); - } - } - - public GUIFrame GuiFrame { get; protected set; } - - [Serialize(false, false)] - public bool AllowUIOverlap - { - get; - set; - } - - private ItemComponent linkToUIComponent; - [Serialize("", false)] - public string LinkUIToComponent - { - get; - set; - } - - [Serialize(0, false)] - public int HudPriority - { - get; - private set; } private bool shouldMuffleLooping; diff --git a/Barotrauma/BarotraumaClient/Source/Items/Item.cs b/Barotrauma/BarotraumaClient/Source/Items/Item.cs index 41c6994b3..c19111f10 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Item.cs @@ -36,33 +36,6 @@ namespace Barotrauma { get { return activeSprite; } } - - public float SpriteRotation; - - private GUITextBlock itemInUseWarning; - private GUITextBlock ItemInUseWarning - { - get - { - if (itemInUseWarning == null) - { - itemInUseWarning = new GUITextBlock(new RectTransform(new Point(10), GUI.Canvas), "", - textColor: Color.Orange, color: Color.Black, - textAlignment:Alignment.Center, style: "OuterGlow"); - } - return itemInUseWarning; - } - } - - public override bool SelectableInEditor - { - get - { - return parentInventory == null && (body == null || body.Enabled) && ShowItems; - } - } - - public float SpriteRotation; private GUITextBlock itemInUseWarning; private GUITextBlock ItemInUseWarning @@ -376,6 +349,7 @@ namespace Barotrauma GUI.DrawLine(spriteBatch, from, to, lineColor, width: 1); //GUI.DrawString(spriteBatch, from, $"Linked to {e.Name}", lineColor, Color.Black * 0.5f); } + } public void UpdateSpriteStates(float deltaTime) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index 5ff7bdcac..c2bc5f659 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -92,6 +92,11 @@ namespace Barotrauma.Networking private int ownerKey; + public bool IsServerOwner + { + get { return ownerKey > 0; } + } + public GameClient(string newName, string ip, int ownerKey=0) { //TODO: gui stuff should probably not be here? @@ -894,6 +899,7 @@ namespace Barotrauma.Networking } yield return new WaitForSeconds(0.5f); } + } waitInServerQueueBox?.Close(); waitInServerQueueBox = null; @@ -935,16 +941,7 @@ namespace Barotrauma.Networking { if (newPermissions == permissions) return; } - } - private void SetMyPermissions(ClientPermissions newPermissions, IEnumerable permittedConsoleCommands) - { - if (!(this.permittedConsoleCommands.Any(c => !permittedConsoleCommands.Contains(c)) || - permittedConsoleCommands.Any(c => !this.permittedConsoleCommands.Contains(c)))) - { - if (newPermissions == permissions) return; - } - permissions = newPermissions; this.permittedConsoleCommands = new List(permittedConsoleCommands); //don't show the "permissions changed" popup if the client owns the server diff --git a/Barotrauma/BarotraumaClient/Source/Networking/ServerSettings.cs b/Barotrauma/BarotraumaClient/Source/Networking/ServerSettings.cs index 1155547c9..e04e92461 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/ServerSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/ServerSettings.cs @@ -524,8 +524,15 @@ namespace Barotrauma.Networking img.Color = img.Sprite == ip.InventoryIcon ? ip.InventoryIconColor : ip.SpriteColor; } + new GUITextBlock(new RectTransform(new Vector2(0.75f, 1.0f), itemFrame.RectTransform), + ip.Name, font: GUI.SmallFont) + { + Wrap = true, + CanBeFocused = false + }; + ExtraCargo.TryGetValue(ip, out int cargoVal); - var amountInput = new GUINumberInput(new RectTransform(new Vector2(0.3f, 1.0f), itemFrame.RectTransform), + var amountInput = new GUINumberInput(new RectTransform(new Vector2(0.35f, 1.0f), itemFrame.RectTransform), GUINumberInput.NumberType.Int, textAlignment: Alignment.CenterLeft) { MinValueInt = 0, diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CharacterEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/CharacterEditorScreen.cs index f75d58b4d..316dd5656 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CharacterEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CharacterEditorScreen.cs @@ -438,6 +438,43 @@ namespace Barotrauma UpdateSourceRect(limb, newRect); } } + UpdateJointCreation(); + if (PlayerInput.KeyHit(Keys.Left)) + { + foreach (var limb in selectedLimbs) + { + var newRect = limb.ActiveSprite.SourceRect; + newRect.X--; + UpdateSourceRect(limb, newRect); + } + } + if (PlayerInput.KeyHit(Keys.Right)) + { + foreach (var limb in selectedLimbs) + { + var newRect = limb.ActiveSprite.SourceRect; + newRect.X++; + UpdateSourceRect(limb, newRect); + } + } + if (PlayerInput.KeyHit(Keys.Down)) + { + foreach (var limb in selectedLimbs) + { + var newRect = limb.ActiveSprite.SourceRect; + newRect.Y++; + UpdateSourceRect(limb, newRect); + } + } + if (PlayerInput.KeyHit(Keys.Up)) + { + foreach (var limb in selectedLimbs) + { + var newRect = limb.ActiveSprite.SourceRect; + newRect.Y--; + UpdateSourceRect(limb, newRect); + } + } } if (!isFreezed) { diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index 7df8e1850..7fa6c23aa 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -300,6 +300,7 @@ namespace Barotrauma playYourself = new GUITickBox(new RectTransform(new Vector2(0.06f, 0.06f), myCharacterFrame.RectTransform) { RelativeOffset = new Vector2(0.05f,0.05f) }, TextManager.Get("PlayYourself")) { + Selected = true, OnSelected = TogglePlayYourself, UserData = "playyourself" }; @@ -794,11 +795,6 @@ namespace Barotrauma if (GameMain.Client != null) { GameMain.Client.ServerSettings.Voting.ResetVotes(GameMain.Client.ConnectedClients); - if (!playYourself.Selected) - { - playYourself.Selected = true; - TogglePlayYourself(playYourself); - } spectateButton.OnClicked = GameMain.Client.SpectateClicked; ReadyToStartBox.OnSelected = GameMain.Client.SetReadyToStart; } @@ -1102,6 +1098,13 @@ namespace Barotrauma public void SetAllowSpectating(bool allowSpectating) { + //server owner is allowed to spectate regardless of the server settings + if (GameMain.Client != null && GameMain.Client.IsServerOwner) + { + return; + } + } + //show the player config menu if spectating is not allowed if (!playYourself.Selected && !allowSpectating) { diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs index 72facfe3c..1fd1335d6 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs @@ -42,12 +42,14 @@ namespace Barotrauma.Networking private bool masterServerResponded; private IRestResponse masterServerResponse; + private bool autoRestartTimerRunning; + public VoipServer VoipServer { get; private set; } - + private bool initiatedStartGame; private CoroutineHandle startGameCoroutine; @@ -368,7 +370,8 @@ namespace Barotrauma.Networking Client owner = connectedClients.Find(c => c.InGame && !c.NeedsMidRoundSync && c.Name == character.OwnerClientName && - c.Connection.RemoteEndPoint.Address.ToString() == character.OwnerClientIP); + c.IPMatches(character.OwnerClientIP)); + if (owner != null && (!serverSettings.AllowSpectating || !owner.SpectateOnly)) { SetClientCharacter(owner, character); @@ -433,11 +436,30 @@ namespace Barotrauma.Networking initiatedStartGame = false; } } - else if (Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count > 0 && !gameStarted && !initiatedStartGame) + else if (Screen.Selected == GameMain.NetLobbyScreen && + !gameStarted && + !initiatedStartGame) { - if (serverSettings.AutoRestart) serverSettings.AutoRestartTimer -= deltaTime; + if (serverSettings.AutoRestart) + { + //autorestart if there are any non-spectators on the server (ignoring the server owner) + bool shouldAutoRestart = connectedClients.Any(c => + c.Connection != OwnerConnection && + (!c.SpectateOnly || !serverSettings.AllowSpectating)); - if (serverSettings.AutoRestart && serverSettings.AutoRestartTimer < 0.0f) + if (shouldAutoRestart != autoRestartTimerRunning) + { + autoRestartTimerRunning = shouldAutoRestart; + GameMain.NetLobbyScreen.LastUpdateID++; + } + + if (autoRestartTimerRunning) + { + serverSettings.AutoRestartTimer -= deltaTime; + } + } + + if (serverSettings.AutoRestart && autoRestartTimerRunning && serverSettings.AutoRestartTimer < 0.0f) { StartGame(); } @@ -1363,7 +1385,7 @@ namespace Barotrauma.Networking outmsg.Write(serverSettings.AutoRestart); if (serverSettings.AutoRestart) { - outmsg.Write(serverSettings.AutoRestartTimer); + outmsg.Write(autoRestartTimerRunning ? serverSettings.AutoRestartTimer : 0.0f); } } else @@ -1580,11 +1602,15 @@ namespace Barotrauma.Networking var teamID = n == 0 ? Character.TeamType.Team1 : Character.TeamType.Team2; //find the clients in this team - List teamClients = teamCount == 1 ? new List(connectedClients) : connectedClients.FindAll(c => c.TeamID == teamID); + List teamClients = teamCount == 1 ? + new List(connectedClients) : + connectedClients.FindAll(c => c.TeamID == teamID); if (serverSettings.AllowSpectating) { teamClients.RemoveAll(c => c.SpectateOnly); } + //always allow the server owner to spectate even if it's disallowed in server settings + teamClients.RemoveAll(c => c.Connection == OwnerConnection && c.SpectateOnly); if (!teamClients.Any() && n > 0) { continue; } @@ -2464,7 +2490,7 @@ namespace Barotrauma.Networking private void UpdateCharacterInfo(NetIncomingMessage message, Client sender) { - sender.SpectateOnly = message.ReadBoolean() && serverSettings.AllowSpectating; + sender.SpectateOnly = message.ReadBoolean() && (serverSettings.AllowSpectating || sender.Connection == OwnerConnection); if (sender.SpectateOnly) { return; diff --git a/Barotrauma/BarotraumaServer/Source/Networking/RespawnManager.cs b/Barotrauma/BarotraumaServer/Source/Networking/RespawnManager.cs index cf81b3502..8b489f1a0 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/RespawnManager.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/RespawnManager.cs @@ -9,9 +9,11 @@ namespace Barotrauma.Networking { private List GetClientsToRespawn() { + GameServer server = networkMember as GameServer; + return networkMember.ConnectedClients.FindAll(c => c.InGame && - (!c.SpectateOnly || !((GameServer)networkMember).ServerSettings.AllowSpectating) && + (!c.SpectateOnly || (!server.ServerSettings.AllowSpectating && server.OwnerConnection != c.Connection)) && (c.Character == null || c.Character.IsDead)); } @@ -27,8 +29,9 @@ namespace Barotrauma.Networking .ToList(); } - int currPlayerCount = server.ConnectedClients.Count(c => c.InGame && (!c.SpectateOnly || !server.ServerSettings.AllowSpectating)); - //if (server.CharacterInfo != null) currPlayerCount++; + int currPlayerCount = server.ConnectedClients.Count(c => + c.InGame && + (!c.SpectateOnly || (!server.ServerSettings.AllowSpectating && server.OwnerConnection != c.Connection))); var existingBots = Character.CharacterList .FindAll(c => c.TeamID == Character.TeamType.Team1 && c.AIController != null && c.Info != null); diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs index ccb3eb2da..167a0025e 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/HumanAIController.cs @@ -179,15 +179,6 @@ namespace Barotrauma { if (GameMain.Client != null) return; - Order newOrder = null; - if (Character.CurrentHull != null) - { - if (Character.CurrentHull.FireSources.Count > 0) - { - var orderPrefab = Order.PrefabList.Find(o => o.AITag == "reportfire"); - newOrder = new Order(orderPrefab, Character.CurrentHull, null); - } - partial void ReportProblems(); private void UpdateSpeaking() diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs index aa850de0a..468bc6397 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs @@ -677,18 +677,6 @@ namespace Barotrauma limb.body.ApplyForce(diff * (float)(Math.Sin(WalkPos) * Math.Sqrt(limb.Mass)) * 30.0f * animStrength); } - - limb?.body.SmoothRotate(angle, torque, wrapAngle: false); - } - - private void SmoothRotateWithoutWrapping(Limb limb, float angle, Limb referenceLimb, float torque) - { - //make sure the angle "has the same number of revolutions" as the reference limb - //(e.g. we don't want to rotate the legs to 0 if the torso is at 360, because that'd blow up the hip joints) - while (referenceLimb.Rotation - angle > MathHelper.TwoPi) - { - angle += MathHelper.TwoPi; - } while (referenceLimb.Rotation - angle < -MathHelper.TwoPi) { angle -= MathHelper.TwoPi; diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index e716766f0..65ca5b84e 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -1035,6 +1035,61 @@ namespace Barotrauma ResetSpeedMultiplier(); // Reset, items will set the value before the next update + return targetMovement; + } + + /// + /// Can be used to modify the character's speed via StatusEffects + /// + public float SpeedMultiplier + { + get + { + if (speedMultipliers.Count == 0) return 1f; + + float greatestPositive = 1f; + float greatestNegative = 1f; + + for (int i = 0; i < speedMultipliers.Count; i++) + { + float val = speedMultipliers[i]; + if (val < 1f) + { + if (val < greatestNegative) + { + greatestNegative = val; + } + } + else + { + if (val > greatestPositive) + { + greatestPositive = val; + } + } + } + + return greatestPositive - (1f - greatestNegative); + } + set + { + if (value == 1f) return; + speedMultipliers.Add(value); + } + } + + public void ResetSpeedMultiplier() + { + speedMultipliers.Clear(); + } + + /// + /// Applies temporary limits to the speed (damage). + /// + public float GetCurrentMaxSpeed(bool run) + { + float currMaxSpeed = AnimController.GetCurrentSpeed(run); + //? //currMaxSpeed *= 1.5f; @@ -1055,6 +1110,38 @@ namespace Barotrauma return currMaxSpeed; } + public void Control(float deltaTime, Camera cam) + { + ViewTarget = null; + if (!AllowInput) return; + + Vector2 smoothedCursorDiff = cursorPosition - SmoothedCursorPosition; + if (Controlled == this) + { + SmoothedCursorPosition = cursorPosition; + } + else + { + smoothedCursorDiff = NetConfig.InterpolateCursorPositionError(smoothedCursorDiff); + SmoothedCursorPosition = cursorPosition - smoothedCursorDiff; + } + + if (!(this is AICharacter) || Controlled == this || IsRemotePlayer) + { + Vector2 targetMovement = GetTargetMovement(); + + AnimController.TargetMovement = targetMovement; + AnimController.IgnorePlatforms = AnimController.TargetMovement.Y < -0.1f; + } + + if (AnimController is HumanoidAnimController) + { + ((HumanoidAnimController) AnimController).Crouching = IsKeyDown(InputType.Crouch); + } + + return currMaxSpeed; + } + /// /// Can be used to modify the character's speed via StatusEffects /// diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index f0b9a0930..7bdada449 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -149,7 +149,7 @@ namespace Barotrauma commands.SelectMany(c => c.names).ToArray(), new string[0] }; - }, isCheat: true)); + })); commands.Add(new Command("items|itemlist", "itemlist: List all the item prefabs available for spawning.", (string[] args) => diff --git a/Barotrauma/BarotraumaShared/Source/GameSettings.cs b/Barotrauma/BarotraumaShared/Source/GameSettings.cs index ccb98ef24..f76ee19a8 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSettings.cs @@ -63,6 +63,24 @@ namespace Barotrauma public VoiceMode VoiceSetting { get; set; } public string VoiceCaptureDevice { get; set; } + public int ParticleLimit { get; set; } + + public float LightMapScale { get; set; } + public bool SpecularityEnabled { get; set; } + public bool ChromaticAberrationEnabled { get; set; } + + public bool MuteOnFocusLost { get; set; } + + public enum VoiceMode + { + Disabled, + PushToTalk, + Activity + }; + + public VoiceMode VoiceSetting { get; set; } + public string VoiceCaptureDevice { get; set; } + public float NoiseGateThreshold { get; set; } = -45; private KeyOrMouse[] keyMapping; @@ -377,8 +395,6 @@ namespace Barotrauma AimAssistAmount = doc.Root.GetAttributeFloat("aimassistamount", 0.5f); - AimAssistAmount = doc.Root.GetAttributeFloat("aimassistamount", 0.5f); - AimAssistAmount = doc.Root.GetAttributeFloat("aimassistamount", 0.5f); keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length]; @@ -550,6 +566,34 @@ namespace Barotrauma TextManager.LoadTextPacks(SelectedContentPackages); + //display error messages after all content packages have been loaded + //to make sure the package that contains text files has been loaded before we attempt to use TextManager + foreach (string missingPackagePath in missingPackagePaths) + { + DebugConsole.ThrowError(TextManager.Get("ContentPackageNotFound").Replace("[packagepath]", missingPackagePath)); + } + foreach (ContentPackage incompatiblePackage in incompatiblePackages) + { + DebugConsole.ThrowError(TextManager.Get(incompatiblePackage.GameVersion <= new Version(0, 0, 0, 0) ? "IncompatibleContentPackageUnknownVersion" : "IncompatibleContentPackage") + .Replace("[packagename]", incompatiblePackage.Name) + .Replace("[packageversion]", incompatiblePackage.GameVersion.ToString()) + .Replace("[gameversion]", GameMain.Version.ToString())); + } + foreach (ContentPackage contentPackage in SelectedContentPackages) + { + foreach (ContentFile file in contentPackage.Files) + { + if (!System.IO.File.Exists(file.Path)) + { + DebugConsole.ThrowError("Error in content package \"" + contentPackage.Name + "\" - file \"" + file.Path + "\" not found."); + continue; + } + ToolBox.IsProperFilenameCase(file.Path); + } + } + + TextManager.LoadTextPacks(SelectedContentPackages); + //display error messages after all content packages have been loaded //to make sure the package that contains text files has been loaded before we attempt to use TextManager foreach (string missingPackagePath in missingPackagePaths) @@ -1128,6 +1172,32 @@ namespace Barotrauma NewLineOnAttributes = true }; +#if CLIENT + if (Tutorial.Tutorials != null) + { + foreach (Tutorial tutorial in Tutorial.Tutorials) + { + if (tutorial.Completed && !CompletedTutorialNames.Contains(tutorial.Name)) + { + CompletedTutorialNames.Add(tutorial.Name); + } + } + } +#endif + var tutorialElement = new XElement("tutorials"); + foreach (string tutorialName in CompletedTutorialNames) + { + tutorialElement.Add(new XElement("Tutorial", new XAttribute("name", tutorialName))); + } + doc.Root.Add(tutorialElement); + + XmlWriterSettings settings = new XmlWriterSettings + { + Indent = true, + OmitXmlDeclaration = true, + NewLineOnAttributes = true + }; + #if CLIENT if (Tutorial.Tutorials != null) { diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs index 38a55074d..e1e01d372 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs @@ -205,6 +205,24 @@ namespace Barotrauma.Items.Components return base.Select(character); } + public override bool Select(Character character) + { + if (item.Container != null) { return false; } + + if (AutoInteractWithContained) + { + foreach (Item contained in Inventory.Items) + { + if (contained == null) continue; + if (contained.TryInteract(character)) + { + return false; + } + } + } + return base.Select(character); + } + public override bool Pick(Character picker) { if (AutoInteractWithContained) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs index 5e0b5c4dc..c3d5d2926 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs @@ -430,13 +430,6 @@ namespace Barotrauma } CurrentLocation.SelectedMissionIndex = missionIndex; - //the destination must be the same as the destination of the mission - if (CurrentLocation.SelectedMission != null && - CurrentLocation.SelectedMission.Locations[1] != SelectedLocation) - { - SelectLocation(CurrentLocation.SelectedMission.Locations[1]); - } - SelectedLocation = location; SelectedConnection = connections.Find(c => c.Locations.Contains(CurrentLocation) && c.Locations.Contains(SelectedLocation)); OnLocationSelected?.Invoke(SelectedLocation, SelectedConnection); diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index 919708fcc..0fa62f65b 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -522,6 +522,10 @@ namespace Barotrauma { maxX = Math.Min(maxX, ruin.Area.X - 100.0f); } + else + { + maxX = Math.Min(maxX, ruin.Area.X - 100.0f); + } if (entity.IsVisible(worldView)) { visibleEntities.Add(entity); } } @@ -546,6 +550,26 @@ namespace Barotrauma spawnPos.X = (minX + maxX) / 2; } + if (minX < 0.0f && maxX > Level.Loaded.Size.X) + { + //no walls found at either side, just use the initial spawnpos and hope for the best + } + else if (minX < 0) + { + //no wall found at the left side, spawn to the left from the right-side wall + spawnPos.X = maxX - minWidth - 100.0f; + } + else if (maxX > Level.Loaded.Size.X) + { + //no wall found at right side, spawn to the right from the left-side wall + spawnPos.X = minX + minWidth + 100.0f; + } + else + { + //walls found at both sides, use their midpoint + spawnPos.X = (minX + maxX) / 2; + } + spawnPos.Y = Math.Min(spawnPos.Y, Level.Loaded.Size.Y - dockedBorders.Height / 2 - 10); return spawnPos - diffFromDockedBorders; } diff --git a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs index ae64fea5b..dac0e7d44 100644 --- a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs +++ b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs @@ -140,11 +140,6 @@ namespace Barotrauma } #endif - public KeyOrMouse State - { - get { return binding; } - } - public void SetState() { hit = binding.IsHit();