Skip to content

Commit cfd32fe

Browse files
committed
warnings, errors, information alerts
1 parent 42fb6e2 commit cfd32fe

File tree

14 files changed

+95
-74
lines changed

14 files changed

+95
-74
lines changed

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,7 @@ private void _buttonCharacterSelect_Clicked(Base sender, MouseButtonState argume
131131
ToggleHidden();
132132
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
133133
{
134-
//Show Logout in Combat Warning
135-
_ = new InputBox(
136-
title: Strings.Combat.WarningTitle,
137-
prompt: Strings.Combat.WarningCharacterSelect,
138-
inputType: InputBox.InputType.YesNo,
139-
onSuccess: LogoutToCharacterSelect
140-
);
134+
ShowCombatWarning();
141135
}
142136
else
143137
{
@@ -160,13 +154,7 @@ private void buttonLogout_Clicked(Base sender, MouseButtonState arguments)
160154
ToggleHidden();
161155
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
162156
{
163-
//Show Logout in Combat Warning
164-
_ = new InputBox(
165-
title: Strings.Combat.WarningTitle,
166-
prompt: Strings.Combat.WarningLogout,
167-
inputType: InputBox.InputType.YesNo,
168-
onSuccess: LogoutToMainMenu
169-
);
157+
ShowCombatWarning();
170158
}
171159
else
172160
{
@@ -189,20 +177,25 @@ private void buttonQuit_Clicked(Base sender, MouseButtonState arguments)
189177
ToggleHidden();
190178
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
191179
{
192-
//Show Logout in Combat Warning
193-
_ = new InputBox(
194-
title: Strings.Combat.WarningTitle,
195-
prompt: Strings.Combat.WarningExitDesktop,
196-
inputType: InputBox.InputType.YesNo,
197-
onSuccess: ExitToDesktop
198-
);
180+
ShowCombatWarning();
199181
}
200182
else
201183
{
202184
ExitToDesktop(null, null);
203185
}
204186
}
205187

188+
private void ShowCombatWarning()
189+
{
190+
AlertWindow.Open(
191+
Strings.Combat.WarningCharacterSelect,
192+
Strings.Combat.WarningTitle,
193+
AlertType.Warning,
194+
handleSubmit: LogoutToCharacterSelect,
195+
inputType: InputBox.InputType.YesNo
196+
);
197+
}
198+
206199
private void ExitToDesktop(object? sender, EventArgs? e)
207200
{
208201
if (Globals.Me != null)

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ private void LogoutToCharacterSelectSelectClicked(Base sender, MouseButtonState
8181
{
8282
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
8383
{
84-
_ = new InputBox(
85-
title: Strings.Combat.WarningTitle,
86-
prompt: Strings.Combat.WarningCharacterSelect,
87-
inputType: InputBox.InputType.YesNo,
88-
onSuccess: LogoutToCharacterSelect
89-
);
84+
ShowCombatWarning();
9085
}
9186
else
9287
{
@@ -98,12 +93,7 @@ private void LogoutToMainToMainMenuClicked(Base sender, MouseButtonState argumen
9893
{
9994
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
10095
{
101-
_ = new InputBox(
102-
title: Strings.Combat.WarningTitle,
103-
prompt: Strings.Combat.WarningLogout,
104-
inputType: InputBox.InputType.YesNo,
105-
onSuccess: LogoutToMainMenu
106-
);
96+
ShowCombatWarning();
10797
}
10898
else
10999
{
@@ -115,19 +105,25 @@ private void ExitToDesktopToDesktopClicked(Base sender, MouseButtonState argumen
115105
{
116106
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
117107
{
118-
_ = new InputBox(
119-
title: Strings.Combat.WarningTitle,
120-
prompt: Strings.Combat.WarningExitDesktop,
121-
inputType: InputBox.InputType.YesNo,
122-
onSuccess: ExitToDesktop
123-
);
108+
ShowCombatWarning();
124109
}
125110
else
126111
{
127112
ExitToDesktop(null, null);
128113
}
129114
}
130115

116+
private static void ShowCombatWarning()
117+
{
118+
AlertWindow.Open(
119+
Strings.Combat.WarningCharacterSelect,
120+
Strings.Combat.WarningTitle,
121+
AlertType.Warning,
122+
handleSubmit: LogoutToCharacterSelect,
123+
inputType: InputBox.InputType.YesNo
124+
);
125+
}
126+
131127
private void OpenSettingsWindow(object? sender, EventArgs? e)
132128
{
133129
if (!_settingsWindow.IsHidden)

Intersect.Client.Core/Interface/Interface.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ public static partial class Interface
2020

2121
private static readonly ConcurrentQueue<Alert> _pendingErrorMessages = new();
2222

23-
public static void ShowError(string message, string? header = default) => _pendingErrorMessages.Enqueue(
24-
new Alert(Message: message, Title: header ?? string.Empty, Type: AlertType.Error)
25-
);
23+
public static void ShowAlert(string message, string? title = default, AlertType alertType = AlertType.Error) =>
24+
_pendingErrorMessages.Enqueue(new Alert(Message: message, Title: title ?? string.Empty, Type: alertType));
2625

2726
//GWEN GUI
2827
public static bool GwenInitialized;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Intersect.Client.Framework.Gwen.Control.EventArguments;
66
using Intersect.Client.General;
77
using Intersect.Client.Interface.Game.Chat;
8+
using Intersect.Client.Interface.Shared;
89
using Intersect.Client.Localization;
910
using Intersect.Client.Networking;
1011
using Intersect.Core;
@@ -396,7 +397,7 @@ void TryCreateCharacter()
396397

397398
if (!FieldChecking.IsValidUsername(_charNameTextbox.Text, Strings.Regex.Username))
398399
{
399-
Interface.ShowError(Strings.CharacterCreation.InvalidName);
400+
Interface.ShowAlert(Strings.CharacterCreation.InvalidName, alertType: AlertType.Error);
400401
return;
401402
}
402403

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Intersect.Client.Framework.Gwen.Control.EventArguments;
55
using Intersect.Client.Framework.Input;
66
using Intersect.Client.General;
7+
using Intersect.Client.Interface.Shared;
78
using Intersect.Client.Localization;
89
using Intersect.Client.Networking;
910
using Intersect.Utilities;
@@ -144,15 +145,15 @@ public void TrySendCode()
144145
{
145146
if (!Networking.Network.IsConnected)
146147
{
147-
Interface.ShowError(Strings.Errors.NotConnected);
148+
Interface.ShowAlert(Strings.Errors.NotConnected, alertType: AlertType.Error);
148149

149150
return;
150151
}
151152

152153
if (!FieldChecking.IsValidUsername(mInputTextbox?.Text, Strings.Regex.Username) &&
153154
!FieldChecking.IsWellformedEmailAddress(mInputTextbox?.Text, Strings.Regex.Email))
154155
{
155-
Interface.ShowError(Strings.Errors.UsernameInvalid);
156+
Interface.ShowAlert(Strings.Errors.UsernameInvalid, alertType: AlertType.Error);
156157
return;
157158
}
158159

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Intersect.Client.Framework.Input;
88
using Intersect.Client.General;
99
using Intersect.Client.Interface.Game.Chat;
10+
using Intersect.Client.Interface.Shared;
1011
using Intersect.Client.Localization;
1112
using Intersect.Client.Networking;
1213
using Intersect.Security;
@@ -282,21 +283,21 @@ private void TryLogin()
282283

283284
if (!Networking.Network.IsConnected)
284285
{
285-
Interface.ShowError(Strings.Errors.NotConnected);
286+
Interface.ShowAlert(Strings.Errors.NotConnected, alertType: AlertType.Error);
286287
return;
287288
}
288289

289290
if (!FieldChecking.IsValidUsername(_usernameInput.Text, Strings.Regex.Username))
290291
{
291-
Interface.ShowError(Strings.Errors.UsernameInvalid);
292+
Interface.ShowAlert(Strings.Errors.UsernameInvalid, alertType: AlertType.Error);
292293
return;
293294
}
294295

295296
if (!FieldChecking.IsValidPassword(_passwordInput.Text, Strings.Regex.Password))
296297
{
297298
if (!_useSavedPass)
298299
{
299-
Interface.ShowError(Strings.Errors.PasswordInvalid);
300+
Interface.ShowAlert(Strings.Errors.PasswordInvalid, alertType: AlertType.Error);
300301
return;
301302
}
302303
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Intersect.Client.Framework.Input;
88
using Intersect.Client.General;
99
using Intersect.Client.Interface.Game.Chat;
10+
using Intersect.Client.Interface.Shared;
1011
using Intersect.Client.Localization;
1112
using Intersect.Client.Networking;
1213
using Intersect.Security;
@@ -317,31 +318,31 @@ private void TryRegister()
317318

318319
if (!Networking.Network.IsConnected)
319320
{
320-
Interface.ShowError(Strings.Errors.NotConnected);
321+
Interface.ShowAlert(Strings.Errors.NotConnected, alertType: AlertType.Error);
321322
return;
322323
}
323324

324325
if (!FieldChecking.IsValidUsername(_usernameInput.Text, Strings.Regex.Username))
325326
{
326-
Interface.ShowError(Strings.Errors.UsernameInvalid);
327+
Interface.ShowAlert(Strings.Errors.UsernameInvalid, alertType: AlertType.Error);
327328
return;
328329
}
329330

330331
if (!FieldChecking.IsWellformedEmailAddress(_emailInput.Text, Strings.Regex.Email))
331332
{
332-
Interface.ShowError(Strings.Registration.EmailInvalid);
333+
Interface.ShowAlert(Strings.Registration.EmailInvalid, alertType: AlertType.Error);
333334
return;
334335
}
335336

336337
if (!FieldChecking.IsValidPassword(_passwordInput.Text, Strings.Regex.Password))
337338
{
338-
Interface.ShowError(Strings.Errors.PasswordInvalid);
339+
Interface.ShowAlert(Strings.Errors.PasswordInvalid, alertType: AlertType.Error);
339340
return;
340341
}
341342

342343
if (_passwordInput.Text != _passwordConfirmationInput.Text)
343344
{
344-
Interface.ShowError(Strings.Registration.PasswordMismatch);
345+
Interface.ShowAlert(Strings.Registration.PasswordMismatch, alertType: AlertType.Error);
345346
return;
346347
}
347348

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Intersect.Client.Framework.Input;
88
using Intersect.Client.General;
99
using Intersect.Client.Interface.Game.Chat;
10+
using Intersect.Client.Interface.Shared;
1011
using Intersect.Client.Localization;
1112
using Intersect.Client.Networking;
1213
using Intersect.Utilities;
@@ -191,25 +192,25 @@ public void TrySendCode()
191192

192193
if (!Networking.Network.IsConnected)
193194
{
194-
Interface.ShowError(Strings.Errors.NotConnected);
195+
Interface.ShowAlert(Strings.Errors.NotConnected, alertType: AlertType.Error);
195196
return;
196197
}
197198

198199
if (string.IsNullOrEmpty(mCodeInputTextbox?.Text))
199200
{
200-
Interface.ShowError(Strings.ResetPass.InputCode);
201+
Interface.ShowAlert(Strings.ResetPass.InputCode, alertType: AlertType.Error);
201202
return;
202203
}
203204

204205
if (mPasswordTextbox.Text != mPasswordTextbox2.Text)
205206
{
206-
Interface.ShowError(Strings.Registration.PasswordMismatch);
207+
Interface.ShowAlert(Strings.Registration.PasswordMismatch, alertType: AlertType.Error);
207208
return;
208209
}
209210

210211
if (!FieldChecking.IsValidPassword(mPasswordTextbox.Text, Strings.Regex.Password))
211212
{
212-
Interface.ShowError(Strings.Errors.PasswordInvalid);
213+
Interface.ShowAlert(Strings.Errors.PasswordInvalid, alertType: AlertType.Error);
213214
return;
214215
}
215216

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Intersect.Client.Interface.Shared;
99
public enum AlertType
1010
{
1111
Unknown,
12-
// Informational? Requires an icon
12+
Information,
1313
Error,
1414
Warning,
1515
}
@@ -24,13 +24,16 @@ private AlertWindow(
2424
string title,
2525
string message,
2626
AlertType alertType,
27-
object? userData = default
27+
object? userData = default,
28+
EventHandler? handleSubmit = default,
29+
EventHandler? handleCancel = default,
30+
InputType inputType = InputType.OkayOnly
2831
) : base(
2932
title,
3033
message,
31-
InputType.OkayOnly,
32-
default,
33-
default,
34+
inputType,
35+
handleSubmit,
36+
handleCancel,
3437
userData
3538
)
3639
{
@@ -77,7 +80,15 @@ public static void OpenPendingAlertWindowsFrom(IProducerConsumerCollection<Alert
7780
}
7881
}
7982

80-
public static void Open(string message, string? title = default, AlertType alertType = AlertType.Unknown, object? userData = default)
83+
public static void Open(
84+
string message,
85+
string? title = default,
86+
AlertType alertType = AlertType.Unknown,
87+
object? userData = default,
88+
EventHandler? handleSubmit = default,
89+
EventHandler? handleCancel = default,
90+
InputType inputType = InputType.OkayOnly
91+
)
8192
{
8293
if (string.IsNullOrWhiteSpace(title))
8394
{
@@ -97,7 +108,10 @@ public static void Open(string message, string? title = default, AlertType alert
97108
title: string.IsNullOrWhiteSpace(title) ? Strings.Errors.Title.ToString() : title,
98109
message: message,
99110
alertType: alertType,
100-
userData: userData
111+
userData: userData,
112+
handleSubmit: handleSubmit,
113+
handleCancel: handleCancel,
114+
inputType: inputType
101115
)
102116
);
103117
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public InputBox(
7171
int maxQuantity = int.MaxValue
7272
) : base(Interface.CurrentInterface.Root, title, true, "InputBox")
7373
{
74-
IsResizable = false;
74+
_defaultFont = GameContentManager.Current.GetFont(name: TitleLabel.FontName, 12);
7575

7676
Alignment = [Alignments.Center];
7777
MinimumSize = new Point(x: 400, y: 150);
@@ -90,7 +90,8 @@ public InputBox(
9090
_txtNumericBg = new ImagePanel(this, "Textbox");
9191
_txtNumeric = new TextBoxNumeric(_txtNumericBg, "TextboxText")
9292
{
93-
Value = quantity
93+
Font = _defaultFont,
94+
Value = quantity,
9495
};
9596
_txtNumeric.SubmitPressed += (sender, e) => SubmitInput();
9697

@@ -111,7 +112,8 @@ public InputBox(
111112
_numericSlider.ValueChanged += _numericSlider_ValueChanged;
112113
_txtNumericSlider = new TextBoxNumeric(_numericSliderBg, "SliderboxText")
113114
{
114-
Value = quantity
115+
Font = _defaultFont,
116+
Value = quantity,
115117
};
116118
_txtNumericSlider.TextChanged += _numericSliderTextbox_TextChanged;
117119
_txtNumericSlider.SubmitPressed += (sender, e) => SubmitInput();

0 commit comments

Comments
 (0)