Skip to content

Commit

Permalink
feature: toggle all option (#17)
Browse files Browse the repository at this point in the history
* upgradle: speedrunapi v1.0

* feature: option to toggle all standardsettings on or off

---------

Co-authored-by: contaria <98704937+KingContaria@users.noreply.github.com>
  • Loading branch information
tildejustin and KingContaria authored Aug 17, 2024
1 parent 1b1fa7b commit c201f4b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {

// SpeedrunAPI
// check for the latest versions at https://jitpack.io/#kingcontaria/speedrunapi
modImplementation "com.github.KingContaria:SpeedrunAPI:0fe52454e2"
modImplementation "com.github.KingContaria:SpeedrunAPI:1.0"

// check for the latest versions at https://jitpack.io/#Minecraft-Java-Edition-Speedrunning/sodium
modCompileOnly "com.github.Minecraft-Java-Edition-Speedrunning:sodium:7e4905f134"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.mojang.blaze3d.platform.GlStateManager;
import me.contaria.standardsettings.options.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.screen.options.LanguageOptionsScreen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
Expand All @@ -30,6 +33,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
Expand All @@ -56,6 +60,9 @@ public class StandardSettingsConfig implements SpeedrunConfig {

public boolean toggleStandardSettings = true;

@SuppressWarnings("unused")
public boolean toggleAll = true;

@Config.Category("f3")
public boolean autoF3Esc = false;

Expand Down Expand Up @@ -261,7 +268,7 @@ private StringOptionStandardSetting register(String id, String category, Functio
return this.register(new StringOptionStandardSetting(id, category, this.options, getter, setter, getText, createMainWidget));
}

private <T extends StandardSetting<?>> T register(T standardSetting) {
private <T extends StandardSetting<?>> T register(T standardSetting) {
this.standardSettings.add(standardSetting);
return standardSetting;
}
Expand Down Expand Up @@ -293,6 +300,46 @@ public Map<String, SpeedrunOption<?>> init() throws ReflectiveOperationException
return options;
}

private void toggleAll(boolean enabled) {
for (StandardSetting<?> setting : StandardSettings.config.standardSettings) {
setting.setEnabled(enabled);
}
for (StandardSetting<?> setting : StandardSettings.config.standardSettingsOnWorldJoin) {
setting.setEnabled(enabled);
}
}

private void confirmToggleAll(ButtonWidget button) {
MinecraftClient client = MinecraftClient.getInstance();
Screen screen = client.currentScreen;
client.openScreen(new ConfirmScreen(
confirmed -> {
if (confirmed) {
this.toggleAll = !this.toggleAll;
this.toggleAll(this.toggleAll);
}
client.openScreen(screen);
},
new TranslatableText("speedrunapi.config.standardsettings.option.toggleAll"),
new TranslatableText("speedrunapi.config.standardsettings.option.toggleAll.description")
.append(" ")
.append(new TranslatableText("speedrunapi.config.standardsettings.option.toggleAll.confirm")),
ScreenTexts.PROCEED,
ScreenTexts.CANCEL
));
}

@Override
public @Nullable SpeedrunOption<?> parseField(Field field, SpeedrunConfig config, String... idPrefix) {
if ("toggleAll".equals(field.getName())) {
return new SpeedrunConfigAPI.CustomOption.Builder<Boolean>(this, this, field, idPrefix)
.createWidget((option, innerConfig, configStorage, optionField) ->
new ButtonWidget(0, 0, 150, 20, ScreenTexts.getToggleText(!option.get()), this::confirmToggleAll)
).build();
}
return SpeedrunConfig.super.parseField(field, config, idPrefix);
}

@Override
public void finishInitialization(SpeedrunConfigContainer<?> container) {
this.configContainer = container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public boolean isEnabled() {
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public boolean toggleEnabled() {
return this.enabled = !this.enabled;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/assets/standardsettings/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"speedrunapi.config.standardsettings.option.language": "Language",
"speedrunapi.config.standardsettings.option.pieDirectory": "Pie Directory",

"speedrunapi.config.standardsettings.option.toggleStandardSettings": "Toggle StandardSettings",
"speedrunapi.config.standardsettings.option.toggleStandardSettings": "Use StandardSettings",
"speedrunapi.config.standardsettings.option.toggleAll": "Toggle all",
"speedrunapi.config.standardsettings.option.toggleAll.description": "This will enable / disable all toggleable options.",
"speedrunapi.config.standardsettings.option.toggleAll.confirm": "If you don't want to do this or understand what this means, please press Cancel.",
"speedrunapi.config.standardsettings.option.autoF3Esc": "F3 Pause on World Load",
"speedrunapi.config.standardsettings.option.autoF3Esc.description": "Automatically opens the F3 Pause Screen on WorldPreview and when joining a world while the game is unfocused.\nMake sure Pause On Lost Focus is disabled for this option to work properly!",
"speedrunapi.config.standardsettings.option.firstAutoF3EscDelay": "First World F3 Pause Delay",
Expand Down

0 comments on commit c201f4b

Please sign in to comment.