diff options
Diffstat (limited to 'src/main/java/dev/isxander/yacl/gui/YACLScreen.java')
-rw-r--r-- | src/main/java/dev/isxander/yacl/gui/YACLScreen.java | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java index 6ecbcc7..6da1c29 100644 --- a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java @@ -5,10 +5,12 @@ import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.YetAnotherConfigLib; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.api.utils.OptionUtils; +import dev.isxander.yacl.impl.YACLConstants; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import java.util.ArrayList; import java.util.List; @@ -24,6 +26,10 @@ public class YACLScreen extends Screen { public final List<CategoryWidget> categoryButtons; public ButtonWidget finishedSaveButton, cancelResetButton, undoButton; + public Text saveButtonMessage; + private int saveButtonMessageTime; + + public YACLScreen(YetAnotherConfigLib config, Screen parent) { super(config.title()); this.config = config; @@ -57,8 +63,16 @@ public class YACLScreen extends Screen { Dimension<Integer> actionDim = Dimension.ofInt(padding, height - padding - 20, columnWidth - padding * 2, 20); finishedSaveButton = new ButtonWidget(actionDim.x(), actionDim.y(), actionDim.width(), actionDim.height(), Text.empty(), (btn) -> { + saveButtonMessage = null; + if (pendingChanges()) { OptionUtils.forEachOptions(config, Option::applyValue); + OptionUtils.forEachOptions(config, option -> { + if (option.changed()) { + YACLConstants.LOGGER.error("Option '{}' was saved as '{}' but the changes don't seem to have applied.", option.name().getString(), option.pendingValue()); + setSaveButtonMessage(Text.translatable("yocl.gui.fail_apply").formatted(Formatting.RED)); + } + }); config.saveFunction().run(); } else close(); }); @@ -78,9 +92,9 @@ public class YACLScreen extends Screen { }); updateActionAvailability(); - addDrawableChild(finishedSaveButton); addDrawableChild(cancelResetButton); addDrawableChild(undoButton); + addDrawableChild(finishedSaveButton); ConfigCategory currentCategory = config.categories().get(currentCategoryIdx); optionList = new OptionListWidget(currentCategory, this, client, width, height); @@ -98,7 +112,7 @@ public class YACLScreen extends Screen { optionList.render(matrices, mouseX, mouseY, delta); for (CategoryWidget categoryWidget : categoryButtons) { - if (categoryWidget.hoveredTicks > 30) { + if (categoryWidget.hoveredTicks > YACLConstants.HOVER_TICKS) { renderOrderedTooltip(matrices, categoryWidget.wrappedDescription, mouseX, mouseY); } } @@ -107,6 +121,21 @@ public class YACLScreen extends Screen { @Override public void tick() { updateActionAvailability(); + + if (saveButtonMessage != null) { + if (saveButtonMessageTime > 140) { + saveButtonMessage = null; + saveButtonMessageTime = 0; + } else { + saveButtonMessageTime++; + finishedSaveButton.setMessage(saveButtonMessage); + } + } + } + + private void setSaveButtonMessage(Text message) { + saveButtonMessage = message; + saveButtonMessageTime = 0; } public void changeCategory(int idx) { @@ -146,7 +175,11 @@ public class YACLScreen extends Screen { @Override public boolean shouldCloseOnEsc() { - return !undoButton.active; + if (pendingChanges()) { + setSaveButtonMessage(finishedSaveButton.getMessage().copy().formatted(Formatting.GREEN, Formatting.BOLD)); + return false; + } + return true; } @Override |