/* * Skytils - Hypixel Skyblock Quality of Life Mod * Copyright (C) 2021 Skytils * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package skytils.skytilsmod.gui import gg.essential.elementa.WindowScreen import gg.essential.elementa.components.* import gg.essential.elementa.components.input.UITextInput import gg.essential.elementa.constraints.* import gg.essential.elementa.dsl.* import gg.essential.elementa.effects.OutlineEffect import gg.essential.vigilance.utils.onLeftClick import net.minecraft.util.ChatAllowedCharacters import skytils.skytilsmod.core.PersistentSave import skytils.skytilsmod.features.impl.handlers.EnchantNames import skytils.skytilsmod.gui.components.SimpleButton import java.awt.Color class EnchantNamesGui : WindowScreen(newGuiScale = 2), ReopenableGUI { private val scrollComponent: ScrollComponent init { UIText("Enchant Names").childOf(window).constrain { x = CenterConstraint() y = RelativeConstraint(0.075f) height = 14.pixels() } scrollComponent = ScrollComponent( innerPadding = 4f, ).childOf(window).constrain { x = CenterConstraint() y = 15.percent() width = 90.percent() height = 70.percent() + 2.pixels() } val bottomButtons = UIContainer().childOf(window).constrain { x = CenterConstraint() y = 90.percent() width = ChildBasedSizeConstraint() height = ChildBasedSizeConstraint() } SimpleButton("Save and Exit").childOf(bottomButtons).constrain { x = 0.pixels() y = 0.pixels() }.onLeftClick { mc.displayGuiScreen(null) } SimpleButton("Add Enchant").childOf(bottomButtons).constrain { x = SiblingConstraint(5f) y = 0.pixels() }.onLeftClick { addNewName() } val tooltipBlock = UIBlock().constrain { x = 5.pixels(); y = basicYConstraint { it.parent.getTop() - it.getHeight() - 6 }; height = ChildBasedSizeConstraint(4f); width = ChildBasedSizeConstraint(4f); color = ConstantColorConstraint(Color(224, 224, 224, 100)) }.effect(OutlineEffect(Color(0, 243, 255), 1f)).also { it.hide() } .addChild(UIWrappedText("What are enchant names? Enchant names simply rename enchants to be anything you want!").constrain { x = 2.pixels(); y = 0.pixels(); width = 90.percentOfWindow() }) UICircle(7f).childOf(window).constrain { x = 9.pixels() y = basicYConstraint { it.parent.getBottom() - it.getHeight() - 2 } }.addChildren( UIText("?", true).constrain { x = CenterConstraint(); y = CenterConstraint() }, tooltipBlock ).onMouseEnter { tooltipBlock.unhide() }.onMouseLeave { tooltipBlock.hide() } for (replacement in EnchantNames.replacements) { addNewName(replacement.key, replacement.value) } } private fun addNewName(name: String = "", replacement: String = "") { val container = UIContainer().childOf(scrollComponent).constrain { x = CenterConstraint() y = SiblingConstraint(5f) width = 80.percent() height = 9.5.percent() }.effect(OutlineEffect(Color(0, 243, 255), 1f)) (UITextInput("Enchant Name").childOf(container).constrain { x = 5.pixels() y = CenterConstraint() width = 40.percent() }.onLeftClick { grabWindowFocus() } as UITextInput).also { it.setText(name) it.onKeyType { _, _ -> it.setText(it.getText().filter(ChatAllowedCharacters::isAllowedCharacter).take(255)) } } (UITextInput("Replacement").childOf(container).constrain { x = SiblingConstraint(5f) y = CenterConstraint() width = 40.percent() }.onLeftClick { grabWindowFocus() } as UITextInput).also { it.setText(replacement) it.onKeyType { _, _ -> it.setText(it.getText().filter(ChatAllowedCharacters::isAllowedCharacter).take(255)) } } SimpleButton("Remove").childOf(container).constrain { x = 85.percent() y = CenterConstraint() height = 75.percent() }.onLeftClick { scrollComponent.removeChild(container) } } override fun onScreenClose() { super.onScreenClose() EnchantNames.replacements.clear() for (container in scrollComponent.allChildren) { val text = container.childrenOfType() if (text.size != 2) throw IllegalStateException("${container.componentName} does not have 2 UITextInput's! Available children ${container.children.map { it.componentName }}") val name = (text.find { it.placeholder == "Enchant Name" } ?: throw IllegalStateException("${container.componentName} does not have the enchant UITextInput! Available children ${container.children.map { it.componentName }}")).getText() val replacement = (text.find { it.placeholder == "Replacement" } ?: throw IllegalStateException("${container.componentName} does not have the replacement UITextInput! Available children ${container.children.map { it.componentName }}")).getText() if (name.isBlank() || replacement.isBlank()) continue println("$name $replacement") EnchantNames.replacements[name] = replacement } PersistentSave.markDirty() } }