From 8b1d1e03bbb481fd2e5b1e86f82d18f5b2146197 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 4 Dec 2016 16:06:13 +0100 Subject: [PATCH] fix menu hiding items cause derpings in detecting current hovering option --- src/itdelatrisu/opsu/states/OptionsMenu.java | 14 +++++++------- src/yugecin/opsudance/ui/OptionsOverlay.java | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/itdelatrisu/opsu/states/OptionsMenu.java b/src/itdelatrisu/opsu/states/OptionsMenu.java index bd0d9b51..a41cb1a5 100644 --- a/src/itdelatrisu/opsu/states/OptionsMenu.java +++ b/src/itdelatrisu/opsu/states/OptionsMenu.java @@ -609,14 +609,14 @@ public class OptionsMenu extends BasicGameState { if (index >= currentTab.options.length) return null; - int i = index; - while (i >= 0) { - if (!currentTab.options[i--].showCondition()) { - if (++index >= currentTab.options.length) { - return null; - } + for (GameOption option : currentTab.options) { + if (option.showCondition()) { + index--; + } + if (index < 0) { + return option; } } - return currentTab.options[index]; + return null; } } diff --git a/src/yugecin/opsudance/ui/OptionsOverlay.java b/src/yugecin/opsudance/ui/OptionsOverlay.java index 885ea098..e366da4d 100644 --- a/src/yugecin/opsudance/ui/OptionsOverlay.java +++ b/src/yugecin/opsudance/ui/OptionsOverlay.java @@ -130,15 +130,15 @@ public class OptionsOverlay { if (index >= options.length) { return -1; } - int i = index; - while (i >= 0) { - if (!options[i--].showCondition()) { - if (++index >= options.length) { - return -1; - } + for (int i = 0; i < options.length; i++) { + if (options[i].showCondition()) { + index--; + } + if (index < 0) { + return i; } } - return index; + return -1; } public void update(int mouseX, int mouseY) {