diff --git a/src/main/java/codechicken/lib/gui/modular/ModularGui.java b/src/main/java/codechicken/lib/gui/modular/ModularGui.java index 242ca4c0..8955970c 100644 --- a/src/main/java/codechicken/lib/gui/modular/ModularGui.java +++ b/src/main/java/codechicken/lib/gui/modular/ModularGui.java @@ -45,6 +45,7 @@ public class ModularGui implements GuiParent { private boolean closeOnEscape = true; private boolean renderBackground = true; private boolean vanillaSlotRendering = false; + private boolean floatingItemDisablesToolTips = true; private Font font; private Minecraft mc; @@ -523,6 +524,17 @@ public void setCursor(ResourceLocation cursor) { this.newCursor = cursor; } + /** + * By default, tool tips are disabled while where is a floating item on screen. This can be used to re-enable them. + */ + public void setFloatingItemDisablesToolTips(boolean floatingItemDisablesToolTips) { + this.floatingItemDisablesToolTips = floatingItemDisablesToolTips; + } + + public boolean doesFloatingItemDisableToolTips() { + return floatingItemDisablesToolTips; + } + public List> getJeiExclusions() { return root.addJeiExclusions(new ArrayList<>()); } diff --git a/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java b/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java index 8e74eba6..f1dbb21b 100644 --- a/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java +++ b/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java @@ -105,7 +105,7 @@ protected boolean handleFloatingItemRender(GuiRender render, int mouseX, int mou } } renderFloatingItem(render, stack, mouseX - 8, mouseY - yOffset, countOverride); - ret = true; + ret = modularGui.doesFloatingItemDisableToolTips(); } if (!this.snapbackItem.isEmpty()) { @@ -120,7 +120,7 @@ protected boolean handleFloatingItemRender(GuiRender render, int mouseX, int mou int xPos = snapbackStartX + (int) ((float) xDist * anim); int yPos = snapbackStartY + (int) ((float) yDist * anim); renderFloatingItem(render, snapbackItem, xPos + leftPos, yPos + topPos, null); - ret = true; + ret = modularGui.doesFloatingItemDisableToolTips(); } return ret; diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java index 099d2c8a..3e074eec 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java @@ -109,7 +109,7 @@ public void renderBackground(GuiRender render, double mouseX, double mouseY, flo @Override public boolean renderOverlay(GuiRender render, double mouseX, double mouseY, float partialTicks, boolean consumed) { if (super.renderOverlay(render, mouseX, mouseY, partialTicks, consumed)) return true; - if (isMouseOver() && !stack.get().isEmpty()) { + if (isMouseOver() && !stack.get().isEmpty() && toolTip.get()) { render.renderTooltip(stack.get(), mouseX, mouseY); return true; } diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java index d85daf4a..239ec6e5 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java @@ -413,6 +413,7 @@ public void mouseMoved(double mouseX, double mouseY) { public boolean mouseReleased(double mouseX, double mouseY, int button, boolean consumed) { if (isMoving()) { validatePosition(true); + onMoved(true); } if (isResizing()) { onResized(true); @@ -438,7 +439,7 @@ protected void onMoved(boolean finished) { protected void onResized(boolean finished) { if (onResizedCallback != null) { - onMovedCallback.accept(finished); + onResizedCallback.accept(finished); } } diff --git a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Constraint.java b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Constraint.java index 63d80344..a3fb6acf 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Constraint.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Constraint.java @@ -78,7 +78,7 @@ static ConstraintImpl.Relative match(GeoRef relativeTo) { * Contains a parameter to the given reference plus the provided fixed offset. * * @param relativeTo The relative geometry. - * @param offset The offset to apply. + * @param offset The offset to apply. */ static ConstraintImpl.Relative relative(GeoRef relativeTo, double offset) { return new ConstraintImpl.Relative(relativeTo, offset); @@ -88,7 +88,7 @@ static ConstraintImpl.Relative relative(GeoRef relativeTo, double offset) { * Contains a parameter to the given reference plus the provided dynamic offset. * * @param relativeTo The relative geometry. - * @param offset The dynamic offset to apply. + * @param offset The dynamic offset to apply. */ static ConstraintImpl.RelativeDynamic relative(GeoRef relativeTo, Supplier offset) { return new ConstraintImpl.RelativeDynamic(relativeTo, offset); @@ -99,32 +99,64 @@ static ConstraintImpl.RelativeDynamic relative(GeoRef relativeTo, Supplier + * This variant also allows a pixel offset. + * + * @param start The Start position. + * @param end The End position. + * @param position The position between start and end. (0=start to 1=end) + * @param offset position offset in pixels + */ + static ConstraintImpl.BetweenOffset between(GeoRef start, GeoRef end, double position, double offset) { + return new ConstraintImpl.BetweenOffset(start, end, position, offset); + } + /** * Contains a parameter to a dynamic position between the two provided references. * Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0. * To prevent this call .clamp() on the returned constraint. * - * @param start The Start position. - * @param end The End position. + * @param start The Start position. + * @param end The End position. * @param position The dynamic position between start and end. (0=start to 1=end) */ static ConstraintImpl.BetweenDynamic between(GeoRef start, GeoRef end, Supplier position) { return new ConstraintImpl.BetweenDynamic(start, end, position); } + /** + * Contains a parameter to a dynamic position between the two provided references. + * Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0. + * To prevent this call .clamp() on the returned constraint. + *

+ * This variant also allows a pixel offset. + * + * @param start The Start position. + * @param end The End position. + * @param position The dynamic position between start and end. (0=start to 1=end) + * @param offset Dynamic position offset in pixels + */ + static ConstraintImpl.BetweenDynamic between(GeoRef start, GeoRef end, Supplier position, Supplier offset) { + return new ConstraintImpl.BetweenOffsetDynamic(start, end, position, offset); + } + /** * Contains a parameter to the mid-point between the two provided references. * * @param start The Start position. - * @param end The End position. + * @param end The End position. */ static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end) { return new ConstraintImpl.MidPoint(start, end, 0); @@ -133,8 +165,8 @@ static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end) { /** * Contains a parameter to the mid-point between the two provided references with a fixed offset. * - * @param start The Start position. - * @param end The End position. + * @param start The Start position. + * @param end The End position. * @param offset offset distance. */ static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end, double offset) { @@ -144,8 +176,8 @@ static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end, double offset) /** * Contains a parameter to the mid-point between the two provided references with a dynamic offset. * - * @param start The Start position. - * @param end The End position. + * @param start The Start position. + * @param end The End position. * @param offset offset distance suppler. */ static ConstraintImpl.MidPointDynamic midPoint(GeoRef start, GeoRef end, Supplier offset) { diff --git a/src/main/java/codechicken/lib/gui/modular/lib/geometry/ConstraintImpl.java b/src/main/java/codechicken/lib/gui/modular/lib/geometry/ConstraintImpl.java index 207fb8ae..258437d0 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/geometry/ConstraintImpl.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/geometry/ConstraintImpl.java @@ -226,6 +226,34 @@ public BetweenDynamic clamp() { } } + public static class BetweenOffset extends Between { + private final double offset; + + public BetweenOffset(GeoRef start, GeoRef end, double pos, double offset) { + super(start, end, pos); + this.offset = offset; + } + + @Override + protected double getImpl() { + return super.getImpl() + offset; + } + } + + public static class BetweenOffsetDynamic extends BetweenDynamic { + private final Supplier offset; + + public BetweenOffsetDynamic(GeoRef start, GeoRef end, Supplier pos, Supplier offset) { + super(start, end, pos); + this.offset = offset; + } + + @Override + protected double getImpl() { + return super.getImpl() + offset.get(); + } + } + public static class MidPoint extends ConstraintImpl { protected final GeoRef start; protected final GeoRef end; diff --git a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java index 4ad613f7..d770073d 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java @@ -79,11 +79,16 @@ default boolean intersects(Rectangle other) { * Returns a new rectangle that represents the intersection area between the two inputs */ default Rectangle intersect(Rectangle other) { - double x = Math.max(x(), other.x()); - double y = Math.max(y(), other.y()); - double width = Math.max(0, Math.min(xMax(), other.xMax()) - x()); - double height = Math.max(0, Math.min(yMax(), other.yMax()) - y()); - return create(x, y, width, height); + double left = Math.max(x(), other.x()); + double right = Math.min(xMax(), other.xMax()); + if (right > left) { + double top = Math.max(y(), other.y()); + double bottom = Math.min(yMax(), other.yMax()); + if (bottom > top) { + return create(left, top, right - left, bottom - top); + } + } + return create(0, 0, 0, 0); } /**