isXander / YetAnotherConfigLib

YetAnotherConfigLib (yacl) is just that. A builder-based configuration library for Minecraft.
GNU Lesser General Public License v3.0
96 stars 36 forks source link

Save Changes doesn't exit the config menu #142

Closed falseresync closed 6 months ago

falseresync commented 7 months ago

I have:

  1. Setup a config with AutoGen
  2. Setup a ModMenu integration

When I click Save changes, no matter if I am in Game or on the Main menu, it does save the config file, but it doesn't exit the config screen. The only way to exit is to click Cancel, or to click Undo (which doesn't undo the changes because I have already clicked Save changes) and then click Done

Ayydxn commented 7 months ago

A workaround you can do for now and what I'm also doing in my project is just to close the screen yourself.

This is what I'm doing:

public Screen getHandle()
    {
        return YetAnotherConfigLib.createBuilder()
                .title(Text.translatable("iridium.options.gui_title"))
                .categories(this.optionCategories)
                .save(() ->
                {
                    this.client.options.write();
                    this.iridiumGameOptions.write();

                    // TODO: (Ayydan) Remove this when YACL has fixed the issue with the "Save Changes" button not working properly.
                    //  Refer to this GitHub issue on its repo for more details: https://github.com/isXander/YetAnotherConfigLib/issues/142
                    this.client.setScreen(this.parentScreen);
                })
                .build()
                .generateScreen(this.parentScreen);
    }

Hope this helps.

falseresync commented 7 months ago

Thanks! This should be a fairly easy PR, I'll see if I could do this in the next couple of days

Ayydxn commented 7 months ago

Thanks! This should be a fairly easy PR, I'll see if I could do this in the next couple of days

Xander fixed it in commit 5c110c8. So now, you can just add this mixin to your project until an update with the fix is released.

@Mixin(YACLScreen.class)
public class YACLScreenMixin
{
    @Shadow
    private boolean pendingChanges;

    @Shadow
    @Final
    public TabManager tabManager;

    @Inject(method = "finishOrSave", at = @At(value = "INVOKE", target = "Ljava/util/Set;forEach(Ljava/util/function/Consumer;)V", shift = At.Shift.AFTER), remap = false)
    public void tempSaveButtonFix(CallbackInfo ci)
    {
        this.pendingChanges = false;

        if (this.tabManager.getSelectedTab() instanceof YACLScreen.CategoryTab categoryTab)
            categoryTab.updateButtons();
    }
} 
falseresync commented 7 months ago

Thanks again!

falseresync commented 6 months ago

Fixed in v3.3.2