Fixed entity linking not working

This commit is contained in:
juanjp600
2017-12-02 01:05:16 -03:00
parent ee04eecd49
commit 5cb603b3e5
3 changed files with 66 additions and 10 deletions
@@ -127,10 +127,15 @@ namespace Barotrauma
if (!prefab.IsLinkable) return; if (!prefab.IsLinkable) return;
if (!PlayerInput.LeftButtonClicked() || !PlayerInput.KeyDown(Keys.Space)) return; if (!PlayerInput.KeyDown(Keys.Space)) return;
bool lClick = PlayerInput.LeftButtonClicked();
bool rClick = PlayerInput.RightButtonClicked();
if (!lClick && !rClick) return;
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition); Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
if (lClick)
{
foreach (MapEntity entity in mapEntityList) foreach (MapEntity entity in mapEntityList)
{ {
if (entity == this || !entity.IsHighlighted) continue; if (entity == this || !entity.IsHighlighted) continue;
@@ -141,6 +146,19 @@ namespace Barotrauma
if (entity.IsLinkable && entity.linkedTo != null) entity.linkedTo.Add(this); if (entity.IsLinkable && entity.linkedTo != null) entity.linkedTo.Add(this);
} }
} }
else
{
foreach (MapEntity entity in mapEntityList)
{
if (entity == this || !entity.IsHighlighted) continue;
if (!linkedTo.Contains(entity)) continue;
if (!entity.IsMouseOn(position)) continue;
linkedTo.Remove(entity);
if (entity.linkedTo != null && entity.linkedTo.Contains(this)) entity.linkedTo.Remove(this);
}
}
}
public override void DrawEditing(SpriteBatch spriteBatch, Camera cam) public override void DrawEditing(SpriteBatch spriteBatch, Camera cam)
{ {
@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework.Input;
namespace Barotrauma namespace Barotrauma
{ {
@@ -57,6 +58,37 @@ namespace Barotrauma
return decal; return decal;
} }
public override void UpdateEditing(Camera cam)
{
if (!PlayerInput.KeyDown(Keys.Space)) return;
bool lClick = PlayerInput.LeftButtonClicked();
bool rClick = PlayerInput.RightButtonClicked();
if (!lClick && !rClick) return;
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
if (lClick)
{
foreach (MapEntity entity in mapEntityList)
{
if (entity == this || !entity.IsHighlighted) continue;
if (!entity.IsMouseOn(position)) continue;
if (entity.IsLinkable && entity.linkedTo != null) entity.linkedTo.Add(this);
}
}
else
{
foreach (MapEntity entity in mapEntityList)
{
if (entity == this || !entity.IsHighlighted) continue;
if (!entity.IsMouseOn(position)) continue;
if (entity.linkedTo != null && entity.linkedTo.Contains(this)) entity.linkedTo.Remove(this);
}
}
}
partial void UpdateProjSpecific(float deltaTime, Camera cam) partial void UpdateProjSpecific(float deltaTime, Camera cam)
{ {
if (EditWater) if (EditWater)
@@ -61,12 +61,18 @@ namespace Barotrauma
} }
[Serialize(false, false)] [Serialize(false, false)]
public virtual bool IsLinkable public bool Linkable //TODO: make this property's name consistent
{ {
get; get;
private set; private set;
} }
public virtual bool IsLinkable
{
get { return Linkable; }
private set { Linkable = value; }
}
public MapEntityCategory Category public MapEntityCategory Category
{ {
get; get;