Skip to content

Commit

Permalink
workaround for incompatibility with REI which made tootips render und…
Browse files Browse the repository at this point in the history
…er RAI UI.
  • Loading branch information
blackd committed Jan 1, 2022
1 parent 4364912 commit c5a5625
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun Project.configureDependencies() {
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/releases/") }
maven { url = uri("https://maven.fabricmc.net/") }

maven { url = uri("https://maven.shedaniel.me") }
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* MixinGameRenderer
*/
@Mixin(GameRenderer.class)
@Mixin(value = GameRenderer.class, priority = 10000)
public class MixinGameRenderer {

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;" +
Expand Down
1 change: 1 addition & 0 deletions platforms/fabric-1.17/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:$loader_version")
modImplementation("com.terraformersmc:modmenu:$modmenu_version")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.40.1+1.17")
modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:6.3.358")
}

loom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* MixinGameRenderer
*/
@Mixin(GameRenderer.class)
@Mixin(value = GameRenderer.class, priority = 10000)
public class MixinGameRenderer {


Expand Down
1 change: 1 addition & 0 deletions platforms/fabric-1.18/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:$loader_version")
modImplementation("com.terraformersmc:modmenu:$modmenu_version")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.43.1+1.18")
modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:7.1.357")
}

loom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* MixinGameRenderer
*/
@Mixin(GameRenderer.class)
@Mixin(value = GameRenderer.class, priority = 10000)
public class MixinGameRenderer {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.anti_ad.mc.common.vanilla.glue.VanillaUtil
import org.anti_ad.mc.ipn.api.IPNButton
import org.anti_ad.mc.ipnext.config.GuiSettings
import org.anti_ad.mc.ipnext.event.LockSlotsHandler
import org.anti_ad.mc.ipnext.gui.inject.base.InsertableWidget
import org.anti_ad.mc.ipnext.inventory.ContainerClicker

object ContainerScreenEventHandler {
Expand Down Expand Up @@ -57,8 +58,8 @@ object ContainerScreenEventHandler {
fun onBackgroundRender() {
currentWidgets?.forEach {
(it as InsertableWidget).postBackgroundRender(VanillaUtil.mouseX(),
VanillaUtil.mouseY(),
VanillaUtil.lastFrameDuration())
VanillaUtil.mouseY(),
VanillaUtil.lastFrameDuration())
}
LockSlotsHandler.onBackgroundRender()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ import org.anti_ad.mc.common.gui.widgets.ButtonWidget
import org.anti_ad.mc.common.gui.widgets.Widget
import org.anti_ad.mc.common.integration.ButtonPositionHint
import org.anti_ad.mc.common.integration.HintsManager
import org.anti_ad.mc.common.math2d.Point
import org.anti_ad.mc.common.math2d.Rectangle
import org.anti_ad.mc.common.math2d.Size
import org.anti_ad.mc.common.vanilla.Vanilla
import org.anti_ad.mc.common.vanilla.alias.ContainerScreen
import org.anti_ad.mc.common.vanilla.alias.CreativeInventoryScreen
import org.anti_ad.mc.common.vanilla.alias.glue.I18n
import org.anti_ad.mc.common.vanilla.render.glue.IdentifierHolder
import org.anti_ad.mc.common.vanilla.render.glue.Sprite
import org.anti_ad.mc.common.vanilla.render.glue.rClearDepth
import org.anti_ad.mc.common.vanilla.render.glue.rDrawOutline
import org.anti_ad.mc.common.vanilla.render.glue.rDrawSprite
import org.anti_ad.mc.common.vanilla.render.glue.rStandardGlState
import org.anti_ad.mc.common.vanilla.render.opaque
import org.anti_ad.mc.ipn.api.IPNButton
Expand All @@ -34,26 +28,18 @@ import org.anti_ad.mc.ipnext.config.GuiSettings
import org.anti_ad.mc.ipnext.config.ModSettings
import org.anti_ad.mc.ipnext.config.SaveLoadManager
import org.anti_ad.mc.ipnext.event.ProfileSwitchHandler
import org.anti_ad.mc.ipnext.gui.inject.base.CheckBoxWidget
import org.anti_ad.mc.ipnext.gui.inject.base.InsertableWidget
import org.anti_ad.mc.ipnext.gui.inject.base.ProfileButtonWidget
import org.anti_ad.mc.ipnext.gui.inject.base.SortButtonWidget
import org.anti_ad.mc.ipnext.ingame.`(containerBounds)`
import org.anti_ad.mc.ipnext.ingame.`(isInventoryTab)`
import org.anti_ad.mc.ipnext.inventory.ContainerType.*
import org.anti_ad.mc.ipnext.inventory.ContainerTypes
import org.anti_ad.mc.ipnext.inventory.GeneralInventoryActions

private val TEXTURE = IdentifierHolder("inventoryprofilesnext",
"textures/gui/gui_buttons.png")


abstract class InsertableWidget: Widget() {

abstract fun postBackgroundRender(mouseX: Int,
mouseY: Int,
partialTicks: Float);

abstract val screen: ContainerScreen<*>

}

class ProfilesUICollectionWidget(override val screen: ContainerScreen<*>,
private val hints: ButtonPositionHint = HintsManager.hintFor(IPNButton.PROFILE_SELECTOR,
screen.javaClass)): InsertableWidget() {
Expand Down Expand Up @@ -388,108 +374,3 @@ class SortingButtonCollectionWidget(override val screen: ContainerScreen<*>) : I
}
}

class CheckBoxWidget : SortButtonWidget {
constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

var highlightTx = 0
var highlightTy = 0
var highlightTooltip: String = ""

override fun render(mouseX: Int,
mouseY: Int,
partialTicks: Float) {
val oldTx = tx
val oldTy = ty
val oldTooltipText = tooltipText
if (ModSettings.INCLUDE_HOTBAR_MODIFIER.isPressing()) {
tx = highlightTx
ty = highlightTy
tooltipText = highlightTooltip
}
super.render(mouseX,
mouseY,
partialTicks)
tx = oldTx
ty = oldTy
tooltipText = oldTooltipText
}
}

open class SortButtonWidget : TexturedButtonWidget {
constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

open var tx = 0
open var ty = 0
open var hints = HintsManager.zeroZero
open var tooltipText: String = ""
override val texture: IdentifierHolder
get() = TEXTURE
override val texturePt: Point
get() = Point(tx,
ty)
override val hoveringTexturePt: Point
get() = Point(tx,
ty + 10)

override fun render(mouseX: Int,
mouseY: Int,
partialTicks: Float) {
super.render(mouseX,
mouseY,
partialTicks)
if (GuiSettings.SHOW_BUTTON_TOOLTIPS.booleanValue && contains(mouseX,
mouseY) && tooltipText.isNotEmpty()) {
Tooltips.addTooltip(tooltipText,
mouseX,
mouseY)
}
}

init {
size = Size(10,
10)
}
}

abstract class TexturedButtonWidget : ButtonWidget {
constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

abstract val texture: IdentifierHolder
abstract val texturePt: Point
abstract val hoveringTexturePt: Point

override fun renderButton(hovered: Boolean) {
val textureLocation = if (hovered) hoveringTexturePt else texturePt
rDrawSprite(Sprite(texture,
Rectangle(textureLocation,
size)),
screenX,
screenY)
}

override fun mouseClicked(x: Int,
y: Int,
button: Int): Boolean {
return super.mouseClicked(x,y,button) && visible
}

}

private open class ProfileButtonWidget: SortButtonWidget {
constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

override fun mouseClicked(x: Int,
y: Int,
button: Int): Boolean {
return super.mouseClicked(x,y,button) && visible
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.anti_ad.mc.ipnext.gui.inject.base

import org.anti_ad.mc.ipnext.config.ModSettings

class CheckBoxWidget : SortButtonWidget {
constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

var highlightTx = 0
var highlightTy = 0
var highlightTooltip: String = ""

override fun render(mouseX: Int,
mouseY: Int,
partialTicks: Float) {
val oldTx = tx
val oldTy = ty
val oldTooltipText = tooltipText
if (ModSettings.INCLUDE_HOTBAR_MODIFIER.isPressing()) {
tx = highlightTx
ty = highlightTy
tooltipText = highlightTooltip
}
super.render(mouseX,
mouseY,
partialTicks)
tx = oldTx
ty = oldTy
tooltipText = oldTooltipText
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.anti_ad.mc.ipnext.gui.inject.base

import org.anti_ad.mc.common.gui.widgets.Widget
import org.anti_ad.mc.common.vanilla.alias.ContainerScreen

abstract class InsertableWidget: Widget() {

abstract fun postBackgroundRender(mouseX: Int,
mouseY: Int,
partialTicks: Float);

abstract val screen: ContainerScreen<*>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.anti_ad.mc.ipnext.gui.inject.base

open class ProfileButtonWidget: SortButtonWidget {
constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

override fun mouseClicked(x: Int,
y: Int,
button: Int): Boolean {
return super.mouseClicked(x,y,button) && visible
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.anti_ad.mc.ipnext.gui.inject.base

import org.anti_ad.mc.common.gui.Tooltips
import org.anti_ad.mc.common.math2d.Point
import org.anti_ad.mc.common.math2d.Size
import org.anti_ad.mc.common.vanilla.render.glue.IdentifierHolder
import org.anti_ad.mc.ipnext.config.GuiSettings

open class SortButtonWidget : TexturedButtonWidget {

companion object {
private val TEXTURE = IdentifierHolder("inventoryprofilesnext",
"textures/gui/gui_buttons.png")
}

init {
size = Size(10,
10)
}

constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

override val texture: IdentifierHolder
get() = TEXTURE

override val texturePt: Point
get() = Point(tx, ty)

override val hoveringTexturePt: Point
get() = Point(tx, ty + 10)

override fun render(mouseX: Int,
mouseY: Int,
partialTicks: Float) {
super.render(mouseX,
mouseY,
partialTicks)
if (GuiSettings.SHOW_BUTTON_TOOLTIPS.booleanValue && contains(mouseX,
mouseY) && tooltipText.isNotEmpty()) {
Tooltips.addTooltip(tooltipText,
mouseX,
mouseY)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.anti_ad.mc.ipnext.gui.inject.base

import org.anti_ad.mc.common.gui.widgets.ButtonWidget
import org.anti_ad.mc.common.integration.HintsManager
import org.anti_ad.mc.common.math2d.Point
import org.anti_ad.mc.common.math2d.Rectangle
import org.anti_ad.mc.common.vanilla.render.glue.IdentifierHolder
import org.anti_ad.mc.common.vanilla.render.glue.Sprite
import org.anti_ad.mc.common.vanilla.render.glue.rDrawSprite

abstract class TexturedButtonWidget : ButtonWidget {
constructor(clickEvent: (button: Int) -> Unit) : super(clickEvent)
constructor(clickEvent: () -> Unit) : super(clickEvent)
constructor() : super()

abstract val texture: IdentifierHolder
abstract val texturePt: Point
abstract val hoveringTexturePt: Point

open var tx = 0
open var ty = 0
open var hints = HintsManager.zeroZero
open var tooltipText: String = ""

override fun renderButton(hovered: Boolean) {
val textureLocation = if (hovered) hoveringTexturePt else texturePt
rDrawSprite(Sprite(texture,
Rectangle(textureLocation,
size)),
screenX,
screenY)
}

override fun mouseClicked(x: Int,
y: Int,
button: Int): Boolean {
return super.mouseClicked(x,y,button) && visible
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ object ContainerClicker {
return@map playerSlot.`(id)` to slot.`(topLeft)`
}.toMap()
}

private val highlights: MutableSet<Highlight> = ConcurrentHashMap.newKeySet()

private fun drawHighlight() {
val screen = Vanilla.screen() as? ContainerScreen<*> ?: return
val topLeft = screen.`(containerBounds)`.topLeft
Expand Down

0 comments on commit c5a5625

Please sign in to comment.