diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs index da396dad7..c6f95eda7 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs @@ -44,29 +44,25 @@ namespace Barotrauma return; } - if (character.MemState[0].SelectedCharacter == null || character.MemState[0].SelectedCharacter.Removed) + if (character.MemState[0].Interact == null || character.MemState[0].Interact.Removed) { character.DeselectCharacter(); - } - else if (character.MemState[0].SelectedCharacter != null) - { - character.SelectCharacter(character.MemState[0].SelectedCharacter); - } - - if (character.MemState[0].SelectedItem == null || character.MemState[0].SelectedItem.Removed) - { character.SelectedConstruction = null; } - else + else if (character.MemState[0].Interact is Character) { - if (character.SelectedConstruction != character.MemState[0].SelectedItem) + character.SelectCharacter((Character)character.MemState[0].Interact); + } + else if (character.MemState[0].Interact is Item newSelectedConstruction) + { + if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction) { - foreach (var ic in character.MemState[0].SelectedItem.Components) + foreach (var ic in newSelectedConstruction.Components) { if (ic.CanBeSelected) ic.Select(character); } } - character.SelectedConstruction = character.MemState[0].SelectedItem; + character.SelectedConstruction = newSelectedConstruction; } if (character.MemState[0].Animation == AnimController.Animation.CPR) @@ -92,13 +88,13 @@ namespace Barotrauma Collider.AngularVelocity = newAngularVelocity; float distSqrd = Vector2.DistanceSquared(newPosition, Collider.SimPosition); - float errorTolerance = character.AllowInput ? 0.01f : 0.2f; + float errorTolerance = character.AllowInput ? 0.01f : 0.1f; if (distSqrd > errorTolerance) { if (distSqrd > 10.0f || !character.AllowInput) { Collider.TargetRotation = newRotation; - SetPosition(newPosition, lerp: distSqrd < 5.0f); + SetPosition(newPosition, lerp: distSqrd < 1.0f); } else { @@ -112,15 +108,8 @@ namespace Barotrauma // -> we need to correct it manually if (!character.AllowInput) { - float mainLimbDistSqrd = Vector2.DistanceSquared(MainLimb.PullJointWorldAnchorA, Collider.SimPosition); - float mainLimbErrorTolerance = 0.1f; - //if the main limb is roughly at the correct position and the collider isn't moving (much at least), - //don't attempt to correct the position. - if (mainLimbDistSqrd > mainLimbErrorTolerance || Collider.LinearVelocity.LengthSquared() > 0.05f) - { - MainLimb.PullJointWorldAnchorB = Collider.SimPosition; - MainLimb.PullJointEnabled = true; - } + MainLimb.PullJointWorldAnchorB = Collider.SimPosition; + MainLimb.PullJointEnabled = true; } } character.MemLocalState.Clear(); @@ -173,30 +162,25 @@ namespace Barotrauma CharacterStateInfo localPos = character.MemLocalState[localPosIndex]; //the entity we're interacting with doesn't match the server's - if (localPos.SelectedCharacter != serverPos.SelectedCharacter) + if (localPos.Interact != serverPos.Interact) { - if (serverPos.SelectedCharacter == null || serverPos.SelectedCharacter.Removed) + if (serverPos.Interact == null || serverPos.Interact.Removed) { character.DeselectCharacter(); - } - else if (serverPos.SelectedCharacter != null) - { - character.SelectCharacter(serverPos.SelectedCharacter); - } - } - if (localPos.SelectedItem != serverPos.SelectedItem) - { - if (serverPos.SelectedItem == null || serverPos.SelectedItem.Removed) - { character.SelectedConstruction = null; } - else if (serverPos.SelectedItem != null) + else if (serverPos.Interact is Character) { - if (character.SelectedConstruction != serverPos.SelectedItem) + character.SelectCharacter((Character)serverPos.Interact); + } + else + { + var newSelectedConstruction = (Item)serverPos.Interact; + if (newSelectedConstruction != null && character.SelectedConstruction != newSelectedConstruction) { - serverPos.SelectedItem.TryInteract(character, true, true); + newSelectedConstruction.TryInteract(character, true, true); } - character.SelectedConstruction = serverPos.SelectedItem; + character.SelectedConstruction = newSelectedConstruction; } } diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs index 996a07b55..79abaed11 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs @@ -200,13 +200,9 @@ namespace Barotrauma { cam.OffsetAmount = 0.0f; } - else if (SelectedConstruction != null && ViewTarget == null && - SelectedConstruction.Components.Any(ic => ic?.GuiFrame != null && ic.ShouldDrawHUD(this))) + else if (SelectedConstruction != null && SelectedConstruction.Components.Any(ic => (ic.GuiFrame != null && GUI.IsMouseOn(ic.GuiFrame)))) { cam.OffsetAmount = 0.0f; - cursorPosition = - SelectedConstruction.Position + - new Vector2(cursorPosition.X % 10.0f, cursorPosition.Y % 10.0f); //apply a little bit of movement to the cursor pos to prevent AFK kicking } else if (Lights.LightManager.ViewTarget == this && Vector2.DistanceSquared(AnimController.Limbs[0].SimPosition, mouseSimPos) > 1.0f) { @@ -214,7 +210,7 @@ namespace Barotrauma { if (deltaTime > 0.0f) cam.OffsetAmount = 0.0f; } - else + else if (Lights.LightManager.ViewTarget == this && Vector2.DistanceSquared(AnimController.Limbs[0].SimPosition, mouseSimPos) > 1.0f) { Body body = Submarine.CheckVisibility(AnimController.Limbs[0].SimPosition, mouseSimPos); Structure structure = body == null ? null : body.UserData as Structure; diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs index e01a3dd2b..a4eb436a9 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs @@ -241,12 +241,10 @@ namespace Barotrauma if (!string.IsNullOrEmpty(jobIdentifier)) { jobPrefab = JobPrefab.List.Find(jp => jp.Identifier == jobIdentifier); - byte skillCount = inc.ReadByte(); - for (int i = 0; i < skillCount; i++) + for (int i = 0; i < jobPrefab.Skills.Count; i++) { - string skillIdentifier = inc.ReadString(); float skillLevel = inc.ReadSingle(); - skillLevels.Add(skillIdentifier, skillLevel); + skillLevels.Add(jobPrefab.Skills[i].Identifier, skillLevel); } } @@ -256,6 +254,7 @@ namespace Barotrauma ID = infoID, }; ch.RecreateHead(headSpriteID,(Race)race, (Gender)gender, hairIndex, beardIndex, moustacheIndex, faceAttachmentIndex); + System.Diagnostics.Debug.Assert(skillLevels.Count == ch.Job.Skills.Count); if (ch.Job != null) { foreach (KeyValuePair skill in skillLevels) @@ -263,12 +262,11 @@ namespace Barotrauma Skill matchingSkill = ch.Job.Skills.Find(s => s.Identifier == skill.Key); if (matchingSkill == null) { - ch.Job.Skills.Add(new Skill(skill.Key, skill.Value)); + DebugConsole.ThrowError("Skill \"" + skill.Key + "\" not found in character \"" + newName + "\""); continue; } matchingSkill.Level = skill.Value; } - ch.Job.Skills.RemoveAll(s => !skillLevels.ContainsKey(s.Identifier)); } return ch; } diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs index 9569a07c5..955c0d516 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs @@ -30,13 +30,12 @@ namespace Barotrauma else { var posInfo = new CharacterStateInfo( - SimPosition, - AnimController.Collider.Rotation, - LastNetworkUpdateID, - AnimController.TargetDir, - SelectedCharacter, - SelectedConstruction, - AnimController.Anim); + SimPosition, + AnimController.Collider.Rotation, + LastNetworkUpdateID, + AnimController.TargetDir, + SelectedCharacter == null ? (Entity)SelectedConstruction : (Entity)SelectedCharacter, + AnimController.Anim); memLocalState.Add(posInfo); @@ -215,7 +214,6 @@ namespace Barotrauma Vector2 linearVelocity = new Vector2( msg.ReadRangedSingle(-MaxVel, MaxVel, 12), msg.ReadRangedSingle(-MaxVel, MaxVel, 12)); - linearVelocity = NetConfig.Quantize(linearVelocity, -MaxVel, MaxVel, 12); bool fixedRotation = msg.ReadBoolean(); float? rotation = null; @@ -225,7 +223,6 @@ namespace Barotrauma rotation = msg.ReadFloat(); float MaxAngularVel = NetConfig.MaxPhysicsBodyAngularVelocity; angularVelocity = msg.ReadRangedSingle(-MaxAngularVel, MaxAngularVel, 8); - angularVelocity = NetConfig.Quantize(angularVelocity.Value, -MaxAngularVel, MaxAngularVel, 8); } bool readStatus = msg.ReadBoolean(); @@ -239,11 +236,7 @@ namespace Barotrauma int index = 0; if (GameMain.Client.Character == this && AllowInput) { - var posInfo = new CharacterStateInfo( - pos, rotation, - networkUpdateID, - facingRight ? Direction.Right : Direction.Left, - selectedCharacter, selectedItem, animation); + var posInfo = new CharacterStateInfo(pos, rotation, networkUpdateID, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation); while (index < memState.Count && NetIdUtils.IdMoreRecent(posInfo.ID, memState[index].ID)) index++; @@ -251,11 +244,7 @@ namespace Barotrauma } else { - var posInfo = new CharacterStateInfo( - pos, rotation, - linearVelocity, angularVelocity, - sendingTime, facingRight ? Direction.Right : Direction.Left, - selectedCharacter, selectedItem, animation); + var posInfo = new CharacterStateInfo(pos, rotation, linearVelocity, angularVelocity, sendingTime, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation); while (index < memState.Count && posInfo.Timestamp > memState[index].Timestamp) index++; diff --git a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs index 697d8f31d..b993f7deb 100644 --- a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs @@ -773,12 +773,20 @@ namespace Barotrauma commands.Add(new Command("checkcrafting", "checkcrafting: Checks item deconstruction & crafting recipes for inconsistencies.", (string[] args) => { - List fabricableItems = new List(); + List fabricableItems = new List(); foreach (MapEntityPrefab mapEntityPrefab in MapEntityPrefab.List) { if (mapEntityPrefab is ItemPrefab itemPrefab) { - fabricableItems.AddRange(itemPrefab.FabricationRecipes); + var fabricatorElement = itemPrefab.ConfigElement.Element("Fabricator"); + if (fabricatorElement == null) { continue; } + + foreach (XElement element in fabricatorElement.Elements()) + { + if (element.Name.ToString().ToLowerInvariant() != "fabricableitem") { continue; } + fabricableItems.Add(new FabricableItem(element)); + } + } } foreach (MapEntityPrefab mapEntityPrefab in MapEntityPrefab.List) @@ -954,6 +962,8 @@ namespace Barotrauma } } } + element.Value = lines[i]; + i++; } }, isCheat: false)); #endif diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/ContextualTutorial.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/ContextualTutorial.cs index 292f85b37..6eb4648fe 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/ContextualTutorial.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/Tutorials/ContextualTutorial.cs @@ -624,9 +624,10 @@ namespace Barotrauma.Tutorials private Character CrewMemberWithJob(string job) { + job = job.ToLowerInvariant(); for (int i = 0; i < crew.Count; i++) { - if (crew[i].Info.Job.Name == job) return crew[i]; + if (crew[i].Info.Job.Name.ToLowerInvariant() == job) return crew[i]; } return null; diff --git a/Barotrauma/BarotraumaClient/Source/GameSettings.cs b/Barotrauma/BarotraumaClient/Source/GameSettings.cs index 96d604bff..6205c6796 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSettings.cs @@ -72,9 +72,9 @@ namespace Barotrauma private void CreateSettingsFrame() { - settingsFrame = new GUIFrame(new RectTransform(new Vector2(0.8f, 0.8f), GUI.Canvas, Anchor.Center)); + settingsFrame = new GUIFrame(new RectTransform(new Point(1024, 768), GUI.Canvas, Anchor.Center)); - var settingsFramePadding = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.9f), settingsFrame.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.05f) }) { RelativeSpacing = 0.01f, IsHorizontal = true }; + var settingsFramePadding = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), settingsFrame.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.05f) }, style: null); /// General tab -------------------------------------------------------------- @@ -85,16 +85,16 @@ namespace Barotrauma var generalLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), leftPanel.RectTransform, Anchor.TopLeft)); - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), generalLayoutGroup.RectTransform), TextManager.Get("ContentPackages")); + //new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), generalLayoutGroup.RectTransform), TextManager.Get("ContentPackages")); var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.75f), generalLayoutGroup.RectTransform)) { - CanBeFocused = false, - ScrollBarVisible = true + CanBeFocused = false }; + foreach (ContentPackage contentPackage in ContentPackage.List) { - var tickBox = new GUITickBox(new RectTransform(new Vector2(0.05f, 0.05f), contentPackageList.Content.RectTransform, minSize: new Point(32, 32)), contentPackage.Name) + var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.067f), contentPackageList.Content.RectTransform, minSize: new Point(0, 15)), contentPackage.Name) { UserData = contentPackage, OnSelected = SelectContentPackage, @@ -119,8 +119,8 @@ namespace Barotrauma } } - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.045f), generalLayoutGroup.RectTransform), TextManager.Get("Language")); - var languageDD = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.045f), generalLayoutGroup.RectTransform)); + new GUITextBlock(new RectTransform(new Vector2(0.92f, 0.05f), generalLayoutGroup.RectTransform), TextManager.Get("Language")); + var languageDD = new GUIDropDown(new RectTransform(new Vector2(0.92f, 0.05f), generalLayoutGroup.RectTransform)); foreach (string language in TextManager.AvailableLanguages) { languageDD.AddItem(TextManager.Get("Language." + language), language); @@ -139,8 +139,8 @@ namespace Barotrauma return true; }; - var rightPanel = new GUILayoutGroup(new RectTransform(new Vector2(0.99f - leftPanel.RectTransform.RelativeSize.X, 0.95f), - settingsFramePadding.RectTransform, Anchor.TopLeft)); + var rightPanel = new GUILayoutGroup(new RectTransform(new Vector2(1.0f - leftPanel.RectTransform.RelativeSize.X, 0.95f), + settingsFramePadding.RectTransform, Anchor.TopRight)); var tabButtonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.05f), rightPanel.RectTransform, Anchor.TopCenter), isHorizontal: true); @@ -239,7 +239,7 @@ namespace Barotrauma return true; }; - GUITickBox vsyncTickBox = new GUITickBox(new RectTransform(new Point(32, 32), leftColumn.RectTransform), TextManager.Get("EnableVSync")) + GUITickBox vsyncTickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), TextManager.Get("EnableVSync")) { ToolTip = TextManager.Get("EnableVSyncToolTip"), OnSelected = (GUITickBox box) => @@ -308,7 +308,7 @@ namespace Barotrauma }; lightScrollBar.OnMoved(lightScrollBar, lightScrollBar.BarScroll); - new GUITickBox(new RectTransform(new Point(32, 32), rightColumn.RectTransform), TextManager.Get("SpecularLighting")) + new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("SpecularLighting")) { ToolTip = TextManager.Get("SpecularLightingToolTip"), Selected = SpecularityEnabled, @@ -320,7 +320,7 @@ namespace Barotrauma } }; - new GUITickBox(new RectTransform(new Point(32, 32), rightColumn.RectTransform), TextManager.Get("ChromaticAberration")) + new GUITickBox(new RectTransform(new Vector2(1.0f, 0.05f), rightColumn.RectTransform), TextManager.Get("ChromaticAberration")) { ToolTip = TextManager.Get("ChromaticAberrationToolTip"), Selected = ChromaticAberrationEnabled, @@ -370,11 +370,11 @@ namespace Barotrauma var audioSliders = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.4f), tabs[(int)Tab.Audio].RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.02f) }) - { RelativeSpacing = 0.01f }; + { RelativeSpacing = 0.01f, Stretch = true }; - GUITextBlock soundVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), TextManager.Get("SoundVolume")); - GUIScrollBar soundScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), - barSize: 0.05f) + GUITextBlock soundVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), audioSliders.RectTransform), TextManager.Get("SoundVolume")); + GUIScrollBar soundScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.2f), audioSliders.RectTransform), + barSize: 0.1f) { UserData = soundVolumeText, BarScroll = SoundVolume, @@ -388,9 +388,9 @@ namespace Barotrauma }; soundScrollBar.OnMoved(soundScrollBar, soundScrollBar.BarScroll); - GUITextBlock musicVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), TextManager.Get("MusicVolume")); - GUIScrollBar musicScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), - barSize: 0.05f) + GUITextBlock musicVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.18f), audioSliders.RectTransform), TextManager.Get("MusicVolume")); + GUIScrollBar musicScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.18f), audioSliders.RectTransform), + barSize: 0.1f) { UserData = musicVolumeText, BarScroll = MusicVolume, @@ -404,9 +404,9 @@ namespace Barotrauma }; musicScrollBar.OnMoved(musicScrollBar, musicScrollBar.BarScroll); - GUITextBlock voiceChatVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), TextManager.Get("VoiceChatVolume")); - GUIScrollBar voiceChatScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), - barSize: 0.05f) + GUITextBlock voiceChatVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.18f), audioSliders.RectTransform), TextManager.Get("VoiceChatVolume")); + GUIScrollBar voiceChatScrollBar = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.18f), audioSliders.RectTransform), + barSize: 0.1f) { UserData = voiceChatVolumeText, BarScroll = VoiceChatVolume, @@ -420,7 +420,7 @@ namespace Barotrauma }; voiceChatScrollBar.OnMoved(voiceChatScrollBar, voiceChatScrollBar.BarScroll); - GUITickBox muteOnFocusLostBox = new GUITickBox(new RectTransform(new Point(32, 32), audioSliders.RectTransform), TextManager.Get("MuteOnFocusLost")); + GUITickBox muteOnFocusLostBox = new GUITickBox(new RectTransform(new Vector2(0.95f, 0.15f), audioSliders.RectTransform), TextManager.Get("MuteOnFocusLost")); muteOnFocusLostBox.Selected = MuteOnFocusLost; muteOnFocusLostBox.ToolTip = TextManager.Get("MuteOnFocusLostToolTip"); muteOnFocusLostBox.OnSelected = (tickBox) => @@ -429,8 +429,15 @@ namespace Barotrauma return true; }; - - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), TextManager.Get("VoiceChat")); + + var voiceSettings = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.5f), tabs[(int)Tab.Audio].RectTransform, Anchor.BottomCenter) + { RelativeOffset = new Vector2(0.0f, 0.04f) }) + { RelativeSpacing = 0.01f, Stretch = true }; + + new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), voiceSettings.RectTransform), TextManager.Get("VoiceChat")); + + //spacing + new GUIFrame(new RectTransform(new Vector2(1.0f, 0.2f), rightColumn.RectTransform), style: null); IList deviceNames = Alc.GetString((IntPtr)null, AlcGetStringList.CaptureDeviceSpecifier); foreach (string name in deviceNames) @@ -440,7 +447,7 @@ namespace Barotrauma if (string.IsNullOrWhiteSpace(VoiceCaptureDevice)) VoiceCaptureDevice = deviceNames[0]; #if (!OSX) - var deviceList = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), VoiceCaptureDevice, deviceNames.Count); + var deviceList = new GUIDropDown(new RectTransform(new Vector2(1.0f, 0.2f), voiceSettings.RectTransform), VoiceCaptureDevice, deviceNames.Count); foreach (string name in deviceNames) { deviceList.AddItem(name, name); @@ -454,13 +461,13 @@ namespace Barotrauma return true; }; #else - var suavemente = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), TextManager.Get("CurrentDevice") + ": " + VoiceCaptureDevice) + var suavemente = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.2f), voiceSettings.RectTransform), TextManager.Get("CurrentDevice") + ": " + VoiceCaptureDevice) { ToolTip = TextManager.Get("CurrentDeviceToolTip.OSX"), TextAlignment = Alignment.CenterX }; - new GUIButton(new RectTransform(new Vector2(1.0f, 0.25f), audioSliders.RectTransform), TextManager.Get("RefreshDefaultDevice")) + new GUIButton(new RectTransform(new Vector2(1.0f, 0.25f), voiceSettings.RectTransform), TextManager.Get("RefreshDefaultDevice")) { ToolTip = TextManager.Get("RefreshDefaultDeviceToolTip"), OnClicked = (bt, userdata) => @@ -476,16 +483,17 @@ namespace Barotrauma } }; #endif - var radioButtonFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.6f), audioSliders.RectTransform)) + var radioButtonFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.6f), voiceSettings.RectTransform)) { - RelativeSpacing = 0.01f + Stretch = true, + RelativeSpacing = 0.05f }; GUIRadioButtonGroup voiceMode = new GUIRadioButtonGroup(); for (int i = 0; i < 3; i++) { string langStr = "VoiceMode." + ((VoiceMode)i).ToString(); - var tick = new GUITickBox(new RectTransform(new Point(32, 32), radioButtonFrame.RectTransform), TextManager.Get(langStr)) + var tick = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.33f), radioButtonFrame.RectTransform), TextManager.Get(langStr)) { ToolTip = TextManager.Get(langStr + "ToolTip") }; @@ -493,9 +501,9 @@ namespace Barotrauma voiceMode.AddRadioButton((VoiceMode)i, tick); } - var micVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), TextManager.Get("MicrophoneVolume")); - var micVolumeSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.1f), audioSliders.RectTransform), - barSize: 0.05f) + var micVolumeText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.18f), voiceSettings.RectTransform), TextManager.Get("MicrophoneVolume")); + var micVolumeSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.18f), voiceSettings.RectTransform), + barSize: 0.1f) { UserData = micVolumeText, BarScroll = (float)Math.Sqrt(MathUtils.InverseLerp(0.2f, 5.0f, MicrophoneVolume)), @@ -511,9 +519,9 @@ namespace Barotrauma }; micVolumeSlider.OnMoved(micVolumeSlider, micVolumeSlider.BarScroll); - var voiceInputContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.25f), audioSliders.RectTransform, Anchor.BottomCenter)); - new GUITextBlock(new RectTransform(new Vector2(0.6f, 0.5f), voiceInputContainer.RectTransform), TextManager.Get("InputType.Voice") + ": "); - var voiceKeyBox = new GUITextBox(new RectTransform(new Vector2(0.4f, 0.5f), voiceInputContainer.RectTransform, Anchor.TopRight), + var voiceInputContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.2f), voiceSettings.RectTransform, Anchor.BottomCenter)); + new GUITextBlock(new RectTransform(new Vector2(0.6f, 1.0f), voiceInputContainer.RectTransform), TextManager.Get("InputType.Voice") + ": "); + var voiceKeyBox = new GUITextBox(new RectTransform(new Vector2(0.4f, 1.0f), voiceInputContainer.RectTransform, Anchor.TopRight), text: keyMapping[(int)InputType.Voice].ToString()) { UserData = InputType.Voice @@ -521,7 +529,7 @@ namespace Barotrauma voiceKeyBox.OnSelected += KeyBoxSelected; voiceKeyBox.SelectedColor = Color.Gold * 0.3f; - var voiceActivityGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.25f), audioSliders.RectTransform)); + var voiceActivityGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.3f), voiceSettings.RectTransform)); GUITextBlock noiseGateText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), voiceActivityGroup.RectTransform), TextManager.Get("NoiseGateThreshold")) { TextGetter = () => @@ -592,19 +600,20 @@ namespace Barotrauma voiceMode.Selected = VoiceSetting; /// Controls tab ------------------------------------------------------------- - var controlsLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), tabs[(int)Tab.Controls].RectTransform, Anchor.Center)) - { RelativeSpacing = 0.01f }; + var controlsLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), tabs[(int)Tab.Controls].RectTransform, Anchor.Center) + { RelativeOffset = new Vector2(0.0f, 0.0f) }) + { RelativeSpacing = 0.01f, Stretch = true }; var inputFrame = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.8f), controlsLayoutGroup.RectTransform)) - { Stretch = true }; - + { + Stretch = true + }; var inputNames = Enum.GetValues(typeof(InputType)); for (int i = 0; i < inputNames.Length; i++) { var inputContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.06f), inputFrame.RectTransform)) { Stretch = true, IsHorizontal = true, RelativeSpacing = 0.05f }; - new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), inputContainer.RectTransform, Anchor.TopLeft) { MinSize = new Point(150, 0) }, - TextManager.Get("InputType." + ((InputType)i)) + ": ", font: GUI.SmallFont) { ForceUpperCase = true }; - var keyBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), inputContainer.RectTransform), + new GUITextBlock(new RectTransform(new Vector2(0.25f, 1.0f), inputContainer.RectTransform, Anchor.TopLeft), TextManager.Get("InputType." + ((InputType)i)) + ": ", font: GUI.SmallFont) { ForceUpperCase = true }; + var keyBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), inputContainer.RectTransform), text: keyMapping[i].ToString(), font: GUI.SmallFont) { UserData = i @@ -614,7 +623,7 @@ namespace Barotrauma } GUITextBlock aimAssistText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), controlsLayoutGroup.RectTransform), TextManager.Get("AimAssist")); GUIScrollBar aimAssistSlider = new GUIScrollBar(new RectTransform(new Vector2(1.0f, 0.05f), controlsLayoutGroup.RectTransform), - barSize: 0.05f) + barSize: 0.1f) { UserData = aimAssistText, BarScroll = MathUtils.InverseLerp(0.0f, 5.0f, AimAssistAmount), @@ -632,7 +641,7 @@ namespace Barotrauma 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"), style: "GUIButtonLarge") + TextManager.Get("Cancel")) { IgnoreLayoutGroups = true, OnClicked = (x, y) => @@ -648,7 +657,7 @@ namespace Barotrauma }; applyButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomRight), - TextManager.Get("ApplySettingsButton"), style: "GUIButtonLarge") + TextManager.Get("ApplySettingsButton")) { IgnoreLayoutGroups = true, Enabled = false diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs index e074796e4..84c7eef11 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Fabricator.cs @@ -20,7 +20,7 @@ namespace Barotrauma.Items.Components private GUIComponent inputInventoryHolder, outputInventoryHolder; private GUICustomComponent inputInventoryOverlay, outputInventoryOverlay; - private FabricationRecipe selectedItem; + private FabricableItem selectedItem; private GUIComponent inSufficientPowerWarning; @@ -38,7 +38,7 @@ namespace Barotrauma.Items.Components { OnSelected = (GUIComponent component, object userdata) => { - selectedItem = userdata as FabricationRecipe; + selectedItem = userdata as FabricableItem; if (selectedItem != null) { SelectItem(Character.Controlled, selectedItem); } return true; } @@ -59,7 +59,7 @@ namespace Barotrauma.Items.Components CanBeFocused = false }; - foreach (FabricationRecipe fi in fabricationRecipes) + foreach (FabricableItem fi in fabricableItems) { GUIFrame frame = new GUIFrame(new RectTransform(new Point(itemList.Rect.Width, 50), itemList.Content.RectTransform), style: null) { @@ -115,13 +115,13 @@ namespace Barotrauma.Items.Components partial void SelectProjSpecific(Character character) { - var nonItems = itemList.Content.Children.Where(c => !(c.UserData is FabricationRecipe)).ToList(); + var nonItems = itemList.Content.Children.Where(c => !(c.UserData is FabricableItem)).ToList(); nonItems.ForEach(i => itemList.Content.RemoveChild(i)); itemList.Content.RectTransform.SortChildren((c1, c2) => { - var item1 = c1.GUIComponent.UserData as FabricationRecipe; - var item2 = c2.GUIComponent.UserData as FabricationRecipe; + var item1 = c1.GUIComponent.UserData as FabricableItem; + var item2 = c2.GUIComponent.UserData as FabricableItem; bool hasSkills1 = DegreeOfSuccess(character, item1.RequiredSkills) >= 0.5f; bool hasSkills2 = DegreeOfSuccess(character, item2.RequiredSkills) >= 0.5f; @@ -144,7 +144,7 @@ namespace Barotrauma.Items.Components { CanBeFocused = false }; - var firstinSufficient = itemList.Content.Children.FirstOrDefault(c => c.UserData is FabricationRecipe fabricableItem && DegreeOfSuccess(character, fabricableItem.RequiredSkills) < 0.5f); + var firstinSufficient = itemList.Content.Children.FirstOrDefault(c => c.UserData is FabricableItem fabricableItem && DegreeOfSuccess(character, fabricableItem.RequiredSkills) < 0.5f); if (firstinSufficient != null) { insufficientSkillsText.RectTransform.RepositionChildInHierarchy(itemList.Content.RectTransform.GetChildIndex(firstinSufficient.RectTransform)); @@ -155,13 +155,13 @@ namespace Barotrauma.Items.Components { overlayComponent.RectTransform.SetAsLastChild(); - FabricationRecipe targetItem = fabricatedItem ?? selectedItem; + FabricableItem targetItem = fabricatedItem ?? selectedItem; if (targetItem != null) { int slotIndex = 0; - var missingItems = new List(); - foreach (FabricationRecipe.RequiredItem requiredItem in targetItem.RequiredItems) + var missingItems = new List(); + foreach (FabricableItem.RequiredItem requiredItem in targetItem.RequiredItems) { for (int i = 0; i < requiredItem.Amount; i++) { @@ -176,7 +176,7 @@ namespace Barotrauma.Items.Components var availableIngredients = GetAvailableIngredients(); - foreach (FabricationRecipe.RequiredItem requiredItem in missingItems) + foreach (FabricableItem.RequiredItem requiredItem in missingItems) { //highlight suitable ingredients in linked inventories foreach (Item item in availableIngredients) @@ -230,7 +230,7 @@ namespace Barotrauma.Items.Components { overlayComponent.RectTransform.SetAsLastChild(); - FabricationRecipe targetItem = fabricatedItem ?? selectedItem; + FabricableItem targetItem = fabricatedItem ?? selectedItem; if (targetItem != null) { var itemIcon = targetItem.TargetItem.InventoryIcon ?? targetItem.TargetItem.sprite; @@ -257,7 +257,7 @@ namespace Barotrauma.Items.Components } } - private bool SelectItem(Character user, FabricationRecipe selectedItem) + private bool SelectItem(Character user, FabricableItem selectedItem) { selectedItemFrame.ClearChildren(); @@ -354,7 +354,7 @@ namespace Barotrauma.Items.Components { foreach (GUIComponent child in itemList.Content.Children) { - var itemPrefab = child.UserData as FabricationRecipe; + var itemPrefab = child.UserData as FabricableItem; if (itemPrefab == null) continue; bool canBeFabricated = CanBeFabricated(itemPrefab, availableIngredients); @@ -377,7 +377,7 @@ namespace Barotrauma.Items.Components public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { - int itemIndex = msg.ReadRangedInteger(-1, fabricationRecipes.Count - 1); + int itemIndex = msg.ReadRangedInteger(-1, fabricableItems.Count - 1); UInt16 userID = msg.ReadUInt16(); Character user = Entity.FindEntityByID(userID) as Character; @@ -391,8 +391,8 @@ namespace Barotrauma.Items.Components if (fabricatedItem != null && fabricationRecipes.IndexOf(fabricatedItem) == itemIndex) return; if (itemIndex < 0 || itemIndex >= fabricationRecipes.Count) return; - SelectItem(user, fabricationRecipes[itemIndex]); - StartFabricating(fabricationRecipes[itemIndex], user); + SelectItem(user, fabricableItems[itemIndex]); + StartFabricating(fabricableItems[itemIndex], user); } } } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Sonar.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Sonar.cs index 9cc203358..a4935fd62 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Sonar.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Sonar.cs @@ -44,9 +44,7 @@ namespace Barotrauma.Items.Components private float displayScale; private float zoomSqrt; - - private float showDirectionalIndicatorTimer; - + //Vector2 = vector from the ping source to the position of the disruption //float = strength of the disruption, between 0-1 List> disruptedDirections = new List>(); @@ -147,7 +145,6 @@ namespace Barotrauma.Items.Components { OnMoved = (scrollbar, scroll) => { - showDirectionalIndicatorTimer = 1.0f; float pingAngle = MathHelper.Lerp(0.0f, MathHelper.TwoPi, scroll); pingDirection = new Vector2((float)Math.Cos(pingAngle), (float)Math.Sin(pingAngle)); if (GameMain.Client != null) @@ -178,7 +175,6 @@ namespace Barotrauma.Items.Components public override void UpdateHUD(Character character, float deltaTime, Camera cam) { - showDirectionalIndicatorTimer -= deltaTime; if (GameMain.Client != null) { if (unsentChanges) @@ -382,13 +378,12 @@ namespace Barotrauma.Items.Components spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); } - float directionalPingVisibility = useDirectionalPing && IsActive ? 1.0f : showDirectionalIndicatorTimer; - if (directionalPingVisibility > 0.0f) + if (useDirectionalPing && IsActive) { Vector2 sector1 = MathUtils.RotatePointAroundTarget(pingDirection * DisplayRadius, Vector2.Zero, DirectionalPingSector * 0.5f); Vector2 sector2 = MathUtils.RotatePointAroundTarget(pingDirection * DisplayRadius, Vector2.Zero, -DirectionalPingSector * 0.5f); - GUI.DrawLine(spriteBatch, center, center + sector1, Color.LightCyan * 0.2f * directionalPingVisibility, width: 3); - GUI.DrawLine(spriteBatch, center, center + sector2, Color.LightCyan * 0.2f * directionalPingVisibility, width: 3); + GUI.DrawLine(spriteBatch, center, center + sector1, Color.LightCyan * 0.2f, width: 3); + GUI.DrawLine(spriteBatch, center, center + sector2, Color.LightCyan * 0.2f, width: 3); } if (GameMain.DebugDraw) diff --git a/Barotrauma/BarotraumaClient/Source/Items/ItemInventory.cs b/Barotrauma/BarotraumaClient/Source/Items/ItemInventory.cs index 6ef97a119..8f2aa6359 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/ItemInventory.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/ItemInventory.cs @@ -11,16 +11,19 @@ namespace Barotrauma protected override void ControlInput(Camera cam) { base.ControlInput(cam); - cam.OffsetAmount = 0; - //if this is used, we need to implement syncing this inventory with the server - /*Character.DisableControls = true; - if (Character.Controlled != null) + if (BackgroundFrame.Contains(PlayerInput.MousePosition)) { - if (PlayerInput.KeyHit(InputType.Select)) + cam.OffsetAmount = 0; + //if this is used, we need to implement syncing this inventory with the server + /*Character.DisableControls = true; + if (Character.Controlled != null) { - Character.Controlled.SelectedConstruction = null; - } - }*/ + if (PlayerInput.KeyHit(InputType.Select)) + { + Character.Controlled.SelectedConstruction = null; + } + }*/ + } } protected override void CalculateBackgroundFrame() diff --git a/Barotrauma/BarotraumaClient/Source/Map/Lights/ConvexHull.cs b/Barotrauma/BarotraumaClient/Source/Map/Lights/ConvexHull.cs index 1cbf20833..c3fcd386c 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Lights/ConvexHull.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Lights/ConvexHull.cs @@ -100,13 +100,17 @@ namespace Barotrauma.Lights private readonly bool[] backFacing; private readonly bool[] ignoreEdge; - private readonly bool isHorizontal; + private MapEntity parentEntity; public VertexPositionColor[] ShadowVertices { get; private set; } public VertexPositionTexture[] PenumbraVertices { get; private set; } public int ShadowVertexCount { get; private set; } - public MapEntity ParentEntity { get; private set; } + public MapEntity ParentEntity + { + get { return parentEntity; } + + } private bool enabled; public bool Enabled @@ -132,8 +136,11 @@ namespace Barotrauma.Lights private set; } - public Rectangle BoundingBox { get; private set; } - + public Rectangle BoundingBox + { + get { return boundingBox; } + } + public ConvexHull(Vector2[] points, Color color, MapEntity parent) { if (shadowEffect == null) @@ -155,13 +162,17 @@ namespace Barotrauma.Lights ParentEntity = parent; - ShadowVertices = new VertexPositionColor[6 * 2]; - PenumbraVertices = new VertexPositionTexture[6]; + //cachedShadows = new Dictionary(); + + shadowVertices = new VertexPositionColor[6 * 2]; + penumbraVertices = new VertexPositionTexture[6]; backFacing = new bool[4]; ignoreEdge = new bool[4]; - SetVertices(points); + //vertices = points; + SetVertices(points); + //CalculateDimensions(); Enabled = true; @@ -195,46 +206,30 @@ namespace Barotrauma.Lights private void MergeOverlappingSegments(ConvexHull ch) { if (ch == this) return; - - if (isHorizontal == ch.isHorizontal) + + //hide segments that are roughly at the some position as some other segment (e.g. the ends of two adjacent wall pieces) + //TODO: prevent "gaps" between shadows when the segments are not exactly at the same position (see the hatches in Humpback for example) + /*float mergeDist = 16; + float mergeDistSqr = mergeDist * mergeDist; + for (int i = 0; i < segments.Length; i++) { - //hide segments that are roughly at the some position as some other segment (e.g. the ends of two adjacent wall pieces) - float mergeDist = 32; - float mergeDistSqr = mergeDist * mergeDist; - for (int i = 0; i < segments.Length; i++) + for (int j = 0; j < ch.segments.Length; j++) { - for (int j = 0; j < ch.segments.Length; j++) + if (Vector2.DistanceSquared(segments[i].Start.Pos, ch.segments[j].Start.Pos) < mergeDistSqr && + Vector2.DistanceSquared(segments[i].End.Pos, ch.segments[j].End.Pos) < mergeDistSqr) { - if (segments[i].IsHorizontal != ch.segments[j].IsHorizontal) { continue; } - - //the segments must be at different sides of the convex hulls to be merged - //(e.g. the right edge of a wall piece and the left edge of another one) - var segment1Center = (segments[i].Start.Pos + segments[i].End.Pos) / 2.0f; - var segment2Center = (ch.segments[j].Start.Pos + ch.segments[j].End.Pos) / 2.0f; - if (Vector2.Dot(segment1Center - BoundingBox.Center.ToVector2(), segment2Center - ch.BoundingBox.Center.ToVector2()) > 0) { continue; } - - if (Vector2.DistanceSquared(segments[i].Start.Pos, ch.segments[j].Start.Pos) < mergeDistSqr && - Vector2.DistanceSquared(segments[i].End.Pos, ch.segments[j].End.Pos) < mergeDistSqr) - { - ignoreEdge[i] = true; - ch.ignoreEdge[j] = true; - MergeSegments(segments[i], ch.segments[j], true); - } - else if (Vector2.DistanceSquared(segments[i].Start.Pos, ch.segments[j].End.Pos) < mergeDistSqr && - Vector2.DistanceSquared(segments[i].End.Pos, ch.segments[j].Start.Pos) < mergeDistSqr) - { - ignoreEdge[i] = true; - ch.ignoreEdge[j] = true; - MergeSegments(segments[i], ch.segments[j], false); - } - } + ignoreEdge[i] = true; + ch.ignoreEdge[j] = true; + } + else if (Vector2.DistanceSquared(segments[i].Start.Pos, ch.segments[j].End.Pos) < mergeDistSqr && + Vector2.DistanceSquared(segments[i].End.Pos, ch.segments[j].Start.Pos) < mergeDistSqr) + { + ignoreEdge[i] = true; + ch.ignoreEdge[j] = true; + } } - } - else - { - //TODO: do something to corner areas where a vertical wall meets a horizontal one - } - + }*/ + //ignore edges that are inside some other convex hull for (int i = 0; i < vertices.Length; i++) { @@ -252,44 +247,6 @@ namespace Barotrauma.Lights } } - private void MergeSegments(Segment segment1, Segment segment2, bool startPointsMatch) - { - int startPointIndex = -1, endPointIndex = -1; - for (int i = 0; i < vertices.Length; i++) - { - if (vertices[i].Pos.NearlyEquals(segment1.Start.Pos)) - startPointIndex = i; - else if (vertices[i].Pos.NearlyEquals(segment1.End.Pos)) - endPointIndex = i; - } - if (startPointIndex == -1 || endPointIndex == -1) { return; } - - int startPoint2Index = -1, endPoint2Index = -1; - for (int i = 0; i < segment2.ConvexHull.vertices.Length; i++) - { - if (segment2.ConvexHull.vertices[i].Pos.NearlyEquals(segment2.Start.Pos)) - startPoint2Index = i; - else if (segment2.ConvexHull.vertices[i].Pos.NearlyEquals(segment2.End.Pos)) - endPoint2Index = i; - } - if (startPoint2Index == -1 || endPoint2Index == -1) { return; } - - if (startPointsMatch) - { - losVertices[startPointIndex].Pos = segment2.ConvexHull.losVertices[startPoint2Index].Pos = - (segment1.Start.Pos + segment2.Start.Pos) / 2.0f; - losVertices[endPointIndex].Pos = segment2.ConvexHull.losVertices[endPoint2Index].Pos = - (segment1.End.Pos + segment2.End.Pos) / 2.0f; - } - else - { - losVertices[startPointIndex].Pos = segment2.ConvexHull.losVertices[startPoint2Index].Pos = - (segment1.Start.Pos + segment2.End.Pos) / 2.0f; - losVertices[endPointIndex].Pos = segment2.ConvexHull.losVertices[endPoint2Index].Pos = - (segment1.End.Pos + segment2.Start.Pos) / 2.0f; - } - } - public void Rotate(Vector2 origin, float amount) { Matrix rotationMatrix = @@ -348,6 +305,11 @@ namespace Barotrauma.Lights ignoreEdge[i] = false; } + for (int i = 0; i < 4; i++) + { + ignoreEdge[i] = false; + } + int margin = 0; if (Math.Abs(points[0].X - points[2].X) < Math.Abs(points[0].Y - points[2].Y)) { @@ -381,7 +343,11 @@ namespace Barotrauma.Lights if (ParentEntity == null) return; - var chList = HullLists.Find(x => x.Submarine == ParentEntity.Submarine); + CalculateDimensions(); + + if (parentEntity == null) return; + + var chList = HullLists.Find(x => x.Submarine == parentEntity.Submarine); if (chList != null) { foreach (ConvexHull ch in chList.List) @@ -407,7 +373,7 @@ namespace Barotrauma.Lights /// /// Returns the segments that are facing towards viewPosition /// - public void GetVisibleSegments(Vector2 viewPosition, List visibleSegments, bool ignoreEdges) + public void GetVisibleSegments(Vector2 viewPosition, List visibleSegments) { for (int i = 0; i < 4; i++) { @@ -440,12 +406,12 @@ namespace Barotrauma.Lights segments[i].Start.WorldPos = segments[i].Start.Pos; segments[i].End.WorldPos = segments[i].End.Pos; } - if (ParentEntity == null || ParentEntity.Submarine == null) { return; } + if (parentEntity == null || parentEntity.Submarine == null) { return; } for (int i = 0; i < 4; i++) { - vertices[i].WorldPos += ParentEntity.Submarine.DrawPosition; - segments[i].Start.WorldPos += ParentEntity.Submarine.DrawPosition; - segments[i].End.WorldPos += ParentEntity.Submarine.DrawPosition; + vertices[i].WorldPos += parentEntity.Submarine.DrawPosition; + segments[i].Start.WorldPos += parentEntity.Submarine.DrawPosition; + segments[i].End.WorldPos += parentEntity.Submarine.DrawPosition; } } diff --git a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs index 9ff808757..cbc9ac0e1 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Lights/LightSource.cs @@ -453,7 +453,7 @@ namespace Barotrauma.Lights foreach (ConvexHull hull in hulls) { hull.RefreshWorldPositions(); - hull.GetVisibleSegments(drawPos, visibleSegments, ignoreEdges: false); + hull.GetVisibleSegments(drawPos, visibleSegments); } //Generate new points at the intersections between segments diff --git a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs index 6041de872..0e5dc2aed 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs @@ -278,22 +278,19 @@ namespace Barotrauma OnClicked = (btn, userdata) => { if (GUI.MouseOn == btn || GUI.MouseOn == btn.TextBlock) messageBox.Close(); return true; } }; background.RectTransform.SetAsFirstChild(); - CreatePreviewWindow(messageBox.Content); - } - public void CreatePreviewWindow(GUIComponent parent) - { - var upperPart = new GUILayoutGroup(new RectTransform(new Vector2(1, 0.4f), parent.RectTransform, Anchor.Center, Pivot.BottomCenter)); - var descriptionBox = new GUIListBox(new RectTransform(new Vector2(1, 0.35f), parent.RectTransform, Anchor.Center, Pivot.TopCenter)) { ScrollBarVisible = true }; + new GUITextBlock(new RectTransform(new Vector2(1, 0), messageBox.Content.RectTransform, Anchor.TopCenter), Name, textAlignment: Alignment.Center, font: GUI.LargeFont, wrap: true); + + var upperPart = new GUIFrame(new RectTransform(new Vector2(1, 0.4f), messageBox.Content.RectTransform, Anchor.Center, Pivot.BottomCenter), color: Color.Transparent); + var descriptionBox = new GUIListBox(new RectTransform(new Vector2(1, 0.35f), messageBox.Content.RectTransform, Anchor.Center, Pivot.TopCenter)); if (PreviewImage == null) { - new GUITextBlock(new RectTransform(new Vector2(1.0f, 1), upperPart.RectTransform), TextManager.Get("SubPreviewImageNotFound")); + new GUITextBlock(new RectTransform(new Vector2(0.45f, 1), upperPart.RectTransform), TextManager.Get("SubPreviewImageNotFound")); } else { - var submarinePreviewBackground = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), upperPart.RectTransform)) { Color = Color.Black }; - new GUIImage(new RectTransform(new Vector2(1.0f, 1.0f), submarinePreviewBackground.RectTransform), PreviewImage, scaleToFit: true); + new GUIImage(new RectTransform(new Vector2(0.45f, 1), upperPart.RectTransform), PreviewImage); } Vector2 realWorldDimensions = Dimensions * Physics.DisplayToRealWorldRatio; @@ -301,42 +298,30 @@ namespace Barotrauma TextManager.Get("Unknown") : TextManager.Get("DimensionsFormat").Replace("[width]", ((int)(realWorldDimensions.X)).ToString()).Replace("[height]", ((int)(realWorldDimensions.Y)).ToString()); - new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), Name, font: GUI.LargeFont, wrap: true) { ForceUpperCase = true, CanBeFocused = false }; + var layoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.45f, 1), upperPart.RectTransform, Anchor.TopRight)); - new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), + new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform), $"{TextManager.Get("Dimensions")}: {dimensionsStr}", - font: GUI.Font, wrap: true) - { CanBeFocused = false }; + font: GUI.SmallFont, wrap: true); - new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), + new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform), $"{TextManager.Get("RecommendedCrewSize")}: {(RecommendedCrewSizeMax == 0 ? TextManager.Get("Unknown") : RecommendedCrewSizeMin + " - " + RecommendedCrewSizeMax)}", - font: GUI.Font, wrap: true) - { CanBeFocused = false }; + font: GUI.SmallFont, wrap: true); - new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), + new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform), $"{TextManager.Get("RecommendedCrewExperience")}: {(string.IsNullOrEmpty(RecommendedCrewExperience) ? TextManager.Get("unknown") : TextManager.Get(RecommendedCrewExperience))}", - font: GUI.Font, wrap: true) - { CanBeFocused = false }; + font: GUI.SmallFont, wrap: true); - new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), - $"{TextManager.Get("RequiredContentPackages")}: {string.Join(", ", RequiredContentPackages)}", - font: GUI.Font, wrap: true) - { CanBeFocused = false }; - - //space - new GUIFrame(new RectTransform(new Vector2(1.0f, 0.05f), descriptionBox.Content.RectTransform), style: null); - - if (Description.Length != 0) - { - new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), TextManager.Get("SaveSubDialogDescription") + ":", font: GUI.Font, wrap: true) { CanBeFocused = false, ForceUpperCase = true }; - } - - new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform), Description, font: GUI.Font, wrap: true) + new GUITextBlock(new RectTransform(new Vector2(1, 0), layoutGroup.RectTransform), + $"{TextManager.Get("RequiredContentPackages")}: {string.Join(", ", RequiredContentPackages)}", + font: GUI.SmallFont, wrap: true); + + new GUITextBlock(new RectTransform(new Vector2(1, 0), descriptionBox.Content.RectTransform, Anchor.TopLeft), Description, font: GUI.SmallFont, wrap: true) { CanBeFocused = false }; } - + public void CreateMiniMap(GUIComponent parent, IEnumerable pointsOfInterest = null) { Rectangle worldBorders = GetDockedBorders(); diff --git a/Barotrauma/BarotraumaClient/Source/Physics/PhysicsBody.cs b/Barotrauma/BarotraumaClient/Source/Physics/PhysicsBody.cs index 88e1011e8..f231c83a0 100644 --- a/Barotrauma/BarotraumaClient/Source/Physics/PhysicsBody.cs +++ b/Barotrauma/BarotraumaClient/Source/Physics/PhysicsBody.cs @@ -171,12 +171,9 @@ namespace Barotrauma newVelocity = new Vector2( msg.ReadRangedSingle(-MaxVel, MaxVel, 12), msg.ReadRangedSingle(-MaxVel, MaxVel, 12)); - newVelocity = NetConfig.Quantize(newVelocity, -MaxVel, MaxVel, 12); - if (!fixedRotation) { newAngularVelocity = msg.ReadRangedSingle(-MaxAngularVel, MaxAngularVel, 8); - newAngularVelocity = NetConfig.Quantize(newAngularVelocity.Value, -MaxAngularVel, MaxAngularVel, 8); } } msg.ReadPadBits(); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs index 8c7e20505..b173ae194 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignSetupUI.cs @@ -18,8 +18,6 @@ namespace Barotrauma private GUITextBox saveNameBox, seedBox; private GUITickBox contextualTutorialBox; - private GUILayoutGroup subPreviewContainer; - private GUIButton loadGameButton; public Action StartNewGame; @@ -47,51 +45,40 @@ namespace Barotrauma RelativeSpacing = 0.05f }; - var leftColumn = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.905f), columnContainer.RectTransform)) + var leftColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform)) { Stretch = true, - RelativeSpacing = 0.015f + RelativeSpacing = 0.02f }; - var rightColumn = new GUILayoutGroup(new RectTransform(isMultiplayer ? Vector2.Zero : new Vector2(1.5f, 1.0f), columnContainer.RectTransform)) + var rightColumn = new GUILayoutGroup(new RectTransform(Vector2.One, columnContainer.RectTransform)) { - Stretch = true, - RelativeSpacing = 0.015f + RelativeSpacing = 0.02f }; - columnContainer.Recalculate(); - // New game left side - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform), TextManager.Get("SaveName") + ":"); - saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), string.Empty); + new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), leftColumn.RectTransform), TextManager.Get("SelectedSub") + ":", textAlignment: Alignment.BottomLeft); + subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform)); - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform), TextManager.Get("MapSeed") + ":"); - seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.05f), leftColumn.RectTransform), ToolBox.RandomSeed(8)); + UpdateSubList(submarines); + + // New game right sideon + new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("SaveName") + ":", textAlignment: Alignment.BottomLeft); + saveNameBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), string.Empty); + + new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("MapSeed") + ":", textAlignment: Alignment.BottomLeft); + seedBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), ToolBox.RandomSeed(8)); if (!isMultiplayer) { - contextualTutorialBox = new GUITickBox(new RectTransform(new Point(32, 32), leftColumn.RectTransform), TextManager.Get("TutorialActive")); + new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.1f), rightColumn.RectTransform), TextManager.Get("TutorialActive") + ":", textAlignment: Alignment.BottomLeft); + contextualTutorialBox = new GUITickBox(new RectTransform(new Point(30, 30), rightColumn.RectTransform), string.Empty); UpdateTutorialSelection(); } - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.02f), leftColumn.RectTransform), TextManager.Get("SelectedSub") + ":"); - subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.65f), leftColumn.RectTransform)) { ScrollBarVisible = true }; - - if (!isMultiplayer) { subList.OnSelected = OnSubSelected; } - - // New game right side - subPreviewContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.8f), rightColumn.RectTransform)) - { - Stretch = true - }; - - var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.13f), - (isMultiplayer ? leftColumn : rightColumn).RectTransform) { MaxSize = new Point(int.MaxValue, 60) }, childAnchor: Anchor.TopRight); - - var startButton = new GUIButton(new RectTransform(isMultiplayer ? new Vector2(0.5f, 2.0f) : Vector2.One, - buttonContainer.RectTransform, Anchor.BottomRight) { MaxSize = new Point(350, 60) }, - TextManager.Get("StartCampaignButton"), style: "GUIButtonLarge") + var startButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.13f), rightColumn.RectTransform, Anchor.BottomRight), TextManager.Get("StartCampaignButton"), style: "GUIButtonLarge") { + IgnoreLayoutGroups = true, OnClicked = (GUIButton btn, object userData) => { if (string.IsNullOrWhiteSpace(saveNameBox.Text)) @@ -173,27 +160,9 @@ namespace Barotrauma } }; - leftColumn.Recalculate(); - rightColumn.Recalculate(); - - - UpdateSubList(submarines); UpdateLoadMenu(saveFiles); } - private bool OnSubSelected(GUIComponent component, object obj) - { - if (subPreviewContainer == null) { return false; } - - subPreviewContainer.ClearChildren(); - - Submarine sub = obj as Submarine; - if (sub == null) { return true; } - - sub.CreatePreviewWindow(subPreviewContainer); - return true; - } - private IEnumerable WaitForCampaignSetup() { string headerText = TextManager.Get("CampaignStartingPleaseWait"); @@ -236,13 +205,27 @@ namespace Barotrauma foreach (Submarine sub in subsToShow) { var textBlock = new GUITextBlock( - new RectTransform(new Vector2(1, 0.1f), subList.Content.RectTransform), + new RectTransform(new Vector2(1, 0.1f), subList.Content.RectTransform) + { + AbsoluteOffset = new Point(10, 0) + }, ToolBox.LimitString(sub.Name, GUI.Font, subList.Rect.Width - 65), style: "ListBoxElement") { ToolTip = sub.Description, UserData = sub }; - + + + var infoButton = new GUIButton(new RectTransform(new Vector2(0.12f, 0.8f), textBlock.RectTransform, Anchor.CenterRight), text: "?") + { + UserData = sub + }; + infoButton.OnClicked += (component, userdata) => + { + // TODO: use relative size + ((Submarine)userdata).CreatePreviewWindow(new GUIMessageBox("", "", 550, 400)); + return true; + }; if (sub.HasTag(SubmarineTag.Shuttle)) { @@ -250,7 +233,8 @@ namespace Barotrauma var shuttleText = new GUITextBlock(new RectTransform(new Point(100, textBlock.Rect.Height), textBlock.RectTransform, Anchor.CenterRight) { - IsFixedSize = false + IsFixedSize = false, + RelativeOffset = new Vector2(infoButton.RectTransform.RelativeSize.X + 0.01f, 0) }, TextManager.Get("Shuttle"), textAlignment: Alignment.Right, font: GUI.SmallFont) { diff --git a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs index 272f9916a..c46668705 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs @@ -51,7 +51,7 @@ namespace Barotrauma new GUIImage(new RectTransform(new Vector2(0.35f, 0.2f), Frame.RectTransform, Anchor.BottomRight) { RelativeOffset = new Vector2(0.05f, 0.05f) }, style: "TitleText"); - buttonsParent = new GUILayoutGroup(new RectTransform(new Vector2(0.3f, 0.85f), parent: Frame.RectTransform, anchor: Anchor.BottomLeft, pivot: Pivot.BottomLeft) + buttonsParent = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.85f), parent: Frame.RectTransform, anchor: Anchor.BottomLeft, pivot: Pivot.BottomLeft) { AbsoluteOffset = new Point(50, 0) }) @@ -61,7 +61,7 @@ namespace Barotrauma }; // === CAMPAIGN - var campaignHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.1f, 0.0f) }, isHorizontal: true); + var campaignHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.1f, 0.0f) }, isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.2f, 0.7f), campaignHolder.RectTransform), "MainMenuCampaignIcon") { @@ -107,7 +107,7 @@ namespace Barotrauma }; // === MULTIPLAYER - var multiplayerHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.0f) }, isHorizontal: true); + var multiplayerHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.0f) }, isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.2f, 0.7f), multiplayerHolder.RectTransform), "MainMenuMultiplayerIcon") { @@ -152,7 +152,7 @@ namespace Barotrauma }; // === CUSTOMIZE - var customizeHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.15f, 0.0f) }, isHorizontal: true); + var customizeHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.15f, 0.0f) }, isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.2f, 0.7f), customizeHolder.RectTransform), "MainMenuCustomizeIcon") { @@ -209,7 +209,7 @@ namespace Barotrauma } // === OPTION - var optionHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.5f), parent: buttonsParent.RectTransform), isHorizontal: true); + var optionHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.5f), parent: buttonsParent.RectTransform), isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.15f, 0.6f), optionHolder.RectTransform), "MainMenuOptionIcon") { @@ -219,7 +219,7 @@ namespace Barotrauma //spacing new GUIFrame(new RectTransform(new Vector2(0.01f, 0.0f), optionHolder.RectTransform), style: null); - var optionButtons = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 1.0f), parent: optionHolder.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.15f) }); + var optionButtons = new GUILayoutGroup(new RectTransform(new Vector2(0.55f, 1.0f), parent: optionHolder.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.15f) }); var optionList = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.15f), parent: optionButtons.RectTransform)) { @@ -241,7 +241,7 @@ namespace Barotrauma //debug button for quickly starting a new round #if DEBUG - new GUIButton(new RectTransform(new Vector2(0.8f, 0.1f), buttonsParent.RectTransform, Anchor.TopLeft, Pivot.BottomLeft) { AbsoluteOffset = new Point(0, -40) }, + new GUIButton(new RectTransform(new Vector2(0.5f, 0.1f), buttonsParent.RectTransform, Anchor.TopLeft, Pivot.BottomLeft) { AbsoluteOffset = new Point(0, -40) }, "Quickstart (dev)", style: "GUIButtonLarge", color: Color.Red) { IgnoreLayoutGroups = true, @@ -255,7 +255,7 @@ namespace Barotrauma #endif var minButtonSize = new Point(120, 20); - var maxButtonSize = new Point(480, 80); + var maxButtonSize = new Point(240, 40); /*new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("TutorialButton"), style: "GUIButtonLarge") { @@ -270,21 +270,16 @@ namespace Barotrauma SetupButtons(buttons); buttons.ForEach(b => b.TextBlock.SetTextPos());*/ - var relativeSize = new Vector2(0.6f, 0.65f); + var relativeSize = new Vector2(0.5f, 0.5f); var minSize = new Point(600, 400); - var maxSize = new Point(2000, 1500); - var anchor = Anchor.CenterRight; - var pivot = Pivot.CenterRight; - Vector2 relativeSpacing = new Vector2(0.05f, 0.0f); - + var maxSize = new Point(900, 600); + var anchor = Anchor.Center; + var pivot = Pivot.Center; menuTabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length + 1]; - - menuTabs[(int)Tab.Settings] = new GUIFrame(new RectTransform(new Vector2(relativeSize.X, 0.8f), GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }, - style: null); - - menuTabs[(int)Tab.NewGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }); + + menuTabs[(int)Tab.NewGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize)); var paddedNewGame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), menuTabs[(int)Tab.NewGame].RectTransform, Anchor.Center), style: null); - menuTabs[(int)Tab.LoadGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }); + menuTabs[(int)Tab.LoadGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize)); var paddedLoadGame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), menuTabs[(int)Tab.LoadGame].RectTransform, Anchor.Center), style: null); campaignSetupUI = new CampaignSetupUI(false, paddedNewGame, paddedLoadGame, Submarine.SavedSubmarines) @@ -295,13 +290,13 @@ namespace Barotrauma var hostServerScale = new Vector2(0.7f, 1.0f); menuTabs[(int)Tab.HostServer] = new GUIFrame(new RectTransform( - Vector2.Multiply(relativeSize, hostServerScale), GUI.Canvas, anchor, pivot, minSize.Multiply(hostServerScale), maxSize.Multiply(hostServerScale)) { RelativeOffset = relativeSpacing }); + Vector2.Multiply(relativeSize, hostServerScale), GUI.Canvas, anchor, pivot, minSize.Multiply(hostServerScale), maxSize.Multiply(hostServerScale))); CreateHostServerFields(); //---------------------------------------------------------------------- - menuTabs[(int)Tab.Tutorials] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }); + menuTabs[(int)Tab.Tutorials] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize)); //PLACEHOLDER var tutorialList = new GUIListBox( @@ -340,7 +335,9 @@ namespace Barotrauma Submarine.Unload(); UpdateTutorialList(); - + + campaignSetupUI.UpdateSubList(Submarine.SavedSubmarines); + ResetButtonStates(null); GameAnalyticsManager.SetCustomDimension01(""); @@ -380,7 +377,6 @@ namespace Barotrauma return false; } - GameMain.Config.ResetSettingsFrame(); selectedTab = (Tab)obj; switch (selectedTab) @@ -388,15 +384,13 @@ namespace Barotrauma case Tab.NewGame: campaignSetupUI.CreateDefaultSaveName(); campaignSetupUI.UpdateTutorialSelection(); - campaignSetupUI.UpdateSubList(Submarine.SavedSubmarines); break; case Tab.LoadGame: campaignSetupUI.UpdateLoadMenu(); break; case Tab.Settings: - menuTabs[(int)Tab.Settings].RectTransform.ClearChildren(); - GameMain.Config.SettingsFrame.RectTransform.Parent = menuTabs[(int)Tab.Settings].RectTransform; - GameMain.Config.SettingsFrame.RectTransform.RelativeSize = Vector2.One; + GameMain.Config.ResetSettingsFrame(); + menuTabs[(int)Tab.Settings] = GameMain.Config.SettingsFrame; break; case Tab.JoinServer: GameMain.ServerListScreen.Select(); @@ -688,7 +682,7 @@ namespace Barotrauma if (backgroundSprite == null) { - backgroundSprite = (LocationType.List.Where(l => l.UseInMainMenu).GetRandom())?.GetPortrait(0); + backgroundSprite = (LocationType.List.Where(l => l.UseInMainMenu).GetRandom()).GetPortrait(0); } if (backgroundSprite != null) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs index 2d7c48e1b..41f2c8abf 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs @@ -22,7 +22,6 @@ namespace Barotrauma "CrewExperienceHigh" }; - private readonly Point defaultPreviewImageSize = new Point(512, 368); private Camera cam; @@ -801,6 +800,11 @@ namespace Barotrauma } #endif + /*foreach (var contentPackage in GameMain.Config.SelectedContentPackages) + { + Submarine.MainSub.RequiredContentPackages.Add(contentPackage.Name); + }*/ + MemoryStream imgStream = new MemoryStream(); CreateImage(defaultPreviewImageSize.X, defaultPreviewImageSize.Y, imgStream); diff --git a/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs b/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs index 8a75d42e0..29f5bade5 100644 --- a/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs +++ b/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs @@ -20,10 +20,8 @@ namespace Barotrauma if (Job != null) { msg.Write(Job.Prefab.Identifier); - msg.Write((byte)Job.Skills.Count); foreach (Skill skill in Job.Skills) { - msg.Write(skill.Identifier); msg.Write(skill.Level); } } diff --git a/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs index 9845cb86c..d9831f872 100644 --- a/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs @@ -362,8 +362,7 @@ namespace Barotrauma if (SelectedCharacter != null || SelectedConstruction != null) { tempBuffer.Write(true); - tempBuffer.Write(SelectedCharacter != null ? SelectedCharacter.ID : NullEntityID); - tempBuffer.Write(SelectedConstruction != null ? SelectedConstruction.ID : NullEntityID); + tempBuffer.Write(SelectedCharacter != null ? SelectedCharacter.ID : SelectedConstruction.ID); if (SelectedCharacter != null) { tempBuffer.Write(AnimController.Anim == AnimController.Animation.CPR); @@ -377,9 +376,8 @@ namespace Barotrauma tempBuffer.Write(SimPosition.X); tempBuffer.Write(SimPosition.Y); float MaxVel = NetConfig.MaxPhysicsBodyVelocity; - AnimController.Collider.LinearVelocity = NetConfig.Quantize(AnimController.Collider.LinearVelocity, -MaxVel, MaxVel, 12); - tempBuffer.WriteRangedSingle(AnimController.Collider.LinearVelocity.X, -MaxVel, MaxVel, 12); - tempBuffer.WriteRangedSingle(AnimController.Collider.LinearVelocity.Y, -MaxVel, MaxVel, 12); + tempBuffer.WriteRangedSingle(MathHelper.Clamp(AnimController.Collider.LinearVelocity.X, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); + tempBuffer.WriteRangedSingle(MathHelper.Clamp(AnimController.Collider.LinearVelocity.Y, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); bool fixedRotation = AnimController.Collider.FarseerBody.FixedRotation; tempBuffer.Write(fixedRotation); @@ -387,7 +385,6 @@ namespace Barotrauma { tempBuffer.Write(AnimController.Collider.Rotation); float MaxAngularVel = NetConfig.MaxPhysicsBodyAngularVelocity; - AnimController.Collider.AngularVelocity = NetConfig.Quantize(AnimController.Collider.AngularVelocity, -MaxAngularVel, MaxAngularVel, 8); tempBuffer.WriteRangedSingle(MathHelper.Clamp(AnimController.Collider.AngularVelocity, -MaxAngularVel, MaxAngularVel), -MaxAngularVel, MaxAngularVel, 8); } diff --git a/Barotrauma/BarotraumaServer/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaServer/Source/Items/Components/Machines/Fabricator.cs index 9203d533a..bdd1935a7 100644 --- a/Barotrauma/BarotraumaServer/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaServer/Source/Items/Components/Machines/Fabricator.cs @@ -12,7 +12,7 @@ namespace Barotrauma.Items.Components { public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { - int itemIndex = msg.ReadRangedInteger(-1, fabricationRecipes.Count - 1); + int itemIndex = msg.ReadRangedInteger(-1, fabricableItems.Count - 1); item.CreateServerEvent(this); @@ -25,17 +25,17 @@ namespace Barotrauma.Items.Components else { //if already fabricating the selected item, return - if (fabricatedItem != null && fabricationRecipes.IndexOf(fabricatedItem) == itemIndex) return; - if (itemIndex < 0 || itemIndex >= fabricationRecipes.Count) return; + if (fabricatedItem != null && fabricableItems.IndexOf(fabricatedItem) == itemIndex) return; + if (itemIndex < 0 || itemIndex >= fabricableItems.Count) return; - StartFabricating(fabricationRecipes[itemIndex], c.Character); + StartFabricating(fabricableItems[itemIndex], c.Character); } } public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null) { - int itemIndex = fabricatedItem == null ? -1 : fabricationRecipes.IndexOf(fabricatedItem); - msg.WriteRangedInteger(-1, fabricationRecipes.Count - 1, itemIndex); + int itemIndex = fabricatedItem == null ? -1 : fabricableItems.IndexOf(fabricatedItem); + msg.WriteRangedInteger(-1, fabricableItems.Count - 1, itemIndex); UInt16 userID = fabricatedItem == null || user == null ? (UInt16)0 : user.ID; msg.Write(userID); } diff --git a/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs b/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs index 10580b11e..b2276c7f5 100644 --- a/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs +++ b/Barotrauma/BarotraumaServer/Source/Physics/PhysicsBody.cs @@ -1,7 +1,11 @@ -using Barotrauma.Networking; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Barotrauma.Networking; using Lidgren.Network; using Microsoft.Xna.Framework; -using System; namespace Barotrauma { @@ -33,12 +37,10 @@ namespace Barotrauma if (FarseerBody.Awake) { body.Enabled = true; - body.LinearVelocity = NetConfig.Quantize(body.LinearVelocity, -MaxVel, MaxVel, 12); - msg.WriteRangedSingle(body.LinearVelocity.X, -MaxVel, MaxVel, 12); - msg.WriteRangedSingle(body.LinearVelocity.Y, -MaxVel, MaxVel, 12); + msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.X, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); + msg.WriteRangedSingle(MathHelper.Clamp(body.LinearVelocity.Y, -MaxVel, MaxVel), -MaxVel, MaxVel, 12); if (!FarseerBody.FixedRotation) { - body.AngularVelocity = NetConfig.Quantize(body.AngularVelocity, -MaxAngularVel, MaxAngularVel, 8); msg.WriteRangedSingle(MathHelper.Clamp(body.AngularVelocity, -MaxAngularVel, MaxAngularVel), -MaxAngularVel, MaxAngularVel, 8); } } diff --git a/Barotrauma/BarotraumaShared/SharedContent.projitems b/Barotrauma/BarotraumaShared/SharedContent.projitems index 3f84508f8..01d85edc4 100644 --- a/Barotrauma/BarotraumaShared/SharedContent.projitems +++ b/Barotrauma/BarotraumaShared/SharedContent.projitems @@ -381,6 +381,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -1798,99 +1801,6 @@ - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - PreserveNewest @@ -2003,9 +1913,6 @@ PreserveNewest - - PreserveNewest - @@ -2653,6 +2560,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs index 45dde7864..15751af28 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs @@ -631,7 +631,8 @@ namespace Barotrauma else { // If the secondary cooldown is defined and expired, check if we can switch the attack - var newLimb = GetAttackLimb(attackWorldPos, AttackingLimb); + var previousLimb = AttackingLimb; + var newLimb = GetAttackLimb(attackWorldPos, previousLimb); if (newLimb != null) { // Attack with the new limb @@ -679,7 +680,8 @@ namespace Barotrauma else { // If the secondary cooldown is defined and expired, check if we can switch the attack - var newLimb = GetAttackLimb(attackWorldPos, AttackingLimb); + var previousLimb = AttackingLimb; + var newLimb = GetAttackLimb(attackWorldPos, previousLimb); if (newLimb != null) { // Attack with the new limb @@ -705,15 +707,16 @@ namespace Barotrauma default: UpdateFallBack(attackWorldPos, deltaTime); return; + } } + if (AttackingLimb == null || _previousAiTarget != SelectedAiTarget) + { + AttackingLimb = GetAttackLimb(attackWorldPos); + } if (canAttack) { - if (AttackingLimb == null || _previousAiTarget != SelectedAiTarget) - { - AttackingLimb = GetAttackLimb(attackWorldPos); - } canAttack = AttackingLimb != null && AttackingLimb.attack.CoolDownTimer <= 0; } float distance = 0; @@ -722,12 +725,6 @@ namespace Barotrauma // Check that we can reach the target distance = Vector2.Distance(AttackingLimb.WorldPosition, attackWorldPos); canAttack = distance < AttackingLimb.attack.Range; - if (!canAttack && !IsCoolDownRunning) - { - // If not, reset the attacking limb, if the cooldown is not running - // Don't use the property, because we don't want cancel reversing, if we are reversing. - _attackingLimb = null; - } } // If the attacking limb is a hand or claw, for example, using it as the steering limb can end in the result where the character circles around the target. For example the Hammerhead steering with the claws when it should use the torso. @@ -797,6 +794,7 @@ namespace Barotrauma { UpdateLimbAttack(deltaTime, AttackingLimb, attackSimPos, distance); } + return false; } private bool SteerThroughGap(Structure wall, WallSection section, Vector2 targetWorldPos, float deltaTime) @@ -1043,7 +1041,7 @@ namespace Barotrauma } else { - steeringManager.SteeringSeek(attackSimPosition - (mouthPos - SimPosition), 2); + steeringManager.SteeringSeek(attackSimPosition - (mouthPos - SimPosition)); } } @@ -1167,15 +1165,15 @@ namespace Barotrauma else if (target.Entity is Structure s) { targetingTag = "wall"; - if (!s.HasBody) - { - // Ignore structures that doesn't have a body (not walls) - continue; - } - // Ignore walls when inside. - valueModifier = character.CurrentHull == null ? 1 : 0; if (aggressiveBoarding) { + // Ignore walls when inside. + valueModifier = character.CurrentHull == null ? 2 : 0; + if (valueModifier > 0) + { + // Ignore structures that doesn't have a body (not walls) + valueModifier *= s.HasBody ? 1 : 0; + } for (int i = 0; i < s.Sections.Length; i++) { var section = s.Sections[i]; @@ -1192,23 +1190,6 @@ namespace Barotrauma } } } - else - { - // Ignore disabled walls - bool isDisabled = true; - for (int i = 0; i < s.Sections.Length; i++) - { - if (!s.SectionBodyDisabled(i)) - { - isDisabled = false; - break; - } - } - if (isDisabled) - { - valueModifier = 0; - } - } } else { diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs index d07b4019d..3c6c35ce4 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveExtinguishFire.cs @@ -84,9 +84,12 @@ namespace Barotrauma useExtinquisherTimer += deltaTime; if (useExtinquisherTimer > 2.0f) useExtinquisherTimer = 0.0f; - character.AIController.SteeringManager.Reset(); character.CursorPosition = fs.Position; character.SetInput(InputType.Aim, false, true); + if (!character.IsClimbing) + { + character.AIController.SteeringManager.Reset(); + } extinguisher.Use(deltaTime, character); if (!targetHull.FireSources.Contains(fs)) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs index 8d65800fd..99a856cd5 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveRepairItem.cs @@ -168,11 +168,8 @@ namespace Barotrauma // Too close -> steer away character.AIController.SteeringManager.SteeringManual(deltaTime, Vector2.Normalize(character.SimPosition - Item.SimPosition) / 2); } - else - { - character.AIController.SteeringManager.Reset(); - } - if (VectorExtensions.Angle(VectorExtensions.Forward(repairTool.Item.body.TransformedRotation), fromToolToTarget) < MathHelper.PiOver4) + if (character.IsClimbing || + VectorExtensions.Angle(VectorExtensions.Forward(repairTool.Item.body.TransformedRotation), fromToolToTarget) < MathHelper.PiOver4) { repairTool.Use(deltaTime, character); } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs index 6e1406f46..a099d8382 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs @@ -696,7 +696,7 @@ namespace Barotrauma return; } - limb.body.ApplyForce(diff * (float)(Math.Sin(WalkPos) * Math.Sqrt(limb.Mass)) * 30.0f * animStrength, maxVelocity: 10.0f); + limb.body.ApplyForce(diff * (float)(Math.Sin(WalkPos) * Math.Sqrt(limb.Mass)) * 30.0f * animStrength); } } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs index 0c001afcb..5db0e80cf 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Barotrauma.Extensions; -using Barotrauma.Networking; namespace Barotrauma { @@ -1123,6 +1122,9 @@ namespace Barotrauma //prevent the hands from going above the top of the ladders handPos.Y = Math.Min(-0.5f, handPos.Y); + //prevent the hands from going above the top of the ladders + handPos.Y = Math.Min(-0.5f, handPos.Y); + // TODO: lock only one hand when aiming? if (!PlayerInput.KeyDown(InputType.Aim) || Math.Abs(movement.Y) > 0.01f) { @@ -1658,7 +1660,7 @@ namespace Barotrauma Holdable holdable = item.GetComponent(); - if (!isClimbing && !usingController && character.Stun <= 0.0f && aim && itemPos != Vector2.Zero) + if (!character.IsClimbing && !usingController && character.Stun <= 0.0f && aim && itemPos != Vector2.Zero) { Vector2 mousePos = ConvertUnits.ToSimUnits(character.SmoothedCursorPosition); @@ -1688,7 +1690,7 @@ namespace Barotrauma } Vector2 transformedHoldPos = shoulder.WorldAnchorA; - if (itemPos == Vector2.Zero || isClimbing || usingController) + if (itemPos == Vector2.Zero || character.IsClimbing || usingController) { if (character.SelectedItems[0] == item) { @@ -1777,6 +1779,8 @@ namespace Barotrauma item.SetTransform(currItemPos, itemAngle + itemAngleRelativeToHoldAngle * Dir); + if (character.IsClimbing) return; + if (!isClimbing) { for (int i = 0; i < 2; i++) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index ebbaceea1..c039da1be 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -1147,7 +1147,7 @@ namespace Barotrauma { //Limb head = AnimController.GetLimb(LimbType.Head); // Values lower than this seem to cause constantious flipping when the mouse is near the player and the player is running, because the root collider moves after flipping. - float followMargin = 40; + float followMargin = 30; if (dontFollowCursor) { AnimController.TargetDir = Direction.Right; @@ -2187,7 +2187,7 @@ namespace Barotrauma if (limbHit == null) return new AttackResult(); - limbHit.body?.ApplyLinearImpulse(attack.TargetImpulseWorld + attack.TargetForceWorld * deltaTime, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + limbHit.body?.ApplyLinearImpulse(attack.TargetImpulseWorld + attack.TargetForceWorld * deltaTime); #if SERVER if (attacker is Character attackingCharacter && attackingCharacter.AIController == null) { @@ -2273,8 +2273,7 @@ namespace Barotrauma { Vector2 diff = dir; if (diff == Vector2.Zero) diff = Rand.Vector(1.0f); - hitLimb.body.ApplyLinearImpulse(Vector2.Normalize(diff) * attackImpulse, hitLimb.SimPosition + ConvertUnits.ToSimUnits(diff), - maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + hitLimb.body.ApplyLinearImpulse(Vector2.Normalize(diff) * attackImpulse, hitLimb.SimPosition + ConvertUnits.ToSimUnits(diff)); } Vector2 simPos = hitLimb.SimPosition + ConvertUnits.ToSimUnits(dir); AttackResult attackResult = hitLimb.AddDamage(simPos, afflictions, playSound); diff --git a/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs index ac52f3b2b..b7e551095 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs @@ -14,17 +14,17 @@ namespace Barotrauma public readonly AnimController.Animation Animation; - public CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, float time, Direction dir, Character selectedCharacter, Item selectedItem, AnimController.Animation animation = AnimController.Animation.None) - : this(pos, rotation, velocity, angularVelocity, 0, time, dir, selectedCharacter, selectedItem, animation) + public CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None) + : this(pos, rotation, velocity, angularVelocity, 0, time, dir, interact, animation) { } - public CharacterStateInfo(Vector2 pos, float? rotation, UInt16 ID, Direction dir, Character selectedCharacter, Item selectedItem, AnimController.Animation animation = AnimController.Animation.None) - : this(pos, rotation, Vector2.Zero, 0.0f, ID, 0.0f, dir, selectedCharacter, selectedItem, animation) + public CharacterStateInfo(Vector2 pos, float? rotation, UInt16 ID, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None) + : this(pos, rotation, Vector2.Zero, 0.0f, ID, 0.0f, dir, interact, animation) { } - protected CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, UInt16 ID, float time, Direction dir, Character selectedCharacter, Item selectedItem, AnimController.Animation animation = AnimController.Animation.None) + protected CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, UInt16 ID, float time, Direction dir, Entity interact, AnimController.Animation animation = AnimController.Animation.None) : base(pos, rotation, velocity, angularVelocity, ID, time) { Direction = dir; diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs b/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs index 2814b127c..dbd782551 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs @@ -626,17 +626,13 @@ namespace Barotrauma Limb limb = character.AnimController.Limbs[limbIndex]; Vector2 forcePos = limb.pullJoint == null ? limb.body.SimPosition : limb.pullJoint.WorldAnchorA; - limb.body.ApplyLinearImpulse(limb.Mass * attack.Force * Vector2.Normalize(attackSimPos - SimPosition), forcePos, - maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + limb.body.ApplyLinearImpulse(limb.Mass * attack.Force * Vector2.Normalize(attackSimPos - SimPosition), forcePos); } } else { Vector2 forcePos = pullJoint == null ? body.SimPosition : pullJoint.WorldAnchorA; - body.ApplyLinearImpulse( - Mass * attack.Force * Vector2.Normalize(attackSimPos - SimPosition), - forcePos, - maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + body.ApplyLinearImpulse(Mass * attack.Force * Vector2.Normalize(attackSimPos - SimPosition), forcePos); } } return wasHit; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs index db3f7c9de..0c14f05fa 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RangedWeapon.cs @@ -1,5 +1,4 @@ -using Barotrauma.Networking; -using FarseerPhysics; +using FarseerPhysics; using FarseerPhysics.Collision; using FarseerPhysics.Dynamics; using Microsoft.Xna.Framework; @@ -165,12 +164,11 @@ namespace Barotrauma.Items.Components //set the rotation of the projectile again because dropping the projectile resets the rotation projectile.Item.SetTransform(projectilePos, - rotation + (projectile.Item.body.Dir * projectile.LaunchRotationRadians)); + rotation + ((item.body.Dir == 1.0f) ? projectile.LaunchRotationRadians : projectile.LaunchRotationRadians - MathHelper.Pi)); //recoil item.body.ApplyLinearImpulse( - new Vector2((float)Math.Cos(projectile.Item.body.Rotation), (float)Math.Sin(projectile.Item.body.Rotation)) * item.body.Mass * -50.0f, - maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + new Vector2((float)Math.Cos(projectile.Item.body.Rotation), (float)Math.Sin(projectile.Item.body.Rotation)) * item.body.Mass * -50.0f); item.RemoveContained(projectile.Item); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs index 6251f88b1..153e694ef 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs @@ -303,8 +303,10 @@ namespace Barotrauma.Items.Components // Too close -> steer away character.AIController.SteeringManager.SteeringManual(deltaTime, Vector2.Normalize(character.SimPosition - leak.SimPosition) / 2); } - else + else if (!character.IsClimbing) { + // Close enough -> stop if not in ladders. + // In ladders, we most likely want to move back and forth, because we cannot aim -> if the leak is on the side, it should get fixed. character.AIController.SteeringManager.Reset(); } } @@ -315,7 +317,7 @@ namespace Barotrauma.Items.Components // Press the trigger only when the tool is approximately facing the target. // If the character is climbing, ignore the check, because we cannot aim while climbing. - if (VectorExtensions.Angle(VectorExtensions.Forward(item.body.TransformedRotation), fromItemToLeak) < MathHelper.PiOver4) + if (character.IsClimbing || VectorExtensions.Angle(VectorExtensions.Forward(item.body.TransformedRotation), fromItemToLeak) < MathHelper.PiOver4) { Use(deltaTime, character); } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs index d52f4287e..b1634a6b7 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs @@ -106,10 +106,10 @@ namespace Barotrauma.Items.Components #endif Character thrower = picker; item.Drop(thrower, createNetworkEvent: GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer); - item.body.ApplyLinearImpulse(throwVector * throwForce * item.body.Mass * 3.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + item.body.ApplyLinearImpulse(throwVector * throwForce * item.body.Mass * 3.0f); - ac.GetLimb(LimbType.Head).body.ApplyLinearImpulse(throwVector * 10.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); - ac.GetLimb(LimbType.Torso).body.ApplyLinearImpulse(throwVector * 10.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + ac.GetLimb(LimbType.Head).body.ApplyLinearImpulse(throwVector*10.0f); + ac.GetLimb(LimbType.Torso).body.ApplyLinearImpulse(throwVector * 10.0f); Limb rightHand = ac.GetLimb(LimbType.RightHand); item.body.AngularVelocity = rightHand.body.AngularVelocity; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs index d74524d9e..e0050c17c 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs @@ -538,6 +538,7 @@ namespace Barotrauma.Items.Components GameAnalyticsManager.AddErrorEventOnce("ItemComponent.DegreeOfSuccess:CharacterNull", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); return 0.0f; } + float average = skillSuccessSum / requiredSkills.Count; float skillSuccessSum = 0.0f; for (int i = 0; i < requiredSkills.Count; i++) @@ -734,13 +735,15 @@ namespace Barotrauma.Items.Components private void OverrideRequiredItems(XElement element) { var prevRequiredItems = new Dictionary>(requiredItems); - requiredItems.Clear(); - + bool overrideRequiredItems = false; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": + if (!overrideRequiredItems) requiredItems.Clear(); + overrideRequiredItems = true; + RelatedItem newRequiredItem = RelatedItem.Load(subElement, item.Name); if (newRequiredItem == null) continue; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs index 5df72ff59..010f24173 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Engine.cs @@ -90,7 +90,7 @@ namespace Barotrauma.Items.Components Force = MathHelper.Lerp(force, (voltage < minVoltage) ? 0.0f : targetForce, 0.1f); if (Math.Abs(Force) > 1.0f) { - Vector2 currForce = new Vector2((force / 10.0f) * maxForce * Math.Min(voltage / minVoltage, 1.0f), 0.0f); + Vector2 currForce = new Vector2((force / 100.0f) * maxForce * Math.Min(voltage / minVoltage, 1.0f), 0.0f); //less effective when in a bad condition currForce *= MathHelper.Lerp(0.5f, 2.0f, item.Condition / item.MaxCondition); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs index 80b083a3e..e0784ca5d 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs @@ -11,9 +11,27 @@ namespace Barotrauma.Items.Components partial class Fabricator : Powered, IServerSerializable, IClientSerializable { - public const float SkillIncreaseMultiplier = 0.5f; + public class RequiredItem + { + public readonly ItemPrefab ItemPrefab; + public int Amount; + public readonly float MinCondition; + public readonly bool UseCondition; - private List fabricationRecipes = new List(); + public RequiredItem(ItemPrefab itemPrefab, int amount, float minCondition, bool useCondition) + { + ItemPrefab = itemPrefab; + Amount = amount; + MinCondition = minCondition; + UseCondition = useCondition; + } + } + + public readonly ItemPrefab TargetItem; + + public readonly string DisplayName; + + public readonly List RequiredItems; private FabricationRecipe fabricatedItem; private float timeUntilReady; @@ -23,41 +41,117 @@ namespace Barotrauma.Items.Components private ItemContainer inputContainer, outputContainer; + public readonly List RequiredSkills; + + public FabricableItem(XElement element) + { + if (element.Attribute("name") != null) + { + string name = element.Attribute("name").Value; + DebugConsole.ThrowError("Error in fabricable item config (" + name + ") - use item identifiers instead of names"); + TargetItem = MapEntityPrefab.Find(name) as ItemPrefab; + if (TargetItem == null) + { + DebugConsole.ThrowError("Error in fabricable item config - item prefab \"" + name + "\" not found."); + return; + } + } + else + { + string identifier = element.GetAttributeString("identifier", ""); + TargetItem = MapEntityPrefab.Find(null, identifier) as ItemPrefab; + if (TargetItem == null) + { + DebugConsole.ThrowError("Error in fabricable item config - item prefab \"" + identifier + "\" not found."); + return; + } + } + + string displayName = element.GetAttributeString("displayname", ""); + DisplayName = string.IsNullOrEmpty(displayName) ? TargetItem.Name : TextManager.Get($"DisplayName.{displayName}"); + + RequiredSkills = new List(); + RequiredTime = element.GetAttributeFloat("requiredtime", 1.0f); + OutCondition = element.GetAttributeFloat("outcondition", 1.0f); + RequiredItems = new List(); + + foreach (XElement subElement in element.Elements()) + { + if (!(me is ItemPrefab itemPrefab)) { continue; } + + foreach (FabricationRecipe recipe in itemPrefab.FabricationRecipes) + { + case "requiredskill": + if (subElement.Attribute("name") != null) + { + DebugConsole.ThrowError("Error in fabricable item " + TargetItem.Name + "! Use skill identifiers instead of names."); + continue; + } + + RequiredSkills.Add(new Skill( + subElement.GetAttributeString("identifier", ""), + subElement.GetAttributeInt("level", 0))); + break; + case "item": + case "requireditem": + string requiredItemIdentifier = subElement.GetAttributeString("identifier", ""); + if (string.IsNullOrWhiteSpace(requiredItemIdentifier)) + { + DebugConsole.ThrowError("Error in fabricable item " + TargetItem.Name + "! One of the required items has no identifier."); + continue; + } + + float minCondition = subElement.GetAttributeFloat("mincondition", 1.0f); + //Substract mincondition from required item's condition or delete it regardless? + bool useCondition = subElement.GetAttributeBool("usecondition", true); + int count = subElement.GetAttributeInt("count", 1); + + + ItemPrefab requiredItem = MapEntityPrefab.Find(null, requiredItemIdentifier.Trim()) as ItemPrefab; + if (requiredItem == null) + { + DebugConsole.ThrowError("Error in fabricable item " + TargetItem.Name + "! Required item \"" + requiredItemIdentifier + "\" not found."); + continue; + } + + var existing = RequiredItems.Find(r => r.ItemPrefab == requiredItem); + if (existing == null) + { + RequiredItems.Add(new RequiredItem(requiredItem, count, minCondition, useCondition)); + } + else + { + + RequiredItems.Remove(existing); + RequiredItems.Add(new RequiredItem(requiredItem, existing.Amount + count, minCondition, useCondition)); + } + + break; + } + } + + InitProjSpecific(); + } + } + + partial class Fabricator : Powered, IServerSerializable, IClientSerializable + { + public const float SkillIncreaseMultiplier = 0.5f; + + private List fabricableItems; + + private FabricableItem fabricatedItem; + private float timeUntilReady; + private float requiredTime; + + private Character user; + + private ItemContainer inputContainer, outputContainer; + private float progressState; public Fabricator(Item item, XElement element) : base(item, element) - { - foreach (XElement subElement in element.Elements()) - { - if (subElement.Name.ToString().ToLowerInvariant() == "fabricableitem") - { - DebugConsole.ThrowError("Error in item " + item.Name + "! Fabrication recipes should be defined in the craftable item's xml, not in the fabricator."); - break; - } - } - - foreach (MapEntityPrefab me in MapEntityPrefab.List) - { - if (!(me is ItemPrefab itemPrefab)) { continue; } - - foreach (FabricationRecipe recipe in itemPrefab.FabricationRecipes) - { - if (recipe.SuitableFabricatorIdentifiers.Length > 0) - { - if (!recipe.SuitableFabricatorIdentifiers.Any(i => item.prefab.Identifier == i || item.HasTag(i))) - { - continue; - } - } - fabricationRecipes.Add(recipe); - } - } - - InitProjSpecific(); - } - - public override void OnItemLoaded() { var containers = item.GetComponents().ToList(); if (containers.Count < 2) @@ -81,6 +175,30 @@ namespace Barotrauma.Items.Components OnItemLoadedProjSpecific(); } + public override void OnItemLoaded() + { + var containers = item.GetComponents().ToList(); + if (containers.Count < 2) + { + DebugConsole.ThrowError("Error in item \"" + item.Name + "\": Fabricators must have two ItemContainer components!"); + return; + } + + inputContainer = containers[0]; + outputContainer = containers[1]; + + foreach (FabricableItem fabricableItem in fabricableItems) + { + int ingredientCount = fabricableItem.RequiredItems.Sum(it => it.Amount); + if (ingredientCount > inputContainer.Capacity) + { + DebugConsole.ThrowError("Error in item \"" + item.Name + "\": There's not enough room in the input inventory for the ingredients of \"" + fabricableItem.TargetItem.Name + "\"!"); + } + } + + OnItemLoadedProjSpecific(); + } + partial void OnItemLoadedProjSpecific(); @@ -99,7 +217,7 @@ namespace Barotrauma.Items.Components return (picker != null); } - private void StartFabricating(FabricationRecipe selectedItem, Character user) + private void StartFabricating(FabricableItem selectedItem, Character user) { if (selectedItem == null) return; if (!outputContainer.Inventory.IsEmpty()) return; @@ -184,7 +302,7 @@ namespace Barotrauma.Items.Components if (timeUntilReady > 0.0f) { return; } var availableIngredients = GetAvailableIngredients(); - foreach (FabricationRecipe.RequiredItem ingredient in fabricatedItem.RequiredItems) + foreach (FabricableItem.RequiredItem ingredient in fabricatedItem.RequiredItems) { for (int i = 0; i < ingredient.Amount; i++) { @@ -210,8 +328,13 @@ namespace Barotrauma.Items.Components { Entity.Spawner.AddToSpawnQueue(fabricatedItem.TargetItem, outputContainer.Inventory, fabricatedItem.TargetItem.Health * fabricatedItem.OutCondition); } - - if ((GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer) && user != null && !user.Removed) + + bool isNotClient = true; +#if CLIENT + isNotClient = GameMain.Client == null; +#endif + + if (isNotClient && user != null) { foreach (Skill skill in fabricatedItem.RequiredSkills) { @@ -222,17 +345,17 @@ namespace Barotrauma.Items.Components CancelFabricating(null); } - private bool CanBeFabricated(FabricationRecipe fabricableItem) + private bool CanBeFabricated(FabricableItem fabricableItem) { if (fabricableItem == null) { return false; } List availableIngredients = GetAvailableIngredients(); return CanBeFabricated(fabricableItem, availableIngredients); } - private bool CanBeFabricated(FabricationRecipe fabricableItem, IEnumerable availableIngredients) + private bool CanBeFabricated(FabricableItem fabricableItem, IEnumerable availableIngredients) { if (fabricableItem == null) { return false; } - foreach (FabricationRecipe.RequiredItem requiredItem in fabricableItem.RequiredItems) + foreach (FabricableItem.RequiredItem requiredItem in fabricableItem.RequiredItems) { if (availableIngredients.Count(it => IsItemValidIngredient(it, requiredItem)) < requiredItem.Amount) { @@ -242,7 +365,7 @@ namespace Barotrauma.Items.Components return true; } - private float GetRequiredTime(FabricationRecipe fabricableItem, Character user) + private float GetRequiredTime(FabricableItem fabricableItem, Character user) { float degreeOfSuccess = DegreeOfSuccess(user, fabricableItem.RequiredSkills); @@ -284,7 +407,7 @@ namespace Barotrauma.Items.Components /// Move the items required for fabrication into the input container. /// The method assumes that all the required ingredients are available either in the input container or linked containers. /// - private void MoveIngredientsToInputContainer(FabricationRecipe targetItem) + private void MoveIngredientsToInputContainer(FabricableItem targetItem) { //required ingredients that are already present in the input container List usedItems = new List(); @@ -315,7 +438,7 @@ namespace Barotrauma.Items.Components } } - private bool IsItemValidIngredient(Item item, FabricationRecipe.RequiredItem requiredItem) + private bool IsItemValidIngredient(Item item, FabricableItem.RequiredItem requiredItem) { return item != null && diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs index 596e50d1e..f53a6a6bb 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Projectile.cs @@ -377,14 +377,23 @@ namespace Barotrauma.Items.Components target.Body.ApplyLinearImpulse(item.body.LinearVelocity * item.body.Mass); return true; } + else if (target.Body.UserData is Limb limb) + { + //severed limbs don't deactivate the projectile (but may still slow it down enough to make it inactive) + if (limb.IsSevered) + { + target.Body.ApplyLinearImpulse(item.body.LinearVelocity * item.body.Mass); + return true; + } - limb.character.LastDamageSource = item; - if (attack != null) { attackResult = attack.DoDamageToLimb(User, limb, item.WorldPosition, 1.0f); } - if (limb.character != null) { character = limb.character; } - } - else if (target.Body.UserData is Structure structure) - { - if (attack != null) { attackResult = attack.DoDamage(User, structure, item.WorldPosition, 1.0f); } + limb.character.LastDamageSource = item; + attackResult = attack.DoDamageToLimb(User, limb, item.WorldPosition, 1.0f); + if (limb.character != null) character = limb.character; + } + else if (target.Body.UserData is Structure structure) + { + attackResult = attack.DoDamage(User, structure, item.WorldPosition, 1.0f); + } } if (character != null) character.LastDamageSource = item; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs index 7845f609c..30c1a1d15 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs @@ -22,10 +22,6 @@ namespace Barotrauma.Items.Components private float blinkTimer; - private bool itemLoaded; - - private float blinkTimer; - public PhysicsBody ParentBody; [Editable(MinValueFloat = 0.0f, MaxValueFloat = 2048.0f), Serialize(100.0f, true)] @@ -81,7 +77,7 @@ namespace Barotrauma.Items.Components IsActive = value; #if SERVER - if (GameMain.Server != null && itemLoaded) { item.CreateServerEvent(this); } + if (GameMain.Server != null && GameMain.Server.GameStarted) { item.CreateServerEvent(this); } #endif } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs index 0d76efa20..8b89d237a 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs @@ -315,7 +315,7 @@ namespace Barotrauma.Items.Components Vector2 diff = nodes[nodes.Count - 1] - newNodePos; Vector2 pullBackDir = diff == Vector2.Zero ? Vector2.Zero : Vector2.Normalize(diff); - user.AnimController.Collider.ApplyForce(pullBackDir * user.Mass * 50.0f, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + user.AnimController.Collider.ApplyForce(pullBackDir * user.Mass * 50.0f); user.AnimController.UpdateUseItem(true, user.WorldPosition + pullBackDir * 200.0f); if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index af2ac7d8e..651e83328 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -491,9 +491,6 @@ namespace Barotrauma case "levelcommonness": case "suitabletreatment": case "containedsprite": - case "fabricate": - case "fabricable": - case "fabricableitem": break; case "staticbody": StaticBodyConfig = subElement; diff --git a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs index 1f1156151..006fde68f 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -31,100 +31,6 @@ namespace Barotrauma } } - class FabricationRecipe - { - public class RequiredItem - { - public readonly ItemPrefab ItemPrefab; - public int Amount; - public readonly float MinCondition; - public readonly bool UseCondition; - - public RequiredItem(ItemPrefab itemPrefab, int amount, float minCondition, bool useCondition) - { - ItemPrefab = itemPrefab; - Amount = amount; - MinCondition = minCondition; - UseCondition = useCondition; - } - } - - public readonly ItemPrefab TargetItem; - public readonly string DisplayName; - public readonly List RequiredItems; - public readonly string[] SuitableFabricatorIdentifiers; - public readonly float RequiredTime; - public readonly float OutCondition; //Percentage-based from 0 to 1 - public readonly List RequiredSkills; - - public FabricationRecipe(XElement element, ItemPrefab itemPrefab) - { - TargetItem = itemPrefab; - string displayName = element.GetAttributeString("displayname", ""); - DisplayName = string.IsNullOrEmpty(displayName) ? itemPrefab.Name : TextManager.Get($"DisplayName.{displayName}"); - - SuitableFabricatorIdentifiers = element.GetAttributeStringArray("suitablefabricators", new string[0]); - - RequiredSkills = new List(); - RequiredTime = element.GetAttributeFloat("requiredtime", 1.0f); - OutCondition = element.GetAttributeFloat("outcondition", 1.0f); - RequiredItems = new List(); - - foreach (XElement subElement in element.Elements()) - { - switch (subElement.Name.ToString().ToLowerInvariant()) - { - case "requiredskill": - if (subElement.Attribute("name") != null) - { - DebugConsole.ThrowError("Error in fabricable item " + itemPrefab.Name + "! Use skill identifiers instead of names."); - continue; - } - - RequiredSkills.Add(new Skill( - subElement.GetAttributeString("identifier", ""), - subElement.GetAttributeInt("level", 0))); - break; - case "item": - case "requireditem": - string requiredItemIdentifier = subElement.GetAttributeString("identifier", ""); - if (string.IsNullOrWhiteSpace(requiredItemIdentifier)) - { - DebugConsole.ThrowError("Error in fabricable item " + itemPrefab.Name + "! One of the required items has no identifier."); - continue; - } - - float minCondition = subElement.GetAttributeFloat("mincondition", 1.0f); - //Substract mincondition from required item's condition or delete it regardless? - bool useCondition = subElement.GetAttributeBool("usecondition", true); - int count = subElement.GetAttributeInt("count", 1); - - - ItemPrefab requiredItem = MapEntityPrefab.Find(null, requiredItemIdentifier.Trim()) as ItemPrefab; - if (requiredItem == null) - { - DebugConsole.ThrowError("Error in fabricable item " + itemPrefab.Name + "! Required item \"" + requiredItemIdentifier + "\" not found."); - continue; - } - - var existing = RequiredItems.Find(r => r.ItemPrefab == requiredItem); - if (existing == null) - { - RequiredItems.Add(new RequiredItem(requiredItem, count, minCondition, useCondition)); - } - else - { - - RequiredItems.Remove(existing); - RequiredItems.Add(new RequiredItem(requiredItem, existing.Amount + count, minCondition, useCondition)); - } - - break; - } - } - } - } - partial class ItemPrefab : MapEntityPrefab { private readonly string configFile; @@ -142,8 +48,6 @@ namespace Barotrauma //the construction can be Activated() by a Character inside the area public List Triggers; - private List fabricationRecipeElements = new List(); - public string ConfigFile { get { return configFile; } @@ -411,18 +315,6 @@ namespace Barotrauma new ItemPrefab(doc.Root, filePath); } } - - //initialize item requirements for fabrication recipes - //(has to be done after all the item prefabs have been loaded, because the - //recipe ingredients may not have been loaded yet when loading the prefab) - foreach (MapEntityPrefab me in List) - { - if (!(me is ItemPrefab itemPrefab)) { continue; } - foreach (XElement fabricationRecipe in itemPrefab.fabricationRecipeElements) - { - itemPrefab.FabricationRecipes.Add(new FabricationRecipe(fabricationRecipe, itemPrefab)); - } - } } public ItemPrefab(XElement element, string filePath) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs index cc1b0cbbd..c3e9b1eae 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs @@ -568,7 +568,7 @@ namespace Barotrauma public void Extinguish(float deltaTime, float amount, Vector2 position) { - for (int i = FireSources.Count - 1; i >= 0; i--) + for (int i = FireSources.Count - 1; i >= 0; i-- ) { FireSources[i].Extinguish(deltaTime, amount, position); } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs index 0bcb4a4e7..1c3ec2339 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/LevelObjects/LevelTrigger.cs @@ -543,19 +543,19 @@ namespace Barotrauma if (ForceVelocityLimit < 1000.0f) body.ApplyForce(Force * currentForceFluctuation * distFactor, ForceVelocityLimit); else - body.ApplyForce(Force * currentForceFluctuation * distFactor, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + body.ApplyForce(Force * currentForceFluctuation * distFactor); break; case TriggerForceMode.Acceleration: if (ForceVelocityLimit < 1000.0f) body.ApplyForce(Force * body.Mass * currentForceFluctuation * distFactor, ForceVelocityLimit); else - body.ApplyForce(Force * body.Mass * currentForceFluctuation * distFactor, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + body.ApplyForce(Force * body.Mass * currentForceFluctuation * distFactor); break; case TriggerForceMode.Impulse: if (ForceVelocityLimit < 1000.0f) - body.ApplyLinearImpulse(Force * currentForceFluctuation * distFactor, maxVelocity: ForceVelocityLimit); + body.ApplyLinearImpulse(Force * currentForceFluctuation * distFactor, ForceVelocityLimit); else - body.ApplyLinearImpulse(Force * currentForceFluctuation * distFactor, maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + body.ApplyLinearImpulse(Force * currentForceFluctuation * distFactor); break; case TriggerForceMode.LimitVelocity: float maxVel = ForceVelocityLimit * currentForceFluctuation * distFactor; @@ -563,8 +563,7 @@ namespace Barotrauma { body.ApplyForce( Vector2.Normalize(-body.LinearVelocity) * - Force.Length() * body.Mass * currentForceFluctuation * distFactor, - maxVelocity: NetConfig.MaxPhysicsBodyVelocity); + Force.Length() * body.Mass * currentForceFluctuation * distFactor); } break; } diff --git a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs index 5c7bfa0f0..74b6afcb2 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs @@ -74,23 +74,5 @@ namespace Barotrauma.Networking if (lengthSqr > 1000.0f) { return Vector2.Zero; } return cursorPositionError *= 0.7f; } - - public static Vector2 Quantize(Vector2 value, float min, float max, int numberOfBits) - { - return new Vector2( - Quantize(value.X, min, max, numberOfBits), - Quantize(value.Y, min, max, numberOfBits)); - } - - public static float Quantize(float value, float min, float max, int numberOfBits) - { - float step = (max - min) / (1 << (numberOfBits + 1)); - if (Math.Abs(value) < step + 0.00001f) - { - return 0.0f; - } - - return MathUtils.RoundTowardsClosest(MathHelper.Clamp(value, min, max), step); - } } } diff --git a/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs b/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs index e4ee52c4c..0f4a6a40b 100644 --- a/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs +++ b/Barotrauma/BarotraumaShared/Source/Physics/PhysicsBody.cs @@ -605,7 +605,7 @@ namespace Barotrauma { if (!IsValidValue(impulse, "impulse", -1e10f, 1e10f)) return; if (!IsValidValue(point, "point")) return; - if (!IsValidValue(impulse / body.Mass, "new velocity", -1000.0f, 1000.0f)) return; + if (!IsValidValue(impulse / body.Mass, "new velocity")) return; body.ApplyLinearImpulse(impulse, point); } @@ -649,14 +649,11 @@ namespace Barotrauma if (!IsValidValue(force, "force", -1e10f, 1e10f)) return; if (!IsValidValue(maxVelocity, "max velocity")) return; + float currSpeed = body.LinearVelocity.Length(); Vector2 velocityAddition = force / Mass * (float)Timing.Step; Vector2 newVelocity = body.LinearVelocity + velocityAddition; - - float newSpeedSqr = newVelocity.LengthSquared(); - if (newSpeedSqr > maxVelocity * maxVelocity) - { - newVelocity = newVelocity.ClampLength(maxVelocity); - } + newVelocity = newVelocity.ClampLength(Math.Max(currSpeed, maxVelocity)); + body.ApplyForce((newVelocity - body.LinearVelocity) * Mass / (float)Timing.Step); }