This repository was archived by the owner on Dec 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathAbstractHudElement.kt
More file actions
120 lines (99 loc) · 4.11 KB
/
AbstractHudElement.kt
File metadata and controls
120 lines (99 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.lambda.client.gui.hudgui
import com.lambda.client.commons.interfaces.Alias
import com.lambda.client.commons.interfaces.DisplayEnum
import com.lambda.client.commons.interfaces.Nameable
import com.lambda.client.event.LambdaEventBus
import com.lambda.client.gui.rgui.windows.BasicWindow
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.modules.client.GuiColors
import com.lambda.client.module.modules.client.Hud
import com.lambda.client.setting.GuiConfig
import com.lambda.client.setting.GuiConfig.setting
import com.lambda.client.setting.configs.AbstractConfig
import com.lambda.client.util.Bind
import com.lambda.client.util.graphics.RenderUtils2D
import com.lambda.client.util.graphics.VertexHelper
import com.lambda.client.util.graphics.font.FontRenderAdapter
import com.lambda.client.util.math.Vec2d
import com.lambda.client.util.math.Vec2f
import com.lambda.client.util.threads.safeListener
import net.minecraftforge.fml.common.gameevent.TickEvent
import org.lwjgl.opengl.GL11.glScalef
abstract class AbstractHudElement(
name: String,
final override val alias: Array<String>,
val category: Category,
val description: String,
val alwaysListening: Boolean,
enabledByDefault: Boolean,
config: AbstractConfig<out Nameable>
) : BasicWindow(name, 20.0f, 20.0f, 100.0f, 50.0f, SettingGroup.HUD_GUI, config), Alias {
val bind by setting("Bind", Bind())
val scale by setting("Scale", 1.0f, 0.1f..4.0f, 0.05f)
val default = setting("Default", false)
override val resizable = false
final override val minWidth: Float get() = FontRenderAdapter.getFontHeight() * scale * 2.0f
final override val minHeight: Float get() = FontRenderAdapter.getFontHeight() * scale
final override val maxWidth: Float get() = hudWidth * scale
final override val maxHeight: Float get() = hudHeight * scale
open val hudWidth: Float get() = 20f
open val hudHeight: Float get() = 10f
val settingList get() = GuiConfig.getSettings(this)
init {
safeListener<TickEvent.ClientTickEvent> {
if (it.phase != TickEvent.Phase.END || !visible) return@safeListener
width = maxWidth
height = maxHeight
}
}
override fun onGuiInit() {
super.onGuiInit()
if (alwaysListening || visible) LambdaEventBus.subscribe(this)
}
override fun onClosed() {
super.onClosed()
if (alwaysListening || visible) LambdaEventBus.subscribe(this)
}
final override fun onTick() {
super.onTick()
}
final override fun onRender(vertexHelper: VertexHelper, absolutePos: Vec2f) {
renderFrame(vertexHelper)
glScalef(scale, scale, scale)
renderHud(vertexHelper)
}
open fun renderHud(vertexHelper: VertexHelper) {}
open fun renderFrame(vertexHelper: VertexHelper) {
RenderUtils2D.drawRectFilled(vertexHelper, Vec2d(0.0, 0.0), Vec2f(renderWidth, renderHeight).toVec2d(), GuiColors.backGround)
RenderUtils2D.drawRectOutline(vertexHelper, Vec2d(0.0, 0.0), Vec2f(renderWidth, renderHeight).toVec2d(), 1.5f, GuiColors.outline)
}
init {
visibleSetting.valueListeners.add { _, it ->
if (it) {
LambdaEventBus.subscribe(this)
lastActiveTime = System.currentTimeMillis()
} else if (!alwaysListening) {
LambdaEventBus.unsubscribe(this)
}
}
default.valueListeners.add { _, it ->
if (it) {
settingList.filter { it != visibleSetting && it != default }.forEach { it.resetValue() }
default.value = false
NotificationManager.registerNotification("$name Set to defaults!")
}
}
if (!enabledByDefault) visible = false
}
enum class Category(override val displayName: String) : DisplayEnum {
CLIENT("Client"),
COMBAT("Combat"),
PLAYER("Player"),
WORLD("World"),
MISC("Misc")
}
protected companion object {
val primaryColor get() = Hud.primaryColor
val secondaryColor get() = Hud.secondaryColor
}
}