Starsector API
Loading...
Searching...
No Matches
ProductionReportIntel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.misc;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.Comparator;
7import java.util.LinkedHashMap;
8import java.util.List;
9import java.util.Set;
10
11import com.fs.starfarer.api.Global;
12import com.fs.starfarer.api.campaign.CargoAPI;
13import com.fs.starfarer.api.campaign.FactionAPI;
14import com.fs.starfarer.api.campaign.SectorEntityToken;
15import com.fs.starfarer.api.campaign.econ.MarketAPI;
16import com.fs.starfarer.api.fleet.FleetMemberAPI;
17import com.fs.starfarer.api.impl.campaign.ids.Factions;
18import com.fs.starfarer.api.impl.campaign.ids.Tags;
19import com.fs.starfarer.api.ui.Alignment;
20import com.fs.starfarer.api.ui.LabelAPI;
21import com.fs.starfarer.api.ui.SectorMapAPI;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.CountingMap;
24import com.fs.starfarer.api.util.Misc;
25
27
28 public static class ProductionData {
29 public LinkedHashMap<String, CargoAPI> data = new LinkedHashMap<String, CargoAPI>();
30
31 public CargoAPI getCargo(String name) {
32 CargoAPI cargo = data.get(name);
33 if (cargo == null) {
34 cargo = Global.getFactory().createCargo(true);
35 cargo.initMothballedShips(Factions.PLAYER);
36 data.put(name, cargo);
37 }
38 return cargo;
39 }
40 public boolean isEmpty() {
41 for (CargoAPI cargo : data.values()) {
42 if (!cargo.isEmpty()) return false;
43 if (cargo.getMothballedShips() != null && !cargo.getMothballedShips().getMembersListCopy().isEmpty()) return false;
44 }
45 return true;
46 }
47 }
48
49 protected MarketAPI gatheringPoint;
50 protected ProductionData data;
51 protected int totalCost;
52 protected int accrued;
53 protected boolean noProductionThisMonth;
54
55
56 public ProductionReportIntel(MarketAPI gatheringPoint, ProductionData data, int totalCost, int accrued, boolean noProductionThisMonth) {
57 this.gatheringPoint = gatheringPoint;
58 this.data = data;
59 this.totalCost = totalCost;
60 this.accrued = accrued;
61 this.noProductionThisMonth = noProductionThisMonth;
62 setDuration(10f);
63 }
64
65
66 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
67
68 Color h = Misc.getHighlightColor();
69 Color g = Misc.getGrayColor();
70 float pad = 3f;
71 float opad = 10f;
72
73 float initPad = pad;
74 if (mode == ListInfoMode.IN_DESC) initPad = opad;
75
76 Color tc = getBulletColorForMode(mode);
77
78 bullet(info);
79
80// if (mode != ListInfoMode.IN_DESC) {
81 if (!data.isEmpty()) {
82 float days = getDaysSincePlayerVisible();
83 if (days < 1) {
84 info.addPara("Items delivered to %s",
85 initPad, tc, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName());
86 initPad = 0f;
87 } else {
88 LabelAPI label = info.addPara("Items delivered to %s %s " + getDaysString(days) + " ago",
89 initPad, tc, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName(),
90 getDays(days));
91 label.setHighlightColors(getFactionForUIColors().getBaseUIColor(), h);
92 initPad = 0f;
93 }
94 }
95 if (totalCost > 0) {
96 info.addPara("Cost this month: %s", initPad, tc, h, Misc.getDGSCredits(totalCost));
97 }
98// if (days >= 1) {
99// addDays(info, "ago", days, tc, initPad);
100// }
101// } else {
102// for (CargoStackAPI stack : cargo.getStacksCopy()) {
103// info.addPara("%s " + Strings.X + " " + stack.getDisplayName(), initPad, tc, h, "" + (int) stack.getSize());
104// initPad = 0f;
105// }
106// for (FleetMemberAPI member : cargo.getMothballedShips().getMembersListCopy()) {
107// info.addPara(member.getVariant().getFullDesignationWithHullName(), tc, initPad);
108// initPad = 0f;
109// }
110// }
111
112 unindent(info);
113 }
114
115 @Override
116 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
117 Color c = getTitleColor(mode);
118 info.addPara(getName(), c, 0f);
119 addBulletPoints(info, mode);
120 }
121
122 @Override
123 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
124 Color h = Misc.getHighlightColor();
125 Color g = Misc.getGrayColor();
126 Color tc = Misc.getTextColor();
127 float pad = 3f;
128 float small = 3f;
129 float opad = 10f;
130
131 if (data == null) {
132 data = new ProductionData();
133 }
134
135 info.addImage(getFactionForUIColors().getLogo(), width, 128, opad);
136
137// float days = getDaysSincePlayerVisible();
138// String daysStr = getDaysString(days);
139// if (days >= 1) {
140// info.addPara("Monthly production completed %s " + daysStr + " ago.", opad, h, getDays(days));
141// } else {
142
143 if (accrued > 0) {
144 info.addPara("A total of %s worth of production effort has been put into projects that have not yet been " +
145 "completed.", opad, Misc.getHighlightColor(), "" + Misc.getDGSCredits(accrued));
146 }
147
149 info.addPara("No production work was done this month due to a lack of funds.", opad);
150 }
151
152 if (!data.isEmpty()) {
153 info.addPara("Production and other resource and ship hull acquisition completed during the last month.", opad);
154 }
155
156// }
157// info.addPara("Monthly production completed.; materiel delivered to %s.",
158// opad, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName());
159
160 addBulletPoints(info, ListInfoMode.IN_DESC);
161
162
163 List<String> keys = new ArrayList<String>(data.data.keySet());
164 Collections.sort(keys, new Comparator<String>() {
165 public int compare(String o1, String o2) {
166 return o1.compareTo(o2);
167 }
168 });
169
170 for (String key : keys) {
171 CargoAPI cargo = data.data.get(key);
172 if (cargo.isEmpty() &&
173 ((cargo.getMothballedShips() == null ||
174 cargo.getMothballedShips().getMembersListCopy().isEmpty()))) {
175 continue;
176 }
177
178 info.addSectionHeading(key, Alignment.MID, opad);
179
180 float valueWidth = 30;
181 if (!cargo.getStacksCopy().isEmpty()) {
182 info.addPara("Weapons, supplies, and other cargo:", opad);
183
184 info.showCargo(cargo, 20, true, opad);
185
186// info.beginGridFlipped(width, 1, valueWidth, opad);
187// int j = 0;
188// for (CargoStackAPI stack : cargo.getStacksCopy()) {
189// String name = info.shortenString(stack.getDisplayName(), width - valueWidth - opad);
190// info.addToGrid(0, j++, name, "" + (int) stack.getSize());
191// }
192// info.addGrid(small);
193 }
194 if (!cargo.getMothballedShips().getMembersListCopy().isEmpty()) {
195 CountingMap<String> counts = new CountingMap<String>();
196 for (FleetMemberAPI member : cargo.getMothballedShips().getMembersListCopy()) {
197 //counts.add(member.getVariant().getFullDesignationWithHullName());
198 counts.add(member.getVariant().getHullSpec().getHullName() + " " + member.getVariant().getDesignation());
199 }
200
201 info.addPara("Ship hulls with basic armaments:", opad);
202
203 info.showShips(cargo.getMothballedShips().getMembersListCopy(), 20, true, opad);
204
205// info.beginGridFlipped(width, 1, valueWidth, opad);
206// int j = 0;
207// for (String hull : counts.keySet()) {
208// String name = info.shortenString(hull, width - valueWidth - opad);
209// info.addToGrid(0, j++, name, "" + (int) counts.getCount(hull));
210// }
211// info.addGrid(small);
212 }
213
214 // in case some of the ships shown are in the player's fleet; the above may cause them to briefly get
215 // set to zero CR
216 Global.getSector().getPlayerFleet().getFleetData().setSyncNeeded();
217 Global.getSector().getPlayerFleet().getFleetData().syncIfNeeded();
218 }
219
220 }
221
222 @Override
223 public String getIcon() {
224 return Global.getSettings().getSpriteName("intel", "production_report");
225 }
226
227 @Override
228 public Set<String> getIntelTags(SectorMapAPI map) {
229 Set<String> tags = super.getIntelTags(map);
230 tags.add(Tags.INTEL_PRODUCTION);
231 return tags;
232 }
233
234 public String getSortString() {
235 return "Production";
236 }
237
238 public String getName() {
239 return "Production Report";
240 }
241
242 @Override
243 public FactionAPI getFactionForUIColors() {
244 return Global.getSector().getPlayerFaction();
245 }
246
247 public String getSmallDescriptionTitle() {
248 return getName();
249 }
250
251 @Override
252 public SectorEntityToken getMapLocation(SectorMapAPI map) {
253 return gatheringPoint.getPrimaryEntity();
254 }
255
256 @Override
257 public boolean shouldRemoveIntel() {
258 if (isImportant()) return false;
259 if (getDaysSincePlayerVisible() < 30) return false;
260 return super.shouldRemoveIntel();
261 }
262
263
264}
265
266
static SettingsAPI getSettings()
Definition Global.java:51
static FactoryAPI getFactory()
Definition Global.java:35
static SectorAPI getSector()
Definition Global.java:59
void createSmallDescription(TooltipMakerAPI info, float width, float height)
ProductionReportIntel(MarketAPI gatheringPoint, ProductionData data, int totalCost, int accrued, boolean noProductionThisMonth)
CargoAPI createCargo(boolean unlimitedStacks)
String getSpriteName(String category, String id)