Starsector API
Loading...
Searching...
No Matches
BaseSpecialItemPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.campaign.impl.items;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Random;
6
7import java.awt.Color;
8
9import org.json.JSONException;
10
11import com.fs.starfarer.api.Global;
12import com.fs.starfarer.api.campaign.CargoStackAPI;
13import com.fs.starfarer.api.campaign.CargoTransferHandlerAPI;
14import com.fs.starfarer.api.campaign.SpecialItemPlugin;
15import com.fs.starfarer.api.campaign.SpecialItemSpecAPI;
16import com.fs.starfarer.api.campaign.SubmarketPlugin.TransferAction;
17import com.fs.starfarer.api.campaign.econ.MarketAPI;
18import com.fs.starfarer.api.campaign.econ.SubmarketAPI;
19import com.fs.starfarer.api.combat.ShipHullSpecAPI;
20import com.fs.starfarer.api.impl.campaign.ids.Tags;
21import com.fs.starfarer.api.loading.FighterWingSpecAPI;
22import com.fs.starfarer.api.loading.WeaponSpecAPI;
23import com.fs.starfarer.api.ui.LabelAPI;
24import com.fs.starfarer.api.ui.TooltipMakerAPI;
25import com.fs.starfarer.api.util.Highlights;
26import com.fs.starfarer.api.util.Misc;
27
29
32 protected String itemId;
33
34
35 public String getId() {
36 return itemId;
37 }
38 public void setId(String id) {
39 this.itemId = id;
41 }
42 public void init(CargoStackAPI stack) {
43 this.stack = stack;
44 }
45
46 @Override
47 public void performRightClickAction(RightClickActionHelper helper) {
49 }
51
52 }
53
54 public boolean hasRightClickAction() {
55 return false;
56 }
57
59 return true;
60 }
61
62
63 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource) {
64 boolean useGray = true;
65 if (getClass() == BaseSpecialItemPlugin.class || Global.CODEX_TOOLTIP_MODE) {
66 useGray = false;
67 }
68 createTooltip(tooltip, expanded, transferHandler, stackSource, useGray);
69 }
70 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource, boolean useGray) {
71 float opad = 10f;
72
74 tooltip.addTitle(getName());
75 } else {
76 tooltip.addSpacer(-opad);
77 }
78
79 String design = getDesignType();
80 Misc.addDesignTypePara(tooltip, design, opad);
81
83 tooltip.setParaSmallInsignia();
84 }
85 if (!spec.getDesc().isEmpty()) {
86 Color c = Misc.getTextColor();
87 if (useGray) c = Misc.getGrayColor();
88 tooltip.addPara(spec.getDesc(), c, opad);
89 }
90
91 if (getClass() == BaseSpecialItemPlugin.class) {
92 addCostLabel(tooltip, opad, transferHandler, stackSource);
93 }
94 }
95
96 public float getTooltipWidth() {
97 return 450;
98 }
99
100 public boolean isTooltipExpandable() {
101 return false;
102 }
103
104 public String getName() {
105 return spec.getName();
106 }
107
108 public int getPrice(MarketAPI market, SubmarketAPI submarket) {
109 if (spec != null) return (int) spec.getBasePrice();
110 return 0;
111 }
112
113 protected float getItemPriceMult() {
114 return Global.getSettings().getFloat("blueprintPriceOriginalItemMult");
115 }
116
117 public void render(float x, float y, float w, float h, float alphaMult, float glowMult, SpecialItemRendererAPI renderer) {
118
119 }
120
121
122
123 protected void addCostLabel(TooltipMakerAPI tooltip, float pad, CargoTransferHandlerAPI transferHandler, Object stackSource) {
124 if (stack == null) return;
125
126 //if (Global.CODEX_TOOLTIP_MODE) return;
128 int cost = (int) stack.getBaseValuePerUnit();
129 tooltip.setParaFontDefault();
130 tooltip.addPara("Base value: %s", pad, Misc.getGrayColor(), Misc.getHighlightColor(), Misc.getDGSCredits(cost));
131 return;
132 //tooltip.setParaSmallInsignia();
133 }
134
135 ItemCostLabelData data = getCostLabelData(stack, transferHandler, stackSource);
136
137 LabelAPI label = tooltip.addPara(data.text, pad);
138 if (data.highlights != null) {
139 label.setHighlight(data.highlights.getText());
140 label.setHighlightColors(data.highlights.getColors());
141 }
142 }
143
144
145 public static class ItemCostLabelData {
146 public String text;
147 public Highlights highlights;
148 }
149
150 protected ItemCostLabelData getCostLabelData(CargoStackAPI stack, CargoTransferHandlerAPI transferHandler, Object stackSource) {
151 String text = "";
152 String highlight = null;
153 Highlights highlights = null;
154 Color highlightColor = Misc.getHighlightColor();
155 TransferAction action = TransferAction.PLAYER_BUY;
156 if (transferHandler != null && stackSource == transferHandler.getManifestOne()) {
157 action = TransferAction.PLAYER_SELL;
158 }
159
160
161 if (action == TransferAction.PLAYER_SELL && stack.getSpecialItemSpecIfSpecial() != null) {
164 text = "Can not remove item";
165 highlight = text;
166 highlights = new Highlights();
167 highlights.append(text, Misc.getNegativeHighlightColor());
168
169 ItemCostLabelData data = new ItemCostLabelData();
170 data.text = text;// + ".";
171 data.highlights = highlights;
172
173 return data;
174 }
175 }
176
177
178
179 if (transferHandler != null && transferHandler.getSubmarketTradedWith() != null &&
180 transferHandler.getSubmarketTradedWith().isIllegalOnSubmarket(stack, action)) {
181 highlightColor = Misc.getNegativeHighlightColor();
182 //text = "Illegal to trade on the " + transferHandler.getSubmarketTradedWith().getNameOneLine() + " here";
183 text = transferHandler.getSubmarketTradedWith().getPlugin().getIllegalTransferText(stack, action);
184 highlight = text;
185 highlights = transferHandler.getSubmarketTradedWith().getPlugin().getIllegalTransferTextHighlights(stack, TransferAction.PLAYER_BUY);
186 } else {
187 if (stackSource != null && transferHandler != null && !transferHandler.isNoCost()) {
188 if (stackSource == transferHandler.getManifestOne()) {
189 int cost = (int)transferHandler.computeCurrentSingleItemSellCost(stack);
190 //text = "Sells for: " + Misc.getWithDGS(cost) + " credits per unit";
191 text = "Sells for: " + Misc.getDGSCredits(cost) + " per unit.";
192 highlight = "" + Misc.getDGSCredits(cost);
193 } else {
194 int cost = (int)transferHandler.computeCurrentSingleItemBuyCost(stack);
195 //text = "Price: " + Misc.getWithDGS(cost) + " credits per unit";
196 text = "Price: " + Misc.getDGSCredits(cost) + " per unit.";
197 highlight = "" + Misc.getDGSCredits(cost);
198 }
199 } else {
200 int cost = (int) stack.getBaseValuePerUnit();
201 //float mult = Global.getSettings().getFloat("nonEconItemSellPriceMult");
202 //cost *= mult;
203 //text = "Base value: " + Misc.getWithDGS(cost) + " credits per unit";
204 text = "Base value: " + Misc.getDGSCredits(cost) + " per unit.";
205 highlight = "" + Misc.getDGSCredits(cost);
206 }
207 }
208
209 if (highlights == null) {
210 highlights = new Highlights();
211 highlights.setText(highlight);
212 highlights.setColors(highlightColor);
213 }
214
215 ItemCostLabelData data = new ItemCostLabelData();
216 data.text = text;// + ".";
217 data.highlights = highlights;
218
219 return data;
220 }
221
222 public String resolveDropParamsToSpecificItemData(String params, Random random) throws JSONException {
223 return "";
224 }
225
226
227
228
229 protected static interface BlueprintLister {
230 boolean isKnown(String id);
231 String getNoun(int num);
232 String getName(String id);
233 }
234
235 protected void addShipList(TooltipMakerAPI tooltip, String title, List<String> hulls, int max, float opad) {
236 addBlueprintList(tooltip, title, hulls, max, opad, new BlueprintLister(){
237 public boolean isKnown(String id) {
238 if (Global.CODEX_TOOLTIP_MODE) return false;
240 }
241 public String getNoun(int num) {
242 if (num == 1) return "hull";
243 return "hulls";
244 }
245 public String getName(String id) {
247 return spec.getNameWithDesignationWithDashClass();
248 }
249 });
250 }
251
252 protected void addWeaponList(TooltipMakerAPI tooltip, String title, List<String> weapons, int max, float opad) {
253 addBlueprintList(tooltip, title, weapons, max, opad, new BlueprintLister(){
254 public boolean isKnown(String id) {
255 if (Global.CODEX_TOOLTIP_MODE) return false;
257 }
258 public String getNoun(int num) {
259 if (num == 1) return "weapon";
260 return "weapons";
261 }
262 public String getName(String id) {
264 return spec.getWeaponName();
265 }
266 });
267 }
268
269 protected void addFighterList(TooltipMakerAPI tooltip, String title, List<String> wings, int max, float opad) {
270 addBlueprintList(tooltip, title, wings, max, opad, new BlueprintLister(){
271 public boolean isKnown(String id) {
272 if (Global.CODEX_TOOLTIP_MODE) return false;
274 }
275 public String getNoun(int num) {
276 if (num == 1) return "fighter LPC";
277 return "fighter LPCs";
278 }
279 public String getName(String id) {
281 return spec.getWingName();
282 }
283 });
284 }
285
286 protected void addBlueprintList(TooltipMakerAPI tooltip, String title, List<String> ids, int max, float opad,
287 BlueprintLister lister) {
288
289 Color b = Misc.getButtonTextColor();
290 Color g = Misc.getGrayColor();
291
293 tooltip.setParaSmallInsignia();
294 }
295 tooltip.addPara(title, opad);
297 tooltip.setParaFontDefault();
298 }
299
300 String tab = " ";
301 float small = 5f;
302 float pad = small;
303
304 int left = ids.size();
305
306 List<String> copy = new ArrayList<String>();
307 for (String id : ids) {
308 if (!lister.isKnown(id)) copy.add(id);
309 }
310 for (String id : ids) {
311 if (lister.isKnown(id)) copy.add(id);
312 }
313
314 ids = copy;
315 for (String id : ids) {
316 boolean known = lister.isKnown(id);
317
318 if (known) {
319 tooltip.addPara(tab + lister.getName(id) + " (known)", g, pad);
320 } else {
321 tooltip.addPara(tab + lister.getName(id), b, pad);
322 }
323 left--;
324 pad = 3f;
325 if (ids.size() - left >= max - 1) break;
326 }
327 if (ids.isEmpty()) {
328 tooltip.addPara(tab + "None", pad);
329 }
330 if (left > 0) {
331 String noun = lister.getNoun(left);
332 tooltip.addPara(tab + "... and %s other " + noun + "", pad, Misc.getHighlightColor(), "" + left);
333 }
334 }
335 public String getDesignType() {
336 return spec.getManufacturer();
337 }
339 return spec;
340 }
341
342// @Override
343// public int getNumToRemove() {
344// return 1;
345// }
346//
347// @Override
348// public boolean shouldRemoveCalledAfterRightClickAction() {
349// return false;
350// }
351// @Override
352// public void setReadOnlyCargoForRightClickAction(CargoAPI cargo) {
353// // TODO Auto-generated method stub
354//
355// }
356
357}
358
359
360
361
362
363
364
static SettingsAPI getSettings()
Definition Global.java:57
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
static SectorAPI getSector()
Definition Global.java:65
ItemCostLabelData getCostLabelData(CargoStackAPI stack, CargoTransferHandlerAPI transferHandler, Object stackSource)
void addCostLabel(TooltipMakerAPI tooltip, float pad, CargoTransferHandlerAPI transferHandler, Object stackSource)
void addWeaponList(TooltipMakerAPI tooltip, String title, List< String > weapons, int max, float opad)
void addBlueprintList(TooltipMakerAPI tooltip, String title, List< String > ids, int max, float opad, BlueprintLister lister)
void addShipList(TooltipMakerAPI tooltip, String title, List< String > hulls, int max, float opad)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource, boolean useGray)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource)
void addFighterList(TooltipMakerAPI tooltip, String title, List< String > wings, int max, float opad)
void render(float x, float y, float w, float h, float alphaMult, float glowMult, SpecialItemRendererAPI renderer)
void setColors(Color ... colors)
void append(String str, Color color)
static Color getTextColor()
Definition Misc.java:839
static String getDGSCredits(float num)
Definition Misc.java:1390
static Color getButtonTextColor()
Definition Misc.java:842
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getGrayColor()
Definition Misc.java:826
static Color getHighlightColor()
Definition Misc.java:792
static LabelAPI addDesignTypePara(TooltipMakerAPI tooltip, String design, float pad)
Definition Misc.java:4946
SpecialItemSpecAPI getSpecialItemSpec(String itemId)
ShipHullSpecAPI getHullSpec(String hullId)
FighterWingSpecAPI getFighterWingSpec(String wingId)
WeaponSpecAPI getWeaponSpec(String weaponId)
SpecialItemSpecAPI getSpecialItemSpecIfSpecial()
float computeCurrentSingleItemSellCost(CargoStackAPI stack)
float computeCurrentSingleItemBuyCost(CargoStackAPI stack)
boolean knowsWeapon(String weaponId)
String getIllegalTransferText(CargoStackAPI stack, TransferAction action)
Highlights getIllegalTransferTextHighlights(CargoStackAPI stack, TransferAction action)
boolean isIllegalOnSubmarket(CargoStackAPI stack, TransferAction action)
void setHighlight(int start, int end)
void setHighlightColors(Color ... colors)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)