From b9a22305dce467764b55b81cd0ae4e8fa6f6990d Mon Sep 17 00:00:00 2001 From: nea Date: Sun, 30 Jul 2023 16:31:23 +0200 Subject: Fix overlapping config elements in config overview --- src/main/kotlin/moe/nea/firmament/Firmament.kt | 18 ++++++++++++++---- .../moe/nea/firmament/gui/config/AllConfigsGui.kt | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/moe/nea/firmament/Firmament.kt b/src/main/kotlin/moe/nea/firmament/Firmament.kt index 6564e9b..c3bb0fc 100644 --- a/src/main/kotlin/moe/nea/firmament/Firmament.kt +++ b/src/main/kotlin/moe/nea/firmament/Firmament.kt @@ -27,6 +27,7 @@ import io.ktor.client.plugins.compression.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.logging.* import io.ktor.serialization.kotlinx.json.* +import java.lang.Exception import java.nio.file.Files import java.nio.file.Path import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback @@ -39,6 +40,7 @@ import net.fabricmc.loader.api.metadata.ModMetadata import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder +import org.freedesktop.dbus.exceptions.DBusException import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job @@ -98,8 +100,12 @@ object Firmament { } val globalJob = Job() - val dbusConnection = DBusConnectionBuilder.forSessionBus() - .build() + val dbusConnection = try { + DBusConnectionBuilder.forSessionBus() + .build() + } catch (e: Exception) { + null + } val coroutineScope = CoroutineScope(EmptyCoroutineContext + CoroutineName("Firmament")) + SupervisorJob(globalJob) @@ -117,12 +123,16 @@ object Firmament { @JvmStatic fun onClientInitialize() { - dbusConnection.requestBusName("moe.nea.firmament") + try { + dbusConnection?.exportObject(FirmamentDbusObject) + dbusConnection?.requestBusName("moe.nea.firmament") + } catch (e: DBusException) { + // :( + } var tick = 0 ClientTickEvent.CLIENT_POST.register(ClientTickEvent.Client { instance -> TickEvent.publish(TickEvent(tick++)) }) - dbusConnection.exportObject(FirmamentDbusObject) IDataHolder.registerEvents() RepoManager.initialize() SBData.init() diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt b/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt index e547e3b..fbde4f5 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt @@ -23,8 +23,11 @@ import io.github.cottonmc.cotton.gui.client.CottonClientScreen import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription import io.github.cottonmc.cotton.gui.widget.WBox import io.github.cottonmc.cotton.gui.widget.WButton +import io.github.cottonmc.cotton.gui.widget.WClippedPanel import io.github.cottonmc.cotton.gui.widget.WGridPanel import io.github.cottonmc.cotton.gui.widget.WLabel +import io.github.cottonmc.cotton.gui.widget.WPanel +import io.github.cottonmc.cotton.gui.widget.WPanelWithInsets import io.github.cottonmc.cotton.gui.widget.WScrollPanel import io.github.cottonmc.cotton.gui.widget.data.Axis import io.github.cottonmc.cotton.gui.widget.data.Insets @@ -33,6 +36,7 @@ import net.minecraft.client.gui.screen.Screen import net.minecraft.text.Text import moe.nea.firmament.features.FeatureManager import moe.nea.firmament.gui.WFixedPanel +import moe.nea.firmament.gui.WTightScrollPanel import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.MC import moe.nea.firmament.util.ScreenUtil.setScreenLater @@ -58,12 +62,18 @@ object AllConfigsGui { }, 0, 1, 10, 1) box.add(WFixedPanel(panel)) } - box.insets = Insets.ROOT_PANEL - lwgd.setRootPanel(WScrollPanel((box)).also { + lwgd.setRootPanel(WBox( + Axis.VERTICAL + ).also { + it.insets = Insets.ROOT_PANEL box.layout() - it.setSize(box.width + 8, MC.window.scaledHeight / 2) + it.add(WFixedPanel((WTightScrollPanel((box)).also { + it.setSize(0, MC.window.scaledHeight / 2) + }))) + it.setSize(0, MC.window.scaledHeight / 2) }) - screen = object : CottonClientScreen(lwgd) { + + screen = object : CottonClientScreen(lwgd) { override fun close() { MC.screen = parent } -- cgit