Skip to content

Commit 3fd22fe

Browse files
rfresh2Avanatiker
andauthored
HUD: Bindings Element (#383)
* Bindings list HUD element (cherry picked from commit ccc4cad) * settings for text shadow and line v spacing * ignore client bindings setting * Changed to LabelHud sry but is way less code and same features Co-authored-by: Constructor <[email protected]>
1 parent b28c739 commit 3fd22fe

File tree

1 file changed

+55
-0
lines changed
  • src/main/kotlin/com/lambda/client/gui/hudgui/elements/client

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.lambda.client.gui.hudgui.elements.client
2+
3+
import com.lambda.client.commons.interfaces.DisplayEnum
4+
import com.lambda.client.event.SafeClientEvent
5+
import com.lambda.client.gui.hudgui.LabelHud
6+
import com.lambda.client.module.AbstractModule
7+
import com.lambda.client.module.ModuleManager
8+
import com.lambda.client.util.color.ColorHolder
9+
import com.lambda.client.util.graphics.font.HAlign
10+
import com.lambda.client.util.threads.safeAsyncListener
11+
import net.minecraftforge.fml.common.gameevent.TickEvent
12+
13+
internal object Bindings : LabelHud(
14+
name = "Bindings",
15+
category = Category.CLIENT,
16+
description = "Display current module keybindings"
17+
) {
18+
19+
private val sortingMode by setting("Sorting Mode", SortingMode.LENGTH)
20+
private val ignoreClientBindings by setting("Ignore Client Category", true,
21+
description = "Ignore bindings for client specific bindings like the ClickGUI")
22+
23+
@Suppress("UNUSED")
24+
private enum class SortingMode(
25+
override val displayName: String,
26+
val comparator: Comparator<AbstractModule>
27+
) : DisplayEnum {
28+
LENGTH("Length", compareByDescending { it.name.length }),
29+
ALPHABET("Alphabet", compareBy { it.name }),
30+
CATEGORY("Category", compareBy { it.category.ordinal })
31+
}
32+
33+
private var modulesWithBindings: List<AbstractModule> = emptyList()
34+
35+
init {
36+
dockingH = HAlign.RIGHT
37+
38+
safeAsyncListener<TickEvent.ClientTickEvent> { event ->
39+
if (event.phase != TickEvent.Phase.END) return@safeAsyncListener
40+
41+
// this isn't terribly efficient, consider creating events for editing bindings and module toggle state
42+
modulesWithBindings = ModuleManager.modules
43+
.sortedWith(sortingMode.comparator)
44+
.filter { if (ignoreClientBindings) it.category != com.lambda.client.module.Category.CLIENT else true }
45+
.filterNot { it.bind.value.isEmpty }
46+
}
47+
}
48+
49+
override fun SafeClientEvent.updateText() {
50+
modulesWithBindings.forEach {
51+
displayText.add(it.name, if (it.isEnabled) ColorHolder(0, 255, 0) else primaryColor)
52+
displayText.addLine(it.bind.toString(), secondaryColor)
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)