From 71d546ff7f9be5303674d2c216b37ec7d113bb39 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 8 Apr 2019 19:17:50 +0300 Subject: [PATCH] (f36b3a111) Merge branch 'dev' of https://github.com/Regalis11/Barotrauma-development into dev --- .../Source/Characters/Character.cs | 22 +++++++++- .../Source/GameSession/CrewManager.cs | 3 -- .../Source/Items/Components/Repairable.cs | 35 ++++++++++++++-- .../Source/Screens/SubEditorScreen.cs | 40 ++++++++++--------- .../Animation/HumanoidAnimController.cs | 35 +--------------- .../Source/Items/Components/Repairable.cs | 29 ++++++++++---- .../BarotraumaShared/Source/PlayerInput.cs | 20 +++++++++- 7 files changed, 115 insertions(+), 69 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs index b43848f23..d7732124d 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs @@ -138,6 +138,9 @@ namespace Barotrauma } } + hudProgressBars = new Dictionary(); + } + partial void UpdateLimbLightSource(Limb limb) { if (limb.LightSource != null) @@ -146,12 +149,14 @@ namespace Barotrauma } } + private bool wasFiring; + /// /// Control the Character according to player input /// public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true) { - if (DisableControls) + if (DisableControls || GUI.PauseMenuOpen || GUI.SettingsMenuOpen) { foreach (Key key in keys) { @@ -161,10 +166,25 @@ 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 6b9d55aee..1a7eaf05b 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -276,9 +276,6 @@ 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 7e8fdc706..ddd2ffb29 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 + partial class Repairable : ItemComponent, IDrawableComponent { private GUIButton repairButton; private GUIProgressBar progressBar; @@ -25,7 +25,13 @@ 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; @@ -98,7 +104,7 @@ namespace Barotrauma.Items.Components } } } - + public override void DrawHUD(SpriteBatch spriteBatch, Character character) { IsActive = true; @@ -137,5 +143,28 @@ 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 a67c22472..1490f9866 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 subList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.9f), paddedLoadFrame.RectTransform)) + 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)) { + ScrollBarVisible = true, OnSelected = (GUIComponent selected, object userData) => { - Submarine sub = userData as Submarine; - if (paddedLoadFrame.FindChild("delete") is GUIButton deleteBtn) - { - deleteBtn.Enabled = !sub.IsVanillaSubmarine(); - } + if (deleteButtonHolder.FindChild("delete") is GUIButton deleteBtn) deleteBtn.Enabled = true; return true; } }; @@ -1307,17 +1307,7 @@ namespace Barotrauma } } - 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) }, + var deleteButton = new GUIButton(new RectTransform(new Vector2(1.0f, 1.0f), deleteButtonHolder.RectTransform, Anchor.TopCenter), TextManager.Get("Delete"), style: "GUIButtonLarge") { Enabled = false, @@ -1335,7 +1325,19 @@ namespace Barotrauma return true; }; - new GUIButton(new RectTransform(new Vector2(0.3f, 0.05f), paddedLoadFrame.RectTransform, Anchor.BottomRight), + 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), 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 f9dd8f513..f1e3c96d7 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs @@ -800,40 +800,7 @@ 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() diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs index f10a3bf3f..706317e0e 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Repairable.cs @@ -66,6 +66,14 @@ 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 { @@ -190,38 +198,43 @@ namespace Barotrauma.Items.Components if (LastActiveTime > Timing.TotalTime) { return true; } foreach (ItemComponent ic in item.Components) { - if (ic is PowerTransfer pt) + if (ic is Fabricator || ic is Deconstructor) + { + //fabricators and deconstructors rely on LastActiveTime + return false; + } + else 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 false; } + if (Math.Abs(pt.CurrPowerConsumption) > 0.1f) { return true; } } else if (ic is Engine engine) { //engines don't deteriorate if they're not running - if (Math.Abs(engine.Force) < 1.0f) { return false; } + if (Math.Abs(engine.Force) > 1.0f) { return true; } } else if (ic is Pump pump) { //pumps don't deteriorate if they're not running - if (Math.Abs(pump.FlowPercentage) < 1.0f) { return false; } + if (Math.Abs(pump.FlowPercentage) > 1.0f) { return true; } } else if (ic is Reactor reactor) { //reactors don't deteriorate if they're not powered up - if (reactor.Temperature < 0.1f) { return false; } + if (reactor.Temperature > 0.1f) { return true; } } else if (ic is OxygenGenerator oxyGenerator) { //oxygen generators don't deteriorate if they're not running - if (oxyGenerator.CurrFlow < 0.1f) { return false; } + if (oxyGenerator.CurrFlow > 0.1f) { return true; } } else if (ic is Powered powered) { - if (powered.Voltage < powered.MinVoltage) { return false; } + if (powered.Voltage >= powered.MinVoltage) { return true; } } } - return true; + return DeteriorateAlways; } private void UpdateFixAnimation(Character character) diff --git a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs index a10a8c412..1f29bd4dd 100644 --- a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs +++ b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs @@ -86,6 +86,25 @@ 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) { @@ -133,7 +152,6 @@ namespace Barotrauma { get { return binding; } } -#endif public void SetState() {