/* * Gimbal * Copyright (C) 2024 moonleay * * 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 . */ package net.moonleay.gimbal.client.screen import net.minecraft.client.gui.screen.Screen import net.minecraft.client.gui.widget.ButtonWidget import net.minecraft.client.gui.widget.CyclingButtonWidget import net.minecraft.client.util.math.MatrixStack import net.minecraft.screen.ScreenTexts import net.minecraft.text.Text import net.moonleay.gimbal.client.config.ClientConfigHolder import net.moonleay.gimbal.client.config.GimbalClientConfig import net.moonleay.gimbal.client.config.GimbalGuiSettings class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfigHolder) : Screen(Text.translatable("gimbal.gui.settings")) { override fun init() { this.addDrawableChild(CyclingButtonWidget.onOffBuilder( // Text.translatable("gimbal.gui.enabled"), // Text.translatable("gimbal.gui.disabled") ) .initially(cfg.config.guiSettings.showHud) .build( this.width / 2 - 155, this.height / 6 + 24 * 0, 150, 20, Text.translatable("gimbal.gui.hud") ) { _: CyclingButtonWidget?, isEnabled: Boolean? -> val oldGui = cfg.config.guiSettings val newGui = GimbalGuiSettings( showHud = isEnabled ?: true, offset = oldGui.offset, horizontalAnchor = oldGui.horizontalAnchor, verticalAnchor = oldGui.verticalAnchor, ) val newConf = GimbalClientConfig( guiSettings = newGui, showToasts = cfg.config.showToasts ) cfg.updateConfig(newConf) }) this.addDrawableChild(ButtonWidget( this.width / 2 - 155 + 160, this.height / 6 + 24 * 0, 150, 20, Text.translatable("gimbal.gui.edithud") ) { _: ButtonWidget? -> this.client!!.setScreen(GimbalEditHudGui(this, cfg)) } ) // Done button this.addDrawableChild(ButtonWidget( this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE ) { _: ButtonWidget? -> this.client!!.setScreen( this.parent ) }) } override fun render(matrices: MatrixStack?, mouseX: Int, mouseY: Int, delta: Float) { this.renderBackground(matrices) drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215) super.render(matrices, mouseX, mouseY, delta) } }