diff --git a/Content.Client/Paper/UI/PaperWindow.xaml.cs b/Content.Client/Paper/UI/PaperWindow.xaml.cs index e270cebc35a..5e070f94dcf 100644 --- a/Content.Client/Paper/UI/PaperWindow.xaml.cs +++ b/Content.Client/Paper/UI/PaperWindow.xaml.cs @@ -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); - Input.TextRope = Rope.Leaf.Empty; - Input.CursorPosition = new TextEdit.CursorPos(); - Input.InsertAtCursor(msg.ToString()); + 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++) { diff --git a/Content.Server/Paper/PaperSystem.cs b/Content.Server/Paper/PaperSystem.cs index eb764f57826..034d6a2643e 100644 --- a/Content.Server/Paper/PaperSystem.cs +++ b/Content.Server/Paper/PaperSystem.cs @@ -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(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); } }