From 9a829206af97a9971bd2fc30b69b3ce3f26ea222 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 8 Apr 2019 19:17:06 +0300 Subject: [PATCH] (2c264b075) Improve readability (no functional changes). --- .../Source/Characters/Character.cs | 21 +------ .../Source/GameSession/CrewManager.cs | 3 + .../Source/Items/Components/Repairable.cs | 35 +---------- .../Source/Screens/SubEditorScreen.cs | 40 ++++++------ .../Animation/HumanoidAnimController.cs | 63 +++++++++++++++---- .../Source/Items/Components/Repairable.cs | 29 +++------ .../BarotraumaShared/Source/PlayerInput.cs | 20 +----- 7 files changed, 85 insertions(+), 126 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs index 4e611d6a6..b43848f23 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs @@ -136,8 +136,6 @@ namespace Barotrauma break; } } - - hudProgressBars = new Dictionary(); } partial void UpdateLimbLightSource(Limb limb) @@ -148,14 +146,12 @@ namespace Barotrauma } } - private bool wasFiring; - /// /// Control the Character according to player input /// public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true) { - if (DisableControls || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) + if (DisableControls) { foreach (Key key in keys) { @@ -165,25 +161,10 @@ namespace Barotrauma } else { - wasFiring |= keys[(int)InputType.Aim].Held && keys[(int)InputType.Shoot].Held; for (int i = 0; i < keys.Length; i++) { keys[i].SetState(); } - //if we were firing (= pressing the aim and shoot keys at the same time) - //and the fire key is the same as Select or Use, reset the key to prevent accidentally selecting/using items - if (wasFiring && !keys[(int)InputType.Shoot].Held) - { - if (GameMain.Config.KeyBind(InputType.Shoot).Equals(GameMain.Config.KeyBind(InputType.Select))) - { - keys[(int)InputType.Select].Reset(); - } - if (GameMain.Config.KeyBind(InputType.Shoot).Equals(GameMain.Config.KeyBind(InputType.Use))) - { - keys[(int)InputType.Use].Reset(); - } - wasFiring = false; - } float targetOffsetAmount = 0.0f; if (moveCam) diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs index 1a7eaf05b..6b9d55aee 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -276,6 +276,9 @@ namespace Barotrauma characterInfos.Add(characterInfo); } + characterInfos.Add(characterInfo); + } + /// /// Remove the character from the crew (and crew menus). /// diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Repairable.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Repairable.cs index ddd2ffb29..7e8fdc706 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Repairable.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Repairable.cs @@ -8,7 +8,7 @@ using System.Xml.Linq; namespace Barotrauma.Items.Components { - partial class Repairable : ItemComponent, IDrawableComponent + partial class Repairable : ItemComponent { private GUIButton repairButton; private GUIProgressBar progressBar; @@ -25,13 +25,7 @@ namespace Barotrauma.Items.Components get; set; } - - public Vector2 DrawSize - { - //use the extents of the item as the draw size - get { return Vector2.Zero; } - } - + public override bool ShouldDrawHUD(Character character) { if (!HasRequiredItems(character, false) || character.SelectedConstruction != item) return false; @@ -104,7 +98,7 @@ namespace Barotrauma.Items.Components } } } - + public override void DrawHUD(SpriteBatch spriteBatch, Character character) { IsActive = true; @@ -143,28 +137,5 @@ namespace Barotrauma.Items.Components { //no need to write anything, just letting the server know we started repairing } - - public void Draw(SpriteBatch spriteBatch, bool editing) - { - if (GameMain.DebugDraw && Character.Controlled?.FocusedItem == item) - { - bool paused = !ShouldDeteriorate(); - if (deteriorationTimer > 0.0f) - { - GUI.DrawString(spriteBatch, - new Vector2(item.WorldPosition.X, -item.WorldPosition.Y), "Deterioration delay " + ((int)deteriorationTimer) + (paused ? " [PAUSED]" : ""), - paused ? Color.Cyan : Color.Lime, Color.Black * 0.5f); - } - else - { - GUI.DrawString(spriteBatch, - new Vector2(item.WorldPosition.X, -item.WorldPosition.Y), "Deteriorating at " + (int)(DeteriorationSpeed * 60.0f) + " units/min" + (paused ? " [PAUSED]" : ""), - paused ? Color.Cyan : Color.Red, Color.Black * 0.5f); - } - GUI.DrawString(spriteBatch, - new Vector2(item.WorldPosition.X, -item.WorldPosition.Y + 20), "Condition: " + (int)item.Condition + "/" + (int)item.MaxCondition, - Color.Orange); - } - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs index 1490f9866..a67c22472 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/SubEditorScreen.cs @@ -1272,17 +1272,17 @@ namespace Barotrauma }; var innerFrame = new GUIFrame(new RectTransform(new Vector2(0.2f, 0.36f), loadFrame.RectTransform, Anchor.Center) { MinSize = new Point(350, 500) }); + GUIFrame paddedLoadFrame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center), style: null); - var paddedLoadFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.9f), innerFrame.RectTransform, Anchor.Center)) { Stretch = true, RelativeSpacing = 0.05f }; - - var deleteButtonHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), paddedLoadFrame.RectTransform, Anchor.Center)); - - var subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 1.0f), paddedLoadFrame.RectTransform)) + var subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.9f), paddedLoadFrame.RectTransform)) { - ScrollBarVisible = true, OnSelected = (GUIComponent selected, object userData) => { - if (deleteButtonHolder.FindChild("delete") is GUIButton deleteBtn) deleteBtn.Enabled = true; + Submarine sub = userData as Submarine; + if (paddedLoadFrame.FindChild("delete") is GUIButton deleteBtn) + { + deleteBtn.Enabled = !sub.IsVanillaSubmarine(); + } return true; } }; @@ -1307,7 +1307,17 @@ namespace Barotrauma } } - var deleteButton = new GUIButton(new RectTransform(new Vector2(1.0f, 1.0f), deleteButtonHolder.RectTransform, Anchor.TopCenter), + new GUIButton(new RectTransform(new Vector2(0.3f, 0.05f), paddedLoadFrame.RectTransform, Anchor.BottomLeft), + TextManager.Get("Cancel"), style: "GUIButtonLarge") + { + OnClicked = (GUIButton btn, object userdata) => + { + loadFrame = null; + return true; + } + }; + + var deleteButton = new GUIButton(new RectTransform(new Vector2(0.3f, 0.05f), paddedLoadFrame.RectTransform, Anchor.BottomRight) { RelativeOffset = new Vector2(0.31f, 0.0f) }, TextManager.Get("Delete"), style: "GUIButtonLarge") { Enabled = false, @@ -1325,19 +1335,7 @@ namespace Barotrauma return true; }; - var controlBtnHolder = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.1f), paddedLoadFrame.RectTransform), isHorizontal: true) { RelativeSpacing = 0.2f, Stretch = true }; - - new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), controlBtnHolder.RectTransform, Anchor.BottomLeft), - TextManager.Get("Cancel"), style: "GUIButtonLarge") - { - OnClicked = (GUIButton btn, object userdata) => - { - loadFrame = null; - return true; - } - }; - - new GUIButton(new RectTransform(new Vector2(0.5f, 1.0f), controlBtnHolder.RectTransform, Anchor.BottomRight), + new GUIButton(new RectTransform(new Vector2(0.3f, 0.05f), paddedLoadFrame.RectTransform, Anchor.BottomRight), TextManager.Get("Load"), style: "GUIButtonLarge") { OnClicked = LoadSub diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs index 529c2d3bc..f9dd8f513 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs @@ -800,7 +800,40 @@ namespace Barotrauma Collider.LinearVelocity.Y > 0.0f ? Collider.LinearVelocity.Y * 0.5f : Collider.LinearVelocity.Y); } } - + + private void ClimbOverObstacles() + { + if (Collider.FarseerBody.ContactList == null || Math.Abs(movement.X) < 0.01f) return; + + //check if the collider is touching a suitable obstacle to climb over + Vector2? handle = null; + FarseerPhysics.Dynamics.Contacts.ContactEdge ce = Collider.FarseerBody.ContactList; + while (ce != null && ce.Contact != null) + { + if (ce.Contact.Enabled && ce.Contact.IsTouching && ce.Contact.FixtureA.CollisionCategories.HasFlag(Physics.CollisionWall)) + { + Vector2 contactNormal; + FarseerPhysics.Common.FixedArray2 contactPos; + ce.Contact.GetWorldManifold(out contactNormal, out contactPos); + + //only climb if moving towards the obstacle + if (Math.Sign(contactPos[0].X - Collider.SimPosition.X) == Math.Sign(movement.X) && + (handle == null || contactPos[0].Y > ((Vector2)handle).Y)) + { + handle = contactPos[0]; + } + } + + ce = ce.Next; + } + else if (onGround && (!character.IsRemotePlayer || (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer))) + { + Collider.LinearVelocity = new Vector2( + movement.X, + Collider.LinearVelocity.Y > 0.0f ? Collider.LinearVelocity.Y * 0.5f : Collider.LinearVelocity.Y); + } + } + private float handCyclePos; private float legCyclePos; void UpdateSwimming() @@ -1155,23 +1188,27 @@ namespace Barotrauma Rectangle trigger = character.SelectedConstruction.Prefab.Triggers.FirstOrDefault(); trigger = character.SelectedConstruction.TransformTrigger(trigger); - bool notClimbing = false; - - bool isNotRemote = true; - if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) isNotRemote = !character.IsRemotePlayer; - - if (isNotRemote) + bool isRemote = false; + bool isClimbing = true; + if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { - notClimbing = character.IsKeyDown(InputType.Left) || character.IsKeyDown(InputType.Right); + isRemote = character.IsRemotePlayer; } - else + if (isRemote) { - notClimbing = Math.Abs(targetMovement.X) > 0.05f || - (TargetMovement.Y < 0.0f && ConvertUnits.ToSimUnits(trigger.Height) + handPos.Y < HeadPosition) || - (TargetMovement.Y > 0.0f && handPos.Y > 0.1f); + if (Math.Abs(targetMovement.X) > 0.05f || + (TargetMovement.Y < 0.0f && ConvertUnits.ToSimUnits(trigger.Height) + handPos.Y < HeadPosition) || + (TargetMovement.Y > 0.0f && handPos.Y > 0.1f)) + { + isClimbing = false; + } + } + else if (character.IsKeyDown(InputType.Left) || character.IsKeyDown(InputType.Right)) + { + isClimbing = false; } - if (notClimbing) + if (!isClimbing) { Anim = Animation.None; character.SelectedConstruction = null; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs index 706317e0e..f10a3bf3f 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs @@ -66,14 +66,6 @@ namespace Barotrauma.Items.Components set; } - //if enabled, the deterioration timer will always run regardless if the item is being used or not - [Serialize(false, false)] - public bool DeteriorateAlways - { - get; - set; - } - private Character currentFixer; public Character CurrentFixer { @@ -198,43 +190,38 @@ namespace Barotrauma.Items.Components if (LastActiveTime > Timing.TotalTime) { return true; } foreach (ItemComponent ic in item.Components) { - if (ic is Fabricator || ic is Deconstructor) - { - //fabricators and deconstructors rely on LastActiveTime - return false; - } - else if (ic is PowerTransfer pt) + if (ic is PowerTransfer pt) { //power transfer items (junction boxes, relays) don't deteriorate if they're no carrying any power - if (Math.Abs(pt.CurrPowerConsumption) > 0.1f) { return true; } + if (Math.Abs(pt.CurrPowerConsumption) < 0.1f) { return false; } } else if (ic is Engine engine) { //engines don't deteriorate if they're not running - if (Math.Abs(engine.Force) > 1.0f) { return true; } + if (Math.Abs(engine.Force) < 1.0f) { return false; } } else if (ic is Pump pump) { //pumps don't deteriorate if they're not running - if (Math.Abs(pump.FlowPercentage) > 1.0f) { return true; } + if (Math.Abs(pump.FlowPercentage) < 1.0f) { return false; } } else if (ic is Reactor reactor) { //reactors don't deteriorate if they're not powered up - if (reactor.Temperature > 0.1f) { return true; } + if (reactor.Temperature < 0.1f) { return false; } } else if (ic is OxygenGenerator oxyGenerator) { //oxygen generators don't deteriorate if they're not running - if (oxyGenerator.CurrFlow > 0.1f) { return true; } + if (oxyGenerator.CurrFlow < 0.1f) { return false; } } else if (ic is Powered powered) { - if (powered.Voltage >= powered.MinVoltage) { return true; } + if (powered.Voltage < powered.MinVoltage) { return false; } } } - return DeteriorateAlways; + return true; } private void UpdateFixAnimation(Character character) diff --git a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs index 1f29bd4dd..a10a8c412 100644 --- a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs +++ b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs @@ -86,25 +86,6 @@ namespace Barotrauma } public override bool Equals(object obj) - { - if (obj is KeyOrMouse keyOrMouse ) - { - if (MouseButton.HasValue) - { - return keyOrMouse.MouseButton.HasValue && keyOrMouse.MouseButton.Value == MouseButton.Value; - } - else - { - return keyOrMouse.Key.Equals(Key); - } - } - else - { - return false; - } - } - - public override string ToString() { switch (MouseButton) { @@ -152,6 +133,7 @@ namespace Barotrauma { get { return binding; } } +#endif public void SetState() {