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.util.ArrayList;
4import java.util.Collections;
5import java.util.Comparator;
6import java.util.LinkedHashMap;
7import java.util.List;
8import java.util.Set;
9
10import java.awt.Color;
11
12import com.fs.starfarer.api.Global;
13import com.fs.starfarer.api.campaign.CargoAPI;
14import com.fs.starfarer.api.campaign.FactionAPI;
15import com.fs.starfarer.api.campaign.SectorEntityToken;
16import com.fs.starfarer.api.campaign.econ.MarketAPI;
17import com.fs.starfarer.api.fleet.FleetMemberAPI;
18import com.fs.starfarer.api.impl.campaign.ids.Factions;
19import com.fs.starfarer.api.impl.campaign.ids.Tags;
20import com.fs.starfarer.api.ui.Alignment;
21import com.fs.starfarer.api.ui.LabelAPI;
22import com.fs.starfarer.api.ui.SectorMapAPI;
23import com.fs.starfarer.api.ui.TooltipMakerAPI;
24import com.fs.starfarer.api.util.CountingMap;
25import com.fs.starfarer.api.util.Misc;
26
28
29 public static class ProductionData {
30 public LinkedHashMap<String, CargoAPI> data = new LinkedHashMap<String, CargoAPI>();
31
32 public CargoAPI getCargo(String name) {
33 CargoAPI cargo = data.get(name);
34 if (cargo == null) {
35 cargo = Global.getFactory().createCargo(true);
37 data.put(name, cargo);
38 }
39 return cargo;
40 }
41 public boolean isEmpty() {
42 for (CargoAPI cargo : data.values()) {
43 if (!cargo.isEmpty()) return false;
44 if (cargo.getMothballedShips() != null && !cargo.getMothballedShips().getMembersListCopy().isEmpty()) return false;
45 }
46 return true;
47 }
48 }
49
51 protected ProductionData data;
52 protected int totalCost;
53 protected int accrued;
54 protected boolean noProductionThisMonth;
55
56
58 this.gatheringPoint = gatheringPoint;
59 this.data = data;
60 this.totalCost = totalCost;
61 this.accrued = accrued;
62 this.noProductionThisMonth = noProductionThisMonth;
63 setDuration(10f);
64 }
65
66
67 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
68
69 Color h = Misc.getHighlightColor();
70 Color g = Misc.getGrayColor();
71 float pad = 3f;
72 float opad = 10f;
73
74 float initPad = pad;
75 if (mode == ListInfoMode.IN_DESC) initPad = opad;
76
77 Color tc = getBulletColorForMode(mode);
78
79 bullet(info);
80
81// if (mode != ListInfoMode.IN_DESC) {
82 if (!data.isEmpty()) {
83 float days = getDaysSincePlayerVisible();
84 if (days < 1) {
85 info.addPara("Items delivered to %s",
86 initPad, tc, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName());
87 initPad = 0f;
88 } else {
89 LabelAPI label = info.addPara("Items delivered to %s %s " + getDaysString(days) + " ago",
90 initPad, tc, getFactionForUIColors().getBaseUIColor(), gatheringPoint.getName(),
91 getDays(days));
92 label.setHighlightColors(getFactionForUIColors().getBaseUIColor(), h);
93 initPad = 0f;
94 }
95 }
96 if (totalCost > 0) {
97 info.addPara("Cost this month: %s", initPad, tc, h, Misc.getDGSCredits(totalCost));
98 }
99// 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
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()) {
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
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
249
250 public String getSmallDescriptionTitle() {
251 return getName();
252 }
253
254 @Override
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
static SettingsAPI getSettings()
Definition Global.java:57
static FactoryAPI getFactory()
Definition Global.java:41
static SectorAPI getSector()
Definition Global.java:65
void addLogTimestamp(TooltipMakerAPI info, Color tc, float opad)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
ProductionReportIntel(MarketAPI gatheringPoint, ProductionData data, int totalCost, int accrued, boolean noProductionThisMonth)
void add(K key, int quantity)
static Color getTextColor()
Definition Misc.java:839
static String getDGSCredits(float num)
Definition Misc.java:1390
static Color getGrayColor()
Definition Misc.java:826
static Color getHighlightColor()
Definition Misc.java:792
CargoAPI createCargo(boolean unlimitedStacks)
String getSpriteName(String category, String id)
void initMothballedShips(String factionId)
List< CargoStackAPI > getStacksCopy()
List< FleetMemberAPI > getMembersListCopy()
void setHighlightColors(Color ... colors)
void addImage(String spriteName, float pad)
void showShips(List< FleetMemberAPI > ships, int max, boolean sort, float pad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
LabelAPI addSectionHeading(String str, Alignment align, float pad)
void showCargo(CargoAPI cargo, int max, boolean sort, float pad)