Skip to content

Commit f371188

Browse files
committed
feat: presets
1 parent f50b3ce commit f371188

File tree

5 files changed

+246
-2
lines changed

5 files changed

+246
-2
lines changed

src/main/java/dev/dfonline/codeclient/CodeClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import dev.dfonline.codeclient.dev.overlay.ActionViewer;
2727
import dev.dfonline.codeclient.dev.overlay.CPUDisplay;
2828
import dev.dfonline.codeclient.dev.overlay.ChestPeeker;
29+
import dev.dfonline.codeclient.config.preset.ConfigPresetScreen;
2930
import dev.dfonline.codeclient.hypercube.actiondump.ActionDump;
3031
import dev.dfonline.codeclient.location.*;
3132
import dev.dfonline.codeclient.switcher.ScopeSwitcher;
@@ -53,6 +54,7 @@
5354
import net.minecraft.client.gui.screen.ChatScreen;
5455
import net.minecraft.client.gui.screen.GameMenuScreen;
5556
import net.minecraft.client.gui.screen.Screen;
57+
import net.minecraft.client.gui.screen.TitleScreen;
5658
import net.minecraft.client.gui.screen.ingame.HandledScreen;
5759
import net.minecraft.client.render.BlockRenderLayer;
5860
import net.minecraft.client.render.RenderLayer;
@@ -193,6 +195,10 @@ public void onInitializeClient() {
193195
ScreenKeyboardEvents.allowKeyRelease(screen).register((screen1, key, scancode, modifiers) -> !CodeClient.onKeyReleased(key, scancode, modifiers));
194196
ScreenMouseEvents.allowMouseClick(screen).register((screen1, mouseX, mouseY, button) -> !CodeClient.onMouseClicked(mouseX, mouseY, button));
195197
ScreenMouseEvents.allowMouseScroll(screen).register((screen1, mouseX, mouseY, horizontalAmount, verticalAmount) -> !CodeClient.onMouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount));
198+
199+
if (!Config.getConfig().HasSelectedPreset && screen instanceof TitleScreen) {
200+
client.setScreen(new ConfigPresetScreen(screen));
201+
}
196202
});
197203

198204
try {

src/main/java/dev/dfonline/codeclient/config/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class Config {
9595
public int MiniMessageTagColor = 0x808080;
9696
public boolean StateSwitcher = true;
9797
public boolean SpeedSwitcher = true;
98+
public boolean HasSelectedPreset = false;
9899

99100
public Config() {
100101
}
@@ -182,6 +183,7 @@ public void save() {
182183
object.addProperty("HighlightExpressions", HighlightExpressions);
183184
object.addProperty("HighlightMiniMessage", HighlightMiniMessage);
184185
object.addProperty("MiniMessageTagColor", MiniMessageTagColor);
186+
object.addProperty("HasSelectedPreset", HasSelectedPreset);
185187

186188
FileManager.writeConfig(object.toString());
187189
} catch (Exception e) {
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package dev.dfonline.codeclient.config.preset;
2+
3+
import dev.dfonline.codeclient.config.Config;
4+
5+
import java.util.function.Consumer;
6+
7+
public enum ConfigPreset {
8+
9+
MINIMAL(config -> {
10+
config.NoClipEnabled = false;
11+
config.PlaceOnAir = false;
12+
config.CodeClientAPI = true;
13+
config.CustomBlockBreaking = false;
14+
config.CustomBlockInteractions = false;
15+
config.CustomTagInteraction = false;
16+
config.AutoFly = false;
17+
config.CodeLayerInteractionMode = Config.LayerInteractionMode.OFF;
18+
config.RecentChestInsert = false;
19+
config.ChestPeeker = false;
20+
config.ReportBrokenBlock = false;
21+
config.ScopeSwitcher = false;
22+
config.TeleportUp = false;
23+
config.TeleportDown = false;
24+
config.SignPeeker = false;
25+
config.CustomCodeChest = Config.CustomChestMenuType.OFF;
26+
config.AdvancedMiddleClick = false;
27+
config.DevForBuild = false;
28+
config.ChatEditsVars = true;
29+
config.InsertOverlay = false;
30+
config.ParameterGhosts = false;
31+
config.ActionViewer = true;
32+
config.RecentValues = 0;
33+
config.ValueDetails = true;
34+
config.PhaseToggle = false;
35+
config.DestroyItemResetMode = Config.DestroyItemReset.OFF;
36+
config.ShowVariableScopeBelowName = true;
37+
config.CPUDisplay = true;
38+
config.CPUDisplayCorner = Config.CPUDisplayCornerOption.TOP_LEFT;
39+
config.HideScopeChangeMessages = true;
40+
config.HighlighterEnabled = true;
41+
config.HighlightExpressions = true;
42+
config.HighlightMiniMessage = true;
43+
config.StateSwitcher = false;
44+
config.SpeedSwitcher = false;
45+
}),
46+
BASIC(config ->{
47+
config.NoClipEnabled = false;
48+
config.PlaceOnAir = false;
49+
config.CodeClientAPI = true;
50+
config.CustomBlockInteractions = false;
51+
config.CustomTagInteraction = true;
52+
config.CodeLayerInteractionMode = Config.LayerInteractionMode.AUTO;
53+
config.RecentChestInsert = true;
54+
config.ChestPeeker = true;
55+
config.ScopeSwitcher = true;
56+
config.TeleportUp = false;
57+
config.TeleportDown = false;
58+
config.SignPeeker = true;
59+
config.CustomCodeChest = Config.CustomChestMenuType.OFF;
60+
config.AdvancedMiddleClick = false;
61+
config.ChatEditsVars = true;
62+
config.InsertOverlay = false;
63+
config.ParameterGhosts = false;
64+
config.ActionViewer = true;
65+
config.ValueDetails = true;
66+
config.PhaseToggle = true;
67+
config.DestroyItemResetMode = Config.DestroyItemReset.OFF;
68+
config.ShowVariableScopeBelowName = true;
69+
config.CPUDisplay = true;
70+
config.CPUDisplayCorner = Config.CPUDisplayCornerOption.TOP_LEFT;
71+
config.HideScopeChangeMessages = true;
72+
config.HighlighterEnabled = true;
73+
config.HighlightExpressions = true;
74+
config.HighlightMiniMessage = true;
75+
config.StateSwitcher = true;
76+
config.SpeedSwitcher = true;
77+
}),
78+
FULL(config -> {
79+
config.NoClipEnabled = true;
80+
config.CodeClientAPI = true;
81+
config.CustomBlockInteractions = true;
82+
config.CustomTagInteraction = true;
83+
config.CodeLayerInteractionMode = Config.LayerInteractionMode.AUTO;
84+
config.RecentChestInsert = true;
85+
config.ChestPeeker = true;
86+
config.ScopeSwitcher = true;
87+
config.TeleportUp = true;
88+
config.TeleportDown = true;
89+
config.SignPeeker = true;
90+
config.CustomCodeChest = Config.CustomChestMenuType.OFF;
91+
config.ChatEditsVars = true;
92+
config.InsertOverlay = true;
93+
config.ParameterGhosts = true;
94+
config.ActionViewer = true;
95+
config.ValueDetails = true;
96+
config.PhaseToggle = true;
97+
config.DestroyItemResetMode = Config.DestroyItemReset.OFF;
98+
config.ShowVariableScopeBelowName = true;
99+
config.CPUDisplay = true;
100+
config.CPUDisplayCorner = Config.CPUDisplayCornerOption.TOP_LEFT;
101+
config.HideScopeChangeMessages = true;
102+
config.HighlighterEnabled = true;
103+
config.HighlightExpressions = true;
104+
config.HighlightMiniMessage = true;
105+
config.StateSwitcher = true;
106+
config.SpeedSwitcher = true;
107+
})
108+
;
109+
110+
private final Consumer<Config> apply;
111+
ConfigPreset(Consumer<Config> apply) {
112+
this.apply = apply;
113+
}
114+
115+
public Consumer<Config> getApply() {
116+
return apply;
117+
}
118+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package dev.dfonline.codeclient.config.preset;
2+
3+
import dev.dfonline.codeclient.config.Config;
4+
import net.minecraft.client.gui.screen.Screen;
5+
import net.minecraft.client.gui.widget.ButtonWidget;
6+
import net.minecraft.client.gui.tooltip.Tooltip;
7+
import net.minecraft.text.Text;
8+
import net.minecraft.client.gui.DrawContext;
9+
10+
public class ConfigPresetScreen extends Screen {
11+
12+
private final Screen parent;
13+
14+
public ConfigPresetScreen(final Screen parent) {
15+
super(Text.translatable("screen.codeclient.config_preset.title"));
16+
this.parent = parent;
17+
}
18+
19+
@Override
20+
protected void init() {
21+
super.init();
22+
23+
final int centerX = this.width / 2;
24+
final int baseY = this.height / 3 + 20;
25+
final int buttonWidth = 120;
26+
final int spacing = 10;
27+
28+
this.addDrawableChild(createPresetButton(
29+
"screen.codeclient.config_preset.minimal",
30+
"screen.codeclient.config_preset.minimal.tooltip",
31+
centerX - (buttonWidth + spacing) - buttonWidth / 2,
32+
baseY,
33+
ConfigPreset.MINIMAL
34+
));
35+
36+
this.addDrawableChild(createPresetButton(
37+
"screen.codeclient.config_preset.basic",
38+
"screen.codeclient.config_preset.basic.tooltip",
39+
centerX - buttonWidth / 2,
40+
baseY,
41+
ConfigPreset.BASIC
42+
));
43+
44+
this.addDrawableChild(createPresetButton(
45+
"screen.codeclient.config_preset.full",
46+
"screen.codeclient.config_preset.full.tooltip",
47+
centerX + (buttonWidth + spacing) - buttonWidth / 2,
48+
baseY,
49+
ConfigPreset.FULL
50+
));
51+
}
52+
53+
private ButtonWidget createPresetButton(final String translationKey, final String tooltipKey, final int x, final int y, final ConfigPreset preset) {
54+
return ButtonWidget.builder(
55+
Text.translatable(translationKey),
56+
button -> applyPreset(preset)
57+
).size(120, 20)
58+
.position(x, y)
59+
.tooltip(Tooltip.of(Text.translatable(tooltipKey)))
60+
.build();
61+
}
62+
63+
private void applyPreset(final ConfigPreset preset) {
64+
final Config config = Config.getConfig();
65+
preset.getApply().accept(config);
66+
config.HasSelectedPreset = true;
67+
config.save();
68+
69+
if (this.client != null) {
70+
this.client.setScreen(this.parent);
71+
}
72+
}
73+
74+
@Override
75+
public void render(final DrawContext context, final int mouseX, final int mouseY, final float delta) {
76+
super.render(context, mouseX, mouseY, delta);
77+
78+
final int titleY = this.height / 6;
79+
final Text title = Text.translatable("screen.codeclient.config_preset.title");
80+
context.drawCenteredTextWithShadow(this.textRenderer, title, this.width / 2, titleY, 0xFFFFFFFF);
81+
82+
final boolean firstRun = !Config.getConfig().HasSelectedPreset;
83+
final Text mainSubtitle = firstRun
84+
? Text.translatable("screen.codeclient.config_preset.welcome.title")
85+
: Text.translatable("screen.codeclient.config_preset.subtitle");
86+
final Text secondarySubtitle = firstRun
87+
? Text.translatable("screen.codeclient.config_preset.welcome.subtitle")
88+
: Text.empty();
89+
90+
final int textY = titleY + 20;
91+
context.drawCenteredTextWithShadow(this.textRenderer, mainSubtitle, this.width / 2, textY, 0xFFA0E6FF);
92+
93+
if (!secondarySubtitle.getString().isEmpty()) {
94+
context.drawCenteredTextWithShadow(this.textRenderer, secondarySubtitle, this.width / 2, textY + 12, 0xFFA0E6FF);
95+
context.drawCenteredTextWithShadow(this.textRenderer, Text.translatable("screen.codeclient.config_preset.hover_hint"), this.width / 2, textY + 24, 0xFFCCCCCC);
96+
} else {
97+
context.drawCenteredTextWithShadow(this.textRenderer, Text.translatable("screen.codeclient.config_preset.hover_hint"), this.width / 2, textY + 12, 0xFFCCCCCC);
98+
}
99+
100+
if (!firstRun) {
101+
final Text warning = Text.translatable("screen.codeclient.config_preset.warning");
102+
context.drawCenteredTextWithShadow(this.textRenderer, warning, this.width / 2, this.height / 3, 0xFFFF5555);
103+
}
104+
}
105+
}

src/main/resources/assets/codeclient/lang/en_us.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,18 @@
331331
"codeclient.action.clearqueue.empty": "Command queue was empty!",
332332
"codeclient.config.advanced_middle_click": "Advanced Middle Click",
333333
"codeclient.config.advanced_middle_click.description": "When enabled, cloning items in inventories will add 1 to your cursor's stack instead of a full stack.",
334-
"codeclient.config.advanced_middle_click.description2": "Holding shift while cloning an item will instead give you a full stack."
335-
}
334+
"codeclient.config.advanced_middle_click.description2": "Holding shift while cloning an item will instead give you a full stack.",
335+
336+
"screen.codeclient.config_preset.title": "Config Preset",
337+
"screen.codeclient.config_preset.subtitle": "Select a config preset to apply it",
338+
"screen.codeclient.config_preset.warning": "Warning: Selecting a preset is irreversible",
339+
"screen.codeclient.config_preset.welcome.title": "Welcome to CodeClient!",
340+
"screen.codeclient.config_preset.welcome.subtitle": "For you to have the best experience, select the config preset that matches your needs!",
341+
"screen.codeclient.config_preset.minimal": "Minimal",
342+
"screen.codeclient.config_preset.basic": "Basic",
343+
"screen.codeclient.config_preset.full": "Full",
344+
"screen.codeclient.config_preset.minimal.tooltip": "A lightweight setup with essentials only. Keeps things close to vanilla.",
345+
"screen.codeclient.config_preset.basic.tooltip": "Balanced defaults recommended for most players.",
346+
"screen.codeclient.config_preset.full.tooltip": "All features enabled for power users. Most opinionated experience.",
347+
"screen.codeclient.config_preset.hover_hint": "(hover on buttons for explanation)"
348+
}

0 commit comments

Comments
 (0)