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: Editable Xp Bar #1944

Merged
merged 9 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -254,6 +254,7 @@ 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.MovableXpBar
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 @@ -848,6 +849,7 @@ class SkyHanniMod {
loadModule(WarpTabComplete)
loadModule(PlayerTabComplete)
loadModule(GetFromSacksTabComplete)
loadModule(MovableXpBar())
loadModule(SlayerProfitTracker)
loadModule(FishingProfitTracker)
loadModule(SeaCreatureTracker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public class GUIConfig {
@Accordion
public HotbarConfig hotbar = new HotbarConfig();

@Expose
@ConfigOption(name = "Xp Bar", desc = "Settings for adjusting the xp bar")
@Accordion
public XPBarConfig xpBar = new XPBarConfig();

@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
Expand Up @@ -25,7 +25,7 @@ public class HotbarConfig {
public Position hotbar = new Position(20, 20);

@Expose
@ConfigOption(name = "Show Outside Skyblock", desc = "Enables the hotbar to be edited even outside of SkyBlock.")
@ConfigOption(name = "Show Outside Skyblock", desc = "Enables it outside of SkyBlock.")
@ConfigEditorBoolean
public boolean showOutsideSkyblock = false;
}
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 XPBarConfig {

@Expose
@ConfigOption(name = "Editable", desc = "Adds the xp bar to the gui editor. Allows for moving and scaling of the xp bar.")
@ConfigEditorBoolean
@FeatureToggle
public boolean editable = false;

@ConfigOption(name = "§cNotice", desc = "This option will be §c§lincompatible §r§7with mods that change the xp bar. Eg: §eApec§7.")
@ConfigEditorInfoText
public String notice = "";

@Expose
@ConfigLink(owner = XPBarConfig.class, field = "editable")
public Position hotbar = new Position(20, 20);

@Expose
@ConfigOption(name = "Show Outside Skyblock", desc = "Enables it outside of SkyBlock.")
@ConfigEditorBoolean
public boolean showOutsideSkyblock = false;
}
42 changes: 42 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/features/gui/MovableXpBar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class MovableXpBar {

private val config get() = SkyHanniMod.feature.gui.xpBar

private var post = false

@SubscribeEvent(priority = EventPriority.LOWEST)
fun onRenderXpBar(event: RenderGameOverlayEvent.Pre) {
if (event.type != RenderGameOverlayEvent.ElementType.EXPERIENCE || !isEnabled()) return
post = true
GlStateManager.pushMatrix()
val scaled = event.resolution
val x = scaled.scaledWidth / 2 - 91
val y = scaled.scaledHeight - 29
config.hotbar.transform()
GlStateManager.translate(-x.toFloat(), -y.toFloat(), 0f) // Must be after transform to work with scaling
GuiEditManager.add(config.hotbar, "Xp Bar", 182 - 1, 5 - 1) // -1 since the editor for some reason add +1
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onRenderXpBar(event: RenderGameOverlayEvent.Post) {
if (event.type != RenderGameOverlayEvent.ElementType.EXPERIENCE || !post) return
GlStateManager.popMatrix()
post = false
}

fun isEnabled(): Boolean =
(LorenzUtils.inSkyBlock || (Minecraft.getMinecraft().thePlayer != null && config.showOutsideSkyblock))
&& config.editable
}
Loading