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

wardbobe #44

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 @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.createWardrobePriceLore
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.currentPage
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.currentWardrobeSlot
Expand Down Expand Up @@ -85,6 +86,12 @@ class CustomWardrobe {
}
}

@SubscribeEvent
fun onInventoryUpdate(event: InventoryUpdatedEvent) {
if (!isEnabled()) return
update()
}


private fun update() {
display = createRenderables()
Expand Down Expand Up @@ -140,7 +147,6 @@ class CustomWardrobe {
add(Triple(warningPos, warningRenderable, 0))
return@buildList
}

for (row in 0 until rows) {
val playersInRow =
if (row != rows - 1 || totalPlayers % maxPlayersPerRow == 0) maxPlayersPerRow else totalPlayers % maxPlayersPerRow
Expand Down Expand Up @@ -202,7 +208,6 @@ class CustomWardrobe {
hoveredSlot = wardrobeSlot.id
}
)
add(Triple(playerBackgroundPosition, playerBackground, wardrobeSlot.id))

val fakePlayer = getFakePlayer()

Expand All @@ -214,18 +219,19 @@ class CustomWardrobe {
Color.GRAY.withAlpha(100)
} else null

add(
Triple(
Position(playerX, playerY),
Renderable.entity(
fakePlayer,
config.eyesFollowMouse,
scale = scale.toInt(),
color = playerColor
),
wardrobeSlot.id
)
val playerRenderable = Renderable.player(
fakePlayer,
config.eyesFollowMouse,
width = containerWidth,
height = containerHeight,
entityScale = scale.toInt(),
padding = 0,
color = playerColor,
)

val slotRenderable = Renderable.doubleLayered(playerBackground, playerRenderable, false)

add(Triple(playerBackgroundPosition, slotRenderable, wardrobeSlot.id))
}
}
}
Expand All @@ -237,10 +243,10 @@ class CustomWardrobe {
}

private fun addButtons(screenWidth: Int, screenHeight: Int, playerHeight: Int) = buildList {
val buttonWidth = 25
val buttonWidth = 24
val centerX = screenWidth / 2
val buttonY = screenHeight / 2 + playerHeight / 2 + 30
val padding = 10
val xOffset = 10

val renderables = listOf(
createHoverableRenderable(
Expand Down Expand Up @@ -279,16 +285,19 @@ class CustomWardrobe {
Renderable.hoverTips(
Renderable.itemStack(
ItemStack(Items.arrow),
(buttonWidth - 1.5) / 15.5,
1.0,
0,
0
),
listOf("§aGo Back", " §7To SkyBlock Menu")
),
Renderable.itemStack(
ItemStack(Items.arrow),
(buttonWidth - 1.5) / 15.5,
0
1.0,
0,
0,
),
padding = 3,
hoveredColor = Color.BLACK,
borderOutlineThickness = 2,
onClick = {
Expand All @@ -301,16 +310,19 @@ class CustomWardrobe {
Renderable.hoverTips(
Renderable.itemStack(
ItemStack(Blocks.barrier),
(buttonWidth - 1.5) / 15.5,
0
1.0,
0,
0,
),
listOf("§cClose")
),
Renderable.itemStack(
ItemStack(Blocks.barrier),
(buttonWidth - 1.5) / 15.5,
0
1.0,
0,
0,
),
padding = 3,
hoveredColor = Color.BLACK,
borderOutlineThickness = 2,
onClick = {
Expand All @@ -320,11 +332,11 @@ class CustomWardrobe {
),
)

val totalWidth = renderables.sumOf { it.width } + (renderables.size - 1) * padding
val totalWidth = renderables.sumOf { it.width } + (renderables.size - 1) * xOffset
val startX = centerX - totalWidth / 2

for ((index, renderable) in renderables.withIndex()) {
add(Triple(Position(startX + index * (renderable.width + padding), buttonY), renderable, 0))
add(Triple(Position(startX + index * (renderable.width + xOffset), buttonY), renderable, 0))
}
}

Expand Down Expand Up @@ -378,6 +390,9 @@ class CustomWardrobe {
hoveredRenderable: Renderable,
unhoveredRenderable: Renderable = Renderable.placeholder(hoveredRenderable.width, hoveredRenderable.height),
topLayerRenderable: Renderable = Renderable.placeholder(0, 0),
padding: Int = 0,
horizontalAlignment: RenderUtils.HorizontalAlignment = RenderUtils.HorizontalAlignment.LEFT,
verticalAlignment: RenderUtils.VerticalAlignment = RenderUtils.VerticalAlignment.TOP,
hoveredColor: Color,
unHoveredColor: Color = hoveredColor,
borderOutlineThickness: Int,
Expand All @@ -394,16 +409,20 @@ class CustomWardrobe {
), topLayerRenderable
),
hoveredColor,
padding = 0,
padding = padding,
topOutlineColor = config.color.topBorderColor.toChromaColorInt(),
bottomOutlineColor = config.color.bottomBorderColor.toChromaColorInt(),
borderOutlineThickness = borderOutlineThickness,
blur = borderOutlineBlur
blur = borderOutlineBlur,
horizontalAlign = horizontalAlignment,
verticalAlign = verticalAlignment
),
Renderable.drawInsideRoundedRect(
unhoveredRenderable,
unHoveredColor,
padding = 0
padding = padding,
horizontalAlign = horizontalAlignment,
verticalAlign = verticalAlignment
),
onHover = { onHover() }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ object WardrobeAPI {
@SubscribeEvent
fun onInventoryUpdate(event: InventoryUpdatedEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!inWardrobe()) return

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

Expand Down
40 changes: 29 additions & 11 deletions src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.features.chroma.ChromaType
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.utils.ColorUtils
import at.hannibal2.skyhanni.utils.ColorUtils.darker
import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzLogger
Expand Down Expand Up @@ -319,6 +320,7 @@ interface Renderable {
fun doubleLayered(
bottomLayer: Renderable,
topLayer: Renderable,
blockBottomHover: Boolean = true,
) = object : Renderable {
override val width = bottomLayer.width
override val height = bottomLayer.height
Expand All @@ -327,7 +329,7 @@ interface Renderable {

override fun render(posX: Int, posY: Int) {
val (x, y) = topLayer.renderXYAligned(posX, posY, width, height)
val (posX, posY) = if (topLayer.isHovered(posX + x, posY + y)) {
val (posX, posY) = if (topLayer.isHovered(posX + x, posY + y) && blockBottomHover) {
bottomLayer.width + 1 to bottomLayer.height + 1
} else {
posX to posY
Expand Down Expand Up @@ -549,7 +551,7 @@ interface Renderable {
override val verticalAlign = [email protected]

override fun render(posX: Int, posY: Int) {
Gui.drawRect(0, 0, width, height, color.rgb)
Gui.drawRect(0, 0, width, height, color.withAlpha(100))
[email protected](posX, posY)
}

Expand Down Expand Up @@ -684,28 +686,44 @@ interface Renderable {
* The x and y coordinates are the bottom middle of the renderable.
* Don't ask me, ask Mojang.
*/
fun entity(
fun player(
entity: EntityLivingBase,
followMouse: Boolean = false,
eyesX: Float = 0f,
eyesY: Float = 0f,
scale: Int = 30,
width: Int = 50,
height: Int = 100,
entityScale: Int = 30,
padding: Int = 5,
color: Int? = null,
condition: () -> Boolean = { true },
colorCondition: () -> Boolean = { true },
) = object : Renderable {
override val width = scale
override val height = scale * 2
override val width = width + 2 * padding
override val height = height + 2 * padding
override val horizontalAlign = HorizontalAlignment.LEFT
override val verticalAlign = VerticalAlignment.TOP

override fun render(posX: Int, posY: Int) {
if (color != null) RenderLivingEntityHelper.setEntityColor(entity, color, condition)
val playerWidth = entityScale
val playerHeight = entityScale * 2
val playerX = posX + width / 2 + padding
val playerY = posY + height / 2 + playerHeight / 2 + padding

if (color != null) RenderLivingEntityHelper.setEntityColor(entity, color, colorCondition)
val mouse = currentRenderPassMousePosition
val mouseXRelativeToPlayer =
if (followMouse) (posX - (mouse?.first ?: Utils.getMouseX())).toFloat() else eyesX
if (followMouse) (playerX - (mouse?.first ?: Utils.getMouseX())).toFloat() else eyesX
val mouseYRelativeToPlayer =
if (followMouse) (posX - (mouse?.second ?: Utils.getMouseY()) - 1.62 * scale).toFloat() else eyesY
drawEntityOnScreen(posX, posY, scale, mouseXRelativeToPlayer, mouseYRelativeToPlayer, entity)
if (followMouse) (playerY - (mouse?.second
?: Utils.getMouseY()) - 1.62 * entityScale).toFloat() else eyesY
drawEntityOnScreen(
playerX,
playerY,
entityScale,
mouseXRelativeToPlayer,
mouseYRelativeToPlayer,
entity
)
}
}
}
Expand Down
Loading