-
Notifications
You must be signed in to change notification settings - Fork 391
Expand file tree
/
Copy pathSimplifiedEscapeMenu.cs
More file actions
193 lines (170 loc) · 5.7 KB
/
Copy pathSimplifiedEscapeMenu.cs
File metadata and controls
193 lines (170 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using Intersect.Client.Core;
using Intersect.Client.Framework.File_Management;
using Intersect.Client.Framework.Gwen;
using Intersect.Client.Framework.Gwen.Control;
using Intersect.Client.Framework.Gwen.Control.EventArguments;
using Intersect.Client.General;
using Intersect.Client.Interface.Shared;
using Intersect.Client.Localization;
using Intersect.Client.MonoGame;
using Intersect.Framework.Core;
namespace Intersect.Client.Interface.Game;
public sealed partial class SimplifiedEscapeMenu : Framework.Gwen.Control.Menu
{
private readonly Func<SettingsWindow> _settingsWindowProvider;
private readonly MenuItem _settings;
private readonly MenuItem _character;
private readonly MenuItem _logout;
private readonly MenuItem _exit;
public SimplifiedEscapeMenu(Canvas gameCanvas, Func<SettingsWindow> settingsWindowProvider) : base(gameCanvas, nameof(SimplifiedEscapeMenu))
{
IsHidden = true;
IconMarginDisabled = true;
_settingsWindowProvider = settingsWindowProvider;
ClearChildren();
_settings = AddItem(Strings.EscapeMenu.Settings);
_character = AddItem(Strings.EscapeMenu.CharacterSelect);
_logout = AddItem(Strings.EscapeMenu.Logout);
_exit = AddItem(Strings.EscapeMenu.ExitToDesktop);
_settings.Clicked += OpenSettingsWindow;
_character.Clicked += LogoutToCharacterSelectSelectClicked;
_logout.Clicked += LogoutToMainToMainMenuClicked;
_exit.Clicked += ExitToDesktopClicked;
LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer?.GetResolutionString());
}
public void ToggleHidden(Button? target)
{
var settingsWindow = _settingsWindowProvider();
if (!settingsWindow.IsHidden || target == null)
{
return;
}
if (this.IsHidden)
{
// Position the context menu within the game canvas if near borders.
var menuPosX = target.ToCanvas(new Point(0, 0)).X;
var menuPosY = target.ToCanvas(new Point(0, 0)).Y;
var newX = menuPosX;
var newY = menuPosY + target.Height + 6;
if (newX + Width >= Canvas?.Width)
{
newX = menuPosX - Width + target.Width;
}
if (newY + Height >= Canvas?.Height)
{
newY = menuPosY - Height - 6;
}
SizeToChildren();
Open(Pos.None);
SetPosition(newX, newY);
}
else
{
Close();
}
}
private void LogoutToCharacterSelectSelectClicked(Base sender, MouseButtonState arguments)
{
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
{
AlertWindow.Open(
Strings.Combat.WarningCharacterSelect,
Strings.Combat.WarningTitle,
AlertType.Warning,
handleSubmit: LogoutToCharacterSelect,
inputType: InputType.YesNo
);
}
else
{
LogoutToCharacterSelect(null, null);
}
}
private void LogoutToMainToMainMenuClicked(Base sender, MouseButtonState arguments)
{
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
{
AlertWindow.Open(
Strings.Combat.WarningLogout,
Strings.Combat.WarningTitle,
AlertType.Warning,
handleSubmit: LogoutToMainMenu,
inputType: InputType.YesNo
);
}
else
{
LogoutToMainMenu(null, null);
}
}
private void ExitToDesktopClicked(Base sender, MouseButtonState arguments)
{
if (IntersectGame._isShowingExitConfirmation)
{
return;
}
if (Globals.Me?.CombatTimer > Timing.Global?.Milliseconds)
{
AlertWindow.Open(
Strings.Combat.WarningExitDesktop,
Strings.Combat.WarningTitle,
AlertType.Warning,
inputType: InputType.YesNo,
handleSubmit: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
Globals.Me.CombatTimer = 0;
Globals.IsRunning = false;
},
handleCancel: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
}
);
}
else
{
AlertWindow.Open(
Strings.General.QuitPrompt,
Strings.General.QuitTitle,
AlertType.Warning,
inputType: InputType.YesNo,
handleSubmit: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
Globals.IsRunning = false;
},
handleCancel: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
}
);
}
IntersectGame._isShowingExitConfirmation = true;
}
private void OpenSettingsWindow(object? sender, EventArgs? e)
{
var settingsWindow = _settingsWindowProvider();
if (settingsWindow.IsVisibleInTree)
{
return;
}
settingsWindow.Show();
}
private static void LogoutToCharacterSelect(object? sender, EventArgs? e)
{
if (Globals.Me != null)
{
Globals.Me.CombatTimer = 0;
}
Main.Logout(true);
}
private static void LogoutToMainMenu(object? sender, EventArgs? e)
{
if (Globals.Me != null)
{
Globals.Me.CombatTimer = 0;
}
Main.Logout(false);
}
}