Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocrafting monitor support for tasks #780

Merged
merged 13 commits into from
Jan 26, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: correct scaling for the autocrafting monitor items
Tooltips need to be at 0.7
The default scale should be 0.5
  • Loading branch information
raoulvdberge committed Jan 26, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fc76aaba44ade6ff33eebb2625781e914af81a69
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ public class AutocraftingMonitorScreen extends AbstractBaseScreen<AbstractAutocr
private static final int COLUMNS = 3;
private static final int ITEMS_AREA_HEIGHT = 179;

private static final int ITEM_COLOR = 0xFFDBDBDB;
private static final int PROCESSING_COLOR = 0xFFD9EDF7;
private static final int SCHEDULED_COLOR = 0xFFE8E5CA;
private static final int CRAFTING_COLOR = 0xFFADDBC6;
@@ -225,6 +226,10 @@ private void renderRow(final GuiGraphics graphics,
}
}

private static int getItemColor(final TaskStatus.Item item, final boolean hovering) {
return hovering ? darkenARGB(getItemColor(item), 0.1) : getItemColor(item);
}

private static int getItemColor(final TaskStatus.Item item) {
if (item.processing() > 0) {
return PROCESSING_COLOR;
@@ -235,7 +240,20 @@ private static int getItemColor(final TaskStatus.Item item) {
if (item.crafting() > 0) {
return CRAFTING_COLOR;
}
return 0;
return ITEM_COLOR;
}

private static int darkenARGB(final int argb, final double percentage) {
final int alpha = (argb >> 24) & 0xFF;
int red = (argb >> 16) & 0xFF;
int green = (argb >> 8) & 0xFF;
int blue = argb & 0xFF;

red = (int) Math.max(0, red * (1 - percentage));
green = (int) Math.max(0, green * (1 - percentage));
blue = (int) Math.max(0, blue * (1 - percentage));

return (alpha << 24) | (red << 16) | (green << 8) | blue;
}

private void renderItem(final GuiGraphics graphics,
@@ -244,8 +262,9 @@ private void renderItem(final GuiGraphics graphics,
final TaskStatus.Item item,
final double mouseX,
final double mouseY) {
final int color = getItemColor(item);
if (color != 0) {
final boolean hovering = isHovering(x - leftPos, y - topPos, 73, 29, mouseX, mouseY);
final int color = getItemColor(item, hovering);
if (color != ITEM_COLOR) {
graphics.fill(x, y, x + 73, y + 29, color);
}
if (item.type() != TaskStatus.ItemType.NORMAL) {
@@ -272,7 +291,7 @@ private static void renderItemErrorIcon(final GuiGraphics graphics, final int x,
graphics.blitSprite(
ERROR,
x + 73 - ICON_SIZE - 3,
y + (29 / 2) - (ICON_SIZE / 2),
y + 29 - ICON_SIZE - 3,
ICON_SIZE,
ICON_SIZE
);
@@ -315,7 +334,8 @@ private void renderItemText(final GuiGraphics graphics,
x,
y,
0x404040,
false
false,
SmallText.DEFAULT_SCALE
);
}

Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ protected void renderWidget(final GuiGraphics graphics,
percentageCompletedProvider.getPercentageCompleted(task.id()) * 100
);
SmallText.render(graphics, Minecraft.getInstance().font, percentageCompleted + "%", textX, textY + ySpacing,
0xFFFFFF, true);
0xFFFFFF, true, SmallText.DEFAULT_SCALE);
updateTooltip();
}

Original file line number Diff line number Diff line change
@@ -350,7 +350,8 @@ private void renderCycleDetected(final GuiGraphics graphics, final int y, final
x + 4,
yy,
0xFF5555,
false
false,
SmallText.DEFAULT_SCALE
);
yy += 10;
SmallText.render(
@@ -360,7 +361,8 @@ private void renderCycleDetected(final GuiGraphics graphics, final int y, final
x + 4,
yy,
0x404040,
false
false,
SmallText.DEFAULT_SCALE
);
yy += 10;
for (final ResourceAmount output : preview.outputsOfPatternWithCycle()) {
@@ -376,7 +378,8 @@ private void renderCycleDetected(final GuiGraphics graphics, final int y, final
x + 4 + 16 + 3,
yy + 5,
0x404040,
false
false,
SmallText.DEFAULT_SCALE
);
yy += 18;
}
@@ -388,7 +391,8 @@ private void renderCycleDetected(final GuiGraphics graphics, final int y, final
x + 4,
yy,
0x404040,
false
false,
SmallText.DEFAULT_SCALE
);
}

@@ -400,7 +404,8 @@ private void renderRequestTooLargeToHandle(final GuiGraphics graphics, final int
x + 4,
y + 4,
0xFF5555,
false
false,
SmallText.DEFAULT_SCALE
);
SmallText.render(
graphics,
@@ -409,7 +414,8 @@ private void renderRequestTooLargeToHandle(final GuiGraphics graphics, final int
x + 4,
y + 4 + 10,
0x404040,
false
false,
SmallText.DEFAULT_SCALE
);
}

@@ -507,7 +513,8 @@ private void renderCellText(final GuiGraphics graphics,
x,
y,
0x404040,
false
false,
SmallText.DEFAULT_SCALE
);
}

Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public int getHeight() {

@Override
public int getWidth(final Font font) {
return ICON_SIZE + ICON_MARGIN + (int) (font.width(text) * SmallText.getScale());
return ICON_SIZE + ICON_MARGIN + (int) (font.width(text) * SmallText.TOOLTIP_SCALE);
}

@Override
@@ -68,7 +68,8 @@ public void renderText(final Font font,
y + yOffset,
0x9F7F50,
matrix,
bufferSource
bufferSource,
SmallText.TOOLTIP_SCALE
);
}

Original file line number Diff line number Diff line change
@@ -47,7 +47,8 @@ public int getHeight() {
public int getWidth(final Font font) {
int width = 0;
for (final FormattedCharSequence line : lines) {
final int lineWidth = HELP_ICON_SIZE + HELP_ICON_MARGIN + (int) (font.width(line) * SmallText.getScale());
final float scale = SmallText.correctScale(SmallText.TOOLTIP_SCALE);
final int lineWidth = HELP_ICON_SIZE + HELP_ICON_MARGIN + (int) (font.width(line) * scale);
if (lineWidth > width) {
width = lineWidth;
}
@@ -64,7 +65,7 @@ public void renderText(final Font font,
final int xx = x + HELP_ICON_SIZE + HELP_ICON_MARGIN;
int yy = y + paddingTop;
for (final FormattedCharSequence line : lines) {
SmallText.render(font, line, xx, yy, pose, buffer);
SmallText.render(font, line, xx, yy, pose, buffer, SmallText.TOOLTIP_SCALE);
yy += 9;
}
}
Original file line number Diff line number Diff line change
@@ -8,11 +8,14 @@
import org.joml.Matrix4f;

public final class SmallText {
public static final float DEFAULT_SCALE = 0.5F;
public static final float TOOLTIP_SCALE = 0.7F;

private SmallText() {
}

public static float getScale() {
return isSmall() ? 0.7F : 1F;
public static float correctScale(final float smallScale) {
return isSmall() ? smallScale : 1F;
}

public static boolean isSmall() {
@@ -24,8 +27,9 @@ public static void render(final Font font,
final int x,
final int y,
final Matrix4f pose,
final MultiBufferSource.BufferSource buffer) {
render(font, text, x, y, -1, pose, buffer);
final MultiBufferSource.BufferSource buffer,
final float smallScale) {
render(font, text, x, y, -1, pose, buffer, smallScale);
}

public static void render(final Font font,
@@ -34,8 +38,9 @@ public static void render(final Font font,
final int y,
final int color,
final Matrix4f pose,
final MultiBufferSource.BufferSource buffer) {
final float scale = getScale();
final MultiBufferSource.BufferSource buffer,
final float smallScale) {
final float scale = correctScale(smallScale);
final Matrix4f scaled = new Matrix4f(pose);
scaled.scale(scale, scale, 1);
font.drawInBatch(
@@ -58,8 +63,9 @@ public static void render(final GuiGraphics graphics,
final int x,
final int y,
final int color,
final boolean dropShadow) {
final float scale = getScale();
final boolean dropShadow,
final float smallScale) {
final float scale = correctScale(smallScale);
graphics.pose().pushPose();
graphics.pose().scale(scale, scale, 1);
graphics.drawString(font, text, (int) (x / scale), (int) (y / scale) + 1, color, dropShadow);
@@ -72,8 +78,9 @@ public static void render(final GuiGraphics graphics,
final int x,
final int y,
final int color,
final boolean dropShadow) {
final float scale = getScale();
final boolean dropShadow,
final float smallScale) {
final float scale = correctScale(smallScale);
graphics.pose().pushPose();
graphics.pose().scale(scale, scale, 1);
graphics.drawString(font, text, (int) (x / scale), (int) (y / scale) + 1, color, dropShadow);
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ public void renderText(final Font font,
final int y,
final Matrix4f pose,
final MultiBufferSource.BufferSource buffer) {
SmallText.render(font, text.getVisualOrderText(), x, y, pose, buffer);
SmallText.render(font, text.getVisualOrderText(), x, y, pose, buffer, SmallText.TOOLTIP_SCALE);
}

@Override
@@ -29,6 +29,6 @@ public int getHeight() {

@Override
public int getWidth(final Font font) {
return (int) (font.width(text) * SmallText.getScale());
return (int) (font.width(text) * SmallText.correctScale(SmallText.TOOLTIP_SCALE));
}
}
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public void render(final GuiGraphics graphics, final int x, final int y, final F
state = State.MOVING_LEFT;
stateTicks = 0;
}
final int width = (int) (font.width(text) * (small ? SmallText.getScale() : 1F));
final int width = (int) (font.width(text) * (small ? SmallText.correctScale(SmallText.DEFAULT_SCALE) : 1F));
if (width > maxWidth) {
final int overflow = width - maxWidth;
if (hovering) {
@@ -58,7 +58,8 @@ public void render(final GuiGraphics graphics, final int x, final int y, final F
x + offset,
y,
color,
dropShadow
dropShadow,
SmallText.DEFAULT_SCALE
);
} else {
graphics.drawString(font, text, x + offset, y, color, dropShadow);
@@ -73,7 +74,8 @@ public void render(final GuiGraphics graphics, final int x, final int y, final F
x,
y,
color,
dropShadow
dropShadow,
SmallText.DEFAULT_SCALE
);
} else {
graphics.drawString(font, text, x, y, color, dropShadow);