Character view model and fixed character display

This commit is contained in:
Westin Miller
2018-01-26 21:48:46 -08:00
parent 725e555733
commit 17413f81ff
7 changed files with 81 additions and 5 deletions

View File

@@ -6,7 +6,12 @@ namespace Torch.Server.ViewModels.Entities
{
public CharacterViewModel(MyCharacter character, EntityTreeViewModel tree) : base(character, tree)
{
character.ControllerInfo.ControlAcquired += (x) => { OnPropertyChanged(nameof(Name)); };
character.ControllerInfo.ControlReleased += (x) => { OnPropertyChanged(nameof(Name)); };
}
public CharacterViewModel()
{
}
}
}

View File

@@ -1,7 +1,9 @@
using System.Windows.Controls;
using Sandbox.Game.World;
using Torch.API.Managers;
using Torch.Collections;
using Torch.Server.Managers;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRageMath;
@@ -32,10 +34,11 @@ namespace Torch.Server.ViewModels.Entities
public virtual string Name
{
get => Entity?.DisplayName;
get => Entity?.DisplayName ?? (Entity != null ? $"eid:{Entity.EntityId}" : "nil");
set
{
TorchBase.Instance.InvokeBlocking(() => Entity.DisplayName = value);
if (Entity!=null)
TorchBase.Instance.InvokeBlocking(() => Entity.DisplayName = value);
OnPropertyChanged();
}
}
@@ -48,7 +51,8 @@ namespace Torch.Server.ViewModels.Entities
if (!Vector3D.TryParse(value, out Vector3D v))
return;
TorchBase.Instance.InvokeBlocking(() => Entity.SetPosition(v));
if (Entity != null)
TorchBase.Instance.InvokeBlocking(() => Entity.SetPosition(v));
OnPropertyChanged();
}
}