Add tooltips

This commit is contained in:
JFronny 2020-12-29 11:19:21 +01:00
parent cf179d9d25
commit b07e0a0671
4 changed files with 29 additions and 7 deletions

View File

@ -21,7 +21,10 @@ This config may include:
You can also provide translations/more complex names for your resource pack's configs.\
The following things can be changed:
- Entry names: `respackopts.field.{packId}.{entryId}`
- Config titles: `respackopts.title.{packId}`
- Category titles: `respackopts.title.{packId}`
- Tooltips: `respackopts.tooltip.{packId}.{entryId}`
In subcategories, you can use `{packId}.{categoryId}` instead of `{packId}`
Please note that translations require your resource pack to be loaded.

View File

@ -6,7 +6,7 @@ minecraft_version=1.16.4
yarn_mappings=1.16.4+build.7
loader_version=0.10.8
# Mod Properties
mod_version=1.3.0
mod_version=1.3.1
maven_group=io.gitlab.jfronny
archives_base_name=respackopts
# Dependencies

View File

@ -1,7 +1,9 @@
{
"respackopts.title.lumi": "Lumi Lights",
"respackopts.field.lumi.tonemap": "Tonemap mode",
"respackopts.tooltip.lumi.tonemap": "Tooltip test",
"respackopts.field.lumi.pbr": "Enable PBR",
"respackopts.field.lumi.debugMode": "Debug Mode",
"respackopts.field.lumi.waterVertexWavy": "Wavy water model"
"respackopts.field.lumi.waterVertexWavy": "Wavy water model",
"respackopts.tooltip.lumi.subcategoryTest.sliderTest": "Yayyy"
}

View File

@ -19,6 +19,7 @@ import net.minecraft.util.Language;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
public class GuiFactory {
@ -47,6 +48,7 @@ public class GuiFactory {
config.addEntry(entryBuilder.startBooleanToggle(getText(n, b), currentValue)
.setDefaultValue(defaultValue)
.setSaveConsumer(v -> Respackopts.boolVals.get(screenId).put(n, v))
.setTooltipSupplier(() -> getTooltip(n, screenId))
.build());
}
else if (p.isNumber()) {
@ -59,6 +61,7 @@ public class GuiFactory {
config.addEntry(entryBuilder.startDoubleField(getText(n, b), currentValue)
.setDefaultValue(defaultValue)
.setSaveConsumer(v -> Respackopts.numVals.get(screenId).put(n, v))
.setTooltipSupplier(() -> getTooltip(n, screenId))
.build());
}
else if (p.isString()) {
@ -71,6 +74,7 @@ public class GuiFactory {
config.addEntry(entryBuilder.startStrField(getText(n, b), currentValue)
.setDefaultValue(defaultValue)
.setSaveConsumer(v -> Respackopts.strVals.get(screenId).put(n, v))
.setTooltipSupplier(() -> getTooltip(n, screenId))
.build());
}
}
@ -96,7 +100,9 @@ public class GuiFactory {
Respackopts.numVals.get(screenId).put(n, (double) j);
j++;
}
}).build());
})
.setTooltipSupplier(() -> getTooltip(n, screenId))
.build());
}
else if (e.isJsonNull()) {
Respackopts.logger.error("Config definition contains null, skipping that entry");
@ -130,9 +136,8 @@ public class GuiFactory {
config.addEntry(entryBuilder.startIntSlider(getText(n, b),
currentValue.intValue(), minV.intValue(), maxV.intValue())
.setDefaultValue(defV.intValue())
.setSaveConsumer(v -> {
Respackopts.numVals.get(screenId).put(n, v.doubleValue());
})
.setSaveConsumer(v -> Respackopts.numVals.get(screenId).put(n, v.doubleValue()))
.setTooltipSupplier(() -> getTooltip(n, screenId))
.build());
}
else {
@ -147,6 +152,7 @@ public class GuiFactory {
//Normal object
SubCategoryBuilder sc = entryBuilder.startSubCategory(getText(n, "respackopts.title." + screenId));
buildCategory(data, screenId, new JfConfigCategorySub(sc), entryBuilder, n);
sc.setTooltipSupplier(() -> getTooltip(n, screenId));
config.addEntry(sc.build());
}
else {
@ -155,6 +161,17 @@ public class GuiFactory {
}
}
private Optional<Text[]> getTooltip(String key, String screenId) {
String k = "respackopts.tooltip." + screenId + "." + key;
if (Language.getInstance().hasTranslation(k)) {
Text[] res = new Text[1];
res[0] = new TranslatableText(k);
return Optional.of(res);
}
else
return Optional.empty();
}
private boolean isWhole(double v) {
return v == Math.floor(v) && !Double.isInfinite(v);
}