From c50db6eb568cade2692082a84e0e9826cc23fc36 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sat, 4 Dec 2021 15:29:36 +0100 Subject: [PATCH] profiles: hud --- .../bixilon/minosoft/config/config/Config.kt | 2 - .../minosoft/config/config/chat/ChatConfig.kt | 19 ------- .../minosoft/config/config/game/GameConfig.kt | 3 - .../config/config/game/hud/ChatConfig.kt | 20 ------- .../config/game/hud/InternalMessagesConfig.kt | 20 ------- .../config/config/network/NetworkConfig.kt | 1 - .../config/profile/GlobalProfileManager.kt | 2 + .../config/profile/ProfileCollection.kt | 3 + .../profile/profiles/eros/ErosProfile.kt | 6 +- .../profiles/eros/text/TextC.kt} | 24 +++++--- .../config/profile/profiles/hud/HUDProfile.kt | 37 ++++++++++++ .../profile/profiles/hud/HUDProfileManager.kt | 36 ++++++++++++ .../profiles/hud/HUDProfileSelectEvent.kt | 7 +++ .../config/profile/profiles/hud/chat/ChatC.kt | 56 +++++++++++++++++++ .../profiles/hud/chat/internal/InternalC.kt} | 25 +++++++-- .../profiles/hud/crosshair/CrosshairC.kt} | 21 ++++--- .../minosoft/data/player/LocalPlayerEntity.kt | 3 +- .../minosoft/data/text/TextComponent.kt | 8 +-- .../gui/rendering/gui/hud/HUDRenderer.kt | 41 +++++++------- .../gui/hud/elements/chat/ChatHUDElement.kt | 16 ++++-- .../chat/InternalMessagesHUDElement.kt | 18 ++++-- .../hud/elements/other/CrosshairHUDElement.kt | 17 +++--- .../clientsettings/ClientSettingsManager.kt | 17 ++++-- .../protocol/packets/s2c/play/JoinGameS2CP.kt | 1 + 24 files changed, 266 insertions(+), 137 deletions(-) delete mode 100644 src/main/java/de/bixilon/minosoft/config/config/chat/ChatConfig.kt delete mode 100644 src/main/java/de/bixilon/minosoft/config/config/game/hud/ChatConfig.kt delete mode 100644 src/main/java/de/bixilon/minosoft/config/config/game/hud/InternalMessagesConfig.kt rename src/main/java/de/bixilon/minosoft/config/{config/game/hud/HUDGameConfig.kt => profile/profiles/eros/text/TextC.kt} (62%) create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfile.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileManager.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileSelectEvent.kt create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/chat/ChatC.kt rename src/main/java/de/bixilon/minosoft/config/{config/game/SkinConfig.kt => profile/profiles/hud/chat/internal/InternalC.kt} (62%) rename src/main/java/de/bixilon/minosoft/config/{config/game/hud/CrosshairConfig.kt => profile/profiles/hud/crosshair/CrosshairC.kt} (67%) diff --git a/src/main/java/de/bixilon/minosoft/config/config/Config.kt b/src/main/java/de/bixilon/minosoft/config/config/Config.kt index bd2ed0112..01907209b 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/Config.kt +++ b/src/main/java/de/bixilon/minosoft/config/config/Config.kt @@ -13,7 +13,6 @@ package de.bixilon.minosoft.config.config -import de.bixilon.minosoft.config.config.chat.ChatConfig import de.bixilon.minosoft.config.config.game.GameConfig import de.bixilon.minosoft.config.config.general.GeneralConfig import de.bixilon.minosoft.config.config.network.NetworkConfig @@ -22,7 +21,6 @@ import de.bixilon.minosoft.config.config.server.ServerConfig data class Config( val general: GeneralConfig = GeneralConfig(), val game: GameConfig = GameConfig(), - val chat: ChatConfig = ChatConfig(), val network: NetworkConfig = NetworkConfig(), val server: ServerConfig = ServerConfig(), ) diff --git a/src/main/java/de/bixilon/minosoft/config/config/chat/ChatConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/chat/ChatConfig.kt deleted file mode 100644 index c06f74705..000000000 --- a/src/main/java/de/bixilon/minosoft/config/config/chat/ChatConfig.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020 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.config.config.chat - -data class ChatConfig( - var colored: Boolean = true, - var obfuscated: Boolean = true, -) diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt index 0a7fbd23c..b232b85ab 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt +++ b/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt @@ -15,11 +15,8 @@ package de.bixilon.minosoft.config.config.game import de.bixilon.minosoft.config.config.game.controls.ControlsGameConfig import de.bixilon.minosoft.config.config.game.graphics.GraphicsGameConfig -import de.bixilon.minosoft.config.config.game.hud.HUDGameConfig data class GameConfig( var graphics: GraphicsGameConfig = GraphicsGameConfig(), - var hud: HUDGameConfig = HUDGameConfig(), var controls: ControlsGameConfig = ControlsGameConfig(), - var skin: SkinConfig = SkinConfig(), ) diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/hud/ChatConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/game/hud/ChatConfig.kt deleted file mode 100644 index 1b3c91eba..000000000 --- a/src/main/java/de/bixilon/minosoft/config/config/game/hud/ChatConfig.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.config.config.game.hud - -data class ChatConfig( - var enabled: Boolean = true, - var width: Int = 320, - var height: Int = 180, -) diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/hud/InternalMessagesConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/game/hud/InternalMessagesConfig.kt deleted file mode 100644 index a5da20c75..000000000 --- a/src/main/java/de/bixilon/minosoft/config/config/game/hud/InternalMessagesConfig.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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.config.config.game.hud - -data class InternalMessagesConfig( - var enabled: Boolean = true, - var width: Int = 320, - var height: Int = 120, -) diff --git a/src/main/java/de/bixilon/minosoft/config/config/network/NetworkConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/network/NetworkConfig.kt index e086f7ee7..f7d4b0c17 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/network/NetworkConfig.kt +++ b/src/main/java/de/bixilon/minosoft/config/config/network/NetworkConfig.kt @@ -16,6 +16,5 @@ package de.bixilon.minosoft.config.config.network import com.squareup.moshi.Json data class NetworkConfig( - @Json(name = "fake_network_brand") var fakeNetworkBrand: Boolean = false, @Json(name = "show_lan_servers") var showLanServers: Boolean = true, ) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt b/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt index 76f18e441..032685dc0 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/GlobalProfileManager.kt @@ -8,6 +8,7 @@ import de.bixilon.minosoft.config.profile.profiles.block.BlockProfileManager import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfileManager import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfileManager import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfileManager import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager @@ -36,6 +37,7 @@ object GlobalProfileManager { RenderingProfileManager, BlockProfileManager, ConnectionProfileManager, + HUDProfileManager, ) private val SELECTED_PROFILES_TYPE: MapType = Jackson.MAPPER.typeFactory.constructMapType(HashMap::class.java, ResourceLocation::class.java, String::class.java) val CLASS_MAPPING: Map, ProfileManager<*>> diff --git a/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt b/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt index d6ce44aa2..0935f6921 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/ProfileCollection.kt @@ -10,6 +10,8 @@ import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfile import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfile +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfileManager import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfile import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfile @@ -26,4 +28,5 @@ data class ProfileCollection( val rendering: RenderingProfile = RenderingProfileManager.selected, val block: BlockProfile = BlockProfileManager.selected, val connection: ConnectionProfile = ConnectionProfileManager.selected, + val hud: HUDProfile = HUDProfileManager.selected, ) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt index 14a507a08..9d661511e 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/ErosProfile.kt @@ -5,6 +5,7 @@ import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.deleg import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.eros.general.GeneralC import de.bixilon.minosoft.config.profile.profiles.eros.server.ServerC +import de.bixilon.minosoft.config.profile.profiles.eros.text.TextC /** * Profile for Eros @@ -19,8 +20,9 @@ class ErosProfile( override val description by delegate(description ?: "") - val general: GeneralC = GeneralC() - val server: ServerC = ServerC() + val general = GeneralC() + val server = ServerC() + val text = TextC() override fun toString(): String { return ErosProfileManager.getName(this) diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/hud/HUDGameConfig.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/text/TextC.kt similarity index 62% rename from src/main/java/de/bixilon/minosoft/config/config/game/hud/HUDGameConfig.kt rename to src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/text/TextC.kt index 09e30677d..39569bc90 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/game/hud/HUDGameConfig.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/text/TextC.kt @@ -11,13 +11,21 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.config.config.game.hud +package de.bixilon.minosoft.config.profile.profiles.eros.text -import com.squareup.moshi.Json +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate -data class HUDGameConfig( - var scale: Float = 2.0f, - var crosshair: CrosshairConfig = CrosshairConfig(), - var chat: ChatConfig = ChatConfig(), - @Json(name = "internal_messages") var internalMessages: InternalMessagesConfig = InternalMessagesConfig(), -) +class TextC { + + /** + * Displays colored text + * If disables it displays the css defined language (defaults to white) + */ + var colored by delegate(true) + + /** + * Enables the obfuscated formatting style + * If false, the text will just blink + */ + var obfuscated by delegate(true) +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfile.kt new file mode 100644 index 000000000..0cfb60e5a --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfile.kt @@ -0,0 +1,37 @@ +package de.bixilon.minosoft.config.profile.profiles.hud + +import de.bixilon.minosoft.config.profile.profiles.Profile +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfileManager.delegate +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfileManager.latestVersion +import de.bixilon.minosoft.config.profile.profiles.hud.chat.ChatC +import de.bixilon.minosoft.config.profile.profiles.hud.crosshair.CrosshairC + +/** + * Profile for hud (rendering) + */ +class HUDProfile( + description: String? = null, +) : Profile { + override var initializing: Boolean = true + private set + override var saved: Boolean = true + override val version: Int = latestVersion + override val description by delegate(description ?: "") + + /** + * The scale of the hud + * Must be non-negative + */ + var scale by delegate(2.0f) { check(it >= 0.0f) { "HUD scale must be non-negative" } } + + val chat = ChatC() + val crosshair = CrosshairC() + + override fun toString(): String { + return HUDProfileManager.getName(this) + } + + init { + initializing = false + } +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileManager.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileManager.kt new file mode 100644 index 000000000..4df785cd0 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileManager.kt @@ -0,0 +1,36 @@ +package de.bixilon.minosoft.config.profile.profiles.hud + +import com.google.common.collect.HashBiMap +import de.bixilon.minosoft.config.profile.GlobalProfileManager +import de.bixilon.minosoft.config.profile.ProfileManager +import de.bixilon.minosoft.modding.event.master.GlobalEventMaster +import de.bixilon.minosoft.util.KUtil.toResourceLocation +import de.bixilon.minosoft.util.KUtil.unsafeCast +import java.util.concurrent.locks.ReentrantLock + +object HUDProfileManager : ProfileManager { + override val namespace = "minosoft:hud".toResourceLocation() + override val latestVersion = 1 + override val saveLock = ReentrantLock() + override val profileClass = HUDProfile::class.java + + + override var currentLoadingPath: String? = null + override val profiles: HashBiMap = HashBiMap.create() + + override var selected: HUDProfile = null.unsafeCast() + set(value) { + field = value + GlobalProfileManager.selectProfile(this, value) + GlobalEventMaster.fireEvent(HUDProfileSelectEvent(value)) + } + + override fun createDefaultProfile(name: String): HUDProfile { + currentLoadingPath = name + val profile = HUDProfile("Default hud profile") + currentLoadingPath = null + profiles[name] = profile + + return profile + } +} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileSelectEvent.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileSelectEvent.kt new file mode 100644 index 000000000..cc33f7d22 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/HUDProfileSelectEvent.kt @@ -0,0 +1,7 @@ +package de.bixilon.minosoft.config.profile.profiles.hud + +import de.bixilon.minosoft.modding.event.events.Event + +class HUDProfileSelectEvent( + val profile: HUDProfile, +) : Event diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/chat/ChatC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/chat/ChatC.kt new file mode 100644 index 000000000..0443d7343 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/chat/ChatC.kt @@ -0,0 +1,56 @@ +/* + * 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.config.profile.profiles.hud.chat + +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfileManager.delegate +import de.bixilon.minosoft.config.profile.profiles.hud.chat.internal.InternalC +import de.bixilon.minosoft.protocol.packets.c2s.play.ClientSettingsC2SP + +class ChatC { + val internal = InternalC() + + /** + * Hides the chat + */ + var hidden by delegate(false) + + /** + * The width of the chat in scaled pixels + */ + var width by delegate(320) + + /** + * The height of the chat in scaled pixels + */ + var height by delegate(180) + + /** + * ToDo: Unknown purpose + * Will be sent to the server + */ + var textFiltering by delegate(false) // ToDo: Implement in the client + + /** + * If false, the chat will appear in white + * Will be sent to the server + */ + var chatColors by delegate(true) // ToDo: Implement in the client + + /** + * Chat mode + * Will be sent to the server + */ + var chatMode by delegate(ClientSettingsC2SP.ChatModes.EVERYTHING) + +} diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/SkinConfig.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/chat/internal/InternalC.kt similarity index 62% rename from src/main/java/de/bixilon/minosoft/config/config/game/SkinConfig.kt rename to src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/chat/internal/InternalC.kt index ee65fe6f4..33d8aad99 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/game/SkinConfig.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/chat/internal/InternalC.kt @@ -11,11 +11,24 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.config.config.game +package de.bixilon.minosoft.config.profile.profiles.hud.chat.internal -import com.squareup.moshi.Json -import de.bixilon.minosoft.data.player.Arms +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfileManager.delegate -data class SkinConfig( - @Json(name = "main_arm") val mainArm: Arms = Arms.RIGHT, -) +class InternalC { + + /** + * Hides the internal chat + */ + var hidden by delegate(false) + + /** + * The width of the internal chat in scaled pixels + */ + var width by delegate(320) + + /** + * The height of the internal chat in scaled pixels + */ + var height by delegate(180) +} diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/hud/CrosshairConfig.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/crosshair/CrosshairC.kt similarity index 67% rename from src/main/java/de/bixilon/minosoft/config/config/game/hud/CrosshairConfig.kt rename to src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/crosshair/CrosshairC.kt index 33c5ca4b6..56654d608 100644 --- a/src/main/java/de/bixilon/minosoft/config/config/game/hud/CrosshairConfig.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/hud/crosshair/CrosshairC.kt @@ -11,14 +11,19 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.config.config.game.hud +package de.bixilon.minosoft.config.profile.profiles.hud.crosshair -import com.squareup.moshi.Json +import de.bixilon.minosoft.config.profile.profiles.hud.HUDProfileManager.delegate import de.bixilon.minosoft.data.text.ChatColors -import de.bixilon.minosoft.data.text.RGBColor -data class CrosshairConfig( - var enabled: Boolean = true, - @Json(name = "complementary_color") var complementaryColor: Boolean = true, - var color: RGBColor = ChatColors.WHITE, -) +class CrosshairC { + /** + * Inverts the color of the crosshair according to the background color + */ + var complementaryColor by delegate(true) + + /** + * The color of the crosshair + */ + var color by delegate(ChatColors.WHITE) +} diff --git a/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt b/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt index daaf09622..98c46cbc9 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/player/LocalPlayerEntity.kt @@ -12,7 +12,6 @@ */ package de.bixilon.minosoft.data.player -import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.data.Axes import de.bixilon.minosoft.data.abilities.Gamemodes import de.bixilon.minosoft.data.abilities.ItemCooldown @@ -581,7 +580,7 @@ class LocalPlayerEntity( get() = healthCondition.hp.toDouble() override val mainArm: Arms - get() = Minosoft.config.config.game.skin.mainArm + get() = connection.profiles.connection.mainArm companion object { private val CLIMBABLE_TAG = "minecraft:climbable".toResourceLocation() 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 13171f099..9d21b2e97 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/TextComponent.kt +++ b/src/main/java/de/bixilon/minosoft/data/text/TextComponent.kt @@ -12,7 +12,7 @@ */ package de.bixilon.minosoft.data.text -import de.bixilon.minosoft.Minosoft +import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager import de.bixilon.minosoft.data.text.events.ClickEvent import de.bixilon.minosoft.data.text.events.HoverEvent import de.bixilon.minosoft.gui.eros.dialog.ErosErrorReport.Companion.report @@ -131,7 +131,7 @@ open class TextComponent( override fun getJavaFXText(nodes: ObservableList): ObservableList { val text = Text(this.message) this.color?.let { - if (Minosoft.config.config.chat.colored) { + if (ErosProfileManager.selected.text.colored) { text.fill = Color.rgb(it.red, it.green, it.blue) } } ?: let { @@ -140,8 +140,8 @@ open class TextComponent( for (chatFormattingCode in formatting) { when (chatFormattingCode) { PreChatFormattingCodes.OBFUSCATED -> { - // ToDo: potential memory/performance leak: Stop timeline, when TextComponent isn't shown anymore - val obfuscatedTimeline = if (Minosoft.config.config.chat.obfuscated) { + // ToDo: This is just slow + val obfuscatedTimeline = if (ErosProfileManager.selected.text.obfuscated) { Timeline( KeyFrame(Duration.millis(50.0), { val chars = text.text.toCharArray() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt index 7f2b640e5..d37af2554 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDRenderer.kt @@ -13,10 +13,10 @@ package de.bixilon.minosoft.gui.rendering.gui.hud -import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.config.key.KeyAction import de.bixilon.minosoft.config.key.KeyBinding import de.bixilon.minosoft.config.key.KeyCodes +import de.bixilon.minosoft.config.profile.change.listener.SimpleChangeListener.Companion.listenRendering import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.gui.rendering.Drawable import de.bixilon.minosoft.gui.rendering.RenderWindow @@ -58,6 +58,7 @@ class HUDRenderer( val connection: PlayConnection, override val renderWindow: RenderWindow, ) : Renderer, OtherDrawable { + private val profile = connection.profiles.hud override val renderSystem: RenderSystem = renderWindow.renderSystem val shader = renderWindow.renderSystem.createShader("minosoft:hud".toResourceLocation()) var scaledSize: Vec2i = renderWindow.window.size @@ -87,16 +88,11 @@ class HUDRenderer( private fun registerDefaultElements() { registerElement(DebugHUDElement) - if (Minosoft.config.config.game.hud.crosshair.enabled) { - registerElement(CrosshairHUDElement) - } + registerElement(CrosshairHUDElement) registerElement(BossbarHUDElement) - if (Minosoft.config.config.game.hud.chat.enabled) { - registerElement(ChatHUDElement) - } - if (Minosoft.config.config.game.hud.internalMessages.enabled) { - registerElement(InternalMessagesHUDElement) - } + registerElement(ChatHUDElement) + + registerElement(InternalMessagesHUDElement) registerElement(BreakProgressHUDElement) registerElement(TabListHUDElement) registerElement(HotbarHUDElement) @@ -105,19 +101,22 @@ class HUDRenderer( registerElement(ScoreboardHUDElement) } - override fun init() { - connection.registerEvent(CallbackEventInvoker.of { - scaledSize = Vec2i(Vec2(it.size) / Minosoft.config.config.game.hud.scale) - matrix = glm.ortho(0.0f, scaledSize.x.toFloat(), scaledSize.y.toFloat(), 0.0f) - matrixChange = true + private fun recalculateMatrices(windowSize: Vec2i = renderWindow.window.size, scale: Float = profile.scale) { + scaledSize = Vec2i(Vec2(windowSize) / scale) + matrix = glm.ortho(0.0f, scaledSize.x.toFloat(), scaledSize.y.toFloat(), 0.0f) + matrixChange = true - for (element in hudElements.toSynchronizedMap().values) { - if (element is LayoutedHUDElement<*>) { - element.layout.silentApply() - } - element.apply() + for (element in hudElements.toSynchronizedMap().values) { + if (element is LayoutedHUDElement<*>) { + element.layout.silentApply() } - }) + element.apply() + } + } + + override fun init() { + connection.registerEvent(CallbackEventInvoker.of { recalculateMatrices(it.size) }) + profile::scale.listenRendering(this, profile = profile) { recalculateMatrices(scale = it) } atlasManager.init() registerDefaultElements() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatHUDElement.kt index a830ccc88..8148b7b41 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/ChatHUDElement.kt @@ -13,7 +13,7 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.chat -import de.bixilon.minosoft.Minosoft +import de.bixilon.minosoft.config.profile.change.listener.SimpleChangeListener.Companion.listenRendering import de.bixilon.minosoft.data.ChatTextPositions import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextFlowElement @@ -28,15 +28,23 @@ import glm_.vec2.Vec2i class ChatHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement(hudRenderer) { private val connection = renderWindow.connection + private val profile = connection.profiles.hud + private val chatProfile = profile.chat override val layout = TextFlowElement(hudRenderer, 20000) + override var enabled: Boolean + get() = !chatProfile.hidden + set(value) { + chatProfile.hidden = !value + } override val layoutOffset: Vec2i get() = Vec2i(2, hudRenderer.scaledSize.y - layout.size.y - BOTTOM_OFFSET) init { - val config = Minosoft.config.config.game.hud.chat - layout.prefMaxSize = Vec2i(config.width, config.height) + layout.prefMaxSize = Vec2i(chatProfile.width, chatProfile.height) + chatProfile::width.listenRendering(this, profile = profile) { layout.prefMaxSize = Vec2i(it, layout.prefMaxSize.y) } + chatProfile::height.listenRendering(this, profile = profile) { layout.prefMaxSize = Vec2i(layout.prefMaxSize.x, it) } } @@ -48,7 +56,7 @@ class ChatHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement { - if (Minosoft.config.config.game.hud.internalMessages.enabled) { + if (!profile.chat.internal.hidden) { return@of } layout += it.message diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalMessagesHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalMessagesHUDElement.kt index db1529463..0e2112e77 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalMessagesHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/chat/InternalMessagesHUDElement.kt @@ -13,7 +13,7 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.chat -import de.bixilon.minosoft.Minosoft +import de.bixilon.minosoft.config.profile.change.listener.SimpleChangeListener.Companion.listenRendering import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextFlowElement import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer @@ -26,22 +26,28 @@ import glm_.vec2.Vec2i class InternalMessagesHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement(hudRenderer) { private val connection = renderWindow.connection + private val profile = connection.profiles.hud + private val internalChatProfile = profile.chat.internal override val layout = TextFlowElement(hudRenderer, 15000) + override var enabled: Boolean + get() = !internalChatProfile.hidden + set(value) { + internalChatProfile.hidden = !value + } override val layoutOffset: Vec2i get() = hudRenderer.scaledSize - Vec2i(layout.size.x, layout.size.y + BOTTOM_OFFSET) init { - val config = Minosoft.config.config.game.hud.internalMessages - layout.prefMaxSize = Vec2i(config.width, config.height) + layout.prefMaxSize = Vec2i(internalChatProfile.width, internalChatProfile.height) + internalChatProfile::width.listenRendering(this, profile = profile) { layout.prefMaxSize = Vec2i(it, layout.prefMaxSize.y) } + internalChatProfile::height.listenRendering(this, profile = profile) { layout.prefMaxSize = Vec2i(layout.prefMaxSize.x, it) } } override fun init() { - connection.registerEvent(CallbackEventInvoker.of { - layout += it.message - }) + connection.registerEvent(CallbackEventInvoker.of { layout += it.message }) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt index 28e64125a..f49773eb3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt @@ -13,7 +13,7 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.other -import de.bixilon.minosoft.Minosoft +import de.bixilon.minosoft.config.profile.change.listener.SimpleChangeListener.Companion.listen import de.bixilon.minosoft.data.abilities.Gamemodes import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer @@ -28,25 +28,29 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList class CrosshairHUDElement(hudRenderer: HUDRenderer) : CustomHUDElement(hudRenderer) { + private val profile = hudRenderer.connection.profiles.hud + private val crosshairProfile = profile.crosshair private lateinit var crosshairAtlasElement: HUDAtlasElement private var mesh: GUIMesh? = null private var previousDebugEnabled: Boolean? = true + private var reapply = true override fun init() { crosshairAtlasElement = hudRenderer.atlasManager[ATLAS_NAME]!! + crosshairProfile::color.listen(this, profile = profile) { reapply = true } } override fun draw() { val debugHUDElement: DebugHUDElement? = hudRenderer[DebugHUDElement] - if (debugHUDElement?.enabled != previousDebugEnabled) { + if (debugHUDElement?.enabled != previousDebugEnabled || reapply) { apply() previousDebugEnabled = debugHUDElement?.enabled } val mesh = mesh ?: return - if (Minosoft.config.config.game.hud.crosshair.complementaryColor) { + if (crosshairProfile.complementaryColor) { renderWindow.renderSystem.reset(blending = true, sourceAlpha = BlendingFunctions.ONE_MINUS_DESTINATION_COLOR, destinationAlpha = BlendingFunctions.ONE_MINUS_SOURCE_COLOR) } else { renderWindow.renderSystem.reset() @@ -60,15 +64,13 @@ class CrosshairHUDElement(hudRenderer: HUDRenderer) : CustomHUDElement(hudRender mesh?.unload() this.mesh = null - val config = Minosoft.config.config.game.hud.crosshair - val mesh = GUIMesh(renderWindow, hudRenderer.matrix, DirectArrayFloatList(42)) // Custom draw to make the crosshair inverted if (renderWindow.connection.player.gamemode == Gamemodes.SPECTATOR) { val hitResult = renderWindow.inputHandler.camera.target ?: return - if (hitResult is EntityRaycastHit && (hitResult !is BlockRaycastHit || renderWindow.connection.world.getBlockEntity(hitResult.blockPosition) == null)) { + if (hitResult !is EntityRaycastHit && (hitResult !is BlockRaycastHit || renderWindow.connection.world.getBlockEntity(hitResult.blockPosition) == null)) { return } } @@ -82,13 +84,14 @@ class CrosshairHUDElement(hudRenderer: HUDRenderer) : CustomHUDElement(hudRender val start = (hudRenderer.scaledSize - CROSSHAIR_SIZE) / 2 - mesh.addQuad(start, start + CROSSHAIR_SIZE, 0, crosshairAtlasElement, config.color, null) + mesh.addQuad(start, start + CROSSHAIR_SIZE, 0, crosshairAtlasElement, crosshairProfile.color, null) // ToDo: Attack indicator mesh.load() this.mesh = mesh + this.reapply = false } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/clientsettings/ClientSettingsManager.kt b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/clientsettings/ClientSettingsManager.kt index 12f74e20f..97cff02e2 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/clientsettings/ClientSettingsManager.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/clientsettings/ClientSettingsManager.kt @@ -32,6 +32,13 @@ class ClientSettingsManager( blocks::simulationDistance.listen(this, profile = blocks) { connection.world.view.simulationDistance = it } + + val hud = connection.profiles.hud + val chat = hud.chat + chat::chatMode.listen(this, profile = hud) { sendClientSettings() } + chat::textFiltering.listen(this, profile = hud) { sendClientSettings() } + chat::chatColors.listen(this, profile = hud) { sendClientSettings() } + profile::mainArm.listen(this, profile = profile) { sendClientSettings() } profile::playerListing.listen(this, profile = profile) { sendClientSettings() } @@ -46,6 +53,8 @@ class ClientSettingsManager( profile::language.listen(this, profile = profile) { sendLanguage() } connection.profiles.eros.general::language.listen(this, profile = connection.profiles.eros) { sendLanguage() } + + // ToDo: Load new language files } @Synchronized @@ -60,13 +69,13 @@ class ClientSettingsManager( fun sendClientSettings() { connection.sendPacket(ClientSettingsC2SP( - locale = (language).toLanguageTag(), - chatColors = true, // ToDo + locale = language.toString(), + chatColors = connection.profiles.hud.chat.chatColors, viewDistance = connection.profiles.block.viewDistance, - chatMode = ClientSettingsC2SP.ChatModes.EVERYTHING, // ToDo + chatMode = connection.profiles.hud.chat.chatMode, skinParts = profile.skin.skinParts, mainArm = profile.mainArm, - disableTextFiltering = true, // ToDo + disableTextFiltering = !connection.profiles.hud.chat.textFiltering, allowListing = profile.playerListing, )) } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt index ec801554b..395bfbf27 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt @@ -170,6 +170,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { connection.settingsManager.sendClientSettings() + // ToDo: This has nothing to do here! val brandName = DefaultRegistries.DEFAULT_PLUGIN_CHANNELS_REGISTRY.forVersion(connection.version)[DefaultPluginChannels.BRAND]!!.resourceLocation val buffer = PlayOutByteBuffer(connection) buffer.writeString("vanilla") // ToDo: Remove prefix