Add checkbox in edit profile screen
This commit is contained in:
parent
b6480365ad
commit
0b0a93dca7
10 changed files with 111 additions and 46 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
package com.axolotlmaid.optionsprofiles.gui;
|
package com.axolotlmaid.optionsprofiles.gui;
|
||||||
|
|
||||||
|
import com.axolotlmaid.optionsprofiles.profiles.ProfileConfiguration;
|
||||||
import com.axolotlmaid.optionsprofiles.profiles.Profiles;
|
import com.axolotlmaid.optionsprofiles.profiles.Profiles;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
|
import net.minecraft.client.gui.components.Checkbox;
|
||||||
import net.minecraft.client.gui.components.EditBox;
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.CommonComponents;
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
|
|
@ -14,6 +16,7 @@ public class EditProfileScreen extends Screen {
|
||||||
private final Component profileName;
|
private final Component profileName;
|
||||||
|
|
||||||
private EditBox profileNameEdit;
|
private EditBox profileNameEdit;
|
||||||
|
private Checkbox keybindingsOnlyCheckbox;
|
||||||
|
|
||||||
public EditProfileScreen(Screen screen, Component profileName) {
|
public EditProfileScreen(Screen screen, Component profileName) {
|
||||||
super(Component.literal(Component.translatable("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString()));
|
super(Component.literal(Component.translatable("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString()));
|
||||||
|
|
@ -22,28 +25,65 @@ public class EditProfileScreen extends Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
ProfileConfiguration profileConfiguration = ProfileConfiguration.get(profileName.getString());
|
||||||
|
|
||||||
this.profileNameEdit = new EditBox(this.font, this.width / 2 - 102, 116, 204, 20, Component.empty());
|
this.profileNameEdit = new EditBox(this.font, this.width / 2 - 102, 116, 204, 20, Component.empty());
|
||||||
this.profileNameEdit.setValue(profileName.getString());
|
this.profileNameEdit.setValue(profileName.getString());
|
||||||
this.addWidget(this.profileNameEdit);
|
this.addWidget(this.profileNameEdit);
|
||||||
|
|
||||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.overwrite-options"), (button) -> {
|
this.keybindingsOnlyCheckbox = Checkbox.builder(
|
||||||
|
Component.translatable("gui.optionsprofiles.keybindings-only"),
|
||||||
|
this.font)
|
||||||
|
.pos(5, this.height - 45)
|
||||||
|
.selected(profileConfiguration.isKeybindingsOnly())
|
||||||
|
.build();
|
||||||
|
this.addRenderableWidget(this.keybindingsOnlyCheckbox);
|
||||||
|
|
||||||
|
this.addRenderableWidget(
|
||||||
|
Button.builder(
|
||||||
|
Component.translatable("gui.optionsprofiles.overwrite-options"),
|
||||||
|
(button) -> {
|
||||||
Profiles.writeProfile(profileName.getString(), true);
|
Profiles.writeProfile(profileName.getString(), true);
|
||||||
this.minecraft.setScreen(this.lastScreen);
|
this.minecraft.setScreen(this.lastScreen);
|
||||||
}).size(100, 20).pos(this.width / 2 - 50, 145).build());
|
})
|
||||||
|
.size(100, 20)
|
||||||
|
.pos(this.width / 2 - 50, 145)
|
||||||
|
.build());
|
||||||
|
|
||||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.rename-profile"), (button) -> {
|
this.addRenderableWidget(
|
||||||
|
Button.builder(
|
||||||
|
Component.translatable("gui.optionsprofiles.rename-profile"),
|
||||||
|
(button) -> {
|
||||||
Profiles.renameProfile(profileName.getString(), this.profileNameEdit.getValue());
|
Profiles.renameProfile(profileName.getString(), this.profileNameEdit.getValue());
|
||||||
this.minecraft.setScreen(new EditProfileScreen(lastScreen, Component.literal(this.profileNameEdit.getValue())));
|
this.minecraft.setScreen(new EditProfileScreen(lastScreen, Component.literal(this.profileNameEdit.getValue())));
|
||||||
}).size(100, 20).pos(this.width / 2 - 50, 166).build());
|
})
|
||||||
|
.size(100, 20)
|
||||||
|
.pos(this.width / 2 - 50, 166)
|
||||||
|
.build());
|
||||||
|
|
||||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button) -> {
|
this.addRenderableWidget(
|
||||||
|
Button.builder(
|
||||||
|
Component.translatable("gui.optionsprofiles.delete-profile")
|
||||||
|
.withStyle(ChatFormatting.RED),
|
||||||
|
(button) -> {
|
||||||
Profiles.deleteProfile(profileName.getString());
|
Profiles.deleteProfile(profileName.getString());
|
||||||
this.minecraft.setScreen(this.lastScreen);
|
this.minecraft.setScreen(this.lastScreen);
|
||||||
}).size(100, 20).pos(5, this.height - 25).build());
|
})
|
||||||
|
.size(100, 20)
|
||||||
|
.pos(5, this.height - 25)
|
||||||
|
.build());
|
||||||
|
|
||||||
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> {
|
this.addRenderableWidget(
|
||||||
|
Button.builder(
|
||||||
|
CommonComponents.GUI_DONE,
|
||||||
|
(button) -> {
|
||||||
|
profileConfiguration.setKeybindingsOnly(keybindingsOnlyCheckbox.selected());
|
||||||
|
profileConfiguration.save();
|
||||||
this.minecraft.setScreen(this.lastScreen);
|
this.minecraft.setScreen(this.lastScreen);
|
||||||
}).size(100, 20).pos(this.width / 2 - 50, this.height - 40).build());
|
})
|
||||||
|
.size(100, 20)
|
||||||
|
.pos(this.width / 2 - 50, this.height - 40)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,15 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
|
||||||
ProfileEntry(Component profileName) {
|
ProfileEntry(Component profileName) {
|
||||||
this.profileName = profileName;
|
this.profileName = profileName;
|
||||||
|
|
||||||
this.editButton = Button.builder(Component.translatable("gui.optionsprofiles.edit-profile"), (button) -> {
|
this.editButton = Button.builder(
|
||||||
minecraft.setScreen(new EditProfileScreen(profilesScreen, profileName));
|
Component.translatable("gui.optionsprofiles.edit-profile"),
|
||||||
}).size(75, 20).createNarration((supplier) -> Component.translatable("gui.optionsprofiles.edit-profile")).build();
|
(button) -> minecraft.setScreen(new EditProfileScreen(profilesScreen, profileName)))
|
||||||
|
.size(75, 20)
|
||||||
|
.build();
|
||||||
|
|
||||||
this.loadButton = Button.builder(Component.translatable("gui.optionsprofiles.load-profile"), (button) -> {
|
this.loadButton = Button.builder(
|
||||||
|
Component.translatable("gui.optionsprofiles.load-profile"),
|
||||||
|
(button) -> {
|
||||||
Profiles.loadProfile(profileName.getString());
|
Profiles.loadProfile(profileName.getString());
|
||||||
|
|
||||||
minecraft.options.load();
|
minecraft.options.load();
|
||||||
|
|
@ -73,7 +77,9 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
|
||||||
minecraft.options.save();
|
minecraft.options.save();
|
||||||
|
|
||||||
button.active = false;
|
button.active = false;
|
||||||
}).size(75, 20).createNarration((supplier) -> Component.translatable("gui.optionsprofiles.load-profile")).build();
|
})
|
||||||
|
.size(75, 20)
|
||||||
|
.build();
|
||||||
|
|
||||||
this.loadButton.active = !Profiles.isProfileLoaded(profileName.getString());
|
this.loadButton.active = !Profiles.isProfileLoaded(profileName.getString());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,24 @@ public class ProfilesScreen extends Screen {
|
||||||
this.profilesList = new ProfilesList(this, this.minecraft);
|
this.profilesList = new ProfilesList(this, this.minecraft);
|
||||||
this.addWidget(this.profilesList);
|
this.addWidget(this.profilesList);
|
||||||
|
|
||||||
// buttons
|
this.addRenderableWidget(
|
||||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.save-current-options"), (button) -> {
|
Button.builder(
|
||||||
|
Component.translatable("gui.optionsprofiles.save-current-options"),
|
||||||
|
(button) -> {
|
||||||
Profiles.createProfile();
|
Profiles.createProfile();
|
||||||
this.profilesList.refreshEntries();
|
this.profilesList.refreshEntries();
|
||||||
}).size(150, 20).pos(this.width / 2 - 155, this.height - 29).build());
|
})
|
||||||
|
.size(150, 20)
|
||||||
|
.pos(this.width / 2 - 155, this.height - 29)
|
||||||
|
.build());
|
||||||
|
|
||||||
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> {
|
this.addRenderableWidget(
|
||||||
this.minecraft.setScreen(this.lastScreen);
|
Button.builder(
|
||||||
}).size(150, 20).pos(this.width / 2 + 5, this.height - 29).build());
|
CommonComponents.GUI_DONE,
|
||||||
|
(button) -> this.minecraft.setScreen(this.lastScreen))
|
||||||
|
.size(150, 20)
|
||||||
|
.pos(this.width / 2 + 5, this.height - 29)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,12 @@ public class MixinOptionsScreen extends Screen {
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "init")
|
@Inject(at = @At("HEAD"), method = "init")
|
||||||
private void init(CallbackInfo info) {
|
private void init(CallbackInfo info) {
|
||||||
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.profiles-menu"), (button) -> {
|
this.addRenderableWidget(
|
||||||
this.minecraft.setScreen(new ProfilesScreen(this));
|
Button.builder(
|
||||||
}).width(100).pos(5, 5).build());
|
Component.translatable("gui.optionsprofiles.profiles-menu"),
|
||||||
|
(button) -> this.minecraft.setScreen(new ProfilesScreen(this)))
|
||||||
|
.width(100)
|
||||||
|
.pos(5, 5)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,15 +12,13 @@ import java.nio.file.Path;
|
||||||
|
|
||||||
public class ProfileConfiguration {
|
public class ProfileConfiguration {
|
||||||
private static final Path profilesDirectory = Profiles.PROFILES_DIRECTORY;
|
private static final Path profilesDirectory = Profiles.PROFILES_DIRECTORY;
|
||||||
|
private static Path configurationFile;
|
||||||
|
|
||||||
private boolean keybindingsOnly = false;
|
private boolean keybindingsOnly = false;
|
||||||
|
|
||||||
public ProfileConfiguration save(String profileName) {
|
public ProfileConfiguration save() {
|
||||||
ProfileConfiguration configuration = new ProfileConfiguration();
|
ProfileConfiguration configuration = new ProfileConfiguration();
|
||||||
|
|
||||||
Path profile = profilesDirectory.resolve(profileName);
|
|
||||||
Path configurationFile = profile.resolve("configuration.json");
|
|
||||||
|
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.create();
|
.create();
|
||||||
|
|
@ -38,7 +36,11 @@ public class ProfileConfiguration {
|
||||||
ProfileConfiguration configuration = new ProfileConfiguration();
|
ProfileConfiguration configuration = new ProfileConfiguration();
|
||||||
|
|
||||||
Path profile = profilesDirectory.resolve(profileName);
|
Path profile = profilesDirectory.resolve(profileName);
|
||||||
Path configurationFile = profile.resolve("configuration.json");
|
configurationFile = profile.resolve("configuration.json");
|
||||||
|
|
||||||
|
if (Files.notExists(configurationFile)) {
|
||||||
|
configuration.save();
|
||||||
|
}
|
||||||
|
|
||||||
try (BufferedReader reader = Files.newBufferedReader(configurationFile)) {
|
try (BufferedReader reader = Files.newBufferedReader(configurationFile)) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,13 @@ public class Profiles {
|
||||||
paths.filter(Files::isDirectory)
|
paths.filter(Files::isDirectory)
|
||||||
.forEach(path -> {
|
.forEach(path -> {
|
||||||
Path configurationFile = path.resolve("configuration.json");
|
Path configurationFile = path.resolve("configuration.json");
|
||||||
if (!Files.exists(configurationFile)) {
|
if (Files.notExists(configurationFile)) {
|
||||||
String profileName = path.getFileName().toString();
|
String profileName = path.getFileName().toString();
|
||||||
|
|
||||||
// Create configuration.json
|
// Create configuration.json
|
||||||
new ProfileConfiguration().save(profileName);
|
ProfileConfiguration.get(profileName);
|
||||||
|
|
||||||
OptionsProfilesMod.LOGGER.warn("[Profile '{}']: Profile updated", profileName);
|
OptionsProfilesMod.LOGGER.warn("[Profile '{}']: Profile configuration added", profileName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
@ -89,7 +89,7 @@ public class Profiles {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Create configuration.json
|
// Create configuration.json
|
||||||
new ProfileConfiguration().save(profileName);
|
ProfileConfiguration.get(profileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
copyOptionFile(profile, OPTIONS_FILE);
|
copyOptionFile(profile, OPTIONS_FILE);
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,6 @@
|
||||||
"gui.optionsprofiles.profile-name-text": "Profile Name",
|
"gui.optionsprofiles.profile-name-text": "Profile Name",
|
||||||
"gui.optionsprofiles.overwrite-options": "Overwrite",
|
"gui.optionsprofiles.overwrite-options": "Overwrite",
|
||||||
"gui.optionsprofiles.rename-profile": "Rename",
|
"gui.optionsprofiles.rename-profile": "Rename",
|
||||||
|
"gui.optionsprofiles.keybindings-only": "Keybindings Only",
|
||||||
"gui.optionsprofiles.delete-profile": "Delete"
|
"gui.optionsprofiles.delete-profile": "Delete"
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
"gui.optionsprofiles.profile-name-text": "Имя профиля",
|
"gui.optionsprofiles.profile-name-text": "Имя профиля",
|
||||||
"gui.optionsprofiles.overwrite-options": "Перезаписать",
|
"gui.optionsprofiles.overwrite-options": "Перезаписать",
|
||||||
"gui.optionsprofiles.rename-profile": "Переименовать",
|
"gui.optionsprofiles.rename-profile": "Переименовать",
|
||||||
|
"gui.optionsprofiles.keybindings-only": "Только элементы управления",
|
||||||
"gui.optionsprofiles.delete-profile": "удалить",
|
"gui.optionsprofiles.delete-profile": "удалить",
|
||||||
|
|
||||||
"modmenu.summaryTranslation.options-profiles": "Cохраняйте и загружайте профили настроек, не выходя из игры.",
|
"modmenu.summaryTranslation.options-profiles": "Cохраняйте и загружайте профили настроек, не выходя из игры.",
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
"gui.optionsprofiles.profile-name-text": "Профиль исеме",
|
"gui.optionsprofiles.profile-name-text": "Профиль исеме",
|
||||||
"gui.optionsprofiles.overwrite-options": "перезапись",
|
"gui.optionsprofiles.overwrite-options": "перезапись",
|
||||||
"gui.optionsprofiles.rename-profile": "переименовывать",
|
"gui.optionsprofiles.rename-profile": "переименовывать",
|
||||||
|
"gui.optionsprofiles.keybindings-only": "Контрольләр генә",
|
||||||
"gui.optionsprofiles.delete-profile": "бетерү",
|
"gui.optionsprofiles.delete-profile": "бетерү",
|
||||||
|
|
||||||
"modmenu.summaryTranslation.options-profiles": "Хәзерге көйләүләр профильләрен саклагыз һәм уеннан чыгусыз йөкләгез.",
|
"modmenu.summaryTranslation.options-profiles": "Хәзерге көйләүләр профильләрен саклагыз һәм уеннан чыгусыз йөкләгез.",
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,6 @@
|
||||||
"gui.optionsprofiles.profile-name-text": "预设名",
|
"gui.optionsprofiles.profile-name-text": "预设名",
|
||||||
"gui.optionsprofiles.overwrite-options": "覆盖",
|
"gui.optionsprofiles.overwrite-options": "覆盖",
|
||||||
"gui.optionsprofiles.rename-profile": "重命名",
|
"gui.optionsprofiles.rename-profile": "重命名",
|
||||||
|
"gui.optionsprofiles.keybindings-only": "仅按键绑定",
|
||||||
"gui.optionsprofiles.delete-profile": "删除"
|
"gui.optionsprofiles.delete-profile": "删除"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue