use of com.demod.factorio.FactorioData 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.FactorioData in project Factorio-FBSR by demodude4u.
the class AssemblingMachineRendering method createRenderers.
@Override
public void createRenderers(Consumer<Renderer> register, WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
LuaValue animationLua = prototype.lua().get("idle_animation");
if (animationLua.isnil()) {
animationLua = prototype.lua().get("animation");
}
List<Sprite> sprites = RenderUtils.getSpritesFromAnimation(animationLua, entity.getDirection());
register.accept(RenderUtils.spriteRenderer(sprites, entity, prototype));
Sprite spriteIcon = new Sprite();
String recipe = entity.json().optString("recipe", null);
if (recipe != null) {
Optional<RecipePrototype> optRecipe = dataTable.getRecipe(recipe);
if (optRecipe.isPresent()) {
RecipePrototype protoRecipe = optRecipe.get();
if (!protoRecipe.lua().get("icon").isnil() || !protoRecipe.lua().get("icons").isnil()) {
spriteIcon.image = FactorioData.getIcon(protoRecipe);
} else {
String name;
if (protoRecipe.lua().get("results") != LuaValue.NIL) {
name = protoRecipe.lua().get("results").get(1).get("name").toString();
} else {
name = protoRecipe.lua().get("result").toString();
}
Optional<? extends DataPrototype> protoProduct = dataTable.getItem(name);
if (!protoProduct.isPresent()) {
protoProduct = dataTable.getFluid(name);
}
spriteIcon.image = protoProduct.map(FactorioData::getIcon).orElse(RenderUtils.EMPTY_IMAGE);
}
spriteIcon.source = new Rectangle(0, 0, spriteIcon.image.getWidth(), spriteIcon.image.getHeight());
spriteIcon.bounds = new Rectangle2D.Double(-0.7, -1.0, 1.4, 1.4);
Renderer delegate = RenderUtils.spriteRenderer(spriteIcon, entity, prototype);
register.accept(new Renderer(Layer.OVERLAY2, delegate.getBounds()) {
@Override
public void render(Graphics2D g) throws Exception {
g.setColor(new Color(0, 0, 0, 180));
g.fill(spriteIcon.bounds);
delegate.render(g);
}
});
}
}
}
Aggregations