mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
eros: replace server types with enum
This commit is contained in:
parent
a329131716
commit
c5e0256ba4
@ -58,6 +58,10 @@ data class ItemStack(
|
||||
return ChatComponent.of("$item {name=${displayName}, count=$count. nbt=$nbt}")
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return toText().legacyText
|
||||
}
|
||||
|
||||
|
||||
private fun parseNBT(nbt: MutableMap<String, Any>?) {
|
||||
if (nbt == null) {
|
||||
|
@ -17,7 +17,6 @@ import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.gui.eros.controller.EmbeddedJavaFXController
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.Refreshable
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.ServerListController
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.type.ServerType
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.type.ServerTypeCardController
|
||||
import de.bixilon.minosoft.gui.eros.modding.events.ErosControllerTerminateEvent
|
||||
import de.bixilon.minosoft.gui.eros.modding.invoker.JavaFXEventInvoker
|
||||
@ -30,33 +29,47 @@ import de.bixilon.minosoft.protocol.protocol.LANServerListener
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import javafx.fxml.FXML
|
||||
import javafx.scene.control.ListView
|
||||
import javafx.scene.layout.AnchorPane
|
||||
import javafx.scene.layout.GridPane
|
||||
import javafx.scene.layout.Pane
|
||||
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
|
||||
import javafx.scene.text.TextFlow
|
||||
|
||||
class PlayMainController : EmbeddedJavaFXController<Pane>() {
|
||||
@FXML
|
||||
private lateinit var playTypeContentFX: Pane
|
||||
|
||||
@FXML
|
||||
private lateinit var playTypeListViewFX: ListView<ServerType>
|
||||
private lateinit var playTypeListViewFX: ListView<ServerTypes>
|
||||
|
||||
@FXML
|
||||
private lateinit var refreshPaneFX: AnchorPane
|
||||
private lateinit var refreshPaneFX: GridPane
|
||||
|
||||
@FXML
|
||||
private lateinit var refreshHeaderFX: TextFlow
|
||||
|
||||
@FXML
|
||||
private lateinit var refreshText1FX: TextFlow
|
||||
|
||||
@FXML
|
||||
private lateinit var refreshText2FX: TextFlow
|
||||
|
||||
|
||||
private lateinit var currentController: EmbeddedJavaFXController<*>
|
||||
|
||||
override fun init() {
|
||||
playTypeListViewFX.setCellFactory { ServerTypeCardController.build() }
|
||||
playTypeListViewFX.items += ServerType(FontAwesomeSolid.SERVER, CUSTOM_SERVER_TYPE, "0 Servers", "") {
|
||||
return@ServerType JavaFXUtil.loadEmbeddedController<ServerListController>(ServerListController.LAYOUT).apply {
|
||||
playTypeListViewFX.items += ServerTypes.VALUES
|
||||
|
||||
|
||||
playTypeListViewFX.selectionModel.selectedItemProperty().addListener { _, _, new ->
|
||||
if (this::currentController.isInitialized) {
|
||||
currentController.terminate()
|
||||
}
|
||||
currentController = when (new) {
|
||||
ServerTypes.CUSTOM -> JavaFXUtil.loadEmbeddedController<ServerListController>(ServerListController.LAYOUT).apply {
|
||||
servers = Minosoft.config.config.server.entries.values
|
||||
refreshList()
|
||||
}
|
||||
}
|
||||
playTypeListViewFX.items += ServerType(FontAwesomeSolid.NETWORK_WIRED, LAN_SERVER_TYPE, "12 Servers", "") {
|
||||
return@ServerType JavaFXUtil.loadEmbeddedController<ServerListController>(ServerListController.LAYOUT).apply {
|
||||
ServerTypes.LAN -> JavaFXUtil.loadEmbeddedController<ServerListController>(ServerListController.LAYOUT).apply {
|
||||
val events: MutableList<EventInvoker> = mutableListOf()
|
||||
events += GlobalEventMaster.registerEvent(JavaFXEventInvoker.of<LANServerDiscoverEvent> { refreshList() })
|
||||
readOnly = true
|
||||
@ -79,34 +92,21 @@ class PlayMainController : EmbeddedJavaFXController<Pane>() {
|
||||
refreshList()
|
||||
}
|
||||
}
|
||||
|
||||
playTypeListViewFX.selectionModel.selectedItemProperty().addListener { _, _, new ->
|
||||
if (this::currentController.isInitialized) {
|
||||
currentController.terminate()
|
||||
}
|
||||
currentController = new.content(new)
|
||||
playTypeContentFX.children.setAll(currentController.root)
|
||||
}
|
||||
|
||||
playTypeListViewFX.selectionModel.select(0)
|
||||
|
||||
ServerTypeCardController.build().apply {
|
||||
refreshPaneFX.children.setAll(root)
|
||||
iconFX.iconLiteral = "fas-sync-alt"
|
||||
iconFX.isVisible = true
|
||||
|
||||
headerFX.text = REFRESH_HEADER
|
||||
text1FX.text = REFRESH_TEXT1
|
||||
text2FX.text = REFRESH_TEXT2
|
||||
|
||||
root.setOnMouseClicked {
|
||||
refreshHeaderFX.text = REFRESH_HEADER
|
||||
refreshText1FX.text = REFRESH_TEXT1
|
||||
refreshText2FX.text = REFRESH_TEXT2
|
||||
refreshPaneFX.setOnMouseClicked {
|
||||
val currentController = currentController
|
||||
if (currentController is Refreshable) {
|
||||
currentController.refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val CUSTOM_SERVER_TYPE = "minosoft:server_type.custom".asResourceLocation()
|
||||
|
@ -11,15 +11,26 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.eros.main.play.server.type
|
||||
package de.bixilon.minosoft.gui.eros.main.play
|
||||
|
||||
import de.bixilon.minosoft.gui.eros.controller.EmbeddedJavaFXController
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.Translatable
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import de.bixilon.minosoft.util.enum.ValuesEnum
|
||||
import org.kordamp.ikonli.Ikon
|
||||
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
|
||||
|
||||
data class ServerType(
|
||||
val icon: FontAwesomeSolid,
|
||||
val header: Any?,
|
||||
val text1: Any?,
|
||||
val text2: Any?,
|
||||
val content: (ServerType) -> EmbeddedJavaFXController<*>,
|
||||
)
|
||||
enum class ServerTypes(val icon: Ikon) : Translatable {
|
||||
CUSTOM(FontAwesomeSolid.SERVER),
|
||||
LAN(FontAwesomeSolid.NETWORK_WIRED),
|
||||
;
|
||||
|
||||
override val translationKey: ResourceLocation = "minosoft:server_type.${name.lowercase()}".asResourceLocation()
|
||||
|
||||
|
||||
companion object : ValuesEnum<ServerTypes> {
|
||||
override val VALUES: Array<ServerTypes> = values()
|
||||
override val NAME_MAP: Map<String, ServerTypes> = KUtil.getEnumValues(VALUES)
|
||||
}
|
||||
}
|
@ -13,15 +13,17 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.eros.main.play.server.type
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCard
|
||||
import de.bixilon.minosoft.gui.eros.card.CardFactory
|
||||
import de.bixilon.minosoft.gui.eros.main.play.ServerTypes
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text
|
||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||
import javafx.fxml.FXML
|
||||
import javafx.scene.text.TextFlow
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
|
||||
class ServerTypeCardController : AbstractCard<ServerType>() {
|
||||
class ServerTypeCardController : AbstractCard<ServerTypes>() {
|
||||
@FXML
|
||||
lateinit var iconFX: FontIcon
|
||||
|
||||
@ -29,29 +31,26 @@ class ServerTypeCardController : AbstractCard<ServerType>() {
|
||||
lateinit var headerFX: TextFlow
|
||||
|
||||
@FXML
|
||||
lateinit var text1FX: TextFlow
|
||||
lateinit var textFX: TextFlow
|
||||
|
||||
@FXML
|
||||
lateinit var text2FX: TextFlow
|
||||
|
||||
override fun updateItem(item: ServerType?, empty: Boolean) {
|
||||
override fun updateItem(item: ServerTypes?, empty: Boolean) {
|
||||
super.updateItem(item, empty)
|
||||
item ?: return
|
||||
|
||||
|
||||
iconFX.isVisible = true
|
||||
|
||||
iconFX.iconCode = item.icon
|
||||
headerFX.text = item.header
|
||||
text1FX.text = item.text1
|
||||
text2FX.text = item.text2
|
||||
headerFX.text = Minosoft.LANGUAGE_MANAGER.translate(item)
|
||||
|
||||
textFX.text = "? servers"
|
||||
}
|
||||
|
||||
|
||||
override fun clear() {
|
||||
iconFX.isVisible = false
|
||||
headerFX.children.clear()
|
||||
text1FX.children.clear()
|
||||
text2FX.children.clear()
|
||||
textFX.children.clear()
|
||||
}
|
||||
|
||||
companion object : CardFactory<ServerTypeCardController> {
|
||||
|
@ -120,15 +120,13 @@ class PlayInByteBuffer : InByteBuffer {
|
||||
)
|
||||
}
|
||||
|
||||
return if (readBoolean()) {
|
||||
return readOptional {
|
||||
ItemStack(
|
||||
item = connection.registries.itemRegistry[readVarInt()],
|
||||
connection = connection,
|
||||
count = readUnsignedByte(),
|
||||
nbt = readNBT()?.compoundCast() ?: mutableMapOf(),
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import org.kordamp.ikonli.javafx.FontIcon?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="500.0" prefWidth="900.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/16" fx:controller="de.bixilon.minosoft.gui.eros.main.play.PlayMainController">
|
||||
<GridPane HBox.hgrow="ALWAYS">
|
||||
<columnConstraints>
|
||||
@ -25,7 +27,40 @@
|
||||
<Insets right="10.0"/>
|
||||
</GridPane.margin>
|
||||
<ListView fx:id="playTypeListViewFX" maxHeight="Infinity" maxWidth="Infinity" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS"/>
|
||||
<AnchorPane fx:id="refreshPaneFX" GridPane.rowIndex="1"/>
|
||||
<GridPane fx:id="refreshPaneFX" GridPane.rowIndex="1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="NEVER"/>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints vgrow="ALWAYS"/>
|
||||
</rowConstraints>
|
||||
<GridPane GridPane.columnIndex="1">
|
||||
<TextFlow fx:id="refreshHeaderFX" style="-fx-font-weight: bold; -fx-font-size: 20;">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="5.0" right="5.0" top="5.0"/>
|
||||
</GridPane.margin>
|
||||
<Text text="Header"/>
|
||||
</TextFlow>
|
||||
<TextFlow fx:id="refreshText1FX" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="5.0" right="5.0"/>
|
||||
</GridPane.margin>
|
||||
<Text text="Text 1"/>
|
||||
</TextFlow>
|
||||
<TextFlow fx:id="refreshText2FX" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="5.0" right="5.0"/>
|
||||
</GridPane.margin>
|
||||
<Text text="Text 2"/>
|
||||
</TextFlow>
|
||||
</GridPane>
|
||||
<FontIcon iconLiteral="fas-sync-alt" iconSize="50">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" right="15.0"/>
|
||||
</GridPane.margin>
|
||||
</FontIcon>
|
||||
</GridPane>
|
||||
</GridPane>
|
||||
</GridPane>
|
||||
</HBox>
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
<?import javafx.scene.text.TextFlow?>
|
||||
<?import org.kordamp.ikonli.javafx.FontIcon?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml/1" fx:id="root" prefHeight="80.0" prefWidth="190.0" xmlns="http://javafx.com/javafx/16" fx:controller="de.bixilon.minosoft.gui.eros.main.play.server.type.ServerTypeCardController">
|
||||
<GridPane HBox.hgrow="ALWAYS">
|
||||
@ -20,26 +21,12 @@
|
||||
</GridPane.margin>
|
||||
<Text text="Header"/>
|
||||
</TextFlow>
|
||||
<TextFlow fx:id="text1FX" GridPane.rowIndex="1">
|
||||
<TextFlow fx:id="textFX" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="5.0" right="5.0"/>
|
||||
</GridPane.margin>
|
||||
<Text text="Text 1"/>
|
||||
</TextFlow>
|
||||
<TextFlow fx:id="text2FX" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="5.0" right="5.0"/>
|
||||
</GridPane.margin>
|
||||
<Text text="Text 2"/>
|
||||
</TextFlow>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints/>
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints/>
|
||||
<RowConstraints/>
|
||||
<RowConstraints/>
|
||||
</rowConstraints>
|
||||
</GridPane>
|
||||
<FontIcon fx:id="iconFX" iconLiteral="fas-exclamation-triangle" iconSize="50">
|
||||
<GridPane.margin>
|
||||
|
Loading…
x
Reference in New Issue
Block a user