From fc411bac3c25cbc581d5b4f681ec6f953c301d86 Mon Sep 17 00:00:00 2001 From: axolotlmaid Date: Fri, 12 Jul 2024 23:48:30 +0100 Subject: [PATCH] Continuation of commit 2f650bb (#20) I keep forgetting to stage my files >:( --- .../gui/EditProfileScreen.java | 105 ++++++++++++++---- .../gui/OptionsToggleList.java | 15 ++- .../gui/OptionsToggleScreen.java | 46 ++++++-- .../optionsprofiles/gui/ProfilesList.java | 85 +++++++++----- .../optionsprofiles/gui/ProfilesScreen.java | 34 ++++-- .../mixin/MixinOptionsScreen.java | 15 ++- .../optionsprofiles/profiles/Profiles.java | 5 +- .../profiles/loaders/SodiumExtraLoader.java | 2 - 8 files changed, 223 insertions(+), 84 deletions(-) diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java index 17facee..fc158ec 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java @@ -7,50 +7,109 @@ import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.*; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; public class EditProfileScreen extends Screen { private final Screen lastScreen; - private final String profileName; + private final Component profileName; private EditBox profileNameEdit; - public EditProfileScreen(Screen screen, String profileName) { - super(new TextComponent(new TranslatableComponent("gui.optionsprofiles.editing-profile-title").getString() + profileName)); + public EditProfileScreen(Screen screen, Component profileName) { + super(new TextComponent(new TranslatableComponent("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString())); this.lastScreen = screen; this.profileName = profileName; } protected void init() { - this.profileNameEdit = new EditBox(this.font, this.width / 2 - 102, this.height - 130, 204, 20, new TextComponent(Component.EMPTY.getString())); - this.profileNameEdit.setValue(profileName); + this.profileNameEdit = new EditBox( + this.font, + this.width / 2 - 102, + 70, + 204, + 20, + new TextComponent(Component.EMPTY.getString()) + ); + this.profileNameEdit.setValue(profileName.getString()); this.addRenderableWidget(this.profileNameEdit); - this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 85, 100, 20, new TranslatableComponent("gui.optionsprofiles.overwrite-options"), (button) -> { - Profiles.writeProfile(profileName, true); - this.minecraft.setScreen(this.lastScreen); - })); + this.addRenderableWidget( + new Button( + this.width / 2 - 75, + 100, + 150, + 20, + new TranslatableComponent("gui.optionsprofiles.overwrite-options"), + (button) -> { + Profiles.writeProfile(profileName.getString(), true); + this.minecraft.setScreen(this.lastScreen); + }, + (button, poseStack, i, j) -> EditProfileScreen.this.renderTooltip(poseStack, new TranslatableComponent("gui.optionsprofiles.overwrite-options.tooltip"), i, j) + ) + ); - this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 65, 100, 20, new TranslatableComponent("gui.optionsprofiles.rename-profile"), (button) -> { - Profiles.renameProfile(profileName, this.profileNameEdit.getValue()); - this.minecraft.setScreen(new EditProfileScreen(lastScreen, this.profileNameEdit.getValue())); - })); + this.addRenderableWidget( + new Button( + this.width / 2 - 75, + 121, + 150, + 20, + new TranslatableComponent("gui.optionsprofiles.rename-profile"), + (button) -> { + Profiles.renameProfile(profileName.getString(), this.profileNameEdit.getValue()); + this.minecraft.setScreen(new EditProfileScreen(lastScreen, new TextComponent(this.profileNameEdit.getValue()))); + } + ) + ); - this.addRenderableWidget(new Button(5, this.height - 25, 100, 20, new TranslatableComponent("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button) -> { - Profiles.deleteProfile(profileName); - this.minecraft.setScreen(this.lastScreen); - })); + this.addRenderableWidget( + new Button( + this.width / 2 - 75, + 142, + 150, + 20, + new TranslatableComponent("gui.optionsprofiles.options-toggle").append("..."), + (button) -> { + this.minecraft.setScreen(new OptionsToggleScreen(this, profileName)); + }, + (button, poseStack, i, j) -> EditProfileScreen.this.renderTooltip(poseStack, new TranslatableComponent("gui.optionsprofiles.options-toggle.tooltip"), i, j) + ) + ); - this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 40, 100, 20, CommonComponents.GUI_DONE, (button) -> { - this.minecraft.setScreen(this.lastScreen); - })); + this.addRenderableWidget( + new Button( + 10, + this.height - 29, + 50, + 20, + new TranslatableComponent("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), + (button) -> { + Profiles.deleteProfile(profileName.getString()); + this.minecraft.setScreen(this.lastScreen); + } + ) + ); + + this.addRenderableWidget( + new Button( + this.width / 2 - 100, + this.height - 29, + 200, + 20, + CommonComponents.GUI_DONE, + (button) -> this.minecraft.setScreen(this.lastScreen) + ) + ); } public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { renderBackground(poseStack); -// this.profileNameEdit.render(poseStack, mouseX, mouseY, delta); + this.profileNameEdit.render(poseStack, mouseX, mouseY, delta); GuiComponent.drawCenteredString(poseStack, this.font, this.title, this.width / 2, 8, 16777215); - GuiComponent.drawCenteredString(poseStack, this.font, new TranslatableComponent("gui.optionsprofiles.profile-name-text"), this.width / 2, this.height - 145, 16777215); + GuiComponent.drawCenteredString(poseStack, this.font, new TranslatableComponent("gui.optionsprofiles.profile-name-text"), this.width / 2, 50, 16777215); super.render(poseStack, mouseX, mouseY, delta); } } \ No newline at end of file diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleList.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleList.java index 155f08d..e92a142 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleList.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleList.java @@ -26,11 +26,13 @@ import java.util.stream.Stream; public class OptionsToggleList extends ContainerObjectSelectionList { private final String profileName; private final ProfileConfiguration profileConfiguration; + private final OptionsToggleScreen optionsToggleScreen; public OptionsToggleList(OptionsToggleScreen optionsToggleScreen, Minecraft minecraft, String profileName) { super(minecraft, optionsToggleScreen.width, optionsToggleScreen.height, 20, optionsToggleScreen.height - 32, 20); - this.profileConfiguration = optionsToggleScreen.profileConfiguration; this.profileName = profileName; + this.profileConfiguration = optionsToggleScreen.profileConfiguration; + this.optionsToggleScreen = optionsToggleScreen; refreshEntries(false, false); } @@ -81,10 +83,12 @@ public class OptionsToggleList extends ContainerObjectSelectionList toggleButton; OptionEntry(String optionKey, String optionValue, boolean toggled) { this.optionKey = new TextComponent(optionKey); + this.optionValue = new TextComponent(optionValue); this.toggleButton = CycleButton.onOffBuilder(toggled).displayOnlyValue().create(0, 0, 44, 20, TextComponent.EMPTY, (button, boolean_) -> { List optionsToLoad = profileConfiguration.getOptionsToLoad(); @@ -101,9 +105,6 @@ public class OptionsToggleList extends ContainerObjectSelectionList children() { diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleScreen.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleScreen.java index fe64769..3c21557 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/OptionsToggleScreen.java @@ -1,8 +1,8 @@ package com.axolotlmaid.optionsprofiles.gui; import com.axolotlmaid.optionsprofiles.profiles.ProfileConfiguration; -import com.axolotlmaid.optionsprofiles.profiles.Profiles; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; @@ -18,7 +18,7 @@ public class OptionsToggleScreen extends Screen { public ProfileConfiguration profileConfiguration; public OptionsToggleScreen(Screen lastScreen, Component profileName) { - super(new TranslatableComponent("gui.optionsprofiles.profiles-menu")); + super(new TranslatableComponent("gui.optionsprofiles.options-toggle").append(": ").append(profileName)); this.lastScreen = lastScreen; this.profileName = profileName; this.profileConfiguration = ProfileConfiguration.get(profileName.getString()); @@ -28,15 +28,41 @@ public class OptionsToggleScreen extends Screen { this.optionsToggleList = new OptionsToggleList(this, this.minecraft, profileName.getString()); this.addWidget(this.optionsToggleList); - // buttons - this.addRenderableWidget(new Button(this.width / 2 - 155, this.height - 29, 150, 20, new TranslatableComponent("gui.optionsprofiles.save-current-options"), (button) -> { -// Profiles.createProfile(); - this.optionsToggleList.refreshEntries(false, false); - })); + this.addRenderableWidget( + new Button( + this.width / 2 - 80, + this.height - 29, + 75, + 20, + new TranslatableComponent("gui.optionsprofiles.all-off").withStyle(ChatFormatting.RED), + (button) -> this.optionsToggleList.refreshEntries(true, false) + ) + ); - this.addRenderableWidget(new Button(this.width / 2 + 5, this.height - 29, 150, 20, CommonComponents.GUI_DONE, (button) -> { - this.minecraft.setScreen(this.lastScreen); - })); + this.addRenderableWidget( + new Button( + this.width / 2 - 155, + this.height - 29, + 75, + 20, + new TranslatableComponent("gui.optionsprofiles.all-on").withStyle(ChatFormatting.GREEN), + (button) -> this.optionsToggleList.refreshEntries(true, true) + ) + ); + + this.addRenderableWidget( + new Button( + this.width / 2 + 5, + this.height - 29, + 150, + 20, + CommonComponents.GUI_DONE, + (button) -> { + profileConfiguration.save(); + this.minecraft.setScreen(this.lastScreen); + } + ) + ); } public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java index 05892f2..09dbe97 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java @@ -1,5 +1,7 @@ package com.axolotlmaid.optionsprofiles.gui; +import com.axolotlmaid.optionsprofiles.OptionsProfilesMod; +import com.axolotlmaid.optionsprofiles.profiles.ProfileConfiguration; import com.axolotlmaid.optionsprofiles.profiles.Profiles; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.vertex.PoseStack; @@ -17,15 +19,15 @@ import net.minecraft.network.chat.TranslatableComponent; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Comparator; import java.util.List; -import java.util.Objects; public class ProfilesList extends ContainerObjectSelectionList { final ProfilesScreen profilesScreen; public ProfilesList(ProfilesScreen profilesScreen, Minecraft minecraft) { - super(minecraft, profilesScreen.width + 45, profilesScreen.height, 20, profilesScreen.height - 48, 20); + super(minecraft, profilesScreen.width + 45, profilesScreen.height, 20, profilesScreen.height - 32, 20); this.profilesScreen = profilesScreen; refreshEntries(); @@ -34,15 +36,20 @@ public class ProfilesList extends ContainerObjectSelectionList directoryStream = Files.newDirectoryStream(profilesDirectory)) { + try (DirectoryStream directoryStream = Files.newDirectoryStream(Profiles.PROFILES_DIRECTORY)) { + List profileList = new ArrayList<>(); for (Path profile : directoryStream) { - this.addEntry(new ProfilesList.ProfileEntry(profile.getFileName().toString())); + profileList.add(profile); + } + + // Sort the list alphabetically based on the profile names + profileList.sort(Comparator.comparing(p -> p.getFileName().toString())); + + for (Path profile : profileList) { + this.addEntry(new ProfilesList.ProfileEntry(new TextComponent(profile.getFileName().toString()))); } } catch (Exception e) { - System.out.println("An error occurred when listing profiles."); - e.printStackTrace(); + OptionsProfilesMod.LOGGER.error("An error occurred when listing profiles", e); } } @@ -51,51 +58,69 @@ public class ProfilesList extends ContainerObjectSelectionList { - private final String profileName; + private final Component profileName; private final Button editButton; private final Button loadButton; - ProfileEntry(String profileName) { + ProfileEntry(Component profileName) { this.profileName = profileName; - this.editButton = new Button(0, 0, 75, 20, new TranslatableComponent("gui.optionsprofiles.edit-profile"), (button) -> { - minecraft.setScreen(new EditProfileScreen(profilesScreen, profileName)); - }); + this.editButton = new Button( + 0, + 0, + 75, + 20, + new TranslatableComponent("gui.optionsprofiles.edit-profile"), + (button) -> { + minecraft.setScreen(new EditProfileScreen(profilesScreen, profileName)); + } + ); - this.loadButton = new Button(0, 0, 75, 20, new TranslatableComponent("gui.optionsprofiles.load-profile"), (button) -> { - Profiles.loadProfile(profileName); + this.loadButton = new Button( + 0, + 0, + 75, + 20, + new TranslatableComponent("gui.optionsprofiles.load-profile"), + (button) -> { + Profiles.loadProfile(profileName.getString()); - minecraft.options.load(); - minecraft.options.loadSelectedResourcePacks(minecraft.getResourcePackRepository()); - minecraft.reloadResourcePacks(); + minecraft.options.load(); - minecraft.options.save(); + if (ProfileConfiguration.get(profileName.getString()).getOptionsToLoad().contains("resourcePacks")) { + minecraft.options.loadSelectedResourcePacks(minecraft.getResourcePackRepository()); + minecraft.reloadResourcePacks(); + } - button.active = false; - }); + minecraft.options.save(); - this.loadButton.active = !Profiles.isProfileLoaded(profileName); + button.active = false; + } + ); + + this.loadButton.active = !Profiles.isProfileLoaded(profileName.getString()); } @Override public void render(PoseStack poseStack, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { Font fontRenderer = ProfilesList.this.minecraft.font; + int posX = ProfilesList.this.getScrollbarPosition() - this.loadButton.getWidth() - 10; + int posY = y - 2; int textY = y + entryHeight / 2; - Objects.requireNonNull(ProfilesList.this.minecraft.font); - GuiComponent.drawString(poseStack, fontRenderer, this.profileName, x - 50, textY - 9 / 2, 16777215); + GuiComponent.drawString(poseStack, fontRenderer, this.profileName, x, textY - 9 / 2, 16777215); - this.editButton.x = x + 115; - this.editButton.y = y; + this.editButton.x = posX - this.editButton.getWidth(); + this.editButton.y = posY; this.editButton.render(poseStack, mouseX, mouseY, tickDelta); - this.loadButton.x = x + 190; - this.loadButton.y = y; + this.loadButton.x = posX; + this.loadButton.y = posY; this.loadButton.render(poseStack, mouseX, mouseY, tickDelta); } diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java index 40ad7dc..90a9b81 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java @@ -21,20 +21,36 @@ public class ProfilesScreen extends Screen { this.profilesList = new ProfilesList(this, this.minecraft); this.addWidget(this.profilesList); - // buttons - this.addRenderableWidget(new Button(this.width / 2 - 155, this.height - 29, 150, 20, new TranslatableComponent("gui.optionsprofiles.save-current-options"), (button) -> { - Profiles.createProfile(); - this.profilesList.refreshEntries(); - })); + this.addRenderableWidget( + new Button( + this.width / 2 - 155, + this.height - 29, + 150, + 20, + new TranslatableComponent("gui.optionsprofiles.save-current-options"),(button) -> { + Profiles.createProfile(); + this.profilesList.refreshEntries(); + } + ) + ); - this.addRenderableWidget(new Button(this.width / 2 + 5, this.height - 29, 150, 20, CommonComponents.GUI_DONE, (button) -> { - this.minecraft.setScreen(this.lastScreen); - })); + this.addRenderableWidget( + new Button( + this.width / 2 + 5, + this.height - 29, + 150, + 20, + CommonComponents.GUI_DONE, + (button) -> { + this.minecraft.setScreen(this.lastScreen); + } + ) + ); } public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { this.profilesList.render(poseStack, mouseX, mouseY, delta); - GuiComponent.drawCenteredString(poseStack, this.font, this.title, this.width / 2, 12, 16777215); + GuiComponent.drawCenteredString(poseStack, this.font, this.title, this.width / 2, 8, 16777215); super.render(poseStack, mouseX, mouseY, delta); } } \ No newline at end of file diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java index 9118eae..add5d5d 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java @@ -19,8 +19,17 @@ public class MixinOptionsScreen extends Screen { @Inject(at = @At("HEAD"), method = "init") private void init(CallbackInfo info) { - this.addRenderableWidget(new Button(5, 5, 75, 20, new TranslatableComponent("gui.optionsprofiles.profiles-menu"), (button) -> { - this.minecraft.setScreen(new ProfilesScreen(this)); - })); + this.addRenderableWidget( + new Button( + 5, + 5, + 75, + 20, + new TranslatableComponent("gui.optionsprofiles.profiles-menu"), + (button) -> { + this.minecraft.setScreen(new ProfilesScreen(this)); + } + ) + ); } } \ No newline at end of file diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java index d102698..2c2cb15 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java @@ -2,8 +2,7 @@ package com.axolotlmaid.optionsprofiles.profiles; import com.axolotlmaid.optionsprofiles.OptionsProfilesMod; import com.axolotlmaid.optionsprofiles.profiles.loaders.DistantHorizonsLoader; -//import com.axolotlmaid.optionsprofiles.profiles.loaders.EmbeddiumLoader; -//import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumExtraLoader; +import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumExtraLoader; import com.axolotlmaid.optionsprofiles.profiles.loaders.SodiumLoader; import org.apache.commons.io.FileUtils; @@ -248,7 +247,7 @@ public class Profiles { loadOptionFile(profileName, OPTIONS_FILE); loadOptionFile(profileName, OPTIFINE_OPTIONS_FILE); loadOptionFile(profileName, SODIUM_OPTIONS_FILE, SodiumLoader::load); -// loadOptionFile(profileName, SODIUM_EXTRA_OPTIONS_FILE, SodiumExtraLoader::load); + loadOptionFile(profileName, SODIUM_EXTRA_OPTIONS_FILE, SodiumExtraLoader::load); // loadOptionFile(profileName, EMBEDDIUM_OPTIONS_FILE, EmbeddiumLoader::load); loadOptionFile(profileName, DISTANT_HORIZONS_OPTIONS_FILE, DistantHorizonsLoader::load); } diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/loaders/SodiumExtraLoader.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/loaders/SodiumExtraLoader.java index e0c70a9..0171173 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/loaders/SodiumExtraLoader.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/loaders/SodiumExtraLoader.java @@ -5,8 +5,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod; import me.flashyreese.mods.sodiumextra.client.gui.SodiumExtraGameOptions; -import me.jellysquid.mods.sodium.client.SodiumClientMod; -import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions; import net.minecraft.resources.ResourceLocation; import java.io.FileReader;