aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-12-07 19:01:08 +0000
committerisXander <xandersmith2008@gmail.com>2023-12-07 19:01:08 +0000
commit7a7111e6c09e16a84279b913b76d3c506aae6a32 (patch)
tree24bd5392608dac1ff1d226d1e05234eef3137b19
parenta694321b8952a64d43134961d58fb60e1adc0cf5 (diff)
downloadYetAnotherConfigLib-7a7111e6c09e16a84279b913b76d3c506aae6a32.tar.gz
YetAnotherConfigLib-7a7111e6c09e16a84279b913b76d3c506aae6a32.tar.bz2
YetAnotherConfigLib-7a7111e6c09e16a84279b913b76d3c506aae6a32.zip
Fix tooltips flickering
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java33
-rw-r--r--test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java2
2 files changed, 21 insertions, 14 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java b/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
index 0bf9c65..d4de9c4 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
@@ -47,10 +47,16 @@ public class YACLScreen extends Screen {
public Tooltip saveButtonTooltipMessage;
private int saveButtonMessageTime;
+ private boolean pendingChanges;
+
public YACLScreen(YetAnotherConfigLib config, Screen parent) {
super(config.title());
this.config = config;
this.parent = parent;
+
+ OptionUtils.forEachOptions(config, option -> {
+ option.addListener((opt, val) -> onOptionChanged(opt));
+ });
}
@Override
@@ -151,16 +157,20 @@ public class YACLScreen extends Screen {
}
private boolean pendingChanges() {
- AtomicBoolean pendingChanges = new AtomicBoolean(false);
- OptionUtils.consumeOptions(config, (option) -> {
- if (option.changed()) {
- pendingChanges.set(true);
- return true;
- }
- return false;
+ return pendingChanges;
+ }
+
+ private void onOptionChanged(Option<?> option) {
+ pendingChanges = false;
+
+ OptionUtils.consumeOptions(config, opt -> {
+ pendingChanges |= opt.changed();
+ return pendingChanges;
});
- return pendingChanges.get();
+ if (tabManager.getCurrentTab() instanceof CategoryTab categoryTab) {
+ categoryTab.updateButtons();
+ }
}
@Override
@@ -314,7 +324,6 @@ public class YACLScreen extends Screen {
@Override
public void tick() {
- updateButtons();
descriptionWidget.tick();
}
@@ -324,14 +333,14 @@ public class YACLScreen extends Screen {
return tooltip;
}
- private void updateButtons() {
+ public void updateButtons() {
boolean pendingChanges = pendingChanges();
undoButton.active = pendingChanges;
saveFinishedButton.setMessage(pendingChanges ? Component.translatable("yacl.gui.save") : GuiUtils.translatableFallback("yacl.gui.done", CommonComponents.GUI_DONE));
- saveFinishedButton.setTooltip(Tooltip.create(pendingChanges ? Component.translatable("yacl.gui.save.tooltip") : Component.translatable("yacl.gui.finished.tooltip")));
+ saveFinishedButton.setTooltip(new YACLTooltip(pendingChanges ? Component.translatable("yacl.gui.save.tooltip") : Component.translatable("yacl.gui.finished.tooltip"), saveFinishedButton));
cancelResetButton.setMessage(pendingChanges ? GuiUtils.translatableFallback("yacl.gui.cancel", CommonComponents.GUI_CANCEL) : Component.translatable("controls.reset"));
- cancelResetButton.setTooltip(Tooltip.create(pendingChanges ? Component.translatable("yacl.gui.cancel.tooltip") : Component.translatable("yacl.gui.reset.tooltip")));
+ cancelResetButton.setTooltip(new YACLTooltip(pendingChanges ? Component.translatable("yacl.gui.cancel.tooltip") : Component.translatable("yacl.gui.reset.tooltip"), cancelResetButton));
}
}
diff --git a/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java b/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java
index 0c56caa..52a51e1 100644
--- a/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java
+++ b/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java
@@ -127,12 +127,10 @@ public class GuiTest {
.name(Component.literal("Slider Controllers"))
.option(Option.<Integer>createBuilder()
.name(Component.literal("Int Slider"))
- .instant(true)
.binding(
defaults.intSlider,
() -> config.intSlider,
value -> config.intSlider = value
-
)
.customController(opt -> new IntegerSliderController(opt, 0, 3, 1))
.build())