feat: settings screen

This commit is contained in:
trafficlunar 2025-03-01 10:02:21 +00:00
parent aa09edda1b
commit aa206fc7e8
5 changed files with 88 additions and 4 deletions

View file

@ -4,7 +4,6 @@ import dev.architectury.event.events.common.CommandRegistrationEvent;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.commands.Commands; import net.minecraft.commands.Commands;
import net.trafficlunar.optionsprofiles.gui.ProfilesScreen; import net.trafficlunar.optionsprofiles.gui.ProfilesScreen;
import net.trafficlunar.optionsprofiles.profiles.OptionsProfilesModConfiguration;
import net.trafficlunar.optionsprofiles.profiles.Profiles; import net.trafficlunar.optionsprofiles.profiles.Profiles;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View file

@ -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.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import net.trafficlunar.optionsprofiles.profiles.Profiles;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;

View file

@ -22,6 +22,13 @@ public class ProfilesScreen extends OptionsSubScreen {
protected void addContents() { protected void addContents() {
this.layout.setHeaderHeight(24); this.layout.setHeaderHeight(24);
this.profilesList = this.layout.addToContents(new ProfilesList(this, this.minecraft)); 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() { protected void addFooter() {

View file

@ -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<Boolean> 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();
}
}

View file

@ -14,5 +14,10 @@
"gui.optionsprofiles.options-toggle": "Select options to toggle", "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.options-toggle.tooltip": "Select the options you want to load in this profile",
"gui.optionsprofiles.all-on": "All ON", "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."
} }