Unify player armor strip logic

This commit is contained in:
DBotThePony 2022-09-24 14:56:14 +07:00
parent fafa42b9b7
commit 2c037b755a
Signed by: DBot
GPG Key ID: DCC23B5715498507
6 changed files with 56 additions and 37 deletions

View File

@ -706,11 +706,8 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I
val playerStrip = EditablePanel(this, frame, height = 72f) val playerStrip = EditablePanel(this, frame, height = 72f)
playerStrip.dock = Dock.TOP playerStrip.dock = Dock.TOP
val armorStrip = EditablePanel(this, playerStrip, width = AbstractSlotPanel.SIZE) makeArmorStrip(menu.armorSlots, playerStrip).also {
armorStrip.dock = Dock.LEFT it.dock = Dock.LEFT
for (slot in menu.armorSlots) {
SlotPanel(this, armorStrip, slot).also { it.dock = Dock.TOP }
} }
EntityRendererPanel(this, playerStrip, minecraft!!.player!!).also { EntityRendererPanel(this, playerStrip, minecraft!!.player!!).also {

View File

@ -101,26 +101,8 @@ class ExoSuitInventoryScreen(menu: ExoSuitInventoryMenu) : MatteryScreen<ExoSuit
topLine.dock = Dock.TOP topLine.dock = Dock.TOP
topLine.setDockMargin(top = 3f) topLine.setDockMargin(top = 3f)
val armorSlotsStrip = EditablePanel(this, topLine, width = 18f) makeArmorStrip(menu.armorSlots, topLine).also {
armorSlotsStrip.dock = Dock.LEFT it.dock = Dock.LEFT
for (slot in menu.armorSlots) {
val cosmeticSlot = menu.cosmeticArmorSlots[slot.type]
if (cosmeticSlot == null) {
SlotPanel(this, armorSlotsStrip, slot).also {
it.dock = Dock.TOP
}
} else {
FoldableSlotPanel(this, armorSlotsStrip,
SlotPanel(this, null, slot).also {
CosmeticToggleButton(this, it, slot.type)
},
listOf(SlotPanel(this, null, cosmeticSlot))
).also {
it.dock = Dock.TOP
}
}
} }
val playerRectangle = EntityRendererPanel(this, topLine, minecraft!!.player!!) val playerRectangle = EntityRendererPanel(this, topLine, minecraft!!.player!!)

View File

@ -19,6 +19,7 @@ import org.lwjgl.opengl.GL13
import ru.dbotthepony.mc.otm.ClientConfig import ru.dbotthepony.mc.otm.ClientConfig
import ru.dbotthepony.mc.otm.client.moveMousePosScaled import ru.dbotthepony.mc.otm.client.moveMousePosScaled
import ru.dbotthepony.mc.otm.client.screen.panels.* import ru.dbotthepony.mc.otm.client.screen.panels.*
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleButton
import ru.dbotthepony.mc.otm.core.maxScrollDivision import ru.dbotthepony.mc.otm.core.maxScrollDivision
import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.MatteryMenu
import java.util.Collections import java.util.Collections
@ -533,6 +534,30 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
} }
} }
fun makeArmorStrip(slots: Collection<Pair<MatteryMenu.EquipmentSlot, Slot?>>, parent: EditablePanel<*>? = null): EditablePanel<*> {
val armorSlotsStrip = EditablePanel(this, parent, width = 18f)
armorSlotsStrip.dock = Dock.LEFT
for ((slot, cosmeticSlot) in slots) {
if (cosmeticSlot == null) {
SlotPanel(this, armorSlotsStrip, slot).also {
it.dock = Dock.TOP
}
} else {
FoldableSlotPanel(this, armorSlotsStrip,
SlotPanel(this, null, slot).also {
CosmeticToggleButton(this, it, slot.type)
},
listOf(SlotPanel(this, null, cosmeticSlot))
).also {
it.dock = Dock.TOP
}
}
}
return armorSlotsStrip
}
companion object { companion object {
const val DEFAULT_FRAME_WIDTH = AbstractSlotPanel.SIZE * 9f + 16f const val DEFAULT_FRAME_WIDTH = AbstractSlotPanel.SIZE * 9f + 16f
const val DEFAULT_FRAME_HEIGHT = 100f const val DEFAULT_FRAME_HEIGHT = 100f

View File

@ -117,13 +117,21 @@ class AndroidStationMenu @JvmOverloads constructor(
val armorSlots = makeArmorSlots() val armorSlots = makeArmorSlots()
init { init {
armorSlots.forEach(this::addSlot) for ((a, b) in armorSlots) {
addSlot(a)
if (b != null) addSlot(b)
}
addInventorySlots() addInventorySlots()
addSlot(androidBattery) addSlot(androidBattery)
val builder = ImmutableList.builder<Slot>() val builder = ImmutableList.builder<Slot>()
builder.addAll(armorSlots)
for ((a, _) in armorSlots) {
builder.add(a)
}
builder.add(androidBattery) builder.add(androidBattery)
storageSlots = builder.build() storageSlots = builder.build()
} }

View File

@ -51,7 +51,7 @@ class ExoSuitInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
} }
} }
val armorSlots: List<EquipmentSlot> = makeArmorSlots() val armorSlots: List<kotlin.Pair<EquipmentSlot, Slot?>> = makeArmorSlots()
val offhandSlot = object : InventorySlot(capability.ply.inventory, 40) { val offhandSlot = object : InventorySlot(capability.ply.inventory, 40) {
override fun getNoItemIcon(): Pair<ResourceLocation, ResourceLocation> { override fun getNoItemIcon(): Pair<ResourceLocation, ResourceLocation> {
@ -66,7 +66,11 @@ class ExoSuitInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
craftingSlots.forEach(this::addSlot) craftingSlots.forEach(this::addSlot)
addSlot(offhandSlot) addSlot(offhandSlot)
armorSlots.forEach(this::addSlot)
for ((a, b) in armorSlots) {
addSlot(a)
if (b != null) addSlot(b)
}
val builder = ImmutableList.builder<Slot>() val builder = ImmutableList.builder<Slot>()
@ -86,8 +90,6 @@ class ExoSuitInventoryMenu(val capability: MatteryPlayerCapability) : MatteryMen
} }
} }
val cosmeticArmorSlots: Map<net.minecraft.world.entity.EquipmentSlot, Slot> = ply.cosmeticArmorSlots?.also { it.values.forEach(this::addSlot) } ?: mapOf()
override fun slotsChanged(container: Container) { override fun slotsChanged(container: Container) {
super.slotsChanged(container) super.slotsChanged(container)

View File

@ -18,6 +18,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.Dock import ru.dbotthepony.mc.otm.client.screen.panels.Dock
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.SlotPanel
import ru.dbotthepony.mc.otm.compat.cos.cosmeticArmorSlots
import ru.dbotthepony.mc.otm.container.ItemFilter import ru.dbotthepony.mc.otm.container.ItemFilter
import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot import ru.dbotthepony.mc.otm.container.ItemFilterNetworkSlot
import ru.dbotthepony.mc.otm.menu.widget.AbstractWidget import ru.dbotthepony.mc.otm.menu.widget.AbstractWidget
@ -431,12 +432,16 @@ abstract class MatteryMenu @JvmOverloads protected constructor(
super.addDataSlots(p_38885_) super.addDataSlots(p_38885_)
} }
fun makeArmorSlots(): List<EquipmentSlot> = ImmutableList.of( fun makeArmorSlots(): List<kotlin.Pair<EquipmentSlot, Slot?>> {
EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.HEAD), val cosmetic = ply.cosmeticArmorSlots
EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.CHEST),
EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.LEGS), return ImmutableList.of(
EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.FEET), EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.HEAD) to cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.HEAD),
) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.CHEST) to cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.CHEST),
EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.LEGS) to cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.LEGS),
EquipmentSlot(net.minecraft.world.entity.EquipmentSlot.FEET) to cosmetic?.get(net.minecraft.world.entity.EquipmentSlot.FEET),
)
}
companion object { companion object {
val TEXTURE_EMPTY_SLOTS: List<ResourceLocation> = ImmutableList.of( val TEXTURE_EMPTY_SLOTS: List<ResourceLocation> = ImmutableList.of(