|
| 1 | +using Content.Client.Message; |
| 2 | +using Content.Shared.CCVar; |
| 3 | +using Content.Shared.MessageBoard.Components; |
| 4 | +using Robust.Client.AutoGenerated; |
| 5 | +using Robust.Client.UserInterface.Controls; |
| 6 | +using Robust.Client.UserInterface.CustomControls; |
| 7 | +using Robust.Client.UserInterface.XAML; |
| 8 | +using Robust.Shared.Configuration; |
| 9 | + |
| 10 | + |
| 11 | +namespace Content.Client.MessageBoard.UI; |
| 12 | + |
| 13 | +[GenerateTypedNameReferences] |
| 14 | +public sealed partial class EntryWindow : DefaultWindow |
| 15 | +{ |
| 16 | + [Dependency] private readonly IConfigurationManager _cfg = default!; |
| 17 | + |
| 18 | + public MessageBoardEntry Entry; |
| 19 | + private bool _isAdmin; |
| 20 | + private string _playerName; |
| 21 | + private MessageBoardBoundUserInterface _owner; |
| 22 | + |
| 23 | + public EntryWindow(MessageBoardEntry entry, bool isAdmin, string playerName, MessageBoardBoundUserInterface owner) |
| 24 | + { |
| 25 | + _owner = owner; |
| 26 | + RobustXamlLoader.Load(this); |
| 27 | + IoCManager.InjectDependencies(this); |
| 28 | + Entry = entry; |
| 29 | + this.Title = entry.Title; |
| 30 | + _isAdmin = isAdmin; |
| 31 | + _playerName = playerName; |
| 32 | + MainTitleLabel.Text = entry.Title; |
| 33 | + var adjustedMainTime = entry.CreationTime.AddYears(_cfg.GetCVar(CCVars.YearOffset)); |
| 34 | + AuthorLabel.Text = $"Posted by {entry.Author} on {adjustedMainTime.ToString()}"; |
| 35 | + MainContentLabel.SetMarkup(entry.Body); |
| 36 | + entry.Comments.Reverse(); |
| 37 | + foreach (var comment in entry.Comments) |
| 38 | + { |
| 39 | + var adjustedTime = comment.CreationTime.AddYears(_cfg.GetCVar(CCVars.YearOffset)); |
| 40 | + bool delete = false; |
| 41 | + if (_isAdmin || _playerName == comment.Author) delete = true; |
| 42 | + var item = new CommentHeader(comment.Body, comment.Author, $"{adjustedTime.ToString()}", delete); |
| 43 | + CommentBC.AddChild(item); |
| 44 | + item.DeleteButton.OnPressed += (args) => |
| 45 | + { |
| 46 | + var ID = comment.UID; |
| 47 | + _owner.SendMessage(new MessageBoardDeleteCommentPublicMessage(ID, Entry.UID)); |
| 48 | + }; |
| 49 | + } |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + public void UpdateEntry(MessageBoardEntry entry) |
| 54 | + { |
| 55 | + Entry = entry; |
| 56 | + this.Title = entry.Title; |
| 57 | + MainTitleLabel.Text = entry.Title; |
| 58 | + var adjustedMainTime = entry.CreationTime.AddYears(_cfg.GetCVar(CCVars.YearOffset)); |
| 59 | + AuthorLabel.Text = $"Posted by {entry.Author} on {adjustedMainTime.ToString()}"; |
| 60 | + MainContentLabel.SetMarkup(entry.Body); |
| 61 | + CommentBC.RemoveAllChildren(); |
| 62 | + entry.Comments.Reverse(); |
| 63 | + foreach (var comment in entry.Comments) |
| 64 | + { |
| 65 | + var adjustedTime = comment.CreationTime.AddYears(_cfg.GetCVar(CCVars.YearOffset)); |
| 66 | + bool delete = false; |
| 67 | + if (_isAdmin || _playerName == comment.Author) delete = true; |
| 68 | + CommentBC.AddChild(new CommentHeader(comment.Body, comment.Author, $"{adjustedTime.ToString()}", delete)); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments