mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 09:05:08 +01:00
fix: make tooltip translation key respect custom entry names
This commit is contained in:
@@ -16,12 +16,12 @@ public class EntryInfo {
|
||||
public MidnightConfig.Condition[] conditions;
|
||||
public final Field field;
|
||||
public final Class<?> dataType;
|
||||
public final String modid, fieldName;
|
||||
public final String modid, fieldName, translationKey;
|
||||
int listIndex;
|
||||
Object defaultValue, value, function;
|
||||
String tempValue; // The value visible in the config screen
|
||||
boolean inLimits = true;
|
||||
Text name, error;
|
||||
Text error;
|
||||
ClickableWidget actionButton; // color picker button / explorer button
|
||||
Tab tab;
|
||||
boolean conditionsMet = true;
|
||||
@@ -41,9 +41,10 @@ public class EntryInfo {
|
||||
}
|
||||
|
||||
if (entry != null && !entry.name().isEmpty())
|
||||
this.name = Text.translatable(entry.name());
|
||||
this.translationKey = entry.name();
|
||||
else if (comment != null && !comment.name().isEmpty())
|
||||
this.name = Text.translatable(comment.name());
|
||||
this.translationKey = comment.name();
|
||||
else this.translationKey = modid + ".midnightconfig." + fieldName;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
@@ -97,7 +98,7 @@ public class EntryInfo {
|
||||
}
|
||||
|
||||
public Tooltip getTooltip(boolean isButton) {
|
||||
String key = this.modid + ".midnightconfig." + this.fieldName + (!isButton ? ".label" : "") + ".tooltip";
|
||||
String key = translationKey + (!isButton ? ".label" : "") + ".tooltip";
|
||||
return Tooltip.of(isButton && this.error != null ? this.error : I18n.hasTranslation(key) ? Text.translatable(key) : Text.empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class MidnightConfigScreen extends Screen {
|
||||
}
|
||||
scrollProgress = list.getScrollY();
|
||||
for (EntryInfo info : MidnightConfig.entries.values())
|
||||
info.updateFieldValue();
|
||||
if (Objects.equals(modid, info.modid)) info.updateFieldValue();
|
||||
updateButtons();
|
||||
if (instance.reloadScreen) {
|
||||
updateList();
|
||||
@@ -154,7 +154,6 @@ public class MidnightConfigScreen extends Screen {
|
||||
if (!visibleButLocked) continue;
|
||||
}
|
||||
if (info.modid.equals(modid) && (info.tab == null || info.tab == tabManager.getCurrentTab())) {
|
||||
Text name = Objects.requireNonNullElseGet(info.name, () -> Text.translatable(translationPrefix + info.fieldName));
|
||||
TextIconButtonWidget resetButton = TextIconButtonWidget.builder(Text.translatable("controls.reset"), (button -> {
|
||||
info.value = info.defaultValue;
|
||||
info.listIndex = 0;
|
||||
@@ -245,8 +244,8 @@ public class MidnightConfigScreen extends Screen {
|
||||
widgets.add(cycleButton);
|
||||
}
|
||||
if (!info.conditionsMet) widgets.forEach(w -> w.active = false);
|
||||
this.list.addButton(widgets, name, info);
|
||||
} else this.list.addButton(List.of(), name, info);
|
||||
this.list.addButton(widgets, Text.translatable(info.translationKey), info);
|
||||
} else this.list.addButton(List.of(), Text.translatable(info.translationKey), info);
|
||||
}
|
||||
list.setScrollY(scrollProgress);
|
||||
updateButtons();
|
||||
|
||||
@@ -6,7 +6,7 @@ yarn_mappings=1.21.9+build.1
|
||||
enabled_platforms=fabric,neoforge
|
||||
|
||||
archives_base_name=midnightlib
|
||||
mod_version=1.8.1
|
||||
mod_version=1.8.2
|
||||
maven_group=eu.midnightdust
|
||||
release_type=release
|
||||
curseforge_id=488090
|
||||
|
||||
Reference in New Issue
Block a user