From 3f8acba85ce820fa8663afb9ccb16688ccc833e0 Mon Sep 17 00:00:00 2001 From: orifu Date: Sun, 2 Jun 2024 15:29:00 +0100 Subject: [PATCH 1/7] initial 1.21 port --- build.gradle | 2 ++ gradle.properties | 10 +++++----- src/main/java/io/ix0rai/rainglow/Rainglow.java | 2 +- .../io/ix0rai/rainglow/config/CustomModeScreen.java | 4 ++-- .../java/io/ix0rai/rainglow/data/RainglowColour.java | 6 +++--- .../io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java | 10 +++++----- src/main/resources/fabric.mod.json | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 6a48f21..17c2b86 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,8 @@ repositories { maven { url = "https://maven.terraformersmc.com/releases/" } maven { url = "https://maven.quiltmc.org/repository/release/" } maven { url = "https://repo.sleeping.town/" } + + flatDir { dirs 'lib' } } configurations { diff --git a/gradle.properties b/gradle.properties index ab82f98..a485d18 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # minecraft, mappings and loader dependencies # check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.6 -quilt_mappings=6 +minecraft_version=1.21-pre1 +quilt_mappings=1 loader_version=0.15.11 # mod properties -mod_version=1.3.1+mc1.20.6 +mod_version=1.3.2+mc1.21 maven_group=rainglow archives_base_name=rainglow # other dependencies java_version=21 -mod_menu_version=10.0.0-beta.1 -fabric_api_version=0.98.0+1.20.6 +mod_menu_version=unknown +fabric_api_version=0.99.4+1.21 diff --git a/src/main/java/io/ix0rai/rainglow/Rainglow.java b/src/main/java/io/ix0rai/rainglow/Rainglow.java index b4c5f6a..ea0985c 100644 --- a/src/main/java/io/ix0rai/rainglow/Rainglow.java +++ b/src/main/java/io/ix0rai/rainglow/Rainglow.java @@ -54,7 +54,7 @@ public void onInitialize() { } public static Identifier id(String id) { - return new Identifier(MOD_ID, id); + return Identifier.method_60655(MOD_ID, id); } public static String generateRandomColourId(World world, RandomGenerator random) { diff --git a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java index 02df6b1..0f4d6bf 100644 --- a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java @@ -76,12 +76,12 @@ private void save() { } @Override - public void init() { + public void method_60325() { HeaderFooterLayoutWidget headerFooterWidget = new HeaderFooterLayoutWidget(this, 61, 33); headerFooterWidget.addToHeader(new TextWidget(TITLE, this.textRenderer), settings -> settings.alignHorizontallyCenter().setBottomPadding(28)); if (!this.isConfirming) { - ButtonListWidget buttonListWidget = headerFooterWidget.addToContents(new ButtonListWidget(this.client, this.width, this.height, this)); + ButtonListWidget buttonListWidget = headerFooterWidget.addToContents(new ButtonListWidget(this.client, this.width, this)); createColourToggles(); buttonListWidget.addEntries(this.options.toArray(new Option[0])); diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java b/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java index f87b2e9..20f057a 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java @@ -58,15 +58,15 @@ public Identifier getTexture(RainglowEntity entityType) { switch (entity) { case GLOW_SQUID -> { String textureName = RainglowEntity.GLOW_SQUID.getDefaultColour() == this ? "glow_squid" : this.getId(); - this.textures.put(entity, new Identifier("textures/entity/squid/" + textureName + ".png")); + this.textures.put(entity, Identifier.method_60656("textures/entity/squid/" + textureName + ".png")); } case ALLAY -> { String textureName = RainglowEntity.ALLAY.getDefaultColour() == this ? "allay" : this.getId(); - this.textures.put(entity, new Identifier("textures/entity/allay/" + textureName + ".png")); + this.textures.put(entity, Identifier.method_60656("textures/entity/allay/" + textureName + ".png")); } case SLIME -> { String textureName = RainglowEntity.SLIME.getDefaultColour() == this ? "slime" : this.getId(); - this.textures.put(entity, new Identifier("textures/entity/slime/" + textureName + ".png")); + this.textures.put(entity, Identifier.method_60656("textures/entity/slime/" + textureName + ".png")); } } } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java index bf24d8e..fad2f04 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java @@ -34,13 +34,13 @@ protected void initDataTracker(Builder builder, CallbackInfo ci) { @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { - RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); + RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random); nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour.getId()); } @Inject(method = "readCustomDataFromNbt", at = @At("TAIL")) public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { - this.setVariant(RainglowEntity.GLOW_SQUID.readNbt(this.getWorld(), nbt, this.getRandom())); + this.setVariant(RainglowEntity.GLOW_SQUID.readNbt(this.getWorld(), nbt, this.random)); } /** @@ -49,7 +49,7 @@ public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { */ @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addParticle(Lnet/minecraft/particle/ParticleEffect;DDDDDD)V"), cancellable = true) public void tickMovement(CallbackInfo ci) { - RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); + RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random); if (colour != RainglowColour.BLUE) { // we add 100 to g to let the mixin know that we want to override the method @@ -60,7 +60,7 @@ public void tickMovement(CallbackInfo ci) { @Override public RainglowColour getVariant() { - return Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); + return Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random); } @Override @@ -85,7 +85,7 @@ protected SquidEntityMixin(EntityType entityType, private int spawnParticles(ServerWorld instance, ParticleEffect particle, double x, double y, double z, int count, double deltaX, double deltaY, double deltaZ, double speed) { if (((Object) this) instanceof GlowSquidEntity) { // send in custom colour data - RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); + RainglowColour colour = Rainglow.getColour(this.getWorld(), RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.random); int index = colour.ordinal(); // round x to 1 decimal place and append index data to the next two return ((ServerWorld) this.getWorld()).spawnParticles(particle, (Math.round(x * 10)) / 10D + index / 1000D, y + 0.5, z, 0, deltaX, deltaY, deltaZ, speed); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e183bb0..580f8fd 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -40,7 +40,7 @@ "fabricloader": ">=0.14.19", "fabric-resource-loader-v0": "*", "fabric-networking-api-v1": "*", - "minecraft": ">=1.20.6" + "minecraft": ">=1.21-" }, "suggests": { From a0926587aa457a5aa8ad92f76b0652fe556e3c5c Mon Sep 17 00:00:00 2001 From: orifu Date: Sun, 2 Jun 2024 16:28:35 +0100 Subject: [PATCH 2/7] fix rai's weird config screen thing --- .../rainglow/config/CustomModeScreen.java | 40 ++++++++++++------- .../rainglow/config/RainglowConfigScreen.java | 6 ++- .../config/ScreenWithUnsavedWarning.java | 2 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java index 0f4d6bf..6a692fa 100644 --- a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java @@ -28,21 +28,24 @@ public class CustomModeScreen extends GameOptionsScreen implements ScreenWithUns public CustomModeScreen(Screen parent) { super(parent, MinecraftClient.getInstance().options, TITLE); - this.saveButton = ButtonWidget.builder(Rainglow.translatableText("config.save"), button -> { - boolean hasColourSelected = false; - for (DeferredSaveOption option : this.options) { - if (option.deferredValue) { - hasColourSelected = true; - break; + + this.saveButton = ButtonWidget.builder( + Rainglow.translatableText("config.save"), + button -> { + boolean hasColourSelected = false; + for (DeferredSaveOption option : this.options) { + if (option.deferredValue) { + hasColourSelected = true; + break; + } + } + + if (!hasColourSelected) { + sendNoColoursToast(); + } else { + this.save(); } - } - - if (!hasColourSelected) { - sendNoColoursToast(); - } else { - this.save(); - } - }).build(); + }).build(); this.saveButton.active = false; } @@ -76,7 +79,7 @@ private void save() { } @Override - public void method_60325() { + public void init() { HeaderFooterLayoutWidget headerFooterWidget = new HeaderFooterLayoutWidget(this, 61, 33); headerFooterWidget.addToHeader(new TextWidget(TITLE, this.textRenderer), settings -> settings.alignHorizontallyCenter().setBottomPadding(28)); @@ -96,6 +99,13 @@ public void method_60325() { headerFooterWidget.arrangeElements(); } + @Override + protected void method_60325() {} + + protected void repositionElements() { + this.clearAndInit(); + } + private static void sendNoColoursToast() { Toast toast = new SystemToast(SystemToast.Id.PACK_LOAD_FAILURE, Rainglow.translatableText("config.no_custom_colours"), Rainglow.translatableText("config.no_custom_colours_description")); MinecraftClient.getInstance().getToastManager().add(toast); diff --git a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java index 1b5c1c3..819f40d 100644 --- a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java @@ -100,7 +100,11 @@ public void init() { } contentLayout.add(gridWidget); - contentLayout.add(ButtonWidget.builder(Rainglow.translatableText("config.custom"), button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this))).width(308).position(4, 0).build(), LayoutSettings.create().setPadding(4, 0)); + contentLayout.add(ButtonWidget.builder( + Rainglow.translatableText("config.custom"), + button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this)) + ).width(308).position(4, 0).build(), + LayoutSettings.create().setPadding(4, 0)); headerFooterWidget.addToContents(contentLayout); diff --git a/src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java b/src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java index 389d003..6ac0f8a 100644 --- a/src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java +++ b/src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java @@ -16,7 +16,7 @@ public interface ScreenWithUnsavedWarning { void clearAndInit(); - default void setUpUnsavedWarning(HeaderFooterLayoutWidget headerFooterWidget, TextRenderer renderer, Screen parent) { + default void setUpUnsavedWarning(HeaderFooterLayoutWidget headerFooterWidget, TextRenderer renderer, Screen parent) { LinearLayoutWidget contentWidget = headerFooterWidget.addToContents(new LinearLayoutWidget(250, 100, LinearLayoutWidget.Orientation.VERTICAL).setSpacing(8)); contentWidget.add(new TextWidget(Rainglow.translatableText("config.unsaved_warning"), renderer), LayoutSettings::alignHorizontallyCenter); From 021e03f02c786c13b3ba45c61eaf6efaac56f8cf Mon Sep 17 00:00:00 2001 From: orifu Date: Sun, 2 Jun 2024 16:30:51 +0100 Subject: [PATCH 3/7] [no ci] ok --- src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java index 6a692fa..0493e58 100644 --- a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java @@ -102,6 +102,7 @@ public void init() { @Override protected void method_60325() {} + @Override protected void repositionElements() { this.clearAndInit(); } From 85d9adc34e554be35fc9df2b1e4868ae5c756e27 Mon Sep 17 00:00:00 2001 From: orifu Date: Wed, 5 Jun 2024 01:29:27 +0100 Subject: [PATCH 4/7] port to 1.21 pre 2 --- build.gradle | 2 -- gradle.properties | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 17c2b86..6a48f21 100644 --- a/build.gradle +++ b/build.gradle @@ -13,8 +13,6 @@ repositories { maven { url = "https://maven.terraformersmc.com/releases/" } maven { url = "https://maven.quiltmc.org/repository/release/" } maven { url = "https://repo.sleeping.town/" } - - flatDir { dirs 'lib' } } configurations { diff --git a/gradle.properties b/gradle.properties index a485d18..e02c57e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G # minecraft, mappings and loader dependencies # check these on https://modmuss50.me/fabric.html -minecraft_version=1.21-pre1 -quilt_mappings=1 +minecraft_version=1.21-pre2 +quilt_mappings=3 loader_version=0.15.11 # mod properties @@ -14,5 +14,5 @@ archives_base_name=rainglow # other dependencies java_version=21 -mod_menu_version=unknown +mod_menu_version=11.0.0-beta.1 fabric_api_version=0.99.4+1.21 From e0b706a5f3fee3819f992d2462b83fbb35b11a11 Mon Sep 17 00:00:00 2001 From: orifu Date: Wed, 5 Jun 2024 01:35:14 +0100 Subject: [PATCH 5/7] rewrite saveable options screen to work better with thing saveable looks nicer than savable crowder my mind --- .../rainglow/config/CustomModeScreen.java | 119 +++--------- .../rainglow/config/RainglowConfigScreen.java | 181 ++++++------------ .../config/SaveableGameOptionsScreen.java | 88 +++++++++ .../config/ScreenWithUnsavedWarning.java | 32 ---- 4 files changed, 174 insertions(+), 246 deletions(-) create mode 100644 src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java delete mode 100644 src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java diff --git a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java index 0493e58..2d5ad20 100644 --- a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java @@ -4,54 +4,43 @@ import io.ix0rai.rainglow.data.RainglowColour; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.option.GameOptionsScreen; -import net.minecraft.client.gui.widget.button.ButtonWidget; -import net.minecraft.client.gui.widget.layout.HeaderFooterLayoutWidget; -import net.minecraft.client.gui.widget.layout.LinearLayoutWidget; -import net.minecraft.client.gui.widget.list.ButtonListWidget; -import net.minecraft.client.gui.widget.text.TextWidget; import net.minecraft.client.option.Option; import net.minecraft.client.toast.SystemToast; import net.minecraft.client.toast.Toast; -import net.minecraft.text.CommonTexts; import net.minecraft.text.Text; -import java.util.ArrayList; -import java.util.List; - -public class CustomModeScreen extends GameOptionsScreen implements ScreenWithUnsavedWarning { - private final ButtonWidget saveButton; - private final List> options = new ArrayList<>(); - private boolean isConfirming; - +public class CustomModeScreen extends SaveableGameOptionsScreen { private static final Text TITLE = Rainglow.translatableText("config.custom"); public CustomModeScreen(Screen parent) { - super(parent, MinecraftClient.getInstance().options, TITLE); + super(parent, TITLE); + } - this.saveButton = ButtonWidget.builder( - Rainglow.translatableText("config.save"), - button -> { - boolean hasColourSelected = false; - for (DeferredSaveOption option : this.options) { - if (option.deferredValue) { - hasColourSelected = true; - break; - } - } + @Override + protected boolean validate() { + boolean hasColourSelected = false; + for (DeferredSaveOption option : this.options) { + if ((boolean) option.deferredValue) { + hasColourSelected = true; + break; + } + } - if (!hasColourSelected) { - sendNoColoursToast(); - } else { - this.save(); - } - }).build(); - this.saveButton.active = false; + if (!hasColourSelected) { + sendNoColoursToast(); + } + return hasColourSelected; } - private void createColourToggles() { - this.options.clear(); + @Override + protected void save() { + Rainglow.CONFIG.customColours.getRealValue().clear(); + super.save(); + Rainglow.CONFIG.save(); + } + @Override + protected void method_60325() { for (RainglowColour colour : RainglowColour.values()) { this.options.add(DeferredSaveOption.createDeferredBoolean( "colour." + colour.getId(), @@ -65,70 +54,12 @@ private void createColourToggles() { enabled -> this.saveButton.active = true )); } - } - - private void save() { - Rainglow.CONFIG.customColours.getRealValue().clear(); - - for (DeferredSaveOption option : this.options) { - option.save(); - } - - Rainglow.CONFIG.save(); - this.saveButton.active = false; - } - - @Override - public void init() { - HeaderFooterLayoutWidget headerFooterWidget = new HeaderFooterLayoutWidget(this, 61, 33); - headerFooterWidget.addToHeader(new TextWidget(TITLE, this.textRenderer), settings -> settings.alignHorizontallyCenter().setBottomPadding(28)); - - if (!this.isConfirming) { - ButtonListWidget buttonListWidget = headerFooterWidget.addToContents(new ButtonListWidget(this.client, this.width, this)); - createColourToggles(); - buttonListWidget.addEntries(this.options.toArray(new Option[0])); - - LinearLayoutWidget linearLayout = headerFooterWidget.addToFooter(LinearLayoutWidget.createHorizontal().setSpacing(8)); - linearLayout.add(ButtonWidget.builder(CommonTexts.DONE, button -> this.closeScreen()).build()); - linearLayout.add(this.saveButton); - } else { - this.setUpUnsavedWarning(headerFooterWidget, this.textRenderer, this.parent); - } - headerFooterWidget.visitWidgets(this::addDrawableSelectableElement); - headerFooterWidget.arrangeElements(); - } - - @Override - protected void method_60325() {} - - @Override - protected void repositionElements() { - this.clearAndInit(); + this.field_51824.addEntries(this.options.toArray(new Option[0])); } private static void sendNoColoursToast() { Toast toast = new SystemToast(SystemToast.Id.PACK_LOAD_FAILURE, Rainglow.translatableText("config.no_custom_colours"), Rainglow.translatableText("config.no_custom_colours_description")); MinecraftClient.getInstance().getToastManager().add(toast); } - - @Override - public void setConfirming(boolean confirming) { - this.isConfirming = confirming; - } - - @Override - public void clearAndInit() { - super.clearAndInit(); - } - - @Override - public void closeScreen() { - if (this.saveButton.active) { - this.isConfirming = true; - this.clearAndInit(); - } else { - MinecraftClient.getInstance().setScreen(this.parent); - } - } } diff --git a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java index 819f40d..ae30e3b 100644 --- a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java @@ -10,41 +10,25 @@ import net.minecraft.client.gui.widget.button.ButtonWidget; import net.minecraft.client.gui.widget.button.CyclingButtonWidget; import net.minecraft.client.gui.widget.layout.GridWidget; -import net.minecraft.client.gui.widget.layout.HeaderFooterLayoutWidget; import net.minecraft.client.gui.widget.layout.LayoutSettings; import net.minecraft.client.gui.widget.layout.LinearLayoutWidget; import net.minecraft.client.gui.widget.text.TextWidget; -import net.minecraft.client.option.Option; -import net.minecraft.text.CommonTexts; import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Language; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -public class RainglowConfigScreen extends Screen implements ScreenWithUnsavedWarning { +public class RainglowConfigScreen extends SaveableGameOptionsScreen { private static final Text TITLE = Rainglow.translatableText("config.title"); public static final Text YES = Text.translatable("gui.yes").styled(style -> style.withColor(0x00FF00)); public static final Text NO = Text.translatable("gui.no").styled(style -> style.withColor(0xFF0000)); - private final Screen parent; - private final Map> toggles = new HashMap<>(); - private final Map> sliders = new HashMap<>(); - private final ButtonWidget saveButton; - private RainglowMode mode; - private boolean isConfirming; public RainglowConfigScreen(@Nullable Screen parent) { - super(TITLE); - this.parent = parent; + super(parent, TITLE); + this.mode = getMode(); - this.saveButton = ButtonWidget.builder(Rainglow.translatableText("config.save"), button -> this.save()).build(); - this.saveButton.active = false; } private void setMode(RainglowMode mode) { @@ -74,104 +58,81 @@ private TextWidget getInfoText() { } @Override - public void init() { - HeaderFooterLayoutWidget headerFooterWidget = new HeaderFooterLayoutWidget(this, 61, 33); - LinearLayoutWidget headerLayout = headerFooterWidget.addToHeader(LinearLayoutWidget.createVertical().setSpacing(8)); - - if (!this.isConfirming) { - // header - headerLayout.add(new TextWidget(TITLE, this.textRenderer), settings -> settings.alignHorizontallyCenter().alignVerticallyTop().setPadding(12)); - headerLayout.add(createModeButton(), LayoutSettings::alignVerticallyBottom); - headerLayout.add(getInfoText(), LayoutSettings::alignHorizontallyCenter); - - // contents - LinearLayoutWidget contentLayout = LinearLayoutWidget.createVertical(); - - GridWidget gridWidget = new GridWidget(); - gridWidget.getDefaultSettings().setHorizontalPadding(4).setBottomPadding(4).alignHorizontallyCenter(); + protected void save() { + super.save(); + this.setMode(this.mode); + } - GridWidget.AdditionHelper mainAdditionHelper = gridWidget.createAdditionHelper(2); - for (RainglowEntity entity : RainglowEntity.values()) { - DeferredSaveOption entityToggle = createEntityToggle(entity); - mainAdditionHelper.add(entityToggle.createButton(MinecraftClient.getInstance().options)); - entityToggle.set(entityToggle.deferredValue); + @Override + protected void method_60325() { + LinearLayoutWidget contentLayout = LinearLayoutWidget.createVertical().setSpacing(8); - mainAdditionHelper.add(createColourRaritySlider(entity).createButton(MinecraftClient.getInstance().options)); - } + contentLayout.add(createModeButton(), LayoutSettings::alignVerticallyBottom); + contentLayout.add(getInfoText(), LayoutSettings::alignHorizontallyCenter); - contentLayout.add(gridWidget); - contentLayout.add(ButtonWidget.builder( - Rainglow.translatableText("config.custom"), - button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this)) - ).width(308).position(4, 0).build(), - LayoutSettings.create().setPadding(4, 0)); + GridWidget gridWidget = new GridWidget(); + gridWidget.getDefaultSettings().setHorizontalPadding(4).setBottomPadding(4).alignHorizontallyCenter(); - headerFooterWidget.addToContents(contentLayout); + GridWidget.AdditionHelper mainAdditionHelper = gridWidget.createAdditionHelper(2); + for (RainglowEntity entity : RainglowEntity.values()) { + DeferredSaveOption entityToggle = createEntityToggle(entity); + mainAdditionHelper.add(entityToggle.createButton(MinecraftClient.getInstance().options)); + entityToggle.set(entityToggle.deferredValue); + this.options.add(entityToggle); - // footer - LinearLayoutWidget linearLayout = headerFooterWidget.addToFooter(LinearLayoutWidget.createHorizontal().setSpacing(8)); - linearLayout.add(ButtonWidget.builder(CommonTexts.DONE, button -> this.closeScreen()).build()); - linearLayout.add(this.saveButton); - } else { - this.setUpUnsavedWarning(headerFooterWidget, this.textRenderer, this.parent); + DeferredSaveOption raritySlider = createColourRaritySlider(entity); + mainAdditionHelper.add(raritySlider.createButton(MinecraftClient.getInstance().options)); + this.options.add(raritySlider); } - headerFooterWidget.visitWidgets(this::addDrawableSelectableElement); - headerFooterWidget.arrangeElements(); + contentLayout.add(gridWidget); + contentLayout.add(ButtonWidget.builder( + Rainglow.translatableText("config.custom"), + button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this)) + ).width(308).position(4, 0).build(), + LayoutSettings.create().setPadding(4, 0)); + + this.field_49503.addToContents(contentLayout); } private DeferredSaveOption createEntityToggle(RainglowEntity entity) { - return toggles.computeIfAbsent(entity, e -> DeferredSaveOption.createDeferredBoolean( - "config.enable_" + e.getId(), - "tooltip.entity_toggle", - Rainglow.CONFIG.toggles.getRealValue().get(e.getId()), - enabled -> Rainglow.CONFIG.toggles.getRealValue().put(e.getId(), enabled), - enabled -> this.saveButton.active = true - )); + return DeferredSaveOption.createDeferredBoolean( + "config.enable_" + entity.getId(), + "tooltip.entity_toggle", + Rainglow.CONFIG.toggles.getRealValue().get(entity.getId()), + enabled -> Rainglow.CONFIG.toggles.getRealValue().put(entity.getId(), enabled), + enabled -> this.saveButton.active = true + ); } private DeferredSaveOption createColourRaritySlider(RainglowEntity entity) { - return sliders.computeIfAbsent(entity, e -> DeferredSaveOption.createDeferredRangedInt( - "config." + e.getId() + "_rarity", - "tooltip.rarity", - Rainglow.CONFIG.rarities.getRealValue().get(e.getId()), - 0, - 100, - rarity -> Rainglow.CONFIG.rarities.getRealValue().put(e.getId(), rarity), - rarity -> this.saveButton.active = true - )); + return DeferredSaveOption.createDeferredRangedInt( + "config." + entity.getId() + "_rarity", + "tooltip.rarity", + Rainglow.CONFIG.rarities.getRealValue().get(entity.getId()), + 0, + 100, + rarity -> Rainglow.CONFIG.rarities.getRealValue().put(entity.getId(), rarity), + rarity -> this.saveButton.active = true + ); } public CyclingButtonWidget createModeButton() { return CyclingButtonWidget.builder(RainglowMode::getText) - .values(RainglowMode.values()) - .initially(this.mode) - .tooltip(this::createColourListLabel) - .build( - 0, - 0, - 308, - 20, - Rainglow.translatableText("config.mode"), - (cyclingButtonWidget, mode) -> { - this.saveButton.active = true; - RainglowConfigScreen.this.mode = mode; - } - ); - } - - private void save() { - Collection> options = new ArrayList<>(this.sliders.values()); - options.addAll(this.toggles.values()); - - for (Option option : options) { - if (option instanceof DeferredSaveOption) { - ((DeferredSaveOption) option).save(); - } - } - - this.setMode(this.mode); - this.saveButton.active = false; + .values(RainglowMode.values()) + .initially(this.mode) + .tooltip(this::createColourListLabel) + .build( + 0, + 0, + 308, + 20, + Rainglow.translatableText("config.mode"), + (cyclingButtonWidget, mode) -> { + this.saveButton.active = true; + this.mode = mode; + } + ); } private Tooltip createColourListLabel(RainglowMode mode) { @@ -203,24 +164,4 @@ private Tooltip createColourListLabel(RainglowMode mode) { Style style = Style.EMPTY.withColor(mode.getText().getStyle().getColor()); return Tooltip.create(Text.literal(text.toString()).setStyle(style)); } - - @Override - public void closeScreen() { - if (this.saveButton.active) { - this.isConfirming = true; - this.clearAndInit(); - } else { - MinecraftClient.getInstance().setScreen(this.parent); - } - } - - @Override - public void setConfirming(boolean confirming) { - this.isConfirming = confirming; - } - - @Override - public void clearAndInit() { - super.clearAndInit(); - } } diff --git a/src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java b/src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java new file mode 100644 index 0000000..d045ec2 --- /dev/null +++ b/src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java @@ -0,0 +1,88 @@ +package io.ix0rai.rainglow.config; + +import io.ix0rai.rainglow.Rainglow; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.option.GameOptionsScreen; +import net.minecraft.client.gui.widget.button.ButtonWidget; +import net.minecraft.client.gui.widget.layout.HeaderFooterLayoutWidget; +import net.minecraft.client.gui.widget.layout.LayoutSettings; +import net.minecraft.client.gui.widget.layout.LinearLayoutWidget; +import net.minecraft.client.gui.widget.text.TextWidget; +import net.minecraft.text.CommonTexts; +import net.minecraft.text.Text; + +import java.util.ArrayList; +import java.util.List; + +public abstract class SaveableGameOptionsScreen extends GameOptionsScreen { + protected final ButtonWidget saveButton; + protected final List> options = new ArrayList<>(); + + public SaveableGameOptionsScreen(Screen parent, Text title) { + super(parent, MinecraftClient.getInstance().options, title); + + this.saveButton = ButtonWidget.builder( + Rainglow.translatableText("config.save"), + button -> { + if (this.validate()) { + this.save(); + } + }).build(); + this.saveButton.active = false; + } + + protected boolean validate() { + return true; + } + + protected void save() { + for (DeferredSaveOption option : this.options) { + option.save(); + } + + this.saveButton.active = false; + } + + @Override + protected void method_31387() { + LinearLayoutWidget linearLayout = this.field_49503.addToFooter(LinearLayoutWidget.createHorizontal().setSpacing(8)); + linearLayout.add(ButtonWidget.builder(CommonTexts.DONE, button -> this.closeScreen()).build()); + linearLayout.add(this.saveButton); + } + + @Override + public void closeScreen() { + if (this.saveButton.active) { + MinecraftClient.getInstance().setScreen(new ConfirmScreen(this.title)); + } else { + MinecraftClient.getInstance().setScreen(this.parent); + } + } + + public class ConfirmScreen extends Screen { + protected ConfirmScreen(Text title) { + super(title); + } + + @Override + protected void init() { + HeaderFooterLayoutWidget headerFooterWidget = new HeaderFooterLayoutWidget(this, 61, 33); + headerFooterWidget.addToHeader(new TextWidget(this.title, this.textRenderer), settings -> settings.alignHorizontallyCenter().setBottomPadding(28)); + + LinearLayoutWidget contentWidget = headerFooterWidget.addToContents(new LinearLayoutWidget(250, 100, LinearLayoutWidget.Orientation.VERTICAL).setSpacing(8)); + contentWidget.add(new TextWidget(Rainglow.translatableText("config.unsaved_warning"), this.textRenderer), LayoutSettings::alignHorizontallyCenter); + + LinearLayoutWidget buttons = new LinearLayoutWidget(250, 20, LinearLayoutWidget.Orientation.HORIZONTAL).setSpacing(8); + buttons.add(ButtonWidget.builder(Rainglow.translatableText("config.continue_editing"), (buttonWidget) -> { + MinecraftClient.getInstance().setScreen(SaveableGameOptionsScreen.this); + }).build()); + buttons.add(ButtonWidget.builder(CommonTexts.YES, (buttonWidget) -> MinecraftClient.getInstance().setScreen(parent)).build()); + + contentWidget.add(buttons, LayoutSettings::alignHorizontallyCenter); + + headerFooterWidget.visitWidgets(this::addDrawableSelectableElement); + headerFooterWidget.arrangeElements(); + } + } +} diff --git a/src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java b/src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java deleted file mode 100644 index 6ac0f8a..0000000 --- a/src/main/java/io/ix0rai/rainglow/config/ScreenWithUnsavedWarning.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.ix0rai.rainglow.config; - -import io.ix0rai.rainglow.Rainglow; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.button.ButtonWidget; -import net.minecraft.client.gui.widget.layout.HeaderFooterLayoutWidget; -import net.minecraft.client.gui.widget.layout.LayoutSettings; -import net.minecraft.client.gui.widget.layout.LinearLayoutWidget; -import net.minecraft.client.gui.widget.text.TextWidget; -import net.minecraft.text.CommonTexts; - -public interface ScreenWithUnsavedWarning { - void setConfirming(boolean confirming); - - void clearAndInit(); - - default void setUpUnsavedWarning(HeaderFooterLayoutWidget headerFooterWidget, TextRenderer renderer, Screen parent) { - LinearLayoutWidget contentWidget = headerFooterWidget.addToContents(new LinearLayoutWidget(250, 100, LinearLayoutWidget.Orientation.VERTICAL).setSpacing(8)); - contentWidget.add(new TextWidget(Rainglow.translatableText("config.unsaved_warning"), renderer), LayoutSettings::alignHorizontallyCenter); - - LinearLayoutWidget buttons = new LinearLayoutWidget(250, 20, LinearLayoutWidget.Orientation.HORIZONTAL).setSpacing(8); - buttons.add(ButtonWidget.builder(Rainglow.translatableText("config.continue_editing"), (buttonWidget) -> { - this.setConfirming(false); - this.clearAndInit(); - }).build()); - buttons.add(ButtonWidget.builder(CommonTexts.YES, (buttonWidget) -> MinecraftClient.getInstance().setScreen(parent)).build()); - - contentWidget.add(buttons, LayoutSettings::alignHorizontallyCenter); - } -} From 621e97c9973a814a2f9735706b6d6688649b0da7 Mon Sep 17 00:00:00 2001 From: orifu Date: Wed, 5 Jun 2024 01:40:28 +0100 Subject: [PATCH 6/7] use that classic intellij format style --- .../rainglow/config/CustomModeScreen.java | 18 +++--- .../rainglow/config/RainglowConfigScreen.java | 62 +++++++++---------- .../config/SaveableGameOptionsScreen.java | 19 +++--- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java index 2d5ad20..3aea6df 100644 --- a/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java @@ -43,15 +43,15 @@ protected void save() { protected void method_60325() { for (RainglowColour colour : RainglowColour.values()) { this.options.add(DeferredSaveOption.createDeferredBoolean( - "colour." + colour.getId(), - null, - Rainglow.CONFIG.customColours.getRealValue().contains(colour.getId()), - enabled -> { - if (enabled) { - Rainglow.CONFIG.customColours.getRealValue().add(colour.getId()); - } - }, - enabled -> this.saveButton.active = true + "colour." + colour.getId(), + null, + Rainglow.CONFIG.customColours.getRealValue().contains(colour.getId()), + enabled -> { + if (enabled) { + Rainglow.CONFIG.customColours.getRealValue().add(colour.getId()); + } + }, + enabled -> this.saveButton.active = true )); } diff --git a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java index ae30e3b..e1106fd 100644 --- a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java @@ -87,52 +87,52 @@ protected void method_60325() { contentLayout.add(gridWidget); contentLayout.add(ButtonWidget.builder( - Rainglow.translatableText("config.custom"), - button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this)) - ).width(308).position(4, 0).build(), - LayoutSettings.create().setPadding(4, 0)); + Rainglow.translatableText("config.custom"), + button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this)) + ).width(308).position(4, 0).build(), + LayoutSettings.create().setPadding(4, 0)); this.field_49503.addToContents(contentLayout); } private DeferredSaveOption createEntityToggle(RainglowEntity entity) { return DeferredSaveOption.createDeferredBoolean( - "config.enable_" + entity.getId(), - "tooltip.entity_toggle", - Rainglow.CONFIG.toggles.getRealValue().get(entity.getId()), - enabled -> Rainglow.CONFIG.toggles.getRealValue().put(entity.getId(), enabled), - enabled -> this.saveButton.active = true + "config.enable_" + entity.getId(), + "tooltip.entity_toggle", + Rainglow.CONFIG.toggles.getRealValue().get(entity.getId()), + enabled -> Rainglow.CONFIG.toggles.getRealValue().put(entity.getId(), enabled), + enabled -> this.saveButton.active = true ); } private DeferredSaveOption createColourRaritySlider(RainglowEntity entity) { return DeferredSaveOption.createDeferredRangedInt( - "config." + entity.getId() + "_rarity", - "tooltip.rarity", - Rainglow.CONFIG.rarities.getRealValue().get(entity.getId()), - 0, - 100, - rarity -> Rainglow.CONFIG.rarities.getRealValue().put(entity.getId(), rarity), - rarity -> this.saveButton.active = true - ); + "config." + entity.getId() + "_rarity", + "tooltip.rarity", + Rainglow.CONFIG.rarities.getRealValue().get(entity.getId()), + 0, + 100, + rarity -> Rainglow.CONFIG.rarities.getRealValue().put(entity.getId(), rarity), + rarity -> this.saveButton.active = true + ); } public CyclingButtonWidget createModeButton() { return CyclingButtonWidget.builder(RainglowMode::getText) - .values(RainglowMode.values()) - .initially(this.mode) - .tooltip(this::createColourListLabel) - .build( - 0, - 0, - 308, - 20, - Rainglow.translatableText("config.mode"), - (cyclingButtonWidget, mode) -> { - this.saveButton.active = true; - this.mode = mode; - } - ); + .values(RainglowMode.values()) + .initially(this.mode) + .tooltip(this::createColourListLabel) + .build( + 0, + 0, + 308, + 20, + Rainglow.translatableText("config.mode"), + (cyclingButtonWidget, mode) -> { + this.saveButton.active = true; + this.mode = mode; + } + ); } private Tooltip createColourListLabel(RainglowMode mode) { diff --git a/src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java b/src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java index d045ec2..1e63431 100644 --- a/src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/SaveableGameOptionsScreen.java @@ -23,12 +23,12 @@ public SaveableGameOptionsScreen(Screen parent, Text title) { super(parent, MinecraftClient.getInstance().options, title); this.saveButton = ButtonWidget.builder( - Rainglow.translatableText("config.save"), - button -> { - if (this.validate()) { - this.save(); - } - }).build(); + Rainglow.translatableText("config.save"), + button -> { + if (this.validate()) { + this.save(); + } + }).build(); this.saveButton.active = false; } @@ -74,9 +74,10 @@ protected void init() { contentWidget.add(new TextWidget(Rainglow.translatableText("config.unsaved_warning"), this.textRenderer), LayoutSettings::alignHorizontallyCenter); LinearLayoutWidget buttons = new LinearLayoutWidget(250, 20, LinearLayoutWidget.Orientation.HORIZONTAL).setSpacing(8); - buttons.add(ButtonWidget.builder(Rainglow.translatableText("config.continue_editing"), (buttonWidget) -> { - MinecraftClient.getInstance().setScreen(SaveableGameOptionsScreen.this); - }).build()); + buttons.add(ButtonWidget.builder( + Rainglow.translatableText("config.continue_editing"), + (buttonWidget) -> MinecraftClient.getInstance().setScreen(SaveableGameOptionsScreen.this) + ).build()); buttons.add(ButtonWidget.builder(CommonTexts.YES, (buttonWidget) -> MinecraftClient.getInstance().setScreen(parent)).build()); contentWidget.add(buttons, LayoutSettings::alignHorizontallyCenter); From 2b8bfb659dd29f1e8e9b65e0c0178bebee2ba3ad Mon Sep 17 00:00:00 2001 From: orifu Date: Wed, 5 Jun 2024 14:59:46 +0100 Subject: [PATCH 7/7] the bad ending :( --- .../ix0rai/rainglow/config/RainglowConfigScreen.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java index e1106fd..51ebb0f 100644 --- a/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java +++ b/src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java @@ -64,10 +64,10 @@ protected void save() { } @Override - protected void method_60325() { + protected void method_60329() { LinearLayoutWidget contentLayout = LinearLayoutWidget.createVertical().setSpacing(8); - contentLayout.add(createModeButton(), LayoutSettings::alignVerticallyBottom); + contentLayout.add(createModeButton(), LayoutSettings::alignHorizontallyCenter); contentLayout.add(getInfoText(), LayoutSettings::alignHorizontallyCenter); GridWidget gridWidget = new GridWidget(); @@ -89,12 +89,15 @@ protected void method_60325() { contentLayout.add(ButtonWidget.builder( Rainglow.translatableText("config.custom"), button -> MinecraftClient.getInstance().setScreen(new CustomModeScreen(this)) - ).width(308).position(4, 0).build(), - LayoutSettings.create().setPadding(4, 0)); + ).width(308).build(), + LayoutSettings::alignHorizontallyCenter); this.field_49503.addToContents(contentLayout); } + @Override + protected void method_60325() {} + private DeferredSaveOption createEntityToggle(RainglowEntity entity) { return DeferredSaveOption.createDeferredBoolean( "config.enable_" + entity.getId(),