Skip to content

Commit 73b5b1d

Browse files
public message board mechanics
1 parent 99fd023 commit 73b5b1d

15 files changed

Lines changed: 463 additions & 59 deletions

File tree

Content.Client/Content.Client.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@
3333
<AdditionalFiles Update="GridControl\UI\StationTaggerWindow.xaml">
3434
<Generator>MSBuild:Compile</Generator>
3535
</AdditionalFiles>
36+
<AdditionalFiles Update="MessageBoard\UI\CommentHeader.xaml">
37+
<Generator>MSBuild:Compile</Generator>
38+
</AdditionalFiles>
3639
<AdditionalFiles Update="MessageBoard\UI\CreateEntry.xaml">
3740
<Generator>MSBuild:Compile</Generator>
3841
</AdditionalFiles>
42+
<AdditionalFiles Update="MessageBoard\UI\EntryHeader.xaml">
43+
<Generator>MSBuild:Compile</Generator>
44+
</AdditionalFiles>
45+
<AdditionalFiles Update="MessageBoard\UI\EntryWindow.xaml">
46+
<Generator>MSBuild:Compile</Generator>
47+
</AdditionalFiles>
3948
</ItemGroup>
4049

4150
<ItemGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<PanelContainer xmlns="https://spacestation14.io" StyleClasses="BackgroundPanel" HorizontalExpand="True" MinHeight="30" Margin="10 10 10 0">
2+
<BoxContainer HorizontalExpand="True" Orientation="Vertical">
3+
<BoxContainer Orientation="Horizontal">
4+
<Label Name="CommentLabel" Text="Looks Very Cool!" />
5+
</BoxContainer>
6+
<BoxContainer Orientation="Horizontal">
7+
<Label Access="Public" Name="AuthorLabel" Text="Posted by Chester Cheetah on 2248-05-01 14:17" />
8+
<Control HorizontalExpand="True" />
9+
<Button Text="Delete" Name="DeleteButton" Access="Public" />
10+
</BoxContainer>
11+
</BoxContainer>
12+
</PanelContainer>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Robust.Client.AutoGenerated;
2+
using Robust.Client.UserInterface.Controls;
3+
using Robust.Client.UserInterface.CustomControls;
4+
using Robust.Client.UserInterface.XAML;
5+
6+
namespace Content.Client.MessageBoard.UI;
7+
8+
[GenerateTypedNameReferences]
9+
public sealed partial class CommentHeader : PanelContainer
10+
{
11+
public CommentHeader(string content, string author, string date, bool deleteEnabled)
12+
{
13+
RobustXamlLoader.Load(this);
14+
IoCManager.InjectDependencies(this);
15+
16+
CommentLabel.Text = content;
17+
AuthorLabel.Text = $"Posted by {author} on {date}";
18+
DeleteButton.Visible = deleteEnabled;
19+
}
20+
}

Content.Client/MessageBoard/UI/CreateEntry.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<DefaultWindow xmlns="https://spacestation14.io"
22
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
33
Title="Create Entry">
4-
<BoxContainer Orientation="Vertical" MinSize="400 400">
4+
<BoxContainer Orientation="Vertical" MinSize="550 350">
55
<BoxContainer Orientation="Horizontal">
66
<Label Text ="Title:"></Label>
77
<LineEdit Name="MainTitleLabel" PlaceHolder="Title Label" Access="Public" HorizontalExpand="True"/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<PanelContainer xmlns="https://spacestation14.io" StyleClasses="BackgroundPanel" HorizontalExpand="True" MinHeight="30" Margin="10 10 10 0">
2+
<BoxContainer HorizontalExpand="True" Orientation="Vertical">
3+
<BoxContainer Orientation="Horizontal">
4+
<Label Name="TitleLabel" Text="(JOB) Looking for engineers to help with a shuttle." StyleClasses="LabelKeyText" />
5+
<Control HorizontalExpand="True" />
6+
<Button Text="View" Name="ViewButton" Access="Public" />
7+
</BoxContainer>
8+
<BoxContainer Orientation="Horizontal">
9+
<Label Access="Public" Name="AuthorLabel" Text="Posted by Chester Cheetah" />
10+
<Control HorizontalExpand="True" />
11+
<Button Text="Delete" Name="DeleteButton" Access="Public" />
12+
</BoxContainer>
13+
<BoxContainer Orientation="Horizontal">
14+
<Label Access="Public" Name="DateLabel" Text="14:17 2246-05-01" />
15+
<Control HorizontalExpand="True" />
16+
<Label Access="Public" Name="CommentsLabel" Text="0 Comments" />
17+
</BoxContainer>
18+
</BoxContainer>
19+
</PanelContainer>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Robust.Client.AutoGenerated;
2+
using Robust.Client.UserInterface.Controls;
3+
using Robust.Client.UserInterface.CustomControls;
4+
using Robust.Client.UserInterface.XAML;
5+
6+
namespace Content.Client.MessageBoard.UI;
7+
8+
[GenerateTypedNameReferences]
9+
public sealed partial class EntryHeader : PanelContainer
10+
{
11+
public EntryHeader(string title, string author, string date, int commentCount, bool deleteEnabled)
12+
{
13+
RobustXamlLoader.Load(this);
14+
IoCManager.InjectDependencies(this);
15+
16+
TitleLabel.Text = title;
17+
AuthorLabel.Text = $"Posted by {author}";
18+
DateLabel.Text = date;
19+
CommentsLabel.Text = $"{commentCount} Comments";
20+
DeleteButton.Visible = deleteEnabled;
21+
}
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<DefaultWindow xmlns="https://spacestation14.io"
2+
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
3+
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
4+
Title="Entry Title">
5+
<BoxContainer Orientation="Vertical" MinSize="550 550">
6+
<BoxContainer Orientation="Vertical">
7+
<Label Text ="Title:" Name="MainTitleLabel"></Label>
8+
<Label Name="AuthorLabel"></Label>
9+
</BoxContainer>
10+
<customControls:HSeparator Margin="5 10 5 10"/>
11+
<PanelContainer StyleIdentifier="PaperEditBackground" MinHeight="300" HorizontalExpand="True">
12+
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">
13+
<BoxContainer HorizontalExpand="True" VerticalExpand="True" Orientation="Vertical" Margin="5 10 5 10">
14+
<RichTextLabel Name="MainContentLabel" Access="Public" HorizontalExpand="True" VerticalExpand="True" VerticalAlignment="Top"/>
15+
</BoxContainer>
16+
</ScrollContainer>
17+
</PanelContainer>
18+
<PanelContainer VerticalExpand="True" HorizontalExpand="True" Name="PublicBoardEntriesPC">
19+
<PanelContainer.PanelOverride>
20+
<gfx:StyleBoxFlat BackgroundColor="#000000" />
21+
</PanelContainer.PanelOverride>
22+
<ScrollContainer HorizontalExpand="True" VerticalExpand="True" HScrollEnabled="False">
23+
<BoxContainer HorizontalExpand="True" VerticalExpand="True" Orientation="Vertical" Margin="5 10 5 10">
24+
<PanelContainer StyleClasses="BackgroundPanel" HorizontalExpand="True" MinHeight="30" Margin="10 10 10 0">
25+
<BoxContainer HorizontalExpand="True" VerticalExpand="True" Orientation="Vertical">
26+
<LineEdit Name="AddCommentLE" HorizontalExpand="True" PlaceHolder="Add a comment" Access="Public"/>
27+
<Button Name="AddCommentBtn" Text="Add Comment" Access="Public"/>
28+
</BoxContainer>
29+
</PanelContainer>
30+
<BoxContainer Orientation="Vertical" Name="CommentBC"></BoxContainer>
31+
</BoxContainer>
32+
</ScrollContainer>
33+
</PanelContainer>
34+
35+
</BoxContainer>
36+
</DefaultWindow>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

Content.Client/MessageBoard/UI/MessageBoard.xaml

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<TabContainer>
99
<BoxContainer Orientation="Vertical" Name="PublicBoard">
1010
<Button Text="Create A New Entry" Name="CreateEntryPublicButton" Access="Public" />
11-
<BoxContainer Orientation="Vertical" Name="PublicBoardEntries" />
1211
<PanelContainer VerticalExpand="True"
1312
HorizontalExpand="True"
1413
SizeFlagsStretchRatio="1"
@@ -20,43 +19,19 @@
2019
<BoxContainer Orientation="Vertical" Margin="5" MinHeight ="10">
2120
<BoxContainer Name="PublicBoardEntriesBC"
2221
Orientation="Vertical"
23-
VerticalExpand="True">
24-
25-
<PanelContainer StyleClasses="BackgroundPanel" HorizontalExpand="True" MinHeight="30" Margin="10 10 10 0">
26-
<BoxContainer
27-
HorizontalExpand="True"
28-
Orientation="Vertical">
29-
<BoxContainer Orientation="Horizontal">
30-
<Label Text="(JOB) Looking for engineers to help with a shuttle." StyleClasses="LabelKeyText" />
31-
<Control HorizontalExpand="True" />
32-
<Button Text="View" />
33-
</BoxContainer>
34-
<Label Access="Public" Name="RewardLabel" Text="Posted by Chester Cheetah" />
35-
<BoxContainer Orientation="Horizontal">
36-
<Label Access="Public" Text="14:17 2246-05-01" />
37-
<Control HorizontalExpand="True" />
38-
<Label Access="Public" Text="0 Comments" />
39-
</BoxContainer>
40-
41-
</BoxContainer>
42-
</PanelContainer>
43-
<PanelContainer StyleClasses="BackgroundPanel" HorizontalExpand="True" MinHeight="30" Margin="10 10 10 0">
44-
<BoxContainer
45-
HorizontalExpand="True"
46-
Orientation="Vertical">
47-
<Label Access="Public" Name="ObjectiveLabel2" Text="Get high from space mirage." />
48-
<Label Access="Public" Name="RewardLabel2" Text="Reward: 100 Precursor" />
49-
<Label Access="Public" Name="SectorChaosLabel2" Text="Sector chaos will slightly increase" />
50-
</BoxContainer>
51-
</PanelContainer>
22+
VerticalExpand="True"
23+
Access="Public">
5224
</BoxContainer>
5325
</BoxContainer>
5426
</ScrollContainer>
5527
</PanelContainer>
5628
</BoxContainer>
5729
<BoxContainer Orientation="Vertical" Name="DirectMessages">
58-
59-
30+
<Label Text="Send Message: " StyleClasses="LabelKeyText"/>
31+
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
32+
<LineEdit Name="SendMessageLE" PlaceHolder="Recipient Name" HorizontalExpand="True"/>
33+
<Button Text="Compose Message" Name="SendMessageButton" Access="Public" />
34+
</BoxContainer>
6035
</BoxContainer>
6136
</TabContainer>
6237
</ScrollContainer>

Content.Client/MessageBoard/UI/MessageBoardBoundUserInterface.cs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
using Content.Client.Administration.Managers;
12
using Content.Client.CrewAssignments.UI;
3+
using Content.Shared.Cargo.BUI;
4+
using Content.Shared.CCVar;
25
using Content.Shared.IdentityManagement;
36
using Content.Shared.MessageBoard.Components;
47
using JetBrains.Annotations;
58
using Robust.Client.GameObjects;
69
using Robust.Client.Player;
710
using Robust.Client.UserInterface.Controls;
11+
using Robust.Shared.Configuration;
12+
using Robust.Shared.Player;
813
using Robust.Shared.Prototypes;
914
using Robust.Shared.Utility;
1015
using System;
@@ -17,14 +22,67 @@ namespace Content.Client.MessageBoard.UI;
1722
[UsedImplicitly]
1823
public sealed class MessageBoardBoundUserInterface : BoundUserInterface
1924
{
20-
[ViewVariables]
25+
[Dependency] private readonly IClientAdminManager _admin = default!;
26+
[Dependency] private readonly IConfigurationManager _cfg = default!;
2127
private MessageBoard? _menu;
2228
private CreateEntry? _createEntry;
29+
private EntryWindow? _entryWindow;
2330

2431
public MessageBoardBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
2532
{
2633
}
2734

35+
protected override void UpdateState(BoundUserInterfaceState state)
36+
{
37+
bool isAdmin = _admin.IsActive();
38+
var player = PlayerManager.LocalEntity;
39+
if (player == null) return;
40+
var playerName = Identity.Name(player.Value, EntMan);
41+
base.UpdateState(state);
42+
if(_menu == null)
43+
{
44+
return;
45+
}
46+
if (state is not MessageBoardInterfaceState cState)
47+
return;
48+
_menu.PublicBoardEntriesBC.DisposeAllChildren();
49+
cState.PublicEntries.Reverse();
50+
foreach (var entry in cState.PublicEntries)
51+
{
52+
bool delete = false;
53+
if (isAdmin || playerName == entry.Author) delete = true;
54+
var adjustedTime = entry.CreationTime.AddYears(_cfg.GetCVar(CCVars.YearOffset));
55+
EntryHeader header = new EntryHeader(entry.Title, entry.Author, $"{adjustedTime.ToString()}", entry.Comments.Count, delete);
56+
_menu.PublicBoardEntriesBC.AddChild(header);
57+
header.DeleteButton.OnPressed += (args) =>
58+
{
59+
SendMessage(new MessageBoardDeleteEntryPublicMessage(entry.UID));
60+
};
61+
header.ViewButton.OnPressed += (args) =>
62+
{
63+
if(_entryWindow != null)
64+
{
65+
_entryWindow.Dispose();
66+
}
67+
var entryWindow = new EntryWindow(entry, isAdmin, playerName, this);
68+
_entryWindow = entryWindow;
69+
entryWindow.OpenCentered();
70+
entryWindow.AddCommentBtn.OnPressed += (commentArgs) =>
71+
{
72+
var comment = entryWindow.AddCommentLE.Text;
73+
if (comment == string.Empty) return;
74+
var ID = entryWindow.Entry.UID;
75+
entryWindow.AddCommentLE.Text = string.Empty;
76+
SendMessage(new MessageBoardPostCommentPublicMessage(ID, comment));
77+
};
78+
};
79+
if (_entryWindow != null && _entryWindow.Entry.UID == entry.UID)
80+
{
81+
_entryWindow.UpdateEntry(entry);
82+
}
83+
}
84+
}
85+
2886
protected override void Open()
2987
{
3088
base.Open();

0 commit comments

Comments
 (0)