From 6c866cec74af2cead24da16b664708635a7af02a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 16 Mar 2020 19:13:33 +0100 Subject: [PATCH] Fixed dropdown menus not working with gamepads --- MLEM.Ui/Elements/Dropdown.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MLEM.Ui/Elements/Dropdown.cs b/MLEM.Ui/Elements/Dropdown.cs index 59e80fd..5da5850 100644 --- a/MLEM.Ui/Elements/Dropdown.cs +++ b/MLEM.Ui/Elements/Dropdown.cs @@ -1,4 +1,6 @@ +using System.Linq; using Microsoft.Xna.Framework; +using MLEM.Misc; namespace MLEM.Ui.Elements { public class Dropdown : Button { @@ -24,6 +26,20 @@ namespace MLEM.Ui.Elements { public void AddElement(Element element) { this.Panel.AddChild(element); + // Since the dropdown causes elements to be over each other, + // usual gamepad code doesn't apply + element.GetGamepadNextElement = (dir, usualNext) => { + if (dir == Direction2.Up) { + var prev = element.GetOlderSibling(); + if (prev != null) + return prev; + } else if (dir == Direction2.Down) { + var next = element.GetSiblings(e => e.GetOlderSibling() == element).FirstOrDefault(); + if (next != null) + return next; + } + return usualNext; + }; } public void AddElement(string text, GenericCallback pressed = null) {