Fix bugs when updating paper UI (#17786)
This commit is contained in:
@@ -178,14 +178,22 @@ namespace Content.Client.Paper.UI
|
||||
public void Populate(SharedPaperComponent.PaperBoundUserInterfaceState state)
|
||||
{
|
||||
bool isEditing = state.Mode == SharedPaperComponent.PaperAction.Write;
|
||||
bool wasEditing = InputContainer.Visible;
|
||||
InputContainer.Visible = isEditing;
|
||||
|
||||
var msg = new FormattedMessage();
|
||||
msg.AddMarkupPermissive(state.Text);
|
||||
|
||||
if (!wasEditing)
|
||||
{
|
||||
// We can get repeated messages with state.Mode == Write if another
|
||||
// player opens the UI for reading. In this case, don't update the
|
||||
// text input, as this player is currently writing new text and we
|
||||
// don't want to lose any text they already input.
|
||||
Input.TextRope = Rope.Leaf.Empty;
|
||||
Input.CursorPosition = new TextEdit.CursorPos();
|
||||
Input.InsertAtCursor(msg.ToString());
|
||||
}
|
||||
|
||||
for (var i = 0; i <= state.StampedBy.Count * 3 + 1; i++)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Paper;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Utility;
|
||||
using static Content.Shared.Paper.SharedPaperComponent;
|
||||
@@ -65,7 +66,11 @@ namespace Content.Server.Paper
|
||||
private void BeforeUIOpen(EntityUid uid, PaperComponent paperComp, BeforeActivatableUIOpenEvent args)
|
||||
{
|
||||
paperComp.Mode = PaperAction.Read;
|
||||
UpdateUserInterface(uid, paperComp);
|
||||
|
||||
if (!TryComp<ActorComponent>(args.User, out var actor))
|
||||
return;
|
||||
|
||||
UpdateUserInterface(uid, paperComp, actor.PlayerSession);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, PaperComponent paperComp, ExaminedEvent args)
|
||||
@@ -100,8 +105,8 @@ namespace Content.Server.Paper
|
||||
return;
|
||||
|
||||
paperComp.Mode = PaperAction.Write;
|
||||
UpdateUserInterface(uid, paperComp);
|
||||
_uiSystem.GetUiOrNull(uid, PaperUiKey.Key)?.Open(actor.PlayerSession);
|
||||
_uiSystem.TryOpen(uid, PaperUiKey.Key, actor.PlayerSession);
|
||||
UpdateUserInterface(uid, paperComp, actor.PlayerSession);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -185,12 +190,13 @@ namespace Content.Server.Paper
|
||||
_appearance.SetData(uid, PaperVisuals.Status, status, appearance);
|
||||
}
|
||||
|
||||
public void UpdateUserInterface(EntityUid uid, PaperComponent? paperComp = null)
|
||||
public void UpdateUserInterface(EntityUid uid, PaperComponent? paperComp = null, IPlayerSession? session = null)
|
||||
{
|
||||
if (!Resolve(uid, ref paperComp))
|
||||
return;
|
||||
|
||||
_uiSystem.GetUiOrNull(uid, PaperUiKey.Key)?.SetState(new PaperBoundUserInterfaceState(paperComp.Content, paperComp.StampedBy, paperComp.Mode));
|
||||
var state = new PaperBoundUserInterfaceState(paperComp.Content, paperComp.StampedBy, paperComp.Mode);
|
||||
_uiSystem.TrySetUiState(uid, PaperUiKey.Key, state, session);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user