Continuation of commit 2f650bb (#20)

I keep forgetting to stage my files >:(
This commit is contained in:
axolotlmaid 2024-07-12 23:48:30 +01:00
parent 2f650bb6d4
commit fc411bac3c
8 changed files with 223 additions and 84 deletions

View file

@ -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.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.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(
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 - 50, this.height - 40, 100, 20, CommonComponents.GUI_DONE, (button) -> {
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);
}
}

View file

@ -26,11 +26,13 @@ import java.util.stream.Stream;
public class OptionsToggleList extends ContainerObjectSelectionList<OptionsToggleList.Entry> {
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<OptionsToggl
public class OptionEntry extends Entry {
private final Component optionKey;
private final Component optionValue;
private final CycleButton<Boolean> 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<String> optionsToLoad = profileConfiguration.getOptionsToLoad();
@ -101,9 +105,6 @@ public class OptionsToggleList extends ContainerObjectSelectionList<OptionsToggl
profileConfiguration.setOptionsToLoad(optionsToLoad);
});
// Set tooltip to the option value (e.g. "ao" will show "true")
// this.toggleButton.renderToolTip(Tooltip.create(Component.literal(optionValue)));
if (toggled) {
this.toggleButton.setMessage(this.toggleButton.getMessage().copy().withStyle(ChatFormatting.GREEN)); // Set the button's color to green
} else {
@ -123,6 +124,12 @@ public class OptionsToggleList extends ContainerObjectSelectionList<OptionsToggl
this.toggleButton.x = posX;
this.toggleButton.y = posY;
this.toggleButton.render(poseStack, mouseX, mouseY, tickDelta);
this.toggleButton.renderToolTip(poseStack, mouseX, mouseY);
// Set tooltip to the option value (e.g. "ao" will show "true") | even though it's non-existent in this version
if (this.toggleButton.isHoveredOrFocused()) {
optionsToggleScreen.renderTooltip(poseStack, optionValue, mouseX, mouseY);
}
}
public List<? extends GuiEventListener> children() {

View file

@ -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.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) {

View file

@ -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<ProfilesList.ProfileEntry> {
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<ProfilesList.Prof
public void refreshEntries() {
this.clearEntries();
Path profilesDirectory = Paths.get("options-profiles/");
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(profilesDirectory)) {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Profiles.PROFILES_DIRECTORY)) {
List<Path> 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<ProfilesList.Prof
}
public int getRowWidth() {
return super.getRowWidth() + 32;
return 340;
}
public class ProfileEntry extends ContainerObjectSelectionList.Entry<ProfilesList.ProfileEntry> {
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) -> {
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();
if (ProfileConfiguration.get(profileName.getString()).getOptionsToLoad().contains("resourcePacks")) {
minecraft.options.loadSelectedResourcePacks(minecraft.getResourcePackRepository());
minecraft.reloadResourcePacks();
}
minecraft.options.save();
button.active = false;
});
}
);
this.loadButton.active = !Profiles.isProfileLoaded(profileName);
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);
}

View file

@ -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) -> {
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.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);
}
}

View file

@ -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.addRenderableWidget(
new Button(
5,
5,
75,
20,
new TranslatableComponent("gui.optionsprofiles.profiles-menu"),
(button) -> {
this.minecraft.setScreen(new ProfilesScreen(this));
}));
}
)
);
}
}

View file

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

View file

@ -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;