Skip to content

Commit f262c46

Browse files
committed
process virtual clicks instead of using a control override
1 parent b39093e commit f262c46

File tree

7 files changed

+84
-44
lines changed

7 files changed

+84
-44
lines changed

Intersect.Client.Core/Core/Input.cs

+8-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Intersect.Client.Entities;
33
using Intersect.Client.Framework.GenericClasses;
44
using Intersect.Client.Framework.Graphics;
5+
using Intersect.Client.Framework.Gwen.Input;
56
using Intersect.Client.Framework.Input;
67
using Intersect.Client.General;
78
using Intersect.Client.Interface;
@@ -97,6 +98,7 @@ public static void OnKeyPressed(Keys modifier, Keys key)
9798
if (inputBlockingComponent is InputBox { IsHidden: false } inputBox)
9899
{
99100
inputBox.SubmitInput();
101+
consumeKey = true;
100102
canFocusChat = false;
101103
break;
102104
}
@@ -108,13 +110,19 @@ public static void OnKeyPressed(Keys modifier, Keys key)
108110
if (inputBlockingComponent is EventWindow { IsHidden: false } eventWindow && Globals.EventDialogs.Count > 0)
109111
{
110112
eventWindow.CloseEventResponse(EventResponseType.OneOption);
113+
consumeKey = true;
111114
canFocusChat = false;
112115

113116
break;
114117
}
115118
}
116119
catch { }
117120
}
121+
122+
if (!consumeKey)
123+
{
124+
125+
}
118126
break;
119127
}
120128

@@ -233,22 +241,6 @@ public static void OnKeyPressed(Keys modifier, Keys key)
233241
break;
234242

235243
case GameStates.Menu:
236-
var selectCharacterWindow = Interface.Interface.MenuUi.MainMenu.SelectCharacterWindow;
237-
238-
switch (control)
239-
{
240-
case Control.Enter:
241-
if (selectCharacterWindow is { IsHidden: false, CharacterSelectionPreviews: { } previews })
242-
{
243-
var selectedPreviewIndex = selectCharacterWindow._selectedCharacterIndex;
244-
if (previews.Length > selectedPreviewIndex && previews[selectedPreviewIndex] != default)
245-
{
246-
selectCharacterWindow.ButtonPlay_Clicked(null, null);
247-
consumeKey = true;
248-
}
249-
}
250-
break;
251-
}
252244
break;
253245

254246
case GameStates.InGame:

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

+6
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ public override void Show()
346346

347347
_selectedCharacterIndex = 0;
348348
UpdateDisplay();
349+
350+
if (_buttonPlay.IsVisibleInParent)
351+
{
352+
PostLayout.Enqueue(button => button.Focus(), _buttonPlay);
353+
}
354+
349355
base.Show();
350356
EnsureArrowsVisibility();
351357
}

Intersect.Client.Framework/Gwen/Control/Base.cs

+5
Original file line numberDiff line numberDiff line change
@@ -3399,6 +3399,11 @@ protected virtual void OnMouseUp(MouseButton mouseButton, Point mousePosition, b
33993399

34003400
public bool KeepFocusOnMouseExit { get; set; }
34013401

3402+
protected void EmitVirtualClick(MouseButtonState args)
3403+
{
3404+
Clicked?.Invoke(this, args);
3405+
}
3406+
34023407
internal void InputMouseButtonState(MouseButton mouseButton, Point mousePosition, bool pressed, bool userAction = true)
34033408
{
34043409
var emitsEvents = !IsDisabledByTree;

Intersect.Client.Framework/Gwen/Control/Button.cs

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Intersect.Client.Framework.Content;
22
using Intersect.Client.Framework.File_Management;
33
using Intersect.Client.Framework.Graphics;
4+
using Intersect.Client.Framework.Gwen.Control.EventArguments;
45
using Intersect.Client.Framework.Gwen.ControlInternal;
56
using Intersect.Client.Framework.Gwen.Input;
67
using Intersect.Client.Framework.Input;
@@ -327,11 +328,26 @@ protected override void OnMouseClicked(MouseButton mouseButton, Point mousePosit
327328
/// </returns>
328329
protected override bool OnKeySpace(bool down)
329330
{
331+
if (!down)
332+
{
333+
EmitVirtualClick(new MouseButtonState(MouseButton.Left, mousePosition: default, isPressed: false));
334+
// OnMouseClicked(MouseButton.Left, default);
335+
return true;
336+
}
337+
330338
return base.OnKeySpace(down);
339+
}
340+
341+
protected override bool OnKeyReturn(bool down)
342+
{
343+
if (!down)
344+
{
345+
EmitVirtualClick(new MouseButtonState(MouseButton.Left, mousePosition: default, isPressed: false));
346+
// OnMouseClicked(MouseButton.Left, default);
347+
return true;
348+
}
331349

332-
//if (down)
333-
// OnClicked(0, 0);
334-
//return true;
350+
return base.OnKeyReturn(down);
335351
}
336352

337353
/// <summary>

Intersect.Client.Framework/Gwen/Control/TextBox.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Intersect.Client.Framework.Gwen.Input;
66
using Intersect.Client.Framework.Input;
77
using Intersect.Core;
8+
using Intersect.Framework.Reflection;
89
using Microsoft.Extensions.Logging;
910
using Newtonsoft.Json.Linq;
1011

@@ -107,6 +108,20 @@ public bool SelectAllOnFocus
107108
}
108109
}
109110

111+
protected override void OnKeyboardFocus()
112+
{
113+
base.OnKeyboardFocus();
114+
115+
ApplicationContext.CurrentContext.Logger.LogDebug("{Node} ({NodeType}) gained keyboard focus", CanonicalName, GetType().GetName());
116+
}
117+
118+
protected override void OnLostKeyboardFocus()
119+
{
120+
base.OnLostKeyboardFocus();
121+
122+
ApplicationContext.CurrentContext.Logger.LogDebug("{Node} ({NodeType}) lost keyboard focus", CanonicalName, GetType().GetName());
123+
}
124+
110125
/// <summary>
111126
/// Indicates whether the text has active selection.
112127
/// </summary>
@@ -417,7 +432,11 @@ protected override void OnMouseDoubleClicked(MouseButton mouseButton, Point mous
417432
/// </returns>
418433
protected override bool OnKeyReturn(bool down)
419434
{
420-
base.OnKeyReturn(down);
435+
if (base.OnKeyReturn(down))
436+
{
437+
return true;
438+
}
439+
421440
if (down)
422441
{
423442
return true;

Intersect.Client.Framework/Gwen/Input/InputHandler.cs

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Immutable;
22
using System.Diagnostics;
33
using System.Text;
4+
using Intersect.Client.Framework.GenericClasses;
45
using Intersect.Client.Framework.Gwen.Control;
56
using Intersect.Client.Framework.Gwen.DragDrop;
67
using Intersect.Client.Framework.Input;
@@ -206,8 +207,9 @@ public static bool IsKeyDown(Key key)
206207
/// </summary>
207208
/// <param name="canvas">Canvas.</param>
208209
/// <param name="chr">Input character.</param>
210+
/// <param name="msgKey"></param>
209211
/// <returns>True if the key was handled.</returns>
210-
public static bool DoSpecialKeys(Base canvas, char chr)
212+
public static bool DoSpecialKeys(Base canvas, char chr, Keys msgKey)
211213
{
212214
if (null == KeyboardFocus)
213215
{
@@ -224,37 +226,37 @@ public static bool DoSpecialKeys(Base canvas, char chr)
224226
return false;
225227
}
226228

227-
if (!IsControlDown)
229+
if (IsControlDown)
228230
{
229-
return false;
230-
}
231+
if (chr == 'C' || chr == 'c')
232+
{
233+
KeyboardFocus.InputCopy(null);
231234

232-
if (chr == 'C' || chr == 'c')
233-
{
234-
KeyboardFocus.InputCopy(null);
235+
return true;
236+
}
235237

236-
return true;
237-
}
238+
if (chr == 'V' || chr == 'v')
239+
{
240+
KeyboardFocus.InputPaste(null);
238241

239-
if (chr == 'V' || chr == 'v')
240-
{
241-
KeyboardFocus.InputPaste(null);
242+
return true;
243+
}
242244

243-
return true;
244-
}
245+
if (chr == 'X' || chr == 'x')
246+
{
247+
KeyboardFocus.InputCut(null);
245248

246-
if (chr == 'X' || chr == 'x')
247-
{
248-
KeyboardFocus.InputCut(null);
249+
return true;
250+
}
249251

250-
return true;
251-
}
252+
if (chr == 'A' || chr == 'a')
253+
{
254+
KeyboardFocus.InputSelectAll(null);
252255

253-
if (chr == 'A' || chr == 'a')
254-
{
255-
KeyboardFocus.InputSelectAll(null);
256+
return true;
257+
}
256258

257-
return true;
259+
return false;
258260
}
259261

260262
return false;

Intersect.Client.Framework/Gwen/Input/IntersectInput.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override bool ProcessMessage(object message)
118118
return mCanvas.Input_Character((char) msg.Unicode[0]);
119119
case InputEvent.KeyDown:
120120
var ch = TranslateChar(msg.Key);
121-
if ((int) msg.MouseBtn > -1 && InputHandler.DoSpecialKeys(mCanvas, ch))
121+
if ((int) msg.MouseBtn < 0 && InputHandler.DoSpecialKeys(mCanvas, ch, msg.Key))
122122
{
123123
return false;
124124
}

0 commit comments

Comments
 (0)