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

View File

@@ -127,18 +127,36 @@ namespace Barotrauma
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);
foreach (MapEntity entity in mapEntityList)
if (lClick)
{
if (entity == this || !entity.IsHighlighted) continue;
if (linkedTo.Contains(entity)) continue;
if (!entity.IsMouseOn(position)) continue;
foreach (MapEntity entity in mapEntityList)
{
if (entity == this || !entity.IsHighlighted) continue;
if (linkedTo.Contains(entity)) continue;
if (!entity.IsMouseOn(position)) continue;
linkedTo.Add(entity);
if (entity.IsLinkable && entity.linkedTo != null) entity.linkedTo.Add(this);
linkedTo.Add(entity);
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);
}
}
}

View File

@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Input;
namespace Barotrauma
{
@@ -56,7 +57,38 @@ namespace Barotrauma
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)
{
if (EditWater)

View File

@@ -59,13 +59,19 @@ namespace Barotrauma
get;
protected set;
}
[Serialize(false, false)]
public virtual bool IsLinkable
public bool Linkable //TODO: make this property's name consistent
{
get;
private set;
}
public virtual bool IsLinkable
{
get { return Linkable; }
private set { Linkable = value; }
}
public MapEntityCategory Category
{