Config: allow floats and always display tooltips
This commit is contained in:
parent
ffd9905d40
commit
9065660523
|
@ -45,6 +45,7 @@ public class EntryInfoWidgetBuilder {
|
|||
if (e == null) return;
|
||||
|
||||
if (type == int.class || type == Integer.class) textField(config, info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true);
|
||||
else if (type == float.class || type == Float.class) textField(config, info, Float::parseFloat, DECIMAL_ONLY, e.min(), e.max(),false);
|
||||
else if (type == double.class || type == Double.class) textField(config, info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(),false);
|
||||
else if (type == String.class) textField(config, info, String::length, null, Math.min(e.min(),0), Math.max(e.max(),1),true);
|
||||
else if (type == boolean.class || type == Boolean.class) {
|
||||
|
|
|
@ -27,11 +27,11 @@ public class MidnightConfigListWidget extends ElementListWidget<ButtonEntry> {
|
|||
}
|
||||
@Override
|
||||
public int getRowWidth() { return 10000; }
|
||||
public Optional<ClickableWidget> getHoveredButton(double mouseX, double mouseY) {
|
||||
public Optional<ClickableWidget> getHoveredButton(double mouseY) {
|
||||
for (ButtonEntry buttonEntry : this.children()) {
|
||||
for (ClickableWidget abstractButtonWidget : buttonEntry.buttons) {
|
||||
if (abstractButtonWidget.isMouseOver(mouseX, mouseY)) {
|
||||
return Optional.of(abstractButtonWidget);
|
||||
for (ClickableWidget button : buttonEntry.buttons) {
|
||||
if (button.visible && mouseY >= button.y && mouseY < button.y + itemHeight) {
|
||||
return Optional.of(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,7 @@ import net.minecraft.text.TranslatableText;
|
|||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
@ -113,20 +110,24 @@ public class TinyConfigScreen extends Screen {
|
|||
this.renderBackground(matrices);
|
||||
this.list.render(matrices, mouseX, mouseY, delta);
|
||||
|
||||
//super.render(matrices, mouseX, mouseY, delta);
|
||||
drawCenteredText(matrices, textRenderer, title, width / 2, 15, 0xFFFFFF);
|
||||
|
||||
for (EntryInfo info : config.entries) {
|
||||
if (list.getHoveredButton(mouseX,mouseY).isPresent()) {
|
||||
ClickableWidget buttonWidget = list.getHoveredButton(mouseX,mouseY).get();
|
||||
Optional<ClickableWidget> widget = list.getHoveredButton(mouseY);
|
||||
if (widget.isPresent()) {
|
||||
for (EntryInfo info : config.entries) {
|
||||
ClickableWidget buttonWidget = widget.get();
|
||||
Text text = ButtonEntry.buttonsWithText.get(buttonWidget);
|
||||
TranslatableText name = new TranslatableText(this.translationPrefix + info.field.getName());
|
||||
String key = translationPrefix + info.field.getName() + ".tooltip";
|
||||
|
||||
if (info.error != null && text.equals(name)) renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
|
||||
else if (I18n.hasTranslation(key) && text.equals(name)) {
|
||||
boolean showTooltip = text.equals(name);
|
||||
String tooltipKey = translationPrefix + info.field.getName() + ".tooltip";
|
||||
if (showTooltip && info.error != null) {
|
||||
showTooltip = false;
|
||||
renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
|
||||
}
|
||||
if (showTooltip && I18n.hasTranslation(tooltipKey)) {
|
||||
showTooltip = false;
|
||||
List<Text> list = new ArrayList<>();
|
||||
for (String str : I18n.translate(key).split("\n"))
|
||||
for (String str : I18n.translate(tooltipKey).split("\n"))
|
||||
list.add(new LiteralText(str));
|
||||
renderTooltip(matrices, list, mouseX, mouseY);
|
||||
}
|
||||
|
|
|
@ -8,13 +8,12 @@ public class TestConfig implements JfConfig {
|
|||
@Entry public static boolean disablePacks = false;
|
||||
@Entry public static Boolean disablePacks2 = false;
|
||||
@Entry public static int intTest = 20;
|
||||
@Entry public static double decimalTest = 20;
|
||||
@Entry(min = -6) public static float floatTest = -5;
|
||||
@Entry(max = 21) public static double doubleTest = 20;
|
||||
@Entry public static String dieStr = "lolz";
|
||||
@Entry @GsonHidden
|
||||
public static String guiOnlyStr = "lolz";
|
||||
@Entry @GsonHidden public static String guiOnlyStr = "lolz";
|
||||
public static String gsonOnlyStr = "lolz";
|
||||
@Entry
|
||||
public static Test enumTest = Test.Test;
|
||||
@Entry public static Test enumTest = Test.Test;
|
||||
|
||||
public enum Test {
|
||||
Test, ER
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
"libjf-config-v0-testmod.jfconfig.intTest": "Int Test",
|
||||
"libjf-config-v0-testmod.jfconfig.decimalTest": "Decimal Test",
|
||||
"libjf-config-v0-testmod.jfconfig.dieStr": "String Test",
|
||||
"libjf-config-v0-testmod.jfconfig.gsonOnlyStr.tooltip": "George",
|
||||
"libjf-config-v0-testmod.jfconfig.enumTest": "Enum Test",
|
||||
"libjf-config-v0-testmod.jfconfig.enumTest.tooltip": "Enum Test Tooltip",
|
||||
"libjf-config-v0-testmod.jfconfig.enum.Test.Test": "Test",
|
||||
|
|
Loading…
Reference in New Issue