Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions OpenDreamClient/ClientVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ public IEnumerable<VerbInfo> GetAllVerbs() {
/// <returns>The ID, src, and information of every executable verb</returns>
public IEnumerable<(int Id, ClientObjectReference Src, VerbInfo VerbInfo)> GetExecutableVerbs(bool ignoreHiddenAttr = false) {
sbyte? seeInvisibility = null;
if (_playerManager.LocalEntity != null) {
_sightQuery.TryGetComponent(_playerManager.LocalEntity.Value, out var mobSight);

EntityUid mob = _interfaceManager.MobUid;
if (mob.IsValid()) {
_sightQuery.TryGetComponent(mob, out var mobSight);

seeInvisibility = mobSight?.SeeInvisibility;
}
Expand Down Expand Up @@ -120,12 +122,12 @@ public IEnumerable<VerbInfo> GetAllVerbs() {
// Check the verb's "set src" allows us to execute this
switch (verb.Accessibility) {
case VerbAccessibility.Usr:
if (entity != _playerManager.LocalEntity)
if (entity != mob)
continue;

break;
case VerbAccessibility.InUsr:
if (_transformSystem.GetParentUid(entity) != _playerManager.LocalEntity)
if (_transformSystem.GetParentUid(entity) != mob)
continue;

break;
Expand Down
4 changes: 3 additions & 1 deletion OpenDreamClient/Input/ContextMenu/ContextMenuPopup.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OpenDreamClient.Interface;
using OpenDreamClient.Interface.Controls.UI;
using OpenDreamClient.Rendering;
using OpenDreamShared.Dream;
Expand All @@ -18,6 +19,7 @@ internal sealed partial class ContextMenuPopup : Popup {
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IDreamInterfaceManager _dreamInterfaceManager = default!;
private readonly ClientAppearanceSystem _appearanceSystem;
private readonly ClientVerbSystem _verbSystem;
private readonly DMISpriteSystem _spriteSystem;
Expand Down Expand Up @@ -115,7 +117,7 @@ public void SetActiveItem(ContextMenuItem item) {
private sbyte GetSeeInvisible() {
if (_playerManager.LocalSession == null)
return 127;
if (!_mobSightQuery.TryGetComponent(_playerManager.LocalSession.AttachedEntity, out DreamMobSightComponent? sight))
if (!_mobSightQuery.TryGetComponent(_dreamInterfaceManager.MobUid, out DreamMobSightComponent? sight))
return 127;

return sight.SeeInvisibility;
Expand Down
67 changes: 59 additions & 8 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
using System.IO;
using System.Text;
using System.Globalization;
using OpenDreamShared.Network.Messages;
using OpenDreamClient.Interface.Controls;
using OpenDreamShared.Interface.Descriptors;
using OpenDreamShared.Interface.DMF;
using OpenDreamClient.Interface.Controls;
using OpenDreamClient.Interface.Prompts;
using OpenDreamClient.Resources;
using OpenDreamClient.Resources.ResourceTypes;
using OpenDreamShared.Dream;
using OpenDreamShared.Interface.Descriptors;
using OpenDreamShared.Interface.DMF;
using OpenDreamShared.Network.Messages;
using Robust.Client;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.ContentPack;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using SixLabors.ImageSharp;
using System.Globalization;
using System.IO;
using System.Linq;
using Robust.Shared.Map;
using System.Text;

namespace OpenDreamClient.Interface;

Expand All @@ -41,9 +42,12 @@ internal sealed class DreamInterfaceManager : IDreamInterfaceManager {
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

[Dependency] private readonly ITimerManager _timerManager = default!;
[Dependency] private readonly IUriOpener _uriOpener = default!;
[Dependency] private readonly IGameController _gameController = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

private readonly ISawmill _sawmill = Logger.GetSawmill("opendream.interface");

Expand All @@ -60,6 +64,34 @@ internal sealed class DreamInterfaceManager : IDreamInterfaceManager {
private Dictionary<WindowId, ControlWindow> ClydeWindowIdToControl { get; } = new();
public CursorHolder Cursors { get; private set; } = default!;

// Current Entity of player's mob, or Invalid if could not be determined.
private EntityUid _mobUid = EntityUid.Invalid;

public EntityUid MobUid {
get {
if (_mobUid.IsValid()) {
return _mobUid;
} else {
return _playerManager.LocalSession?.AttachedEntity.GetValueOrDefault(EntityUid.Invalid) ?? EntityUid.Invalid;
}
}
private set => _mobUid = value;
}

// Current Entity of player's eye, or Invalid if could not be determined.
private EntityUid _eyeUid = EntityUid.Invalid;

public EntityUid EyeUid {
get {
if (_eyeUid.IsValid()) {
return _eyeUid;
} else {
return _playerManager.LocalSession?.AttachedEntity.GetValueOrDefault(EntityUid.Invalid) ?? EntityUid.Invalid;
}
}
private set => _eyeUid = value;
}

public ViewRange View {
get => _view;
private set {
Expand Down Expand Up @@ -131,6 +163,7 @@ public void Initialize() {
_netManager.RegisterNetMessage<MsgLoadInterface>(RxLoadInterface);
_netManager.RegisterNetMessage<MsgAckLoadInterface>();
_netManager.RegisterNetMessage<MsgUpdateClientInfo>(RxUpdateClientInfo);
_netManager.RegisterNetMessage<MsgNotifyMobEyeUpdate>(RxNotifyMobEyeUpdate);
_clyde.OnWindowFocused += OnWindowFocused;
}

Expand Down Expand Up @@ -339,6 +372,22 @@ private void RxUpdateClientInfo(MsgUpdateClientInfo msg) {
}
}

private void RxNotifyMobEyeUpdate(MsgNotifyMobEyeUpdate msg) {
var mob = _entityManager.GetEntity(msg.MobNetEntity);
if (mob.IsValid()) {
MobUid = mob;
} else {
MobUid = _playerManager.LocalSession?.AttachedEntity.GetValueOrDefault(EntityUid.Invalid) ?? EntityUid.Invalid;
}

var eye = _entityManager.GetEntity(msg.EyeNetEntity);
if (eye.IsValid()) {
EyeUid = eye;
} else {
EyeUid = _playerManager.LocalSession?.AttachedEntity.GetValueOrDefault(EntityUid.Invalid) ?? EntityUid.Invalid;
}
}

private void ShowPrompt(PromptWindow prompt) {
prompt.Owner = _clyde.MainWindow;
prompt.Show();
Expand Down Expand Up @@ -1081,6 +1130,8 @@ public interface IDreamInterfaceManager {
public bool ShowPopupMenus { get; }
public int IconSize { get; }
public CursorHolder Cursors { get; }
public EntityUid MobUid { get; }
public EntityUid EyeUid { get; }

void Initialize();
void FrameUpdate(FrameEventArgs frameEventArgs);
Expand Down
2 changes: 2 additions & 0 deletions OpenDreamClient/Interface/DummyDreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public sealed class DummyDreamInterfaceManager : IDreamInterfaceManager {
public bool ShowPopupMenus => true;
public int IconSize => 32;
public CursorHolder Cursors => null!;
public EntityUid MobUid => EntityUid.Invalid;
public EntityUid EyeUid => EntityUid.Invalid;

[Dependency] private readonly IClientNetManager _netManager = default!;

Expand Down
19 changes: 13 additions & 6 deletions OpenDreamClient/Rendering/DreamViewOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,21 @@ public DreamViewOverlay(RenderTargetPool renderTargetPool) {
protected override void Draw(in OverlayDrawArgs args) {
using var _ = _prof.Group("Dream View Overlay");

EntityUid? eye = _playerManager.LocalSession?.AttachedEntity;
if (eye == null)
EntityUid eye = _interfaceManager.EyeUid;
if (!eye.IsValid()) {
return;
}

EntityUid mob = _interfaceManager.MobUid;
if (!mob.IsValid()) {
return;
}

//Main drawing of sprites happens here
try {
var viewportSize = (Vector2i)(args.Viewport.Size / args.Viewport.RenderScale);

DrawAll(args, eye.Value, viewportSize);
DrawAll(args, mob, eye, viewportSize);
} catch (Exception e) {
_sawmill.Error($"Error occurred while rendering frame. Error details:\n{e.Message}\n{e.StackTrace}");
}
Expand All @@ -145,17 +151,18 @@ protected override void Draw(in OverlayDrawArgs args) {
_rendererMetaDataRental.Push(_rendererMetaDataToReturn.Pop());
}

private void DrawAll(OverlayDrawArgs args, EntityUid eye, Vector2i viewportSize) {
private void DrawAll(OverlayDrawArgs args, EntityUid mob, EntityUid eye, Vector2i viewportSize) {
if (!_xformQuery.TryGetComponent(eye, out var eyeTransform))
return;

var eyeCoords = _transformSystem.GetMapCoordinates(eye, eyeTransform);
if (!_mapManager.TryFindGridAt(eyeCoords, out var gridUid, out var grid))
return;

_mobSightQuery.TryGetComponent(eye, out var mobSight);
_mobSightQuery.TryGetComponent(mob, out var mobSight);
_mobSightQuery.TryGetComponent(eye, out var eyeSight);
var seeVis = mobSight?.SeeInvisibility ?? 127;
var sight = mobSight?.Sight ?? 0;
var sight = eyeSight?.Sight ?? 0;

var worldHandle = args.WorldHandle;
var worldAABB = args.WorldAABB;
Expand Down
19 changes: 17 additions & 2 deletions OpenDreamRuntime/DreamConnection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Threading.Tasks;
using System.Web;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Objects.Types;
using OpenDreamRuntime.Procs.Native;
Expand All @@ -10,6 +8,8 @@
using Robust.Shared.Enums;
using Robust.Shared.Player;
using SpaceWizards.Sodium;
using System.Threading.Tasks;
using System.Web;

namespace OpenDreamRuntime;

Expand All @@ -18,6 +18,7 @@ public sealed class DreamConnection {
[Dependency] private readonly DreamObjectTree _objectTree = default!;
[Dependency] private readonly DreamResourceManager _resourceManager = default!;
[Dependency] private readonly WalkManager _walkManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;

Expand Down Expand Up @@ -51,6 +52,8 @@ [ViewVariables] public DreamObjectMob? Mob {
Eye = value;
}

UpdateMobEye();

if (_mob != null) {
// If the mob is already owned by another player, kick them out
if (_mob.Connection != null)
Expand All @@ -69,6 +72,8 @@ [ViewVariables] public DreamObjectMovable? Eye {
set {
_eye = value;
_playerManager.SetAttachedEntity(Session!, _eye?.Entity);

UpdateMobEye();
}
}

Expand Down Expand Up @@ -504,4 +509,14 @@ public bool TryConvertPromptResponse(DreamValueType type, object? value, out Dre
converted = default;
return false;
}

private void UpdateMobEye() {
var mobUid = Mob?.Entity.Id ?? EntityUid.Invalid.Id;
var eyeUid = Eye?.Entity.Id ?? EntityUid.Invalid.Id;
var msg = new MsgNotifyMobEyeUpdate() {
MobNetEntity = _entityManager.GetNetEntity(new(mobUid)),
EyeNetEntity = _entityManager.GetNetEntity(new(eyeUid))
};
Session?.Channel.SendMessage(msg);
}
}
1 change: 1 addition & 0 deletions OpenDreamRuntime/DreamManager.Connections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private void InitializeConnectionManager() {
_netManager.RegisterNetMessage<MsgSound>();
_netManager.RegisterNetMessage<MsgUpdateClientInfo>();
_netManager.RegisterNetMessage<MsgAllAppearances>();
_netManager.RegisterNetMessage<MsgNotifyMobEyeUpdate>();

var topicPort = _config.GetCVar(OpenDreamCVars.TopicPort);
var worldTopicAddress = new IPEndPoint(IPAddress.Loopback, topicPort);
Expand Down
24 changes: 24 additions & 0 deletions OpenDreamShared/Network/Messages/MsgNotifyMobEyeUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Lidgren.Network;
using Robust.Shared.GameObjects;
using Robust.Shared.Network;
using Robust.Shared.Serialization;

namespace OpenDreamShared.Network.Messages;

//Server -> Client: Tell the client about the current entity UIDs of its mob and eye
public sealed class MsgNotifyMobEyeUpdate : NetMessage {
public override MsgGroups MsgGroup => MsgGroups.EntityEvent;

public NetEntity MobNetEntity;
public NetEntity EyeNetEntity;

public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) {
MobNetEntity = new(buffer.ReadInt32());
EyeNetEntity = new(buffer.ReadInt32());
}

public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer) {
buffer.Write(MobNetEntity.Id);
buffer.Write(EyeNetEntity.Id);
}
}
Loading