Skip to content

Commit d143499

Browse files
committed
feat(1173): add YesNoCancel for boolean inputs
1 parent b04b30c commit d143499

File tree

6 files changed

+97
-45
lines changed

6 files changed

+97
-45
lines changed

Intersect (Core)/Network/Packets/Client/EventInputVariablePacket.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ public EventInputVariablePacket()
1010
{
1111
}
1212

13-
public EventInputVariablePacket(Guid eventId, int value, string stringValue = "", bool canceled = false)
13+
public EventInputVariablePacket(Guid eventId, bool booleanValue, int value, string stringValue = "", bool canceled = false)
1414
{
1515
EventId = eventId;
16+
BooleanValue = booleanValue;
1617
Value = value;
1718
StringValue = stringValue;
1819
Canceled = canceled;
@@ -22,12 +23,15 @@ public EventInputVariablePacket(Guid eventId, int value, string stringValue = ""
2223
public Guid EventId { get; set; }
2324

2425
[Key(1)]
25-
public int Value { get; set; }
26+
public bool BooleanValue { get; set; }
2627

2728
[Key(2)]
2829
public string StringValue { get; set; }
2930

3031
[Key(3)]
32+
public int Value { get; set; }
33+
34+
[Key(4)]
3135
public bool Canceled { get; set; }
3236

3337
}

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

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public enum InputType
1616

1717
YesNo,
1818

19+
YesNoCancel,
20+
1921
NumericInput,
2022

2123
TextInput,
@@ -29,9 +31,11 @@ public enum InputType
2931

3032
public double Value { get; set; }
3133

34+
public bool BooleanValue { get; set; }
35+
3236
// Events
33-
private event EventHandler? OkayEventHandler;
34-
private event EventHandler? CancelEventHandler;
37+
private event EventHandler? Cancelled;
38+
private event EventHandler? Submitted;
3539

3640
// Types
3741
private readonly InputType _inputType;
@@ -46,6 +50,7 @@ public enum InputType
4650
private readonly TextBoxNumeric _txtNumericSlider;
4751
private readonly Button _btnYes;
4852
private readonly Button _btnNo;
53+
private readonly Button _btnCancel;
4954
private readonly Button _btnOk;
5055
private readonly Label _promptLabel;
5156

@@ -63,8 +68,8 @@ public InputBox(
6368
int maxQuantity = int.MaxValue
6469
) : base(Interface.CurrentInterface.Root, title, true, "InputBox")
6570
{
66-
OkayEventHandler = onSuccess;
67-
CancelEventHandler = onCancel;
71+
Submitted = onSuccess;
72+
Cancelled = onCancel;
6873
UserData = userData;
6974
_inputType = inputType;
7075
_prompt = prompt;
@@ -134,17 +139,23 @@ public InputBox(
134139
{
135140
Text = Strings.InputBox.Okay
136141
};
137-
_btnYes.Clicked += (sender, e) => SubmitInput();
142+
_btnYes.Clicked += btnYes_Clicked;
143+
144+
_btnCancel = new Button(this, "CancelButton")
145+
{
146+
Text = Strings.InputBox.Cancel,
147+
};
148+
_btnCancel.Clicked += btnCancel_Clicked;
138149

139150
_btnNo = new Button(this, "NoButton")
140151
{
141-
Text = Strings.InputBox.Cancel
152+
Text = Strings.InputBox.No,
142153
};
143-
_btnNo.Clicked += cancelBtn_Clicked;
154+
_btnNo.Clicked += btnNo_Clicked;
144155

145156
_btnOk = new Button(this, "OkayButton")
146157
{
147-
Text = Strings.InputBox.Okay
158+
Text = Strings.InputBox.Okay,
148159
};
149160
_btnOk.Clicked += (sender, e) => SubmitInput();
150161

@@ -202,51 +213,74 @@ private void _beforeDraw(Base sender, EventArgs arguments)
202213
{
203214
case InputType.YesNo:
204215
_btnYes.Text = Strings.InputBox.Yes;
205-
_btnNo.Text = Strings.InputBox.No;
216+
_btnCancel.Text = Strings.InputBox.No;
206217
_btnOk.Hide();
218+
_btnNo.Hide();
207219
_btnYes.Show();
208-
_btnNo.Show();
220+
_btnCancel.Show();
209221
_txtNumericBg.Hide();
210222
_numericSliderBg.Hide();
211223
_textboxBg.Hide();
224+
break;
225+
226+
case InputType.YesNoCancel:
227+
_btnYes.Text = Strings.InputBox.Yes;
228+
_btnYes.Show();
229+
230+
_btnCancel.Text = Strings.InputBox.Cancel;
231+
_btnCancel.Show();
232+
233+
_btnNo.Text = Strings.InputBox.No;
234+
_btnNo.Show();
212235

236+
_btnOk.Hide();
237+
_txtNumericBg.Hide();
238+
_numericSliderBg.Hide();
239+
_textboxBg.Hide();
213240
break;
241+
214242
case InputType.OkayOnly:
215243
_btnOk.Show();
216244
_btnYes.Hide();
217245
_btnNo.Hide();
246+
_btnCancel.Hide();
218247
_txtNumericBg.Hide();
219248
_numericSliderBg.Hide();
220249
_textboxBg.Hide();
221-
222250
break;
251+
223252
case InputType.NumericInput:
224253
_btnOk.Hide();
225254
_btnYes.Show();
226-
_btnNo.Show();
255+
_btnNo.Hide();
256+
_btnCancel.Show();
227257
_txtNumericBg.Show();
228258
_numericSliderBg.Hide();
229259
_textboxBg.Hide();
230-
231260
break;
261+
232262
case InputType.NumericSliderInput:
233263
_btnOk.Hide();
234264
_btnYes.Show();
235-
_btnNo.Show();
265+
_btnNo.Hide();
266+
_btnCancel.Show();
236267
_txtNumericBg.Hide();
237268
_numericSliderBg.Show();
238269
_textboxBg.Hide();
239-
240270
break;
271+
241272
case InputType.TextInput:
242273
_btnOk.Hide();
243274
_btnYes.Show();
244-
_btnNo.Show();
275+
_btnNo.Hide();
276+
_btnCancel.Show();
245277
_txtNumericBg.Hide();
246278
_numericSliderBg.Hide();
247279
_textboxBg.Show();
248-
249280
break;
281+
282+
default:
283+
throw new NotImplementedException($"{_inputType} not yet implemented");
250284
}
251285

252286
Show();
@@ -255,7 +289,27 @@ private void _beforeDraw(Base sender, EventArgs arguments)
255289
}
256290
}
257291

258-
void cancelBtn_Clicked(Base sender, ClickedEventArgs arguments)
292+
void btnNo_Clicked(Base sender, ClickedEventArgs arguments)
293+
{
294+
if (_inputType == InputType.YesNoCancel)
295+
{
296+
BooleanValue = false;
297+
}
298+
299+
SubmitInput();
300+
}
301+
302+
void btnYes_Clicked(Base sender, ClickedEventArgs arguments)
303+
{
304+
if (_inputType == InputType.YesNoCancel)
305+
{
306+
BooleanValue = true;
307+
}
308+
309+
SubmitInput();
310+
}
311+
312+
void btnCancel_Clicked(Base sender, ClickedEventArgs arguments)
259313
{
260314
if (_inputType == InputType.NumericInput)
261315
{
@@ -272,7 +326,7 @@ void cancelBtn_Clicked(Base sender, ClickedEventArgs arguments)
272326
Value = _numericSlider.Value;
273327
}
274328

275-
CancelEventHandler?.Invoke(this, EventArgs.Empty);
329+
Cancelled?.Invoke(this, EventArgs.Empty);
276330
Dispose();
277331
}
278332

@@ -293,7 +347,7 @@ public void SubmitInput()
293347
Value = _numericSlider.Value;
294348
}
295349

296-
OkayEventHandler?.Invoke(this, EventArgs.Empty);
350+
Submitted?.Invoke(this, EventArgs.Empty);
297351
Dispose();
298352
}
299353

@@ -303,6 +357,7 @@ public override void Focus(bool moveMouse = false)
303357
{
304358
case InputType.OkayOnly:
305359
case InputType.YesNo:
360+
case InputType.YesNoCancel:
306361
break;
307362
case InputType.NumericInput:
308363
_txtNumeric.Focus(moveMouse);

Intersect.Client.Core/Networking/PacketHandler.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,23 +1164,12 @@ public void HandlePacket(IPacketSender packetSender, EventDialogPacket packet)
11641164
//InputVariablePacket
11651165
public void HandlePacket(IPacketSender packetSender, InputVariablePacket packet)
11661166
{
1167-
var type = InputBox.InputType.NumericInput;
1168-
switch (packet.Type)
1167+
var type = packet.Type switch
11691168
{
1170-
case VariableDataType.String:
1171-
type = InputBox.InputType.TextInput;
1172-
1173-
break;
1174-
case VariableDataType.Integer:
1175-
case VariableDataType.Number:
1176-
type = InputBox.InputType.NumericInput;
1177-
1178-
break;
1179-
case VariableDataType.Boolean:
1180-
type = InputBox.InputType.YesNo;
1181-
1182-
break;
1183-
}
1169+
VariableDataType.String => InputBox.InputType.TextInput,
1170+
VariableDataType.Boolean => InputBox.InputType.YesNoCancel,
1171+
_ => InputBox.InputType.NumericInput,
1172+
};
11841173

11851174
_ = new InputBox(
11861175
title: packet.Title,

Intersect.Client.Core/Networking/PacketSender.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ public static void SendEventInputVariable(object? sender, EventArgs e)
147147
{
148148
if (sender is InputBox inputBox && inputBox.UserData is Guid eventId)
149149
{
150-
Network.SendPacket(new EventInputVariablePacket(eventId, (int)inputBox.Value, inputBox.TextValue));
150+
Network.SendPacket(new EventInputVariablePacket(eventId, inputBox.BooleanValue, (int)inputBox.Value, inputBox.TextValue));
151151
}
152152
}
153153

154154
public static void SendEventInputVariableCancel(object? sender, EventArgs e)
155155
{
156156
if (sender is InputBox inputBox && inputBox.UserData is Guid eventId)
157157
{
158-
Network.SendPacket(new EventInputVariablePacket(eventId, (int)inputBox.Value, inputBox.TextValue, true));
158+
Network.SendPacket(new EventInputVariablePacket(eventId, inputBox.BooleanValue, (int)inputBox.Value, inputBox.TextValue, true));
159159
}
160160
}
161161

@@ -497,7 +497,7 @@ public static void SendTransferGuild(Guid id)
497497
{
498498
Network.SendPacket(new UpdateGuildMemberPacket(id, null, Enums.GuildMemberUpdateAction.Transfer));
499499
}
500-
500+
501501
public static void SendClosePicture(Guid eventId)
502502
{
503503
if (eventId != Guid.Empty)

Intersect.Server.Core/Entities/Player.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6730,7 +6730,7 @@ public void PictureClosed(Guid eventId)
67306730
}
67316731
}
67326732

6733-
public void RespondToEventInput(Guid eventId, int newValue, string newValueString, bool canceled = false)
6733+
public void RespondToEventInput(Guid eventId, bool newValueBool, int newValue, string newValueString, bool canceled = false)
67346734
{
67356735
lock (mEventLock)
67366736
{
@@ -6847,11 +6847,11 @@ public void RespondToEventInput(Guid eventId, int newValue, string newValueStrin
68476847

68486848
break;
68496849
case VariableDataType.Boolean:
6850-
if (value.Boolean != newValue > 0)
6850+
if (value.Boolean != newValueBool)
68516851
{
68526852
changed = true;
68536853
}
6854-
value.Boolean = newValue > 0;
6854+
value.Boolean = newValueBool;
68556855
success = true;
68566856

68576857
break;

Intersect.Server.Core/Networking/PacketHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,11 @@ public void HandlePacket(Client client, EventResponsePacket packet)
14061406
public void HandlePacket(Client client, EventInputVariablePacket packet)
14071407
{
14081408
client.Entity.RespondToEventInput(
1409-
packet.EventId, packet.Value, packet.StringValue, packet.Canceled
1409+
packet.EventId,
1410+
packet.BooleanValue,
1411+
packet.Value,
1412+
packet.StringValue,
1413+
packet.Canceled
14101414
);
14111415
}
14121416

0 commit comments

Comments
 (0)