diff --git a/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesMod.java b/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesMod.java index f2c0999..3c206c2 100644 --- a/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesMod.java +++ b/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesMod.java @@ -4,7 +4,6 @@ import dev.architectury.event.events.common.CommandRegistrationEvent; import net.minecraft.client.Minecraft; import net.minecraft.commands.Commands; import net.trafficlunar.optionsprofiles.gui.ProfilesScreen; -import net.trafficlunar.optionsprofiles.profiles.OptionsProfilesModConfiguration; import net.trafficlunar.optionsprofiles.profiles.Profiles; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesModConfiguration.java b/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesModConfiguration.java index 1ce88b6..55e3958 100644 --- a/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesModConfiguration.java +++ b/common/src/main/java/net/trafficlunar/optionsprofiles/OptionsProfilesModConfiguration.java @@ -1,8 +1,8 @@ -package net.trafficlunar.optionsprofiles.profiles; +package net.trafficlunar.optionsprofiles; -import net.trafficlunar.optionsprofiles.OptionsProfilesMod; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import net.trafficlunar.optionsprofiles.profiles.Profiles; import java.io.BufferedReader; import java.io.BufferedWriter; diff --git a/common/src/main/java/net/trafficlunar/optionsprofiles/gui/ProfilesScreen.java b/common/src/main/java/net/trafficlunar/optionsprofiles/gui/ProfilesScreen.java index dd5ce20..ee97d97 100644 --- a/common/src/main/java/net/trafficlunar/optionsprofiles/gui/ProfilesScreen.java +++ b/common/src/main/java/net/trafficlunar/optionsprofiles/gui/ProfilesScreen.java @@ -22,6 +22,13 @@ public class ProfilesScreen extends OptionsSubScreen { protected void addContents() { this.layout.setHeaderHeight(24); this.profilesList = this.layout.addToContents(new ProfilesList(this, this.minecraft)); + + this.addRenderableWidget(Button.builder( + Component.translatable("gui.optionsprofiles.settings-button"), + (button) -> this.minecraft.setScreen(new SettingsScreen(this))) + .width(75) + .pos(1, 1) + .build()); } protected void addFooter() { diff --git a/common/src/main/java/net/trafficlunar/optionsprofiles/gui/SettingsScreen.java b/common/src/main/java/net/trafficlunar/optionsprofiles/gui/SettingsScreen.java new file mode 100644 index 0000000..737a9c1 --- /dev/null +++ b/common/src/main/java/net/trafficlunar/optionsprofiles/gui/SettingsScreen.java @@ -0,0 +1,73 @@ +package net.trafficlunar.optionsprofiles.gui; + +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.CycleButton; +import net.minecraft.client.gui.components.StringWidget; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.layouts.HeaderAndFooterLayout; +import net.minecraft.client.gui.layouts.LayoutSettings; +import net.minecraft.client.gui.layouts.LinearLayout; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.trafficlunar.optionsprofiles.OptionsProfilesMod; + +public class SettingsScreen extends Screen { + private final Screen lastScreen; + private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 24, 33); + + public SettingsScreen(Screen lastScreen) { + super(Component.translatable("gui.optionsprofiles.settings-menu")); + this.lastScreen = lastScreen; + } + + protected void init() { + LinearLayout linearLayoutHeader = this.layout.addToHeader(LinearLayout.vertical()); + linearLayoutHeader.addChild(new StringWidget(this.title, this.font), LayoutSettings::alignHorizontallyCenter); + + LinearLayout linearLayoutContent = this.layout.addToContents(LinearLayout.horizontal().spacing(12), LayoutSettings::alignHorizontallyCenter); + CycleButton showProfilesButtonButton = CycleButton.onOffBuilder(OptionsProfilesMod.config().shouldShowProfilesButton()).displayOnlyValue().create(this.width / 2 + 60, 100, 44, 20, Component.empty(), (button, boolean_) -> { + // If toggled to true + if (boolean_) { + button.setMessage(button.getMessage().copy().withStyle(ChatFormatting.GREEN)); // Set the button's color to green + } else { + button.setMessage(button.getMessage().copy().withStyle(ChatFormatting.RED)); // Set the button's color to red + } + + OptionsProfilesMod.config().setShowProfilesButton(boolean_); + }); + + showProfilesButtonButton.setTooltip(Tooltip.create(Component.translatable("gui.optionsprofiles.show-profiles-button.tooltip"))); + + // Set color on first init + if (OptionsProfilesMod.config().shouldShowProfilesButton()) { + showProfilesButtonButton.setMessage(showProfilesButtonButton.getMessage().copy().withStyle(ChatFormatting.GREEN)); // Set the button's color to green + } else { + showProfilesButtonButton.setMessage(showProfilesButtonButton.getMessage().copy().withStyle(ChatFormatting.RED)); // Set the button's color to red + } + + linearLayoutContent.addChild(new StringWidget(Component.translatable("gui.optionsprofiles.show-profiles-button"), this.font), LayoutSettings::alignVerticallyMiddle); + linearLayoutContent.addChild(showProfilesButtonButton); + + this.layout.addToFooter( + Button.builder( + CommonComponents.GUI_DONE, + (button) -> this.onClose()) + .width(200) + .build() + ); + + this.layout.visitWidgets(this::addRenderableWidget); + this.repositionElements(); + } + + protected void repositionElements() { + this.layout.arrangeElements(); + } + + public void onClose() { + this.minecraft.setScreen(this.lastScreen); + OptionsProfilesMod.config().save(); + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/optionsprofiles/lang/en_us.json b/common/src/main/resources/assets/optionsprofiles/lang/en_us.json index e3b4a31..0a01b06 100644 --- a/common/src/main/resources/assets/optionsprofiles/lang/en_us.json +++ b/common/src/main/resources/assets/optionsprofiles/lang/en_us.json @@ -14,5 +14,10 @@ "gui.optionsprofiles.options-toggle": "Select options to toggle", "gui.optionsprofiles.options-toggle.tooltip": "Select the options you want to load in this profile", "gui.optionsprofiles.all-on": "All ON", - "gui.optionsprofiles.all-off": "All OFF" + "gui.optionsprofiles.all-off": "All OFF", + + "gui.optionsprofiles.settings-button": "Settings", + "gui.optionsprofiles.settings-menu": "Options Profiles Settings", + "gui.optionsprofiles.show-profiles-button": "Show Profiles Button", + "gui.optionsprofiles.show-profiles-button.tooltip": "Toggle to remove the profiles button in Options. Access profiles through /optionsprofiles." } \ No newline at end of file