Skip to content

Commit

Permalink
Add per player mutes
Browse files Browse the repository at this point in the history
  • Loading branch information
PunkPun committed Aug 6, 2022
1 parent b7b169a commit 93c5102
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 16 deletions.
3 changes: 3 additions & 0 deletions OpenRA.Game/TextNotificationsManager.cs
Expand Up @@ -21,6 +21,8 @@ public static class TextNotificationsManager
static readonly string SystemMessageLabel;

public static long ChatDisabledUntil { get; internal set; }
public static readonly Dictionary<int, bool> MutedPlayers = new Dictionary<int, bool>();

static readonly List<TextNotification> NotificationsCache = new List<TextNotification>();
public static IReadOnlyList<TextNotification> Notifications => NotificationsCache;

Expand Down Expand Up @@ -94,6 +96,7 @@ static bool IsPoolEnabled(TextNotificationPool pool)
public static void Clear()
{
NotificationsCache.Clear();
MutedPlayers.Clear();
}
}
}
17 changes: 16 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs
Expand Up @@ -27,6 +27,7 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager,
{
var player = world.LocalPlayer;
var playerPanel = widget.Get<ScrollPanelWidget>("PLAYER_LIST");
var statsHeader = widget.Get("STATS_HEADERS");

if (player != null && !player.NonCombatant)
{
Expand All @@ -51,14 +52,16 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager,
{
// Expand the stats window to cover the hidden objectives
var objectiveGroup = widget.Get("OBJECTIVE");
var statsHeader = widget.Get("STATS_HEADERS");

objectiveGroup.Visible = false;
statsHeader.Bounds.Y -= objectiveGroup.Bounds.Height;
playerPanel.Bounds.Y -= objectiveGroup.Bounds.Height;
playerPanel.Bounds.Height += objectiveGroup.Bounds.Height;
}

if (!orderManager.LobbyInfo.Clients.Any(c => !c.IsBot && c.Index != orderManager.LocalClient.Index && c.State != Session.ClientState.Disconnected))
statsHeader.Get<LabelWidget>("CHAT").Visible = false;

var teamTemplate = playerPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE");
var spectatorTemplate = playerPanel.Get("SPECTATOR_TEMPLATE");
Expand Down Expand Up @@ -112,6 +115,12 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager,
var scoreCache = new CachedTransform<int, string>(s => s.ToString());
item.Get<LabelWidget>("SCORE").GetText = () => scoreCache.Update(p.PlayerStatistics?.Experience ?? 0);

var muteCheckbox = item.Get<CheckboxWidget>("MUTE");
muteCheckbox.IsChecked = () => TextNotificationsManager.MutedPlayers[pp.ClientIndex];
muteCheckbox.OnClick = () => TextNotificationsManager.MutedPlayers[pp.ClientIndex] ^= true;
muteCheckbox.IsVisible = () => !pp.IsBot && client.State != Session.ClientState.Disconnected && pp.ClientIndex != orderManager.LocalClient.Index;
muteCheckbox.GetTooltipText = () => muteCheckbox.IsChecked() ? "Unmute this player" : "Mute this player";

playerPanel.AddChild(item);
}
}
Expand Down Expand Up @@ -159,6 +168,12 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager,
confirmText: "Kick");
};

var muteCheckbox = item.Get<CheckboxWidget>("MUTE");
muteCheckbox.IsChecked = () => TextNotificationsManager.MutedPlayers[client.Index];
muteCheckbox.OnClick = () => TextNotificationsManager.MutedPlayers[client.Index] ^= true;
muteCheckbox.IsVisible = () => !client.IsBot && client.State != Session.ClientState.Disconnected && client.Index != orderManager.LocalClient.Index;
muteCheckbox.GetTooltipText = () => muteCheckbox.IsChecked() ? "Unmute this player" : "Mute this player";

playerPanel.AddChild(item);
}
}
Expand Down
6 changes: 6 additions & 0 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs
Expand Up @@ -57,6 +57,9 @@ public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Mo
var disableTeamChat = alwaysDisabled || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer)));
var teamChat = !disableTeamChat;

if (TextNotificationsManager.MutedPlayers.Count == 0)
orderManager.LobbyInfo.Clients.Do((c) => TextNotificationsManager.MutedPlayers.Add(c.Index, false));

tabCompletion.Commands = chatTraits.OfType<ChatCommands>().ToArray().SelectMany(x => x.Commands.Keys);
tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList();

Expand Down Expand Up @@ -261,6 +264,9 @@ void INotificationHandler<TextNotification>.Handle(TextNotification notification
if (!IsNotificationEligible(notification))
return;

if (notification.ClientId != TextNotificationsManager.SystemClientId && TextNotificationsManager.MutedPlayers[notification.ClientId])
return;

if (!IsNotificationMuted(notification))
chatOverlayDisplay?.AddNotification(notification);

Expand Down
9 changes: 9 additions & 0 deletions mods/cnc/chrome.yaml
Expand Up @@ -418,6 +418,15 @@ checkmark-cross:
checkmark-highlighted-cross:
Inherits: checkmark-cross

checkmark-mute:
Inherits: ^Chrome
Regions:
unchecked: 768, 209, 16, 13
checked: 785, 209, 16, 13

checkmark-highlighted-mute:
Inherits: checkmark-mute

flags:
Inherits: ^Chrome
Regions:
Expand Down
33 changes: 28 additions & 5 deletions mods/cnc/chrome/ingame-infostats.yaml
Expand Up @@ -50,11 +50,17 @@ Container@SKIRMISH_STATS:
Label@SCORE:
X: 360
Y: 1
Width: 75
Width: 58
Height: 25
Text: Score
Font: Bold
Align: Right
Label@CHAT:
X: 418
Y: 1
Width: 20
Height: 25
Text: Chat
Font: Bold
ScrollPanel@PLAYER_LIST:
X: 15
Y: 105
Expand Down Expand Up @@ -116,10 +122,18 @@ Container@SKIRMISH_STATS:
Shadow: True
Label@SCORE:
X: 360
Width: 75
Width: 58
Height: 25
Shadow: True
Checkbox@MUTE:
X: 418
Width: 20
Height: 25
Align: Right
Shadow: True
Checkmark: mute
Background:
TooltipContainer: TOOLTIP_CONTAINER
Align: Right
Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27
Height: 25
Expand All @@ -144,7 +158,7 @@ Container@SKIRMISH_STATS:
Height: 25
Shadow: True
Button@KICK:
X: 195
X: 264
Width: 24
Height: 25
Children:
Expand All @@ -153,3 +167,12 @@ Container@SKIRMISH_STATS:
ImageName: kick
X: 6
Y: 8
Checkbox@MUTE:
X: 418
Width: 20
Height: 25
Shadow: True
Checkmark: mute
Background:
TooltipContainer: TOOLTIP_CONTAINER
Align: Right
32 changes: 27 additions & 5 deletions mods/common/chrome/ingame-infostats.yaml
Expand Up @@ -47,11 +47,16 @@ Container@SKIRMISH_STATS:
Font: Bold
Label@SCORE:
X: 360
Width: 75
Width: 58
Height: 25
Text: Score
Font: Bold
Align: Right
Label@CHAT:
X: 418
Width: 20
Height: 25
Text: Chat
Font: Bold
ScrollPanel@PLAYER_LIST:
X: 20
Y: 105
Expand Down Expand Up @@ -114,10 +119,18 @@ Container@SKIRMISH_STATS:
Shadow: True
Label@SCORE:
X: 360
Width: 75
Width: 58
Height: 25
Align: Right
Shadow: True
Checkbox@MUTE:
X: 418
Width: 20
Height: 25
Shadow: True
Checkmark: mute
Background:
TooltipContainer: TOOLTIP_CONTAINER
Align: Right
Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27
Height: 25
Expand All @@ -142,7 +155,7 @@ Container@SKIRMISH_STATS:
Height: 25
Shadow: True
Button@KICK:
X: 195
X: 264
Width: 24
Height: 25
Children:
Expand All @@ -151,3 +164,12 @@ Container@SKIRMISH_STATS:
ImageName: kick
X: 6
Y: 8
Checkbox@MUTE:
X: 418
Width: 20
Height: 25
Shadow: True
Checkmark: mute
Background:
TooltipContainer: TOOLTIP_CONTAINER
Align: Right
9 changes: 9 additions & 0 deletions mods/d2k/chrome.yaml
Expand Up @@ -395,6 +395,15 @@ checkmark-cross:
checkmark-highlighted-cross:
Inherits: checkmark-cross

checkmark-mute:
Inherits: ^Glyphs
Regions:
unchecked: 0, 144, 16, 13
checked: 17, 144, 16, 13

checkmark-highlighted-mute:
Inherits: checkmark-mute

checkbox-hover:
Inherits: ^Dialog
PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2
Expand Down
33 changes: 28 additions & 5 deletions mods/d2k/chrome/ingame-infostats.yaml
Expand Up @@ -50,11 +50,17 @@ Container@SKIRMISH_STATS:
Label@SCORE:
X: 360
Y: 1
Width: 75
Width: 58
Height: 25
Text: Score
Font: Bold
Align: Right
Label@CHAT:
X: 418
Y: 1
Width: 20
Height: 25
Text: Chat
Font: Bold
ScrollPanel@PLAYER_LIST:
X: 20
Y: 105
Expand Down Expand Up @@ -115,10 +121,18 @@ Container@SKIRMISH_STATS:
Shadow: True
Label@SCORE:
X: 360
Width: 75
Width: 58
Height: 25
Shadow: True
Checkbox@MUTE:
X: 418
Width: 20
Height: 25
Align: Right
Shadow: True
Checkmark: mute
Background:
TooltipContainer: TOOLTIP_CONTAINER
Align: Right
Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27
Height: 25
Expand All @@ -143,7 +157,7 @@ Container@SKIRMISH_STATS:
Height: 25
Shadow: True
Button@KICK:
X: 195
X: 264
Width: 24
Height: 25
Children:
Expand All @@ -152,3 +166,12 @@ Container@SKIRMISH_STATS:
ImageName: kick
X: 6
Y: 8
Checkbox@MUTE:
X: 418
Width: 20
Height: 25
Shadow: True
Checkmark: mute
Background:
TooltipContainer: TOOLTIP_CONTAINER
Align: Right
9 changes: 9 additions & 0 deletions mods/ra/chrome.yaml
Expand Up @@ -524,6 +524,15 @@ checkmark-cross:
checkmark-highlighted-cross:
Inherits: checkmark-cross

checkmark-mute:
Inherits: ^Glyphs
Regions:
unchecked: 0, 170, 16, 13
checked: 17, 170, 16, 13

checkmark-highlighted-mute:
Inherits: checkmark-mute

checkbox-hover:
Inherits: ^Dialog
PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2
Expand Down
9 changes: 9 additions & 0 deletions mods/ts/chrome.yaml
Expand Up @@ -657,6 +657,15 @@ checkmark-cross:
checkmark-highlighted-cross:
Inherits: checkmark-cross

checkmark-mute:
Inherits: ^Glyphs
Regions:
unchecked: 0, 144, 16, 13
checked: 17, 144, 16, 13

checkmark-highlighted-mute:
Inherits: checkmark-mute

checkbox-hover:
Inherits: ^Dialog
PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2
Expand Down

0 comments on commit 93c5102

Please sign in to comment.