mirror of
https://github.com/Shiewk/BedrockDeathScreen.git
synced 2026-04-27 22:44:17 +02:00
Add a config screen to toggle score text
This commit is contained in:
@@ -16,6 +16,17 @@ repositories {
|
|||||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||||
// for more information about repositories.
|
// for more information about repositories.
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = "Modrinth"
|
||||||
|
url = "https://api.modrinth.com/maven"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroup "maven.modrinth"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -26,6 +37,7 @@ dependencies {
|
|||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
modImplementation "maven.modrinth:modmenu:14.0.0-rc.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package de.shiewk.bedrockdeathscreen;
|
|||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
public class BedrockDeathScreenMod implements ModInitializer {
|
public final class BedrockDeathScreenMod implements ModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,67 @@
|
|||||||
package de.shiewk.bedrockdeathscreen.client;
|
package de.shiewk.bedrockdeathscreen.client;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import de.shiewk.bedrockdeathscreen.config.BedrockDeathScreenConfig;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
|
||||||
|
public final class BedrockDeathScreenClient implements ClientModInitializer {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(BedrockDeathScreenClient.class);
|
||||||
|
private static final Gson gson = new Gson();
|
||||||
|
private static BedrockDeathScreenConfig config = new BedrockDeathScreenConfig();
|
||||||
|
private static Path configPath;
|
||||||
|
|
||||||
public class BedrockDeathScreenClient implements ClientModInitializer {
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
|
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||||
|
configPath = minecraftClient.runDirectory.toPath().resolve("config/bedrockdeathscreen.json");
|
||||||
|
|
||||||
|
try {
|
||||||
|
loadConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void loadConfig() throws IOException {
|
||||||
|
log.info("Loading config");
|
||||||
|
if (Files.isRegularFile(configPath)){
|
||||||
|
try (BufferedReader reader = Files.newBufferedReader(configPath)) {
|
||||||
|
BedrockDeathScreenConfig loadedConfig = gson.fromJson(reader, BedrockDeathScreenConfig.class);
|
||||||
|
if (loadedConfig != null) {
|
||||||
|
config = loadedConfig;
|
||||||
|
} else {
|
||||||
|
log.info("Config could not be deserialized, not loading.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("Config file is not a regular file, not loading.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BedrockDeathScreenConfig getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveConfig() throws IOException {
|
||||||
|
log.info("Saving config");
|
||||||
|
Files.createDirectories(configPath.getParent());
|
||||||
|
if (!Files.isRegularFile(configPath)){
|
||||||
|
Files.createFile(configPath);
|
||||||
|
}
|
||||||
|
try (BufferedWriter writer = Files.newBufferedWriter(configPath, StandardOpenOption.TRUNCATE_EXISTING)) {
|
||||||
|
gson.toJson(config, writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package de.shiewk.bedrockdeathscreen.client.screen;
|
package de.shiewk.bedrockdeathscreen.client.screen;
|
||||||
|
|
||||||
|
import de.shiewk.bedrockdeathscreen.client.BedrockDeathScreenClient;
|
||||||
import de.shiewk.bedrockdeathscreen.client.screen.components.BedrockDeathScreenButton;
|
import de.shiewk.bedrockdeathscreen.client.screen.components.BedrockDeathScreenButton;
|
||||||
|
import de.shiewk.bedrockdeathscreen.config.BedrockDeathScreenConfig;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.gui.screen.DeathScreen;
|
import net.minecraft.client.gui.screen.DeathScreen;
|
||||||
import net.minecraft.client.gui.screen.MessageScreen;
|
import net.minecraft.client.gui.screen.MessageScreen;
|
||||||
@@ -21,6 +23,7 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
public static final long CURSOR_HAND = GLFW.glfwCreateStandardCursor(GLFW.GLFW_POINTING_HAND_CURSOR);
|
public static final long CURSOR_HAND = GLFW.glfwCreateStandardCursor(GLFW.GLFW_POINTING_HAND_CURSOR);
|
||||||
public static final Identifier VIGNETTE = Identifier.of("bedrockdeathscreen", "textures/gui/death_vignette.png");
|
public static final Identifier VIGNETTE = Identifier.of("bedrockdeathscreen", "textures/gui/death_vignette.png");
|
||||||
|
|
||||||
|
private final BedrockDeathScreenConfig config;
|
||||||
private final long screenCreationTime;
|
private final long screenCreationTime;
|
||||||
private final Text message;
|
private final Text message;
|
||||||
private Text scoreText = Text.empty();
|
private Text scoreText = Text.empty();
|
||||||
@@ -36,6 +39,7 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
|
|
||||||
public BedrockDeathScreen(@Nullable Text message, boolean isHardcore) {
|
public BedrockDeathScreen(@Nullable Text message, boolean isHardcore) {
|
||||||
super(message, isHardcore);
|
super(message, isHardcore);
|
||||||
|
this.config = BedrockDeathScreenClient.getConfig();
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.hardcore = isHardcore;
|
this.hardcore = isHardcore;
|
||||||
screenCreationTime = Util.getMeasuringTimeNano();
|
screenCreationTime = Util.getMeasuringTimeNano();
|
||||||
@@ -78,11 +82,13 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
context.drawCenteredTextWithShadow(this.textRenderer, this.message, this.width / 2, (int) (this.height / 3.5), new Color(255, 255, 255, textOpacity).getRGB());
|
context.drawCenteredTextWithShadow(this.textRenderer, this.message, this.width / 2, (int) (this.height / 3.5), new Color(255, 255, 255, textOpacity).getRGB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (config.showScore){
|
||||||
final int scoreTextOpacity = (int) Math.min(255, (totalScreenTime - 1250f) / 3f);
|
final int scoreTextOpacity = (int) Math.min(255, (totalScreenTime - 1250f) / 3f);
|
||||||
if (scoreTextOpacity > 3){
|
if (scoreTextOpacity > 3){
|
||||||
context.drawCenteredTextWithShadow(this.textRenderer, this.scoreText, this.width / 2, (int) (this.height / 3.5) + 12, new Color(255, 255, 255, scoreTextOpacity).getRGB());
|
context.drawCenteredTextWithShadow(this.textRenderer, this.scoreText, this.width / 2, (int) (this.height / 3.5) + 12, new Color(255, 255, 255, scoreTextOpacity).getRGB());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (confirmingExit){
|
if (confirmingExit){
|
||||||
context.drawCenteredTextWithShadow(this.textRenderer, BedrockDeathScreen.confirmQuitText, this.width / 2, this.height - this.height / 3 - 24, new Color(255, 255, 255, 255).getRGB());
|
context.drawCenteredTextWithShadow(this.textRenderer, BedrockDeathScreen.confirmQuitText, this.width / 2, this.height - this.height / 3 - 24, new Color(255, 255, 255, 255).getRGB());
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package de.shiewk.bedrockdeathscreen.client.screen;
|
||||||
|
|
||||||
|
import de.shiewk.bedrockdeathscreen.client.BedrockDeathScreenClient;
|
||||||
|
import de.shiewk.bedrockdeathscreen.config.BedrockDeathScreenConfig;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.GridWidget;
|
||||||
|
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
||||||
|
import net.minecraft.client.gui.widget.TextWidget;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public final class ConfigScreen extends Screen {
|
||||||
|
|
||||||
|
private final Screen parent;
|
||||||
|
private final BedrockDeathScreenConfig config = BedrockDeathScreenClient.getConfig();
|
||||||
|
private boolean configChanged = false;
|
||||||
|
|
||||||
|
public ConfigScreen(Screen parent) {
|
||||||
|
super(Text.empty());
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
addDrawableChild(new TextWidget(
|
||||||
|
0, 5, width, 9,
|
||||||
|
Text.translatable("bedrockdeathscreen.config"),
|
||||||
|
textRenderer
|
||||||
|
));
|
||||||
|
addDrawableChild(new ButtonWidget.Builder(
|
||||||
|
Text.translatable("gui.done"),
|
||||||
|
button -> this.close()
|
||||||
|
).position(width / 2 - 75, this.height - 25).build());
|
||||||
|
|
||||||
|
GridWidget grid = new GridWidget();
|
||||||
|
grid.getMainPositioner().margin(4, 4, 4, 4);
|
||||||
|
final GridWidget.Adder adder = grid.createAdder(2);
|
||||||
|
|
||||||
|
adder.add(createButton(
|
||||||
|
"bedrockdeathscreen.config.showScore",
|
||||||
|
config.showScore,
|
||||||
|
button -> {
|
||||||
|
config.showScore = !config.showScore;
|
||||||
|
configChanged = true;
|
||||||
|
button.setMessage(getButtonText("bedrockdeathscreen.config.showScore", config.showScore));
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
grid.refreshPositions();
|
||||||
|
SimplePositioningWidget.setPos(grid, 0, 0, this.width, this.height, 0.5F, 0.5F);
|
||||||
|
grid.forEachChild(this::addDrawableChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Text getButtonText(String translation, boolean state) {
|
||||||
|
return Text.translatable(
|
||||||
|
translation,
|
||||||
|
state ? Text.translatable("gui.yes") : Text.translatable("gui.no")
|
||||||
|
).withColor(state ? 0x00ff00 : 0xff5555);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ButtonWidget createButton(String translation, boolean state, ButtonWidget.PressAction action) {
|
||||||
|
return ButtonWidget.builder(
|
||||||
|
getButtonText(translation, state),
|
||||||
|
action
|
||||||
|
).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
if (configChanged){
|
||||||
|
try {
|
||||||
|
BedrockDeathScreenClient.saveConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert client != null;
|
||||||
|
client.setScreen(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.shiewk.bedrockdeathscreen.config;
|
||||||
|
|
||||||
|
public final class BedrockDeathScreenConfig {
|
||||||
|
|
||||||
|
public boolean showScore = true;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package de.shiewk.bedrockdeathscreen.config;
|
||||||
|
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
import de.shiewk.bedrockdeathscreen.client.screen.ConfigScreen;
|
||||||
|
|
||||||
|
public final class ModMenuConfig implements ModMenuApi {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
|
return ConfigScreen::new;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"bedrockdeathscreen.config": "BedrockDeathScreen-Einstellungen",
|
||||||
|
"bedrockdeathscreen.config.showScore": "Punktestand anzeigen: %s"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"bedrockdeathscreen.config": "BedrockDeathScreen config",
|
||||||
|
"bedrockdeathscreen.config.showScore": "Show score: %s"
|
||||||
|
}
|
||||||
@@ -19,6 +19,9 @@
|
|||||||
],
|
],
|
||||||
"main": [
|
"main": [
|
||||||
"de.shiewk.bedrockdeathscreen.BedrockDeathScreenMod"
|
"de.shiewk.bedrockdeathscreen.BedrockDeathScreenMod"
|
||||||
|
],
|
||||||
|
"modmenu": [
|
||||||
|
"de.shiewk.bedrockdeathscreen.config.ModMenuConfig"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
|||||||
Reference in New Issue
Block a user