Skip to content

Commit b630bd0

Browse files
committed
Improved MenuBar
1 parent 872814a commit b630bd0

File tree

14 files changed

+227
-232
lines changed

14 files changed

+227
-232
lines changed

src/main/kotlin/com/lambda/config/AbstractSetting.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ abstract class AbstractSetting<T : Any>(
158158
groups.add(path.toList())
159159
}
160160

161-
fun reset() {
162-
if (value == defaultValue) {
161+
fun reset(silent: Boolean = false) {
162+
if (!silent && value == defaultValue) {
163163
ConfigCommand.info(notChangedMessage())
164164
return
165165
}
166-
ConfigCommand.info(resetMessage(value, defaultValue))
166+
if (!silent) ConfigCommand.info(resetMessage(value, defaultValue))
167167
value = defaultValue
168168
}
169169

src/main/kotlin/com/lambda/gui/DearImGui.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ object DearImGui : Loadable {
4343
val implGlfw = ImGuiImplGlfw()
4444
val implGl3 = ImGuiImplGl3()
4545

46+
const val EXTERNAL_LINK = ''
47+
4648
val io: ImGuiIO get() = ImGui.getIO()
4749
const val DEFAULT_FLAGS = ImGuiConfigFlags.NavEnableKeyboard or // Enable Keyboard Controls
4850
ImGuiConfigFlags.NavEnableSetMousePos or // Move the cursor using the keyboard
@@ -59,7 +61,7 @@ object DearImGui : Loadable {
5961
val glyphRanges = ImFontGlyphRangesBuilder().apply {
6062
addRanges(io.fonts.glyphRangesDefault)
6163
addRanges(io.fonts.glyphRangesGreek)
62-
addChar('') // U+2934 for external links
64+
addChar(EXTERNAL_LINK)
6365
}.buildRanges()
6466
io.fonts.addFontFromFileTTF("fonts/FiraSans-Regular.ttf".path, baseFontSize * scale, ImFontConfig(), glyphRanges)
6567
io.fonts.build()

src/main/kotlin/com/lambda/gui/MenuBar.kt

Lines changed: 126 additions & 183 deletions
Large diffs are not rendered by default.

src/main/kotlin/com/lambda/gui/components/ClickGuiLayout.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ import com.lambda.gui.MenuBar.buildMenuBar
2424
import com.lambda.gui.dsl.ImGuiBuilder.buildLayout
2525
import com.lambda.module.ModuleRegistry
2626
import com.lambda.module.modules.client.ClickGui
27-
import com.lambda.module.tag.ModuleTag
27+
import com.lambda.module.tag.ModuleTag.Companion.shownTags
2828
import imgui.ImGui
2929
import imgui.flag.ImGuiWindowFlags.AlwaysAutoResize
3030

3131
object ClickGuiLayout : Loadable {
32-
private val shownTags = ModuleTag.defaults.toMutableList()
33-
3432
init {
3533
listen<GuiEvent.NewFrame> {
3634
if (!ClickGui.isEnabled) return@listen
@@ -41,17 +39,6 @@ object ClickGuiLayout : Loadable {
4139
ModuleRegistry.modules
4240
.filter { it.tag == tag }
4341
.forEach { with(ModuleEntry(it)) { buildLayout() } }
44-
45-
// ToDo: Add a proper context menu to the window
46-
popupContextWindow("lambda_window_ctx") {
47-
text("Window Menu")
48-
separator()
49-
menuItem("Close This Window") {
50-
// ToDo (Close under-cursor window):
51-
// - Requires a mapping from ImGui window to your visibility flag.
52-
// - Can be implemented if you track per-window IDs & vis flags.
53-
}
54-
}
5542
}
5643
}
5744

src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ object HudGuiLayout : Loadable {
2929
const val DEFAULT_HUD_FLAGS =
3030
ImGuiWindowFlags.NoDecoration or
3131
ImGuiWindowFlags.NoBackground or
32-
ImGuiWindowFlags.AlwaysAutoResize
32+
ImGuiWindowFlags.AlwaysAutoResize or
33+
ImGuiWindowFlags.NoDocking
3334

3435
init {
3536
listen<GuiEvent.NewFrame> {

src/main/kotlin/com/lambda/gui/components/ModuleEntry.kt

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,46 @@ import com.lambda.gui.Layout
2222
import com.lambda.gui.dsl.ImGuiBuilder
2323
import com.lambda.module.Module
2424
import com.lambda.util.NamedEnum
25+
import com.lambda.util.KeyCode
26+
import imgui.ImGui
2527
import imgui.flag.ImGuiTabBarFlags
28+
import imgui.flag.ImGuiCol
2629

2730
class ModuleEntry(val module: Module): Layout {
2831
override fun ImGuiBuilder.buildLayout() {
29-
checkbox("##-$module", module::isEnabled)
32+
if (module.isEnabled) {
33+
withStyleColor(ImGuiCol.Header, 0.20f, 0.55f, 0.25f, 0.85f) {
34+
withStyleColor(ImGuiCol.HeaderHovered, 0.25f, 0.65f, 0.30f, 0.90f) {
35+
withStyleColor(ImGuiCol.HeaderActive, 0.20f, 0.55f, 0.25f, 1.00f) {
36+
selectable(module.name, selected = true) {
37+
module.toggle()
38+
}
39+
}
40+
}
41+
}
42+
} else {
43+
selectable(module.name, selected = false) {
44+
module.toggle()
45+
}
46+
}
3047
lambdaTooltip(module.description)
31-
sameLine()
32-
treeNode(module.name) {
33-
lambdaTooltip(module.description)
48+
49+
ImGui.setNextWindowSizeConstraints(0f, 0f, Float.MAX_VALUE, io.displaySize.y * 0.5f)
50+
popupContextItem("##ctx-${module.name}") {
3451
group {
35-
val visibleSettings = module.settings.filter { it.visibility() }
52+
with(module.keybindSetting) { buildLayout() }
53+
sameLine()
54+
smallButton("Reset") {
55+
module.settings.forEach { it.reset(silent = true) }
56+
}
57+
lambdaTooltip("Resets all settings for this module to their default values")
58+
}
59+
separator()
60+
group {
61+
val visibleSettings = module.settings.filter { it.visibility() } - module.keybindSetting
3662
val (grouped, ungrouped) = visibleSettings.partition { it.groups.isNotEmpty() }
3763

3864
ungrouped.forEach { with(it) { buildLayout() } }
39-
4065
renderGroup(grouped, emptyList())
4166
}
4267
}

src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@
3636

3737
package com.lambda.gui.dsl
3838

39-
import com.lambda.context.SafeContext
4039
import com.lambda.gui.dsl.ImGuiBuilder.text
4140
import com.lambda.module.modules.client.ClickGui
42-
import com.lambda.threading.runSafe
4341
import com.lambda.util.math.Vec2d
4442
import imgui.*
4543
import imgui.ImGui.*

src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import com.lambda.config.Configuration
2424
import com.lambda.config.configurations.ModuleConfig
2525
import com.lambda.context.SafeContext
2626
import com.lambda.event.Muteable
27+
import com.lambda.event.events.ClientEvent
28+
import com.lambda.event.events.ConnectionEvent
2729
import com.lambda.event.events.KeyboardEvent
2830
import com.lambda.event.listener.Listener
2931
import com.lambda.event.listener.SafeListener
@@ -111,10 +113,10 @@ abstract class Module(
111113
private val alwaysListening: Boolean = false,
112114
enabledByDefault: Boolean = false,
113115
defaultKeybind: KeyCode = KeyCode.UNBOUND,
116+
autoDisable: Boolean = false
114117
) : Nameable, Muteable, Configurable(ModuleConfig) {
115118
private val isEnabledSetting = setting("Enabled", enabledByDefault) { false }
116-
private val keybindSetting = setting("Keybind", defaultKeybind)
117-
val reset by setting("Reset", { settings.forEach { it.reset() }; this@Module.info("Settings set to default") }, "Reset settings values to default.")
119+
val keybindSetting = setting("Keybind", defaultKeybind) { false }
118120

119121
open val isVisible: Boolean = true
120122

@@ -142,6 +144,10 @@ abstract class Module(
142144

143145
onEnableUnsafe { LambdaSound.MODULE_ON.play() }
144146
onDisableUnsafe { LambdaSound.MODULE_OFF.play() }
147+
148+
listen<ClientEvent.Shutdown> { if (autoDisable) disable() }
149+
listen<ClientEvent.Startup> { if (autoDisable) disable() }
150+
listen<ConnectionEvent.Disconnect> { if (autoDisable) disable() }
145151
}
146152

147153
fun enable() {

src/main/kotlin/com/lambda/module/modules/debug/SettingTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object SettingTest : Module(
6868
private val blockPosSetting by setting("Block Position", BlockPos(0, 0, 0)).group(Group.COMPLEX)
6969
private val blockSetting by setting("Block Setting", Blocks.OBSIDIAN).group(Group.COMPLEX)
7070
private val colorSetting by setting("Color Setting", Color.GREEN).group(Group.COMPLEX)
71-
private val keybindSetting by setting("Key Bind Setting", KeyCode.T).group(Group.COMPLEX)
71+
private val keybindSettingTest by setting("Key Bind Setting", KeyCode.T).group(Group.COMPLEX)
7272

7373
// Complex collections
7474
private val blockPosSet by setting("Block Position Set", setOf(BlockPos(0, 0, 0)), setOf(BlockPos(0, 0, 0))).group(Group.COMPLEX)

src/main/kotlin/com/lambda/module/modules/network/PacketDelay.kt

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import com.lambda.module.tag.ModuleTag
2626
import com.lambda.threading.runConcurrent
2727
import com.lambda.threading.runGameScheduled
2828
import com.lambda.util.ClientPacket
29+
import com.lambda.util.Describable
30+
import com.lambda.util.NamedEnum
2931
import com.lambda.util.PacketUtils.handlePacketSilently
3032
import com.lambda.util.PacketUtils.sendPacketSilently
3133
import com.lambda.util.ServerPacket
@@ -39,11 +41,11 @@ object PacketDelay : Module(
3941
description = "Delays packets client-bound & server-bound",
4042
tag = ModuleTag.NETWORK,
4143
) {
42-
private val mode by setting("Mode", Mode.STATIC)
43-
private val networkScope by setting("Network Scope", Direction.BOTH)
44-
private val packetScope by setting("Packet Scope", PacketType.ANY)
45-
private val inboundDelay by setting("Inbound Delay", 250L, 0L..5000L, 10L, unit = "ms") { networkScope != Direction.OUTBOUND }
46-
private val outboundDelay by setting("Outbound Delay", 250L, 0L..5000L, 10L, unit = "ms") { networkScope != Direction.INBOUND }
44+
private val mode by setting("Mode", Mode.Static, description = "How the delay is applied: Static queues packets until a flush; Pulse delays each packet individually.")
45+
private val networkScope by setting("Network Scope", Direction.Both, description = "Which direction(s) to affect: inbound (server → you), outbound (you → server), or both.")
46+
private val packetScope by setting("Packet Scope", PacketType.Any, description = "What packets to delay. Choose all packets or a specific packet type.")
47+
private val inboundDelay by setting("Inbound Delay", 250L, 0L..5000L, 10L, unit = "ms", description = "Time to delay packets received from the server before processing.") { networkScope != Direction.Outbound }
48+
private val outboundDelay by setting("Outbound Delay", 250L, 0L..5000L, 10L, unit = "ms", description = "Time to delay packets sent to the server before sending.") { networkScope != Direction.Inbound }
4749

4850
private var outboundPool = ConcurrentLinkedDeque<ServerPacket>()
4951
private var inboundPool = ConcurrentLinkedDeque<ClientPacket>()
@@ -52,7 +54,7 @@ object PacketDelay : Module(
5254

5355
init {
5456
listen<RenderEvent.World> {
55-
if (mode != Mode.STATIC) return@listen
57+
if (mode != Mode.Static) return@listen
5658

5759
flushPools(System.currentTimeMillis())
5860
}
@@ -61,12 +63,12 @@ object PacketDelay : Module(
6163
if (!packetScope.filter(event.packet)) return@listen
6264

6365
when (mode) {
64-
Mode.STATIC -> {
66+
Mode.Static -> {
6567
outboundPool.add(event.packet)
6668
event.cancel()
6769
}
6870

69-
Mode.PULSE -> {
71+
Mode.Pulse -> {
7072
runConcurrent {
7173
delay(outboundDelay)
7274
runGameScheduled {
@@ -82,12 +84,12 @@ object PacketDelay : Module(
8284
if (!packetScope.filter(event.packet)) return@listen
8385

8486
when (mode) {
85-
Mode.STATIC -> {
87+
Mode.Static -> {
8688
inboundPool.add(event.packet)
8789
event.cancel()
8890
}
8991

90-
Mode.PULSE -> {
92+
Mode.Pulse -> {
9193
runConcurrent {
9294
delay(inboundDelay)
9395
runGameScheduled {
@@ -128,10 +130,30 @@ object PacketDelay : Module(
128130
}
129131
}
130132

131-
enum class Mode { STATIC, PULSE, }
132-
enum class Direction { BOTH, INBOUND, OUTBOUND }
133-
enum class PacketType(val filter: (Packet<*>) -> Boolean) {
134-
ANY({ true }),
135-
KEEP_ALIVE({ it is KeepAliveC2SPacket })
133+
enum class Mode(
134+
override val displayName: String,
135+
override val description: String,
136+
) : NamedEnum, Describable {
137+
Static("Static", "Queue packets and release them in bursts based on your delay. Useful for batching traffic."),
138+
Pulse("Pulse", "Apply a per-packet delay before it is sent/processed. Useful for smoothing timing.")
136139
}
140+
141+
enum class Direction(
142+
override val displayName: String,
143+
override val description: String,
144+
) : NamedEnum, Describable {
145+
Both("Both", "Affects both outbound (client → server) and inbound (server → client) packets."),
146+
Inbound("Inbound", "Affects only packets received from the server."),
147+
Outbound("Outbound", "Affects only packets sent to the server.")
148+
}
149+
150+
enum class PacketType(
151+
override val displayName: String,
152+
override val description: String,
153+
val filter: (Packet<*>) -> Boolean,
154+
) : NamedEnum, Describable {
155+
Any("Any", "Delay every packet regardless of type.", { true }),
156+
KeepAlive("Keep-Alive", "Delay only KeepAlive packets (useful for simulating higher ping).", { it is KeepAliveC2SPacket })
157+
}
158+
137159
}

0 commit comments

Comments
 (0)