|
4 | 4 | import com.daniking.backtools.config.AItemLike; |
5 | 5 | import com.daniking.backtools.config.ToolTransformation; |
6 | 6 | import com.daniking.backtools.config.menu.yacl.ButtonList; |
7 | | -import com.daniking.backtools.config.menu.yacl.ItemTagControllerBuilder; |
| 7 | +import com.daniking.backtools.config.menu.yacl.ToolTransformationScreen; |
8 | 8 | import com.terraformersmc.modmenu.api.ConfigScreenFactory; |
9 | 9 | import com.terraformersmc.modmenu.api.ModMenuApi; |
10 | 10 | import dev.isxander.yacl3.api.*; |
11 | 11 | import dev.isxander.yacl3.api.controller.BooleanControllerBuilder; |
12 | | -import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder; |
13 | | -import dev.isxander.yacl3.api.controller.StringControllerBuilder; |
14 | | -import dev.isxander.yacl3.impl.SimpleStateManager; |
15 | 12 | import net.fabricmc.api.EnvType; |
16 | 13 | import net.fabricmc.api.Environment; |
17 | 14 | import net.minecraft.client.MinecraftClient; |
|
20 | 17 | import org.jetbrains.annotations.NotNull; |
21 | 18 |
|
22 | 19 | import java.util.*; |
23 | | -import java.util.concurrent.atomic.AtomicReference; |
24 | 20 | import java.util.function.Consumer; |
25 | 21 | import java.util.function.Supplier; |
26 | 22 |
|
@@ -70,7 +66,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() { |
70 | 66 | ConfigCategory.createBuilder(). |
71 | 67 | name(Text.literal("back tools")). |
72 | 68 | group(ButtonList.createBuilder(). |
73 | | - state(new ListStateManager( |
| 69 | + state(StateManager.createSimple( |
74 | 70 | new ListBinding( |
75 | 71 | () -> BackTools.getConfigHandler().rawBackTools(), |
76 | 72 | newMap -> BackTools.getConfigHandler().rawBackTools(newMap)) |
@@ -98,21 +94,22 @@ public Map.Entry<AItemLike, ToolTransformation> defaultValue() { |
98 | 94 | (yaclScreen, entryListButtonOption) -> { |
99 | 95 | Map.Entry<AItemLike, ToolTransformation> pendingValue = entryListButtonOption.pendingValue(); |
100 | 96 | MinecraftClient.getInstance().setScreen( |
101 | | - buildTransformationScreen( |
| 97 | + ToolTransformationScreen.createToolTransformationScreen( |
| 98 | + yaclScreen, |
| 99 | + false, |
102 | 100 | pendingValue.getKey(), |
103 | 101 | pendingValue.getValue(), |
104 | | - Text.literal("back tools"), |
105 | 102 | BackTools.getConfigHandler().isAdvancedMenu(), |
106 | 103 | entryListButtonOption::requestSet |
107 | | - ).generateScreen(yaclScreen) |
| 104 | + ) |
108 | 105 | ); |
109 | 106 | }).build() |
110 | 107 | ).build() |
111 | 108 | ).category( |
112 | 109 | ConfigCategory.createBuilder(). |
113 | 110 | name(Text.literal("belt tools")). |
114 | 111 | group(ButtonList.createBuilder(). |
115 | | - state(new ListStateManager( |
| 112 | + state(StateManager.createSimple( |
116 | 113 | new ListBinding( |
117 | 114 | () -> BackTools.getConfigHandler().rawBeltTools(), |
118 | 115 | newMap -> BackTools.getConfigHandler().rawBeltTools(newMap)) |
@@ -140,157 +137,21 @@ public Map.Entry<AItemLike, ToolTransformation> defaultValue() { |
140 | 137 | (yaclScreen, entryListButtonOption) -> { |
141 | 138 | Map.Entry<AItemLike, ToolTransformation> pendingValue = entryListButtonOption.pendingValue(); |
142 | 139 | MinecraftClient.getInstance().setScreen( |
143 | | - buildTransformationScreen( |
| 140 | + ToolTransformationScreen.createToolTransformationScreen( |
| 141 | + yaclScreen, |
| 142 | + true, |
144 | 143 | pendingValue.getKey(), |
145 | 144 | pendingValue.getValue(), |
146 | | - Text.literal("belt tools"), |
147 | 145 | BackTools.getConfigHandler().isAdvancedMenu(), |
148 | 146 | entryListButtonOption::requestSet |
149 | | - ).generateScreen(yaclScreen) |
| 147 | + ) |
150 | 148 | ); |
151 | 149 | }).build() |
152 | 150 | ).build() |
153 | 151 | ).build(). |
154 | 152 | generateScreen(parent); |
155 | 153 | } |
156 | 154 |
|
157 | | - private static @NotNull YetAnotherConfigLib buildTransformationScreen(final @NotNull AItemLike initialItemLike, |
158 | | - final @NotNull ToolTransformation toolTransformation, |
159 | | - final Text toolPlacementType, |
160 | | - final boolean advancedMode, |
161 | | - final @NotNull Consumer<Map.Entry<AItemLike, ToolTransformation>> resultConsumer) { // todo translations |
162 | | - final @NotNull AtomicReference<@NotNull AItemLike> itemLikeReference = new AtomicReference<>(initialItemLike); |
163 | | - final @NotNull ToolTransformation.ToolTransformationBuilder toolTransformationBuilder = toolTransformation.toBuilder(); |
164 | | - final @NotNull AtomicReference<@NotNull String> rawComponentReference = new AtomicReference<>("{}"); // todo |
165 | | - |
166 | | - return YetAnotherConfigLib.createBuilder(). |
167 | | - title(toolPlacementType). |
168 | | - category(ConfigCategory.createBuilder(). |
169 | | - name(toolPlacementType). |
170 | | - option( |
171 | | - Option.<AItemLike>createBuilder(). |
172 | | - name(Text.literal("item (tag)")). |
173 | | - binding(AItemLike.fromItem(Items.STONE_SWORD), |
174 | | - itemLikeReference::get, |
175 | | - itemLikeReference::set |
176 | | - ). |
177 | | - controller(ItemTagControllerBuilder::create).//description(OptionDescription.createBuilder().). |
178 | | - build() |
179 | | - ).optionIf(advancedMode, Option.<String>createBuilder(). |
180 | | - name(Text.literal("components")). |
181 | | - controller(StringControllerBuilder::create). |
182 | | - binding( |
183 | | - "{}", // todo |
184 | | - rawComponentReference::get, |
185 | | - rawComponentReference::set |
186 | | - ).build() |
187 | | - ).groupIf(advancedMode, |
188 | | - OptionGroup.createBuilder(). |
189 | | - name(Text.literal("Offset")). |
190 | | - option(Option.<Float>createBuilder(). |
191 | | - name(Text.literal("X")). |
192 | | - controller(FloatFieldControllerBuilder::create). |
193 | | - binding(0F, |
194 | | - toolTransformationBuilder::offsetX, |
195 | | - toolTransformationBuilder::offsetX |
196 | | - ).build() |
197 | | - ). |
198 | | - option(Option.<Float>createBuilder(). |
199 | | - name(Text.literal("Y")). |
200 | | - controller(FloatFieldControllerBuilder::create). |
201 | | - binding(0F, |
202 | | - toolTransformationBuilder::offsetY, |
203 | | - toolTransformationBuilder::offsetY |
204 | | - ).build() |
205 | | - ). |
206 | | - option(Option.<Float>createBuilder(). |
207 | | - name(Text.literal("Z")). |
208 | | - controller(FloatFieldControllerBuilder::create). |
209 | | - binding(0F, |
210 | | - toolTransformationBuilder::offsetZ, |
211 | | - toolTransformationBuilder::offsetZ |
212 | | - ).build() |
213 | | - ).build() |
214 | | - ).group(OptionGroup.createBuilder(). |
215 | | - name(Text.literal("rotation")). |
216 | | - optionIf(advancedMode, Option.<Float>createBuilder(). |
217 | | - name(Text.literal("X")). |
218 | | - controller(FloatFieldControllerBuilder::create). |
219 | | - binding(0F, |
220 | | - toolTransformationBuilder::rotationX, |
221 | | - toolTransformationBuilder::rotationX |
222 | | - ).build()). |
223 | | - optionIf(advancedMode, Option.<Float>createBuilder(). |
224 | | - name(Text.literal("Y")). |
225 | | - controller(FloatFieldControllerBuilder::create). |
226 | | - binding(0F, |
227 | | - toolTransformationBuilder::rotationY, |
228 | | - toolTransformationBuilder::rotationY |
229 | | - ).build()). |
230 | | - option(Option.<Float>createBuilder(). |
231 | | - name(Text.literal("Z")). |
232 | | - controller(FloatFieldControllerBuilder::create). |
233 | | - binding(0F, |
234 | | - toolTransformationBuilder::rotationZ, |
235 | | - toolTransformationBuilder::rotationZ |
236 | | - ).build()). |
237 | | - build() |
238 | | - ).groupIf(advancedMode, |
239 | | - OptionGroup.createBuilder(). |
240 | | - name(Text.literal("Scale")). |
241 | | - option(Option.<Float>createBuilder(). |
242 | | - name(Text.literal("X")). |
243 | | - controller(FloatFieldControllerBuilder::create). |
244 | | - binding(1F, |
245 | | - toolTransformationBuilder::scaleX, |
246 | | - toolTransformationBuilder::scaleX |
247 | | - ).build() |
248 | | - ). |
249 | | - option(Option.<Float>createBuilder(). |
250 | | - name(Text.literal("Y")). |
251 | | - controller(FloatFieldControllerBuilder::create). |
252 | | - binding(1F, |
253 | | - toolTransformationBuilder::scaleY, |
254 | | - toolTransformationBuilder::scaleY |
255 | | - ).build() |
256 | | - ). |
257 | | - option(Option.<Float>createBuilder(). |
258 | | - name(Text.literal("Z")). |
259 | | - controller(FloatFieldControllerBuilder::create). |
260 | | - binding(1F, |
261 | | - toolTransformationBuilder::scaleZ, |
262 | | - toolTransformationBuilder::scaleZ |
263 | | - ).build() |
264 | | - ).build() |
265 | | - ).optionIf(advancedMode, Option.<Boolean>createBuilder(). |
266 | | - name(Text.literal("is symmetric")). |
267 | | - controller(option -> BooleanControllerBuilder.create(option). |
268 | | - trueFalseFormatter() |
269 | | - ).binding( |
270 | | - true, |
271 | | - toolTransformationBuilder::isSymmetric, |
272 | | - toolTransformationBuilder::isSymmetric |
273 | | - ).build() |
274 | | - ).option(Option.<Boolean>createBuilder(). |
275 | | - name(Text.literal("is blacklisted")). |
276 | | - controller(option -> BooleanControllerBuilder.create(option). |
277 | | - trueFalseFormatter() |
278 | | - ).binding( |
279 | | - false, |
280 | | - toolTransformationBuilder::isBlacklisted, |
281 | | - toolTransformationBuilder::isBlacklisted |
282 | | - ).build() |
283 | | - ).build() |
284 | | - ).save(() -> resultConsumer.accept(Map.entry(itemLikeReference.get(), toolTransformationBuilder.build()))). |
285 | | - build(); |
286 | | - } |
287 | | - |
288 | | - private static class ListStateManager extends SimpleStateManager<@NotNull List<Map.@NotNull Entry<@NotNull AItemLike, @NotNull ToolTransformation>>> { // todo???? |
289 | | - public ListStateManager(final @NotNull ListBinding binding) { |
290 | | - super(binding); |
291 | | - } |
292 | | - } |
293 | | - |
294 | 155 | private static class ListBinding implements Binding<@NotNull List<Map.@NotNull Entry<@NotNull AItemLike, @NotNull ToolTransformation>>> { |
295 | 156 | private final @NotNull Supplier<@NotNull SequencedMap<@NotNull AItemLike, @NotNull ToolTransformation>> mapGetter; |
296 | 157 | private final @NotNull Consumer<@NotNull LinkedHashMap<@NotNull AItemLike, @NotNull ToolTransformation>> mapSetter; |
|
0 commit comments