Fix options not refreshing in the options screen without reopening (#22)

This commit is contained in:
axolotlmaid 2024-07-16 12:36:23 +01:00
parent b38c3f7c57
commit 427b961fb0
2 changed files with 13 additions and 2 deletions

View file

@ -4,15 +4,18 @@ import com.axolotlmaid.optionsprofiles.profiles.Profiles;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.layouts.LinearLayout;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.options.OptionsScreen;
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
public class ProfilesScreen extends OptionsSubScreen {
private Screen optionsLastScreen;
public ProfilesList profilesList;
public ProfilesScreen(Screen lastScreen) {
public ProfilesScreen(Screen lastScreen, Screen optionsLastScreen) {
super(lastScreen, null, Component.translatable("gui.optionsprofiles.profiles-menu"));
this.optionsLastScreen = optionsLastScreen;
}
protected void addOptions() {}
@ -41,6 +44,10 @@ public class ProfilesScreen extends OptionsSubScreen {
);
}
public void onClose() {
this.minecraft.setScreen(new OptionsScreen(optionsLastScreen, this.minecraft.options));
}
protected void repositionElements() {
this.layout.arrangeElements();
this.profilesList.updateSize(this.width, this.layout);

View file

@ -5,13 +5,17 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.options.OptionsScreen;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(OptionsScreen.class)
public class MixinOptionsScreen extends Screen {
@Shadow @Final private Screen lastScreen;
protected MixinOptionsScreen(Component component) {
super(component);
}
@ -21,7 +25,7 @@ public class MixinOptionsScreen extends Screen {
this.addRenderableWidget(
Button.builder(
Component.translatable("gui.optionsprofiles.profiles-menu"),
(button) -> this.minecraft.setScreen(new ProfilesScreen(this)))
(button) -> this.minecraft.setScreen(new ProfilesScreen(this, lastScreen)))
.width(75)
.pos(5, 5)
.build()