Skip to content

Commit

Permalink
A few more gui fixes and tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Apr 3, 2024
1 parent 7f936e8 commit 463deb1
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/main/java/codechicken/lib/gui/modular/ModularGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ModularGui implements GuiParent<ModularGui> {
private boolean closeOnEscape = true;
private boolean renderBackground = true;
private boolean vanillaSlotRendering = false;
private boolean floatingItemDisablesToolTips = true;

private Font font;
private Minecraft mc;
Expand Down Expand Up @@ -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<GuiElement<?>> getJeiExclusions() {
return root.addJeiExclusions(new ArrayList<>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -438,7 +439,7 @@ protected void onMoved(boolean finished) {

protected void onResized(boolean finished) {
if (onResizedCallback != null) {
onMovedCallback.accept(finished);
onResizedCallback.accept(finished);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Double> offset) {
return new ConstraintImpl.RelativeDynamic(relativeTo, offset);
Expand All @@ -99,32 +99,64 @@ static ConstraintImpl.RelativeDynamic relative(GeoRef relativeTo, Supplier<Doubl
* 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 position between start and end. (0=start to 1=end)
*/
static ConstraintImpl.Between between(GeoRef start, GeoRef end, double position) {
return new ConstraintImpl.Between(start, end, position);
}

/**
* Contains a parameter to a fixed 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.
* <p>
* 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<Double> 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.
* <p>
* 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<Double> position, Supplier<Double> 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);
Expand All @@ -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) {
Expand All @@ -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<Double> offset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double> offset;

public BetweenOffsetDynamic(GeoRef start, GeoRef end, Supplier<Double> pos, Supplier<Double> offset) {
super(start, end, pos);
this.offset = offset;
}

@Override
protected double getImpl() {
return super.getImpl() + offset.get();
}
}

public static class MidPoint extends ConstraintImpl<MidPoint> {
protected final GeoRef start;
protected final GeoRef end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 463deb1

Please sign in to comment.