001package com.fs.starfarer.api.impl.campaign.intel.misc; 002 003import java.util.ArrayList; 004import java.util.Collections; 005import java.util.Comparator; 006import java.util.LinkedHashMap; 007import java.util.List; 008import java.util.Set; 009 010import java.awt.Color; 011 012import com.fs.starfarer.api.Global; 013import com.fs.starfarer.api.campaign.CargoAPI; 014import com.fs.starfarer.api.campaign.FactionAPI; 015import com.fs.starfarer.api.campaign.SectorEntityToken; 016import com.fs.starfarer.api.campaign.econ.MarketAPI; 017import com.fs.starfarer.api.fleet.FleetMemberAPI; 018import com.fs.starfarer.api.impl.campaign.ids.Factions; 019import com.fs.starfarer.api.impl.campaign.ids.Tags; 020import com.fs.starfarer.api.ui.Alignment; 021import com.fs.starfarer.api.ui.LabelAPI; 022import com.fs.starfarer.api.ui.SectorMapAPI; 023import com.fs.starfarer.api.ui.TooltipMakerAPI; 024import com.fs.starfarer.api.util.CountingMap; 025import com.fs.starfarer.api.util.Misc; 026 027public class ProductionReportIntel extends FleetLogIntel { 028 029 public static class ProductionData { 030 public LinkedHashMap<String, CargoAPI> data = new LinkedHashMap<String, CargoAPI>(); 031 032 public CargoAPI getCargo(String name) { 033 CargoAPI cargo = data.get(name); 034 if (cargo == null) { 035 cargo = Global.getFactory().createCargo(true); 036 cargo.initMothballedShips(Factions.PLAYER); 037 data.put(name, cargo); 038 } 039 return cargo; 040 } 041 public boolean isEmpty() { 042 for (CargoAPI cargo : data.values()) { 043 if (!cargo.isEmpty()) return false; 044 if (cargo.getMothballedShips() != null && !cargo.getMothballedShips().getMembersListCopy().isEmpty()) return false; 045 } 046 return true; 047 } 048 } 049 050 protected MarketAPI gatheringPoint; 051 protected ProductionData data; 052 protected int totalCost; 053 protected int accrued; 054 protected boolean noProductionThisMonth; 055 056 057 public ProductionReportIntel(MarketAPI gatheringPoint, ProductionData data, int totalCost, int accrued, boolean noProductionThisMonth) { 058 this.gatheringPoint = gatheringPoint; 059 this.data = data; 060 this.totalCost = totalCost; 061 this.accrued = accrued; 062 this.noProductionThisMonth = noProductionThisMonth; 063 setDuration(10f); 064 } 065 066 067 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) { 068 069 Color h = Misc.getHighlightColor(); 070 Color g = Misc.getGrayColor(); 071 float pad = 3f; 072 float opad = 10f; 073 074 float initPad = pad; 075 if (mode == ListInfoMode.IN_DESC) initPad = opad; 076 077 Color tc = getBulletColorForMode(mode); 078 079 bullet(info); 080 081// if (mode != ListInfoMode.IN_DESC) { 082 if (!data.isEmpty()) { 083 float days = getDaysSincePlayerVisible(); 084 if (days < 1) { 085 info.addPara("Items delivered to %s", 086 initPad, tc, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName()); 087 initPad = 0f; 088 } else { 089 LabelAPI label = info.addPara("Items delivered to %s %s " + getDaysString(days) + " ago", 090 initPad, tc, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName(), 091 getDays(days)); 092 label.setHighlightColors(getFactionForUIColors().getBaseUIColor(), h); 093 initPad = 0f; 094 } 095 } 096 if (totalCost > 0) { 097 info.addPara("Cost this month: %s", initPad, tc, h, Misc.getDGSCredits(totalCost)); 098 } 099// if (days >= 1) { 100// addDays(info, "ago", days, tc, initPad); 101// } 102// } else { 103// for (CargoStackAPI stack : cargo.getStacksCopy()) { 104// info.addPara("%s " + Strings.X + " " + stack.getDisplayName(), initPad, tc, h, "" + (int) stack.getSize()); 105// initPad = 0f; 106// } 107// for (FleetMemberAPI member : cargo.getMothballedShips().getMembersListCopy()) { 108// info.addPara(member.getVariant().getFullDesignationWithHullName(), tc, initPad); 109// initPad = 0f; 110// } 111// } 112 113 unindent(info); 114 } 115 116 @Override 117 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) { 118 Color c = getTitleColor(mode); 119 info.addPara(getName(), c, 0f); 120 addBulletPoints(info, mode); 121 } 122 123 @Override 124 public void createSmallDescription(TooltipMakerAPI info, float width, float height) { 125 Color h = Misc.getHighlightColor(); 126 Color g = Misc.getGrayColor(); 127 Color tc = Misc.getTextColor(); 128 float pad = 3f; 129 float small = 3f; 130 float opad = 10f; 131 132 if (data == null) { 133 data = new ProductionData(); 134 } 135 136 info.addImage(getFactionForUIColors().getLogo(), width, 128, opad); 137 138// float days = getDaysSincePlayerVisible(); 139// String daysStr = getDaysString(days); 140// if (days >= 1) { 141// info.addPara("Monthly production completed %s " + daysStr + " ago.", opad, h, getDays(days)); 142// } else { 143 144 if (accrued > 0) { 145 info.addPara("A total of %s worth of production effort has been put into projects that have not yet been " + 146 "completed.", opad, Misc.getHighlightColor(), "" + Misc.getDGSCredits(accrued)); 147 } 148 149 if (noProductionThisMonth) { 150 info.addPara("No production work was done this month due to a lack of funds.", opad); 151 } 152 153 if (!data.isEmpty()) { 154 info.addPara("Production and other resource and ship hull acquisition completed during the last month.", opad); 155 } 156 157// } 158// info.addPara("Monthly production completed.; materiel delivered to %s.", 159// opad, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName()); 160 161 addBulletPoints(info, ListInfoMode.IN_DESC); 162 163 164 List<String> keys = new ArrayList<String>(data.data.keySet()); 165 Collections.sort(keys, new Comparator<String>() { 166 public int compare(String o1, String o2) { 167 return o1.compareTo(o2); 168 } 169 }); 170 171 for (String key : keys) { 172 CargoAPI cargo = data.data.get(key); 173 if (cargo.isEmpty() && 174 ((cargo.getMothballedShips() == null || 175 cargo.getMothballedShips().getMembersListCopy().isEmpty()))) { 176 continue; 177 } 178 179 info.addSectionHeading(key, Alignment.MID, opad); 180 181 float valueWidth = 30; 182 if (!cargo.getStacksCopy().isEmpty()) { 183 info.addPara("Weapons, supplies, and other cargo:", opad); 184 185 info.showCargo(cargo, 20, true, opad); 186 187// info.beginGridFlipped(width, 1, valueWidth, opad); 188// int j = 0; 189// for (CargoStackAPI stack : cargo.getStacksCopy()) { 190// String name = info.shortenString(stack.getDisplayName(), width - valueWidth - opad); 191// info.addToGrid(0, j++, name, "" + (int) stack.getSize()); 192// } 193// info.addGrid(small); 194 } 195 if (!cargo.getMothballedShips().getMembersListCopy().isEmpty()) { 196 CountingMap<String> counts = new CountingMap<String>(); 197 for (FleetMemberAPI member : cargo.getMothballedShips().getMembersListCopy()) { 198 //counts.add(member.getVariant().getFullDesignationWithHullName()); 199 counts.add(member.getVariant().getHullSpec().getHullName() + " " + member.getVariant().getDesignation()); 200 } 201 202 info.addPara("Ship hulls with basic armaments:", opad); 203 204 info.showShips(cargo.getMothballedShips().getMembersListCopy(), 20, true, opad); 205 206// info.beginGridFlipped(width, 1, valueWidth, opad); 207// int j = 0; 208// for (String hull : counts.keySet()) { 209// String name = info.shortenString(hull, width - valueWidth - opad); 210// info.addToGrid(0, j++, name, "" + (int) counts.getCount(hull)); 211// } 212// info.addGrid(small); 213 } 214 215 // in case some of the ships shown are in the player's fleet; the above may cause them to briefly get 216 // set to zero CR 217 Global.getSector().getPlayerFleet().getFleetData().setSyncNeeded(); 218 Global.getSector().getPlayerFleet().getFleetData().syncIfNeeded(); 219 } 220 221 addLogTimestamp(info, tc, opad); 222 } 223 224 @Override 225 public String getIcon() { 226 return Global.getSettings().getSpriteName("intel", "production_report"); 227 } 228 229 @Override 230 public Set<String> getIntelTags(SectorMapAPI map) { 231 Set<String> tags = super.getIntelTags(map); 232 tags.add(Tags.INTEL_PRODUCTION); 233 return tags; 234 } 235 236 public String getSortString() { 237 //return "Production"; 238 return super.getSortString(); 239 } 240 241 public String getName() { 242 return "Production Report"; 243 } 244 245 @Override 246 public FactionAPI getFactionForUIColors() { 247 return Global.getSector().getPlayerFaction(); 248 } 249 250 public String getSmallDescriptionTitle() { 251 return getName(); 252 } 253 254 @Override 255 public SectorEntityToken getMapLocation(SectorMapAPI map) { 256 return gatheringPoint.getPrimaryEntity(); 257 } 258 259 @Override 260 public boolean shouldRemoveIntel() { 261 if (isImportant()) return false; 262 if (getDaysSincePlayerVisible() < 30) return false; 263 return super.shouldRemoveIntel(); 264 } 265 266 267} 268 269