diff --git a/api/Vigilance.api b/api/Vigilance.api index 1afa27d..9cc182c 100644 --- a/api/Vigilance.api +++ b/api/Vigilance.api @@ -392,6 +392,7 @@ public final class gg/essential/vigilance/gui/CategoryLabel : gg/essential/eleme public fun (Lgg/essential/vigilance/gui/SettingsGui;Lgg/essential/vigilance/data/Category;)V public final fun deselect ()V public final fun isSelected ()Z + public final fun markSelected ()V public final fun select ()V public final fun setSelected (Z)V } diff --git a/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt b/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt index 3006f23..71e6492 100644 --- a/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt +++ b/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt @@ -11,7 +11,7 @@ import gg.essential.vigilance.data.Category import gg.essential.vigilance.gui.elementa.GuiScaleOffsetConstraint import gg.essential.vigilance.utils.onLeftClick -class CategoryLabel(private val gui: SettingsGui, private val category: Category) : UIContainer() { +class CategoryLabel(private val gui: SettingsGui, internal val category: Category) : UIContainer() { private val text by UIText(category.name).constrain { y = CenterConstraint() @@ -54,11 +54,6 @@ class CategoryLabel(private val gui: SettingsGui, private val category: Category fun select() { gui.selectCategory(category) - - isSelected = true - text.animate { - setColorAnimation(Animations.OUT_EXP, 0.5f, VigilancePalette.textActive.toConstraint()) - } } fun deselect() { @@ -67,4 +62,11 @@ class CategoryLabel(private val gui: SettingsGui, private val category: Category setColorAnimation(Animations.OUT_EXP, 0.5f, VigilancePalette.text.toConstraint()) } } + + fun markSelected() { + isSelected = true + text.animate { + setColorAnimation(Animations.OUT_EXP, 0.5f, VigilancePalette.textActive.toConstraint()) + } + } } diff --git a/src/main/kotlin/gg/essential/vigilance/gui/SettingsGui.kt b/src/main/kotlin/gg/essential/vigilance/gui/SettingsGui.kt index 39b360c..ae68244 100644 --- a/src/main/kotlin/gg/essential/vigilance/gui/SettingsGui.kt +++ b/src/main/kotlin/gg/essential/vigilance/gui/SettingsGui.kt @@ -184,7 +184,16 @@ class SettingsGui( newCategory.scrollToTop() currentCategory = newCategory - sidebarScroller.childrenOfType().firstOrNull { it.isSelected }?.deselect() + val labels = sidebarScroller.childrenOfType() + + labels + .firstOrNull { it.isSelected } + ?.deselect() + + // We compare names because the `items` field could technically be the same but the `Category` could be a different instance. + labels + .firstOrNull { it.category.name == category.name } + ?.markSelected() } override fun updateGuiScale() {