From 480dcdebedcde1ce39382091a52e656ed69406d6 Mon Sep 17 00:00:00 2001 From: Zelophed Date: Mon, 29 Jun 2020 01:07:21 +0200 Subject: [PATCH] Goggle overlay offset -added two config entries to offset the goggle overlay on x/y axis -added a command (/create overlay [reset]) to allow editing the overlay position ingame --- src/generated/resources/.cache/cache | 2 +- .../resources/assets/create/lang/en_us.json | 9 ++ .../goggles/GoggleConfigScreen.java | 86 +++++++++++++++++++ .../goggles/GoggleOverlayRenderer.java | 18 ++-- .../command/ConfigureConfigPacket.java | 51 +++++++++-- .../foundation/command/CreateCommand.java | 1 + .../command/OverlayConfigCommand.java | 46 ++++++++++ .../command/ToggleDebugCommand.java | 5 +- .../create/foundation/config/CClient.java | 3 + .../assets/create/lang/default/messages.json | 9 ++ 10 files changed, 213 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java create mode 100644 src/main/java/com/simibubi/create/foundation/command/OverlayConfigCommand.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index e07ce1129..c7bd920cf 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -336,7 +336,7 @@ c77b46d8b459e5c7cc495393546f3fcca8a1fa1d assets\create\blockstates\weathered_lim 7f39521b211441f5c3e06d60c5978cebe16cacfb assets\create\blockstates\zinc_block.json b7181bcd8182b2f17088e5aa881f374c9c65470c assets\create\blockstates\zinc_ore.json 5753bc985f4c202fe16387c32fb8ad80c631c933 assets\create\lang\en_ud.json -0640b1b64ac1a1e337178f932f22b0b2aea61d46 assets\create\lang\en_us.json +21f721489c30a85337d5007895a54ff1db9e5f6c assets\create\lang\en_us.json 846200eb548d3bfa2e77b41039de159b4b6cfb45 assets\create\models\block\acacia_window.json 1930fa3a3c98d53dd19e4ee7f55bc27fd47aa281 assets\create\models\block\acacia_window_pane_noside.json 1763ea2c9b981d187f5031ba608f3d5d3be3986a assets\create\models\block\acacia_window_pane_noside_alt.json diff --git a/src/generated/resources/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index fcc292fd4..0ddd73a31 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -815,6 +815,15 @@ "create.mechanical_mixer.min_ingredients": "Min. Ingredients", + "create.gui.config.overlay1": "Hi :)", + "create.gui.config.overlay2": "This is a sample overlay", + "create.gui.config.overlay3": "Click or drag with your mouse", + "create.gui.config.overlay4": "to move this preview", + "create.gui.config.overlay5": "Press ESC to exit this screen", + "create.gui.config.overlay6": "and save the new position", + "create.gui.config.overlay7": "Run /create overlay reset", + "create.gui.config.overlay8": "to reset to the default position", + "create.command.killTPSCommand": "killtps", "create.command.killTPSCommand.status.slowed_by.0": "[Create]: Server tick is currently slowed by %s ms :o", "create.command.killTPSCommand.status.slowed_by.1": "[Create]: Server tick is slowed by %s ms now >:)", diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java new file mode 100644 index 000000000..edb006233 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java @@ -0,0 +1,86 @@ +package com.simibubi.create.content.contraptions.goggles; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.simibubi.create.AllItems; +import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.gui.AbstractSimiScreen; +import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.utility.Lang; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextFormatting; + +import java.util.ArrayList; +import java.util.List; + +public class GoggleConfigScreen extends AbstractSimiScreen { + + private int offsetX; + private int offsetY; + private final List tooltip; + + public GoggleConfigScreen() { + String spacing = " "; + tooltip = new ArrayList<>(); + tooltip.add(spacing + Lang.translate("gui.config.overlay1")); + tooltip.add(spacing + TextFormatting.GRAY + Lang.translate("gui.config.overlay2")); + tooltip.add(""); + tooltip.add(spacing + Lang.translate("gui.config.overlay3")); + tooltip.add(spacing + Lang.translate("gui.config.overlay4")); + tooltip.add(""); + tooltip.add(spacing + TextFormatting.GRAY + Lang.translate("gui.config.overlay5")); + tooltip.add(spacing + TextFormatting.GRAY + Lang.translate("gui.config.overlay6")); + tooltip.add(""); + tooltip.add(spacing + Lang.translate("gui.config.overlay7")); + tooltip.add(spacing + Lang.translate("gui.config.overlay8")); + } + + @Override + protected void init() { + Minecraft mc = Minecraft.getInstance(); + this.width = mc.getWindow().getScaledWidth(); + this.height = mc.getWindow().getScaledHeight(); + + offsetX = AllConfigs.CLIENT.overlayOffsetX.get(); + offsetY = AllConfigs.CLIENT.overlayOffsetY.get(); + } + + @Override + public void removed() { + AllConfigs.CLIENT.overlayOffsetX.set(offsetX); + AllConfigs.CLIENT.overlayOffsetY.set(offsetY); + } + + @Override + public boolean mouseClicked(double x, double y, int button) { + updateOffset(x, y); + + return true; + } + + @Override + public boolean mouseDragged(double p_mouseDragged_1_, double p_mouseDragged_3_, int p_mouseDragged_5_, double p_mouseDragged_6_, double p_mouseDragged_8_) { + updateOffset(p_mouseDragged_1_, p_mouseDragged_3_); + + return true; + } + + private void updateOffset(double windowX, double windowY) { + offsetX = (int) (windowX - (this.width / 2)); + offsetY = (int) (windowY - (this.height / 2)); + } + + @Override + protected void renderWindow(int mouseX, int mouseY, float partialTicks) { + RenderSystem.pushMatrix(); + int posX = this.width / 2 + offsetX; + int posY = this.height / 2 + offsetY; + //tooltipScreen.renderTooltip(tooltip, tooltipScreen.width / 2, tooltipScreen.height / 2); + renderTooltip(tooltip, posX, posY); + + ItemStack item = AllItems.GOGGLES.asStack(); + //GuiGameElement.of(item).at(tooltipScreen.width / 2 + 10, tooltipScreen.height / 2 - 16).render(); + GuiGameElement.of(item).at(posX + 10, posY - 16).render(); + RenderSystem.popMatrix(); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java index 710c76388..2e728d649 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java @@ -1,12 +1,9 @@ package com.simibubi.create.content.contraptions.goggles; -import java.util.ArrayList; -import java.util.List; - import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllItems; +import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.GuiGameElement; - import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.world.ClientWorld; @@ -23,6 +20,9 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import java.util.ArrayList; +import java.util.List; + @EventBusSubscriber(value = Dist.CLIENT) public class GoggleOverlayRenderer { @@ -76,10 +76,14 @@ public class GoggleOverlayRenderer { RenderSystem.pushMatrix(); Screen tooltipScreen = new TooltipScreen(null); tooltipScreen.init(mc, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); - tooltipScreen.renderTooltip(tooltip, tooltipScreen.width / 2, tooltipScreen.height / 2); - + int posX = tooltipScreen.width / 2 + AllConfigs.CLIENT.overlayOffsetX.get(); + int posY = tooltipScreen.height / 2 + AllConfigs.CLIENT.overlayOffsetY.get(); + //tooltipScreen.renderTooltip(tooltip, tooltipScreen.width / 2, tooltipScreen.height / 2); + tooltipScreen.renderTooltip(tooltip, posX, posY); + ItemStack item = AllItems.GOGGLES.asStack(); - GuiGameElement.of(item).at(tooltipScreen.width / 2 + 10, tooltipScreen.height / 2 - 16).render(); + //GuiGameElement.of(item).at(tooltipScreen.width / 2 + 10, tooltipScreen.height / 2 - 16).render(); + GuiGameElement.of(item).at(posX + 10, posY - 16).render(); RenderSystem.popMatrix(); } diff --git a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java index 354405087..45d17d4b4 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/foundation/command/ConfigureConfigPacket.java @@ -1,19 +1,23 @@ package com.simibubi.create.foundation.command; -import java.util.function.Supplier; - +import com.simibubi.create.content.contraptions.goggles.GoggleConfigScreen; import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.networking.SimplePacketBase; - import net.minecraft.network.PacketBuffer; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.network.NetworkEvent; +import org.apache.logging.log4j.LogManager; + +import java.util.function.Consumer; +import java.util.function.Supplier; public class ConfigureConfigPacket extends SimplePacketBase { - private String option; - private String value; + private final String option; + private final String value; public ConfigureConfigPacket(String option, String value) { this.option = option; @@ -34,11 +38,44 @@ public class ConfigureConfigPacket extends SimplePacketBase { @Override public void handle(Supplier ctx) { ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { - if (option.equals("rainbowDebug")) { - AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value)); + try { + Actions.valueOf(option).performAction(value); + } catch (IllegalArgumentException e) { + LogManager.getLogger().warn("Received ConfigureConfigPacket with invalid Option: " + option); } })); ctx.get().setPacketHandled(true); } + + enum Actions { + rainbowDebug((value) -> { + AllConfigs.CLIENT.rainbowDebug.set(Boolean.parseBoolean(value)); + }), + overlayScreen((value) -> { + overlayScreenAction(); + }), + overlayReset((value) -> { + AllConfigs.CLIENT.overlayOffsetX.set(0); + AllConfigs.CLIENT.overlayOffsetY.set(0); + }), + + ; + + private final Consumer consumer; + + Actions(Consumer action) { + this.consumer = action; + } + + void performAction(String value){ + consumer.accept(value); + } + + @OnlyIn(Dist.CLIENT) + private static void overlayScreenAction(){ + //this doesn't work if i move it into the enum constructor like the other two. if there's a proper way to do this, please let me know + ScreenOpener.open(new GoggleConfigScreen()); + } + } } diff --git a/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java b/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java index 27de9b3b2..9126dedba 100644 --- a/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/CreateCommand.java @@ -10,6 +10,7 @@ public class CreateCommand { public CreateCommand(CommandDispatcher dispatcher) { dispatcher.register(Commands.literal("create") .then(ToggleDebugCommand.register()) + .then(OverlayConfigCommand.register()) .then(ClearBufferCacheCommand.register()) //.then(KillTPSCommand.register()) //Commented out for release ); diff --git a/src/main/java/com/simibubi/create/foundation/command/OverlayConfigCommand.java b/src/main/java/com/simibubi/create/foundation/command/OverlayConfigCommand.java new file mode 100644 index 000000000..632782c06 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/OverlayConfigCommand.java @@ -0,0 +1,46 @@ +package com.simibubi.create.foundation.command; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.simibubi.create.foundation.networking.AllPackets; +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.network.PacketDistributor; + +public class OverlayConfigCommand { + + public static ArgumentBuilder register() { + return Commands.literal("overlay") + .requires(cs -> cs.hasPermissionLevel(0)) + .then(Commands.literal("reset") + .executes(ctx -> { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ConfigureConfigPacket.Actions.overlayReset.performAction("")); + + DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> + AllPackets.channel.send( + PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) ctx.getSource().getEntity()), + new ConfigureConfigPacket(ConfigureConfigPacket.Actions.overlayReset.name(), ""))); + + ctx.getSource().sendFeedback(new StringTextComponent("reset overlay offset"), true); + + return 1; + }) + ) + .executes(ctx -> { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ConfigureConfigPacket.Actions.overlayScreen.performAction("")); + + DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> + AllPackets.channel.send( + PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) ctx.getSource().getEntity()), + new ConfigureConfigPacket(ConfigureConfigPacket.Actions.overlayScreen.name(), ""))); + + ctx.getSource().sendFeedback(new StringTextComponent("window opened"), true); + + return 1; + }); + + } +} diff --git a/src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java b/src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java index a59870fa6..984164449 100644 --- a/src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java +++ b/src/main/java/com/simibubi/create/foundation/command/ToggleDebugCommand.java @@ -21,12 +21,13 @@ public class ToggleDebugCommand { .then(Commands.argument("value", BoolArgumentType.bool()) .executes(ctx -> { boolean value = BoolArgumentType.getBool(ctx, "value"); - DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> AllConfigs.CLIENT.rainbowDebug.set(value)); + //DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> AllConfigs.CLIENT.rainbowDebug.set(value)); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ConfigureConfigPacket.Actions.rainbowDebug.performAction(String.valueOf(value))); DistExecutor.runWhenOn(Dist.DEDICATED_SERVER, () -> () -> AllPackets.channel.send( PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) ctx.getSource().getEntity()), - new ConfigureConfigPacket("rainbowDebug", String.valueOf(value)))); + new ConfigureConfigPacket(ConfigureConfigPacket.Actions.rainbowDebug.name(), String.valueOf(value)))); ctx.getSource().sendFeedback(new StringTextComponent((value ? "enabled" : "disabled") + " rainbow debug"), true); diff --git a/src/main/java/com/simibubi/create/foundation/config/CClient.java b/src/main/java/com/simibubi/create/foundation/config/CClient.java index ee189517a..0bd1eb895 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CClient.java +++ b/src/main/java/com/simibubi/create/foundation/config/CClient.java @@ -13,6 +13,9 @@ public class CClient extends ConfigBase { public ConfigBool rainbowDebug = b(true, "enableRainbowDebug", "Show colourful debug information while the F3-Menu is open."); + public ConfigInt overlayOffsetX = i(0, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetX", "Offset the overlay from goggle- and hover- information by this many pixels on the X axis; Use /create overlay"); + public ConfigInt overlayOffsetY = i(0, Integer.MIN_VALUE, Integer.MAX_VALUE, "overlayOffsetY", "Offset the overlay from goggle- and hover- information by this many pixels on the Y axis; Use /create overlay"); + @Override public String getName() { return "client"; diff --git a/src/main/resources/assets/create/lang/default/messages.json b/src/main/resources/assets/create/lang/default/messages.json index 2eb783b07..04933d1bf 100644 --- a/src/main/resources/assets/create/lang/default/messages.json +++ b/src/main/resources/assets/create/lang/default/messages.json @@ -343,6 +343,15 @@ "create.tooltip.analogStrength": "Analog Strength: %1$s/15", "create.mechanical_mixer.min_ingredients": "Min. Ingredients", + "create.gui.config.overlay1": "Hi :)", + "create.gui.config.overlay2": "This is a sample overlay", + "create.gui.config.overlay3": "Click or drag with your mouse", + "create.gui.config.overlay4": "to move this preview", + "create.gui.config.overlay5": "Press ESC to exit this screen", + "create.gui.config.overlay6": "and save the new position", + "create.gui.config.overlay7": "Run /create overlay reset", + "create.gui.config.overlay8": "to reset to the default position", + "create.command.killTPSCommand": "killtps", "create.command.killTPSCommand.status.slowed_by.0": "[Create]: Server tick is currently slowed by %s ms :o", "create.command.killTPSCommand.status.slowed_by.1": "[Create]: Server tick is slowed by %s ms now >:)",