Fix bugs when updating paper UI (#17786)

This commit is contained in:
eoineoineoin
2023-07-02 13:43:27 +01:00
committed by GitHub
parent b33e93054a
commit 9194c548f8
2 changed files with 22 additions and 8 deletions

View File

@@ -178,14 +178,22 @@ namespace Content.Client.Paper.UI
public void Populate(SharedPaperComponent.PaperBoundUserInterfaceState state) public void Populate(SharedPaperComponent.PaperBoundUserInterfaceState state)
{ {
bool isEditing = state.Mode == SharedPaperComponent.PaperAction.Write; bool isEditing = state.Mode == SharedPaperComponent.PaperAction.Write;
bool wasEditing = InputContainer.Visible;
InputContainer.Visible = isEditing; InputContainer.Visible = isEditing;
var msg = new FormattedMessage(); var msg = new FormattedMessage();
msg.AddMarkupPermissive(state.Text); msg.AddMarkupPermissive(state.Text);
Input.TextRope = Rope.Leaf.Empty; if (!wasEditing)
Input.CursorPosition = new TextEdit.CursorPos(); {
Input.InsertAtCursor(msg.ToString()); // 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++) for (var i = 0; i <= state.StampedBy.Count * 3 + 1; i++)
{ {

View File

@@ -8,6 +8,7 @@ using Content.Shared.Interaction;
using Content.Shared.Paper; using Content.Shared.Paper;
using Content.Shared.Tag; using Content.Shared.Tag;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using static Content.Shared.Paper.SharedPaperComponent; using static Content.Shared.Paper.SharedPaperComponent;
@@ -65,7 +66,11 @@ namespace Content.Server.Paper
private void BeforeUIOpen(EntityUid uid, PaperComponent paperComp, BeforeActivatableUIOpenEvent args) private void BeforeUIOpen(EntityUid uid, PaperComponent paperComp, BeforeActivatableUIOpenEvent args)
{ {
paperComp.Mode = PaperAction.Read; 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) private void OnExamined(EntityUid uid, PaperComponent paperComp, ExaminedEvent args)
@@ -100,8 +105,8 @@ namespace Content.Server.Paper
return; return;
paperComp.Mode = PaperAction.Write; paperComp.Mode = PaperAction.Write;
UpdateUserInterface(uid, paperComp); _uiSystem.TryOpen(uid, PaperUiKey.Key, actor.PlayerSession);
_uiSystem.GetUiOrNull(uid, PaperUiKey.Key)?.Open(actor.PlayerSession); UpdateUserInterface(uid, paperComp, actor.PlayerSession);
return; return;
} }
@@ -185,12 +190,13 @@ namespace Content.Server.Paper
_appearance.SetData(uid, PaperVisuals.Status, status, appearance); _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)) if (!Resolve(uid, ref paperComp))
return; 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);
} }
} }