Skip to content

Commit 0bd5872

Browse files
committed
Setting groups with visual tabs
1 parent 6d4a273 commit 0bd5872

24 files changed

+404
-348
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.lambda.gui.Layout
3434
import com.lambda.threading.runSafe
3535
import com.lambda.util.Communication.info
3636
import com.lambda.util.Nameable
37+
import com.lambda.util.NamedEnum
3738
import com.lambda.util.extension.CommandBuilder
3839
import com.lambda.util.text.ClickEvents
3940
import com.lambda.util.text.HoverEvents
@@ -99,6 +100,7 @@ abstract class AbstractSetting<T : Any>(
99100
val visibility: () -> Boolean,
100101
) : Jsonable, Nameable, Layout {
101102
private val listeners = mutableListOf<ValueListener<T>>()
103+
val groups: MutableList<List<NamedEnum>> = mutableListOf()
102104

103105
var value by Delegates.observable(defaultValue) { _, from, to ->
104106
listeners.forEach {
@@ -107,7 +109,6 @@ abstract class AbstractSetting<T : Any>(
107109
}
108110
}
109111

110-
private val isVisible get() = visibility()
111112
val isModified get() = value != defaultValue
112113

113114
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value
@@ -149,6 +150,10 @@ abstract class AbstractSetting<T : Any>(
149150
listeners.add(ValueListener(false, block))
150151
}
151152

153+
fun group(vararg path: NamedEnum) = apply {
154+
groups.add(path.toList())
155+
}
156+
152157
fun reset() {
153158
if (value == defaultValue) {
154159
ConfigCommand.info(notChangedMessage())

src/main/kotlin/com/lambda/config/groups/BuildSettings.kt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,36 @@ package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
2121
import com.lambda.util.BlockUtils.allSigns
22+
import com.lambda.util.NamedEnum
2223

2324
class BuildSettings(
2425
c: Configurable,
26+
baseGroup: NamedEnum,
2527
vis: () -> Boolean = { true }
2628
) : BuildConfig {
27-
enum class Page {
28-
General, Break, Place
29+
enum class Group(override val displayName: String) : NamedEnum {
30+
General("General"),
31+
Break("Break"),
32+
Place("Place")
2933
}
3034

31-
private val page by c.setting("Build Page", Page.General, "Current page", vis)
32-
3335
// General
34-
override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.General }
35-
override val stayInRange by c.setting("Stay In Range", true, "Stay in range of blocks") { vis() && page == Page.General && pathing }
36-
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks") { vis() && page == Page.General }
37-
override val maxPendingInteractions by c.setting("Max Pending Interactions", 1, 1..10, 1, "Dont wait for this many interactions for the server response") { vis() && page == Page.General }
36+
override val pathing by c.setting("Pathing", true, "Path to blocks", vis).group(baseGroup, Group.General)
37+
override val stayInRange by c.setting("Stay In Range", true, "Stay in range of blocks", vis).group(baseGroup, Group.General)
38+
override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks", vis).group(baseGroup, Group.General)
39+
override val maxPendingInteractions by c.setting("Max Pending Interactions", 1, 1..10, 1, "Dont wait for this many interactions for the server response", visibility = vis).group(baseGroup, Group.General)
3840

3941
// Breaking
40-
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking") { vis() && page == Page.Break }
41-
override val breakConfirmation by c.setting("Break Confirmation", false, "Wait for block break confirmation") { vis() && page == Page.Break }
42-
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.Break }
43-
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.Break }
44-
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() && page == Page.Break }
45-
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, allSigns, "Blocks that wont be broken") { vis() && page == Page.Break }
42+
override val rotateForBreak by c.setting("Rotate For Break", true, "Rotate towards block while breaking", vis).group(baseGroup, Group.Break)
43+
override val breakConfirmation by c.setting("Break Confirmation", false, "Wait for block break confirmation", vis).group(baseGroup, Group.Break)
44+
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick", visibility = vis).group(baseGroup, Group.Break)
45+
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)", vis).group(baseGroup, Group.Break)
46+
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks", vis).group(baseGroup, Group.Break)
47+
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, allSigns, "Blocks that wont be broken", vis).group(baseGroup, Group.Break)
4648

4749
// Placing
48-
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() && page == Page.Place }
49-
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation") { vis() && page == Page.Place }
50-
override val placementsPerTick by c.setting("Instant Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick") { vis() && page == Page.Place }
51-
52-
override val interactionTimeout by c.setting("Interaction Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks") { vis() && (page == Page.Place && placeConfirmation || page == Page.Break && breakConfirmation) }
50+
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing", vis).group(baseGroup, Group.Place)
51+
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation", vis).group(baseGroup, Group.Place)
52+
override val placementsPerTick by c.setting("Instant Places Per Tick", 1, 1..30, 1, "Maximum instant block places per tick", visibility = vis).group(baseGroup, Group.Place)
53+
override val interactionTimeout by c.setting("Interaction Timeout", 10, 1..30, 1, "Timeout for block breaks in ticks", unit = " ticks") { vis() && (placeConfirmation || breakConfirmation) }.group(baseGroup, Group.Break).group(baseGroup, Group.Place)
5354
}

src/main/kotlin/com/lambda/config/groups/HotbarSettings.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ package com.lambda.config.groups
2020
import com.lambda.config.Configurable
2121
import com.lambda.interaction.request.Priority
2222
import com.lambda.interaction.request.hotbar.HotbarConfig
23+
import com.lambda.util.NamedEnum
2324

2425
class HotbarSettings(
2526
c: Configurable,
27+
baseGroup: NamedEnum,
2628
priority: Priority = 0,
2729
vis: () -> Boolean = { true }
2830
) : HotbarConfig(priority) {
29-
override val keepTicks by c.setting("Keep Ticks", 3, 0..20, 1, "The number of ticks to keep the current hotbar selection active", " ticks", vis)
30-
override var switchPause by c.setting("Switch Pause", 0, 0..20, 1, "The delay in ticks to pause actions after switching to the slot", " ticks", vis)
31+
override val keepTicks by c.setting("Keep Ticks", 3, 0..20, 1, "The number of ticks to keep the current hotbar selection active", " ticks", vis).group(baseGroup)
32+
override var switchPause by c.setting("Switch Pause", 0, 0..20, 1, "The delay in ticks to pause actions after switching to the slot", " ticks", vis).group(baseGroup)
3133
}

src/main/kotlin/com/lambda/config/groups/InteractionSettings.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
2121
import com.lambda.interaction.request.rotation.visibilty.PointSelection
22+
import com.lambda.util.NamedEnum
2223
import com.lambda.util.world.raycast.InteractionMask
2324
import kotlin.math.max
2425

2526
class InteractionSettings(
2627
c: Configurable,
28+
baseGroup: NamedEnum,
2729
private val usage: InteractionMask,
2830
vis: () -> Boolean = { true },
2931
) : InteractionConfig {
3032
// Reach
31-
private val useDefaultReach by c.setting("Default Reach", true, "Whether to use vanilla interaction ranges", vis)
32-
private val attackReachSetting = if (usage.entity) c.setting("Attack Reach", DEFAULT_ATTACK_REACH, 1.0..10.0, 0.01, "Maximum entity interaction distance") { vis() && !useDefaultReach } else null
33-
private val interactReachSetting = if (usage.block) c.setting("Interact Reach", DEFAULT_INTERACT_REACH, 1.0..10.0, 0.01, "Maximum block interaction distance") { vis() && !useDefaultReach } else null
33+
private val useDefaultReach by c.setting("Default Reach", true, "Whether to use vanilla interaction ranges", vis).group(baseGroup)
34+
private val attackReachSetting = if (usage.entity) c.setting("Attack Reach", DEFAULT_ATTACK_REACH, 1.0..10.0, 0.01, "Maximum entity interaction distance") { vis() && !useDefaultReach }.group(baseGroup) else null
35+
private val interactReachSetting = if (usage.block) c.setting("Interact Reach", DEFAULT_INTERACT_REACH, 1.0..10.0, 0.01, "Maximum block interaction distance") { vis() && !useDefaultReach }.group(baseGroup) else null
3436

3537
override val attackReach: Double get() {
3638
check(usage.entity) {
@@ -55,13 +57,13 @@ class InteractionSettings(
5557
}
5658

5759
// Point scan
58-
override val strictRayCast by c.setting("Strict Raycast", true, "Whether to include the environment to the ray cast context", vis)
59-
override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible", vis)
60-
override val resolution by c.setting("Resolution", 5, 1..20, 1, "The amount of grid divisions per surface of the hit box", "", vis)
61-
override val pointSelection by c.setting("Point Selection", PointSelection.Optimum, "The strategy to select the best hit point", vis)
60+
override val strictRayCast by c.setting("Strict Raycast", true, "Whether to include the environment to the ray cast context", vis).group(baseGroup)
61+
override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible", vis).group(baseGroup)
62+
override val resolution by c.setting("Resolution", 5, 1..20, 1, "The amount of grid divisions per surface of the hit box", "", vis).group(baseGroup)
63+
override val pointSelection by c.setting("Point Selection", PointSelection.Optimum, "The strategy to select the best hit point", vis).group(baseGroup)
6264

6365
// Swing
64-
override val swingHand by c.setting("Swing Hand", true, "Whether to swing hand on interactions", vis)
66+
override val swingHand by c.setting("Swing Hand", true, "Whether to swing hand on interactions", vis).group(baseGroup)
6567

6668
companion object {
6769
const val DEFAULT_ATTACK_REACH = 3.0

src/main/kotlin/com/lambda/config/groups/InventorySettings.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
21+
import com.lambda.util.NamedEnum
2122
import com.lambda.util.item.ItemUtils
2223

2324
class InventorySettings(
2425
c: Configurable,
26+
baseGroup: NamedEnum,
2527
vis: () -> Boolean = { true },
2628
) : InventoryConfig {
27-
override val disposables by c.setting("Disposables", ItemUtils.defaultDisposables, ItemUtils.defaultDisposables, "Items that will be ignored when checking for a free slot", vis)
28-
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest", vis)
29-
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones", vis)
30-
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from", vis)
31-
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to", vis)
29+
override val disposables by c.setting("Disposables", ItemUtils.defaultDisposables, ItemUtils.defaultDisposables, "Items that will be ignored when checking for a free slot", vis).group(baseGroup)
30+
override val accessEnderChest by c.setting("Access Ender Chest", false, "Allow access to the player's ender chest", vis).group(baseGroup)
31+
override val swapWithDisposables by c.setting("Swap With Disposables", true, "Swap items with disposable ones", vis).group(baseGroup)
32+
override val providerPriority by c.setting("Provider Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when retrieving the item from", vis).group(baseGroup)
33+
override val storePriority by c.setting("Store Priority", InventoryConfig.Priority.WithMinItems, "What container to prefer when storing the item to", vis).group(baseGroup)
3234
}

src/main/kotlin/com/lambda/config/groups/RotationSettings.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.config.Configurable
2121
import com.lambda.interaction.request.Priority
2222
import com.lambda.interaction.request.rotation.RotationConfig
2323
import com.lambda.interaction.request.rotation.RotationMode
24+
import com.lambda.util.NamedEnum
2425
import kotlin.math.PI
2526
import kotlin.math.abs
2627
import kotlin.math.cos
@@ -30,31 +31,32 @@ import kotlin.random.Random
3031

3132
class RotationSettings(
3233
c: Configurable,
34+
baseGroup: NamedEnum,
3335
priority: Priority = 0,
3436
vis: () -> Boolean = { true }
3537
) : RotationConfig(priority) {
36-
override var rotationMode by c.setting("Mode", RotationMode.Sync, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera, NONE - No rotation", vis)
38+
override var rotationMode by c.setting("Mode", RotationMode.Sync, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera, NONE - No rotation", vis).group(baseGroup)
3739

3840
/** How many ticks to keep the rotation before resetting */
39-
override val keepTicks by c.setting("Keep Rotation", 3, 0..10, 1, "Ticks to keep rotation", " ticks") { rotate && vis() }
41+
override val keepTicks by c.setting("Keep Rotation", 3, 0..10, 1, "Ticks to keep rotation", " ticks") { rotate && vis() }.group(baseGroup)
4042

4143
/** How many ticks to wait before resetting the rotation */
42-
override val decayTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", " ticks") { rotate && vis() }
44+
override val decayTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", " ticks") { rotate && vis() }.group(baseGroup)
4345

4446
/** Whether the rotation is instant */
45-
var instant by c.setting("Instant Rotation", true, "Instantly rotate") { rotate && vis() }
47+
var instant by c.setting("Instant Rotation", true, "Instantly rotate") { rotate && vis() }.group(baseGroup)
4648

4749
/**
4850
* The mean (average/base) value used to calculate rotation speed.
4951
* This value represents the center of the distribution.
5052
*/
51-
var mean by c.setting("Mean", 40.0, 1.0..120.0, 0.1, "Average rotation speed", unit = "°") { rotate && vis() && !instant }
53+
var mean by c.setting("Mean", 40.0, 1.0..120.0, 0.1, "Average rotation speed", unit = "°") { rotate && vis() && !instant }.group(baseGroup)
5254

5355
/**
5456
* The standard deviation for the Gaussian distribution used to calculate rotation speed.
5557
* This value represents the spread of rotation speed.
5658
*/
57-
var spread by c.setting("Spread", 10.0, 0.0..60.0, 0.1, "Spread of rotation speeds", unit = "°") { rotate && vis() && !instant }
59+
var spread by c.setting("Spread", 10.0, 0.0..60.0, 0.1, "Spread of rotation speeds", unit = "°") { rotate && vis() && !instant }.group(baseGroup)
5860

5961
/**
6062
* We must always provide turn speed to the interpolator because the player's yaw might exceed the -180 to 180 range.

src/main/kotlin/com/lambda/config/groups/Targeting.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.lambda.interaction.request.rotation.Rotation.Companion.dist
2424
import com.lambda.interaction.request.rotation.Rotation.Companion.rotation
2525
import com.lambda.interaction.request.rotation.Rotation.Companion.rotationTo
2626
import com.lambda.threading.runSafe
27+
import com.lambda.util.NamedEnum
2728
import com.lambda.util.extension.fullHealth
2829
import com.lambda.util.math.distSq
2930
import com.lambda.util.world.fastEntitySearch
@@ -49,6 +50,7 @@ import java.util.*
4950
*/
5051
abstract class Targeting(
5152
private val owner: Configurable,
53+
private val baseGroup: NamedEnum,
5254
private val predicate: () -> Boolean = { true },
5355
private val defaultRange: Double,
5456
private val maxRange: Double,
@@ -133,20 +135,21 @@ abstract class Targeting(
133135
*/
134136
class Combat(
135137
owner: Configurable,
138+
baseGroup: NamedEnum,
136139
defaultRange: Double = 5.0,
137140
maxRange: Double = 16.0,
138141
predicate: () -> Boolean = { true },
139-
) : Targeting(owner, predicate, defaultRange, maxRange) {
142+
) : Targeting(owner, baseGroup, predicate, defaultRange, maxRange) {
140143

141144
/**
142145
* The field of view limit for targeting entities. Configurable between 5 and 180 degrees.
143146
*/
144-
val fov by owner.setting("FOV Limit", 180, 5..180, 1) { predicate() }
147+
val fov by owner.setting("FOV Limit", 180, 5..180, 1) { predicate() }.group(baseGroup)
145148

146149
/**
147150
* The priority used to determine which entity is targeted. Configurable with default set to [Priority.DISTANCE].
148151
*/
149-
val priority by owner.setting("Priority", Priority.DISTANCE) { predicate() }
152+
val priority by owner.setting("Priority", Priority.DISTANCE) { predicate() }.group(baseGroup)
150153

151154
/**
152155
* Validates whether a given entity is targetable for combat based on the field of view limit and other settings.
@@ -184,8 +187,9 @@ abstract class Targeting(
184187
*/
185188
class ESP(
186189
owner: Configurable,
190+
baseGroup: NamedEnum,
187191
predicate: () -> Boolean = { true },
188-
) : Targeting(owner, predicate, 128.0, 1024.0)
192+
) : Targeting(owner, baseGroup, predicate, 128.0, 1024.0)
189193

190194
/**
191195
* Enum representing the different priority factors used for determining the best target.

src/main/kotlin/com/lambda/config/settings/comparable/EnumSetting.kt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ import com.lambda.brigadier.executeWithResult
2626
import com.lambda.brigadier.required
2727
import com.lambda.config.AbstractSetting
2828
import com.lambda.gui.dsl.ImGuiBuilder
29+
import com.lambda.util.NamedEnum
2930
import com.lambda.util.StringUtils.capitalize
3031
import com.lambda.util.extension.CommandBuilder
32+
import com.lambda.util.extension.displayValue
3133
import imgui.ImColor
3234
import imgui.ImGui
3335
import imgui.ImVec2
@@ -60,22 +62,7 @@ class EnumSetting<T : Enum<T>>(
6062
sameLine()
6163
helpMarker(description)
6264

63-
combo("##$name", ::index, value.enumValues.map { it.name.capitalize() }.toTypedArray())
64-
slider("##$name#", ::index, 0, value.enumValues.size - 1, format = "", flags = AlwaysClamp)
65-
66-
val min = ImGui.getItemRectMin()
67-
val max = ImGui.getItemRectMax()
68-
val textSize = ImGui.calcTextSize(value.name)
69-
val center = ImVec2(
70-
(min.x + max.x) * 0.5f - textSize.x * 0.5f,
71-
(min.y + max.y) * 0.5f - textSize.y * 0.5f
72-
)
73-
74-
windowDrawList.addText(
75-
center,
76-
ImColor.rgb(Color.WHITE),
77-
value.name,
78-
)
65+
combo("##$name", ::index, value.enumValues.map { it.displayValue }.toTypedArray())
7966
}
8067

8168
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

0 commit comments

Comments
 (0)