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