aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java87
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreview.java19
3 files changed, 81 insertions, 27 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java
index 216fb6499..89bd772e3 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java
@@ -94,7 +94,7 @@ public class REIConfigScreen extends Screen {
Minecraft.getInstance().setScreen(new CreditsScreen(this));
}));
this.widgets.add(Widgets.createLabel(new Point(width / 2, 12), this.title));
- int sideWidth = (int) (width / 3.8);
+ int sideWidth = (int) (width / 4.2);
boolean singlePane = width - 20 - sideWidth <= 330;
int singleSideWidth = 32 + 6 + 4;
Widget[] list = {ConfigEntriesListWidget.create(new Rectangle(singlePane ? 8 + singleSideWidth : 12 + sideWidth, 32, singlePane ? width - 16 - singleSideWidth : width - 20 - sideWidth, height - 32 - 32), activeCategory.getGroups())};
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java
index 60757720e..e23924ac7 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java
@@ -35,37 +35,71 @@ import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption;
import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup;
import me.shedaniel.rei.impl.client.gui.config.options.preview.TooltipPreview;
import net.minecraft.client.gui.GuiComponent;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
+import org.jetbrains.annotations.Nullable;
-import java.util.AbstractList;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.function.IntSupplier;
import java.util.function.Supplier;
public class ConfigGroupWidget {
+ private static final Map<OptionGroup, Pair<PreviewLocation, SpecialGroupConstructor>> SPECIAL_GROUPS = new HashMap<>();
+
+ static {
+ addPreview(AllREIConfigGroups.APPEARANCE_TOOLTIPS, PreviewLocation.RIGHT, (entry, width, height) -> TooltipPreview.create(width, height));
+ }
+
+ public static void addPreview(OptionGroup group, PreviewLocation location, SpecialGroupConstructor constructor) {
+ SPECIAL_GROUPS.put(group, Pair.of(location, constructor));
+ }
+
public static WidgetWithBounds create(OptionGroup entry, int width) {
- if (entry == AllREIConfigGroups.APPEARANCE_TOOLTIPS) {
+ WidgetWithBounds groupTitle = Widgets.createLabel(new Point(0, 3), entry.getGroupName().copy().withStyle(style -> style.withColor(0xFFC0C0C0).withUnderlined(true)))
+ .leftAligned()
+ .withPadding(0, 0, 0, 6);
+ WidgetWithBounds contents;
+
+ if (SPECIAL_GROUPS.containsKey(entry)) {
+ Pair<PreviewLocation, SpecialGroupConstructor> pair = SPECIAL_GROUPS.get(entry);
+ PreviewLocation location = pair.getLeft();
int halfWidth = width * 6 / 10 - 2;
- WidgetWithBounds left = _create(entry, halfWidth);
- Widget background = Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
- GuiComponent.fill(matrices, 0, 0, width - halfWidth - 4, left.getBounds().height, 0xFF333333);
- GuiComponent.fill(matrices, 1, 1, width - halfWidth - 4 - 1, left.getBounds().height - 1, 0xFF000000);
- });
- Widget right = Widgets.withTranslate(TooltipPreview.create(() -> width - halfWidth - 4, () -> left.getBounds().height), halfWidth + 2, 0, 0);
- return Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, left.getBounds().height), left, background, right);
+ if (halfWidth <= 200) location = PreviewLocation.TOP;
+
+ if (location == PreviewLocation.RIGHT) {
+ WidgetWithBounds original = _create(entry, halfWidth);
+ Widget background = createBackgroundSlot(() -> new Rectangle(halfWidth + 2, 0, width - halfWidth - 4, original.getBounds().height));
+ Widget right = Widgets.withTranslate(pair.getRight().create(entry, () -> width - halfWidth - 4, () -> original.getBounds().height), halfWidth + 2, 0, 0);
+ contents = Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, original.getBounds().height), original, background, right);
+ } else {
+ WidgetWithBounds original = _create(entry, width);
+
+ if (location == PreviewLocation.TOP) {
+ WidgetWithBounds widget = pair.getRight().create(entry, () -> width, null);
+ Widget background = createBackgroundSlot(widget::getBounds);
+ WidgetWithBounds translatedOriginal = Widgets.withTranslate(original, () -> Matrix4f.createTranslateMatrix(0, widget.getBounds().height + 4, 0));
+ contents = Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, widget.getBounds().height + 4 + translatedOriginal.getBounds().height), translatedOriginal, background, widget);
+ } else {
+ WidgetWithBounds widget = pair.getRight().create(entry, () -> width, null);
+ Widget background = createBackgroundSlot(widget::getBounds);
+ contents = Widgets.concatWithBounds(() -> new Rectangle(0, 0, width, original.getBounds().getMaxY() + 4 + widget.getBounds().height), original,
+ Widgets.withTranslate(Widgets.concat(background, widget), () -> Matrix4f.createTranslateMatrix(0, original.getBounds().getMaxY() + 4, 0)));
+ }
+ }
+ } else {
+ contents = _create(entry, width);
}
- return _create(entry, width);
+ return Widgets.concatWithBounds(
+ () -> new Rectangle(0, 0, width, groupTitle.getBounds().getMaxY() + contents.getBounds().height),
+ groupTitle,
+ Widgets.withTranslate(contents, () -> Matrix4f.createTranslateMatrix(0, groupTitle.getBounds().getMaxY(), 0))
+ );
}
private static WidgetWithBounds _create(OptionGroup entry, int width) {
List<Triple<Widget, Supplier<Rectangle>, Matrix4f[]>> widgets = new ArrayList<>();
int[] height = {0};
- WidgetWithBounds groupTitle = Widgets.createLabel(new Point(0, 3), entry.getGroupName().copy().withStyle(style -> style.withColor(0xFFC0C0C0).withUnderlined(true)))
- .leftAligned()
- .withPadding(0, 0, 0, 6);
- widgets.add(Triple.of(groupTitle, groupTitle::getBounds, new Matrix4f[]{new Matrix4f()}));
- height[0] = Math.max(height[0], groupTitle.getBounds().getMaxY());
for (CompositeOption<?> option : entry.getOptions()) {
Matrix4f[] translation = new Matrix4f[]{Matrix4f.createTranslateMatrix(0, height[0], 0)};
@@ -77,7 +111,7 @@ public class ConfigGroupWidget {
Matrix4f[] translationDrawable = new Matrix4f[]{Matrix4f.createTranslateMatrix(0, height[0], 0)};
widgets.add(Triple.of(Widgets.withTranslate(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
for (int x = 0; x <= width; x += 4) {
- GuiComponent.fill(matrices, x, 1, x + 2, 2, 0xFF757575);
+ GuiComponent.fill(matrices, Math.min(width, x), 1, Math.min(width, x + 2), 2, 0xFF757575);
}
}), () -> translationDrawable[0]), () ->
MatrixUtils.transform(translationDrawable[0], new Rectangle(0, 0, 1, 7)), translationDrawable));
@@ -106,4 +140,21 @@ public class ConfigGroupWidget {
}
});
}
+
+ @FunctionalInterface
+ public interface SpecialGroupConstructor {
+ WidgetWithBounds create(OptionGroup entry, IntSupplier width, @Nullable IntSupplier height);
+ }
+
+ public enum PreviewLocation {
+ RIGHT, TOP, BOTTOM
+ }
+
+ private static Widget createBackgroundSlot(Supplier<Rectangle> bounds) {
+ return Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
+ Rectangle rectangle = bounds.get();
+ GuiComponent.fill(matrices, rectangle.x, rectangle.y, rectangle.getMaxX(), rectangle.getMaxY(), 0xFF333333);
+ GuiComponent.fill(matrices, rectangle.x + 1, rectangle.y + 1, rectangle.getMaxX() - 1, rectangle.getMaxY() - 1, 0xFF000000);
+ });
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreview.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreview.java
index 06846a1d8..b55ba666b 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreview.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreview.java
@@ -29,7 +29,7 @@ import com.mojang.math.Matrix4f;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
-import me.shedaniel.rei.api.client.gui.widgets.Widget;
+import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;
@@ -45,14 +45,16 @@ import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.IntSupplier;
import java.util.stream.Stream;
public class TooltipPreview {
- public static Widget create(IntSupplier width, IntSupplier height) {
- return Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
+ public static WidgetWithBounds create(IntSupplier width, @Nullable IntSupplier height) {
+ Rectangle bounds = new Rectangle();
+ return Widgets.withBounds(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
EntryStack<ItemStack> stack = EntryStacks.of(Items.OAK_PLANKS);
boolean appendModNames = (Boolean) ((REIConfigScreen) Minecraft.getInstance().screen).getOptions().get(AllREIConfigOptions.APPEND_MOD_NAMES);
boolean appendFavorites = (Boolean) ((REIConfigScreen) Minecraft.getInstance().screen).getOptions().get(AllREIConfigOptions.APPEND_FAVORITES_HINT);
@@ -66,13 +68,14 @@ public class TooltipPreview {
entries.addAll(Stream.of(I18n.get("text.rei.favorites_tooltip", name).split("\n"))
.map(TextComponent::new).map(Tooltip::entry).toList());
}
- List<FormattedCharSequence> components = entries.stream().flatMap(entry -> Minecraft.getInstance().font.split(entry.getAsText(), width.getAsInt() - 8 - 4).stream()).toList();
+ List<FormattedCharSequence> components = entries.stream().flatMap(entry -> Minecraft.getInstance().font.split(entry.getAsText(), width.getAsInt() - 12 - 4).stream()).toList();
int minWidth = components.stream().mapToInt(component -> Minecraft.getInstance().font.width(component)).max().orElse(0) + 4;
- int minHeight = components.stream().mapToInt(component -> components.get(0) == component ? 2 + 10 : 10).sum() + 4;
+ int minHeight = components.stream().mapToInt(component -> components.get(0) == component && components.size() >= 2 ? 2 + 10 : 10).sum() + 4;
- int tX = Math.max(4, (width.getAsInt() - minWidth) / 2), tWidth = Math.min(width.getAsInt() - 8, minWidth), tY = 24 + 4, tHeight = Math.min(minHeight, height.getAsInt() - tY - 4);
+ int tX = Math.max(6, (width.getAsInt() - minWidth) / 2), tWidth = Math.min(width.getAsInt() - 12, minWidth), tY = 24 + 4, tHeight = Math.min(minHeight, height == null ? 100000 : height.getAsInt() - tY - 4);
matrices.pushPose();
- matrices.translate(0, Math.max(0, (height.getAsInt() - (tY + tHeight)) / 2), 400);
+ matrices.translate(0, height == null ? 4 : Math.max(0, (height.getAsInt() - (tY + tHeight)) / 2), 400);
+ bounds.setBounds(0, 0, width.getAsInt(), height == null ? tY + tHeight + 12 : height.getAsInt());
stack.getRenderer().render(stack, matrices, new Rectangle(width.getAsInt() / 2 - 12, 0, 24, 24), mouseX, mouseY, delta);
matrices.translate(0, 0, -400);
@@ -107,7 +110,7 @@ public class TooltipPreview {
}
matrices.popPose();
- });
+ }), bounds);
}
private static void fillGradient(Matrix4f pose, BufferBuilder builder, int x1, int y1, int x2, int y2, int blitOffset, int color1, int color2) {