|
| 1 | +using Content.Client.CrewAssignments.UI; |
| 2 | +using Content.Shared.IdentityManagement; |
| 3 | +using Content.Shared.MessageBoard.Components; |
| 4 | +using JetBrains.Annotations; |
| 5 | +using Robust.Client.GameObjects; |
| 6 | +using Robust.Client.Player; |
| 7 | +using Robust.Client.UserInterface.Controls; |
| 8 | +using Robust.Shared.Prototypes; |
| 9 | +using Robust.Shared.Utility; |
| 10 | +using System; |
| 11 | +using System.Collections.Generic; |
| 12 | +using System.Text; |
| 13 | +using static Robust.Client.UserInterface.Controls.MenuBar; |
| 14 | + |
| 15 | +namespace Content.Client.MessageBoard.UI; |
| 16 | + |
| 17 | +[UsedImplicitly] |
| 18 | +public sealed class MessageBoardBoundUserInterface : BoundUserInterface |
| 19 | +{ |
| 20 | + [ViewVariables] |
| 21 | + private MessageBoard? _menu; |
| 22 | + private CreateEntry? _createEntry; |
| 23 | + |
| 24 | + public MessageBoardBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) |
| 25 | + { |
| 26 | + } |
| 27 | + |
| 28 | + protected override void Open() |
| 29 | + { |
| 30 | + base.Open(); |
| 31 | + var spriteSystem = EntMan.System<SpriteSystem>(); |
| 32 | + var dependencies = IoCManager.Instance!; |
| 33 | + _menu = new MessageBoard(Owner, EntMan, dependencies.Resolve<IPrototypeManager>(), spriteSystem); |
| 34 | + var localPlayer = dependencies.Resolve<IPlayerManager>().LocalEntity; |
| 35 | + var description = new FormattedMessage(); |
| 36 | + _menu.OnClose += Close; |
| 37 | + _menu.OpenCentered(); |
| 38 | + _menu.CreateEntryPublicButton.OnPressed += CreateEntryPublic; |
| 39 | + } |
| 40 | + |
| 41 | + public void CreateEntryPublic(BaseButton.ButtonEventArgs args) |
| 42 | + { |
| 43 | + if(_createEntry != null) |
| 44 | + { |
| 45 | + _createEntry.Dispose(); |
| 46 | + } |
| 47 | + _createEntry = new CreateEntry(); |
| 48 | + _createEntry.OpenCentered(); |
| 49 | + _createEntry.CurrentEntryType = CreateEntry.EntryType.Public; |
| 50 | + _createEntry.PostButton.OnPressed += FinalizeEntryPublic; |
| 51 | + } |
| 52 | + |
| 53 | + public void FinalizeEntryPublic(BaseButton.ButtonEventArgs args) |
| 54 | + { |
| 55 | + if (_createEntry == null) |
| 56 | + return; |
| 57 | + var title = _createEntry.MainTitleLabel.Text; |
| 58 | + var content = Rope.Collapse(_createEntry.DescriptionLabel.TextRope); |
| 59 | + if(title == string.Empty || content == string.Empty) |
| 60 | + { |
| 61 | + return; |
| 62 | + } |
| 63 | + SendMessage(new MessageBoardCreateEntryPublicMessage(title, content)); |
| 64 | + _createEntry.Dispose(); |
| 65 | + _createEntry = null; |
| 66 | + } |
| 67 | + |
| 68 | + protected override void Dispose(bool disposing) |
| 69 | + { |
| 70 | + base.Dispose(disposing); |
| 71 | + |
| 72 | + if (!disposing) |
| 73 | + return; |
| 74 | + |
| 75 | + _menu?.Dispose(); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments