Search in sources :

Example 1 with DataPrototype

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;
            });
        }
    };
}
Also used : Color(java.awt.Color) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Point2D(java.awt.geom.Point2D) Level(com.demod.dcba.CommandReporting.Level) Rectangle2D(java.awt.geom.Rectangle2D) RenderingHints(java.awt.RenderingHints) DataTable(com.demod.factorio.DataTable) JSONException(org.json.JSONException) RailEdge(com.demod.fbsr.WorldMap.RailEdge) JSONObject(org.json.JSONObject) Ellipse2D(java.awt.geom.Ellipse2D) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) LinkedHashMultiset(com.google.common.collect.LinkedHashMultiset) Shape(java.awt.Shape) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) DataPrototype(com.demod.factorio.prototype.DataPrototype) Collection(java.util.Collection) Set(java.util.Set) AffineTransform(java.awt.geom.AffineTransform) CubicCurve2D(java.awt.geom.CubicCurve2D) ItemPrototype(com.demod.factorio.prototype.ItemPrototype) List(java.util.List) ModInfo(com.demod.factorio.ModInfo) FactorioData(com.demod.factorio.FactorioData) Entry(java.util.Map.Entry) Optional(java.util.Optional) BasicStroke(java.awt.BasicStroke) Queue(java.util.Queue) EntityPrototype(com.demod.factorio.prototype.EntityPrototype) Rectangle(java.awt.Rectangle) Multiset(com.google.common.collect.Multiset) HashMap(java.util.HashMap) RecipePrototype(com.demod.factorio.prototype.RecipePrototype) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RailNode(com.demod.fbsr.WorldMap.RailNode) ImmutableList(com.google.common.collect.ImmutableList) Graphics2D(java.awt.Graphics2D) SimpleEntry(java.util.AbstractMap.SimpleEntry) Layer(com.demod.fbsr.Renderer.Layer) Stroke(java.awt.Stroke) TilePrototype(com.demod.factorio.prototype.TilePrototype) Line2D(java.awt.geom.Line2D) CommandReporting(com.demod.dcba.CommandReporting) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) Consumer(java.util.function.Consumer) Utils(com.demod.factorio.Utils) ArrayDeque(java.util.ArrayDeque) TotalRawCalculator(com.demod.factorio.TotalRawCalculator) Table(com.google.common.collect.Table) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) Font(java.awt.Font) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Point2D(java.awt.geom.Point2D)

Example 2 with DataPrototype

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]));
    });
}
Also used : ItemPrototype(com.demod.factorio.prototype.ItemPrototype) Color(java.awt.Color) DataPrototype(com.demod.factorio.prototype.DataPrototype) BufferedImage(java.awt.image.BufferedImage)

Aggregations

DataPrototype (com.demod.factorio.prototype.DataPrototype)2 ItemPrototype (com.demod.factorio.prototype.ItemPrototype)2 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 CommandReporting (com.demod.dcba.CommandReporting)1 Level (com.demod.dcba.CommandReporting.Level)1 DataTable (com.demod.factorio.DataTable)1 FactorioData (com.demod.factorio.FactorioData)1 ModInfo (com.demod.factorio.ModInfo)1 TotalRawCalculator (com.demod.factorio.TotalRawCalculator)1 Utils (com.demod.factorio.Utils)1 EntityPrototype (com.demod.factorio.prototype.EntityPrototype)1 RecipePrototype (com.demod.factorio.prototype.RecipePrototype)1 TilePrototype (com.demod.factorio.prototype.TilePrototype)1 Layer (com.demod.fbsr.Renderer.Layer)1 RailEdge (com.demod.fbsr.WorldMap.RailEdge)1 RailNode (com.demod.fbsr.WorldMap.RailNode)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMultiset (com.google.common.collect.LinkedHashMultiset)1