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 Jul 4, 2022
1 parent 85081eb commit e74b528
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 11 deletions.
2 changes: 2 additions & 0 deletions OpenRA.Game/Network/OrderManager.cs
Expand Up @@ -55,6 +55,8 @@ public sealed class OrderManager : IDisposable

public IReadOnlyList<TextNotification> NotificationsCache => notificationsCache;

public readonly Dictionary<int, bool> MutedPlayerLib = new Dictionary<int, bool>();

bool disposed;
bool generateSyncReport = false;
int sentOrdersFrame = 0;
Expand Down
16 changes: 14 additions & 2 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs
Expand Up @@ -27,12 +27,12 @@ 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)
{
var checkbox = widget.Get<CheckboxWidget>("STATS_CHECKBOX");
var statusLabel = widget.Get<LabelWidget>("STATS_STATUS");

checkbox.IsChecked = () => player.WinState != WinState.Undefined;
checkbox.GetCheckmarkType = () => player.WinState == WinState.Won ? "tick" : "cross";

Expand All @@ -51,14 +51,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 +114,11 @@ 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 = () => orderManager.MutedPlayerLib[pp.ClientIndex];
muteCheckbox.OnClick = () => orderManager.MutedPlayerLib[pp.ClientIndex] ^= true;
muteCheckbox.IsDisabled = () => pp.IsBot || client.State == Session.ClientState.Disconnected || pp.ClientIndex == orderManager.LocalClient.Index;

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

var muteCheckbox = item.Get<CheckboxWidget>("MUTE");
muteCheckbox.IsChecked = () => orderManager.MutedPlayerLib[client.Index];
muteCheckbox.OnClick = () => orderManager.MutedPlayerLib[client.Index] ^= true;
muteCheckbox.IsDisabled = () => client.IsBot || client.State == Session.ClientState.Disconnected || client.Index == orderManager.LocalClient.Index;

playerPanel.AddChild(item);
}
}
Expand Down
6 changes: 6 additions & 0 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs
Expand Up @@ -59,6 +59,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 (orderManager.MutedPlayerLib.Count == 0)
orderManager.LobbyInfo.Clients.Do((c) => orderManager.MutedPlayerLib.Add(c.Index, false));

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

Expand Down Expand Up @@ -265,6 +268,9 @@ public void AddNotificationWrapper(TextNotification notification)
if (!IsNotificationEligible(notification))
return;

if (notification.ClientId != TextNotificationsManager.ClientIdSystem && orderManager.MutedPlayerLib[notification.ClientId])
return;

if (!Game.Settings.Game.HideReplayChat || !world.IsReplay || notification.ClientId == TextNotificationsManager.ClientIdSystem)
chatOverlayDisplay?.AddNotification(notification);

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

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

checkmark-highlighted-mute:
Inherits: checkmark-mute

flags:
Inherits: ^Chrome
Regions:
Expand Down
31 changes: 28 additions & 3 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: 55
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,19 @@ Container@SKIRMISH_STATS:
Shadow: True
Label@SCORE:
X: 360
Width: 75
Width: 55
Height: 25
Shadow: True
Checkbox@MUTE:
X: 418
Y: 9
Width: 20
Height: 25
Align: Right
Shadow: True
CheckOffset: 0, 0
CheckmarkType: mute
HasBackground: false
Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27
Height: 25
Expand Down Expand Up @@ -153,3 +168,13 @@ Container@SKIRMISH_STATS:
ImageName: kick
X: 6
Y: 8
Checkbox@MUTE:
X: 418
Y: 9
Width: 20
Height: 25
Align: Right
Shadow: True
CheckOffset: 0, 0
CheckmarkType: mute
HasBackground: false
30 changes: 27 additions & 3 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: 55
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,19 @@ Container@SKIRMISH_STATS:
Shadow: True
Label@SCORE:
X: 360
Width: 75
Width: 45
Height: 25
Shadow: True
Checkbox@MUTE:
X: 418
Y: 9
Width: 20
Height: 25
Align: Right
Shadow: True
CheckOffset: 0, 0
CheckmarkType: mute
HasBackground: false
Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27
Height: 25
Expand Down Expand Up @@ -151,3 +165,13 @@ Container@SKIRMISH_STATS:
ImageName: kick
X: 6
Y: 8
Checkbox@MUTE:
X: 418
Y: 9
Width: 20
Height: 25
Align: Right
Shadow: True
CheckOffset: 0, 0
CheckmarkType: mute
HasBackground: false
11 changes: 11 additions & 0 deletions mods/d2k/chrome.yaml
Expand Up @@ -395,6 +395,17 @@ checkmark-cross:
checkmark-highlighted-cross:
Inherits: checkmark-cross

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

checkmark-highlighted-mute:
Inherits: checkmark-mute

checkbox-hover:
Inherits: ^Dialog
PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2
Expand Down
31 changes: 28 additions & 3 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: 55
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,19 @@ Container@SKIRMISH_STATS:
Shadow: True
Label@SCORE:
X: 360
Width: 75
Width: 55
Height: 25
Shadow: True
Checkbox@MUTE:
X: 418
Y: 9
Width: 20
Height: 25
Align: Right
Shadow: True
CheckOffset: 0, 0
CheckmarkType: mute
HasBackground: false
Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27
Height: 25
Expand Down Expand Up @@ -152,3 +167,13 @@ Container@SKIRMISH_STATS:
ImageName: kick
X: 6
Y: 8
Checkbox@MUTE:
X: 418
Y: 9
Width: 20
Height: 25
Align: Right
Shadow: True
CheckOffset: 0, 0
CheckmarkType: mute
HasBackground: false
11 changes: 11 additions & 0 deletions mods/ra/chrome.yaml
Expand Up @@ -524,6 +524,17 @@ checkmark-cross:
checkmark-highlighted-cross:
Inherits: checkmark-cross

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

checkmark-highlighted-mute:
Inherits: checkmark-mute

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

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

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 e74b528

Please sign in to comment.