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

85 lines
2.7 KiB
Kotlin

package net.shadowfacts.phycon.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.network.DeviceBlockEntity
import net.shadowfacts.phycon.network.block.redstone.RedstoneControllerBlockEntity
import net.shadowfacts.phycon.network.component.ActivationController
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)
))
}
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)
))
}
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 isPauseScreen() = false
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
if (keyCode == GLFW.GLFW_KEY_E) {
onClose()
return true
}
return super.keyPressed(keyCode, scanCode, modifiers)
}
}