Skip to content

Commit 97ffd4e

Browse files
committed
pass focus to sliderbar from slider
1 parent 8c322d1 commit 97ffd4e

File tree

16 files changed

+218
-86
lines changed

16 files changed

+218
-86
lines changed

Intersect.Client.Core/Interface/Debugging/DebugWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private Table CreateInfoTableDebugStats(Base parent)
408408
var titleRow = table.AddRow(Strings.Debug.ControlUnderCursor, columnCount: 2, name: "ControlUnderCursorRow", columnIndex: 1);
409409

410410
table.AddRow(Strings.Internals.Type, name: "TypeRow").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.GetType().GetName(), Strings.Internals.NotApplicable);
411-
table.AddRow(Strings.Internals.Name, name: "NameRow").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.CanonicalName, NoValue);
411+
table.AddRow(Strings.Internals.Name, name: "NameRow").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.ParentQualifiedName, NoValue);
412412
table.AddRow(Strings.Internals.IsVisible, name: "IsVisible").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.IsVisible, NoValue);
413413
table.AddRow(Strings.Internals.IsVisibleInParent, name: "IsVisibleInParent").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.IsVisibleInParent, NoValue);
414414
table.AddRow(Strings.Internals.IsDisabled, name: "IsDisabled").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.IsDisabled, NoValue);

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

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private void NotifyAttaching(Base parent)
351351
ApplicationContext.Context.Value?.Logger.LogWarning(
352352
exception,
353353
"Error occurred while invoking OnAttaching() for {NodeName}",
354-
CanonicalName
354+
ParentQualifiedName
355355
);
356356
}
357357
}
@@ -375,7 +375,7 @@ private void NotifyDetaching(Base parent)
375375
ApplicationContext.Context.Value?.Logger.LogWarning(
376376
exception,
377377
"Error occurred while invoking OnDetaching() for {NodeName}",
378-
CanonicalName
378+
ParentQualifiedName
379379
);
380380
}
381381
}
@@ -397,7 +397,7 @@ private void NotifyDetachingFromRoot(Base root)
397397
ApplicationContext.Context.Value?.Logger.LogWarning(
398398
exception,
399399
"Error occurred while invoking OnDetachingFromRoot() for {NodeName}",
400-
CanonicalName
400+
ParentQualifiedName
401401
);
402402
}
403403

@@ -411,8 +411,8 @@ private void NotifyDetachingFromRoot(Base root)
411411
ApplicationContext.Context.Value?.Logger.LogWarning(
412412
exception,
413413
"Error occurred while invoking NotifyDetachingFromRoot() for {NodeName} from {RootName}",
414-
CanonicalName,
415-
root.CanonicalName
414+
ParentQualifiedName,
415+
root.ParentQualifiedName
416416
);
417417
}
418418
}
@@ -434,7 +434,7 @@ private void NotifyAttachingToRoot(Base root)
434434
ApplicationContext.Context.Value?.Logger.LogWarning(
435435
exception,
436436
"Error occurred while invoking OnAttachingToRoot() for {NodeName}",
437-
CanonicalName
437+
ParentQualifiedName
438438
);
439439
}
440440

@@ -448,8 +448,8 @@ private void NotifyAttachingToRoot(Base root)
448448
ApplicationContext.Context.Value?.Logger.LogWarning(
449449
exception,
450450
"Error occurred while invoking NotifyAttachingToRoot() for {NodeName} to {RootName}",
451-
CanonicalName,
452-
root.CanonicalName
451+
ParentQualifiedName,
452+
root.ParentQualifiedName
453453
);
454454
}
455455
}
@@ -471,8 +471,8 @@ private void PropagateCanvas(Canvas? canvas)
471471
ApplicationContext.Context.Value?.Logger.LogWarning(
472472
exception,
473473
"Exception thrown while invoking PropagateCanvas() for {NodeName} with {CanvasName}",
474-
CanonicalName,
475-
canvas?.CanonicalName ?? "null"
474+
ParentQualifiedName,
475+
canvas?.ParentQualifiedName ?? "null"
476476
);
477477
}
478478
}
@@ -623,7 +623,7 @@ public virtual string? TooltipText
623623
{
624624
ApplicationContext.CurrentContext.Logger.LogWarning(
625625
"Unable to set tooltip text of {ControlName} to '{TooltipText}' because it is set to an incompatible control type {ControlType}",
626-
CanonicalName,
626+
ParentQualifiedName,
627627
value,
628628
_tooltip.GetType().GetName(qualified: true)
629629
);
@@ -895,14 +895,22 @@ public bool ShouldCacheToTexture
895895
/// <summary>
896896
/// Gets the control's internal canonical name.
897897
/// </summary>
898-
public string CanonicalName => mParent == null ? Name : mParent.Name + "." + Name;
898+
public string ParentQualifiedName =>
899+
mParent is { } parent ? $"{parent.Name}.{Name}" : Name;
900+
901+
public string CanonicalName =>
902+
(mActualParent ?? mParent) is { } parent
903+
? $"{parent.CanonicalName}.{Name}"
904+
: _name ?? $"(unnamed {GetType().GetName(qualified: true)})";
905+
906+
public string QualifiedName => $"{GetType().GetName(qualified: true)} ({Name})";
899907

900908
/// <summary>
901909
/// Gets or sets the control's internal name.
902910
/// </summary>
903-
public string? Name
911+
public string Name
904912
{
905-
get => _name;
913+
get => _name ?? $"(unnamed {GetType().Name})";
906914
set => _name = value;
907915
}
908916

@@ -1304,7 +1312,7 @@ public void LoadJsonUi(GameContentManager.UI stage, string? resolution = default
13041312
catch (Exception exception)
13051313
{
13061314
//Log JSON UI Loading Error
1307-
throw new Exception("Error loading json ui for " + CanonicalName, exception);
1315+
throw new Exception("Error loading json ui for " + ParentQualifiedName, exception);
13081316
}
13091317
}
13101318

@@ -2423,7 +2431,7 @@ public virtual bool SetBounds(int x, int y, int width, int height)
24232431
{
24242432
ApplicationContext.CurrentContext.Logger.LogWarning(
24252433
"Extremely large component resize '{ComponentName}' {OldBounds} => {NewBounds}",
2426-
CanonicalName,
2434+
ParentQualifiedName,
24272435
oldBounds.Size,
24282436
newBounds.Size
24292437
);
@@ -2959,16 +2967,25 @@ protected bool PlaySound(string? name)
29592967

29602968
public bool IsActive
29612969
{
2962-
get => _mouseButtonPressed.GetValueOrDefault(MouseButton.Left, false);
2963-
set => _mouseButtonPressed[MouseButton.Left] = value;
2970+
get => IsMouseButtonActive(MouseButton.Left);
2971+
set
2972+
{
2973+
if (value)
2974+
{
2975+
_mouseButtonPressed.Add(MouseButton.Left);
2976+
}
2977+
else
2978+
{
2979+
_mouseButtonPressed.Remove(MouseButton.Left);
2980+
}
2981+
}
29642982
}
29652983

2966-
public bool IsMouseButtonActive(MouseButton mouseButton) =>
2967-
_mouseButtonPressed.GetValueOrDefault(mouseButton, false);
2984+
public bool IsMouseButtonActive(MouseButton mouseButton) => _mouseButtonPressed.Contains(mouseButton);
29682985

2969-
private readonly Dictionary<MouseButton, bool> _mouseButtonPressed = [];
2986+
private readonly HashSet<MouseButton> _mouseButtonPressed = [];
29702987

2971-
public IReadOnlyDictionary<MouseButton, bool> MouseButtonPressed => _mouseButtonPressed;
2988+
public IReadOnlySet<MouseButton> MouseButtonPressed => _mouseButtonPressed;
29722989

29732990
protected virtual void OnMouseClicked(MouseButton mouseButton, Point mousePosition, bool userAction = true)
29742991
{
@@ -2995,7 +3012,7 @@ internal void InputMouseButtonState(MouseButton mouseButton, Point mousePosition
29953012
var wasActive = IsMouseButtonActive(mouseButton);
29963013
if (pressed)
29973014
{
2998-
_mouseButtonPressed[mouseButton] = true;
3015+
_mouseButtonPressed.Add(mouseButton);
29993016
InputHandler.MouseFocus = this;
30003017

30013018
if (!wasActive)
@@ -3018,8 +3035,17 @@ internal void InputMouseButtonState(MouseButton mouseButton, Point mousePosition
30183035
}
30193036
}
30203037

3021-
_mouseButtonPressed[mouseButton] = false;
3022-
InputHandler.MouseFocus = null;
3038+
_mouseButtonPressed.Remove(mouseButton);
3039+
3040+
if (_mouseButtonPressed.Count < 1)
3041+
{
3042+
// Only replace focus if no mouse buttons are pressed
3043+
// ApplicationContext.CurrentContext.Logger.LogTrace(
3044+
// "Setting MouseFocus to null from {NodeName}",
3045+
// CanonicalName
3046+
// );
3047+
InputHandler.MouseFocus = null;
3048+
}
30233049

30243050
if (wasActive)
30253051
{
@@ -4167,7 +4193,7 @@ protected virtual bool OnKeyTab(bool down, bool shift = false)
41674193

41684194
if (next is { IsTabable: true, IsDisabledByTree: false, IsHiddenByTree: false })
41694195
{
4170-
Console.WriteLine($"Focusing {next.CanonicalName} ({next.GetFullishName()})");
4196+
Console.WriteLine($"Focusing {next.ParentQualifiedName} ({next.GetFullishName()})");
41714197
next.Focus(moveMouse: next is not TextBox);
41724198
}
41734199

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public override void UpdateColors()
373373
ApplicationContext.CurrentContext.Logger.LogError(
374374
"Text color for the current control state of {ComponentType} '{ComponentName}' is somehow null IsDisabled={IsDisabled} IsActive={IsActive} IsHovered={IsHovered}",
375375
GetType().GetName(qualified: true),
376-
CanonicalName,
376+
ParentQualifiedName,
377377
IsDisabled,
378378
IsActive,
379379
IsHovered

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Intersect.Client.Framework.Gwen.Input;
55
using Intersect.Client.Framework.Audio;
66
using Intersect.Client.Framework.Input;
7+
using Intersect.Core;
8+
using Microsoft.Extensions.Logging;
79

810
namespace Intersect.Client.Framework.Gwen.Control;
911

@@ -285,25 +287,42 @@ public bool Input_MouseMoved(int x, int y, int dx, int dy)
285287

286288
InputHandler.OnMouseMoved(this, x, y, dx, dy);
287289

288-
if (InputHandler.HoveredControl == null)
290+
var hoveredControl = InputHandler.HoveredControl;
291+
if (hoveredControl == null)
289292
{
293+
// ApplicationContext.Context.Value?.Logger.LogTrace(
294+
// "Skipping emitting mouse moved because there is no hovered control"
295+
// );
290296
return false;
291297
}
292298

293-
if (InputHandler.HoveredControl == this)
299+
if (hoveredControl == this)
294300
{
301+
// ApplicationContext.Context.Value?.Logger.LogTrace(
302+
// "Skipping emitting mouse moved because {ControlName} is this canvas",
303+
// hoveredControl.CanonicalName
304+
// );
295305
return false;
296306
}
297307

298-
if (InputHandler.HoveredControl.Canvas != this)
308+
if (hoveredControl.Canvas != this)
299309
{
310+
// ApplicationContext.Context.Value?.Logger.LogTrace(
311+
// "Skipping emitting mouse moved because {ControlName} is not part of this canvas",
312+
// hoveredControl.CanonicalName
313+
// );
300314
return false;
301315
}
302316

303-
InputHandler.HoveredControl.InputMouseMoved(x, y, dx, dy);
304-
InputHandler.HoveredControl.UpdateCursor();
317+
// ApplicationContext.Context.Value?.Logger.LogTrace(
318+
// "Emitting mouse moved to {ControlName}",
319+
// hoveredControl.CanonicalName
320+
// );
321+
322+
hoveredControl.InputMouseMoved(x, y, dx, dy);
323+
hoveredControl.UpdateCursor();
305324

306-
DragAndDrop.OnMouseMoved(InputHandler.HoveredControl, x, y);
325+
DragAndDrop.OnMouseMoved(hoveredControl, x, y);
307326

308327
return true;
309328
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public MenuItem? SelectedItem
100100
ApplicationContext.CurrentContext.Logger.LogWarning(
101101
"Tried to set selected item of {ComponentTypeName} '{ComponentName}' to '{SelectionName}' ({SelectionType})",
102102
GetType().GetName(qualified: true),
103-
CanonicalName,
103+
ParentQualifiedName,
104104
value.Name,
105105
value.GetType().GetName(qualified: true)
106106
);
@@ -218,7 +218,7 @@ public override void LoadJson(JToken obj, bool isRoot = default)
218218
public virtual MenuItem AddItem(string label, string? name = default, object? userData = default)
219219
{
220220
var item = _menu.AddItem(label, null, "", "", Font);
221-
item.Name = name;
221+
item.Name = name!;
222222
item.Selected += OnItemSelected;
223223
item.UserData = userData;
224224
item.SetTextColor(GetTextColor(ComponentState.Normal), ComponentState.Normal);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ public override void UpdateColors()
850850
{
851851
ApplicationContext.CurrentContext.Logger.LogError(
852852
"Text color for the current control state of '{ComponentName}' is somehow null IsDisabled={IsDisabled} IsActive={IsActive} IsHovered={IsHovered}",
853-
CanonicalName,
853+
ParentQualifiedName,
854854
IsDisabled,
855855
IsActive,
856856
IsHovered

Intersect.Client.Framework/Gwen/Control/Layout/Table.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ protected virtual Point ComputeColumnWidths(TableRow[]? rows = null)
723723

724724
ApplicationContext.CurrentContext.Logger.LogTrace(
725725
"Computed table '{TableName}' content size: ({Width}, {Height})",
726-
CanonicalName,
726+
ParentQualifiedName,
727727
actualWidth,
728728
actualHeight
729729
);
@@ -763,7 +763,7 @@ public override Point GetChildrenSize()
763763
var childrenSize = base.GetChildrenSize();
764764
ApplicationContext.CurrentContext.Logger.LogTrace(
765765
"Table {TableName} children size is {ChildrenSize}",
766-
CanonicalName,
766+
ParentQualifiedName,
767767
childrenSize
768768
);
769769
return childrenSize;
@@ -773,7 +773,7 @@ public override bool SizeToChildren(bool resizeX = true, bool resizeY = true, bo
773773
{
774774
ApplicationContext.CurrentContext.Logger.LogTrace(
775775
"Resizing Table {TableName} to children (X={ResizeX}, Y={ResizeY}, Recursive={Recursive})...",
776-
CanonicalName,
776+
ParentQualifiedName,
777777
resizeX,
778778
resizeY,
779779
recursive
@@ -835,7 +835,7 @@ protected override void OnSizeChanged(Point oldSize, Point newSize)
835835

836836
ApplicationContext.CurrentContext.Logger.LogTrace(
837837
"Table {TableName} size changed from {OldSize} to {NewSize}",
838-
CanonicalName,
838+
ParentQualifiedName,
839839
oldSize,
840840
newSize
841841
);

Intersect.Client.Framework/Gwen/Control/Layout/TableRow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ protected override void OnSizeChanged(Point oldSize, Point newSize)
293293

294294
ApplicationContext.CurrentContext.Logger.LogTrace(
295295
"Table row {CanonicalName} resized from {OldSize} to {NewSize}",
296-
CanonicalName,
296+
ParentQualifiedName,
297297
oldSize,
298298
newSize
299299
);
@@ -329,7 +329,7 @@ protected override void OnChildSizeChanged(Base child, Point oldChildSize, Point
329329
{
330330
base.OnChildSizeChanged(child, oldChildSize, newChildSize);
331331

332-
var childCanonicalName = child.CanonicalName;
332+
var childCanonicalName = child.ParentQualifiedName;
333333
if (childCanonicalName.StartsWith('.') || childCanonicalName.EndsWith('.'))
334334
{
335335
return;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public Menu(Base parent, string? name = default) : base(parent, name)
4444
IconMarginDisabled = false;
4545

4646
DeleteOnClose = false;
47-
Name = name;
4847
}
4948

5049
internal override bool IsMenuComponent => true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public void InvalidateRebuild()
222222
ApplicationContext.CurrentContext.Logger.LogTrace(
223223
"Requesting rebuild of {NodeType} ({NodeName})",
224224
nameof(RichLabel),
225-
CanonicalName
225+
ParentQualifiedName
226226
);
227227

228228
_needsRebuild = true;

0 commit comments

Comments
 (0)