Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
bfcb941f0f
@ -486,7 +486,7 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun insertStack(stack: ItemStackWrapper, simulate: Boolean): ItemStackWrapper {
|
override fun insertStack(stack: ItemStackWrapper, simulate: Boolean): ItemStackWrapper {
|
||||||
if (energy.batteryLevel.isZero || !filter.match(stack.item))
|
if (redstoneControl.isBlockedByRedstone || energy.batteryLevel.isZero || !filter.match(stack.item))
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
val maxPossibleDemand = ITEM_STORAGE.energyPerOperation * stack.count
|
val maxPossibleDemand = ITEM_STORAGE.energyPerOperation * stack.count
|
||||||
@ -531,7 +531,7 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun extractStack(id: UUID, amount: BigInteger, simulate: Boolean): ItemStackWrapper {
|
override fun extractStack(id: UUID, amount: BigInteger, simulate: Boolean): ItemStackWrapper {
|
||||||
if (!amount.isPositive)
|
if (redstoneControl.isBlockedByRedstone || !amount.isPositive)
|
||||||
return ItemStackWrapper.EMPTY
|
return ItemStackWrapper.EMPTY
|
||||||
|
|
||||||
val maxPossibleDemand = ITEM_STORAGE.energyPerOperation * amount
|
val maxPossibleDemand = ITEM_STORAGE.energyPerOperation * amount
|
||||||
|
@ -194,7 +194,7 @@ class StorageImporterBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun insertItem(slot: Int, stack: ItemStack, simulate: Boolean): ItemStack {
|
override fun insertItem(slot: Int, stack: ItemStack, simulate: Boolean): ItemStack {
|
||||||
if (!filter.match(stack))
|
if (redstoneControl.isBlockedByRedstone || !filter.match(stack))
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
val view = cell.storageGraph?.getVirtualComponent(ITEM_STORAGE) ?: return stack
|
val view = cell.storageGraph?.getVirtualComponent(ITEM_STORAGE) ?: return stack
|
||||||
@ -225,6 +225,9 @@ class StorageImporterBlockEntity(blockPos: BlockPos, blockState: BlockState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tick() {
|
fun tick() {
|
||||||
|
if (redstoneControl.isBlockedByRedstone)
|
||||||
|
return
|
||||||
|
|
||||||
batteryChargeLoop()
|
batteryChargeLoop()
|
||||||
cell.tickEnergyDemanding()
|
cell.tickEnergyDemanding()
|
||||||
|
|
||||||
@ -334,6 +337,9 @@ class StorageExporterBlockEntity(blockPos: BlockPos, blockState: BlockState) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tick() {
|
fun tick() {
|
||||||
|
if (redstoneControl.isBlockedByRedstone)
|
||||||
|
return
|
||||||
|
|
||||||
batteryChargeLoop()
|
batteryChargeLoop()
|
||||||
cell.tickEnergyDemanding()
|
cell.tickEnergyDemanding()
|
||||||
|
|
||||||
|
@ -76,6 +76,9 @@ class StoragePowerSupplierBlockEntity(blockPos: BlockPos, blockState: BlockState
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tick() {
|
fun tick() {
|
||||||
|
if (redstoneControl.isBlockedByRedstone)
|
||||||
|
return
|
||||||
|
|
||||||
batteryChargeLoop()
|
batteryChargeLoop()
|
||||||
|
|
||||||
if (energy.batteryLevel.isZero)
|
if (energy.batteryLevel.isZero)
|
||||||
|
@ -145,6 +145,9 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
|
|||||||
override val energyFlow = FlowDirection.input(isInput)
|
override val energyFlow = FlowDirection.input(isInput)
|
||||||
|
|
||||||
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
|
if (redstoneControl.isBlockedByRedstone)
|
||||||
|
return Decimal.ZERO
|
||||||
|
|
||||||
val it = inputCapability.first
|
val it = inputCapability.first
|
||||||
|
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
@ -170,6 +173,9 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
|
||||||
|
if (redstoneControl.isBlockedByRedstone)
|
||||||
|
return Decimal.ZERO
|
||||||
|
|
||||||
val it = outputCapability.first
|
val it = outputCapability.first
|
||||||
|
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
|
@ -133,6 +133,9 @@ class EnergyServoBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matte
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun tick() {
|
fun tick() {
|
||||||
|
if (redstoneControl.isBlockedByRedstone)
|
||||||
|
return
|
||||||
|
|
||||||
val charge = container[SLOT_CHARGE]
|
val charge = container[SLOT_CHARGE]
|
||||||
val discharge = container[SLOT_DISCHARGE]
|
val discharge = container[SLOT_DISCHARGE]
|
||||||
|
|
||||||
|
@ -22,9 +22,6 @@ data class MatteryAtlas(
|
|||||||
winding: UVWindingOrder = this.winding,
|
winding: UVWindingOrder = this.winding,
|
||||||
) = MatterySprite(texture, x = x, y = y, width = width, height = height, atlasHeight = this.height, atlasWidth = this.width, winding = winding)
|
) = MatterySprite(texture, x = x, y = y, width = width, height = height, atlasHeight = this.height, atlasWidth = this.width, winding = winding)
|
||||||
|
|
||||||
@Deprecated("Construct grid directly instead")
|
|
||||||
fun grid(rows: Int, columns: Int) = GridAtlas(texture, this.width / rows, this.height / columns, rows = rows, columns = columns)
|
fun grid(rows: Int, columns: Int) = GridAtlas(texture, this.width / rows, this.height / columns, rows = rows, columns = columns)
|
||||||
|
|
||||||
@Deprecated("Construct grid directly instead")
|
|
||||||
fun grid(width: Float, height: Float, rows: Int, columns: Int) = GridAtlas(texture, width, height, rows, columns)
|
fun grid(width: Float, height: Float, rows: Int, columns: Int) = GridAtlas(texture, width, height, rows, columns)
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,5 @@ object WidgetLocation {
|
|||||||
val PROGRESS_ARROWS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/progress_arrows.png"), 22f, 31f)
|
val PROGRESS_ARROWS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/progress_arrows.png"), 22f, 31f)
|
||||||
val HORIZONTAL_GAUGES = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/horizontal_gauges.png"), 96f, 54f)
|
val HORIZONTAL_GAUGES = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/horizontal_gauges.png"), 96f, 54f)
|
||||||
val VERTICAL_GAUGES = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/vertical_gauges.png"), 90f, 48f)
|
val VERTICAL_GAUGES = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/vertical_gauges.png"), 90f, 48f)
|
||||||
|
val REDSTONE_CONTROLS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/redstone.png"), 54f, 18f)
|
||||||
}
|
}
|
||||||
|
@ -46,4 +46,10 @@ object Widgets18 {
|
|||||||
val BUTTON_DISABLED_STRETCHABLE = makeButton(GRID)
|
val BUTTON_DISABLED_STRETCHABLE = makeButton(GRID)
|
||||||
val BUTTON_DISABLED = GRID.next()
|
val BUTTON_DISABLED = GRID.next()
|
||||||
val COOLDOWN = GRID.next()
|
val COOLDOWN = GRID.next()
|
||||||
|
|
||||||
|
private val redstoneGrid = WidgetLocation.REDSTONE_CONTROLS.grid(rows = 1, columns = 3)
|
||||||
|
|
||||||
|
val REDSTONE_IGNORED = redstoneGrid.next()
|
||||||
|
val REDSTONE_LOW = redstoneGrid.next()
|
||||||
|
val REDSTONE_HIGH = redstoneGrid.next()
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context)
|
|||||||
|
|
||||||
poseStack.pushPose()
|
poseStack.pushPose()
|
||||||
poseStack.rotateWithBlockFacing(tile.blockState.rotationThree)
|
poseStack.rotateWithBlockFacing(tile.blockState.rotationThree)
|
||||||
poseStack.translate(0.5f, 0.5f, 0.6f)
|
poseStack.translate(0.5f, 0.5f, 0.5f)
|
||||||
poseStack.scale(0.01f, 0.01f, 0.01f)
|
poseStack.scale(0.01f, 0.01f, 0.01f)
|
||||||
|
|
||||||
val sorse = DynamicBufferSource.WORLD
|
val sorse = DynamicBufferSource.WORLD
|
||||||
|
@ -11,6 +11,7 @@ import net.minecraft.client.renderer.entity.ItemRenderer
|
|||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.inventory.Slot
|
import net.minecraft.world.inventory.Slot
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraftforge.client.event.ContainerScreenEvent.Render.Background
|
import net.minecraftforge.client.event.ContainerScreenEvent.Render.Background
|
||||||
import net.minecraftforge.client.event.ContainerScreenEvent.Render.Foreground
|
import net.minecraftforge.client.event.ContainerScreenEvent.Render.Foreground
|
||||||
import net.minecraftforge.common.MinecraftForge
|
import net.minecraftforge.common.MinecraftForge
|
||||||
@ -62,6 +63,40 @@ abstract class MatteryScreen<T : MatteryMenu>(menu: T, inventory: Inventory, tit
|
|||||||
val quickCraftingType get() = quickCraftingType
|
val quickCraftingType get() = quickCraftingType
|
||||||
val isQuickCrafting get() = isQuickCrafting
|
val isQuickCrafting get() = isQuickCrafting
|
||||||
|
|
||||||
|
fun renderItemStack(absoluteX: Float, absoluteY: Float, itemstack: ItemStack, countOverride: String? = null) {
|
||||||
|
if (!itemstack.isEmpty) {
|
||||||
|
RenderSystem.enableDepthTest()
|
||||||
|
|
||||||
|
val systemPoseStack = RenderSystem.getModelViewStack()
|
||||||
|
|
||||||
|
systemPoseStack.pushPose()
|
||||||
|
systemPoseStack.translate(absoluteX + 1f, absoluteY + 1f, 0f)
|
||||||
|
RenderSystem.applyModelViewMatrix()
|
||||||
|
RenderSystem.depthFunc(GL11.GL_LESS)
|
||||||
|
|
||||||
|
// Thanks Mojang
|
||||||
|
// Very cool
|
||||||
|
// (for int x, int y, which are then cast into doubles anyway)
|
||||||
|
itemRenderer.blitOffset = 1f // Z pos
|
||||||
|
|
||||||
|
itemRenderer.renderAndDecorateItem(
|
||||||
|
requireNotNull(ru.dbotthepony.mc.otm.client.minecraft.player) { "yo, dude, what the fuck" },
|
||||||
|
itemstack,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
(absoluteX + absoluteY * 1000f).toInt()
|
||||||
|
)
|
||||||
|
|
||||||
|
RenderSystem.depthFunc(GL11.GL_ALWAYS)
|
||||||
|
itemRenderer.renderGuiItemDecorations(font, itemstack, 0, 0, countOverride)
|
||||||
|
itemRenderer.blitOffset = 0f
|
||||||
|
|
||||||
|
// too big accumulations can lead to Z near clipping issues
|
||||||
|
systemPoseStack.popPose()
|
||||||
|
RenderSystem.applyModelViewMatrix()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (slot in menu.slots) {
|
for (slot in menu.slots) {
|
||||||
slot.x = Int.MAX_VALUE
|
slot.x = Int.MAX_VALUE
|
||||||
|
@ -7,6 +7,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.Dock
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
|
import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkedStringInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkedStringInputPanel
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu
|
import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu
|
||||||
@ -24,6 +25,8 @@ class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component)
|
|||||||
lock.dockMargin = DockProperty(2f, 2f, 2f, 2f)
|
lock.dockMargin = DockProperty(2f, 2f, 2f, 2f)
|
||||||
lock.tooltip = TranslatableComponent("otm.gui.lock_holo_screen.tip")
|
lock.tooltip = TranslatableComponent("otm.gui.lock_holo_screen.tip")
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
|||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.ButtonPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.ButtonPanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.MatterCapacitorSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.MatterCapacitorSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
||||||
@ -37,10 +38,11 @@ class MatterBottlerScreen(menu: MatterBottlerMenu, inventory: Inventory, title:
|
|||||||
progress = ProgressGaugePanel(this, frame, menu.progressWidget, 90f, PROGRESS_ARROW_TOP)
|
progress = ProgressGaugePanel(this, frame, menu.progressWidget, 90f, PROGRESS_ARROW_TOP)
|
||||||
|
|
||||||
if (minecraft?.player?.isSpectator != true) {
|
if (minecraft?.player?.isSpectator != true) {
|
||||||
val mode = ButtonPanel(this, frame, 46f, 69f, 100f, 20f, TranslatableComponent("otm.matter_bottler.switch_mode"))
|
ButtonPanel(this, frame, 46f, 69f, 100f, 20f, TranslatableComponent("otm.matter_bottler.switch_mode"), onPress = menu.workFlow::switchValue)
|
||||||
mode.bind { menu.workFlow.switchValue() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
||||||
@ -27,6 +28,8 @@ class MatterDecomposerScreen(p_97741_: MatterDecomposerMenu, p_97742_: Inventory
|
|||||||
SlotPanel(this, frame, menu.outputMain, 74f, PROGRESS_SLOT_TOP)
|
SlotPanel(this, frame, menu.outputMain, 74f, PROGRESS_SLOT_TOP)
|
||||||
SlotPanel(this, frame, menu.outputStacking, 56f, PROGRESS_SLOT_TOP)
|
SlotPanel(this, frame, menu.outputStacking, 56f, PROGRESS_SLOT_TOP)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ class MatterPanelScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (minecraft?.player?.isSpectator != true) {
|
if (minecraft?.player?.isSpectator != true) {
|
||||||
ButtonPanel(this@MatterPanelScreen, frame, width = 80f, label = TranslatableComponent("otm.container.matter_panel.cancel_task"), onPress = {
|
ButtonPanel(this@MatterPanelScreen, frame, width = 80f, label = TranslatableComponent("otm.container.matter_panel.cancel_task"), onPress = Runnable {
|
||||||
menu.requestTaskCancel(task.id)
|
menu.requestTaskCancel(task.id)
|
||||||
frame.remove()
|
frame.remove()
|
||||||
}).also {
|
}).also {
|
||||||
@ -259,32 +259,32 @@ class MatterPanelScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 8), onPress = { input.increase(8) }).also {
|
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 8), onPress = Runnable { input.increase(8) }).also {
|
||||||
it.dock = Dock.RIGHT
|
it.dock = Dock.RIGHT
|
||||||
it.dockLeft = 2f
|
it.dockLeft = 2f
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 64), onPress = { input.increase(64) }).also {
|
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 64), onPress = Runnable { input.increase(64) }).also {
|
||||||
it.dock = Dock.RIGHT
|
it.dock = Dock.RIGHT
|
||||||
it.dockLeft = 2f
|
it.dockLeft = 2f
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 256), onPress = { input.increase(256) }).also {
|
ButtonPanel(this, rowTop, width = 40f, label = TranslatableComponent("otm.container.matter_panel.increase_by", 256), onPress = Runnable { input.increase(256) }).also {
|
||||||
it.dock = Dock.RIGHT
|
it.dock = Dock.RIGHT
|
||||||
it.dockLeft = 2f
|
it.dockLeft = 2f
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 8), onPress = { input.increase(-8) }).also {
|
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 8), onPress = Runnable { input.increase(-8) }).also {
|
||||||
it.dock = Dock.RIGHT
|
it.dock = Dock.RIGHT
|
||||||
it.dockLeft = 2f
|
it.dockLeft = 2f
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 64), onPress = { input.increase(-64) }).also {
|
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 64), onPress = Runnable { input.increase(-64) }).also {
|
||||||
it.dock = Dock.RIGHT
|
it.dock = Dock.RIGHT
|
||||||
it.dockLeft = 2f
|
it.dockLeft = 2f
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 256), onPress = { input.increase(-256) }).also {
|
ButtonPanel(this, rowBottom, width = 40f, label = TranslatableComponent("otm.container.matter_panel.decrease_by", 256), onPress = Runnable { input.increase(-256) }).also {
|
||||||
it.dock = Dock.RIGHT
|
it.dock = Dock.RIGHT
|
||||||
it.dockLeft = 2f
|
it.dockLeft = 2f
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
||||||
@ -23,6 +24,8 @@ class MatterRecyclerScreen(menu: MatterRecyclerMenu, inventory: Inventory, title
|
|||||||
ProgressGaugePanel(this, frame, menu.progress, 63f, PROGRESS_ARROW_TOP).flop = true
|
ProgressGaugePanel(this, frame, menu.progress, 63f, PROGRESS_ARROW_TOP).flop = true
|
||||||
SlotPanel(this, frame, menu.input, 93f, PROGRESS_SLOT_TOP)
|
SlotPanel(this, frame, menu.input, 93f, PROGRESS_SLOT_TOP)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.MatterGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
||||||
@ -29,6 +30,8 @@ class MatterReplicatorScreen(p_97741_: MatterReplicatorMenu, p_97742_: Inventory
|
|||||||
SlotPanel(this, frame, menu.storageSlots[3], 80f, PROGRESS_SLOT_TOP + 22f)
|
SlotPanel(this, frame, menu.storageSlots[3], 80f, PROGRESS_SLOT_TOP + 22f)
|
||||||
SlotPanel(this, frame, menu.storageSlots[4], 80f + 18f, PROGRESS_SLOT_TOP + 22f)
|
SlotPanel(this, frame, menu.storageSlots[4], 80f + 18f, PROGRESS_SLOT_TOP + 22f)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.PatternGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.PatternGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
||||||
@ -24,6 +25,8 @@ class MatterScannerScreen(p_97741_: MatterScannerMenu, p_97742_: Inventory, p_97
|
|||||||
ProgressGaugePanel(this, frame, menu.progress, 63f, PROGRESS_ARROW_TOP).flop = true
|
ProgressGaugePanel(this, frame, menu.progress, 63f, PROGRESS_ARROW_TOP).flop = true
|
||||||
SlotPanel(this, frame, menu.input, 93f, PROGRESS_SLOT_TOP)
|
SlotPanel(this, frame, menu.input, 93f, PROGRESS_SLOT_TOP)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.client.screen.panels.button
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants
|
||||||
|
import net.minecraft.client.gui.screens.Screen
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
|
import java.util.function.IntConsumer
|
||||||
|
import java.util.function.IntPredicate
|
||||||
|
|
||||||
|
abstract class AbstractButtonPanel<out S : Screen>(
|
||||||
|
screen: S,
|
||||||
|
parent: EditablePanel<*>?,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
width: Float = 10f,
|
||||||
|
height: Float = 10f,
|
||||||
|
) : EditablePanel<S>(screen, parent, x, y, width, height), IntPredicate {
|
||||||
|
var isPressed = false
|
||||||
|
protected set
|
||||||
|
|
||||||
|
open var isDisabled = false
|
||||||
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
|
if (!value) {
|
||||||
|
isPressed = false
|
||||||
|
grabMouseInput = false
|
||||||
|
}
|
||||||
|
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun test(value: Int): Boolean {
|
||||||
|
return value == InputConstants.MOUSE_BUTTON_LEFT
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun onClick(mouseButton: Int)
|
||||||
|
|
||||||
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
|
if (isDisabled || isPressed || !test(button)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tryToGrabMouseInput()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
isPressed = true
|
||||||
|
playGuiClickSound()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
|
if (!isPressed || !test(button)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
grabMouseInput = false
|
||||||
|
isPressed = false
|
||||||
|
|
||||||
|
if (isHovered) {
|
||||||
|
onClick(button)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
@ -20,12 +20,10 @@ abstract class BooleanRectangleButtonPanel<out S : Screen>(
|
|||||||
val skinElementInactive: AbstractMatterySprite? = null,
|
val skinElementInactive: AbstractMatterySprite? = null,
|
||||||
val onChange: ((newValue: Boolean) -> Unit)? = null,
|
val onChange: ((newValue: Boolean) -> Unit)? = null,
|
||||||
) : RectangleButtonPanel<S>(screen, parent, x, y, width, height, null) {
|
) : RectangleButtonPanel<S>(screen, parent, x, y, width, height, null) {
|
||||||
override fun onClick(clickButton: Int) {
|
override fun onClick(mouseButton: Int) {
|
||||||
if (clickButton == InputConstants.MOUSE_BUTTON_LEFT) {
|
val newValue = !prop.value
|
||||||
val newValue = !prop.value
|
prop.value = newValue
|
||||||
prop.value = newValue
|
onChange?.invoke(newValue)
|
||||||
onChange?.invoke(newValue)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
|
@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.client.render.Widgets18
|
|||||||
import ru.dbotthepony.mc.otm.client.render.drawAligned
|
import ru.dbotthepony.mc.otm.client.render.drawAligned
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
import ru.dbotthepony.mc.otm.core.math.RGBAColor
|
||||||
|
import java.util.function.IntConsumer
|
||||||
|
|
||||||
open class ButtonPanel<out S : Screen>(
|
open class ButtonPanel<out S : Screen>(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -17,9 +18,10 @@ open class ButtonPanel<out S : Screen>(
|
|||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = 40f,
|
width: Float = 40f,
|
||||||
height: Float = HEIGHT,
|
height: Float = HEIGHT,
|
||||||
var label: Component
|
var label: Component,
|
||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
var onPress: IntConsumer? = null
|
||||||
constructor(screen: S, parent: EditablePanel<*>?, label: Component) : this(screen, parent, x = 0f, label = label)
|
) : AbstractButtonPanel<S>(screen, parent, x, y, width, height) {
|
||||||
|
constructor(screen: S, parent: EditablePanel<*>?, label: Component, onPress: IntConsumer? = null) : this(screen, parent, x = 0f, label = label, onPress = onPress)
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -30,75 +32,28 @@ open class ButtonPanel<out S : Screen>(
|
|||||||
height: Float = HEIGHT,
|
height: Float = HEIGHT,
|
||||||
label: Component,
|
label: Component,
|
||||||
onPress: Runnable
|
onPress: Runnable
|
||||||
) : this(screen, parent, x, y, width, height, label) {
|
) : this(screen, parent, x, y, width, height, label, onPress = IntConsumer { onPress.run() })
|
||||||
this.callback = onPress
|
|
||||||
}
|
|
||||||
|
|
||||||
protected var callback: Runnable? = null
|
|
||||||
protected var pressed = false
|
|
||||||
|
|
||||||
protected open fun onClick(button: Int) {
|
|
||||||
callback?.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
|
||||||
if (isDisabled || pressed) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tryToGrabMouseInput()) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
pressed = true
|
|
||||||
playGuiClickSound()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
|
||||||
if (!pressed) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
grabMouseInput = false
|
|
||||||
pressed = false
|
|
||||||
|
|
||||||
if (isHovered) {
|
|
||||||
onClick(button)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
fun bind(runnable: Runnable) {
|
|
||||||
callback = runnable
|
|
||||||
}
|
|
||||||
|
|
||||||
var textColor = RGBAColor.WHITE
|
var textColor = RGBAColor.WHITE
|
||||||
|
|
||||||
var isDisabled = false
|
override fun onClick(mouseButton: Int) {
|
||||||
set(value) {
|
onPress?.accept(mouseButton)
|
||||||
if (field != value) {
|
}
|
||||||
if (!value) {
|
|
||||||
pressed = false
|
|
||||||
grabMouseInput = false
|
|
||||||
}
|
|
||||||
|
|
||||||
field = value
|
protected fun renderStretchableBackground(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
|
||||||
if (isDisabled) {
|
if (isDisabled) {
|
||||||
Widgets18.BUTTON_DISABLED_STRETCHABLE.render(stack, width = width, height = height)
|
Widgets18.BUTTON_DISABLED_STRETCHABLE.render(stack, width = width, height = height)
|
||||||
} else if (pressed) {
|
} else if (isPressed) {
|
||||||
Widgets18.BUTTON_PRESSED_STRETCHABLE.render(stack, width = width, height = height)
|
Widgets18.BUTTON_PRESSED_STRETCHABLE.render(stack, width = width, height = height)
|
||||||
} else if (isHovered) {
|
} else if (isHovered) {
|
||||||
Widgets18.BUTTON_HOVERED_STRETCHABLE.render(stack, width = width, height = height)
|
Widgets18.BUTTON_HOVERED_STRETCHABLE.render(stack, width = width, height = height)
|
||||||
} else {
|
} else {
|
||||||
Widgets18.BUTTON_IDLE_STRETCHABLE.render(stack, width = width, height = height)
|
Widgets18.BUTTON_IDLE_STRETCHABLE.render(stack, width = width, height = height)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
|
renderStretchableBackground(stack, mouseX, mouseY, partialTick)
|
||||||
font.drawAligned(stack, label, TextAlign.CENTER_CENTER, width / 2f, height / 2f, textColor.toInt())
|
font.drawAligned(stack, label, TextAlign.CENTER_CENTER, width / 2f, height / 2f, textColor.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.client.screen.panels.button
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import net.minecraft.world.item.Items
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
|
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
|
||||||
|
|
||||||
|
fun <S : MatteryScreen<*>> makeRedstoneSettingButton(
|
||||||
|
screen: S,
|
||||||
|
parent: EditablePanel<*>?,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
control: IPlayerInputWithFeedback<RedstoneSetting>
|
||||||
|
): LargeEnumRectangleButtonPanel<S, RedstoneSetting> {
|
||||||
|
return object : LargeEnumRectangleButtonPanel<S, RedstoneSetting>(
|
||||||
|
screen, parent, x = x, y = y,
|
||||||
|
defaultValue = RedstoneSetting.LOW, enum = RedstoneSetting::class.java,
|
||||||
|
prop = control,
|
||||||
|
) {
|
||||||
|
override var isDisabled: Boolean
|
||||||
|
get() = !control.test(minecraft.player)
|
||||||
|
set(value) {}
|
||||||
|
|
||||||
|
init {
|
||||||
|
add(RedstoneSetting.IGNORED, tooltip = RedstoneSetting.IGNORED.description, skinElement = Widgets18.REDSTONE_IGNORED)
|
||||||
|
add(RedstoneSetting.LOW, tooltip = RedstoneSetting.LOW.description, skinElement = Widgets18.REDSTONE_LOW)
|
||||||
|
add(RedstoneSetting.HIGH, tooltip = RedstoneSetting.HIGH.description, skinElement = Widgets18.REDSTONE_HIGH)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <S : MatteryScreen<*>> makeDeviceControls(
|
||||||
|
screen: S,
|
||||||
|
parent: FramePanel<S>,
|
||||||
|
redstone: IPlayerInputWithFeedback<RedstoneSetting>? = null
|
||||||
|
): EditablePanel<S> {
|
||||||
|
val panel = object : EditablePanel<S>(screen, parent, width = LargeEnumRectangleButtonPanel.SIZE, height = 0f, x = parent.width + 3f) {
|
||||||
|
override fun tick() {
|
||||||
|
super.tick()
|
||||||
|
x = parent.width + 3f
|
||||||
|
y = 0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var y = 0f
|
||||||
|
|
||||||
|
if (redstone != null) {
|
||||||
|
y += makeRedstoneSettingButton(screen, panel, y = y, control = redstone).height + 2f
|
||||||
|
}
|
||||||
|
|
||||||
|
panel.height = (y - 2f).coerceAtLeast(0f)
|
||||||
|
return panel
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
package ru.dbotthepony.mc.otm.client.screen.panels.button
|
package ru.dbotthepony.mc.otm.client.screen.panels.button
|
||||||
|
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
|
import ru.dbotthepony.mc.otm.core.GetterSetter
|
||||||
import ru.dbotthepony.mc.otm.core.value
|
import ru.dbotthepony.mc.otm.core.value
|
||||||
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
|
||||||
|
|
||||||
@ -15,7 +17,7 @@ open class CheckBoxInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
width: Float = REGULAR_DIMENSIONS + 120f,
|
width: Float = REGULAR_DIMENSIONS + 120f,
|
||||||
height: Float = REGULAR_DIMENSIONS
|
height: Float = REGULAR_DIMENSIONS
|
||||||
) : CheckBoxPanel<S>(screen, parent, x, y, width, height) {
|
) : CheckBoxPanel<S>(screen, parent, x, y, width, height) {
|
||||||
override var checked: Boolean
|
override var isChecked: Boolean
|
||||||
get() = widget.value
|
get() = widget.value
|
||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
@ -23,7 +25,7 @@ open class CheckBoxInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
get() = !widget.test(minecraft.player)
|
get() = !widget.test(minecraft.player)
|
||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
override fun onClick() {
|
override fun onClick(mouseButton: Int) {
|
||||||
widget.accept(!checked)
|
widget.accept(!isChecked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,13 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants
|
import com.mojang.blaze3d.platform.InputConstants
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
|
import it.unimi.dsi.fastutil.booleans.BooleanConsumer
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
||||||
import ru.dbotthepony.mc.otm.client.render.AbstractMatterySprite
|
import ru.dbotthepony.mc.otm.client.render.AbstractMatterySprite
|
||||||
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
|
import ru.dbotthepony.mc.otm.core.TextComponent
|
||||||
|
|
||||||
open class CheckBoxPanel<out S : Screen> @JvmOverloads constructor(
|
open class CheckBoxPanel<out S : Screen> @JvmOverloads constructor(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -14,34 +16,42 @@ open class CheckBoxPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
x: Float = 0f,
|
x: Float = 0f,
|
||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = REGULAR_DIMENSIONS,
|
width: Float = REGULAR_DIMENSIONS,
|
||||||
height: Float = REGULAR_DIMENSIONS
|
height: Float = REGULAR_DIMENSIONS,
|
||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
var onPress: BooleanConsumer? = null
|
||||||
open var checked = false
|
) : AbstractButtonPanel<S>(screen, parent, x, y, width, height) {
|
||||||
open var isDisabled = false
|
open var isChecked = false
|
||||||
protected var isPressed = false
|
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
open val IDLE_UNCHECKED: AbstractMatterySprite = Companion.IDLE_UNCHECKED
|
||||||
|
open val IDLE_CHECKED: AbstractMatterySprite = Companion.IDLE_CHECKED
|
||||||
|
open val HOVERED_UNCHECKED: AbstractMatterySprite = Companion.HOVERED_UNCHECKED
|
||||||
|
open val HOVERED_CHECKED: AbstractMatterySprite = Companion.HOVERED_CHECKED
|
||||||
|
open val PRESSED_UNCHECKED: AbstractMatterySprite = Companion.PRESSED_UNCHECKED
|
||||||
|
open val PRESSED_CHECKED: AbstractMatterySprite = Companion.PRESSED_CHECKED
|
||||||
|
open val DISABLED_UNCHECKED: AbstractMatterySprite = Companion.DISABLED_UNCHECKED
|
||||||
|
open val DISABLED_CHECKED: AbstractMatterySprite = Companion.DISABLED_CHECKED
|
||||||
|
|
||||||
|
protected fun renderCheckboxBackground(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
if (isDisabled) {
|
if (isDisabled) {
|
||||||
if (checked) {
|
if (isChecked) {
|
||||||
DISABLED_CHECKED.render(stack, width = width, height = height)
|
DISABLED_CHECKED.render(stack, width = width, height = height)
|
||||||
} else {
|
} else {
|
||||||
DISABLED_UNCHECKED.render(stack, width = width, height = height)
|
DISABLED_UNCHECKED.render(stack, width = width, height = height)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isPressed) {
|
if (isPressed) {
|
||||||
if (checked) {
|
if (isChecked) {
|
||||||
PRESSED_CHECKED.render(stack, width = width, height = height)
|
PRESSED_CHECKED.render(stack, width = width, height = height)
|
||||||
} else {
|
} else {
|
||||||
PRESSED_UNCHECKED.render(stack, width = width, height = height)
|
PRESSED_UNCHECKED.render(stack, width = width, height = height)
|
||||||
}
|
}
|
||||||
} else if (isHovered) {
|
} else if (isHovered) {
|
||||||
if (checked) {
|
if (isChecked) {
|
||||||
HOVERED_CHECKED.render(stack, width = width, height = height)
|
HOVERED_CHECKED.render(stack, width = width, height = height)
|
||||||
} else {
|
} else {
|
||||||
HOVERED_UNCHECKED.render(stack, width = width, height = height)
|
HOVERED_UNCHECKED.render(stack, width = width, height = height)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (checked) {
|
if (isChecked) {
|
||||||
IDLE_CHECKED.render(stack, width = width, height = height)
|
IDLE_CHECKED.render(stack, width = width, height = height)
|
||||||
} else {
|
} else {
|
||||||
IDLE_UNCHECKED.render(stack, width = width, height = height)
|
IDLE_UNCHECKED.render(stack, width = width, height = height)
|
||||||
@ -50,31 +60,13 @@ open class CheckBoxPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun onClick() {
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
checked = !checked
|
renderCheckboxBackground(stack, mouseX, mouseY, partialTick)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun onClick(mouseButton: Int) {
|
||||||
if (!isDisabled && button == InputConstants.MOUSE_BUTTON_LEFT) {
|
isChecked = !isChecked
|
||||||
grabMouseInput = true
|
onPress?.accept(isChecked)
|
||||||
isPressed = true
|
|
||||||
playGuiClickSound()
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
|
||||||
if (isPressed && button == InputConstants.MOUSE_BUTTON_LEFT) {
|
|
||||||
if (isHovered) {
|
|
||||||
onClick()
|
|
||||||
}
|
|
||||||
|
|
||||||
isPressed = false
|
|
||||||
grabMouseInput = false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -12,6 +12,7 @@ import ru.dbotthepony.mc.otm.core.GetterSetter
|
|||||||
import ru.dbotthepony.mc.otm.core.TextComponent
|
import ru.dbotthepony.mc.otm.core.TextComponent
|
||||||
import ru.dbotthepony.mc.otm.core.next
|
import ru.dbotthepony.mc.otm.core.next
|
||||||
import ru.dbotthepony.mc.otm.core.prev
|
import ru.dbotthepony.mc.otm.core.prev
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.EnumValueCodec
|
||||||
import ru.dbotthepony.mc.otm.core.value
|
import ru.dbotthepony.mc.otm.core.value
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
@ -23,31 +24,25 @@ abstract class EnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
|
|||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float,
|
width: Float,
|
||||||
height: Float,
|
height: Float,
|
||||||
val enum: Class<T>,
|
enum: Class<T>,
|
||||||
val prop: GetterSetter<T>,
|
val prop: GetterSetter<T>,
|
||||||
val defaultValue: T,
|
val defaultValue: T,
|
||||||
val onChange: ((newValue: T) -> Unit)? = null,
|
|
||||||
) : RectangleButtonPanel<S>(screen, parent, x, y, width, height, null) {
|
) : RectangleButtonPanel<S>(screen, parent, x, y, width, height, null) {
|
||||||
private var building = true
|
val enum = EnumValueCodec.searchClass(enum)
|
||||||
|
private var isBuilding = true
|
||||||
|
|
||||||
protected val enumMapping = EnumMap<T, Pair<AbstractMatterySprite, UVWindingOrder>>(enum)
|
data class Entry<T : Enum<T>>(
|
||||||
protected val tooltipMapping = EnumMap<T, Component>(enum)
|
val key: T,
|
||||||
|
val skinElement: AbstractMatterySprite?,
|
||||||
|
val winding: UVWindingOrder = UVWindingOrder.NORMAL,
|
||||||
|
val tooltip: Component? = null
|
||||||
|
)
|
||||||
|
|
||||||
fun addTooltip(value: T, component: Component): EnumRectangleButtonPanel<S, T> {
|
protected val enumMapping = EnumMap<T, Entry<T>>(enum)
|
||||||
check(tooltipMapping.put(value, component) == null) { "Already has mapping for $value" }
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var mainTooltip: Component? = null
|
|
||||||
set(value) {
|
|
||||||
if (field != null) {
|
|
||||||
throw UnsupportedOperationException("Write once only")
|
|
||||||
}
|
|
||||||
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isFullyDefined(): Boolean {
|
fun isFullyDefined(): Boolean {
|
||||||
|
if (!isBuilding) return true
|
||||||
|
|
||||||
for (value in enum.enumConstants) {
|
for (value in enum.enumConstants) {
|
||||||
if (enumMapping[value] == null) {
|
if (enumMapping[value] == null) {
|
||||||
return false
|
return false
|
||||||
@ -69,77 +64,54 @@ abstract class EnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
|
|||||||
return missing
|
return missing
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(value: T, skinElement: AbstractMatterySprite, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel<S, T> {
|
fun add(key: T, skinElement: AbstractMatterySprite? = null, tooltip: Component? = null, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel<S, T> {
|
||||||
return add(value, skinElement to winding)
|
return add(Entry(key = key, skinElement = skinElement, winding = winding, tooltip = tooltip))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(value: T, skinElement: AbstractMatterySprite, component: Component, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel<S, T> {
|
fun add(entry: Entry<T>): EnumRectangleButtonPanel<S, T> {
|
||||||
return add(value, component, skinElement to winding)
|
check(isBuilding) { "Not building" }
|
||||||
}
|
check(enumMapping.put(entry.key, entry) == null) { "Already has mapping for ${entry.key}" }
|
||||||
|
if (enumMapping.size == enum.enumConstants.size) finish()
|
||||||
fun add(value: T, component: Component, skinElement: AbstractMatterySprite, winding: UVWindingOrder = UVWindingOrder.NORMAL): EnumRectangleButtonPanel<S, T> {
|
|
||||||
return add(value, component, skinElement to winding)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun add(value: T, pair: Pair<AbstractMatterySprite, UVWindingOrder>): EnumRectangleButtonPanel<S, T> {
|
|
||||||
check(building) { "Not building" }
|
|
||||||
check(enumMapping.put(value, pair) == null) { "Already has mapping for $value" }
|
|
||||||
|
|
||||||
if (enumMapping.size == enum.enumConstants.size) {
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(value: T, component: Component, pair: Pair<AbstractMatterySprite, UVWindingOrder>): EnumRectangleButtonPanel<S, T> {
|
|
||||||
addTooltip(value, component)
|
|
||||||
return add(value, pair)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun finish(): EnumRectangleButtonPanel<S, T> {
|
fun finish(): EnumRectangleButtonPanel<S, T> {
|
||||||
check(building) { "Not building" }
|
check(isBuilding) { "Not building" }
|
||||||
check(isFullyDefined()) {
|
check(isFullyDefined()) { "Not all enums having their mapping defined, missing are: ${missingValues.joinToString(", ")}" }
|
||||||
"Not all enums having their mapping defined, missing are: ${missingValues.joinToString(", ")}"
|
isBuilding = false
|
||||||
}
|
|
||||||
|
|
||||||
building = false
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
check(!building) { "Still building this button!" }
|
check(!isBuilding) { "Still building this button!" }
|
||||||
super.innerRender(stack, mouseX, mouseY, partialTick)
|
super.innerRender(stack, mouseX, mouseY, partialTick)
|
||||||
val pair = checkNotNull(enumMapping[prop.get()]) { "HOW" }
|
val entry = checkNotNull(enumMapping[prop.get()]) { "HOW" }
|
||||||
pair.first.render(stack, 0f, 0f, width, height, pair.second)
|
entry.skinElement?.render(stack, 0f, 0f, width, height, entry.winding)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
check(!building) { "Still building this button!" }
|
check(!isBuilding) { "Still building this button!" }
|
||||||
return super.mouseClickedInner(x, y, button)
|
return super.mouseClickedInner(x, y, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
||||||
check(!building) { "Still building this button!" }
|
check(!isBuilding) { "Still building this button!" }
|
||||||
return super.mouseReleasedInner(x, y, button)
|
return super.mouseReleasedInner(x, y, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(clickButton: Int) {
|
override fun test(value: Int): Boolean {
|
||||||
when (clickButton) {
|
return value == InputConstants.MOUSE_BUTTON_LEFT ||
|
||||||
InputConstants.MOUSE_BUTTON_LEFT -> {
|
value == InputConstants.MOUSE_BUTTON_RIGHT ||
|
||||||
prop.value = prop.value.next(enum.enumConstants)
|
value == InputConstants.MOUSE_BUTTON_MIDDLE
|
||||||
onChange?.invoke(prop.get())
|
}
|
||||||
}
|
|
||||||
|
|
||||||
InputConstants.MOUSE_BUTTON_RIGHT -> {
|
|
||||||
prop.value = prop.value.prev(enum.enumConstants)
|
|
||||||
onChange?.invoke(prop.get())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
override fun onClick(mouseButton: Int) {
|
||||||
|
when (mouseButton) {
|
||||||
|
InputConstants.MOUSE_BUTTON_LEFT -> prop.value = prop.value.next(enum.enumConstants)
|
||||||
|
InputConstants.MOUSE_BUTTON_RIGHT -> prop.value = prop.value.prev(enum.enumConstants)
|
||||||
InputConstants.MOUSE_BUTTON_MIDDLE -> {
|
InputConstants.MOUSE_BUTTON_MIDDLE -> {
|
||||||
if (prop.get() != defaultValue) {
|
if (prop.value != defaultValue) {
|
||||||
prop.value = defaultValue
|
prop.value = defaultValue
|
||||||
onChange?.invoke(prop.get())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,33 +122,27 @@ abstract class EnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
|
|||||||
return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick)
|
return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mainTooltip == null && tooltipMapping.size == 0) {
|
if (tooltip == null && tooltipList == null && enumMapping.values.none { it.tooltip != null }) {
|
||||||
return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick)
|
return super.innerRenderTooltips(stack, mouseX, mouseY, partialTick)
|
||||||
}
|
}
|
||||||
|
|
||||||
val listing = ArrayList<Component>()
|
val listing = ArrayList<Component>()
|
||||||
|
|
||||||
if (mainTooltip != null) {
|
if (tooltipList != null) {
|
||||||
listing.add(mainTooltip!!)
|
listing.addAll(tooltipList!!)
|
||||||
|
listing.add(SPACE)
|
||||||
|
} else if (tooltip != null) {
|
||||||
|
listing.add(tooltip!!)
|
||||||
listing.add(SPACE)
|
listing.add(SPACE)
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((key, value) in tooltipMapping) {
|
for (entry in enumMapping.values) {
|
||||||
if (key == prop.get()) {
|
if (entry.tooltip != null) {
|
||||||
listing.add(value.copy().withStyle(ChatFormatting.WHITE))
|
listing.add(entry.tooltip.copy().withStyle(if (entry.key == prop.get()) ChatFormatting.WHITE else ChatFormatting.GRAY))
|
||||||
} else {
|
|
||||||
listing.add(value.copy().withStyle(ChatFormatting.GRAY))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.renderComponentTooltip(
|
screen.renderComponentTooltip(stack, listing, mouseX.toInt(), mouseY.toInt(), font)
|
||||||
stack,
|
|
||||||
listing,
|
|
||||||
mouseX.toInt(),
|
|
||||||
mouseY.toInt(),
|
|
||||||
font
|
|
||||||
)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@ open class LargeEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
|
|||||||
enum: Class<T>,
|
enum: Class<T>,
|
||||||
prop: GetterSetter<T>,
|
prop: GetterSetter<T>,
|
||||||
defaultValue: T,
|
defaultValue: T,
|
||||||
onChange: ((newValue: T) -> Unit)? = null,
|
) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue) {
|
||||||
) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue, onChange) {
|
|
||||||
final override val IDLE = Widgets18.BUTTON_IDLE
|
final override val IDLE = Widgets18.BUTTON_IDLE
|
||||||
final override val HOVERED = Widgets18.BUTTON_HOVERED
|
final override val HOVERED = Widgets18.BUTTON_HOVERED
|
||||||
final override val PRESSED = Widgets18.BUTTON_PRESSED
|
final override val PRESSED = Widgets18.BUTTON_PRESSED
|
||||||
|
@ -5,6 +5,8 @@ import net.minecraft.client.gui.screens.Screen
|
|||||||
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
import ru.dbotthepony.mc.otm.client.playGuiClickSound
|
||||||
import ru.dbotthepony.mc.otm.client.render.AbstractMatterySprite
|
import ru.dbotthepony.mc.otm.client.render.AbstractMatterySprite
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
|
import ru.dbotthepony.mc.otm.core.TextComponent
|
||||||
|
import java.util.function.IntConsumer
|
||||||
|
|
||||||
@Suppress("PropertyName")
|
@Suppress("PropertyName")
|
||||||
abstract class RectangleButtonPanel<out S : Screen>(
|
abstract class RectangleButtonPanel<out S : Screen>(
|
||||||
@ -14,35 +16,21 @@ abstract class RectangleButtonPanel<out S : Screen>(
|
|||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float,
|
width: Float,
|
||||||
height: Float,
|
height: Float,
|
||||||
val onPress: ((clickButton: Int) -> Unit)? = null,
|
var onPress: IntConsumer? = null,
|
||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
) : AbstractButtonPanel<S>(screen, parent, x, y, width, height) {
|
||||||
protected var pressed = false
|
|
||||||
|
|
||||||
protected open fun onClick(clickButton: Int) {
|
|
||||||
onPress?.invoke(clickButton)
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract val PRESSED: AbstractMatterySprite
|
abstract val PRESSED: AbstractMatterySprite
|
||||||
abstract val HOVERED: AbstractMatterySprite
|
abstract val HOVERED: AbstractMatterySprite
|
||||||
abstract val IDLE: AbstractMatterySprite
|
abstract val IDLE: AbstractMatterySprite
|
||||||
abstract val DISABLED: AbstractMatterySprite
|
abstract val DISABLED: AbstractMatterySprite
|
||||||
|
|
||||||
var isDisabled = false
|
override fun onClick(mouseButton: Int) {
|
||||||
set(value) {
|
onPress?.accept(mouseButton)
|
||||||
if (field != value) {
|
}
|
||||||
if (!value) {
|
|
||||||
pressed = false
|
|
||||||
grabMouseInput = false
|
|
||||||
}
|
|
||||||
|
|
||||||
field = value
|
protected fun renderSquareButton(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
|
||||||
if (isDisabled) {
|
if (isDisabled) {
|
||||||
DISABLED.render(stack, 0f, 0f, width, height)
|
DISABLED.render(stack, 0f, 0f, width, height)
|
||||||
} else if (pressed) {
|
} else if (isPressed) {
|
||||||
PRESSED.render(stack, 0f, 0f, width, height)
|
PRESSED.render(stack, 0f, 0f, width, height)
|
||||||
} else if (isHovered) {
|
} else if (isHovered) {
|
||||||
HOVERED.render(stack, 0f, 0f, width, height)
|
HOVERED.render(stack, 0f, 0f, width, height)
|
||||||
@ -51,31 +39,7 @@ abstract class RectangleButtonPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseClickedInner(x: Double, y: Double, button: Int): Boolean {
|
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||||
if (!isDisabled) {
|
renderSquareButton(stack, mouseX, mouseY, partialTick)
|
||||||
if (!pressed) {
|
|
||||||
playGuiClickSound()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tryToGrabMouseInput()) {
|
|
||||||
pressed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun mouseReleasedInner(x: Double, y: Double, button: Int): Boolean {
|
|
||||||
if (!isDisabled && pressed) {
|
|
||||||
pressed = false
|
|
||||||
|
|
||||||
if (isHovered) {
|
|
||||||
onClick(button)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
grabMouseInput = false
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,7 @@ open class SmallEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
|
|||||||
enum: Class<T>,
|
enum: Class<T>,
|
||||||
prop: GetterSetter<T>,
|
prop: GetterSetter<T>,
|
||||||
defaultValue: T,
|
defaultValue: T,
|
||||||
onChange: ((newValue: T) -> Unit)? = null,
|
) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue) {
|
||||||
) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue, onChange) {
|
|
||||||
final override val IDLE = Widgets8.BUTTON_IDLE
|
final override val IDLE = Widgets8.BUTTON_IDLE
|
||||||
final override val HOVERED = Widgets8.BUTTON_HOVERED
|
final override val HOVERED = Widgets8.BUTTON_HOVERED
|
||||||
final override val PRESSED = Widgets8.BUTTON_PRESSED
|
final override val PRESSED = Widgets8.BUTTON_PRESSED
|
||||||
|
@ -44,22 +44,16 @@ open class QueryUserPanel<out S: Screen>(
|
|||||||
|
|
||||||
this.height = height + bottom.height + PADDING + PADDING_TOP + 4f
|
this.height = height + bottom.height + PADDING + PADDING_TOP + 4f
|
||||||
|
|
||||||
ButtonPanel(screen, bottom, width = font.width(TranslatableComponent("otm.gui.cancel")) + 12f, label = TranslatableComponent("otm.gui.cancel")).also {
|
ButtonPanel(screen, bottom, width = font.width(TranslatableComponent("otm.gui.cancel")) + 12f, label = TranslatableComponent("otm.gui.cancel"), onPress = Runnable {
|
||||||
it.bind {
|
onCancel?.run()
|
||||||
onCancel?.run()
|
this.remove()
|
||||||
this.remove()
|
}).dock = Dock.RIGHT
|
||||||
}
|
|
||||||
|
|
||||||
it.dock = Dock.RIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onConfirm != null) {
|
if (onConfirm != null) {
|
||||||
ButtonPanel(screen, bottom, width = font.width(TranslatableComponent("otm.gui.confirm")) + 12f, label = TranslatableComponent("otm.gui.confirm")).also {
|
ButtonPanel(screen, bottom, width = font.width(TranslatableComponent("otm.gui.confirm")) + 12f, label = TranslatableComponent("otm.gui.confirm"), onPress = Runnable {
|
||||||
it.bind {
|
onConfirm.run()
|
||||||
onConfirm.run()
|
this.remove()
|
||||||
this.remove()
|
}).also {
|
||||||
}
|
|
||||||
|
|
||||||
it.dock = Dock.RIGHT
|
it.dock = Dock.RIGHT
|
||||||
it.dockRight = 2f
|
it.dockRight = 2f
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ import net.minecraft.client.renderer.GameRenderer
|
|||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraftforge.client.extensions.common.IClientItemExtensions
|
import net.minecraftforge.client.extensions.common.IClientItemExtensions
|
||||||
import org.lwjgl.opengl.GL11
|
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.*
|
import ru.dbotthepony.mc.otm.client.render.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
@ -27,40 +25,11 @@ abstract class AbstractSlotPanel<out S : MatteryScreen<*>> @JvmOverloads constru
|
|||||||
SLOT_BACKGROUND.render(stack, width = width, height = height)
|
SLOT_BACKGROUND.render(stack, width = width, height = height)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun renderRegular(stack: PoseStack, itemstack: ItemStack, count_override: String? = null) {
|
protected open fun renderRegular(stack: PoseStack, itemstack: ItemStack, countOverride: String? = null) {
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||||
|
|
||||||
if (!itemstack.isEmpty) {
|
if (!itemstack.isEmpty) {
|
||||||
RenderSystem.enableDepthTest()
|
screen.renderItemStack(absoluteX, absoluteY, itemstack, countOverride)
|
||||||
|
|
||||||
val systemPoseStack = RenderSystem.getModelViewStack()
|
|
||||||
|
|
||||||
systemPoseStack.pushPose()
|
|
||||||
systemPoseStack.translate((absoluteX + 1f).toDouble(), (absoluteY + 1f).toDouble(), 0.0)
|
|
||||||
RenderSystem.applyModelViewMatrix()
|
|
||||||
RenderSystem.depthFunc(GL11.GL_LESS)
|
|
||||||
|
|
||||||
// Thanks Mojang
|
|
||||||
// Very cool
|
|
||||||
// (for int x, int y, which are then cast into doubles anyway)
|
|
||||||
screen.itemRenderer.blitOffset = 1f // Z pos
|
|
||||||
|
|
||||||
screen.itemRenderer.renderAndDecorateItem(
|
|
||||||
requireNotNull(minecraft.player) { "yo, dude, what the fuck" },
|
|
||||||
itemstack,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
(absoluteX + absoluteY * 1000f).toInt()
|
|
||||||
)
|
|
||||||
|
|
||||||
RenderSystem.depthFunc(GL11.GL_ALWAYS)
|
|
||||||
screen.itemRenderer.renderGuiItemDecorations(screen.font, itemstack, 0, 0, count_override)
|
|
||||||
screen.itemRenderer.blitOffset = 0f
|
|
||||||
|
|
||||||
// too big accumulations can lead to Z near clipping issues
|
|
||||||
systemPoseStack.popPose()
|
|
||||||
RenderSystem.applyModelViewMatrix()
|
|
||||||
|
|
||||||
clearDepth(stack)
|
clearDepth(stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,16 +139,15 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
|
|||||||
|
|
||||||
val refillPriority = SmallEnumRectangleButtonPanel(this, arrowLine,
|
val refillPriority = SmallEnumRectangleButtonPanel(this, arrowLine,
|
||||||
enum = ItemMonitorPlayerSettings.IngredientPriority::class.java,
|
enum = ItemMonitorPlayerSettings.IngredientPriority::class.java,
|
||||||
prop = menu.settings::ingredientPriority.asGetterSetter(),
|
prop = menu.settings::ingredientPriority.asGetterSetter(watch = { _, _ -> menu.sendSettingsToServer() }),
|
||||||
defaultValue = ItemMonitorPlayerSettings.IngredientPriority.SYSTEM,
|
defaultValue = ItemMonitorPlayerSettings.IngredientPriority.SYSTEM)
|
||||||
onChange = { menu.sendSettingsToServer() })
|
|
||||||
|
|
||||||
refillPriority.mainTooltip = TranslatableComponent("otm.gui.item_monitor.refill_source.desc")
|
refillPriority.tooltip = TranslatableComponent("otm.gui.item_monitor.refill_source.desc")
|
||||||
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.SYSTEM, ItemMonitorPlayerSettings.IngredientPriority.SYSTEM.component, Widgets8.WHITE_ARROW_DOWN, UVWindingOrder.FLIP)
|
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.SYSTEM, tooltip = ItemMonitorPlayerSettings.IngredientPriority.SYSTEM.component, skinElement = Widgets8.WHITE_ARROW_DOWN, winding = UVWindingOrder.FLIP)
|
||||||
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.INVENTORY, ItemMonitorPlayerSettings.IngredientPriority.INVENTORY.component, Widgets8.WHITE_ARROW_DOWN)
|
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.INVENTORY, tooltip = ItemMonitorPlayerSettings.IngredientPriority.INVENTORY.component, skinElement = Widgets8.WHITE_ARROW_DOWN)
|
||||||
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.INVENTORY_FIRST, ItemMonitorPlayerSettings.IngredientPriority.INVENTORY_FIRST.component, Widgets8.ARROW_SIDEWAYS, UVWindingOrder.FLIP)
|
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.INVENTORY_FIRST, tooltip = ItemMonitorPlayerSettings.IngredientPriority.INVENTORY_FIRST.component, skinElement = Widgets8.ARROW_SIDEWAYS, winding = UVWindingOrder.FLIP)
|
||||||
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.SYSTEM_FIRST, ItemMonitorPlayerSettings.IngredientPriority.SYSTEM_FIRST.component, Widgets8.ARROW_SIDEWAYS)
|
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.SYSTEM_FIRST, tooltip = ItemMonitorPlayerSettings.IngredientPriority.SYSTEM_FIRST.component, skinElement = Widgets8.ARROW_SIDEWAYS)
|
||||||
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.DO_NOT, ItemMonitorPlayerSettings.IngredientPriority.DO_NOT.component, Widgets8.MINUS)
|
refillPriority.add(ItemMonitorPlayerSettings.IngredientPriority.DO_NOT, tooltip = ItemMonitorPlayerSettings.IngredientPriority.DO_NOT.component, skinElement = Widgets8.MINUS)
|
||||||
|
|
||||||
refillPriority.dock = Dock.LEFT
|
refillPriority.dock = Dock.LEFT
|
||||||
|
|
||||||
@ -161,25 +160,23 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
|
|||||||
|
|
||||||
val resultTarget = SmallEnumRectangleButtonPanel(this, resultAndButtons, y = 38f,
|
val resultTarget = SmallEnumRectangleButtonPanel(this, resultAndButtons, y = 38f,
|
||||||
enum = ItemMonitorPlayerSettings.ResultTarget::class.java,
|
enum = ItemMonitorPlayerSettings.ResultTarget::class.java,
|
||||||
prop = menu.settings::resultTarget.asGetterSetter(),
|
prop = menu.settings::resultTarget.asGetterSetter(watch = { _, _ -> menu.sendSettingsToServer() }),
|
||||||
defaultValue = ItemMonitorPlayerSettings.ResultTarget.MIXED,
|
defaultValue = ItemMonitorPlayerSettings.ResultTarget.MIXED)
|
||||||
onChange = { menu.sendSettingsToServer() })
|
|
||||||
|
|
||||||
resultTarget.mainTooltip = TranslatableComponent("otm.gui.item_monitor.result_target.desc")
|
resultTarget.tooltip = TranslatableComponent("otm.gui.item_monitor.result_target.desc")
|
||||||
resultTarget.add(ItemMonitorPlayerSettings.ResultTarget.MIXED, ItemMonitorPlayerSettings.ResultTarget.MIXED.component, Widgets8.ARROW_SIDEWAYS)
|
resultTarget.add(ItemMonitorPlayerSettings.ResultTarget.MIXED, tooltip = ItemMonitorPlayerSettings.ResultTarget.MIXED.component, skinElement = Widgets8.ARROW_SIDEWAYS)
|
||||||
resultTarget.add(ItemMonitorPlayerSettings.ResultTarget.ALL_INVENTORY, ItemMonitorPlayerSettings.ResultTarget.ALL_INVENTORY.component, Widgets8.ARROW_PAINTED_UP, UVWindingOrder.FLIP)
|
resultTarget.add(ItemMonitorPlayerSettings.ResultTarget.ALL_INVENTORY, tooltip = ItemMonitorPlayerSettings.ResultTarget.ALL_INVENTORY.component, skinElement = Widgets8.ARROW_PAINTED_UP, winding = UVWindingOrder.FLIP)
|
||||||
resultTarget.add(ItemMonitorPlayerSettings.ResultTarget.ALL_SYSTEM, ItemMonitorPlayerSettings.ResultTarget.ALL_SYSTEM.component, Widgets8.ARROW_PAINTED_UP)
|
resultTarget.add(ItemMonitorPlayerSettings.ResultTarget.ALL_SYSTEM, tooltip = ItemMonitorPlayerSettings.ResultTarget.ALL_SYSTEM.component, skinElement = Widgets8.ARROW_PAINTED_UP)
|
||||||
|
|
||||||
val craftingAmount = SmallEnumRectangleButtonPanel(this, resultAndButtons, x = 10f, y = 38f,
|
val craftingAmount = SmallEnumRectangleButtonPanel(this, resultAndButtons, x = 10f, y = 38f,
|
||||||
enum = ItemMonitorPlayerSettings.Amount::class.java,
|
enum = ItemMonitorPlayerSettings.Amount::class.java,
|
||||||
prop = menu.settings::craftingAmount.asGetterSetter(),
|
prop = menu.settings::craftingAmount.asGetterSetter(watch = { _, _ -> menu.sendSettingsToServer() }),
|
||||||
defaultValue = ItemMonitorPlayerSettings.Amount.STACK,
|
defaultValue = ItemMonitorPlayerSettings.Amount.STACK)
|
||||||
onChange = { menu.sendSettingsToServer() })
|
|
||||||
|
|
||||||
craftingAmount.mainTooltip = TranslatableComponent("otm.gui.item_monitor.amount.desc")
|
craftingAmount.tooltip = TranslatableComponent("otm.gui.item_monitor.amount.desc")
|
||||||
craftingAmount.add(ItemMonitorPlayerSettings.Amount.ONE, ItemMonitorPlayerSettings.Amount.ONE.component, Widgets8.ONE)
|
craftingAmount.add(ItemMonitorPlayerSettings.Amount.ONE, tooltip = ItemMonitorPlayerSettings.Amount.ONE.component, skinElement = Widgets8.ONE)
|
||||||
craftingAmount.add(ItemMonitorPlayerSettings.Amount.STACK, ItemMonitorPlayerSettings.Amount.STACK.component, Widgets8.S)
|
craftingAmount.add(ItemMonitorPlayerSettings.Amount.STACK, tooltip = ItemMonitorPlayerSettings.Amount.STACK.component, skinElement = Widgets8.S)
|
||||||
craftingAmount.add(ItemMonitorPlayerSettings.Amount.FULL, ItemMonitorPlayerSettings.Amount.FULL.component, Widgets8.F)
|
craftingAmount.add(ItemMonitorPlayerSettings.Amount.FULL, tooltip = ItemMonitorPlayerSettings.Amount.FULL.component, skinElement = Widgets8.F)
|
||||||
|
|
||||||
val craftingHistory = GridPanel(this, bottomPanel, width = 3 * 18f, height = 3 * 18f, columns = 3, rows = 3)
|
val craftingHistory = GridPanel(this, bottomPanel, width = 3 * 18f, height = 3 * 18f, columns = 3, rows = 3)
|
||||||
craftingHistory.dock = Dock.LEFT
|
craftingHistory.dock = Dock.LEFT
|
||||||
|
@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
|||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
||||||
@ -28,6 +29,8 @@ class StorageBusScreen(menu: StorageBusMenu, inventory: Inventory, title: Compon
|
|||||||
|
|
||||||
CheckBoxLabelInputPanel(this, frame, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist"), 59f, 78f, width = 170f)
|
CheckBoxLabelInputPanel(this, frame, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist"), 59f, 78f, width = 170f)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
|||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
||||||
@ -28,6 +29,8 @@ class StorageExporterScreen(menu: StorageExporterMenu, inventory: Inventory, tit
|
|||||||
|
|
||||||
CheckBoxLabelInputPanel(this, frame, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist"), 59f, 78f, width = 170f)
|
CheckBoxLabelInputPanel(this, frame, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist"), 59f, 78f, width = 170f)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
|||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
||||||
@ -28,6 +29,8 @@ class StorageImporterScreen(menu: StorageImporterMenu, inventory: Inventory, tit
|
|||||||
|
|
||||||
CheckBoxLabelInputPanel(this, frame, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist"), 59f, 78f, width = 170f)
|
CheckBoxLabelInputPanel(this, frame, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist"), 59f, 78f, width = 170f)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.HorizontalPowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.HorizontalPowerGaugePanel
|
||||||
@ -66,6 +67,8 @@ class StoragePowerSupplierScreen(menu: StoragePowerSupplierMenu, inventory: Inve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import ru.dbotthepony.mc.otm.client.render.drawRect
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.ButtonPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.ButtonPanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.EquipmentBatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.EquipmentBatterySlotPanel
|
||||||
@ -643,12 +644,10 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I
|
|||||||
researchCanvas.parent = research
|
researchCanvas.parent = research
|
||||||
|
|
||||||
val bottom = EditablePanel(this, research, 0f, 0f, 0f, 20f)
|
val bottom = EditablePanel(this, research, 0f, 0f, 0f, 20f)
|
||||||
val close = ButtonPanel(this, bottom, 0f, 0f, 90f, 20f, TranslatableComponent("otm.container.matter_panel.close"))
|
val close = ButtonPanel(this, bottom, 0f, 0f, 90f, 20f, TranslatableComponent("otm.container.matter_panel.close"), onPress = Runnable { research!!.remove() })
|
||||||
|
|
||||||
bottom.dock = Dock.BOTTOM
|
bottom.dock = Dock.BOTTOM
|
||||||
|
|
||||||
close.dock = Dock.RIGHT
|
close.dock = Dock.RIGHT
|
||||||
close.bind { research!!.remove() }
|
|
||||||
|
|
||||||
bottom.setDockMargin(0f, 0f, 4f, 4f)
|
bottom.setDockMargin(0f, 0f, 4f, 4f)
|
||||||
researchCanvas.setDockMargin(4f, 4f, 4f, 4f)
|
researchCanvas.setDockMargin(4f, 4f, 4f, 4f)
|
||||||
@ -732,6 +731,8 @@ class AndroidStationScreen constructor(p_97741_: AndroidStationMenu, p_97742_: I
|
|||||||
|
|
||||||
this.playerStrip = playerStrip
|
this.playerStrip = playerStrip
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,13 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
||||||
|
|
||||||
class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Component) :
|
class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Component) :
|
||||||
MatteryScreen<BatteryBankMenu>(menu, p_97742_, p_97743_) {
|
MatteryScreen<BatteryBankMenu>(menu, p_97742_, p_97743_) {
|
||||||
|
|
||||||
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
|
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
|
||||||
val frame = super.makeMainFrame()!!
|
val frame = super.makeMainFrame()!!
|
||||||
|
|
||||||
WidePowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT)
|
WidePowerGaugePanel(this, frame, menu.powerLevel, LEFT_MARGIN, GAUGE_TOP_WITHOUT_SLOT)
|
||||||
@ -22,6 +23,8 @@ class BatteryBankScreen(menu: BatteryBankMenu, p_97742_: Inventory, p_97743_: Co
|
|||||||
for (i in 6 .. 11)
|
for (i in 6 .. 11)
|
||||||
BatterySlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * (i - 6), 32f + 18f)
|
BatterySlotPanel(this, frame, menu.storageSlots[i], 44f + 18 * (i - 6), 32f + 18f)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import net.minecraft.network.chat.Component
|
|||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||||
@ -12,7 +13,7 @@ import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
|||||||
import ru.dbotthepony.mc.otm.menu.tech.ChemicalGeneratorMenu
|
import ru.dbotthepony.mc.otm.menu.tech.ChemicalGeneratorMenu
|
||||||
|
|
||||||
class ChemicalGeneratorScreen(menu: ChemicalGeneratorMenu, inventory: Inventory, title: Component) : MatteryScreen<ChemicalGeneratorMenu>(menu, inventory, title) {
|
class ChemicalGeneratorScreen(menu: ChemicalGeneratorMenu, inventory: Inventory, title: Component) : MatteryScreen<ChemicalGeneratorMenu>(menu, inventory, title) {
|
||||||
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
|
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
|
||||||
val frame = super.makeMainFrame()!!
|
val frame = super.makeMainFrame()!!
|
||||||
|
|
||||||
WidePowerGaugePanel(this, frame, menu.energy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
|
WidePowerGaugePanel(this, frame, menu.energy, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
|
||||||
@ -33,6 +34,8 @@ class ChemicalGeneratorScreen(menu: ChemicalGeneratorMenu, inventory: Inventory,
|
|||||||
SlotPanel(this, frame, menu.residueSlot, 56f, PROGRESS_SLOT_TOP)
|
SlotPanel(this, frame, menu.residueSlot, 56f, PROGRESS_SLOT_TOP)
|
||||||
SlotPanel(this, frame, menu.fuelSlot, 104f, PROGRESS_SLOT_TOP)
|
SlotPanel(this, frame, menu.fuelSlot, 104f, PROGRESS_SLOT_TOP)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
|||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.ButtonPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.ButtonPanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkNumberInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkNumberInputPanel
|
||||||
import ru.dbotthepony.mc.otm.core.util.formatPower
|
import ru.dbotthepony.mc.otm.core.util.formatPower
|
||||||
import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu
|
import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu
|
||||||
@ -81,10 +82,9 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
|
|||||||
label.setDockMargin(4f, 0f, 0f, 0f)
|
label.setDockMargin(4f, 0f, 0f, 0f)
|
||||||
|
|
||||||
if (!menu.ply.isSpectator) {
|
if (!menu.ply.isSpectator) {
|
||||||
val button = ButtonPanel(this, frame, 0f, 0f, 0f, 20f, TranslatableComponent("block.overdrive_that_matters.energy_counter.switch"))
|
val button = ButtonPanel(this, frame, 0f, 0f, 0f, 20f, TranslatableComponent("block.overdrive_that_matters.energy_counter.switch"), onPress = Runnable { menu.switchDirection.input(null) })
|
||||||
button.dock = Dock.TOP
|
button.dock = Dock.TOP
|
||||||
button.setDockMargin(4f, 0f, 4f, 0f)
|
button.setDockMargin(4f, 0f, 4f, 0f)
|
||||||
button.bind { menu.switchDirection.input(null) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val infoPanels = frame.fetchChildren()
|
val infoPanels = frame.fetchChildren()
|
||||||
@ -107,6 +107,8 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
|
|||||||
|
|
||||||
limitsTab.onClose!!.run()
|
limitsTab.onClose!!.run()
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
|||||||
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.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.HorizontalPowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.HorizontalPowerGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.TallHorizontalPowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.TallHorizontalPowerGaugePanel
|
||||||
@ -61,6 +62,8 @@ class EnergyServoScreen(menu: EnergyServoMenu, inventory: Inventory, title: Comp
|
|||||||
it.dockRight
|
it.dockRight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
|
||||||
@ -12,7 +13,7 @@ import ru.dbotthepony.mc.otm.menu.tech.PlatePressMenu
|
|||||||
|
|
||||||
class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Component) :
|
class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Component) :
|
||||||
MatteryScreen<PlatePressMenu>(menu, inventory, title) {
|
MatteryScreen<PlatePressMenu>(menu, inventory, title) {
|
||||||
override fun makeMainFrame(): FramePanel<out MatteryScreen<*>> {
|
override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
|
||||||
val frame = super.makeMainFrame()!!
|
val frame = super.makeMainFrame()!!
|
||||||
|
|
||||||
WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
|
WidePowerGaugePanel(this, frame, menu.powerWidget, LEFT_MARGIN, GAUGE_TOP_WITH_SLOT)
|
||||||
@ -22,6 +23,8 @@ class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Compon
|
|||||||
ProgressGaugePanel(this, frame, menu.progressGauge, 78f, PROGRESS_ARROW_TOP)
|
ProgressGaugePanel(this, frame, menu.progressGauge, 78f, PROGRESS_ARROW_TOP)
|
||||||
SlotPanel(this, frame, menu.outputSlot, 104f, PROGRESS_SLOT_TOP)
|
SlotPanel(this, frame, menu.outputSlot, 104f, PROGRESS_SLOT_TOP)
|
||||||
|
|
||||||
|
makeDeviceControls(this, frame, redstone = menu.redstone)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,5 +66,28 @@ interface GetterSetter<V> : Supplier<V>, Consumer<V>, ReadWriteProperty<Any?, V>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <V> KMutableProperty0<V>.asGetterSetter() = GetterSetter.of(this)
|
fun <V> KMutableProperty0<V>.asGetterSetter(watch: ((old: V, new: V) -> Unit)? = null): GetterSetter<V> {
|
||||||
|
return GetterSetter.of(this).let {
|
||||||
|
if (watch != null) {
|
||||||
|
it.watch(watch)
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <V> GetterSetter<V>.watch(watch: (old: V, new: V) -> Unit): GetterSetter<V> {
|
||||||
|
return object : GetterSetter<V> {
|
||||||
|
override fun get(): V {
|
||||||
|
return this@watch.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun accept(t: V) {
|
||||||
|
val old = get()
|
||||||
|
this@watch.accept(t)
|
||||||
|
watch.invoke(old, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun <V> KMutableProperty0<V>.asGetterOnly() = GetterSetter.of(Supplier { this.get() }, Consumer { /* do nothing */ })
|
fun <V> KMutableProperty0<V>.asGetterOnly() = GetterSetter.of(Supplier { this.get() }, Consumer { /* do nothing */ })
|
||||||
|
@ -76,7 +76,8 @@ val VarLongValueCodec = StreamCodec(DataInputStream::readVarLongLE, DataOutputSt
|
|||||||
val BinaryStringCodec = StreamCodec(DataInputStream::readBinaryString, DataOutputStream::writeBinaryString)
|
val BinaryStringCodec = StreamCodec(DataInputStream::readBinaryString, DataOutputStream::writeBinaryString)
|
||||||
|
|
||||||
class EnumValueCodec<V : Enum<V>>(clazz: Class<out V>, val writeByIndices: Boolean = false) : IStreamCodec<V> {
|
class EnumValueCodec<V : Enum<V>>(clazz: Class<out V>, val writeByIndices: Boolean = false) : IStreamCodec<V> {
|
||||||
private val values = search(clazz) ?: throw ClassCastException("$clazz does not have enum constants. Not an enum?")
|
val clazz = searchClass(clazz)
|
||||||
|
private val values = searchClass(clazz).enumConstants!!
|
||||||
|
|
||||||
override fun read(stream: DataInputStream): V {
|
override fun read(stream: DataInputStream): V {
|
||||||
if (writeByIndices) {
|
if (writeByIndices) {
|
||||||
@ -109,14 +110,18 @@ class EnumValueCodec<V : Enum<V>>(clazz: Class<out V>, val writeByIndices: Boole
|
|||||||
*
|
*
|
||||||
* is there an already existing solution?
|
* is there an already existing solution?
|
||||||
*/
|
*/
|
||||||
fun <V : Enum<V>> search(clazz: Class<out V>): Array<V>? {
|
fun <V : Enum<V>> searchClass(clazz: Class<out V>): Class<out V> {
|
||||||
var search: Class<*> = clazz
|
var search: Class<*> = clazz
|
||||||
|
|
||||||
while (search.enumConstants == null && search.superclass != null) {
|
while (search.enumConstants == null && search.superclass != null) {
|
||||||
search = search.superclass
|
search = search.superclass
|
||||||
}
|
}
|
||||||
|
|
||||||
return search.enumConstants as? Array<V>
|
if (search.enumConstants == null) {
|
||||||
|
throw ClassCastException("$clazz does not represent an enum or enum subclass")
|
||||||
|
}
|
||||||
|
|
||||||
|
return search as Class<out V>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||||
import net.minecraft.world.SimpleContainer
|
import net.minecraft.world.SimpleContainer
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
|
|
||||||
abstract class MatteryPoweredMenu protected constructor(
|
abstract class MatteryPoweredMenu protected constructor(
|
||||||
menuType: MenuType<*>,
|
menuType: MenuType<*>,
|
||||||
@ -14,6 +16,7 @@ abstract class MatteryPoweredMenu protected constructor(
|
|||||||
) : MatteryMenu(menuType, containerID, inventory, tile) {
|
) : MatteryMenu(menuType, containerID, inventory, tile) {
|
||||||
val powerWidget: LevelGaugeWidget
|
val powerWidget: LevelGaugeWidget
|
||||||
val batterySlot: BatterySlot
|
val batterySlot: BatterySlot
|
||||||
|
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (tile == null) {
|
if (tile == null) {
|
||||||
@ -22,6 +25,7 @@ abstract class MatteryPoweredMenu protected constructor(
|
|||||||
} else {
|
} else {
|
||||||
powerWidget = LevelGaugeWidget(this, tile.energy)
|
powerWidget = LevelGaugeWidget(this, tile.energy)
|
||||||
batterySlot = BatterySlot(tile.batteryContainer, 0)
|
batterySlot = BatterySlot(tile.batteryContainer, 0)
|
||||||
|
redstone.with(tile.redstoneControl::redstoneSetting)
|
||||||
}
|
}
|
||||||
|
|
||||||
addSlot(batterySlot)
|
addSlot(batterySlot)
|
||||||
|
@ -2,9 +2,11 @@ package ru.dbotthepony.mc.otm.menu.decorative
|
|||||||
|
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.inventory.Slot
|
import net.minecraft.world.inventory.Slot
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
||||||
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.menu.input.StringInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.StringInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
|
|
||||||
@ -15,14 +17,17 @@ class HoloSignMenu @JvmOverloads constructor(
|
|||||||
) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) {
|
) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) {
|
||||||
val text = StringInputWithFeedback(this)
|
val text = StringInputWithFeedback(this)
|
||||||
val locked = BooleanInputWithFeedback(this)
|
val locked = BooleanInputWithFeedback(this)
|
||||||
|
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
text.filter { it.isCreative || !locked.value }
|
text.filter { it.isCreative || !locked.value }
|
||||||
|
redstone.filter { it.isCreative || !locked.value }
|
||||||
locked.filter { it.isCreative }
|
locked.filter { it.isCreative }
|
||||||
|
|
||||||
if (tile != null) {
|
if (tile != null) {
|
||||||
text.withConsumer { if (tile.locked) tile.text = it else tile.text = HoloSignBlockEntity.truncate(it) }.withSupplier(tile::text)
|
text.withConsumer { if (tile.locked) tile.text = it else tile.text = HoloSignBlockEntity.truncate(it) }.withSupplier(tile::text)
|
||||||
locked.with(tile::locked)
|
locked.with(tile::locked)
|
||||||
|
redstone.with(tile.redstoneControl::redstoneSetting)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,33 @@ import kotlin.reflect.KMutableProperty0
|
|||||||
*
|
*
|
||||||
* Getting and setting values should ONLY be done clientside
|
* Getting and setting values should ONLY be done clientside
|
||||||
*/
|
*/
|
||||||
interface IPlayerInputWithFeedback<V> : GetterSetter<V>, Predicate<Player?>
|
interface IPlayerInputWithFeedback<V> : GetterSetter<V>, Predicate<Player?> {
|
||||||
|
companion object {
|
||||||
|
fun <V> of(getterSetter: GetterSetter<V>): IPlayerInputWithFeedback<V> {
|
||||||
|
return object : IPlayerInputWithFeedback<V>, GetterSetter<V> by getterSetter {
|
||||||
|
override fun test(t: Player?): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <V> of(getterSetter: GetterSetter<V>, filter: Predicate<Player?>): IPlayerInputWithFeedback<V> {
|
||||||
|
return object : IPlayerInputWithFeedback<V>, GetterSetter<V> by getterSetter, Predicate<Player?> by filter {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <V> validPlayer(getterSetter: GetterSetter<V>): IPlayerInputWithFeedback<V> {
|
||||||
|
return object : IPlayerInputWithFeedback<V>, GetterSetter<V> by getterSetter {
|
||||||
|
override fun test(t: Player?): Boolean {
|
||||||
|
return t != null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <V> GetterSetter<V>.wrapAsPlayerInput(filter: Predicate<Player?> = Predicate { it != null }): IPlayerInputWithFeedback<V> {
|
||||||
|
return IPlayerInputWithFeedback.of(this, filter)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Server to Client synchronization and Client to Server input
|
* Represents Server to Client synchronization and Client to Server input
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.menu.input
|
||||||
|
|
||||||
|
import ru.dbotthepony.mc.otm.core.GetterSetter
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.EnumValueCodec
|
||||||
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
|
import kotlin.reflect.KMutableProperty0
|
||||||
|
|
||||||
|
class EnumInputWithFeedback<E : Enum<E>>(menu: MatteryMenu, clazz: Class<E>) : AbstractPlayerInputWithFeedback<E>() {
|
||||||
|
val codec = EnumValueCodec(clazz)
|
||||||
|
private val default = codec.clazz.enumConstants!![0]
|
||||||
|
|
||||||
|
override val input = menu.PlayerInput(codec, false) { consumer?.invoke(it) }
|
||||||
|
override val value by menu.mSynchronizer.ComputedField(getter = { supplier?.invoke() ?: default }, codec)
|
||||||
|
|
||||||
|
constructor(menu: MatteryMenu, clazz: Class<E>, state: KMutableProperty0<E>) : this(menu, clazz) {
|
||||||
|
with(state)
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(menu: MatteryMenu, clazz: Class<E>, state: GetterSetter<E>) : this(menu, clazz) {
|
||||||
|
with(state)
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import kotlin.jvm.JvmOverloads
|
|||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
|
||||||
import net.minecraft.world.SimpleContainer
|
import net.minecraft.world.SimpleContainer
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
import ru.dbotthepony.mc.otm.core.ImmutableList
|
import ru.dbotthepony.mc.otm.core.ImmutableList
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
@ -12,6 +13,7 @@ import ru.dbotthepony.mc.otm.core.orNull
|
|||||||
import ru.dbotthepony.mc.otm.menu.BatterySlot
|
import ru.dbotthepony.mc.otm.menu.BatterySlot
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
||||||
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
|
|
||||||
class BatteryBankMenu @JvmOverloads constructor(
|
class BatteryBankMenu @JvmOverloads constructor(
|
||||||
@ -21,8 +23,13 @@ class BatteryBankMenu @JvmOverloads constructor(
|
|||||||
) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) {
|
) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) {
|
||||||
val powerLevel: LevelGaugeWidget
|
val powerLevel: LevelGaugeWidget
|
||||||
override val storageSlots: List<MatterySlot>
|
override val storageSlots: List<MatterySlot>
|
||||||
|
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
if (tile != null) {
|
||||||
|
redstone.with(tile.redstoneControl::redstoneSetting)
|
||||||
|
}
|
||||||
|
|
||||||
val container: Container = tile?.container ?: SimpleContainer(BatteryBankBlockEntity.CAPACITY)
|
val container: Container = tile?.container ?: SimpleContainer(BatteryBankBlockEntity.CAPACITY)
|
||||||
powerLevel = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.ENERGY)?.orNull())
|
powerLevel = LevelGaugeWidget(this, tile?.getCapability(MatteryCapability.ENERGY)?.orNull())
|
||||||
|
|
||||||
|
@ -5,10 +5,12 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraftforge.common.ForgeHooks
|
import net.minecraftforge.common.ForgeHooks
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
import net.minecraftforge.common.capabilities.ForgeCapabilities
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
import ru.dbotthepony.mc.otm.block.entity.tech.ChemicalGeneratorBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.ChemicalGeneratorBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.core.ifPresentK
|
import ru.dbotthepony.mc.otm.core.ifPresentK
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
||||||
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
@ -16,6 +18,14 @@ import ru.dbotthepony.mc.otm.registry.MMenus
|
|||||||
class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, tile: ChemicalGeneratorBlockEntity? = null)
|
class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, tile: ChemicalGeneratorBlockEntity? = null)
|
||||||
: MatteryMenu(MMenus.CHEMICAL_GENERATOR, id, inv, tile) {
|
: MatteryMenu(MMenus.CHEMICAL_GENERATOR, id, inv, tile) {
|
||||||
|
|
||||||
|
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (tile != null) {
|
||||||
|
redstone.with(tile.redstoneControl::redstoneSetting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val container = tile?.container ?: SimpleContainer(3)
|
val container = tile?.container ?: SimpleContainer(3)
|
||||||
|
|
||||||
val fuelSlot = object : MatterySlot(container, ChemicalGeneratorBlockEntity.SLOT_INPUT) {
|
val fuelSlot = object : MatterySlot(container, ChemicalGeneratorBlockEntity.SLOT_INPUT) {
|
||||||
@ -44,6 +54,7 @@ class ChemicalGeneratorMenu @JvmOverloads constructor(id: Int, inv: Inventory, t
|
|||||||
val energy = LevelGaugeWidget(this, tile?.energy)
|
val energy = LevelGaugeWidget(this, tile?.energy)
|
||||||
var burnTime by mSynchronizer.int()
|
var burnTime by mSynchronizer.int()
|
||||||
|
|
||||||
|
|
||||||
override val storageSlots = listOf(
|
override val storageSlots = listOf(
|
||||||
addSlot(fuelSlot),
|
addSlot(fuelSlot),
|
||||||
addSlot(batterySlot),
|
addSlot(batterySlot),
|
||||||
|
@ -5,10 +5,12 @@ import kotlin.jvm.JvmOverloads
|
|||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.inventory.Slot
|
import net.minecraft.world.inventory.Slot
|
||||||
import net.minecraft.world.level.block.Block
|
import net.minecraft.world.level.block.Block
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
import ru.dbotthepony.mc.otm.block.tech.EnergyCounterBlock
|
import ru.dbotthepony.mc.otm.block.tech.EnergyCounterBlock
|
||||||
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyCounterBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyCounterBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
@ -28,6 +30,14 @@ class EnergyCounterMenu @JvmOverloads constructor(
|
|||||||
tile.level?.setBlock(tile.blockPos, tile.blockState.setValue(EnergyCounterBlock.INPUT_DIRECTION, tile.blockState.getValue(EnergyCounterBlock.INPUT_DIRECTION).opposite), Block.UPDATE_ALL)
|
tile.level?.setBlock(tile.blockPos, tile.blockState.setValue(EnergyCounterBlock.INPUT_DIRECTION, tile.blockState.getValue(EnergyCounterBlock.INPUT_DIRECTION).opposite), Block.UPDATE_ALL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (tile != null) {
|
||||||
|
redstone.with(tile.redstoneControl::redstoneSetting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var inputDirection by mSynchronizer.enum(Direction::class.java)
|
var inputDirection by mSynchronizer.enum(Direction::class.java)
|
||||||
|
|
||||||
val maxIOInput = bigDecimalInput {
|
val maxIOInput = bigDecimalInput {
|
||||||
|
@ -5,10 +5,12 @@ import net.minecraft.world.SimpleContainer
|
|||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.inventory.Slot
|
import net.minecraft.world.inventory.Slot
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyServoBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.energy
|
import ru.dbotthepony.mc.otm.capability.energy
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
import ru.dbotthepony.mc.otm.menu.MatterySlot
|
||||||
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
|
|
||||||
@ -22,6 +24,14 @@ class EnergyServoMenu @JvmOverloads constructor(
|
|||||||
|
|
||||||
val powerGauge = LevelGaugeWidget(this, tile?.energy)
|
val powerGauge = LevelGaugeWidget(this, tile?.energy)
|
||||||
|
|
||||||
|
val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (tile != null) {
|
||||||
|
redstone.with(tile.redstoneControl::redstoneSetting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val container = tile?.container ?: SimpleContainer(2)
|
val container = tile?.container ?: SimpleContainer(2)
|
||||||
|
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 736 B |
Binary file not shown.
Loading…
Reference in New Issue
Block a user