PhysicalConnectivity/src/main/kotlin/net/shadowfacts/phycon/client/screen/console/DeviceConsoleScreen.kt

132 lines
4.5 KiB
Kotlin

package net.shadowfacts.phycon.client.screen.console
import net.minecraft.text.TranslatableText
import net.minecraft.util.Identifier
import net.shadowfacts.cacao.CacaoScreen
import net.shadowfacts.cacao.geometry.Size
import net.shadowfacts.cacao.util.Color
import net.shadowfacts.cacao.util.texture.Texture
import net.shadowfacts.cacao.view.Label
import net.shadowfacts.cacao.view.TextureView
import net.shadowfacts.cacao.viewcontroller.TabViewController
import net.shadowfacts.cacao.viewcontroller.ViewController
import net.shadowfacts.cacao.window.Window
import net.shadowfacts.kiwidsl.dsl
import net.shadowfacts.phycon.block.DeviceBlockEntity
import net.shadowfacts.phycon.block.miner.MinerBlockEntity
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlockEntity
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlockEntity
import net.shadowfacts.phycon.component.ActivationController
import net.shadowfacts.phycon.component.NetworkStackProvider
import net.shadowfacts.phycon.component.NetworkStackReceiver
import org.lwjgl.glfw.GLFW
/**
* @author shadowfacts
*/
class DeviceConsoleScreen(
val device: DeviceBlockEntity,
): CacaoScreen(TranslatableText("item.phycon.console")) {
private val tabController: TabViewController<TabViewController.SimpleTab>
init {
val tabs = mutableListOf(
TabViewController.SimpleTab(
Label("IP").apply { textColor = Color.TEXT },
TranslatableText("gui.phycon.console.details"),
DeviceDetailsViewController(device)
)
)
if (device is ActivationController.ActivatableDevice) {
tabs.add(TabViewController.SimpleTab(
TextureView(Texture(Identifier("textures/item/ender_pearl.png"), 0, 0, 16, 16)).apply {
intrinsicContentSize = Size(16.0, 16.0)
},
TranslatableText("gui.phycon.console.remote"),
ActivatableDeviceViewController(device),
device::canConfigureActivationController
))
}
if (device is RedstoneControllerBlockEntity) {
tabs.add(TabViewController.SimpleTab(
TextureView(Texture(Identifier("textures/block/redstone_torch.png"), 0, 0, 16, 16)).apply {
intrinsicContentSize = Size(16.0, 16.0)
},
TranslatableText("block.phycon.redstone_controller"),
RedstoneControllerViewController(device)
))
}
if (device is MinerBlockEntity) {
tabs.add(TabViewController.SimpleTab(
TextureView(Texture(Identifier("textures/item/diamond_pickaxe.png"), 0, 0, 16, 16)).apply {
intrinsicContentSize = Size(16.0, 16.0)
},
TranslatableText("block.phycon.miner"),
MinerViewController(device)
))
}
if (device is NetworkStackProvider) {
tabs.add(TabViewController.SimpleTab(
Label("P").apply { textColor = Color.TEXT },
TranslatableText("gui.phycon.console.provider"),
ProviderViewController(device),
device::canConfigureProviderPriority
))
}
if (device is NetworkStackReceiver) {
tabs.add(TabViewController.SimpleTab(
Label("R").apply { textColor = Color.TEXT },
TranslatableText("gui.phycon.console.receiver"),
ReceiverViewController(device),
))
}
if (device is RedstoneEmitterBlockEntity) {
tabs.add(TabViewController.SimpleTab(
TextureView(Texture(Identifier("textures/item/redstone.png"), 0, 0, 16, 16)).apply {
intrinsicContentSize = Size(16.0, 16.0)
},
TranslatableText("block.phycon.redstone_emitter"),
RedstoneEmitterViewController(device)
))
}
if (device is P2PReceiverBlockEntity) {
tabs.add(TabViewController.SimpleTab(
TextureView(Texture(Identifier("textures/item/ender_pearl.png"), 0, 0, 16, 16)).apply {
intrinsicContentSize = Size(16.0, 16.0)
},
TranslatableText("block.phycon.p2p_receiver"),
P2PReceiverViewController(device)
))
}
tabController = TabViewController(tabs)
val root = object: ViewController() {
override fun viewDidLoad() {
super.viewDidLoad()
embedChild(tabController, pinEdges = false)
view.solver.dsl {
tabController.view.centerXAnchor equalTo view.centerXAnchor
tabController.view.centerYAnchor equalTo view.centerYAnchor
tabController.tabVCContainer.widthAnchor equalTo 200
tabController.tabVCContainer.heightAnchor equalTo 150
}
}
}
addWindow(Window(root))
}
override fun shouldPause() = false
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
if (keyCode == GLFW.GLFW_KEY_E) {
close()
return true
}
return super.keyPressed(keyCode, scanCode, modifiers)
}
}