use of com.demod.factorio.prototype.DataPrototype in project Factorio-FBSR by demodude4u.
the class FBSR method createItemListPanel.
private static PanelRenderer createItemListPanel(DataTable table, String title, Map<String, Double> items) {
final double header = 0.8;
final double spacing = 0.7;
final double iconSize = 0.6;
return new PanelRenderer(3.0, header + items.size() * spacing + 0.2) {
@Override
public void render(Graphics2D g, double width, double height) {
g.setColor(GRID_COLOR);
g.setStroke(GRID_STROKE);
g.draw(new Rectangle2D.Double(0, 0, width, height));
Font font = new Font("Monospaced", Font.BOLD, 1).deriveFont(0.6f);
g.setFont(font);
g.drawString(title, 0.3f, 0.65f);
double startX = 0.6;
double startY = header + spacing / 2.0;
Rectangle2D.Double spriteBox = new Rectangle2D.Double(startX - iconSize / 2.0, startY - iconSize / 2.0, iconSize, iconSize);
Point2D.Double textPos = new Point2D.Double(startX + 0.5, startY + 0.18);
items.entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).forEach(e -> {
String itemName = e.getKey();
double amount = e.getValue();
Optional<BufferedImage> image = Optional.empty();
if (itemName.equals(TotalRawCalculator.RAW_TIME)) {
image = Optional.of(timeIcon);
} else {
Optional<? extends DataPrototype> prototype = table.getItem(itemName);
if (!prototype.isPresent()) {
prototype = table.getFluid(itemName);
}
image = prototype.map(FactorioData::getIcon);
}
image.ifPresent(i -> {
RenderUtils.drawImageInBounds(i, new Rectangle(0, 0, i.getWidth(), i.getHeight()), spriteBox, g);
});
String amountStr;
if (amount < 99999) {
g.setColor(GRID_COLOR);
amountStr = RenderUtils.fmtDouble(Math.ceil(amount));
} else if (amount < 9999999) {
g.setColor(GRID_COLOR.brighter());
amountStr = RenderUtils.fmtDouble(Math.ceil(amount / 1000)) + "k";
} else {
g.setColor(GRID_COLOR.brighter().brighter());
amountStr = RenderUtils.fmtDouble(Math.ceil(amount / 1000000)) + "M";
}
g.setFont(font);
g.drawString(amountStr, (float) textPos.x, (float) textPos.y);
spriteBox.y += spacing;
textPos.y += spacing;
});
}
};
}
use of com.demod.factorio.prototype.DataPrototype in project Factorio-FBSR by demodude4u.
the class FBSR method getItemLogisticColor.
private static Color getItemLogisticColor(DataTable table, String itemName) {
return itemColorCache.computeIfAbsent(itemName, k -> {
Optional<ItemPrototype> optProto = table.getItem(k);
if (!optProto.isPresent()) {
System.err.println("ITEM MISSING FOR LOGISTICS: " + k);
return Color.MAGENTA;
}
DataPrototype prototype = optProto.get();
BufferedImage image = FactorioData.getIcon(prototype);
Color color = RenderUtils.getAverageColor(image);
// return new Color(color.getRGB() | 0xA0A0A0);
// return color.brighter().brighter();
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
return Color.getHSBColor(hsb[0], Math.max(0.25f, hsb[1]), Math.max(0.5f, hsb[2]));
// return Color.getHSBColor(hsb[0], Math.max(1f, hsb[1]),
// Math.max(0.75f, hsb[2]));
});
}
Aggregations