From 29ddd9d05a59c9540869c0f96648cda8ad9364df Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Wed, 29 May 2024 23:42:34 +0200 Subject: Feature: Moveable and Scaleable Hotbar (#1903) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 ++ .../skyhanni/config/features/gui/GUIConfig.java | 5 +++ .../skyhanni/config/features/gui/HotbarConfig.java | 31 ++++++++++++++++ .../skyhanni/features/gui/MovableHotBar.kt | 41 ++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/gui/HotbarConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/gui/MovableHotBar.kt (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 0374024e0..794a7a568 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -251,6 +251,7 @@ import at.hannibal2.skyhanni.features.garden.visitor.NPCVisitorFix import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI import at.hannibal2.skyhanni.features.garden.visitor.VisitorListener import at.hannibal2.skyhanni.features.garden.visitor.VisitorRewardWarning +import at.hannibal2.skyhanni.features.gui.MovableHotBar import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern import at.hannibal2.skyhanni.features.gui.quiver.QuiverDisplay @@ -532,6 +533,7 @@ class SkyHanniMod { loadModule(RenderData()) loadModule(GardenCropMilestones) loadModule(GardenCropMilestonesCommunityFix) + loadModule(MovableHotBar()) loadModule(GardenCropUpgrades) loadModule(VisitorListener()) loadModule(VisitorRewardWarning()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java index 1309780a8..b259fd26d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/GUIConfig.java @@ -61,6 +61,11 @@ public class GUIConfig { @Accordion public DiscordRPCConfig discordRPC = new DiscordRPCConfig(); + @Expose + @ConfigOption(name = "Hotbar", desc = "Settings for adjusting the hotbar") + @Accordion + public HotbarConfig hotbar = new HotbarConfig(); + @Expose @ConfigOption(name = "Marked Players", desc = "Players that got marked with §e/shmarkplayer§7.") @Accordion diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/gui/HotbarConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/gui/HotbarConfig.java new file mode 100644 index 000000000..e13c18a8d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/gui/HotbarConfig.java @@ -0,0 +1,31 @@ +package at.hannibal2.skyhanni.config.features.gui; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorInfoText; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class HotbarConfig { + + @Expose + @ConfigOption(name = "Editable", desc = "Adds the hotbar to the gui editor. Allows for moving and scaling of the hotbar.") + @ConfigEditorBoolean + @FeatureToggle + public boolean editable = false; + + @ConfigOption(name = "§cNotice", desc = "This option will be §c§lincompatible §r§7with mods that change the hotbar. Eg: §eApec§7.") + @ConfigEditorInfoText + public String notice = ""; + + @Expose + @ConfigLink(owner = HotbarConfig.class, field = "editable") + public Position hotbar = new Position(20, 20); + + @Expose + @ConfigOption(name = "Show Outside Skyblock", desc = "Enables the hotbar to be edited even outside of SkyBlock.") + @ConfigEditorBoolean + public boolean showOutsideSkyblock = false; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/MovableHotBar.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/MovableHotBar.kt new file mode 100644 index 000000000..37a86eb22 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/MovableHotBar.kt @@ -0,0 +1,41 @@ +package at.hannibal2.skyhanni.features.gui + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.GuiEditManager +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.transform +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class MovableHotBar { + + private val config get() = SkyHanniMod.feature.gui.hotbar + + private var post = false + + @SubscribeEvent + fun onRenderHotbar(event: RenderGameOverlayEvent.Pre) { + if (event.type != RenderGameOverlayEvent.ElementType.HOTBAR || !isEnabled()) return + post = true + GlStateManager.pushMatrix() + val scaled = event.resolution + val x = scaled.scaledWidth / 2 - 91 + val y = scaled.scaledHeight - 22 + config.hotbar.transform() + GlStateManager.translate(-x.toFloat(), -y.toFloat(), 0f) // Must be after transform to work with scaling + GuiEditManager.add(config.hotbar, "Hotbar", 182 - 1, 22 - 1) // -1 since the editor for some reason add +1 + } + + @SubscribeEvent + fun onRenderHotbar(event: RenderGameOverlayEvent.Post) { + if (event.type != RenderGameOverlayEvent.ElementType.HOTBAR || !post) return + GlStateManager.popMatrix() + post = false + } + + fun isEnabled(): Boolean = + (LorenzUtils.inSkyBlock || (Minecraft.getMinecraft().thePlayer != null && config.showOutsideSkyblock)) + && config.editable +} -- cgit