Render handler of cosmetic armor switch button
This commit is contained in:
parent
2c037b755a
commit
cc268332f8
@ -5,8 +5,11 @@ import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
|
||||
import net.minecraft.client.gui.screens.inventory.InventoryScreen
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import ru.dbotthepony.mc.otm.client.render.element
|
||||
import ru.dbotthepony.mc.otm.client.screen.ExoSuitInventoryScreen
|
||||
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleRenderButton
|
||||
import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorLoaded
|
||||
|
||||
private fun calculateScale(width: Float, height: Float): Int {
|
||||
val aspectRatio = width / height
|
||||
@ -42,6 +45,12 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
|
||||
scissor = true
|
||||
}
|
||||
|
||||
init {
|
||||
if (entity is Player && isCosmeticArmorLoaded) {
|
||||
CosmeticToggleRenderButton(screen, this, x = this.width - 7f, y = this.height - 7f)
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
if (entity.isDeadOrDying) {
|
||||
return
|
||||
@ -59,6 +68,15 @@ class EntityRendererPanel<out S : Screen> @JvmOverloads constructor(
|
||||
entity
|
||||
)
|
||||
}
|
||||
|
||||
override fun performLayout() {
|
||||
super.performLayout()
|
||||
|
||||
val button = children.firstOrNull { it is CosmeticToggleRenderButton } as CosmeticToggleRenderButton? ?: return
|
||||
|
||||
button.x = this.width - 7f
|
||||
button.y = this.height - 7f
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.compat.cos
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import lain.mods.cos.impl.ModObjects
|
||||
import lain.mods.cos.impl.client.PlayerRenderHandler
|
||||
import lain.mods.cos.impl.client.gui.GuiCosArmorInventory
|
||||
import lain.mods.cos.impl.client.gui.GuiCosArmorToggleButton
|
||||
import lain.mods.cos.impl.network.packet.PacketSetSkinArmor
|
||||
@ -22,6 +23,8 @@ import ru.dbotthepony.mc.otm.client.render.element
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.AbstractSlotPanel
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||
import ru.dbotthepony.mc.otm.client.screen.panels.RectangleButtonPanel
|
||||
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton.Companion.BUTTON_ACTIVE
|
||||
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton.Companion.BUTTON_INACTIVE
|
||||
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
||||
|
||||
val isCosmeticArmorLoaded by lazy {
|
||||
@ -93,7 +96,7 @@ private val Screen.isCosmeticArmorScreenImpl: Boolean get() {
|
||||
|
||||
class CosmeticToggleButton<out S : Screen>(
|
||||
screen: S,
|
||||
parent: EditablePanel<S>? = null,
|
||||
parent: EditablePanel<*>?,
|
||||
index: EquipmentSlot,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
@ -129,9 +132,9 @@ class CosmeticToggleButton<out S : Screen>(
|
||||
val inv = ModObjects.invMan.getCosArmorInventoryClient(minecraft.player?.uuid ?: throw ConcurrentModificationException())
|
||||
|
||||
if (inv.isSkinArmor(index)) {
|
||||
BUTTON_ACTIVE.render(stack, x, y, width, height)
|
||||
BUTTON_ACTIVE.render(stack, width = width, height = height)
|
||||
} else {
|
||||
BUTTON_INACTIVE.render(stack, x, y, width, height)
|
||||
BUTTON_INACTIVE.render(stack, width = width, height = height)
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,3 +143,35 @@ class CosmeticToggleButton<out S : Screen>(
|
||||
val BUTTON_ACTIVE = GuiCosArmorInventory.TEXTURE.element(5f, 176f, 5f, 5f)
|
||||
}
|
||||
}
|
||||
|
||||
class CosmeticToggleRenderButton<out S : Screen>(
|
||||
screen: S,
|
||||
parent: EditablePanel<*>?,
|
||||
x: Float = 0f,
|
||||
y: Float = 0f,
|
||||
width: Float = 5f,
|
||||
height: Float = 5f
|
||||
) : RectangleButtonPanel<S>(screen, parent, x, y, width, height) {
|
||||
override val PRESSED: SkinElement
|
||||
get() = BUTTON_ACTIVE
|
||||
override val HOVERED: SkinElement
|
||||
get() = BUTTON_ACTIVE
|
||||
override val IDLE: SkinElement
|
||||
get() = BUTTON_INACTIVE
|
||||
override val DISABLED: SkinElement
|
||||
get() = BUTTON_INACTIVE
|
||||
|
||||
override fun onClick(clickButton: Int) {
|
||||
if (clickButton == InputConstants.MOUSE_BUTTON_LEFT) {
|
||||
PlayerRenderHandler.Disabled = !PlayerRenderHandler.Disabled
|
||||
}
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
if (PlayerRenderHandler.Disabled) {
|
||||
BUTTON_ACTIVE.render(stack, width = width, height = height)
|
||||
} else {
|
||||
BUTTON_INACTIVE.render(stack, width = width, height = height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user