If focused on both a character and an item, the one that's closer to the cursor can be interacted with (instead of characters having higher priority, because that would make it impossible to interact with items that are next to a dead/unconscious character). Selected characters can also be deselected without highlighting the character with the cursor.

+ extra null check in HasRequiredItems
This commit is contained in:
Joonas Rikkonen
2017-07-08 14:32:01 +03:00
parent 4d2e7c33b1
commit 4e4983f0a6
2 changed files with 15 additions and 16 deletions
@@ -1232,13 +1232,14 @@ namespace Barotrauma
if ((!isLocalPlayer && IsKeyHit(InputType.Select) && GameMain.Server == null) || (isLocalPlayer && (findFocusedTimer <= 0.0f || Screen.Selected == GameMain.EditMapScreen))) if ((!isLocalPlayer && IsKeyHit(InputType.Select) && GameMain.Server == null) || (isLocalPlayer && (findFocusedTimer <= 0.0f || Screen.Selected == GameMain.EditMapScreen)))
{ {
focusedCharacter = FindCharacterAtPosition(mouseSimPos); focusedCharacter = FindCharacterAtPosition(mouseSimPos);
if (focusedCharacter != null) focusedItem = FindItemAtPosition(mouseSimPos, AnimController.InWater ? 0.5f : 0.25f);
if (focusedCharacter != null && focusedItem != null)
{ {
focusedItem = null; // We can only focus one thing at a time if (Vector2.DistanceSquared(mouseSimPos, focusedCharacter.SimPosition) > Vector2.DistanceSquared(mouseSimPos, focusedItem.SimPosition))
} {
else focusedCharacter = null;
{ }
focusedItem = FindItemAtPosition(mouseSimPos, AnimController.InWater ? 0.5f : 0.25f);
} }
findFocusedTimer = 0.05f; findFocusedTimer = 0.05f;
} }
@@ -1247,16 +1248,13 @@ namespace Barotrauma
findFocusedTimer -= deltaTime; findFocusedTimer -= deltaTime;
} }
if (focusedCharacter != null && IsKeyHit(InputType.Select)) if (selectedCharacter != null && IsKeyHit(InputType.Select))
{ {
if (selectedCharacter != null) DeselectCharacter();
{ }
DeselectCharacter(); else if (focusedCharacter != null && IsKeyHit(InputType.Select))
} {
else SelectCharacter(focusedCharacter);
{
SelectCharacter(focusedCharacter);
}
} }
else if (focusedItem != null) else if (focusedItem != null)
{ {
@@ -437,6 +437,7 @@ namespace Barotrauma.Items.Components
public bool HasRequiredItems(Character character, bool addMessage) public bool HasRequiredItems(Character character, bool addMessage)
{ {
if (!requiredItems.Any()) return true; if (!requiredItems.Any()) return true;
if (character.Inventory == null) return false;
foreach (RelatedItem ri in requiredItems) foreach (RelatedItem ri in requiredItems)
{ {
@@ -449,7 +450,7 @@ namespace Barotrauma.Items.Components
} }
if (!hasItem && ri.Type.HasFlag(RelatedItem.RelationType.Picked)) if (!hasItem && ri.Type.HasFlag(RelatedItem.RelationType.Picked))
{ {
if (character.Inventory.Items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true; if (character.Inventory.Items.FirstOrDefault(x => x != null && x.Condition > 0.0f && ri.MatchesItem(x)) != null) hasItem = true;
} }
if (!hasItem) if (!hasItem)
{ {