Bladeren bron

Close #79

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 4 jaren geleden
bovenliggende
commit
103f1e8b2c

+ 2 - 2
build.gradle

@@ -1,6 +1,6 @@
 plugins {
-    id "architectury-plugin" version "3.0.74"
-    id "forgified-fabric-loom" version "0.6.67" apply false
+    id "architectury-plugin" version "3.0.83"
+    id "forgified-fabric-loom" version "0.6.68" apply false
     id "com.matthewprenger.cursegradle" version "1.4.0" apply false
     id "maven-publish"
     id "org.cadixdev.licenser" version "0.5.0" apply false

+ 1 - 1
common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java

@@ -91,7 +91,7 @@ public class ClothConfigDemo {
         testing.addEntry(entryBuilder.startModifierKeyCodeField(new TextComponent("Cool Modifier Key"), ModifierKeyCode.of(InputConstants.Type.KEYSYM.getOrCreate(79), Modifier.of(false, true, false))).setDefaultValue(ModifierKeyCode.of(InputConstants.Type.KEYSYM.getOrCreate(79), Modifier.of(false, true, false))).build());
         testing.addEntry(entryBuilder.startDoubleList(new TextComponent("A list of Doubles"), Arrays.asList(1d, 2d, 3d)).setDefaultValue(Arrays.asList(1d, 2d, 3d)).build());
         testing.addEntry(entryBuilder.startLongList(new TextComponent("A list of Longs"), Arrays.asList(1L, 2L, 3L)).setDefaultValue(Arrays.asList(1L, 2L, 3L)).build());
-        testing.addEntry(entryBuilder.startStrList(new TextComponent("A list of Strings"), Arrays.asList("abc", "xyz")).setDefaultValue(Arrays.asList("abc", "xyz")).build());
+        testing.addEntry(entryBuilder.startStrList(new TextComponent("A list of Strings"), Arrays.asList("abc", "xyz")).setTooltip(new TextComponent("Yes this is some beautiful tooltip\nOh and this is the second line!")).setDefaultValue(Arrays.asList("abc", "xyz")).build());
         SubCategoryBuilder colors = entryBuilder.startSubCategory(new TextComponent("Colors")).setExpanded(true);
         colors.add(entryBuilder.startColorField(new TextComponent("A color field"), 0x00ffff).setDefaultValue(0x00ffff).build());
         colors.add(entryBuilder.startColorField(new TextComponent("An alpha color field"), 0xff00ffff).setDefaultValue(0xff00ffff).setAlphaMode(true).build());

+ 9 - 2
common/src/main/java/me/shedaniel/clothconfig2/gui/entries/TooltipListEntry.java

@@ -25,16 +25,18 @@ import me.shedaniel.clothconfig2.api.Tooltip;
 import me.shedaniel.math.Point;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
+import net.minecraft.client.Minecraft;
 import net.minecraft.network.chat.Component;
+import net.minecraft.util.FormattedCharSequence;
 import org.jetbrains.annotations.ApiStatus;
 import org.jetbrains.annotations.Nullable;
 
+import java.util.Arrays;
 import java.util.Optional;
 import java.util.function.Supplier;
 
 @Environment(EnvType.CLIENT)
 public abstract class TooltipListEntry<T> extends AbstractConfigListEntry<T> {
-    
     @Nullable private Supplier<Optional<Component[]>> tooltipSupplier;
     
     @ApiStatus.Internal
@@ -56,10 +58,15 @@ public abstract class TooltipListEntry<T> extends AbstractConfigListEntry<T> {
         if (isMouseInside(mouseX, mouseY, x, y, entryWidth, entryHeight)) {
             Optional<Component[]> tooltip = getTooltip(mouseX, mouseY);
             if (tooltip.isPresent() && tooltip.get().length > 0)
-                addTooltip(Tooltip.of(new Point(mouseX, mouseY), tooltip.get()));
+                addTooltip(Tooltip.of(new Point(mouseX, mouseY), postProcessTooltip(tooltip.get())));
         }
     }
     
+    private FormattedCharSequence[] postProcessTooltip(Component[] tooltip) {
+        return Arrays.stream(tooltip).flatMap(component -> Minecraft.getInstance().font.split(component, getConfigScreen().width).stream())
+                .toArray(FormattedCharSequence[]::new);
+    }
+    
     public Optional<Component[]> getTooltip() {
         if (tooltipSupplier != null)
             return tooltipSupplier.get();

+ 1 - 1
gradle.properties

@@ -6,7 +6,7 @@ supported_version=1.16.4/5
 
 archives_base_name=cloth-config
 archives_base_name_snapshot=cloth-config-snapshot
-base_version=4.10
+base_version=4.11
 maven_group=me.shedaniel.cloth
 
 jankson_version=1.2.0