Skip to content

Commit 463deb1

Browse files
committed
A few more gui fixes and tweaks.
1 parent 7f936e8 commit 463deb1

File tree

7 files changed

+98
-20
lines changed

7 files changed

+98
-20
lines changed

Diff for: src/main/java/codechicken/lib/gui/modular/ModularGui.java

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class ModularGui implements GuiParent<ModularGui> {
4545
private boolean closeOnEscape = true;
4646
private boolean renderBackground = true;
4747
private boolean vanillaSlotRendering = false;
48+
private boolean floatingItemDisablesToolTips = true;
4849

4950
private Font font;
5051
private Minecraft mc;
@@ -523,6 +524,17 @@ public void setCursor(ResourceLocation cursor) {
523524
this.newCursor = cursor;
524525
}
525526

527+
/**
528+
* By default, tool tips are disabled while where is a floating item on screen. This can be used to re-enable them.
529+
*/
530+
public void setFloatingItemDisablesToolTips(boolean floatingItemDisablesToolTips) {
531+
this.floatingItemDisablesToolTips = floatingItemDisablesToolTips;
532+
}
533+
534+
public boolean doesFloatingItemDisableToolTips() {
535+
return floatingItemDisablesToolTips;
536+
}
537+
526538
public List<GuiElement<?>> getJeiExclusions() {
527539
return root.addJeiExclusions(new ArrayList<>());
528540
}

Diff for: src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected boolean handleFloatingItemRender(GuiRender render, int mouseX, int mou
105105
}
106106
}
107107
renderFloatingItem(render, stack, mouseX - 8, mouseY - yOffset, countOverride);
108-
ret = true;
108+
ret = modularGui.doesFloatingItemDisableToolTips();
109109
}
110110

111111
if (!this.snapbackItem.isEmpty()) {
@@ -120,7 +120,7 @@ protected boolean handleFloatingItemRender(GuiRender render, int mouseX, int mou
120120
int xPos = snapbackStartX + (int) ((float) xDist * anim);
121121
int yPos = snapbackStartY + (int) ((float) yDist * anim);
122122
renderFloatingItem(render, snapbackItem, xPos + leftPos, yPos + topPos, null);
123-
ret = true;
123+
ret = modularGui.doesFloatingItemDisableToolTips();
124124
}
125125

126126
return ret;

Diff for: src/main/java/codechicken/lib/gui/modular/elements/GuiItemStack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void renderBackground(GuiRender render, double mouseX, double mouseY, flo
109109
@Override
110110
public boolean renderOverlay(GuiRender render, double mouseX, double mouseY, float partialTicks, boolean consumed) {
111111
if (super.renderOverlay(render, mouseX, mouseY, partialTicks, consumed)) return true;
112-
if (isMouseOver() && !stack.get().isEmpty()) {
112+
if (isMouseOver() && !stack.get().isEmpty() && toolTip.get()) {
113113
render.renderTooltip(stack.get(), mouseX, mouseY);
114114
return true;
115115
}

Diff for: src/main/java/codechicken/lib/gui/modular/elements/GuiManipulable.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ public void mouseMoved(double mouseX, double mouseY) {
413413
public boolean mouseReleased(double mouseX, double mouseY, int button, boolean consumed) {
414414
if (isMoving()) {
415415
validatePosition(true);
416+
onMoved(true);
416417
}
417418
if (isResizing()) {
418419
onResized(true);
@@ -438,7 +439,7 @@ protected void onMoved(boolean finished) {
438439

439440
protected void onResized(boolean finished) {
440441
if (onResizedCallback != null) {
441-
onMovedCallback.accept(finished);
442+
onResizedCallback.accept(finished);
442443
}
443444
}
444445

Diff for: src/main/java/codechicken/lib/gui/modular/lib/geometry/Constraint.java

+43-11
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static ConstraintImpl.Relative match(GeoRef relativeTo) {
7878
* Contains a parameter to the given reference plus the provided fixed offset.
7979
*
8080
* @param relativeTo The relative geometry.
81-
* @param offset The offset to apply.
81+
* @param offset The offset to apply.
8282
*/
8383
static ConstraintImpl.Relative relative(GeoRef relativeTo, double offset) {
8484
return new ConstraintImpl.Relative(relativeTo, offset);
@@ -88,7 +88,7 @@ static ConstraintImpl.Relative relative(GeoRef relativeTo, double offset) {
8888
* Contains a parameter to the given reference plus the provided dynamic offset.
8989
*
9090
* @param relativeTo The relative geometry.
91-
* @param offset The dynamic offset to apply.
91+
* @param offset The dynamic offset to apply.
9292
*/
9393
static ConstraintImpl.RelativeDynamic relative(GeoRef relativeTo, Supplier<Double> offset) {
9494
return new ConstraintImpl.RelativeDynamic(relativeTo, offset);
@@ -99,32 +99,64 @@ static ConstraintImpl.RelativeDynamic relative(GeoRef relativeTo, Supplier<Doubl
9999
* Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0.
100100
* To prevent this call .clamp() on the returned constraint.
101101
*
102-
* @param start The Start position.
103-
* @param end The End position.
102+
* @param start The Start position.
103+
* @param end The End position.
104104
* @param position The position between start and end. (0=start to 1=end)
105105
*/
106106
static ConstraintImpl.Between between(GeoRef start, GeoRef end, double position) {
107107
return new ConstraintImpl.Between(start, end, position);
108108
}
109109

110+
/**
111+
* Contains a parameter to a fixed position between the two provided references.
112+
* Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0.
113+
* To prevent this call .clamp() on the returned constraint.
114+
* <p>
115+
* This variant also allows a pixel offset.
116+
*
117+
* @param start The Start position.
118+
* @param end The End position.
119+
* @param position The position between start and end. (0=start to 1=end)
120+
* @param offset position offset in pixels
121+
*/
122+
static ConstraintImpl.BetweenOffset between(GeoRef start, GeoRef end, double position, double offset) {
123+
return new ConstraintImpl.BetweenOffset(start, end, position, offset);
124+
}
125+
110126
/**
111127
* Contains a parameter to a dynamic position between the two provided references.
112128
* Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0.
113129
* To prevent this call .clamp() on the returned constraint.
114130
*
115-
* @param start The Start position.
116-
* @param end The End position.
131+
* @param start The Start position.
132+
* @param end The End position.
117133
* @param position The dynamic position between start and end. (0=start to 1=end)
118134
*/
119135
static ConstraintImpl.BetweenDynamic between(GeoRef start, GeoRef end, Supplier<Double> position) {
120136
return new ConstraintImpl.BetweenDynamic(start, end, position);
121137
}
122138

139+
/**
140+
* Contains a parameter to a dynamic position between the two provided references.
141+
* Note: it is possible to go outside the given range if the given position is greater than 1 or less than 0.
142+
* To prevent this call .clamp() on the returned constraint.
143+
* <p>
144+
* This variant also allows a pixel offset.
145+
*
146+
* @param start The Start position.
147+
* @param end The End position.
148+
* @param position The dynamic position between start and end. (0=start to 1=end)
149+
* @param offset Dynamic position offset in pixels
150+
*/
151+
static ConstraintImpl.BetweenDynamic between(GeoRef start, GeoRef end, Supplier<Double> position, Supplier<Double> offset) {
152+
return new ConstraintImpl.BetweenOffsetDynamic(start, end, position, offset);
153+
}
154+
123155
/**
124156
* Contains a parameter to the mid-point between the two provided references.
125157
*
126158
* @param start The Start position.
127-
* @param end The End position.
159+
* @param end The End position.
128160
*/
129161
static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end) {
130162
return new ConstraintImpl.MidPoint(start, end, 0);
@@ -133,8 +165,8 @@ static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end) {
133165
/**
134166
* Contains a parameter to the mid-point between the two provided references with a fixed offset.
135167
*
136-
* @param start The Start position.
137-
* @param end The End position.
168+
* @param start The Start position.
169+
* @param end The End position.
138170
* @param offset offset distance.
139171
*/
140172
static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end, double offset) {
@@ -144,8 +176,8 @@ static ConstraintImpl.MidPoint midPoint(GeoRef start, GeoRef end, double offset)
144176
/**
145177
* Contains a parameter to the mid-point between the two provided references with a dynamic offset.
146178
*
147-
* @param start The Start position.
148-
* @param end The End position.
179+
* @param start The Start position.
180+
* @param end The End position.
149181
* @param offset offset distance suppler.
150182
*/
151183
static ConstraintImpl.MidPointDynamic midPoint(GeoRef start, GeoRef end, Supplier<Double> offset) {

Diff for: src/main/java/codechicken/lib/gui/modular/lib/geometry/ConstraintImpl.java

+28
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,34 @@ public BetweenDynamic clamp() {
226226
}
227227
}
228228

229+
public static class BetweenOffset extends Between {
230+
private final double offset;
231+
232+
public BetweenOffset(GeoRef start, GeoRef end, double pos, double offset) {
233+
super(start, end, pos);
234+
this.offset = offset;
235+
}
236+
237+
@Override
238+
protected double getImpl() {
239+
return super.getImpl() + offset;
240+
}
241+
}
242+
243+
public static class BetweenOffsetDynamic extends BetweenDynamic {
244+
private final Supplier<Double> offset;
245+
246+
public BetweenOffsetDynamic(GeoRef start, GeoRef end, Supplier<Double> pos, Supplier<Double> offset) {
247+
super(start, end, pos);
248+
this.offset = offset;
249+
}
250+
251+
@Override
252+
protected double getImpl() {
253+
return super.getImpl() + offset.get();
254+
}
255+
}
256+
229257
public static class MidPoint extends ConstraintImpl<MidPoint> {
230258
protected final GeoRef start;
231259
protected final GeoRef end;

Diff for: src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ default boolean intersects(Rectangle other) {
7979
* Returns a new rectangle that represents the intersection area between the two inputs
8080
*/
8181
default Rectangle intersect(Rectangle other) {
82-
double x = Math.max(x(), other.x());
83-
double y = Math.max(y(), other.y());
84-
double width = Math.max(0, Math.min(xMax(), other.xMax()) - x());
85-
double height = Math.max(0, Math.min(yMax(), other.yMax()) - y());
86-
return create(x, y, width, height);
82+
double left = Math.max(x(), other.x());
83+
double right = Math.min(xMax(), other.xMax());
84+
if (right > left) {
85+
double top = Math.max(y(), other.y());
86+
double bottom = Math.min(yMax(), other.yMax());
87+
if (bottom > top) {
88+
return create(left, top, right - left, bottom - top);
89+
}
90+
}
91+
return create(0, 0, 0, 0);
8792
}
8893

8994
/**

0 commit comments

Comments
 (0)