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

wabrobbbdbdbbbbbbbbbbbbbbbbbbbbbbbbbd #60

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import at.hannibal2.skyhanni.features.dungeon.DungeonFloor;
import at.hannibal2.skyhanni.features.event.diana.DianaProfitTracker;
import at.hannibal2.skyhanni.features.event.diana.MythologicalCreatureTracker;
import at.hannibal2.skyhanni.features.event.hoppity.HoppityCollectionStats;
import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasureTracker;
import at.hannibal2.skyhanni.features.fishing.tracker.FishingProfitTracker;
import at.hannibal2.skyhanni.features.fishing.tracker.SeaCreatureTracker;
Expand Down Expand Up @@ -623,6 +622,7 @@ public static class WardrobeStorage {
public Map<Integer, WardrobeAPI.WardrobeData> wardrobeData = new HashMap<>();

@Expose
@Nullable
public Integer currentWardrobeSlot = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment
import at.hannibal2.skyhanni.utils.RenderUtils.VerticalAlignment
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiContainer
Expand All @@ -43,78 +44,36 @@ object CustomWardrobe {
private val config get() = SkyHanniMod.feature.inventory.customWardrobe

private var displayRenderable: Renderable? = null
private var buttonsRenderable: Renderable? = null
private var inventoryButton: Renderable? = null
private var editMode = false
private var waitingForInventoryUpdate = false
private var lastEditClick = SimpleTimeMark.farPast()

@SubscribeEvent
fun onGuiRender(event: GuiContainerEvent.BeforeDraw) {
if (!isEnabled() || editMode) return
event.cancel()
}

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent) {
if (!isEnabled()) return
val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return
if (editMode) { // Inventory Button for re-enabling the Custom Wardrobe
val renderable = inventoryButton ?: addReEnableButton().also { inventoryButton = it }
val accessorGui = gui as AccessorGuiContainer
val posX = accessorGui.guiLeft + (1.05 * accessorGui.width).toInt()
val posY = accessorGui.guiTop + (accessorGui.height - renderable.height) / 2
Position(posX, posY).renderRenderable(renderable, posLabel = "Custom Wardrobe", addToGuiManager = false)
return
}
val gui = event.gui
val renderable = displayRenderable ?: run {
update()
displayRenderable ?: return
}
val button = buttonsRenderable ?: return

val fullRenderable = Renderable.drawInsideRoundedRect(
Renderable.doubleLayered(
Renderable.verticalContainer(
listOf(renderable, button),
config.spacing.buttonSlotsVerticalSpacing,
horizontalAlign = HorizontalAlignment.CENTER
),
Renderable.clickable(
Renderable.string(
"§7SkyHanni",
horizontalAlign = HorizontalAlignment.RIGHT,
verticalAlign = VerticalAlignment.BOTTOM,
scale = 1.0 * (config.spacing.globalScale / 100.0)
).let { Renderable.hoverable(hovered = Renderable.underlined(it), unhovered = it) },
onClick = {
config::enabled.jumpToEditor()
reset()
currentPage = null
}
),
blockBottomHover = false
),
config.color.backgroundColor.toChromaColor(),
padding = 10
)

// Change global wardrobe scale if its taller or wider than the screen
if (fullRenderable.width > gui.width || fullRenderable.height > gui.height) {
if (renderable.width > gui.width || renderable.height > gui.height) {
if (config.spacing.globalScale <= 1) return
val newScale = (config.spacing.globalScale * (0.9 / max(
fullRenderable.width.toDouble() / gui.width,
fullRenderable.height.toDouble() / gui.height
renderable.width.toDouble() / gui.width,
renderable.height.toDouble() / gui.height
))).toInt()
config.spacing.globalScale = newScale
ChatUtils.clickableChat(
"Auto-set your Global Scale in custom wardrobe, as it was too tall/wide.",
onClick = { config::spacing.jumpToEditor() }
)
update()
return
}

val (width, height) = fullRenderable.width to fullRenderable.height
val (width, height) = renderable.width to renderable.height
val pos = Position((gui.width - width) / 2, (gui.height - height) / 2)
if (waitingForInventoryUpdate && config.loadingText) {
val loadingRenderable = Renderable.string("§cLoading...")
Expand All @@ -124,8 +83,21 @@ object CustomWardrobe {
}

GlStateManager.translate(0f, 0f, 100f)
pos.renderRenderable(fullRenderable, posLabel = "Custom Wardrobe", addToGuiManager = false)
pos.renderRenderable(renderable, posLabel = "Custom Wardrobe", addToGuiManager = false)
GlStateManager.translate(0f, 0f, -100f)
event.cancel()
}

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (!isEnabled()) return
if (!editMode) return
val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return
val renderable = inventoryButton ?: addReEnableButton().also { inventoryButton = it }
val accessorGui = gui as AccessorGuiContainer
val posX = accessorGui.guiLeft + (1.05 * accessorGui.width).toInt()
val posY = accessorGui.guiTop + (accessorGui.height - renderable.height) / 2
Position(posX, posY).renderRenderable(renderable, posLabel = "Custom Wardrobe", addToGuiManager = false)
}

@SubscribeEvent
Expand All @@ -144,9 +116,13 @@ object CustomWardrobe {
update()
}

@SubscribeEvent
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
if (lastEditClick.passedSince() < 50.milliseconds) event.cancel()
}

private fun update() {
displayRenderable = createRenderables()
buttonsRenderable = addButtons()
}

private fun createRenderables(): Renderable {
Expand Down Expand Up @@ -259,14 +235,40 @@ object CustomWardrobe {
horizontalAlign = HorizontalAlignment.CENTER
)

return allSlotsRenderable
val button = addButtons()

val fullRenderable = Renderable.drawInsideRoundedRect(
Renderable.doubleLayered(
Renderable.verticalContainer(
listOf(allSlotsRenderable, button),
config.spacing.buttonSlotsVerticalSpacing,
horizontalAlign = HorizontalAlignment.CENTER
),
Renderable.clickable(
Renderable.string(
"§7SkyHanni",
horizontalAlign = HorizontalAlignment.RIGHT,
verticalAlign = VerticalAlignment.BOTTOM,
scale = 1.0 * (config.spacing.globalScale / 100.0)
).let { Renderable.hoverable(hovered = Renderable.underlined(it), unhovered = it) },
onClick = {
config::enabled.jumpToEditor()
reset()
currentPage = null
}
),
blockBottomHover = false
),
config.color.backgroundColor.toChromaColor(),
padding = 10
)
return fullRenderable
}

private fun reset() {
inCustomWardrobe = false
editMode = false
displayRenderable = null
buttonsRenderable = null
inventoryButton = null
}

Expand Down Expand Up @@ -308,6 +310,7 @@ object CustomWardrobe {
"§bEdit",
onClick = {
reset()
lastEditClick = SimpleTimeMark.now()
editMode = true
}
)
Expand Down Expand Up @@ -337,6 +340,7 @@ object CustomWardrobe {
onClick = {
inCustomWardrobe = false
editMode = false
lastEditClick = SimpleTimeMark.now()
update()
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package at.hannibal2.skyhanni.features.inventory.wardrobe
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.inCustomWardrobe
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.inWardrobe
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.wardrobeSlots
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

Expand All @@ -17,10 +14,10 @@ class EstimatedWardrobePrice {
fun onTooltip(event: LorenzToolTipEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.armor) return
if (!inWardrobe()) return
if (inCustomWardrobe) return
if (!WardrobeAPI.inWardrobe()) return
if (WardrobeAPI.inCustomWardrobe) return

val slot = wardrobeSlots.firstOrNull {
val slot = WardrobeAPI.wardrobeSlots.firstOrNull {
event.slot.slotNumber == it.inventorySlot && it.isInCurrentPage()
} ?: return

Expand All @@ -32,9 +29,7 @@ class EstimatedWardrobePrice {
var index = 3

tooltip.add(index++, "")
lore.forEach {
tooltip.add(index++, it)
}
tooltip.addAll(index, lore)
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ object WardrobeAPI {
val chestplateSlot = FIRST_CHESTPLATE_SLOT + slot
val leggingsSlot = FIRST_LEGGINGS_SLOT + slot
val bootsSlot = FIRST_BOOTS_SLOT + slot
list.add(WardrobeSlot(id, page, inventorySlot, helmetSlot, chestplateSlot, leggingsSlot, bootsSlot))
id++
list.add(WardrobeSlot(++id, page, inventorySlot, helmetSlot, chestplateSlot, leggingsSlot, bootsSlot))
}
}
wardrobeSlots = list
Expand Down Expand Up @@ -169,11 +168,9 @@ object WardrobeAPI {
fun onInventoryUpdate(event: InventoryUpdatedEvent) {
if (!LorenzUtils.inSkyBlock) return

val inWardrobe = inventoryPattern.matchMatcher(event.inventoryName) {
inventoryPattern.matchMatcher(event.inventoryName) {
currentPage = group("currentPage").formatInt()
true
} ?: false
if (!inWardrobe) return
} ?: return
if (currentPage == null) return

val itemsList = event.inventoryItems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(RendererLivingEntity.class)
public class MixinRendererLivingEntity {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ object RenderUtils {
GlStateManager.pushMatrix()
val (x, y) = transform()
Renderable.withMousePosition(x, y) {
renderable.renderXAligned(0, 0, renderable.width)
renderable.render(0, 0)
}
GlStateManager.popMatrix()
if (addToGuiManager) GuiEditManager.add(this, posLabel, renderable.width, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned
import at.hannibal2.skyhanni.utils.shader.ShaderManager
import io.github.moulberry.notenoughupdates.util.Utils
import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
Expand Down Expand Up @@ -296,10 +295,8 @@ interface Renderable {
highlightsOnHoverSlots: List<Int> = emptyList(),
onHover: () -> Unit = {},
) = object : Renderable {
override val width: Int
get() = max(hovered.width, unhovered.width)
override val height: Int
get() = max(hovered.height, unhovered.height)
override val width = max(hovered.width, unhovered.width)
override val height = max(hovered.height, unhovered.height)
override val horizontalAlign get() = if (isHovered) hovered.horizontalAlign else unhovered.horizontalAlign
override val verticalAlign get() = if (isHovered) hovered.verticalAlign else unhovered.verticalAlign

Expand Down Expand Up @@ -562,14 +559,14 @@ interface Renderable {
}

// TODO use this to render current boosted crop in next jacob contest crops
fun Renderable.renderBounds(color: Color = LorenzColor.GREEN.toColor()) = object : Renderable {
fun Renderable.renderBounds(color: Int = LorenzColor.GREEN.toColor().withAlpha(100)) = object : Renderable {
override val width = this@renderBounds.width
override val height = this@renderBounds.height
override val horizontalAlign = this@renderBounds.horizontalAlign
override val verticalAlign = this@renderBounds.verticalAlign

override fun render(posX: Int, posY: Int) {
Gui.drawRect(0, 0, width, height, color.withAlpha(100))
Gui.drawRect(0, 0, width, height, color)
this@renderBounds.render(posX, posY)
}

Expand Down Expand Up @@ -854,16 +851,14 @@ interface Renderable {
val playerY = height / 2 + playerHeight / 2 + padding

override fun render(posX: Int, posY: Int) {

GlStateManager.color(1f, 1f, 1f, 1f)
if (color != null) RenderLivingEntityHelper.setEntityColor(player, color, colorCondition)
val mouse = currentRenderPassMousePosition
val mouse = currentRenderPassMousePosition ?: return
val mouseXRelativeToPlayer =
if (followMouse) (posX + playerX - (mouse?.first ?: Utils.getMouseX())).toFloat() else eyesX
if (followMouse) (posX + playerX - mouse.first).toFloat() else eyesX
val mouseYRelativeToPlayer =
if (followMouse) (posY + playerY - (mouse?.second
?: Utils.getMouseY()) - 1.62 * entityScale).toFloat() else eyesY
GlStateManager.translate(0f, 0f, 500f)
if (followMouse) (posY + playerY - mouse.second - 1.62 * entityScale).toFloat() else eyesY
GlStateManager.translate(0f, 0f, 100f)
drawEntityOnScreen(
playerX,
playerY,
Expand All @@ -872,7 +867,7 @@ interface Renderable {
mouseYRelativeToPlayer,
player
)
GlStateManager.translate(0f, 0f, -500f)
GlStateManager.translate(0f, 0f, -100f)
}
}
}
Expand Down
Loading