Skip to content

Commit a7c4916

Browse files
committed
feat: make version label copy version string to clipboard on click
1 parent a3b6429 commit a7c4916

File tree

4 files changed

+75
-49
lines changed

4 files changed

+75
-49
lines changed

Intersect.Client.Core/Interface/Game/EscapeMenu.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using Intersect.Client.Core;
22
using Intersect.Client.Framework.File_Management;
3-
using Intersect.Client.Framework.Gwen;
43
using Intersect.Client.Framework.Gwen.Control;
54
using Intersect.Client.Framework.Gwen.Control.EventArguments;
65
using Intersect.Client.General;
76
using Intersect.Client.Interface.Shared;
87
using Intersect.Client.Localization;
9-
using Intersect.Core;
108
using Intersect.Utilities;
119

1210
namespace Intersect.Client.Interface.Game;
@@ -16,7 +14,6 @@ public partial class EscapeMenu : ImagePanel
1614
private readonly SettingsWindow _settingsWindow;
1715
private readonly Button _buttonCharacterSelect;
1816
private readonly Panel _versionPanel;
19-
private readonly Label _versionLabel;
2017

2118
public EscapeMenu(Canvas gameCanvas) : base(gameCanvas, nameof(EscapeMenu))
2219
{
@@ -81,28 +78,7 @@ public EscapeMenu(Canvas gameCanvas) : base(gameCanvas, nameof(EscapeMenu))
8178
_buttonCharacterSelect.IsDisabled = true;
8279
}
8380

84-
_versionPanel = new Panel(this, name: nameof(_versionPanel))
85-
{
86-
Alignment = [Alignments.Bottom, Alignments.Right],
87-
BackgroundColor = new Color(0x7f, 0, 0, 0),
88-
Padding = new Padding(8, 4),
89-
RestrictToParent = true,
90-
IsVisible = ApplicationContext.CurrentContext.IsDeveloper, // TODO: Remove this when showing a game version is added
91-
};
92-
93-
_versionLabel = new Label(_versionPanel, name: nameof(_versionLabel))
94-
{
95-
Alignment = [Alignments.Center],
96-
AutoSizeToContents = true,
97-
Font = GameContentManager.Current.GetFont("sourcesansproblack", 10),
98-
Text = ApplicationContext.CurrentContext.VersionName,
99-
TextPadding = new Padding(2, 0),
100-
IsVisible = ApplicationContext.CurrentContext.IsDeveloper,
101-
};
102-
103-
_versionLabel.SizeToContents();
104-
105-
_versionPanel.SizeToChildren();
81+
_versionPanel = new VersionPanel(this, name: nameof(_versionPanel));
10682
}
10783

10884
public override void Invalidate()

Intersect.Client.Core/Interface/Menu/MenuGuiBase.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Intersect.Client.Framework.File_Management;
33
using Intersect.Client.Framework.Gwen;
44
using Intersect.Client.Framework.Gwen.Control;
5+
using Intersect.Client.Interface.Shared;
56
using Intersect.Client.Localization;
67
using Intersect.Client.Networking;
78
using Intersect.Core;
@@ -13,8 +14,7 @@ public partial class MenuGuiBase : IMutableInterface
1314
private readonly Canvas _menuCanvas;
1415
private readonly ImagePanel _serverStatusArea;
1516
private readonly Label _serverStatusLabel;
16-
private readonly Panel _versionPanel;
17-
private readonly Label _versionLabel;
17+
private readonly VersionPanel _versionPanel;
1818

1919
public MainMenu MainMenu { get; }
2020

@@ -26,28 +26,7 @@ public MenuGuiBase(Canvas myCanvas)
2626

2727
MainMenu = new MainMenu(_menuCanvas);
2828

29-
_versionPanel = new Panel(_menuCanvas, name: nameof(_versionPanel))
30-
{
31-
Alignment = [Alignments.Bottom, Alignments.Right],
32-
BackgroundColor = new Color(0x7f, 0, 0, 0),
33-
Padding = new Padding(8, 4),
34-
RestrictToParent = true,
35-
IsVisible = ApplicationContext.CurrentContext.IsDeveloper, // TODO: Remove this when showing a game version is added
36-
};
37-
38-
_versionLabel = new Label(_versionPanel, name: nameof(_versionLabel))
39-
{
40-
Alignment = [Alignments.Center],
41-
AutoSizeToContents = true,
42-
Font = GameContentManager.Current.GetFont("sourcesansproblack", 10),
43-
Text = ApplicationContext.CurrentContext.VersionName,
44-
TextPadding = new Padding(2, 0),
45-
IsVisible = ApplicationContext.CurrentContext.IsDeveloper,
46-
};
47-
48-
_versionLabel.SizeToContents();
49-
50-
_versionPanel.SizeToChildren();
29+
_versionPanel = new VersionPanel(_menuCanvas, name: nameof(_versionPanel));
5130

5231
_serverStatusArea = new ImagePanel(_menuCanvas, "ServerStatusArea")
5332
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Intersect.Client.Framework.Gwen;
2+
using Intersect.Client.Framework.Gwen.Control;
3+
using Intersect.Client.Framework.Gwen.Platform;
4+
using Intersect.Client.Framework.Input;
5+
6+
namespace Intersect.Client.Interface.Shared;
7+
8+
public partial class VersionLabel : Label
9+
{
10+
public VersionLabel(Base parent, string name = nameof(VersionLabel)) : base(parent: parent, name: name)
11+
{
12+
AutoSizeToContents = true;
13+
Dock = Pos.Top;
14+
MouseInputEnabled = true;
15+
TextPadding = new Padding(2, 0);
16+
}
17+
18+
protected override void Layout(Framework.Gwen.Skin.Base skin)
19+
{
20+
base.Layout(skin);
21+
22+
SizeToContents();
23+
}
24+
25+
protected override void OnMouseClicked(MouseButton mouseButton, Point mousePosition, bool userAction = true)
26+
{
27+
base.OnMouseClicked(mouseButton, mousePosition, userAction);
28+
29+
if (Text is { } text && !string.IsNullOrWhiteSpace(text))
30+
{
31+
Neutral.SetClipboardText(text);
32+
}
33+
}
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Intersect.Client.Framework.File_Management;
2+
using Intersect.Client.Framework.Gwen;
3+
using Intersect.Client.Framework.Gwen.Control;
4+
using Intersect.Core;
5+
6+
namespace Intersect.Client.Interface.Shared;
7+
8+
public partial class VersionPanel : Panel
9+
{
10+
private readonly VersionLabel _engineVersionLabel;
11+
12+
public VersionPanel(Base parent, string name = nameof(VersionPanel)) : base(parent: parent, name: name)
13+
{
14+
Alignment = [Alignments.Bottom, Alignments.Right];
15+
BackgroundColor = new Color(0x7f, 0, 0, 0);
16+
Padding = new Padding(8, 4);
17+
RestrictToParent = true;
18+
// TODO: Remove this when showing a game version is added
19+
IsVisible = ApplicationContext.CurrentContext.IsDeveloper;
20+
21+
var font = GameContentManager.Current.GetFont("sourcesansproblack", 10);
22+
23+
_engineVersionLabel = new VersionLabel(this, name: nameof(_engineVersionLabel))
24+
{
25+
Font = font,
26+
Text = ApplicationContext.CurrentContext.VersionName,
27+
IsVisible = ApplicationContext.CurrentContext.IsDeveloper,
28+
};
29+
}
30+
31+
protected override void Layout(Framework.Gwen.Skin.Base skin)
32+
{
33+
base.Layout(skin);
34+
35+
SizeToChildren();
36+
}
37+
}

0 commit comments

Comments
 (0)