DoubleFieldBuilder.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package me.shedaniel.clothconfig2.impl.builders;
  2. import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
  3. import me.shedaniel.clothconfig2.gui.entries.DoubleListEntry;
  4. import java.util.Optional;
  5. import java.util.function.Consumer;
  6. import java.util.function.Supplier;
  7. public class DoubleFieldBuilder extends FieldBuilder<Double> {
  8. private Consumer<Double> saveConsumer = null;
  9. private Supplier<Optional<String[]>> tooltipSupplier = null;
  10. private double value;
  11. private Double min = null, max = null;
  12. public DoubleFieldBuilder(String resetButtonKey, String fieldNameKey, double value) {
  13. super(resetButtonKey, fieldNameKey);
  14. this.value = value;
  15. }
  16. public DoubleFieldBuilder setSaveConsumer(Consumer<Double> saveConsumer) {
  17. this.saveConsumer = saveConsumer;
  18. return this;
  19. }
  20. public DoubleFieldBuilder setDefaultValue(Supplier<Double> defaultValue) {
  21. this.defaultValue = defaultValue;
  22. return this;
  23. }
  24. public DoubleFieldBuilder setMin(double min) {
  25. this.min = min;
  26. return this;
  27. }
  28. public DoubleFieldBuilder setMax(double max) {
  29. this.max = max;
  30. return this;
  31. }
  32. public DoubleFieldBuilder removeMin() {
  33. this.min = null;
  34. return this;
  35. }
  36. public DoubleFieldBuilder removeMax() {
  37. this.max = null;
  38. return this;
  39. }
  40. public DoubleFieldBuilder setTooltipSupplier(Supplier<Optional<String[]>> tooltipSupplier) {
  41. this.tooltipSupplier = tooltipSupplier;
  42. return this;
  43. }
  44. @Override
  45. public AbstractConfigListEntry buildEntry() {
  46. DoubleListEntry entry = new DoubleListEntry(getFieldNameKey(), value, getResetButtonKey(), defaultValue, saveConsumer, tooltipSupplier);
  47. if (min != null)
  48. entry.setMinimum(min);
  49. if (max != null)
  50. entry.setMaximum(max);
  51. return entry;
  52. }
  53. }