From 9aed7e9e0321cc458452bd0b6e0250b369ff4639 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sun, 1 Aug 2021 13:33:45 +0200 Subject: [PATCH] eros: css loading, wip styling --- .../minosoft/data/text/TextComponent.kt | 1 - .../minosoft/gui/eros/util/JavaFXUtil.kt | 2 + .../minosoft/util/ResourceURLHandler.kt | 57 ++++++++++++ .../java/de/bixilon/minosoft/util/Util.java | 1 + .../util/microsoft/MicrosoftOAuthUtils.kt | 25 +++-- .../resources/assets/minosoft/eros/style.css | 93 +++++++++++++++++++ 6 files changed, 165 insertions(+), 14 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/util/ResourceURLHandler.kt create mode 100644 src/main/resources/assets/minosoft/eros/style.css diff --git a/src/main/java/de/bixilon/minosoft/data/text/TextComponent.kt b/src/main/java/de/bixilon/minosoft/data/text/TextComponent.kt index 3ab3a3518..16fb57c4a 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/TextComponent.kt +++ b/src/main/java/de/bixilon/minosoft/data/text/TextComponent.kt @@ -123,7 +123,6 @@ open class TextComponent( override fun getJavaFXText(nodes: ObservableList): ObservableList { val text = Text(this.message) this.color?.let { - text.fill = Color.WHITE if (Minosoft.config.config.chat.colored) { text.fill = Color.rgb(it.red, it.green, it.blue) } diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt b/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt index ca0061e60..54e5ba6fa 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt @@ -49,6 +49,8 @@ object JavaFXUtil { stage.scene = Scene(parent) stage.icons.setAll(MINOSOFT_LOGO) + stage.scene.stylesheets.add("resource:minosoft:eros/style.css") + val controller: T = fxmlLoader.getController() if (controller is JavaFXWindowController) { diff --git a/src/main/java/de/bixilon/minosoft/util/ResourceURLHandler.kt b/src/main/java/de/bixilon/minosoft/util/ResourceURLHandler.kt new file mode 100644 index 000000000..cf8dc617a --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/util/ResourceURLHandler.kt @@ -0,0 +1,57 @@ +/* + * Minosoft + * Copyright (C) 2021 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.util + +import de.bixilon.minosoft.Minosoft +import de.bixilon.minosoft.data.registries.ResourceLocation +import java.io.InputStream +import java.net.URL +import java.net.URLConnection +import java.net.URLStreamHandler +import java.net.URLStreamHandlerFactory + + +object ResourceURLHandler { + + init { + URL.setURLStreamHandlerFactory(ResourceURLStreamHandlerFactory) + } + + + private object ResourceStreamHandler : URLStreamHandler() { + override fun openConnection(url: URL?): URLConnection { + return ResourceURLConnection(url) + } + } + + + private object ResourceURLStreamHandlerFactory : URLStreamHandlerFactory { + + override fun createURLStreamHandler(protocol: String): URLStreamHandler? { + if (protocol == "resource") { + return ResourceStreamHandler + } + return null + } + } + + private class ResourceURLConnection(url: URL?) : URLConnection(url) { + override fun connect() { + } + + override fun getInputStream(): InputStream { + return Minosoft.MINOSOFT_ASSETS_MANAGER.readAssetAsStream(ResourceLocation(url.path)) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/util/Util.java b/src/main/java/de/bixilon/minosoft/util/Util.java index 11a208c31..441884ec6 100644 --- a/src/main/java/de/bixilon/minosoft/util/Util.java +++ b/src/main/java/de/bixilon/minosoft/util/Util.java @@ -288,6 +288,7 @@ public final class Util { public static void initUtilClasses() { forceClassInit(Log.class); + forceClassInit(ResourceURLHandler.class); forceClassInit(MicrosoftOAuthUtils.class); forceClassInit(TimeWorker.class); } diff --git a/src/main/java/de/bixilon/minosoft/util/microsoft/MicrosoftOAuthUtils.kt b/src/main/java/de/bixilon/minosoft/util/microsoft/MicrosoftOAuthUtils.kt index 1e46df006..5468aac9a 100644 --- a/src/main/java/de/bixilon/minosoft/util/microsoft/MicrosoftOAuthUtils.kt +++ b/src/main/java/de/bixilon/minosoft/util/microsoft/MicrosoftOAuthUtils.kt @@ -20,9 +20,7 @@ import de.bixilon.minosoft.terminal.RunConfiguration import de.bixilon.minosoft.util.HTTP import de.bixilon.minosoft.util.Util import de.bixilon.minosoft.util.logging.Log -import java.net.URL import java.net.URLConnection -import java.net.URLStreamHandler object MicrosoftOAuthUtils { val NULL_URL_CONNECTION: URLConnection = object : URLConnection(null) { @@ -166,16 +164,17 @@ object MicrosoftOAuthUtils { } init { - URL.setURLStreamHandlerFactory { - if (it == "ms-xal-" + ProtocolDefinition.MICROSOFT_ACCOUNT_APPLICATION_ID) { - return@setURLStreamHandlerFactory object : URLStreamHandler() { - override fun openConnection(url: URL): URLConnection { - loginToMicrosoftAccount(Util.urlQueryToMap(url.query)["code"]!!) - return NULL_URL_CONNECTION - } - } - } - return@setURLStreamHandlerFactory null - } + // ToDo +// URL.setURLStreamHandlerFactory { +// if (it == "ms-xal-" + ProtocolDefinition.MICROSOFT_ACCOUNT_APPLICATION_ID) { +// return@setURLStreamHandlerFactory object : URLStreamHandler() { +// override fun openConnection(url: URL): URLConnection { +// loginToMicrosoftAccount(Util.urlQueryToMap(url.query)["code"]!!) +// return NULL_URL_CONNECTION +// } +// } +// } +// return@setURLStreamHandlerFactory null +// } } } diff --git a/src/main/resources/assets/minosoft/eros/style.css b/src/main/resources/assets/minosoft/eros/style.css new file mode 100644 index 000000000..02a4d2d50 --- /dev/null +++ b/src/main/resources/assets/minosoft/eros/style.css @@ -0,0 +1,93 @@ +/* + * Minosoft + * Copyright (C) 2021 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + + +* { + -primary-color: #448aff; + -primary-light-color: #83b9ff; + -primary-dark-color: #005ecb; + -secondary-color: #2c3746; + -secondary-light-color: #566171; + -secondary-dark-color: #03111f; + -primary-text-color: #000000; + -secondary-text-color: #ffffff; + -secondary-light-light-color: #868191; +} + +.root { + -fx-background-color: -secondary-color; + -fx-text-fill: -secondary-text-color; +} + +.label { + -fx-text-fill: -secondary-text-color; +} + +.combo-box .list-cell { + -fx-background: -secondary-color; + -fx-background-color: transparent; + -fx-text-fill: -secondary-text-color; +} + +.combo-box-popup .list-view { + -fx-background-color: -secondary-color; +} + +.combo-box-popup .list-view .list-cell:filled:selected, .combo-box-popup .list-view .list-cell:filled:selected:hover { + -fx-background: -primary-light-color; + -fx-background-color: -secondary-dark-color; + -fx-text-fill: -secondary-text-color; +} + +.combo-box-popup .list-view .list-cell:filled:hover { + -fx-background-color: -secondary-light-color; + -fx-text-fill: -secondary-text-color; +} + +.combo-box-base { + -fx-background-color: -secondary-color; +} + +.list-cell { + -fx-border-width: 3px; + -fx-background-color: -secondary-color; +} + +.list-cell:selected { + -fx-background-color: -secondary-color; +} + +.list-cell:filled:hover { + -fx-background-color: -secondary-light-color; +} + +.list-view { + -fx-background-color: -secondary-color; +} + +.obfuscated { + -fx-font-family: "Hack"; +} + +.button { + -fx-background-color: -primary-color; + -fx-text-fill: -secondary-text-color; +} + +.check-box { + -fx-text-fill: -secondary-text-color; +} + +.ikonli-font-icon { + -fx-icon-color: -primary-light-color; +}