Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Moveable and Scaleable Hotbar #1903

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -532,6 +533,7 @@ class SkyHanniMod {
loadModule(RenderData())
loadModule(GardenCropMilestones)
loadModule(GardenCropMilestonesCommunityFix)
loadModule(MovableHotBar())
loadModule(GardenCropUpgrades)
loadModule(VisitorListener())
loadModule(VisitorRewardWarning())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
41 changes: 41 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/features/gui/MovableHotBar.kt
Original file line number Diff line number Diff line change
@@ -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
}
Loading