Fractal Softworks Forum

Starsector => Mods => Modding => Topic started by: Originem on December 09, 2018, 01:38:28 AM

Title: TooltipMakerAPI's Basics in Hullmod or Other things
Post by: Originem on December 09, 2018, 01:38:28 AM
Some simple application of TooltipMakerAPI in hullmod coding.
And please modders who learn from this could move the string into strings.json, which could help translation.

(https://my.mixtape.moe/qahlab.png)

Code
    @Override
    public boolean shouldAddDescriptionToTooltip(ShipAPI.HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
        return !isForModSpec;
    }

    @Override
    public void addPostDescriptionSection(TooltipMakerAPI tooltip, ShipAPI.HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
        float pad = 10f;
        tooltip.addSectionHeading("Testing Grid", Alignment.MID, pad);
        int col = 3;
        Color valueColor = new Color(0, 255, 100);
        tooltip.beginGrid((width - pad * 2f) / (col * col), col);
        tooltip.addToGrid(0, 0, "X0", "Y0", valueColor);
        tooltip.addToGrid(1, 0, "X1", "Y0", valueColor);
        tooltip.addToGrid(2, 0, "X2", "Y0", valueColor);
        tooltip.addToGrid(0, 1, "X0", "Y1", valueColor);
        tooltip.addToGrid(1, 1, "X1", "Y1", valueColor);
        tooltip.addToGrid(2, 1, "X2", "Y1", valueColor);
        tooltip.addToGrid(0, 2, "X0", "Y2", valueColor);
        tooltip.addToGrid(1, 2, "X1", "Y2", valueColor);
        tooltip.addToGrid(2, 2, "X2", "Y2", valueColor);
        tooltip.addGrid(pad);

        TooltipMakerAPI text = tooltip.beginImageWithText(Global.getSettings().getCommoditySpec(Commodities.ALPHA_CORE).getIconName(), 36);
        text.addPara("I think it's fu*king COOL!", 0);
        tooltip.addImageWithText(pad);

        text = tooltip.beginImageWithText(Global.getSettings().getCommoditySpec(Commodities.BETA_CORE).getIconName(), 36);
        text.addPara("I think so.", 0);
        tooltip.addImageWithText(pad);

        text = tooltip.beginImageWithText(Global.getSettings().getCommoditySpec(Commodities.GAMMA_CORE).getIconName(), 36);
        text.addPara("NO I HAVE THE OPPOSITE OPINION!!!", 0);
        tooltip.addImageWithText(pad);

        tooltip.addSectionHeading("Then Gamma core turns into...", Alignment.MID, pad);

        CargoAPI debris = Global.getFactory().createCargo(true);
        debris.addCommodity(Commodities.METALS, 40f);
        debris.addCommodity(Commodities.RARE_METALS, 20f);
        debris.addCommodity(Commodities.ORE, 10f);
        debris.addCommodity(Commodities.RARE_ORE, 5f);
        debris.addCommodity(Commodities.HEAVY_MACHINERY, 5f);

        tooltip.showCargo(debris, 6, true, pad);

        tooltip.addPara("...Poor Gamma Core.", pad);
    }