Skip to content

Commit 2c82427

Browse files
committed
Feature: Add movable Action Bar and Held Item Tooltip
1 parent 501f994 commit 2c82427

File tree

7 files changed

+199
-0
lines changed

7 files changed

+199
-0
lines changed

src/main/java/at/hannibal2/skyhanni/api/minecraftevents/RenderEvents.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ object RenderEvents {
7777
fun postExperienceNumberLayerEventPost(context: GuiGraphics) {
7878
GameOverlayRenderPostEvent(context, RenderLayer.EXPERIENCE_NUMBER).post()
7979
}
80+
81+
@JvmStatic
82+
fun postHeldItemTooltipLayerEventPre(context: GuiGraphics): Boolean {
83+
return GameOverlayRenderPreEvent(context, RenderLayer.HELD_ITEM_TOOLTIP).post()
84+
}
85+
86+
@JvmStatic
87+
fun postHeldItemTooltipLayerEventPost(context: GuiGraphics) {
88+
GameOverlayRenderPostEvent(context, RenderLayer.HELD_ITEM_TOOLTIP).post()
89+
}
90+
91+
@JvmStatic
92+
fun postActionBarLayerEventPre(context: GuiGraphics): Boolean {
93+
return GameOverlayRenderPreEvent(context, RenderLayer.ACTION_BAR).post()
94+
}
95+
96+
@JvmStatic
97+
fun postActionBarLayerEventPost(context: GuiGraphics) {
98+
GameOverlayRenderPostEvent(context, RenderLayer.ACTION_BAR).post()
99+
}
80100
}
81101

82102
enum class RenderLayer {
@@ -97,6 +117,8 @@ enum class RenderLayer {
97117
CHAT,
98118
PLAYER_LIST,
99119
DEBUG,
120+
HELD_ITEM_TOOLTIP,
121+
ACTION_BAR,
100122

101123
// Not a real forge layer but is used on modern Minecraft versions
102124
EXPERIENCE_NUMBER,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package at.hannibal2.skyhanni.config.features.gui
2+
3+
import at.hannibal2.skyhanni.config.FeatureToggle
4+
import at.hannibal2.skyhanni.config.core.config.Position
5+
import com.google.gson.annotations.Expose
6+
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean
7+
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink
8+
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption
9+
10+
class ActionBarConfig {
11+
@Expose
12+
@ConfigOption(
13+
name = "Enabled",
14+
desc = "Allows for moving and scaling the action bar in the SkyHanni GUI Editor.",
15+
)
16+
@ConfigEditorBoolean
17+
@FeatureToggle
18+
var enabled: Boolean = false
19+
20+
@Expose
21+
@ConfigLink(owner = ActionBarConfig::class, field = "enabled")
22+
val position: Position = Position(20, 20)
23+
24+
@Expose
25+
@ConfigOption(name = "Show Outside SkyBlock", desc = "Shows the action bar outside of SkyBlock.")
26+
@ConfigEditorBoolean
27+
var showOutsideSkyblock: Boolean = false
28+
}

src/main/java/at/hannibal2/skyhanni/config/features/gui/GuiConfig.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ class GuiConfig {
8181
@Accordion
8282
val xpBar: XPBarConfig = XPBarConfig()
8383

84+
@Expose
85+
@ConfigOption(name = "Action Bar", desc = "Settings for adjusting the action bar.")
86+
@Accordion
87+
val actionBar: ActionBarConfig = ActionBarConfig()
88+
89+
@Expose
90+
@ConfigOption(name = "Held Item Tooltip", desc = "Settings for adjusting the held item tooltip.")
91+
@Accordion
92+
val heldItemTooltip: HeldItemTooltipConfig = HeldItemTooltipConfig()
93+
8494
@Expose
8595
@ConfigOption(name = "Mayor Overlay", desc = "Settings for the mayor overlay.")
8696
@Accordion
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package at.hannibal2.skyhanni.config.features.gui
2+
3+
import at.hannibal2.skyhanni.config.FeatureToggle
4+
import at.hannibal2.skyhanni.config.core.config.Position
5+
import com.google.gson.annotations.Expose
6+
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean
7+
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink
8+
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption
9+
10+
class HeldItemTooltipConfig {
11+
@Expose
12+
@ConfigOption(
13+
name = "Enabled",
14+
desc = "Allows for moving and scaling the held item tooltip in the SkyHanni GUI Editor.",
15+
)
16+
@ConfigEditorBoolean
17+
@FeatureToggle
18+
var enabled: Boolean = false
19+
20+
@Expose
21+
@ConfigLink(owner = HeldItemTooltipConfig::class, field = "enabled")
22+
val position: Position = Position(20, 20)
23+
24+
@Expose
25+
@ConfigOption(name = "Show Outside SkyBlock", desc = "Shows the held item tooltip outside of SkyBlock.")
26+
@ConfigEditorBoolean
27+
var showOutsideSkyblock: Boolean = false
28+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package at.hannibal2.skyhanni.features.gui
2+
3+
import at.hannibal2.skyhanni.SkyHanniMod
4+
import at.hannibal2.skyhanni.api.event.HandleEvent
5+
import at.hannibal2.skyhanni.api.minecraftevents.RenderLayer
6+
import at.hannibal2.skyhanni.data.GuiEditManager
7+
import at.hannibal2.skyhanni.events.render.gui.GameOverlayRenderPostEvent
8+
import at.hannibal2.skyhanni.events.render.gui.GameOverlayRenderPreEvent
9+
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
10+
import at.hannibal2.skyhanni.utils.RenderUtils.transform
11+
import at.hannibal2.skyhanni.utils.SkyBlockUtils
12+
import at.hannibal2.skyhanni.utils.compat.DrawContextUtils
13+
import at.hannibal2.skyhanni.utils.compat.GuiScreenUtils
14+
import at.hannibal2.skyhanni.utils.compat.MinecraftCompat
15+
16+
@SkyHanniModule
17+
object MovableActionBar {
18+
19+
private val config get() = SkyHanniMod.feature.gui.actionBar
20+
21+
private var post = false
22+
23+
@HandleEvent(priority = HandleEvent.LOWEST)
24+
fun onRenderOverlayPre(event: GameOverlayRenderPreEvent) {
25+
if (event.type != RenderLayer.ACTION_BAR || !isEnabled()) return
26+
post = true
27+
DrawContextUtils.pushMatrix()
28+
val x = GuiScreenUtils.scaledWindowWidth / 2 - 91
29+
val y = GuiScreenUtils.scaledWindowHeight - 72
30+
config.position.transform()
31+
DrawContextUtils.translate(-x.toFloat(), -y.toFloat())
32+
GuiEditManager.add(config.position, "Action Bar", 182 - 1, 10 - 1)
33+
}
34+
35+
@HandleEvent(priority = HandleEvent.HIGHEST)
36+
fun onRenderOverlayPost(event: GameOverlayRenderPostEvent) {
37+
if (event.type != RenderLayer.ACTION_BAR || !post) return
38+
DrawContextUtils.popMatrix()
39+
post = false
40+
}
41+
42+
private fun isEnabled() = (SkyBlockUtils.inSkyBlock || (MinecraftCompat.localPlayerExists && config.showOutsideSkyblock)) &&
43+
config.enabled
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package at.hannibal2.skyhanni.features.gui
2+
3+
import at.hannibal2.skyhanni.SkyHanniMod
4+
import at.hannibal2.skyhanni.api.event.HandleEvent
5+
import at.hannibal2.skyhanni.api.minecraftevents.RenderLayer
6+
import at.hannibal2.skyhanni.data.GuiEditManager
7+
import at.hannibal2.skyhanni.events.render.gui.GameOverlayRenderPostEvent
8+
import at.hannibal2.skyhanni.events.render.gui.GameOverlayRenderPreEvent
9+
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
10+
import at.hannibal2.skyhanni.utils.RenderUtils.transform
11+
import at.hannibal2.skyhanni.utils.SkyBlockUtils
12+
import at.hannibal2.skyhanni.utils.compat.DrawContextUtils
13+
import at.hannibal2.skyhanni.utils.compat.GuiScreenUtils
14+
import at.hannibal2.skyhanni.utils.compat.MinecraftCompat
15+
16+
@SkyHanniModule
17+
object MovableHeldItemTooltip {
18+
19+
private val config get() = SkyHanniMod.feature.gui.heldItemTooltip
20+
21+
private var post = false
22+
23+
@HandleEvent(priority = HandleEvent.LOWEST)
24+
fun onRenderOverlayPre(event: GameOverlayRenderPreEvent) {
25+
if (event.type != RenderLayer.HELD_ITEM_TOOLTIP || !isEnabled()) return
26+
post = true
27+
DrawContextUtils.pushMatrix()
28+
val x = GuiScreenUtils.scaledWindowWidth / 2 - 91
29+
val y = GuiScreenUtils.scaledWindowHeight - 59
30+
config.position.transform()
31+
DrawContextUtils.translate(-x.toFloat(), -y.toFloat())
32+
GuiEditManager.add(config.position, "Held Item Tooltip", 182 - 1, 10 - 1)
33+
}
34+
35+
@HandleEvent(priority = HandleEvent.HIGHEST)
36+
fun onRenderOverlayPost(event: GameOverlayRenderPostEvent) {
37+
if (event.type != RenderLayer.HELD_ITEM_TOOLTIP || !post) return
38+
DrawContextUtils.popMatrix()
39+
post = false
40+
}
41+
42+
private fun isEnabled() = (SkyBlockUtils.inSkyBlock || (MinecraftCompat.localPlayerExists && config.showOutsideSkyblock)) &&
43+
config.enabled
44+
}

src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGui.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,27 @@ private void handleSubtitle(Component component, Operation<Void> original) {
104104
}
105105
}
106106

107+
@Inject(method = "renderSelectedItemName", at = @At("HEAD"), cancellable = true)
108+
public void renderSelectedItemNamePre(GuiGraphics context, CallbackInfo ci) {
109+
if (RenderEvents.postHeldItemTooltipLayerEventPre(context)) {
110+
ci.cancel();
111+
}
112+
}
113+
114+
@Inject(method = "renderSelectedItemName", at = @At("TAIL"))
115+
public void renderSelectedItemNamePost(GuiGraphics context, CallbackInfo ci) {
116+
RenderEvents.postHeldItemTooltipLayerEventPost(context);
117+
}
118+
119+
@Inject(method = "renderOverlayMessage", at = @At("HEAD"), cancellable = true)
120+
public void renderOverlayMessagePre(GuiGraphics context, DeltaTracker deltaTracker, CallbackInfo ci) {
121+
if (RenderEvents.postActionBarLayerEventPre(context)) {
122+
ci.cancel();
123+
}
124+
}
125+
126+
@Inject(method = "renderOverlayMessage", at = @At("TAIL"))
127+
public void renderOverlayMessagePost(GuiGraphics context, DeltaTracker deltaTracker, CallbackInfo ci) {
128+
RenderEvents.postActionBarLayerEventPost(context);
129+
}
107130
}

0 commit comments

Comments
 (0)