From d98c245183eb27d195898a2b1df48cb62e058624 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 25 Apr 2019 17:46:26 +0300 Subject: [PATCH] (714944a46) - Item triggers can be used to define areas that cause the item to be highlighted, not just areas that the player has to be inside to interact with the item. - Triggers take item scale into account. - Added triggers around the integrated buttons in the new hatch/window variants (-> fixes hatches not being highlighted by putting the cursor on the button when there's a ladder next to the player). --- .../Source/Characters/Character.cs | 9 ++++----- .../BarotraumaShared/Source/Items/Item.cs | 16 ++++++++-------- .../BarotraumaShared/Source/Items/ItemPrefab.cs | 17 ++++++++++++++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 29a014669..b8f27ed24 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -1546,12 +1546,11 @@ namespace Barotrauma } } } - - - if (item.InteractDistance == 0.0f && !item.Prefab.Triggers.Any()) return false; + + if (item.InteractDistance == 0.0f && !item.Prefab.Triggers.Any()) { return false; } Pickable pickableComponent = item.GetComponent(); - if (pickableComponent != null && (pickableComponent.Picker != null && !pickableComponent.Picker.IsDead)) return false; + if (pickableComponent != null && (pickableComponent.Picker != null && !pickableComponent.Picker.IsDead)) { return false; } Vector2 characterDirection = Vector2.Transform(Vector2.UnitY, Matrix.CreateRotationZ(AnimController.Collider.Rotation)); @@ -1565,7 +1564,7 @@ namespace Barotrauma } bool insideTrigger = item.IsInsideTrigger(upperBodyPosition) || item.IsInsideTrigger(lowerBodyPosition); - if (item.Prefab.Triggers.Count > 0 && !insideTrigger) return false; + if (item.Prefab.Triggers.Count > 0 && !insideTrigger && item.Prefab.RequireBodyInsideTrigger) { return false; } Rectangle itemDisplayRect = new Rectangle(item.InteractionRect.X, item.InteractionRect.Y - item.InteractionRect.Height, item.InteractionRect.Width, item.InteractionRect.Height); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 3b41a4437..1622e76e8 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -833,16 +833,16 @@ namespace Barotrauma { return world ? new Rectangle( - WorldRect.X + trigger.X, - WorldRect.Y + trigger.Y, - (trigger.Width == 0) ? Rect.Width : trigger.Width, - (trigger.Height == 0) ? Rect.Height : trigger.Height) + (int)(WorldRect.X + trigger.X * Scale), + (int)(WorldRect.Y + trigger.Y * Scale), + (trigger.Width == 0) ? Rect.Width : (int)(trigger.Width * Scale), + (trigger.Height == 0) ? Rect.Height : (int)(trigger.Height * Scale)) : new Rectangle( - Rect.X + trigger.X, - Rect.Y + trigger.Y, - (trigger.Width == 0) ? Rect.Width : trigger.Width, - (trigger.Height == 0) ? Rect.Height : trigger.Height); + (int)(Rect.X + trigger.X * Scale), + (int)(Rect.Y + trigger.Y * Scale), + (trigger.Width == 0) ? Rect.Width : (int)(trigger.Width * Scale), + (trigger.Height == 0) ? Rect.Height : (int)(trigger.Height * Scale)); } /// diff --git a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs index c9301ebb3..b3fb03da7 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -132,14 +132,16 @@ namespace Barotrauma //default size protected Vector2 size; - private float impactTolerance; + private List fabricationRecipeElements = new List(); private bool canSpriteFlipX, canSpriteFlipY; private Dictionary prices; - //an area next to the construction - //the construction can be Activated() by a Character inside the area + /// + /// Defines areas where the item can be interacted with. If RequireBodyInsideTrigger is set to true, the character + /// has to be within the trigger to interact. If it's set to false, having the cursor within the trigger is enough. + /// public List Triggers; private List fabricationRecipeElements = new List(); @@ -196,6 +198,15 @@ namespace Barotrauma private set; } + //if true and the item has trigger areas defined, characters need to be within the trigger to interact with the item + //if false, trigger areas define areas that can be used to highlight the item + [Serialize(true, false)] + public bool RequireBodyInsideTrigger + { + get; + private set; + } + //should the camera focus on the item when selected [Serialize(false, false)]