diff options
author | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-16 11:37:42 -0230 |
---|---|---|
committer | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-16 11:37:42 -0230 |
commit | 13df8fe35749850d7bd560d51f67596094378d16 (patch) | |
tree | 85d5195eb7c193e19f2d588846cafb43e0c8eef0 /src | |
parent | c1d86146d76e4f3ddc18fbca6dedc5e5d473c11b (diff) | |
download | SkyblockHud-Death-Defied-13df8fe35749850d7bd560d51f67596094378d16.tar.gz SkyblockHud-Death-Defied-13df8fe35749850d7bd560d51f67596094378d16.tar.bz2 SkyblockHud-Death-Defied-13df8fe35749850d7bd560d51f67596094378d16.zip |
Added Dialogue boxes
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java | 2 | ||||
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java | 1 | ||||
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java | 13 | ||||
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java | 100 | ||||
-rw-r--r-- | src/main/resources/assets/skyblockhud/dialogue.png | bin | 0 -> 1537 bytes |
5 files changed, 116 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java index 280a18d..95a9499 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java @@ -33,4 +33,6 @@ public class GuiTextures { public static final ResourceLocation playerStat = new ResourceLocation("skyblockhud", "playerstats.png"); public static final ResourceLocation mapOverlay = new ResourceLocation("skyblockhud", "maps/map_overlay.png"); public static final ResourceLocation mining = new ResourceLocation("skyblockhud", "mines.png"); + + public static final ResourceLocation dialogue = new ResourceLocation("skyblockhud", "dialogue.png"); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java index 7e1f215..ab957a0 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java @@ -124,6 +124,7 @@ public class SkyblockHud { MinecraftForge.EVENT_BUS.register(new BossbarHandler()); MinecraftForge.EVENT_BUS.register(new MapHandler()); MinecraftForge.EVENT_BUS.register(new MiningHud()); + MinecraftForge.EVENT_BUS.register(new NpcDialogue()); } // DISABLE UNTIL NEW SYSTEM diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java index f26bef3..3f0f452 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java @@ -59,6 +59,9 @@ public class SBHConfig extends Config { case "heat": editOverlay(activeConfigCategory, 45, 7, mining.heatBar); return; + case "dialogue": + editOverlay(activeConfigCategory, 182, 68, misc.dialoguePos); + return; } } @@ -105,6 +108,16 @@ public class SBHConfig extends Config { @ConfigOption(name = "Bar Textures", desc = "Change the style of bars. Dont change this unless the pack ur using tells you can.") @ConfigEditorDropdown(values = { "Style 1", "Style 2" }) public int barTexture = 0; + + @Expose + @ConfigOption(name = "Hide Dialogue Box", desc = "Hides the Dialogue Box.") + @ConfigEditorBoolean + public boolean hideDialogueBox = true; + + @Expose + @ConfigOption(name = "Dialogue Box", desc = "") + @ConfigEditorButton(runnableId = "dialogue", buttonText = "Edit") + public Position dialoguePos = new Position(0, -50, true, false); } public static class MainHud { diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java new file mode 100644 index 0000000..efccbbf --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/NpcDialogue.java @@ -0,0 +1,100 @@ +package com.thatgravyboat.skyblockhud.handlers; + +import com.thatgravyboat.skyblockhud.SkyblockHud; +import com.thatgravyboat.skyblockhud.Utils; +import java.util.ArrayDeque; +import java.util.List; +import java.util.Locale; +import java.util.Queue; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import static com.thatgravyboat.skyblockhud.GuiTextures.dialogue; + +public class NpcDialogue { + + public static final Pattern NPC_DIALOGUE_REGEX = Pattern.compile("\\[NPC] (.*): (.*)"); + + private static boolean showDialogue = false; + private static int ticks = 0; + + private static final Queue<String> DIALOGUE = new ArrayDeque<>(); + private static String currentNpc = "Unknown"; + private static String currentDialogue = null; + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event){ + if (event.phase.equals(TickEvent.Phase.START) || SkyblockHud.config.misc.hideDialogueBox) return; + if (showDialogue) ticks++; + else ticks = 0; + + if (showDialogue && ticks % 60 == 0){ + currentDialogue = DIALOGUE.poll(); + + if (currentDialogue == null) { + showDialogue = false; + currentNpc = "Unknown"; + } + } + } + + @SubscribeEvent + public void onChat(ClientChatReceivedEvent event){ + if (event.type != 2 && !SkyblockHud.config.misc.hideDialogueBox){ + String message = Utils.removeColor(event.message.getUnformattedText()); + if (message.toLowerCase(Locale.ENGLISH).startsWith("[npc]")){ + Matcher matcher = NPC_DIALOGUE_REGEX.matcher(message); + if (matcher.find()) { + showDialogue = true; + event.setCanceled(true); + currentNpc = matcher.group(1); + if (currentDialogue != null) { + DIALOGUE.add(matcher.group(2)); + } else { + currentDialogue = matcher.group(2); + } + } + } + } + } + + @SubscribeEvent + public void renderOverlay(RenderGameOverlayEvent.Post event) { + if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), showDialogue, !SkyblockHud.config.misc.hideDialogueBox)) { + Minecraft mc = Minecraft.getMinecraft(); + mc.renderEngine.bindTexture(dialogue); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); + + int x = SkyblockHud.config.misc.dialoguePos.getAbsX(event.resolution,182) - 91; + int y = SkyblockHud.config.misc.dialoguePos.getAbsY(event.resolution,68); + + Gui.drawModalRectWithCustomSizedTexture(x,y, 0, 0, 182, 68, 256, 256); + + FontRenderer font = mc.fontRendererObj; + + font.drawString(currentNpc, x + 40, y + 10, 0xffffff); + + List<String> text = font.listFormattedStringToWidth(currentDialogue, 160); + + for (int i = 0; i < text.size(); i++) { + Utils.drawStringScaled(text.get(i), font, x + 40, y + 10 + font.FONT_HEIGHT + 6 + (i * font.FONT_HEIGHT + 3), false, 0xffffff, 0.75f); + } + } + } + + + + + + + + +} diff --git a/src/main/resources/assets/skyblockhud/dialogue.png b/src/main/resources/assets/skyblockhud/dialogue.png Binary files differnew file mode 100644 index 0000000..b637193 --- /dev/null +++ b/src/main/resources/assets/skyblockhud/dialogue.png |