aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
blob: c6ed5441a3d40de0bd86c5ec08e0a29db3a5e6e2 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/**
 *   This Source Code Form is subject to the terms of the Mozilla Public
 *   License, v. 2.0. If a copy of the MPL was not distributed with this
 *   file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * If it is not possible or desirable to put the notice in a particular
 * file, then You may include the notice in a location (such as a LICENSE
 * file in a relevant directory) where a recipient would be likely to look
 * for such a notice.
 *
 * You may add additional accurate notices of copyright ownership.
 */
@file:UseSerializers(com.dulkirfabric.config.serializations.KeySerializer::class)
package com.dulkirfabric.config

import com.dulkirfabric.DulkirModFabric.mc
import com.dulkirfabric.config.ConfigHelper.mkKeyField
import com.dulkirfabric.config.ConfigHelper.mkStringField
import com.dulkirfabric.config.ConfigHelper.mkToggle
import com.dulkirfabric.util.render.AnimationPreset
import com.dulkirfabric.util.render.HudElement
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import me.shedaniel.clothconfig2.api.ConfigBuilder
import moe.nea.jarvis.api.Point
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.util.InputUtil
import net.minecraft.client.util.InputUtil.UNKNOWN_KEY
import net.minecraft.text.LiteralTextContent
import net.minecraft.text.MutableText
import net.minecraft.text.Text
import net.minecraft.text.TextColor
import net.minecraft.util.Formatting
import net.minecraft.util.Identifier
import java.io.File

class DulkirConfig {

    private val buttonText: Text =
        MutableText.of(LiteralTextContent("Dulkir")).formatted(Formatting.BOLD, Formatting.YELLOW)
    var screen: Screen

    init {
        val builder = ConfigBuilder.create().setTitle(buttonText)
        builder.setDefaultBackgroundTexture(Identifier("minecraft:textures/block/oak_planks.png"))
        builder.setGlobalized(true)
        builder.setGlobalizedExpanded(false)
        builder.setParentScreen(mc.currentScreen)
        builder.setSavingRunnable(::saveConfig)
        val entryBuilder = builder.entryBuilder()
        val general = builder.getOrCreateCategory(Text.literal("General"))
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Inventory Scale Toggle"),
                configOptions::invScaleBool,
                Text.literal("This is a tooltip"))
        )
        general.addEntry(
            entryBuilder.startFloatField(Text.literal("Inventory Scale"), configOptions.inventoryScale)
                .setTooltip(Text.literal("Size of GUI whenever you're in an inventory screen"))
                .setSaveConsumer { newValue ->
                    configOptions.inventoryScale = newValue
                }
                .build()
        )
        general.addEntry(
            entryBuilder.startFloatField(Text.literal("Tooltip Scale"), configOptions.tooltipScale)
                .setTooltip(Text.literal("Default Value for Scaling a particular tooltip without scroll input"))
                .setSaveConsumer { newValue -> configOptions.tooltipScale = newValue }
                .build()
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Ignore Reverse Third Person"), configOptions::ignoreReverseThirdPerson)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Disable Status Effect Rendering"), configOptions::statusEffectHidden)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Custom Block outlines"), configOptions::customBlockOutlines)
        )
        general.addEntry(
            entryBuilder.startIntSlider(Text.literal("Line Thickness"), configOptions.blockOutlineThickness, 1, 5)
                .setSaveConsumer { newValue -> configOptions.blockOutlineThickness = newValue }
                .build()
        )
        general.addEntry(
            entryBuilder.startColorField(Text.literal("Outline Color"), TextColor.fromRgb(configOptions.blockOutlineColor))
                .setSaveConsumer { newValue -> configOptions.blockOutlineColor = newValue }
                .build()
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Abiphone DND"), configOptions::abiPhoneDND)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Abiphone Caller ID"), configOptions::abiPhoneCallerID)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Inactive Effigy Waypoints"), configOptions::inactiveEffigyDisplay)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Disable Explosion Particles"), configOptions::disableExplosionParticles)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Durability-Based Cooldown Display"), configOptions::duraCooldown)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Hide Armor Overlay in Skyblock"), configOptions::hideArmorOverlay)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Hide Hunger Overlay in Skyblock"), configOptions::hideHungerOverlay)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Hide Fire Overlay"), configOptions::hideFireOverlay)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Hide Lightning (SkyBlock only)"), configOptions::hideLightning)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Hide Non-Crits"), configOptions::hideNonCrits)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Hide Crits"), configOptions::hideCrits)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Truncate Crits"), configOptions::truncateDamage)
        )
        general.addEntry(
            entryBuilder.startIntSlider(Text.literal("Anti Downtime Alarm"), configOptions.alarmTimeout, 0, 1000)
                .setSaveConsumer {
                    configOptions.alarmTimeout = it
                }
                .setTooltip(Text.literal("Set to 0 to disable. (Time in seconds)"))
                .build()
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Arachne Keeper Waypoints"), configOptions::arachneKeeperWaypoints)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Arachne Boss Spawn Timer"), configOptions::arachneSpawnTimer)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Convert Action Bar to HUD elements"), configOptions::hudifyActionBar,
                tooltip = Text.literal("This converts Mana/Health/Def/Stacks as HUD elements"))
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Show Speed in HUD"), configOptions::speedHud)
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Include EHP in def HUD element"), configOptions::showEHP,
                tooltip = Text.literal("Must have Action Bar HUD elements Enabled"))
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Hide Held Item Tooltips"), configOptions::hideHeldItemTooltip,
                tooltip = Text.literal("This is for the pesky overlay that pops up on switching items"))
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Etherwarp Preview"), configOptions::showEtherwarpPreview,
                tooltip = Text.literal("Highlights the targeted block when shifting with a aotv."))
        )
        general.addEntry(
            entryBuilder.startAlphaColorField(Text.literal("Etherwarp Preview Color"), configOptions.etherwarpPreviewColor)
                .setDefaultValue(0x99FFFFFF.toInt())
                .setSaveConsumer { newValue -> configOptions.etherwarpPreviewColor = newValue }
                .build()
        )
        general.addEntry(
            entryBuilder.mkToggle(Text.literal("Broken Hype Notification"), configOptions::brokenHypNotif)
        )

        val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts"))
        shortcuts.addEntry(
            entryBuilder.mkKeyField(Text.literal("Dynamic Key"), configOptions::dynamicKey)
        )
        shortcuts.addEntry(
            entryBuilder.mkToggle(Text.literal("Only Register Shortcuts in Skyblock"), configOptions::macrosSkyBlockOnly,
                Text.literal("Useful if you want to use some of these binds elsewhere for non-skyblock specific stuff."))
        )
        shortcuts.addEntry(
            ConfigHelper.mkConfigList(
                Text.literal("Macros"),
                configOptions::macrosList,
                { Macro(UNKNOWN_KEY, "") },
                Text.literal("Macro"),
                { value ->
                    listOf(
                        entryBuilder.mkStringField(Text.literal("Command"), value::command),
                        entryBuilder.mkKeyField(Text.literal("KeyBinding"), value::keyBinding)
                    )
                }
            )
        )

        val aliases = builder.getOrCreateCategory(Text.literal("Shortcuts"))
        aliases.addEntry(
            ConfigHelper.mkConfigList(
                Text.literal("Aliases (do not include '/')"),
                configOptions::aliasList,
                { Alias("", "") },
                Text.literal("Alias"),
                { value ->
                    listOf(
                        entryBuilder.mkStringField(Text.literal("Command"), value::command),
                        entryBuilder.mkStringField(Text.literal("Alias"), value::alias)
                    )
                }
            )
        )
        val animations = builder.getOrCreateCategory(Text.literal("Animations"))

        //TODO: Come up with some custome float slider instead of int slider jank
        animations.addEntry(
            entryBuilder.startIntSlider(Text.literal("posX"), configOptions.animationPreset.posX, -150, 150)
                .setSaveConsumer { newValue -> configOptions.animationPreset.posX = newValue }
                .setDefaultValue(0)
                .build()
        )
        animations.addEntry(
            entryBuilder.startIntSlider(Text.literal("posY"), configOptions.animationPreset.posY, -150, 150)
                .setSaveConsumer { newValue -> configOptions.animationPreset.posY = newValue }
                .setDefaultValue(0)
                .build()
        )
        animations.addEntry(
            entryBuilder.startIntSlider(Text.literal("posZ"), configOptions.animationPreset.posZ, -150, 50)
                .setSaveConsumer { newValue -> configOptions.animationPreset.posZ = newValue }
                .setDefaultValue(0)
                .build()
        )
        animations.addEntry(
            entryBuilder.startIntSlider(Text.literal("rotationX"), configOptions.animationPreset.rotX, -180, 180)
                .setSaveConsumer { newValue -> configOptions.animationPreset.rotX = newValue }
                .setDefaultValue(0)
                .build()
        )
        animations.addEntry(
            entryBuilder.startIntSlider(Text.literal("rotationY"), configOptions.animationPreset.rotY, -180, 180)
                .setSaveConsumer { newValue -> configOptions.animationPreset.rotY = newValue }
                .setDefaultValue(0)
                .build()
        )
        animations.addEntry(
            entryBuilder.startIntSlider(Text.literal("rotationZ"), configOptions.animationPreset.rotZ, -180, 180)
                .setSaveConsumer { newValue -> configOptions.animationPreset.rotZ = newValue }
                .setDefaultValue(0)
                .build()
        )
        animations.addEntry(
            entryBuilder.startFloatField(Text.literal("Held Item Scale"), configOptions.animationPreset.scale)
                .setTooltip(Text.literal("Recommended range of .1 - 2"))
                .setSaveConsumer { newValue ->
                    configOptions.animationPreset.scale = newValue
                }
                .setDefaultValue(1f)
                .build()
        )
        animations.addEntry(
            entryBuilder.startIntSlider(Text.literal("Swing Speed"), configOptions.animationPreset.swingDuration, 2, 20)
                .setSaveConsumer { newValue -> configOptions.animationPreset.swingDuration = newValue }
                .setDefaultValue(6)
                .build()
        )
        animations.addEntry(
            entryBuilder.startBooleanToggle(Text.literal("Cancel Re-Equip Animation"), configOptions.animationPreset.cancelReEquip)
                .setSaveConsumer {newValue -> configOptions.animationPreset.cancelReEquip = newValue }
                .setDefaultValue(false)
                .build()
        )

        val bridge = builder.getOrCreateCategory(Text.literal("Bridge Features"))

        bridge.addEntry(
            entryBuilder.mkToggle(Text.literal("Format Bridge Messages"), configOptions::bridgeFormatter)
        )
        bridge.addEntry(
            entryBuilder.mkStringField(Text.literal("Bridge Bot IGN"), configOptions::bridgeBotName)
        )
        bridge.addEntry(
            entryBuilder.startColorField(Text.literal("Bridge User Color"), configOptions.bridgeNameColor)
                .setDefaultValue(Formatting.GOLD.colorValue!!)
                .setSaveConsumer { newValue -> configOptions.bridgeNameColor = newValue }
                .build()
        )

        val slayer = builder.getOrCreateCategory(Text.literal("Slayer"))
        slayer.addEntry(
            entryBuilder.mkToggle(Text.literal("MiniBoss Highlight Box"), configOptions::boxMinis)
        )
        slayer.addEntry(
            entryBuilder.mkToggle(Text.literal("MiniBoss Announcement Alert"), configOptions::announceMinis)
        )
        slayer.addEntry(
            entryBuilder.mkToggle(Text.literal("Show Kill Time on Slayer Completion"), configOptions::slayerKillTime,
                Text.literal("Shows up in chat!"))
        )
        slayer.addEntry(
            entryBuilder.mkToggle(Text.literal("Blaze Slayer Attunement Display"), configOptions::attunementDisplay,
                Text.literal("Shows a wireframe in the correct color for the slayer."))
        )
        slayer.addEntry(
            entryBuilder.mkToggle(Text.literal("Disable ALL particles during Blaze slayer boss"), configOptions::cleanBlaze)
        )
        slayer.addEntry(
            entryBuilder.mkToggle(Text.literal("Vampire Steak Display"), configOptions::steakDisplay,
                Text.literal("Shows a wireframe on vampire boss when you can 1 tap it"))
        )
        slayer.addEntry(
            entryBuilder.mkToggle(Text.literal("Blood Ichor Highlight"), configOptions::ichorHighlight,
                Text.literal("Highlights the T5 mechanic that you line up with the boss."))
        )

        val garden = builder.getOrCreateCategory(Text.literal("Garden"))
        garden.addEntry(
            entryBuilder.mkToggle(Text.literal("Show Visitor Info in HUD"), configOptions::visitorHud)
        )
        garden.addEntry(
            entryBuilder.mkToggle(Text.literal("Show Composter Info in HUD"), configOptions::showComposterInfo)
        )
        garden.addEntry(
            entryBuilder.mkToggle(Text.literal("Show Title alert when max visitors"), configOptions::visitorAlert)
        )
        garden.addEntry(
            entryBuilder.mkToggle(Text.literal("Persistent Visitor alert (dependent on previous)"), configOptions::persistentVisitorAlert)
        )
        garden.addEntry(
            entryBuilder.mkToggle(Text.literal("Show Blocks per second (SPEED)"), configOptions::speedBpsHud)
        )
        garden.addEntry(
            entryBuilder.mkToggle(Text.literal("Show Pitch/Yaw in HUD"), configOptions::pitchYawDisplay)
        )

        builder.transparentBackground()
        screen = builder.build()
    }

    @Serializable
    data class ConfigOptions(
        var invScaleBool: Boolean = false,
        var inventoryScale: Float = 1f,
        var macrosList: List<Macro> = listOf(Macro(UNKNOWN_KEY, "")),
        var macrosSkyBlockOnly: Boolean = false,
        var aliasList: List<Alias> = listOf(Alias("", "")),
        var ignoreReverseThirdPerson: Boolean = false,
        var dynamicKey: InputUtil.Key = UNKNOWN_KEY,
        var customBlockOutlines: Boolean = false,
        var blockOutlineThickness: Int = 3,
        var blockOutlineColor: Int = 0xFFFFFF,
        var abiPhoneDND: Boolean = false,
        var abiPhoneCallerID: Boolean = false,
        var tooltipScale: Float = 1f,
        var statusEffectHidden: Boolean = false,
        var inactiveEffigyDisplay: Boolean = false,
        var disableExplosionParticles: Boolean = false,
        var hideArmorOverlay: Boolean = true,
        var hideHungerOverlay: Boolean = true,
        var animationPreset: AnimationPreset = AnimationPreset(),
        var duraCooldown: Boolean = false,
        var alarmTimeout: Int = 0,
        var arachneKeeperWaypoints: Boolean = false,
        var arachneSpawnTimer: Boolean = false,
        var bridgeFormatter: Boolean = false,
        var bridgeBotName: String = "Dilkur",
        var bridgeNameColor: Int = Formatting.GOLD.colorValue!!,
        val positions: MutableMap<String, HudElement.Positioning> = mutableMapOf(),
        var hudifyActionBar: Boolean = true,
        var showEHP: Boolean = false,
        var hideHeldItemTooltip: Boolean = false,
        var showEtherwarpPreview: Boolean = true,
        var etherwarpPreviewColor: Int = 0x99FFFFFF.toInt(),
        var announceMinis: Boolean = false,
        var boxMinis: Boolean = false,
        var attunementDisplay: Boolean = false,
        var hideFireOverlay: Boolean = false,
        var hideLightning: Boolean = false,
        var cleanBlaze: Boolean= false,
        var timeSlayerBoss: Boolean = false,
        var hideNonCrits: Boolean = false,
        var truncateDamage: Boolean = false,
        var hideCrits: Boolean = false,
        var visitorHud: Boolean = false,
        var showComposterInfo: Boolean = false,
        var slayerKillTime: Boolean = false,
        var visitorAlert: Boolean = false,
        var persistentVisitorAlert: Boolean = false,
        var brokenHypNotif: Boolean = false,
        var steakDisplay: Boolean = false,
        var ichorHighlight: Boolean = false,
        var speedHud: Boolean = false,
        var speedBpsHud: Boolean = false,
        var pitchYawDisplay: Boolean = false,
    )

    @Serializable
    data class Macro(
        var keyBinding: InputUtil.Key,
        var command: String,
    )

    @Serializable
    data class Alias(
        var alias: String,
        var command: String
    )

    /**
     * Object for storing all the actual config values that will be used in doing useful stuff with the config
     */
    companion object ConfigVars {

        var configOptions = ConfigOptions()

        val huds = mutableListOf<Triple<HudElement, Point, Float>>()

        fun hudElement(
            id: String, label: Text, width: Int, height: Int,
            defaultPosition: Point, scale: Float = 1f
        ): HudElement {
            val element = HudElement(
                configOptions.positions.getOrPut(
                    id
                ) { HudElement.Positioning(defaultPosition.x(), defaultPosition.y(), scale) },
                id,
                label, width, height,
            )
            huds.add(Triple(element, defaultPosition, scale))
            return element
        }

        fun saveConfig() {
            val json = Json {
                prettyPrint = true
                ignoreUnknownKeys = true
                encodeDefaults = true
            }

            val configDirectory = File(mc.runDirectory, "config")
            if (!configDirectory.exists()) {
                configDirectory.mkdir()
            }
            val configFile = File(configDirectory, "dulkirConfig.json")
            configFile.writeText(json.encodeToString(configOptions))
        }

        fun loadConfig() {
            val configDir = File(mc.runDirectory, "config")
            if (!configDir.exists()) return
            val configFile = File(configDir, "dulkirConfig.json")
            if (configFile.exists()) {
                val json = Json {
                    prettyPrint = true
                    ignoreUnknownKeys = true
                    encodeDefaults = true
                }
                configOptions = json.decodeFromString<ConfigOptions>(configFile.readText())
            }
            huds.forEach { (element, defaultPosition, scale) ->
                element.positioning = configOptions.positions.getOrPut(
                    element.key
                ) { HudElement.Positioning(defaultPosition.x(), defaultPosition.y(), scale) }
            }
        }
    }
}