Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/Vigilance.api
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ public final class gg/essential/vigilance/gui/CategoryLabel : gg/essential/eleme
public fun <init> (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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like an implementation detail (granted, the entire CategoryLabel does, but it's too late for that one). When would it ever make sense for a third-party to call this method (rather than select)? If there's no such case, then it should be internal, not part of our public API.

public final fun select ()V
public final fun setSelected (Z)V
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/kotlin/gg/essential/vigilance/gui/CategoryLabel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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() {
Expand All @@ -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())
}
}
Comment on lines +65 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For symmetry I think we should also make a markDeselected (or have this method accept a selected: Boolean) which the current deselect calls, and then slap a @Deprecated on select and deselect because we shouldn't be using them any more, they only exist for backwards compatibility, we should always be using gui.selectCategory (which will in turn only use the mark* method(s)).

}
11 changes: 10 additions & 1 deletion src/main/kotlin/gg/essential/vigilance/gui/SettingsGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,16 @@ class SettingsGui(
newCategory.scrollToTop()
currentCategory = newCategory

sidebarScroller.childrenOfType<CategoryLabel>().firstOrNull { it.isSelected }?.deselect()
val labels = sidebarScroller.childrenOfType<CategoryLabel>()

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But can the same argument not be made for name as well? Shouldn't we just compare by reference?

labels
.firstOrNull { it.category.name == category.name }
?.markSelected()
}

override fun updateGuiScale() {
Expand Down