From d9f0189d758b1f5d9fbb1bb4b1c378367d7239bd Mon Sep 17 00:00:00 2001 From: Conor <71222289+cbyrneee@users.noreply.github.com> Date: Sun, 30 Oct 2022 21:54:34 +0000 Subject: [PATCH 1/4] CategoryLabel: Make `category` field internal --- src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt b/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt index 3006f23..14de6cc 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() From 757904539eeb94e0940896a54ea28ee3ab15cd95 Mon Sep 17 00:00:00 2001 From: Conor <71222289+cbyrneee@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:01:40 +0000 Subject: [PATCH 2/4] CategoryLabel: Move visual selection logic to `markSelected()` --- .../gg/essential/vigilance/gui/CategoryLabel.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt b/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt index 14de6cc..71e6492 100644 --- a/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt +++ b/src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt @@ -54,11 +54,6 @@ class CategoryLabel(private val gui: SettingsGui, internal val category: Categor 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, internal val category: Categor setColorAnimation(Animations.OUT_EXP, 0.5f, VigilancePalette.text.toConstraint()) } } + + fun markSelected() { + isSelected = true + text.animate { + setColorAnimation(Animations.OUT_EXP, 0.5f, VigilancePalette.textActive.toConstraint()) + } + } } From 5bd77643d85b5fa973b6e057cc55ef60b011c702 Mon Sep 17 00:00:00 2001 From: Conor <71222289+cbyrneee@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:07:07 +0000 Subject: [PATCH 3/4] SettingsGui: Mark label as selected when calling `selectCategory()` Selecting the category visually and programmatically both call this method, so it's better that we do the visual style here like we do for deselection. --- .../kotlin/gg/essential/vigilance/gui/SettingsGui.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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() { From ce1b793505650ccdf2188347304a5903da3a3781 Mon Sep 17 00:00:00 2001 From: Conor <71222289+cbyrneee@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:12:52 +0000 Subject: [PATCH 4/4] API: Update Vigilance.api --- api/Vigilance.api | 1 + 1 file changed, 1 insertion(+) 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 }