From dcb84f9faf0c8dbf3ff1adf5ad15a81dfb80d95a Mon Sep 17 00:00:00 2001 From: Zelaux <58040045+Zelaux@users.noreply.github.com> Date: Thu, 14 Oct 2021 23:23:12 +0500 Subject: [PATCH] Made the Menus API less conflicting (#6154) * Made the Menus API less conflicting * Fixed ignoring zero menuId in Menus --- core/src/mindustry/ui/Menus.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/ui/Menus.java b/core/src/mindustry/ui/Menus.java index 511bd7b55b..016b3416c0 100644 --- a/core/src/mindustry/ui/Menus.java +++ b/core/src/mindustry/ui/Menus.java @@ -11,11 +11,12 @@ import static mindustry.Vars.*; /** Class for handling menus and notifications across the network. Unstable API! */ public class Menus{ - private static IntMap menuListeners = new IntMap<>(); + private static final Seq menuListeners = new Seq<>(); /** Register a *global* menu listener. If no option is chosen, the option is returned as -1. */ - public static void registerMenu(int id, MenuListener listener){ - menuListeners.put(id, listener); + public static int registerMenu(MenuListener listener){ + menuListeners.add(listener); + return menuListeners.size - 1; } //do not invoke any of the methods below directly, use Call @@ -30,7 +31,7 @@ public class Menus{ @Remote(targets = Loc.both, called = Loc.both) public static void menuChoose(@Nullable Player player, int menuId, int option){ - if(player != null && menuListeners.containsKey(menuId)){ + if(player != null && menuId >= 0 && menuId < menuListeners.size){ Events.fire(new MenuOptionChooseEvent(player, menuId, option)); menuListeners.get(menuId).get(player, option); }