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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
package dev.isxander.yacl3.test;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.*;
import dev.isxander.yacl3.gui.RequireRestartScreen;
import dev.isxander.yacl3.gui.controllers.*;
import dev.isxander.yacl3.gui.controllers.cycling.EnumController;
import dev.isxander.yacl3.gui.controllers.slider.DoubleSliderController;
import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController;
import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController;
import dev.isxander.yacl3.gui.controllers.slider.LongSliderController;
import dev.isxander.yacl3.gui.controllers.string.StringController;
import dev.isxander.yacl3.gui.controllers.string.number.DoubleFieldController;
import dev.isxander.yacl3.gui.controllers.string.number.FloatFieldController;
import dev.isxander.yacl3.gui.controllers.string.number.IntegerFieldController;
import dev.isxander.yacl3.gui.controllers.string.number.LongFieldController;
import dev.isxander.yacl3.platform.YACLPlatform;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.GraphicsStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.toasts.SystemToast;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import org.apache.commons.lang3.StringUtils;
import java.awt.Color;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
public class GuiTest {
public static Screen getModConfigScreenFactory(Screen parent) {
return YetAnotherConfigLib.create(ConfigTest.GSON, (defaults, config, builder) -> builder
.title(Component.literal("Test Suites"))
.category(ConfigCategory.createBuilder()
.name(Component.literal("Suites"))
.option(ButtonOption.createBuilder()
.name(Component.literal("Full Test Suite"))
.action((screen, opt) -> Minecraft.getInstance().setScreen(getFullTestSuite(screen)))
.build())
.option(ButtonOption.createBuilder()
.name(Component.literal("Auto-gen test"))
.action((screen, opt) -> {
AutogenConfigTest.INSTANCE.load();
Minecraft.getInstance().setScreen(AutogenConfigTest.INSTANCE.generateGui().generateScreen(screen));
})
.build())
.option(ButtonOption.createBuilder()
.name(Component.literal("Kotlin DSL Test"))
.action((screen, opt) -> {
Minecraft.getInstance().setScreen(DslTestKt.kotlinDslGui(screen));
})
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Wiki"))
.option(ButtonOption.createBuilder()
.name(Component.literal("Get Started"))
.action((screen, opt) -> Minecraft.getInstance().setScreen(getWikiGetStarted(screen)))
.build())
.build())
.build())
)
.generateScreen(parent);
}
private static Screen getFullTestSuite(Screen parent) {
AtomicReference<Option<Boolean>> booleanOption = new AtomicReference<>();
ConfigTest.GSON.load();
return YetAnotherConfigLib.create(ConfigTest.GSON, (defaults, config, builder) -> builder
.title(Component.literal("Test GUI"))
.category(ConfigCategory.createBuilder()
.name(Component.literal("Control Examples"))
.tooltip(Component.literal("Example Category Description"))
.group(OptionGroup.createBuilder()
.name(Component.literal("Boolean Controllers"))
.option(Util.make(() -> {
var opt = Option.<Boolean>createBuilder()
.name(Component.literal("Boolean Toggle"))
.description(OptionDescription.createBuilder()
.text(Component.empty()
.append(Component.literal("a").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("a")))))
.append(Component.literal("b").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("b")))))
.append(Component.literal("c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("c")))))
.append(Component.literal("e").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("e")))))
.withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://isxander.dev")))
)
.webpImage(imageSample("sample1.webp"))
.build())
.binding(
defaults.booleanToggle,
() -> config.booleanToggle,
(value) -> config.booleanToggle = value
)
.controller(BooleanControllerBuilder::create)
.flag(OptionFlag.GAME_RESTART)
.build();
booleanOption.set(opt);
return opt;
}))
.option(Option.<Boolean>createBuilder()
.name(Component.literal("Custom Boolean Toggle"))
.description(val -> OptionDescription.createBuilder()
.text(Component.literal("You can customize controllers like so! YACL is truly infinitely customizable! This tooltip is long in order to demonstrate the cool, smooth scrolling of these descriptions. Did you know, they are also super clickable?! I know, cool right, YACL 3.x really is amazing."))
.build())
.binding(
defaults.customBooleanToggle,
() -> config.customBooleanToggle,
(value) -> config.customBooleanToggle = value
)
.controller(opt -> BooleanControllerBuilder.create(opt)
.formatValue(state -> state ? Component.literal("Amazing") : Component.literal("Not Amazing"))
.coloured(true))
.listener((opt, val) -> booleanOption.get().setAvailable(val))
.build())
.option(Option.<Boolean>createBuilder()
.name(Component.literal("Tick Box"))
.description(OptionDescription.createBuilder()
.text(Component.literal("There are even alternate methods of displaying the same data type!"))
.webpImage(imageSample("sample3.webp"))
.build())
.binding(
defaults.tickbox,
() -> config.tickbox,
(value) -> config.tickbox = value
)
.controller(TickBoxControllerBuilder::create)
.build())
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Slider Controllers"))
.option(Option.<Integer>createBuilder()
.name(Component.literal("Int Slider"))
.description(OptionDescription.createBuilder()
.gifImage(imageSample("sample4.gif"))
.build())
.binding(
defaults.intSlider,
() -> config.intSlider,
value -> config.intSlider = value
)
.customController(opt -> new IntegerSliderController(opt, 0, 3, 1))
.build())
.option(Option.<Double>createBuilder()
.name(Component.literal("Double Slider"))
.binding(
defaults.doubleSlider,
() -> config.doubleSlider,
(value) -> config.doubleSlider = value
)
.customController(opt -> new DoubleSliderController(opt, 0, 3, 0.05))
.build())
.option(Option.<Float>createBuilder()
.name(Component.literal("Float Slider"))
.binding(
defaults.floatSlider,
() -> config.floatSlider,
(value) -> config.floatSlider = value
)
.customController(opt -> new FloatSliderController(opt, 0, 3, 0.1f))
.build())
.option(Option.<Long>createBuilder()
.name(Component.literal("Long Slider"))
.binding(
defaults.longSlider,
() -> config.longSlider,
(value) -> config.longSlider = value
)
.customController(opt -> new LongSliderController(opt, 0, 1_000_000, 100))
.build())
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Input Field Controllers"))
.option(Option.<String>createBuilder()
.name(Component.literal("Component Option"))
.binding(
defaults.textField,
() -> config.textField,
value -> config.textField = value
)
.customController(StringController::new)
.build())
.option(Option.<Color>createBuilder()
.name(Component.literal("Color Option"))
.binding(
defaults.colorOption,
() -> config.colorOption,
value -> config.colorOption = value
)
.controller(opt -> ColorControllerBuilder.create(opt)
.allowAlpha(true))
.build())
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Number Fields"))
.option(Option.<Double>createBuilder()
.name(Component.literal("Double Field"))
.binding(
defaults.doubleField,
() -> config.doubleField,
value -> config.doubleField = value
)
.customController(DoubleFieldController::new)
.build())
.option(Option.<Float>createBuilder()
.name(Component.literal("Float Field"))
.binding(
defaults.floatField,
() -> config.floatField,
value -> config.floatField = value
)
.customController(FloatFieldController::new)
.build())
.option(Option.<Integer>createBuilder()
.name(Component.literal("Integer Field"))
.binding(
defaults.intField,
() -> config.intField,
value -> config.intField = value
)
.customController(IntegerFieldController::new)
.build())
.option(Option.<Long>createBuilder()
.name(Component.literal("Long Field"))
.binding(
defaults.longField,
() -> config.longField,
value -> config.longField = value
)
.customController(LongFieldController::new)
.build())
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Enum Controllers"))
.option(Option.<ConfigTest.Alphabet>createBuilder()
.name(Component.literal("Enum Cycler"))
.binding(
defaults.enumOption,
() -> config.enumOption,
(value) -> config.enumOption = value
)
.customController(opt -> new EnumController<>(opt, ConfigTest.Alphabet.class))
.build())
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Dropdown Controllers"))
.option(Option.<String>createBuilder()
.name(Component.literal("String Dropdown"))
.binding(
defaults.stringOptions,
() -> config.stringOptions,
(value) -> config.stringOptions = value
)
.controller(opt -> DropdownStringControllerBuilder.create(opt)
.values("Apple", "Banana", "Cherry", "Date")
)
.build())
.option(Option.<String>createBuilder()
.name(Component.literal("String suggestions"))
.binding(
defaults.stringSuggestions,
() -> config.stringSuggestions,
(value) -> config.stringSuggestions = value
)
.controller(opt -> DropdownStringControllerBuilder.create(opt)
.values("Apple", "Banana", "Cherry", "Date")
.allowAnyValue(true)
)
.build())
.option(Option.<Item>createBuilder()
.name(Component.literal("Item Dropdown"))
.binding(
defaults.item,
() -> config.item,
(value) -> config.item = value
)
.controller(ItemControllerBuilder::create)
.build())
.option(Option.<ChatFormatting>createBuilder()
.name(Component.literal("Enum Dropdown"))
.binding(
defaults.formattingOption,
() -> config.formattingOption,
(value) -> config.formattingOption = value
)
.controller(option -> EnumDropdownControllerBuilder.create(option).formatValue(formatting -> Component.literal(StringUtils.capitalize(formatting.getName()).replaceAll("_", " "))))
.build())
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Options that aren't really options"))
.option(ButtonOption.createBuilder()
.name(Component.literal("Button \"Option\""))
.action((screen, opt) -> opt.setAvailable(false))
.build())
.option(LabelOption.create(
Component.empty()
.append(Component.literal("a").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("a")))))
.append(Component.literal("b").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("b")))))
.append(Component.literal("c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("c")))))
.append(Component.literal("e").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("e")))))
.withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://isxander.dev"))))
)
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("Minecraft Bindings"))
.description(OptionDescription.of(Component.literal("YACL can also bind Minecraft options!")))
.option(Option.<Boolean>createBuilder()
.name(Component.literal("Minecraft AutoJump"))
.description(OptionDescription.of(Component.literal("You can even bind minecraft options!")))
.binding(Binding.minecraft(Minecraft.getInstance().options.autoJump()))
.customController(TickBoxController::new)
.build())
.option(Option.<GraphicsStatus>createBuilder()
.name(Component.literal("Minecraft Graphics Mode"))
.binding(Binding.minecraft(Minecraft.getInstance().options.graphicsMode()))
.customController(opt -> new EnumController<>(opt, GraphicsStatus.class))
.build())
.build())
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("List Test"))
.group(ListOption.<String>createBuilder()
.name(Component.literal("String List"))
.binding(
defaults.stringList,
() -> config.stringList,
val -> config.stringList = val
)
.controller(StringControllerBuilder::create)
.initial("")
.minimumNumberOfEntries(3)
.maximumNumberOfEntries(5)
.insertEntriesAtEnd(true)
.build())
.group(ListOption.<Integer>createBuilder()
.name(Component.literal("Slider List"))
.binding(
defaults.intList,
() -> config.intList,
val -> config.intList = val
)
.controller(opt -> IntegerSliderControllerBuilder.create(opt)
.range(0, 10).step(1))
.initial(0)
.available(false)
.build())
.group(ListOption.<Component>createBuilder()
.name(Component.literal("Useless Label List"))
.binding(Binding.immutable(List.of(Component.literal("It's quite impressive that literally every single controller works, without problem."))))
.customController(LabelController::new)
.initial(Component.literal("Initial label"))
.build())
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Group Test"))
.option(Option.<Boolean>createBuilder()
.name(Component.literal("Root Test"))
.binding(
defaults.groupTestRoot,
() -> config.groupTestRoot,
value -> config.groupTestRoot = value
)
.customController(TickBoxController::new)
.build())
.group(OptionGroup.createBuilder()
.name(Component.literal("First Group"))
.option(Option.<Boolean>createBuilder()
.name(Component.literal("First Group Test 1"))
.binding(
defaults.groupTestFirstGroup,
() -> config.groupTestFirstGroup,
value -> config.groupTestFirstGroup = value
)
.customController(TickBoxController::new)
.build())
.option(Option.<Boolean>createBuilder()
.name(Component.literal("First Group Test 2"))
.binding(
defaults.groupTestFirstGroup2,
() -> config.groupTestFirstGroup2,
value -> config.groupTestFirstGroup2 = value
)
.customController(TickBoxController::new)
.build())
.build())
.group(OptionGroup.createBuilder()
.name(Component.empty())
.option(Option.<Boolean>createBuilder()
.name(Component.literal("Second Group Test"))
.binding(
defaults.groupTestSecondGroup,
() -> config.groupTestSecondGroup,
value -> config.groupTestSecondGroup = value
)
.customController(TickBoxController::new)
.build())
.build())
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Color Picker Test"))
.option(Option.<Color>createBuilder()
.name(Component.literal("Top Color Option"))
.binding(
defaults.topColorOption,
() -> config.topColorOption,
value -> config.topColorOption = value
)
.customController(ColorController::new)
.description(OptionDescription.of(Component.literal("A Color Controller's Color Picker will appear beneath the color if there is not enough room above it.")))
.build())
.option(LabelOption.create(Component.literal("Enabling a Color Controller's Color Picker at the top of the screen will appear beneath it if there isn't enough room above. This also applies to color controllers with alpha enabled.")))
.option(Option.<Color>createBuilder()
.name(Component.literal("Alpha Color Option"))
.binding(
defaults.alphaColorOption,
() -> config.alphaColorOption,
value -> config.alphaColorOption = value
)
.customController(opt -> new ColorController(opt, true))
.description(OptionDescription.of(Component.literal("A Color Picker will also allow you to choose a Color Controller's alpha if it is enabled.")))
.build())
.option(ButtonOption.createBuilder()
.name(Component.literal("Button \"Option\""))
.action((screen, opt) -> opt.setAvailable(false))
.build())
.option(LabelOption.create(Component.literal("You can try and hit the button above while the color picker below is visible, but you shouldn't be able to.")))
.option(Option.<Color>createBuilder()
.name(Component.literal("Button Color Option"))
.binding(
defaults.buttonColorOption,
() -> config.buttonColorOption,
value -> config.buttonColorOption = value
)
.customController(ColorController::new)
.description(OptionDescription.of(Component.literal("Other controller's buttons are disabled while a color picker is visible!")))
.build())
.option(LabelOption.create(Component.literal("The color picker button will be outlined with a light grey color instead of white if the controller's color is very light. This is all determined using the hue and value(brightness) of the color.")))
.option(Option.<Color>createBuilder()
.name(Component.literal("Alternative Color Outline"))
.binding(
defaults.alternativePreviewOutline,
() -> config.alternativePreviewOutline,
value -> config.alternativePreviewOutline = value
)
.customController(opt -> new ColorController(opt, true))
.description(OptionDescription.of(Component.literal("This helps users who don't know about the color picker discover it, even if a developer chooses a lighter color")))
.build())
.option(LabelOption.create(Component.literal("An extra color controller with alpha enabled to show that it too has the alternative color outline")))
.option(Option.<Color>createBuilder()
.name(Component.literal("Alpha Color Option 2"))
.binding(
defaults.anotherAlphaColorOption,
() -> config.anotherAlphaColorOption,
value -> config.anotherAlphaColorOption = value
)
.customController(opt -> new ColorController(opt, true))
.description(OptionDescription.of(Component.literal("Yay!!!!!!")))
.build())
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Category Test"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Category Test"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Category Test"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Category Test"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Category Test"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Category Test"))
.option(LabelOption.create(Component.literal("This is a test category!")))
.build())
.category(PlaceholderCategory.createBuilder()
.name(Component.literal("Placeholder Category"))
.screen((client, yaclScreen) -> new RequireRestartScreen(yaclScreen))
.build())
.save(() -> {
Minecraft.getInstance().options.save();
ConfigTest.GSON.serializer().save();
})
)
.generateScreen(parent);
}
private static ResourceLocation imageSample(String name) {
return YACLPlatform.rl("yacl_test", "textures/images/" + name);
}
private static boolean myBooleanOption = true;
private static Screen getWikiGetStarted(Screen parent) {
return YetAnotherConfigLib.createBuilder()
.title(Component.literal("Used for narration. Could be used to render a title in the future."))
.category(ConfigCategory.createBuilder()
.name(Component.literal("Name of the category"))
.tooltip(Component.literal("This Component will appear as a tooltip when you hover or focus the button with Tab. There is no need to add \n to wrap as YACL will do it for you."))
.group(OptionGroup.createBuilder()
.name(Component.literal("Name of the group"))
.description(OptionDescription.of(Component.literal("This Component will appear when you hover over the name or focus on the collapse button with Tab.")))
.option(Option.<Boolean>createBuilder()
.name(Component.literal("Boolean Option"))
.description(OptionDescription.of(Component.literal("This Component will appear as a tooltip when you hover over the option.")))
.binding(true, () -> myBooleanOption, newVal -> myBooleanOption = newVal)
.customController(TickBoxController::new)
.build())
.build())
.build())
.build()
.generateScreen(parent);
}
}
|