Skip to content

Commit 24efdf1

Browse files
authored
1 parent c44b05b commit 24efdf1

File tree

7 files changed

+209
-89
lines changed

7 files changed

+209
-89
lines changed

Intersect.Client.Core/Interface/Interface.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Intersect.Client.Interface;
1616

1717
public static partial class Interface
1818
{
19-
private static FPSPanel? _fpsPanel;
19+
private static StatisticsPanel? _statisticsPanel;
2020
private static readonly ConcurrentQueue<Alert> PendingErrorMessages = new();
2121

2222
private static bool _initialized;
@@ -80,22 +80,41 @@ public static MenuGuiBase MenuUi
8080
public static MutableInterface CurrentInterface => NullableCurrentInterface ??
8181
throw new InvalidOperationException("No current UI initialized");
8282

83-
private static bool _showFPSPanel;
83+
private static bool _showStatisticsPanelFPS;
84+
private static bool _showStatisticsPanelPing;
8485

85-
public static bool ShowFPSPanel
86+
public static bool ShowStatisticsPanelFPS
8687
{
87-
get => _showFPSPanel;
88+
get => _showStatisticsPanelFPS;
8889
set
8990
{
90-
if (_showFPSPanel == value)
91+
if (_showStatisticsPanelFPS == value)
9192
{
9293
return;
9394
}
9495

95-
_showFPSPanel = value;
96-
if (_fpsPanel is { } fpsPanel)
96+
_showStatisticsPanelFPS = value;
97+
if (_statisticsPanel is { } panel)
9798
{
98-
fpsPanel.IsVisibleInParent = _showFPSPanel;
99+
panel.IsFPSEnabled = value;
100+
}
101+
}
102+
}
103+
104+
public static bool ShowStatisticsPanelPing
105+
{
106+
get => _showStatisticsPanelPing;
107+
set
108+
{
109+
if (_showStatisticsPanelPing == value)
110+
{
111+
return;
112+
}
113+
114+
_showStatisticsPanelPing = value;
115+
if (_statisticsPanel is { } panel)
116+
{
117+
panel.IsPingEnabled = value;
99118
}
100119
}
101120
}
@@ -234,10 +253,12 @@ public static void InitGwen()
234253
_uiMainMenu = null;
235254
}
236255

237-
_showFPSPanel = Globals.Database?.ShowFPSCounter ?? false;
238-
_fpsPanel = new FPSPanel(CurrentInterface.Root)
256+
_showStatisticsPanelFPS = Globals.Database?.ShowFPSCounter ?? false;
257+
_showStatisticsPanelPing = Globals.Database?.ShowPingCounter ?? false;
258+
_statisticsPanel = new StatisticsPanel(CurrentInterface.Root)
239259
{
240-
IsVisibleInParent = _showFPSPanel,
260+
IsFPSEnabled = _showStatisticsPanelFPS,
261+
IsPingEnabled = _showStatisticsPanelPing,
241262
};
242263

243264
Globals.EmitLifecycleChangedState();

Intersect.Client.Core/Interface/Shared/FPSPanel.cs

Lines changed: 0 additions & 77 deletions
This file was deleted.

Intersect.Client.Core/Interface/Shared/SettingsWindow.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public partial class SettingsWindow : Window
7575
private readonly LabeledComboBox _resolutionList;
7676
private readonly LabeledComboBox _fpsList;
7777
private readonly LabeledCheckBox _showFPSCounterCheckbox;
78+
private readonly LabeledCheckBox _showPingCounterCheckbox;
7879
public readonly LabeledCheckBox _enableScrollingWorldZoomCheckbox;
7980
private readonly LabeledSlider _worldScale;
8081
private readonly LabeledCheckBox _fullscreenCheckbox;
@@ -237,6 +238,17 @@ public SettingsWindow(Base parent) : base(parent: parent, title: Strings.Setting
237238
Text = Strings.Settings.TypewriterText,
238239
};
239240

241+
// Game > Information
242+
243+
_showPingCounterCheckbox = new LabeledCheckBox(parent: _informationSettings, name: nameof(_showPingCounterCheckbox))
244+
{
245+
Dock = Pos.Top,
246+
Font = _defaultFont,
247+
FontSize = 12,
248+
Text = Strings.Settings.ShowPingCounter,
249+
};
250+
_showPingCounterCheckbox.CheckChanged += ShowPingCounterCheckboxOnCheckChanged;
251+
240252
// Game Settings - Information: Friends.
241253
_friendOverheadInfoCheckbox = new LabeledCheckBox(parent: _informationSettings, name: nameof(_friendOverheadInfoCheckbox))
242254
{
@@ -603,7 +615,12 @@ public SettingsWindow(Base parent) : base(parent: parent, title: Strings.Setting
603615

604616
private static void ShowFPSCounterCheckboxOnCheckChanged(ICheckbox fpsCounterCheckbox, ValueChangedEventArgs<bool> args)
605617
{
606-
Interface.ShowFPSPanel = args.Value;
618+
Interface.ShowStatisticsPanelFPS = args.Value;
619+
}
620+
621+
private static void ShowPingCounterCheckboxOnCheckChanged(ICheckbox pingCounterCheckbox, ValueChangedEventArgs<bool> args)
622+
{
623+
Interface.ShowStatisticsPanelPing = args.Value;
607624
}
608625

609626
protected override void EnsureInitialized()
@@ -868,6 +885,7 @@ private void Reset()
868885
{
869886
Title = Strings.Settings.Title;
870887

888+
_gameSettingsTabInterface.Select();
871889
_gameSettingsTab.Select();
872890

873891
UpdateWorldScaleControls();
@@ -998,6 +1016,7 @@ public void Show(Base? returnTo)
9981016
}
9991017
}
10001018

1019+
_showPingCounterCheckbox.IsChecked = Globals.Database.ShowPingCounter;
10011020
_showFPSCounterCheckbox.IsChecked = Globals.Database.ShowFPSCounter;
10021021

10031022
switch (Globals.Database.TargetFps)
@@ -1204,6 +1223,7 @@ private void SettingsApplyBtn_Clicked(Base sender, MouseButtonState arguments)
12041223
}
12051224

12061225
Globals.Database.ShowFPSCounter = _showFPSCounterCheckbox.IsChecked;
1226+
Globals.Database.ShowPingCounter = _showPingCounterCheckbox.IsChecked;
12071227

12081228
// Audio Settings.
12091229
Globals.Database.MusicVolume = (int)_musicSlider.Value;
@@ -1234,6 +1254,8 @@ private void CancelPendingChangesButton_Clicked(Base sender, MouseButtonState ar
12341254
// Update previously saved values in order to discard changes.
12351255
Globals.Database.MusicVolume = _previousMusicVolume;
12361256
Globals.Database.SoundVolume = _previousSoundVolume;
1257+
Interface.ShowStatisticsPanelFPS = Globals.Database.ShowFPSCounter;
1258+
Interface.ShowStatisticsPanelPing = Globals.Database.ShowPingCounter;
12371259
Audio.UpdateGlobalVolume();
12381260
_keybindingEditControls = new Controls(Controls.ActiveControls);
12391261

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
using System.Numerics;
2+
using Intersect.Client.Core;
3+
using Intersect.Client.Framework.File_Management;
4+
using Intersect.Client.Framework.Gwen;
5+
using Intersect.Client.Framework.Gwen.Control;
6+
using Intersect.Client.Framework.Gwen.Control.EventArguments;
7+
using Intersect.Client.Interface.Data;
8+
using Intersect.Client.Localization;
9+
10+
namespace Intersect.Client.Interface.Shared;
11+
12+
public partial class StatisticsPanel : Panel
13+
{
14+
private readonly Label _labelFPS;
15+
private readonly Label _labelPing;
16+
17+
public StatisticsPanel(Base parent, string name = nameof(StatisticsPanel)) : base(parent: parent, name: name)
18+
{
19+
Alignment = [Alignments.Top, Alignments.Right];
20+
BackgroundColor = new Color(0x7f, 0, 0, 0);
21+
DockChildSpacing = new Padding(0, 4);
22+
Padding = new Padding(8, 4);
23+
RestrictToParent = true;
24+
25+
var font = GameContentManager.Current.GetFont("sourcesansproblack");
26+
27+
_labelFPS = new Label(this, name: nameof(_labelFPS))
28+
{
29+
AutoSizeToContents = false,
30+
Dock = Pos.Top,
31+
Font = font,
32+
FontSize = 10,
33+
Padding = new Padding(8, 4),
34+
Text = Strings.General.FpsLabelFormat.ToString(Graphics.Renderer.FPS),
35+
TextAlign = Pos.Center,
36+
};
37+
var sizeFPS = Graphics.Renderer.MeasureText(
38+
Strings.General.FpsLabelFormat.ToString(10_000),
39+
font,
40+
size: 10,
41+
fontScale: 1
42+
);
43+
_labelFPS.MinimumSize = sizeFPS;
44+
45+
_labelPing = new Label(this, name: nameof(_labelPing))
46+
{
47+
AutoSizeToContents = false,
48+
Dock = Pos.Top,
49+
Font = font,
50+
FontSize = 10,
51+
Padding = new Padding(8, 4),
52+
Text = Strings.General.PingLabelFormat.ToString(Networking.Network.Ping),
53+
TextAlign = Pos.Center,
54+
};
55+
var sizePing = Graphics.Renderer.MeasureText(
56+
Strings.General.PingLabelFormat.ToString(10_000),
57+
font,
58+
size: 10,
59+
fontScale: 1
60+
);
61+
_labelPing.MinimumSize = sizePing;
62+
63+
MinimumSize = new Vector2(
64+
16 + Math.Max(sizeFPS.X, sizePing.X),
65+
8 + Math.Max(sizeFPS.Y, sizePing.Y)
66+
);
67+
68+
DelegateDataProvider<int> fpsProvider = new(() => Graphics.Renderer.FPS)
69+
{
70+
UserData = _labelFPS,
71+
};
72+
AddDataProvider(fpsProvider);
73+
fpsProvider.ValueChanged += OnFPSChanged;
74+
75+
DelegateDataProvider<int> pingProvider = new(() => Networking.Network.Ping)
76+
{
77+
UserData = _labelPing,
78+
};
79+
AddDataProvider(pingProvider);
80+
pingProvider.ValueChanged += OnPingChanged;
81+
}
82+
83+
public bool IsFPSEnabled
84+
{
85+
get => _labelFPS.IsVisibleInParent;
86+
set => _labelFPS.IsVisibleInParent = value;
87+
}
88+
89+
public bool IsPingEnabled
90+
{
91+
get => _labelPing.IsVisibleInParent;
92+
set => _labelPing.IsVisibleInParent = value;
93+
}
94+
95+
protected override void OnChildVisibilityChanged(object? sender, VisibilityChangedEventArgs eventArgs)
96+
{
97+
base.OnChildVisibilityChanged(sender, eventArgs);
98+
99+
IsVisibleInParent = IsFPSEnabled || IsPingEnabled;
100+
}
101+
102+
private static void OnFPSChanged(IDataProvider dataProvider, ValueChangedEventArgs<int> args)
103+
{
104+
if (dataProvider is not DataProvider<int> typedProvider)
105+
{
106+
throw new InvalidOperationException("Received event from invalid data provider");
107+
}
108+
109+
if (typedProvider.UserData is not Label label)
110+
{
111+
throw new InvalidOperationException("Data provider's user data is not a label as expected");
112+
}
113+
114+
label.Text = Strings.General.FpsLabelFormat.ToString(args.Value);
115+
}
116+
117+
private static void OnPingChanged(IDataProvider dataProvider, ValueChangedEventArgs<int> args)
118+
{
119+
if (dataProvider is not DataProvider<int> typedProvider)
120+
{
121+
throw new InvalidOperationException("Received event from invalid data provider");
122+
}
123+
124+
if (typedProvider.UserData is not Label label)
125+
{
126+
throw new InvalidOperationException("Data provider's user data is not a label as expected");
127+
}
128+
129+
label.Text = Strings.General.PingLabelFormat.ToString(args.Value);
130+
}
131+
132+
protected override void Layout(Framework.Gwen.Skin.Base skin)
133+
{
134+
base.Layout(skin);
135+
136+
SizeToChildren();
137+
}
138+
}

Intersect.Client.Core/Localization/Strings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,9 @@ public partial struct General
12631263

12641264
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
12651265
public static LocalizedString FpsLabelFormat = @"{0}fps";
1266+
1267+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
1268+
public static LocalizedString PingLabelFormat = @"{0}ms";
12661269
}
12671270

12681271
public partial struct Guilds
@@ -2110,6 +2113,9 @@ public partial struct Settings
21102113
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
21112114
public static LocalizedString ShowFPSCounter = @"Show FPS Counter";
21122115

2116+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
2117+
public static LocalizedString ShowPingCounter = @"Show Ping Counter";
2118+
21132119
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
21142120
public static LocalizedString Fullscreen = @"Fullscreen";
21152121

0 commit comments

Comments
 (0)