|
73 | 73 | * Based on <a href="https://github.com/Minenash/TinyConfig">https://github.com/Minenash/TinyConfig</a> |
74 | 74 | * Credits to Minenash |
75 | 75 | * <p> |
76 | | - * Adapted by Jamalam for JamLib |
| 76 | + * <p> |
| 77 | + * Adapted by Jamalam for use in JamLib |
77 | 78 | */ |
78 | 79 |
|
79 | 80 | @SuppressWarnings({"unchecked", "unused"}) |
@@ -162,14 +163,23 @@ else if (type == String.class || type == List.class) { |
162 | 163 | }, func); |
163 | 164 | } else if (type.isEnum()) { |
164 | 165 | List<?> values = Arrays.asList(field.getType().getEnumConstants()); |
165 | | - Function<Object, Text> func = value -> Text.translatable(modid + ".jamlibconfig." + "enum." + type.getSimpleName() + "." + info.value.toString()); |
| 166 | + Function<Object, Text> func = (value) -> { |
| 167 | + String translationKey = modid + ".jamlibconfig.enum." + type.getSimpleName() + "." + info.value.toString(); |
| 168 | + |
| 169 | + if (I18n.hasTranslation(translationKey)) { |
| 170 | + return Text.translatable(translationKey); |
| 171 | + } else { |
| 172 | + return Text.literal(info.value.toString()); |
| 173 | + } |
| 174 | + }; |
166 | 175 | info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> { |
167 | 176 | int index = values.indexOf(info.value) + 1; |
168 | 177 | info.value = values.get(index >= values.size() ? 0 : index); |
169 | 178 | button.setMessage(func.apply(info.value)); |
170 | 179 | }, func); |
171 | 180 | } |
172 | 181 | } |
| 182 | + |
173 | 183 | entries.add(info); |
174 | 184 | } |
175 | 185 |
|
@@ -232,7 +242,7 @@ public static Screen getScreen(Screen parent, String modid) { |
232 | 242 | @Environment(EnvType.CLIENT) |
233 | 243 | private static class MidnightConfigScreen extends Screen { |
234 | 244 | protected MidnightConfigScreen(Screen parent, String modid) { |
235 | | - super(Text.translatable(modid + ".jamlibconfig." + "title")); |
| 245 | + super(getConfigScreenTitle(modid)); |
236 | 246 | this.parent = parent; |
237 | 247 | this.modid = modid; |
238 | 248 | this.translationPrefix = modid + ".jamlibconfig."; |
@@ -390,6 +400,15 @@ else if (I18n.hasTranslation(key) && text.equals(name)) { |
390 | 400 | } |
391 | 401 | super.render(matrices, mouseX, mouseY, delta); |
392 | 402 | } |
| 403 | + |
| 404 | + @SuppressWarnings("OptionalGetWithoutIsPresent") |
| 405 | + private static Text getConfigScreenTitle(String modid) { |
| 406 | + if (I18n.hasTranslation(modid + ".jamlibconfig.title")) { |
| 407 | + return Text.translatable(modid + ".jamlibconfig.title"); |
| 408 | + } else { |
| 409 | + return Text.literal(FabricLoader.getInstance().getModContainer(modid).get().getMetadata().getName()); |
| 410 | + } |
| 411 | + } |
393 | 412 | } |
394 | 413 |
|
395 | 414 | @Environment(EnvType.CLIENT) |
|
0 commit comments