diff --git a/src/main/java/me/rigamortis/seppuku/Seppuku.java b/src/main/java/me/rigamortis/seppuku/Seppuku.java index f8ba800..771fbce 100644 --- a/src/main/java/me/rigamortis/seppuku/Seppuku.java +++ b/src/main/java/me/rigamortis/seppuku/Seppuku.java @@ -107,7 +107,15 @@ public final class Seppuku { this.getEventManager().dispatchEvent(new EventLoad()); - this.logger.info("Loaded"); + // Add runtime hook to listen for shutdown to save configs + Runtime.getRuntime().addShutdownHook(new Thread("Seppuku Shutdown Hook") { + @Override + public void run() { + getConfigManager().saveAll(); + } + }); + + this.logger.info("Seppuku Loaded Successfully"); } public void errorChat(String message) { diff --git a/src/main/java/me/rigamortis/seppuku/api/gui/hud/component/HudComponent.java b/src/main/java/me/rigamortis/seppuku/api/gui/hud/component/HudComponent.java index 2ea5eb8..b34c873 100644 --- a/src/main/java/me/rigamortis/seppuku/api/gui/hud/component/HudComponent.java +++ b/src/main/java/me/rigamortis/seppuku/api/gui/hud/component/HudComponent.java @@ -41,6 +41,10 @@ public class HudComponent { } + public void keyTyped(char typedChar, int keyCode) { + + } + public boolean collidesWith(HudComponent other) { // Collision x-axis? boolean collisionX = this.x + this.w > other.x && diff --git a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/GuiHudEditor.java b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/GuiHudEditor.java index fa07a28..7aacbd2 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/GuiHudEditor.java +++ b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/GuiHudEditor.java @@ -35,6 +35,12 @@ public final class GuiHudEditor extends GuiScreen { } } } + + for (HudComponent component : Seppuku.INSTANCE.getHudManager().getComponentList()) { + if (component.isVisible()) { + component.keyTyped(typedChar, keyCode); + } + } } @Override diff --git a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/FirstLaunchComponent.java b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/FirstLaunchComponent.java new file mode 100644 index 0000000..da41183 --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/FirstLaunchComponent.java @@ -0,0 +1,73 @@ +package me.rigamortis.seppuku.impl.gui.hud.component; + +import me.rigamortis.seppuku.Seppuku; +import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent; +import me.rigamortis.seppuku.api.module.Module; +import me.rigamortis.seppuku.api.util.RenderUtil; +import me.rigamortis.seppuku.impl.gui.hud.GuiHudEditor; +import me.rigamortis.seppuku.impl.module.render.HudModule; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Keyboard; + +import java.security.Key; + +/** + * created by noil on 5/7/2020 + */ +public final class FirstLaunchComponent extends DraggableHudComponent { + + private Module hudModule; + + private String textData; + + public FirstLaunchComponent() { + super("FirstLaunch"); + + final String textData = "Welcome to Seppuku Client!\n\n" + + "Press ~ (tilda/grave) to open the GUI / hud-editor."; + this.setTextData(textData); + + this.setVisible(true); + this.setSnappable(false); + this.setW(200); + this.setH(38); + this.setX(2); + this.setY(2); + + this.hudModule = Seppuku.INSTANCE.getModuleManager().find(HudModule.class); + } + + @Override + public void render(int mouseX, int mouseY, float partialTicks) { + super.render(mouseX, mouseY, partialTicks); + + final Minecraft mc = Minecraft.getMinecraft(); + + // Background + RenderUtil.drawRect(this.getX(), this.getY(), this.getX() + this.getW(), this.getY() + this.getH(), 0xFF202020); + + // Render text data + mc.fontRenderer.drawSplitString(this.textData, (int) this.getX() + 2, (int) this.getY() + 2, 200, 0xFFFFFFFF); + } + + public void onClose() { + if (this.hudModule != null) { + if(this.hudModule.isEnabled()) { + this.hudModule.onEnable(); + }else { + this.hudModule.toggle(); + } + this.hudModule.setEnabled(true); + } + + this.setVisible(false); + } + + public String getTextData() { + return textData; + } + + public void setTextData(String textData) { + this.textData = textData; + } +} diff --git a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PopupComponent.java b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PopupComponent.java index 1257d26..323511a 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PopupComponent.java +++ b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PopupComponent.java @@ -30,9 +30,6 @@ public class PopupComponent extends DraggableHudComponent { final Minecraft mc = Minecraft.getMinecraft(); - if (!(mc.currentScreen instanceof GuiHudEditor)) // ensure we are in the hud editor screen only - return; - // background RenderUtil.drawRect(this.getX(), this.getY(), this.getX() + this.getW(), this.getY() + this.getH(), 0xFF202020); @@ -54,7 +51,7 @@ public class PopupComponent extends DraggableHudComponent { mouseY <= this.getY() + CLOSE_BUTTON_SIZE; if (insideCloseButton && button == 0) { - this.setVisible(false); + this.onCloseButton(); } } @@ -65,4 +62,8 @@ public class PopupComponent extends DraggableHudComponent { public void setTextData(String textData) { this.textData = textData; } + + public void onCloseButton() { + this.setVisible(false); + } } diff --git a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/TutorialComponent.java b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/TutorialComponent.java index 73d8899..d87442b 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/TutorialComponent.java +++ b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/TutorialComponent.java @@ -33,13 +33,13 @@ public final class TutorialComponent extends PopupComponent { @Override public void render(int mouseX, int mouseY, float partialTicks) { - super.render(mouseX, mouseY, partialTicks); - final Minecraft mc = Minecraft.getMinecraft(); if (!(mc.currentScreen instanceof GuiHudEditor)) // ensure we are in the hud editor screen only return; + super.render(mouseX, mouseY, partialTicks); + // drag me! mc.fontRenderer.drawStringWithShadow("(drag me!)", this.getX() + this.getW() - 80, this.getY() + 10, 0xFFAAAAAA); } diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/ConfigManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/ConfigManager.java index f6f3d2c..ff64744 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/ConfigManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/ConfigManager.java @@ -18,7 +18,7 @@ public final class ConfigManager { private File moduleConfigDir; private File hudComponentConfigDir; - private boolean firstLaunch; + private boolean firstLaunch = false; private List configurableList = new ArrayList<>(); @@ -31,7 +31,7 @@ public final class ConfigManager { private void generateDirectories() { this.configDir = new File(CONFIG_PATH); if (!this.configDir.exists()) { - this.firstLaunch = true; + this.setFirstLaunch(true); this.configDir.mkdirs(); } diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/HudManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/HudManager.java index c2b624e..38ac8e1 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/HudManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/HudManager.java @@ -5,11 +5,14 @@ import me.rigamortis.seppuku.api.event.render.EventRender2D; import me.rigamortis.seppuku.api.gui.hud.component.HudComponent; import me.rigamortis.seppuku.api.module.Module; import me.rigamortis.seppuku.api.util.ReflectionUtil; +import me.rigamortis.seppuku.impl.gui.hud.GuiHudEditor; import me.rigamortis.seppuku.impl.gui.hud.anchor.AnchorPoint; import me.rigamortis.seppuku.impl.gui.hud.component.*; import me.rigamortis.seppuku.impl.gui.hud.component.module.ModuleListComponent; +import me.rigamortis.seppuku.impl.module.render.HudModule; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiChat; +import net.minecraft.client.gui.GuiIngame; import net.minecraft.client.gui.ScaledResolution; import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; @@ -29,6 +32,8 @@ public final class HudManager { private List componentList = new CopyOnWriteArrayList<>(); private List anchorPoints = new ArrayList<>(); + private final FirstLaunchComponent firstLaunchComponent; + public HudManager() { final ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft()); @@ -86,6 +91,9 @@ public final class HudManager { // Organize alphabetically this.componentList = this.componentList.stream().sorted((obj1, obj2) -> obj1.getName().compareTo(obj2.getName())).collect(Collectors.toList()); + // Create first launch component + this.firstLaunchComponent = new FirstLaunchComponent(); + Seppuku.INSTANCE.getEventManager().addEventListener(this); } @@ -98,6 +106,16 @@ public final class HudManager { public void onRender(EventRender2D event) { final Minecraft mc = Minecraft.getMinecraft(); + if (this.firstLaunchComponent != null && mc.world != null) { + if (Seppuku.INSTANCE.getConfigManager().isFirstLaunch()) { + if (mc.currentScreen instanceof GuiHudEditor) { + firstLaunchComponent.onClose(); + } else if (firstLaunchComponent.isVisible()) { + firstLaunchComponent.render(0, 0, event.getPartialTicks()); + } + } + } + final int chatHeight = (mc.currentScreen instanceof GuiChat) ? 14 : 0; for (AnchorPoint point : this.anchorPoints) { diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/hidden/KeybindsModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/hidden/KeybindsModule.java index 0dcc249..8f030cd 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/hidden/KeybindsModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/hidden/KeybindsModule.java @@ -24,7 +24,6 @@ public final class KeybindsModule extends Module { if(mod != null) { if(mod.getType() != ModuleType.HIDDEN && event.getKey() == Keyboard.getKeyIndex(mod.getKey()) && Keyboard.getKeyIndex(mod.getKey()) != Keyboard.KEY_NONE) { mod.toggle(); - Seppuku.INSTANCE.getConfigManager().saveAll(); } } } diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java index fce1f96..067dda1 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/render/HudModule.java @@ -22,7 +22,7 @@ public final class HudModule extends Module { public final Value hidePotions = new Value("HidePotions", new String[]{"HidePotions", "HidePots", "Hide_Potions"}, "Hides the Vanilla potion hud (at the top right of the screen).", true); public HudModule() { - super("Hud", new String[]{"Overlay"}, "Shows lots of useful info", "NONE", -1, ModuleType.RENDER); + super("Hud", new String[]{"Overlay"}, "Renders hud components on the screen.", "NONE", -1, ModuleType.RENDER); this.setHidden(true); } @@ -30,11 +30,7 @@ public final class HudModule extends Module { public void render(EventRender2D event) { final Minecraft mc = Minecraft.getMinecraft(); - if (mc.gameSettings.showDebugInfo) { - return; - } - - if (mc.currentScreen instanceof GuiHudEditor) { + if (mc.gameSettings.showDebugInfo || mc.currentScreen instanceof GuiHudEditor || mc.player == null) { return; } @@ -42,7 +38,6 @@ public final class HudModule extends Module { GlStateManager.enableBlend(); for (HudComponent component : Seppuku.INSTANCE.getHudManager().getComponentList()) { if (component.isVisible()) { - //dont render components with the TOP_CENTER anchor if we are looking at the tab list if (component instanceof DraggableHudComponent) { final DraggableHudComponent draggableComponent = (DraggableHudComponent) component;