1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

improve gamepad priority calculation

This commit is contained in:
Ell 2022-03-14 15:59:22 +01:00
parent d5f3453c71
commit 8fa94f1186
2 changed files with 8 additions and 6 deletions

View file

@ -387,7 +387,7 @@ namespace MLEM.Ui {
continue;
var distSq = child.Area.DistanceSquared(this.SelectedElement.Area);
// both distance and angle play a role in a destination button's priority, so we combine them
var priority = distSq * (angle / MathHelper.TwoPi + 1);
var priority = (distSq + 1) * (angle / MathHelper.PiOver2 + 1);
if (closest == null || priority < closestPriority) {
closest = child;
closestPriority = priority;

View file

@ -305,11 +305,13 @@ namespace Sandbox {
newPanel.AddChild(new Button(Anchor.TopLeft, new Vector2(100, 20), "Text", "Tooltip text"));
this.UiSystem.Add("Panel", newPanel);
var keybind = new Keybind(MouseButton.Left, ModifierKey.Shift);
var keybindPanel = new Panel(Anchor.BottomRight, new Vector2(100, 100), new Vector2(5));
for (var i = 0; i < 3; i++) {
var button = keybindPanel.AddChild(ElementHelper.KeybindButton(Anchor.AutoLeft, new Vector2(0.5F, 12), keybind, Input, "Press", Keys.Escape, index: i));
button.Text.TextScale = 0.1F;
var keybindPanel = new Panel(Anchor.BottomRight, new Vector2(130, 150), new Vector2(5));
for (var i = 0; i < 15; i++) {
var button = keybindPanel.AddChild(new Button(default, default, i.ToString()));
button.Anchor = Anchor.AutoInline;
button.Padding = new Padding(0.5F);
button.SetHeightBasedOnChildren = false;
button.Size = new Vector2(30, 50);
}
this.UiSystem.Add("Keybinds", keybindPanel);
}