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

132 lines
4.5 KiB
Kotlin
Raw Normal View History

2021-03-26 02:15:46 +00:00
package net.shadowfacts.phycon.client.screen.console
2021-02-28 02:48:40 +00:00
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
2021-02-28 18:48:39 +00:00
import net.shadowfacts.phycon.block.DeviceBlockEntity
2021-03-03 22:23:57 +00:00
import net.shadowfacts.phycon.block.miner.MinerBlockEntity
2021-12-24 17:34:16 +00:00
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlockEntity
2021-03-01 03:03:29 +00:00
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlockEntity
2021-02-28 18:48:39 +00:00
import net.shadowfacts.phycon.component.ActivationController
2021-03-04 03:00:21 +00:00
import net.shadowfacts.phycon.component.NetworkStackProvider
2021-03-04 04:13:09 +00:00
import net.shadowfacts.phycon.component.NetworkStackReceiver
2021-02-28 02:48:40 +00:00
import org.lwjgl.glfw.GLFW
/**
* @author shadowfacts
*/
class DeviceConsoleScreen(
val device: DeviceBlockEntity,
): CacaoScreen(TranslatableText("item.phycon.console")) {
2021-02-28 17:19:09 +00:00
private val tabController: TabViewController<TabViewController.SimpleTab>
2021-02-28 02:48:40 +00:00
init {
val tabs = mutableListOf(
2021-02-28 17:19:09 +00:00
TabViewController.SimpleTab(
2021-02-28 02:48:40 +00:00
Label("IP").apply { textColor = Color.TEXT },
TranslatableText("gui.phycon.console.details"),
DeviceDetailsViewController(device)
)
)
if (device is ActivationController.ActivatableDevice) {
2021-02-28 17:19:09 +00:00
tabs.add(TabViewController.SimpleTab(
2021-02-28 02:48:40 +00:00
TextureView(Texture(Identifier("textures/item/ender_pearl.png"), 0, 0, 16, 16)).apply {
intrinsicContentSize = Size(16.0, 16.0)
},
TranslatableText("gui.phycon.console.remote"),
2021-03-03 22:23:57 +00:00
ActivatableDeviceViewController(device),
device::canConfigureActivationController
2021-02-28 02:48:40 +00:00
))
}
if (device is RedstoneControllerBlockEntity) {
2021-03-03 22:23:57 +00:00
tabs.add(TabViewController.SimpleTab(
2021-02-28 02:48:40 +00:00
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)
))
}
2021-03-03 22:23:57 +00:00
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)
))
}
2021-03-04 03:00:21 +00:00
if (device is NetworkStackProvider) {
tabs.add(TabViewController.SimpleTab(
Label("P").apply { textColor = Color.TEXT },
TranslatableText("gui.phycon.console.provider"),
ProviderViewController(device),
device::canConfigureProviderPriority
))
}
2021-03-04 04:13:09 +00:00
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)
))
}
2021-12-24 17:34:16 +00:00
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)
))
}
2021-02-28 02:48:40 +00:00
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))
}
2022-06-16 14:45:32 +00:00
override fun shouldPause() = false
2021-02-28 02:48:40 +00:00
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
if (keyCode == GLFW.GLFW_KEY_E) {
2022-06-16 14:45:32 +00:00
close()
2021-02-28 02:48:40 +00:00
return true
}
return super.keyPressed(keyCode, scanCode, modifiers)
}
}