Skip to content

Commit

Permalink
Add LTSX options menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Chai committed Jun 24, 2024
1 parent cd3e4a2 commit df49c11
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.gradle/
/run/
/build/
out/production/Davinci.main/link/botwmcs/davinci/client/gui/screen/DemoScreen.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package link.botwmcs.davinci.client.gui.screen.ltsx;

import link.botwmcs.davinci.client.gui.component.ColorButton;
import net.minecraft.client.Options;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.layouts.FrameLayout;
import net.minecraft.client.gui.layouts.GridLayout;
import net.minecraft.client.gui.screens.AccessibilityOptionsScreen;
import net.minecraft.client.gui.screens.ChatOptionsScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.SkinCustomizationScreen;
import net.minecraft.network.chat.Component;

import java.util.function.Supplier;

public class InterfaceOptionsScreen extends Screen {
private final Screen lastScreen;
private final Options options;

protected InterfaceOptionsScreen(Screen lastScreen, Options options) {
super(Component.literal("Interface Options Screen"));
this.lastScreen = lastScreen;
this.options = options;
}

@Override
protected void init() {
GridLayout gridLayout = new GridLayout();
gridLayout.defaultCellSetting().paddingHorizontal(5).paddingBottom(4).alignHorizontallyCenter();
GridLayout.RowHelper rowHelper = gridLayout.createRowHelper(2);
rowHelper.addChild(this.openScreenButton(Component.translatable("options.chat.title"), () -> new ChatOptionsScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(Component.translatable("options.skinCustomisation"), () -> new SkinCustomizationScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(Component.translatable("options.accessibility.title"), () -> new AccessibilityOptionsScreen(this, this.options)));


gridLayout.arrangeElements();
FrameLayout.alignInRectangle(gridLayout, 0, this.height / 6 - 12, this.width, this.height, 0.5f, 0.0f);
gridLayout.visitWidgets(this::addRenderableWidget);
super.init();
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
this.renderBackground(guiGraphics);
super.render(guiGraphics, mouseX, mouseY, delta);
}

@Override
public void onClose() {
this.minecraft.setScreen(this.lastScreen);
}

private Button openScreenButton(Component text, int color, Supplier<Screen> screenSupplier) {
return new ColorButton(0, 0, 150, 20, text, color, button -> this.minecraft.setScreen(screenSupplier.get()));
// return Button.builder(text, button -> this.minecraft.setScreen((Screen)screenSupplier.get())).build();
}

private Button openScreenButton(Component text, Supplier<Screen> screenSupplier) {
return this.openScreenButton(text, 0xFFFFFFFF, screenSupplier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package link.botwmcs.davinci.client.gui.screen.ltsx;

import link.botwmcs.davinci.client.gui.component.ColorButton;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.CycleButton;
import net.minecraft.client.gui.components.LockIconButton;
import net.minecraft.client.gui.layouts.*;
import net.minecraft.client.gui.screens.*;
import net.minecraft.client.gui.screens.controls.ControlsScreen;
import net.minecraft.client.gui.screens.packs.PackSelectionScreen;
import net.minecraft.client.gui.screens.telemetry.TelemetryInfoScreen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundChangeDifficultyPacket;
import net.minecraft.network.protocol.game.ServerboundLockDifficultyPacket;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.world.Difficulty;

import java.util.function.Supplier;

public class LtsxOptionsScreen extends Screen {
private static final Component SKIN_CUSTOMIZATION = Component.translatable("options.skinCustomisation");
private static final Component SOUNDS = Component.translatable("options.sounds");
private static final Component VIDEO = Component.translatable("options.video");
private static final Component CONTROLS = Component.translatable("options.controls");
private static final Component LANGUAGE = Component.translatable("options.language");
private static final Component CHAT = Component.translatable("options.chat.title");
private static final Component RESOURCEPACK = Component.translatable("options.resourcepack");
private static final Component ACCESSIBILITY = Component.translatable("options.accessibility.title");
private static final Component TELEMETRY = Component.translatable("options.telemetry");
private static final Component CREDITS_AND_ATTRIBUTION = Component.translatable("options.credits_and_attribution");
private static final int DEFAULT_COLOR = 0xFFFFFFFF;
private final Screen lastScreen;
private final Options options;
private CycleButton<Difficulty> difficultyButton;
private LockIconButton lockButton;

public LtsxOptionsScreen(Screen lastScreen, Options options) {
super(Component.literal("LTSX Options Screen"));
this.lastScreen = lastScreen;
this.options = options;
}

@Override
protected void init() {
GridLayout gridLayout = new GridLayout();
gridLayout.defaultCellSetting().paddingHorizontal(5).paddingBottom(4).alignHorizontallyCenter();
GridLayout.RowHelper rowHelper = gridLayout.createRowHelper(2);
rowHelper.addChild(this.options.fov().createButton(this.minecraft.options, 0, 0, 150));
rowHelper.addChild(this.openScreenButton(Component.translatable("menu.titlescreen.account"), 0xFF008FE1, () -> new LtsxOptionsScreen(this, this.options)));
rowHelper.addChild(SpacerElement.height(26), 2);
// rowHelper.addChild(this.openScreenButton(SKIN_CUSTOMIZATION, () -> new SkinCustomizationScreen(this, this.options)));
// rowHelper.addChild(this.openScreenButton(SOUNDS, () -> new SoundOptionsScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(Component.translatable("menu.options.interface"), DEFAULT_COLOR, () -> new InterfaceOptionsScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(VIDEO, () -> new VideoSettingsScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(CONTROLS, () -> new ControlsScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(LANGUAGE, () -> new LanguageSelectScreen((Screen)this, this.options, this.minecraft.getLanguageManager())));
// rowHelper.addChild(this.openScreenButton(CHAT, () -> new ChatOptionsScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(RESOURCEPACK, () -> new PackSelectionScreen(this.minecraft.getResourcePackRepository(), this::applyPacks, this.minecraft.getResourcePackDirectory(), Component.translatable("resourcePack.title"))));
rowHelper.addChild(this.openScreenButton(TELEMETRY, () -> new LtsxTelemetryScreen(this, this.options)));
rowHelper.addChild(this.openScreenButton(CREDITS_AND_ATTRIBUTION, () -> new CopyrightScreen(this)));
rowHelper.addChild(Button.builder(CommonComponents.GUI_DONE, button -> this.minecraft.setScreen(this.lastScreen)).width(200).build(), 2, rowHelper.newCellSettings().paddingTop(6));
gridLayout.arrangeElements();
FrameLayout.alignInRectangle(gridLayout, 0, this.height / 6 - 12, this.width, this.height, 0.5f, 0.0f);
gridLayout.visitWidgets(this::addRenderableWidget);
super.init();
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
this.renderBackground(guiGraphics);
super.render(guiGraphics, mouseX, mouseY, delta);
}

@Override
public void removed() {
this.options.save();
}

private Button openScreenButton(Component text, int color, Supplier<Screen> screenSupplier) {
return new ColorButton(0, 0, 150, 20, text, color, button -> this.minecraft.setScreen(screenSupplier.get()));
// return Button.builder(text, button -> this.minecraft.setScreen((Screen)screenSupplier.get())).build();
}

private Button openScreenButton(Component text, Supplier<Screen> screenSupplier) {
return this.openScreenButton(text, DEFAULT_COLOR, screenSupplier);
}

private void applyPacks(PackRepository packs) {
this.options.updateResourcePacks(packs);
this.minecraft.setScreen(this);
}

private LayoutElement createOnlineButton() {
if (this.minecraft.level != null && this.minecraft.hasSingleplayerServer()) {
this.difficultyButton = OptionsScreen.createDifficultyButton(0, 0, "options.difficulty", this.minecraft);
if (!this.minecraft.level.getLevelData().isHardcore()) {
this.lockButton = new LockIconButton(0, 0, button -> this.minecraft.setScreen(new ConfirmScreen(this::lockCallback, Component.translatable("difficulty.lock.title"), Component.translatable("difficulty.lock.question", this.minecraft.level.getLevelData().getDifficulty().getDisplayName()))));
this.difficultyButton.setWidth(this.difficultyButton.getWidth() - this.lockButton.getWidth());
this.lockButton.setLocked(this.minecraft.level.getLevelData().isDifficultyLocked());
this.lockButton.active = !this.lockButton.isLocked();
this.difficultyButton.active = !this.lockButton.isLocked();
LinearLayout linearLayout = new LinearLayout(150, 0, LinearLayout.Orientation.HORIZONTAL);
linearLayout.addChild(this.difficultyButton);
linearLayout.addChild(this.lockButton);
return linearLayout;
}
this.difficultyButton.active = false;
return this.difficultyButton;
}
return Button.builder(Component.translatable("options.online"), button -> this.minecraft.setScreen(OnlineOptionsScreen.createOnlineOptionsScreen(this.minecraft, this, this.options))).bounds(this.width / 2 + 5, this.height / 6 - 12 + 24, 150, 20).build();
}

private void lockCallback(boolean value) {
this.minecraft.setScreen(this);
if (value && this.minecraft.level != null) {
this.minecraft.getConnection().send(new ServerboundLockDifficultyPacket(true));
this.lockButton.setLocked(true);
this.lockButton.active = false;
this.difficultyButton.active = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package link.botwmcs.davinci.client.gui.screen.ltsx;

import net.minecraft.client.Options;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;

public class LtsxTelemetryScreen extends Screen {
private final Screen lastScreen;
private final Options options;

public LtsxTelemetryScreen(Screen lastScreen, Options options) {
super(Component.literal("LTSX Telemetry Screen"));
this.lastScreen = lastScreen;
this.options = options;
}

@Override
protected void init() {
super.init();
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
this.renderBackground(guiGraphics);
super.render(guiGraphics, mouseX, mouseY, delta);
}

@Override
public void onClose() {
this.minecraft.setScreen(this.lastScreen);
}
}
36 changes: 36 additions & 0 deletions src/main/java/link/botwmcs/davinci/mixin/OptionsScreenMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package link.botwmcs.davinci.mixin;

import link.botwmcs.davinci.client.gui.screen.ltsx.LtsxOptionsScreen;
import link.botwmcs.davinci.client.gui.screen.ltsx.LtsxTitleScreen;
import net.minecraft.client.Options;
import net.minecraft.client.gui.screens.OptionsScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(OptionsScreen.class)
public abstract class OptionsScreenMixin extends Screen {
protected OptionsScreenMixin(Component title, Options options, Screen lastScreen) {
super(title);
this.options = options;
this.lastScreen = lastScreen;
}
@Mutable
@Shadow @Final
private final Options options;

@Mutable
@Shadow @Final
private final Screen lastScreen;

@Inject(method = "init", at = @At("HEAD"))
public void init(CallbackInfo ci) {
this.minecraft.setScreen(new LtsxOptionsScreen(lastScreen, options));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package link.botwmcs.davinci.mixin;

import link.botwmcs.davinci.client.gui.screen.ltsx.LtsxTelemetryScreen;
import net.minecraft.client.Options;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.telemetry.TelemetryInfoScreen;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(TelemetryInfoScreen.class)
public class TelemetryInfoScreenMixin extends Screen {
protected TelemetryInfoScreenMixin(Component title, Options options, Screen lastScreen) {
super(title);
this.options = options;
this.lastScreen = lastScreen;
}

@Mutable
@Shadow
@Final
private final Options options;

@Mutable
@Shadow @Final
private final Screen lastScreen;

@Inject(method = "init", at = @At("HEAD"))
public void init(CallbackInfo ci) {
this.minecraft.setScreen(new LtsxTelemetryScreen(lastScreen, options));
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/davinci/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
"menu.copyright.mojang": "About Minecraft",
"menu.copyright.ltsx": "About LTSX",
"menu.copyright.apple.tooltip": "。゚ヽ(゚´Д`)ノ゚。",
"menu.copyright.mojang.tooltip": "See Mojang Copyright"
"menu.copyright.mojang.tooltip": "See Mojang Copyright",
"menu.options.title": "Options",
"menu.options.interface": "Interface..."
}
2 changes: 2 additions & 0 deletions src/main/resources/davinci.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
],
"client": [
"BossHealthOverlayMixin",
"OptionsScreenMixin",
"TelemetryInfoScreenMixin",
"TitleScreenMixin"
],
"injectors": {
Expand Down

0 comments on commit df49c11

Please sign in to comment.