|
| 1 | +/* |
| 2 | + * Copyright (C) 2026 The Debugify Contributors |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LGPL-3.0-or-later |
| 5 | + */ |
1 | 6 | package dev.isxander.debugify.client.gui; |
2 | 7 |
|
3 | 8 | import dev.isxander.debugify.config.DebugifyConfig; |
|
14 | 19 | import net.minecraft.network.chat.Component; |
15 | 20 |
|
16 | 21 | public class ConfigGuiHelper { |
17 | | - public static Screen createConfigGui(DebugifyConfig config, Screen parent) { |
18 | | - var yacl = YetAnotherConfigLib.createBuilder() |
19 | | - .title(Component.translatable("debugify.name")) |
20 | | - .save(config::save); |
21 | | - |
22 | | - var gameplayWarning = LabelOption.create(Component.translatable("debugify.gameplay.warning").withStyle(ChatFormatting.RED)); |
23 | | - var gameplayInMultiplayer = Option.<Boolean>createBuilder() |
24 | | - .name(Component.translatable("debugify.gameplay.enable_in_multiplayer")) |
25 | | - .binding( |
26 | | - false, |
27 | | - () -> config.gameplayFixesInMultiplayer, |
28 | | - value -> config.gameplayFixesInMultiplayer = value |
29 | | - ) |
30 | | - .controller(TickBoxControllerBuilder::create) |
31 | | - .build(); |
32 | | - |
33 | | - for (BugFix.Env env : BugFix.Env.values()) { |
34 | | - var categoryBuilder = ConfigCategory.createBuilder() |
35 | | - .name(Component.translatable(env.getDisplayName())) |
36 | | - .tooltip(Component.translatable(env.getDescriptionKey())); |
37 | | - |
38 | | - for (FixCategory fixCategory : FixCategory.values()) { |
39 | | - var groupBuilder = OptionGroup.createBuilder() |
40 | | - .name(Component.translatable(fixCategory.getDisplayName())); |
41 | | - |
42 | | - if (fixCategory == FixCategory.GAMEPLAY) { |
43 | | - groupBuilder |
44 | | - .option(gameplayWarning) |
45 | | - .option(gameplayInMultiplayer); |
46 | | - } |
47 | | - |
48 | | - config.getBugFixes().forEach((bug, enabled) -> { |
49 | | - if (bug.env() == env && bug.category() == fixCategory) { |
50 | | - var conflicts = bug.getActiveConflicts().stream().map(id -> FabricLoader.getInstance().getModContainer(id).orElseThrow().getMetadata().getName()).toList(); |
51 | | - var satisfiesOS = bug.satisfiesOSRequirement(); |
52 | | - var errored = DebugifyErrorHandler.hasErrored(bug); |
53 | | - var unavailable = !conflicts.isEmpty() || !satisfiesOS || errored; |
54 | | - |
55 | | - var optionBuilder = Option.<Boolean>createBuilder() |
56 | | - .name(Component.literal(bug.bugId())) |
57 | | - .binding( |
58 | | - bug.enabledByDefault(), |
59 | | - () -> config.getBugFixes().get(bug), |
60 | | - value -> config.getBugFixes().replace(bug, value) |
61 | | - ) |
62 | | - .customController(opt -> new BugFixController(opt, errored)) |
63 | | - .available(!unavailable) |
64 | | - .flag(OptionFlag.GAME_RESTART); |
65 | | - |
66 | | - OptionDescription.Builder descriptionBuilder = OptionDescription.createBuilder(); |
67 | | - |
68 | | - if (errored) { |
69 | | - descriptionBuilder.text(Component.translatable("debugify.error.mixin_error", bug.bugId()).withStyle(ChatFormatting.RED, ChatFormatting.BOLD)); |
70 | | - } |
71 | | - |
72 | | - for (String conflictMod : conflicts) { |
73 | | - descriptionBuilder.text(Component.translatable("debugify.error.conflict", bug.bugId(), conflictMod).withStyle(ChatFormatting.RED)); |
74 | | - } |
75 | | - |
76 | | - if (!satisfiesOS) |
77 | | - descriptionBuilder.text(Component.translatable("debugify.error.os", bug.bugId(), Component.translatable(bug.requiredOs().getDisplayName())).withStyle(ChatFormatting.RED)); |
78 | | - |
79 | | - if (bug.description() != null) |
80 | | - descriptionBuilder.text(Component.literal(bug.description())); |
81 | | - |
82 | | - String fixExplanationTooltipKey = "debugify.fix_explanation." + bug.bugId().toLowerCase(); |
83 | | - if (Language.getInstance().has(fixExplanationTooltipKey)) |
84 | | - descriptionBuilder.text(Component.translatable(fixExplanationTooltipKey).withStyle(ChatFormatting.GRAY)); |
85 | | - |
86 | | - String fixEffectTooltipKey = "debugify.fix_effect." + bug.bugId().toLowerCase(); |
87 | | - if (Language.getInstance().has(fixEffectTooltipKey)) |
88 | | - descriptionBuilder.text(Component.translatable(fixEffectTooltipKey).withStyle(ChatFormatting.GOLD)); |
89 | | - |
90 | | - optionBuilder.description(descriptionBuilder.build()); |
91 | | - |
92 | | - groupBuilder.option(optionBuilder.build()); |
93 | | - } |
94 | | - }); |
95 | | - |
96 | | - categoryBuilder.group(groupBuilder.build()); |
97 | | - } |
98 | | - |
99 | | - yacl.category(categoryBuilder.build()); |
100 | | - } |
101 | | - |
102 | | - yacl.category(ConfigCategory.createBuilder() |
103 | | - .name(Component.translatable("debugify.misc")) |
104 | | - .option(Option.<Boolean>createBuilder() |
105 | | - .name(Component.translatable("debugify.misc.default_disabled")) |
106 | | - .description(OptionDescription.of(Component.translatable("debugify.misc.default_disabled.description"))) |
107 | | - .binding( |
108 | | - false, |
109 | | - () -> config.defaultDisabled, |
110 | | - value -> config.defaultDisabled = value |
111 | | - ) |
112 | | - .controller(BooleanControllerBuilder::create) |
113 | | - .build()) |
114 | | - .build()); |
115 | | - |
116 | | - return yacl.build().generateScreen(parent); |
117 | | - } |
| 22 | + public static Screen createConfigGui(DebugifyConfig config, Screen parent) { |
| 23 | + var yacl = YetAnotherConfigLib.createBuilder() |
| 24 | + .title(Component.translatable("debugify.name")) |
| 25 | + .save(config::save); |
| 26 | + |
| 27 | + var gameplayWarning = LabelOption.create(Component.translatable("debugify.gameplay.warning").withStyle(ChatFormatting.RED)); |
| 28 | + var gameplayInMultiplayer = Option.<Boolean>createBuilder() |
| 29 | + .name(Component.translatable("debugify.gameplay.enable_in_multiplayer")) |
| 30 | + .binding( |
| 31 | + false, |
| 32 | + () -> config.gameplayFixesInMultiplayer, |
| 33 | + value -> config.gameplayFixesInMultiplayer = value |
| 34 | + ) |
| 35 | + .controller(TickBoxControllerBuilder::create) |
| 36 | + .build(); |
| 37 | + |
| 38 | + for (BugFix.Env env : BugFix.Env.values()) { |
| 39 | + var categoryBuilder = ConfigCategory.createBuilder() |
| 40 | + .name(Component.translatable(env.getDisplayName())) |
| 41 | + .tooltip(Component.translatable(env.getDescriptionKey())); |
| 42 | + |
| 43 | + for (FixCategory fixCategory : FixCategory.values()) { |
| 44 | + var groupBuilder = OptionGroup.createBuilder() |
| 45 | + .name(Component.translatable(fixCategory.getDisplayName())); |
| 46 | + |
| 47 | + if (fixCategory == FixCategory.GAMEPLAY) { |
| 48 | + groupBuilder |
| 49 | + .option(gameplayWarning) |
| 50 | + .option(gameplayInMultiplayer); |
| 51 | + } |
| 52 | + |
| 53 | + config.getBugFixes().forEach((bug, enabled) -> { |
| 54 | + if (bug.env() == env && bug.category() == fixCategory) { |
| 55 | + var conflicts = bug.getActiveConflicts().stream().map(id -> FabricLoader.getInstance().getModContainer(id).orElseThrow().getMetadata().getName()).toList(); |
| 56 | + var satisfiesOS = bug.satisfiesOSRequirement(); |
| 57 | + var errored = DebugifyErrorHandler.hasErrored(bug); |
| 58 | + var unavailable = !conflicts.isEmpty() || !satisfiesOS || errored; |
| 59 | + |
| 60 | + var optionBuilder = Option.<Boolean>createBuilder() |
| 61 | + .name(Component.literal(bug.bugId())) |
| 62 | + .binding( |
| 63 | + bug.enabledByDefault(), |
| 64 | + () -> config.getBugFixes().get(bug), |
| 65 | + value -> config.getBugFixes().replace(bug, value) |
| 66 | + ) |
| 67 | + .customController(opt -> new BugFixController(opt, errored)) |
| 68 | + .available(!unavailable) |
| 69 | + .flag(OptionFlag.GAME_RESTART); |
| 70 | + |
| 71 | + OptionDescription.Builder descriptionBuilder = OptionDescription.createBuilder(); |
| 72 | + |
| 73 | + if (errored) { |
| 74 | + descriptionBuilder.text(Component.translatable("debugify.error.mixin_error", bug.bugId()).withStyle(ChatFormatting.RED, ChatFormatting.BOLD)); |
| 75 | + } |
| 76 | + |
| 77 | + for (String conflictMod : conflicts) { |
| 78 | + descriptionBuilder.text(Component.translatable("debugify.error.conflict", bug.bugId(), conflictMod).withStyle(ChatFormatting.RED)); |
| 79 | + } |
| 80 | + |
| 81 | + if (!satisfiesOS) |
| 82 | + descriptionBuilder.text(Component.translatable("debugify.error.os", bug.bugId(), Component.translatable(bug.requiredOs().getDisplayName())).withStyle(ChatFormatting.RED)); |
| 83 | + |
| 84 | + if (bug.description() != null) |
| 85 | + descriptionBuilder.text(Component.literal(bug.description())); |
| 86 | + |
| 87 | + String fixExplanationTooltipKey = "debugify.fix_explanation." + bug.bugId().toLowerCase(); |
| 88 | + if (Language.getInstance().has(fixExplanationTooltipKey)) |
| 89 | + descriptionBuilder.text(Component.translatable(fixExplanationTooltipKey).withStyle(ChatFormatting.GRAY)); |
| 90 | + |
| 91 | + String fixEffectTooltipKey = "debugify.fix_effect." + bug.bugId().toLowerCase(); |
| 92 | + if (Language.getInstance().has(fixEffectTooltipKey)) |
| 93 | + descriptionBuilder.text(Component.translatable(fixEffectTooltipKey).withStyle(ChatFormatting.GOLD)); |
| 94 | + |
| 95 | + optionBuilder.description(descriptionBuilder.build()); |
| 96 | + |
| 97 | + groupBuilder.option(optionBuilder.build()); |
| 98 | + } |
| 99 | + }); |
| 100 | + |
| 101 | + categoryBuilder.group(groupBuilder.build()); |
| 102 | + } |
| 103 | + |
| 104 | + yacl.category(categoryBuilder.build()); |
| 105 | + } |
| 106 | + |
| 107 | + yacl.category(ConfigCategory.createBuilder() |
| 108 | + .name(Component.translatable("debugify.misc")) |
| 109 | + .option(Option.<Boolean>createBuilder() |
| 110 | + .name(Component.translatable("debugify.misc.default_disabled")) |
| 111 | + .description(OptionDescription.of(Component.translatable("debugify.misc.default_disabled.description"))) |
| 112 | + .binding( |
| 113 | + false, |
| 114 | + () -> config.defaultDisabled, |
| 115 | + value -> config.defaultDisabled = value |
| 116 | + ) |
| 117 | + .controller(BooleanControllerBuilder::create) |
| 118 | + .build()) |
| 119 | + .build()); |
| 120 | + |
| 121 | + return yacl.build().generateScreen(parent); |
| 122 | + } |
118 | 123 | } |
0 commit comments