aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/main/java/me/shedaniel')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java86
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java83
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java66
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/RendererWrappedWidget.java72
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/VanillaWrappedWidget.java82
5 files changed, 357 insertions, 32 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java
new file mode 100644
index 000000000..5867f4232
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java
@@ -0,0 +1,86 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.gui.widget;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Matrix4f;
+import com.mojang.math.Vector4f;
+import me.shedaniel.rei.api.client.gui.widgets.DelegateWidget;
+import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
+
+import java.util.function.Supplier;
+
+public class DelegateWidgetWithTranslate extends DelegateWidget {
+ private final Supplier<Matrix4f> translate;
+
+ public DelegateWidgetWithTranslate(WidgetWithBounds widget, Supplier<Matrix4f> translate) {
+ super(widget);
+ this.translate = translate;
+ }
+
+ @Override
+ public void render(PoseStack poseStack, int i, int j, float f) {
+ poseStack.pushPose();
+ poseStack.last().pose().multiply(translate.get());
+ Vector4f mouse = transformMouse(i, j);
+ super.render(poseStack, (int) mouse.x(), (int) mouse.y(), f);
+ poseStack.popPose();
+ }
+
+ private Vector4f transformMouse(double mouseX, double mouseY) {
+ Vector4f mouse = new Vector4f((float) mouseX, (float) mouseY, 0, 1);
+ mouse.transform(translate.get());
+ return mouse;
+ }
+
+ @Override
+ public boolean containsMouse(double mouseX, double mouseY) {
+ Vector4f mouse = transformMouse(mouseX, mouseY);
+ return super.containsMouse(mouse.x(), mouse.y());
+ }
+
+ @Override
+ public boolean mouseClicked(double d, double e, int i) {
+ Vector4f mouse = transformMouse(d, e);
+ return super.mouseClicked(mouse.x(), mouse.y(), i);
+ }
+
+ @Override
+ public boolean mouseReleased(double d, double e, int i) {
+ Vector4f mouse = transformMouse(d, e);
+ return super.mouseReleased(mouse.x(), mouse.y(), i);
+ }
+
+ @Override
+ public boolean mouseDragged(double d, double e, int i, double f, double g) {
+ Vector4f mouse = transformMouse(d, e);
+ return super.mouseDragged(mouse.x(), mouse.y(), i, f, g);
+ }
+
+ @Override
+ public boolean mouseScrolled(double d, double e, double f) {
+ Vector4f mouse = transformMouse(d, e);
+ return super.mouseScrolled(mouse.x(), mouse.y(), f);
+ }
+} \ No newline at end of file
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
index e39b48fc5..f757bf9ad 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java
@@ -23,13 +23,14 @@
package me.shedaniel.rei.impl.client.gui.widget;
-import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.math.Matrix4f;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.gui.DrawableConsumer;
+import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.gui.widgets.*;
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
import me.shedaniel.rei.api.common.display.Display;
@@ -44,12 +45,12 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
+import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
import java.util.Collection;
import java.util.List;
-import java.util.Objects;
import java.util.function.Supplier;
@ApiStatus.Internal
@@ -141,34 +142,8 @@ public final class InternalWidgets {
return new MergedWidget(widget2, widget1);
}
- private static class MergedWidget extends Widget {
- private final List<Widget> widgets;
-
- public MergedWidget(Widget widget1, Widget widget2) {
- this.widgets = Lists.newArrayList(Objects.requireNonNull(widget1), Objects.requireNonNull(widget2));
- }
-
- @Override
- public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
- for (Widget widget : widgets) {
- widget.setZ(getZ());
- widget.render(matrices, mouseX, mouseY, delta);
- }
- }
-
- @Override
- public List<? extends GuiEventListener> children() {
- return widgets;
- }
-
- @Override
- public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
- for (Widget widget : this.widgets) {
- if (widget.mouseScrolled(mouseX, mouseY, amount))
- return true;
- }
- return false;
- }
+ public static Widget concatWidgets(List<Widget> widgets) {
+ return new MergedWidget(widgets);
}
private static class LateRenderableWidget extends DelegateWidget implements LateRenderable {
@@ -188,17 +163,33 @@ public final class InternalWidgets {
}
@Override
+ public Widget wrapVanillaWidget(GuiEventListener element) {
+ if (element instanceof Widget) return (Widget) element;
+ return new VanillaWrappedWidget(element);
+ }
+
+ @Override
+ public WidgetWithBounds wrapRenderer(Supplier<Rectangle> bounds, Renderer renderer) {
+ return new RendererWrappedWidget(renderer, bounds);
+ }
+
+ @Override
+ public WidgetWithBounds withTranslate(WidgetWithBounds widget, Supplier<Matrix4f> translate) {
+ return new DelegateWidgetWithTranslate(widget, translate);
+ }
+
+ @Override
public Widget createDrawableWidget(DrawableConsumer drawable) {
return new DrawableWidget(drawable);
}
@Override
- public me.shedaniel.rei.api.client.gui.widgets.Slot createSlot(Point point) {
+ public Slot createSlot(Point point) {
return new EntryWidget(point);
}
@Override
- public me.shedaniel.rei.api.client.gui.widgets.Slot createSlot(Rectangle bounds) {
+ public Slot createSlot(Rectangle bounds) {
return new EntryWidget(bounds);
}
@@ -236,5 +227,33 @@ public final class InternalWidgets {
public DrawableConsumer createFillRectangleConsumer(Rectangle rectangle, int color) {
return new FillRectangleDrawableConsumer(rectangle, color);
}
+
+ @Override
+ public Widget createShapelessIcon(Point point) {
+ int magnification;
+ double scale = Minecraft.getInstance().getWindow().getGuiScale();
+ if (scale >= 1 && scale <= 4 && scale == Math.floor(scale)) {
+ magnification = (int) scale;
+ } else if (scale > 4 && scale == Math.floor(scale)) {
+ magnification = 1;
+ for (int i = 4; i >= 1; i--) {
+ if (scale % i == 0) {
+ magnification = i;
+ break;
+ }
+ }
+ } else {
+ magnification = 4;
+ }
+ Rectangle bounds = new Rectangle(point.getX() - 9, point.getY() + 1, 8, 8);
+ Widget widget = Widgets.createTexturedWidget(new ResourceLocation("roughlyenoughitems:textures/gui/shapeless_icon_" + magnification + "x.png"), bounds.getX(), bounds.getY(), 0, 0, bounds.getWidth(), bounds.getHeight(), 1, 1, 1, 1);
+ return Widgets.withTooltip(Widgets.withBounds(widget, bounds),
+ new TranslatableComponent("text.rei.shapeless"));
+ }
+
+ @Override
+ public Widget concatWidgets(List<Widget> widgets) {
+ return InternalWidgets.concatWidgets(widgets);
+ }
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java
new file mode 100644
index 000000000..e419a7db7
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java
@@ -0,0 +1,66 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.gui.widget;
+
+import com.google.common.collect.Lists;
+import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.rei.api.client.gui.widgets.Widget;
+import net.minecraft.client.gui.components.events.GuiEventListener;
+
+import java.util.List;
+import java.util.Objects;
+
+public class MergedWidget extends Widget {
+ private final List<Widget> widgets;
+
+ public MergedWidget(Widget widget1, Widget widget2) {
+ this.widgets = Lists.newArrayList(Objects.requireNonNull(widget1), Objects.requireNonNull(widget2));
+ }
+
+ public MergedWidget(List<Widget> widgets) {
+ this.widgets = widgets;
+ }
+
+ @Override
+ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ for (Widget widget : widgets) {
+ widget.setZ(getZ());
+ widget.render(matrices, mouseX, mouseY, delta);
+ }
+ }
+
+ @Override
+ public List<? extends GuiEventListener> children() {
+ return widgets;
+ }
+
+ @Override
+ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
+ for (Widget widget : this.widgets) {
+ if (widget.mouseScrolled(mouseX, mouseY, amount))
+ return true;
+ }
+ return false;
+ }
+} \ No newline at end of file
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/RendererWrappedWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/RendererWrappedWidget.java
new file mode 100644
index 000000000..97d9f3e3d
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/RendererWrappedWidget.java
@@ -0,0 +1,72 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.gui.widget;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.math.Rectangle;
+import me.shedaniel.rei.api.client.gui.Renderer;
+import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
+import net.minecraft.client.gui.components.events.GuiEventListener;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Supplier;
+
+public class RendererWrappedWidget extends WidgetWithBounds {
+ private final Renderer renderer;
+ private final Supplier<Rectangle> bounds;
+
+ public RendererWrappedWidget(Renderer renderer, Supplier<Rectangle> bounds) {
+ this.renderer = Objects.requireNonNull(renderer);
+ this.bounds = Objects.requireNonNull(bounds);
+ }
+
+ @Override
+ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ renderer.render(matrices, getBounds(), mouseX, mouseY, delta);
+ }
+
+ @Override
+ public List<? extends GuiEventListener> children() {
+ if (renderer instanceof GuiEventListener listener)
+ return Collections.singletonList(listener);
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void setZ(int z) {
+ renderer.setZ(z);
+ }
+
+ @Override
+ public int getZ() {
+ return renderer.getZ();
+ }
+
+ @Override
+ public Rectangle getBounds() {
+ return bounds.get();
+ }
+} \ No newline at end of file
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/VanillaWrappedWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/VanillaWrappedWidget.java
new file mode 100644
index 000000000..2aacd5e73
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/VanillaWrappedWidget.java
@@ -0,0 +1,82 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.gui.widget;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.rei.api.client.gui.widgets.Widget;
+import net.minecraft.client.gui.GuiComponent;
+import net.minecraft.client.gui.components.events.ContainerEventHandler;
+import net.minecraft.client.gui.components.events.GuiEventListener;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+public class VanillaWrappedWidget extends Widget {
+ private GuiEventListener element;
+
+ public VanillaWrappedWidget(GuiEventListener element) {
+ this.element = Objects.requireNonNull(element);
+ setFocused(element);
+ }
+
+ @Override
+ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ if (element instanceof GuiComponent component)
+ component.setBlitOffset(getZ());
+ if (element instanceof net.minecraft.client.gui.components.Widget widget)
+ widget.render(matrices, mouseX, mouseY, delta);
+ }
+
+ @Override
+ public List<? extends GuiEventListener> children() {
+ return Collections.singletonList(element);
+ }
+
+ @Nullable
+ @Override
+ public GuiEventListener getFocused() {
+ return element;
+ }
+
+ @Override
+ public void setFocused(@Nullable GuiEventListener guiEventListener) {
+ if (guiEventListener == element) {
+ super.setFocused(element);
+ } else if (element instanceof ContainerEventHandler handler) {
+ handler.setFocused(guiEventListener);
+ }
+ }
+
+ @Override
+ public boolean isDragging() {
+ return true;
+ }
+
+ @Override
+ public boolean containsMouse(double mouseX, double mouseY) {
+ return element.isMouseOver(mouseX, mouseY);
+ }
+} \ No newline at end of file