Skip to content

Commit 830e9a5

Browse files
committed
UI actions need to be triggered by a change in input state #2581
re-apply refactoring, this is what I get for starting working on this before comitting the massive texture overhaul changes :clown:
1 parent 2869bd9 commit 830e9a5

File tree

19 files changed

+138
-44
lines changed

19 files changed

+138
-44
lines changed

Intersect.Client.Core/Core/Controls/Controls.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,25 @@ private bool TrySaveBindingFor(Control control, int bindingIndex, ControlBinding
323323
}
324324
}
325325

326+
public static bool IsControlJustPressed(Control control) => IsControlJustPressed(control, out _, out _);
327+
328+
public static bool IsControlJustPressed(
329+
Control control,
330+
[NotNullWhen(true)] out ControlMapping? activeMapping,
331+
[NotNullWhen(true)] out ControlBinding? activeBinding
332+
)
333+
{
334+
if (ActiveControls.Mappings.TryGetValue(control, out var mapping) && mapping.IsActive(out activeBinding) && !activeBinding.WasDown())
335+
{
336+
activeMapping = mapping;
337+
return true;
338+
}
339+
340+
activeMapping = null;
341+
activeBinding = null;
342+
return false;
343+
}
344+
326345
public static bool IsControlPressed(Control control) => IsControlPressed(control, out _, out _);
327346

328347
public static bool IsControlPressed(

Intersect.Client.Core/Entities/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ private void AutoTurnToTarget(Entity en)
18631863

18641864
private static void ToggleTargetContextMenu(Entity en)
18651865
{
1866-
if (Globals.InputManager.MouseButtonDown(MouseButton.Right))
1866+
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Right))
18671867
{
18681868
Interface.Interface.GameUi.TargetContextMenu.ToggleHidden(en);
18691869
}

Intersect.Client.Core/Interface/Game/Bag/BagItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void pnl_HoverEnter(Base sender, EventArgs arguments)
116116

117117
mMouseOver = true;
118118
mCanDrag = true;
119-
if (Globals.InputManager.MouseButtonDown(MouseButton.Left))
119+
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
120120
{
121121
mCanDrag = false;
122122

@@ -186,7 +186,7 @@ public void Update()
186186
{
187187
if (mMouseOver)
188188
{
189-
if (!Globals.InputManager.MouseButtonDown(MouseButton.Left))
189+
if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
190190
{
191191
mCanDrag = true;
192192
mMouseX = -1;

Intersect.Client.Core/Interface/Game/Bank/BankItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void pnl_HoverEnter(Base sender, EventArgs arguments)
134134

135135
mMouseOver = true;
136136
mCanDrag = true;
137-
if (Globals.InputManager.MouseButtonDown(MouseButton.Left))
137+
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
138138
{
139139
mCanDrag = false;
140140

@@ -204,7 +204,7 @@ public void Update()
204204
{
205205
if (mMouseOver)
206206
{
207-
if (!Globals.InputManager.MouseButtonDown(MouseButton.Left))
207+
if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
208208
{
209209
mCanDrag = true;
210210
mMouseX = -1;

Intersect.Client.Core/Interface/Game/Character/EquipmentItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void pnl_HoverEnter(Base sender, EventArgs arguments)
9191
return;
9292
}
9393

94-
if (Globals.InputManager.MouseButtonDown(MouseButton.Left))
94+
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
9595
{
9696
return;
9797
}

Intersect.Client.Core/Interface/Game/Crafting/RecipeItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void pnl_HoverEnter(Base sender, EventArgs arguments)
101101

102102
mMouseOver = true;
103103
mCanDrag = true;
104-
if (Globals.InputManager.MouseButtonDown(MouseButton.Left))
104+
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
105105
{
106106
mCanDrag = false;
107107

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public bool Update()
4747
InputHandler.MousePosition.X - mPnl.Width / 2, InputHandler.MousePosition.Y - mPnl.Height / 2
4848
);
4949

50-
if (!Globals.InputManager.MouseButtonDown(MouseButton.Left))
50+
if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
5151
{
5252
return true;
5353
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
using Intersect.Client.Networking;
1313
using Intersect.Client.Utilities;
1414
using Intersect.Configuration;
15+
using Intersect.Core;
1516
using Intersect.Enums;
17+
using Intersect.Framework.Core;
1618
using Intersect.Utilities;
19+
using Microsoft.Extensions.Logging;
1720

1821
namespace Intersect.Client.Interface.Game;
1922

@@ -192,6 +195,7 @@ private EventWindow(Canvas gameCanvas, Dialog dialog) : base(gameCanvas, nameof(
192195
MakeModal(dim: true);
193196
BringToFront();
194197
Interface.InputBlockingComponents.Add(this);
198+
ApplicationContext.CurrentContext.Logger.LogTrace("Event window opened");
195199

196200
#endregion Configure and Display
197201
}
@@ -239,10 +243,10 @@ private void Update()
239243
optionButton.IsDisabled = disableResponse;
240244
}
241245
}
242-
else if (Controls.IsControlPressed(Control.AttackInteract))
246+
else if (Controls.IsControlJustPressed(Control.AttackInteract))
243247
{
244248
SkipTypewriting();
245-
_promptScroller.ScrollToBottom();
249+
Defer(_promptScroller.ScrollToBottom);
246250
}
247251
else
248252
{
@@ -256,6 +260,7 @@ public static void ShowOrUpdateDialog(Canvas canvas)
256260
{
257261
if (_instance is { } instance)
258262
{
263+
// ApplicationContext.CurrentContext.Logger.LogTrace("Updating previous opened event window");
259264
instance.Update();
260265
return;
261266
}

Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private void hotbarIcon_HoverEnter(Base sender, EventArgs arguments)
203203

204204
_mouseOver = true;
205205
_canDrag = true;
206-
if (Globals.InputManager.MouseButtonDown(MouseButton.Left))
206+
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
207207
{
208208
_canDrag = false;
209209

@@ -528,7 +528,7 @@ public void Update()
528528

529529
if (_mouseOver)
530530
{
531-
if (!Globals.InputManager.MouseButtonDown(MouseButton.Left))
531+
if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
532532
{
533533
_canDrag = true;
534534
_mouseX = -1;

Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void pnl_HoverEnter(Base sender, EventArgs arguments)
187187

188188
mMouseOver = true;
189189
mCanDrag = true;
190-
if (Globals.InputManager.MouseButtonDown(MouseButton.Left))
190+
if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
191191
{
192192
mCanDrag = false;
193193

@@ -358,7 +358,7 @@ public void Update()
358358
{
359359
if (mMouseOver)
360360
{
361-
if (!Globals.InputManager.MouseButtonDown(MouseButton.Left))
361+
if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left))
362362
{
363363
mCanDrag = true;
364364
mMouseX = -1;

0 commit comments

Comments
 (0)