1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

Fixed dropdown menus not working with gamepads

This commit is contained in:
Ellpeck 2020-03-16 19:13:33 +01:00
parent e96b155f99
commit 6c866cec74

View file

@ -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) {