|
|
|
@ -5,23 +5,21 @@ import com.github.vini2003.blade.common.data.Position
@@ -5,23 +5,21 @@ import com.github.vini2003.blade.common.data.Position
|
|
|
|
|
import com.github.vini2003.blade.common.data.Size |
|
|
|
|
import com.github.vini2003.blade.common.data.Slots |
|
|
|
|
import com.github.vini2003.blade.common.handler.BaseScreenHandler |
|
|
|
|
import com.github.vini2003.blade.common.widget.base.ButtonWidget |
|
|
|
|
import com.github.vini2003.blade.common.widget.base.SlotListWidget |
|
|
|
|
import com.github.vini2003.blade.common.widget.base.SlotWidget |
|
|
|
|
import com.github.vini2003.blade.common.widget.base.TextWidget |
|
|
|
|
import com.github.vini2003.blade.common.widget.base.* |
|
|
|
|
import com.martmists.ynet.YNetMod |
|
|
|
|
import com.martmists.ynet.blockentity.ControllerBlockEntity |
|
|
|
|
import com.martmists.ynet.ext.next |
|
|
|
|
import com.martmists.ynet.ext.ofRGB |
|
|
|
|
import com.martmists.ynet.network.Channel |
|
|
|
|
import com.martmists.ynet.network.ConfiguredBlockEntity |
|
|
|
|
import com.martmists.ynet.network.InteractionMode |
|
|
|
|
import com.martmists.ynet.transfer.type.DisabledType |
|
|
|
|
import com.martmists.ynet.util.WidgetBuilder |
|
|
|
|
import com.martmists.ynet.screen.util.ColoredButtonWidget |
|
|
|
|
import com.martmists.ynet.screen.util.WidgetBuilder |
|
|
|
|
import com.martmists.ynet.util.YNetRegistry |
|
|
|
|
import net.minecraft.entity.player.PlayerEntity |
|
|
|
|
import net.minecraft.inventory.SimpleInventory |
|
|
|
|
import net.minecraft.item.ItemStack |
|
|
|
|
import net.minecraft.network.PacketByteBuf |
|
|
|
|
import net.minecraft.screen.slot.SlotActionType |
|
|
|
|
import net.minecraft.text.LiteralText |
|
|
|
|
import net.minecraft.text.TranslatableText |
|
|
|
@ -29,9 +27,17 @@ import net.minecraft.util.math.BlockPos
@@ -29,9 +27,17 @@ import net.minecraft.util.math.BlockPos
|
|
|
|
|
|
|
|
|
|
class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: BlockPos) : BaseScreenHandler(YNetMod.CONTROLLER_SCREEN_HANDLER, syncId, player) { |
|
|
|
|
val be = player.world.getBlockEntity(pos) as ControllerBlockEntity |
|
|
|
|
var currentChannel: Channel<*>? = null |
|
|
|
|
var currentBlock: ConfiguredBlockEntity? = null |
|
|
|
|
var selectedButton: ButtonWidget? = null |
|
|
|
|
var currentBlockSet = false |
|
|
|
|
|
|
|
|
|
lateinit var currentChannel: Channel<*> |
|
|
|
|
lateinit var currentBlock: ConfiguredBlockEntity |
|
|
|
|
lateinit var selectedButton: AbstractWidget |
|
|
|
|
|
|
|
|
|
lateinit var rpcText: TextWidget |
|
|
|
|
lateinit var rpcButton: ButtonWidget |
|
|
|
|
lateinit var rpbButton: ButtonWidget |
|
|
|
|
lateinit var rpbSlots: MutableCollection<SlotWidget> |
|
|
|
|
|
|
|
|
|
val filterInventory = SimpleInventory( |
|
|
|
|
ItemStack.EMPTY, |
|
|
|
|
ItemStack.EMPTY, |
|
|
|
@ -92,19 +98,17 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -92,19 +98,17 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
// +------------------+ +-------------------+ |
|
|
|
|
|
|
|
|
|
val main = WidgetBuilder.build(this) { |
|
|
|
|
size(Size.of(370, 192)) |
|
|
|
|
size(Size.of(390, 192)) |
|
|
|
|
position(Position.of(width/2 - root.size.width/2, height/2 - root.size.height/2)) |
|
|
|
|
|
|
|
|
|
// EMPTY |
|
|
|
|
val rightPanelEmpty = panel { |
|
|
|
|
size(Size.of(165, 95)) |
|
|
|
|
relativePosition(200, 5) |
|
|
|
|
hidden(true) |
|
|
|
|
relativePosition(220, 5) |
|
|
|
|
hidden(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CHANNEL |
|
|
|
|
var rpcText: TextWidget? = null |
|
|
|
|
var rpcButton: ButtonWidget? = null |
|
|
|
|
val rightPanelChannel = panel { |
|
|
|
|
size(rightPanelEmpty.size) |
|
|
|
|
position(rightPanelEmpty.position) |
|
|
|
@ -117,11 +121,12 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -117,11 +121,12 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
} |
|
|
|
|
rpcButton = button ({ channelTypeButton -> |
|
|
|
|
val types = YNetRegistry.getTypes().toMutableList().also { it.add(0, DisabledType) } |
|
|
|
|
println(currentChannel) |
|
|
|
|
val newChannel = Channel(currentChannel!!.network, currentChannel!!.connectedBlocks.map { ConfiguredBlockEntity(it.controller, it.be, 0, InteractionMode.DISABLED, mutableListOf()) }.toMutableList(), types.next(currentChannel!!.type)) |
|
|
|
|
currentChannel!!.network.channels[currentChannel!!.network.channels.indexOf(currentChannel)] = newChannel |
|
|
|
|
val newChannel = Channel(currentChannel.network, currentChannel.connectedBlocks.map { ConfiguredBlockEntity(it.controller, it.be, 0, InteractionMode.DISABLED, mutableListOf()) }.toMutableList(), types.next(currentChannel.type)) |
|
|
|
|
be.network.channels[be.network.channels.indexOf(currentChannel)] = newChannel |
|
|
|
|
currentChannel = newChannel |
|
|
|
|
channelTypeButton.label = TranslatableText(newChannel.type.identifier.toString().replace("ynet:", "ynet.ui.")) |
|
|
|
|
(selectedButton as ColoredButtonWidget).color = Color.ofRGB(newChannel.type.color) |
|
|
|
|
be.markDirty() |
|
|
|
|
}) { |
|
|
|
|
size(Size.of(90, 20)) |
|
|
|
|
relativePosition(55, 20) |
|
|
|
@ -129,12 +134,10 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -129,12 +134,10 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// BLOCK |
|
|
|
|
var rpbButton: ButtonWidget? = null |
|
|
|
|
var rpbSlots: MutableCollection<SlotWidget>? = null |
|
|
|
|
val rightPanelBlock = panel { |
|
|
|
|
size(rightPanelEmpty.size) |
|
|
|
|
position(rightPanelEmpty.position) |
|
|
|
|
hidden(false) |
|
|
|
|
hidden(true) |
|
|
|
|
text(TranslatableText("ynet.ui.block")) { |
|
|
|
|
relativePosition(40, 5) |
|
|
|
|
} |
|
|
|
@ -143,17 +146,18 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -143,17 +146,18 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
} |
|
|
|
|
rpbButton = button ({ |
|
|
|
|
val modes = InteractionMode.values().toList() |
|
|
|
|
currentBlock!!.mode = modes.next(currentBlock!!.mode) |
|
|
|
|
it.label = TranslatableText("ynet.ui.mode." + currentBlock!!.mode.name.toLowerCase()) |
|
|
|
|
when (currentBlock!!.mode) { |
|
|
|
|
currentBlock.mode = modes.next(currentBlock.mode) |
|
|
|
|
it.label = TranslatableText("ynet.ui.mode." + currentBlock.mode.name.toLowerCase()) |
|
|
|
|
when (currentBlock.mode) { |
|
|
|
|
InteractionMode.INSERT -> { |
|
|
|
|
selectedButton!!.label = LiteralText("I") |
|
|
|
|
(selectedButton as ButtonWidget).label = LiteralText("I") |
|
|
|
|
} |
|
|
|
|
InteractionMode.EXTRACT -> { |
|
|
|
|
selectedButton!!.label = LiteralText("E") |
|
|
|
|
(selectedButton as ButtonWidget).label = LiteralText("E") |
|
|
|
|
} |
|
|
|
|
else -> {} |
|
|
|
|
} |
|
|
|
|
be.markDirty() |
|
|
|
|
}) { |
|
|
|
|
size(Size.of(90, 20)) |
|
|
|
|
relativePosition(55, 20) |
|
|
|
@ -167,62 +171,76 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -167,62 +171,76 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
|
|
|
|
|
// LEFT PANEL |
|
|
|
|
panel { |
|
|
|
|
size(Size.of(193, 182)) |
|
|
|
|
size(Size.of(213, 182)) |
|
|
|
|
relativePosition(5, 5) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (x in 0 until 10) { |
|
|
|
|
button(Color.of(DisabledType.color), { |
|
|
|
|
button(Color.ofRGB(be.network.channels[x].type.color), { |
|
|
|
|
currentChannel = be.network.channels[x] |
|
|
|
|
rpcButton!!.label = TranslatableText(currentChannel!!.type.identifier.toString().replace("ynet:", "ynet.ui.")) |
|
|
|
|
rpcText!!.text = TranslatableText("ynet.ui.channel.index", x) |
|
|
|
|
rpcButton.label = TranslatableText(currentChannel.type.identifier.toString().replace("ynet:", "ynet.ui.")) |
|
|
|
|
rpcText.text = TranslatableText("ynet.ui.channel.index", x) |
|
|
|
|
rightPanelEmpty.hidden = true |
|
|
|
|
rightPanelChannel.hidden = false |
|
|
|
|
rightPanelBlock.hidden = true |
|
|
|
|
selectedButton = it |
|
|
|
|
}) { |
|
|
|
|
size(Size.of(14, 14)) |
|
|
|
|
relativePosition(40 + 15*x, 6) |
|
|
|
|
relativePosition(26 + 15*x, 6) |
|
|
|
|
root.label = LiteralText(x.toString()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
list { |
|
|
|
|
size(Size.of(180, 140)) |
|
|
|
|
relativePosition(3, 20) |
|
|
|
|
size(Size.of(202, 140)) |
|
|
|
|
relativePosition(3, 25) |
|
|
|
|
|
|
|
|
|
be.network.getConnectedBlocks().forEachIndexed { index, block -> |
|
|
|
|
panel { |
|
|
|
|
size(Size.of(180, 30)) |
|
|
|
|
size(Size.of(175, 25)) |
|
|
|
|
relativePosition(3, 32 * index) |
|
|
|
|
|
|
|
|
|
icon(be.world!!.getBlockState(block.pos).block) { |
|
|
|
|
icon(be.world!!.getBlockState(block.pos).block, LiteralText(block.pos.toShortString())) { |
|
|
|
|
size(Size.of(20, 20)) |
|
|
|
|
relativePosition(4, 4) |
|
|
|
|
relativePosition(4, 5) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (x in 0 until 10) { |
|
|
|
|
button ({ |
|
|
|
|
if (be.network.channels[x].type == DisabledType) return@button |
|
|
|
|
selectedButton = it |
|
|
|
|
currentBlock = be.network.channels[x].connectedBlocks.first { b -> b.be == block } |
|
|
|
|
currentBlock = be.network.channels[x].connectedBlocks.first { b -> b.be === block } |
|
|
|
|
currentBlockSet = true |
|
|
|
|
|
|
|
|
|
rpbButton!!.label = TranslatableText("ynet.ui.mode." + currentBlock!!.mode.name.toLowerCase()) |
|
|
|
|
rpbButton.label = TranslatableText("ynet.ui.mode." + currentBlock.mode.name.toLowerCase()) |
|
|
|
|
// TODO: Priority |
|
|
|
|
for (i in 0 until filterInventory.size()) { |
|
|
|
|
filterInventory.setStack(i, ItemStack.EMPTY) |
|
|
|
|
} |
|
|
|
|
currentBlock!!.filter.forEachIndexed { index, itemStack -> |
|
|
|
|
currentBlock.filter.forEachIndexed { index, itemStack -> |
|
|
|
|
filterInventory.setStack(index, itemStack) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rightPanelEmpty.hidden = true |
|
|
|
|
rightPanelChannel.hidden = true |
|
|
|
|
rightPanelBlock.hidden = false |
|
|
|
|
rpbSlots?.forEach { s -> s.hidden = be.network.channels[x].type.canFilter } |
|
|
|
|
rpbSlots.forEach { s -> s.hidden = be.network.channels[x].type.canFilter } |
|
|
|
|
}) { |
|
|
|
|
size(Size.of(14, 14)) |
|
|
|
|
relativePosition(20 + 15*x, 6) |
|
|
|
|
root.label = LiteralText(" ") |
|
|
|
|
val cbe = be.network.channels[x].connectedBlocks.first { b -> b.be == block } |
|
|
|
|
when (cbe.mode) { |
|
|
|
|
InteractionMode.INSERT -> { |
|
|
|
|
root.label = LiteralText("I") |
|
|
|
|
} |
|
|
|
|
InteractionMode.EXTRACT -> { |
|
|
|
|
root.label = LiteralText("E") |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
root.label = LiteralText(" ") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -231,18 +249,18 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -231,18 +249,18 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
text(TranslatableText("container.inventory")) { |
|
|
|
|
relativePosition(202, 101) |
|
|
|
|
relativePosition(222, 101) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Slots.addPlayerInventory(Position.of(main, 202, 110), Size.of(18, 18), main, getPlayer().inventory) |
|
|
|
|
Slots.addPlayerInventory(Position.of(main, 222, 110), Size.of(18, 18), main, getPlayer().inventory) |
|
|
|
|
|
|
|
|
|
addWidget(main) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onSlotClick(slotNumber: Int, button: Int, actionType: SlotActionType?, playerEntity: PlayerEntity?): ItemStack { |
|
|
|
|
val cursor = playerEntity!!.inventory.cursorStack |
|
|
|
|
if (slotNumber < 0 || currentBlock == null) return cursor |
|
|
|
|
if (slotNumber < 0 || !currentBlockSet) return cursor |
|
|
|
|
val copy = cursor.copy() |
|
|
|
|
when { |
|
|
|
|
(slots[slotNumber] ?: return cursor).inventory == filterInventory -> { |
|
|
|
@ -252,15 +270,15 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -252,15 +270,15 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
copy.count = 1 |
|
|
|
|
val old = filterInventory.getStack(slotNumber) |
|
|
|
|
if (!old.isEmpty) { |
|
|
|
|
currentBlock!!.filter.remove(old) |
|
|
|
|
currentBlock.filter.remove(old) |
|
|
|
|
} |
|
|
|
|
filterInventory.setStack(slotNumber, copy) |
|
|
|
|
currentBlock!!.filter.add(copy) |
|
|
|
|
currentBlock.filter.add(copy) |
|
|
|
|
} |
|
|
|
|
} else if (button == 1) { // Take |
|
|
|
|
val old = filterInventory.getStack(slotNumber) |
|
|
|
|
if (!old.isEmpty) { |
|
|
|
|
currentBlock!!.filter.remove(old) |
|
|
|
|
currentBlock.filter.remove(old) |
|
|
|
|
} |
|
|
|
|
filterInventory.setStack(slotNumber, ItemStack.EMPTY) |
|
|
|
|
} |
|
|
|
@ -279,7 +297,7 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
@@ -279,7 +297,7 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
|
|
|
|
|
} |
|
|
|
|
copy.count = 1 |
|
|
|
|
filterInventory.setStack(index, copy) |
|
|
|
|
currentBlock!!.filter.add(copy) |
|
|
|
|
currentBlock.filter.add(copy) |
|
|
|
|
return cursor |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|