Starsector API
Loading...
Searching...
No Matches
GenericSpecialItemPlugin.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;
5
6import java.awt.Color;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CargoTransferHandlerAPI;
10import com.fs.starfarer.api.campaign.SpecialItemData;
11import com.fs.starfarer.api.campaign.econ.Industry;
12import com.fs.starfarer.api.campaign.econ.InstallableIndustryItemPlugin.InstallableItemDescriptionMode;
13import com.fs.starfarer.api.impl.campaign.econ.impl.InstallableItemEffect;
14import com.fs.starfarer.api.impl.campaign.econ.impl.ItemEffectsRepo;
15import com.fs.starfarer.api.loading.IndustrySpecAPI;
16import com.fs.starfarer.api.ui.LabelAPI;
17import com.fs.starfarer.api.ui.TooltipMakerAPI;
18import com.fs.starfarer.api.util.Misc;
19
21
22 protected void addInstalledInSection(TooltipMakerAPI tooltip, float pad) {
23 String list = "";
24 String [] params = spec.getParams().split(",");
25 String [] array = new String[params.length];
26 int i = 0;
27 for (String curr : params) {
28 curr = curr.trim();
30 if (ind == null) continue;
31 list += ind.getName() + ", ";
32 array[i] = ind.getName();
33 i++;
34 }
35 if (!list.isEmpty()) {
36 list = list.substring(0, list.length() - 2);
37 tooltip.addPara(list, pad,
39 //Misc.getGrayColor(), Misc.getHighlightColor(), array);
40 //Misc.getGrayColor(), Misc.getTextColor(), array);
41 }
42 }
43
44 public static void addReqsSection(Industry industry, InstallableItemEffect effect, TooltipMakerAPI tooltip, boolean withRequiresText, float pad) {
45 List<String> reqs = effect.getRequirements(industry);
46 List<String> unmet = effect.getUnmetRequirements(industry);
47
48 if (reqs == null) reqs = new ArrayList<String>();
49 if (unmet == null) unmet = new ArrayList<String>();
50
51 Color [] hl = new Color[reqs.size()];
52
53 int i = 0;
54 String list = "";
55 for (String curr : reqs) {
56 list += curr + ", ";
57
58 if (unmet.contains(curr)) {
60 } else {
61 hl[i] = Misc.getBasePlayerColor();
62 //hl[i] = Misc.getHighlightColor();
63 //hl[i] = Misc.getTextColor();
64 }
65 i++;
66 }
67 if (!list.isEmpty()) {
68 list = list.substring(0, list.length() - 2);
69 list = Misc.ucFirst(list);
70 reqs.set(0, Misc.ucFirst(reqs.get(0)));
71
72 float bulletWidth = 70f;
73 if (withRequiresText) {
74 tooltip.setBulletWidth(bulletWidth);
76 tooltip.setBulletedListMode("Requires:");
77 }
78
79 LabelAPI label = tooltip.addPara(list, Misc.getGrayColor(), pad);
80 label.setHighlightColors(hl);
81 label.setHighlight(reqs.toArray(new String[0]));
82
83 if (withRequiresText) {
84 tooltip.setBulletedListMode(null);
85 }
86 }
87
88 }
89
90 public static void addSpecialNotesSection(Industry industry, InstallableItemEffect effect, TooltipMakerAPI tooltip, boolean withRequiresText, float pad) {
91 String name = effect.getSpecialNotesName();
92 if (name == null) return;
93
94 List<String> reqs = effect.getSpecialNotes(industry);
95 if (reqs == null) return;
96
97 Color [] hl = new Color[reqs.size()];
98
99 int i = 0;
100 String list = "";
101 for (String curr : reqs) {
102 list += curr + ", ";
103 hl[i] = Misc.getBasePlayerColor();
104 i++;
105 }
106 if (!list.isEmpty()) {
107 list = list.substring(0, list.length() - 2);
108 list = Misc.ucFirst(list);
109 reqs.set(0, Misc.ucFirst(reqs.get(0)));
110
111 float bulletWidth = 70f;
112 if (withRequiresText) {
113 tooltip.setBulletWidth(bulletWidth);
115 tooltip.setBulletedListMode(name + ":");
116 }
117
118 LabelAPI label = tooltip.addPara(list, Misc.getGrayColor(), pad);
119 label.setHighlightColors(hl);
120 label.setHighlight(reqs.toArray(new String[0]));
121
122 if (withRequiresText) {
123 tooltip.setBulletedListMode(null);
124 }
125 }
126
127 }
128
129 protected transient boolean tooltipIsForPlanetSearch = false;
130 public boolean isTooltipIsForPlanetSearch() {
132 }
134 this.tooltipIsForPlanetSearch = tooltipIsForPlanetSearch;
135 }
136
137
138 @Override
139 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource) {
140 //super.createTooltip(tooltip, expanded, transferHandler, stackSource, false);
141
142 // doing this in core code instead where it catches all special items not just colony ones
143// if (!Global.CODEX_TOOLTIP_MODE) {
144// if (getSpec().hasTag(Items.TAG_COLONY_ITEM) || getSpec().hasTag(Tags.CODEX_UNLOCKABLE)) {
145// SharedUnlockData.get().reportPlayerAwareOfSpecialItem(getId(), true);
146// }
147// }
148
149 float pad = 0f;
150 float opad = 10f;
151
153 tooltip.addTitle(getName());
154 } else {
155 tooltip.addSpacer(-opad);
156 }
157
158 LabelAPI design = null;
159
161 design = Misc.addDesignTypePara(tooltip, getDesignType(), opad);
162 }
163
164 float bulletWidth = 86f;
165 if (design != null) {
166 bulletWidth = design.computeTextWidth("Design type: ");
167 }
168
170 if (effect != null) {
171 tooltip.setBulletWidth(bulletWidth);
173
174 tooltip.setBulletedListMode("Installed in:");
175 addInstalledInSection(tooltip, opad);
176 tooltip.setBulletedListMode("Requires:");
177 addReqsSection(null, effect, tooltip, false, pad);
178 if (effect.getSpecialNotesName() != null) {
179 tooltip.setBulletedListMode(effect.getSpecialNotesName() + ":");
180 addSpecialNotesSection(null, effect, tooltip, false, pad);
181 }
182
183 tooltip.setBulletedListMode(null);
184
186 tooltip.setParaSmallInsignia();
187 }
188
190 if (!spec.getDesc().isEmpty()) {
191 Color c = Misc.getTextColor();
192 //if (useGray) c = Misc.getGrayColor();
193 tooltip.addPara(spec.getDesc(), c, opad);
194 }
195 }
196
198 effect.addItemDescription(null, tooltip, new SpecialItemData(getId(), null), InstallableItemDescriptionMode.CARGO_TOOLTIP);
199 }
200 } else {
201 if (!spec.getDesc().isEmpty() && !tooltipIsForPlanetSearch) {
202 Color c = Misc.getTextColor();
204 tooltip.setParaSmallInsignia();
205 }
206 tooltip.addPara(spec.getDesc(), c, opad);
207 }
208 }
209
210 addCostLabel(tooltip, opad, transferHandler, stackSource);
211 }
212
213}
214
215
216
217
static SettingsAPI getSettings()
Definition Global.java:57
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
void addCostLabel(TooltipMakerAPI tooltip, float pad, CargoTransferHandlerAPI transferHandler, Object stackSource)
static void addSpecialNotesSection(Industry industry, InstallableItemEffect effect, TooltipMakerAPI tooltip, boolean withRequiresText, float pad)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource)
static void addReqsSection(Industry industry, InstallableItemEffect effect, TooltipMakerAPI tooltip, boolean withRequiresText, float pad)
static Map< String, InstallableItemEffect > ITEM_EFFECTS
static Color getTextColor()
Definition Misc.java:839
static String ucFirst(String str)
Definition Misc.java:559
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getBasePlayerColor()
Definition Misc.java:833
static Color getGrayColor()
Definition Misc.java:826
static LabelAPI addDesignTypePara(TooltipMakerAPI tooltip, String design, float pad)
Definition Misc.java:4946
IndustrySpecAPI getIndustrySpec(String industryId)
void addItemDescription(Industry industry, TooltipMakerAPI text, SpecialItemData data, InstallableItemDescriptionMode mode)
void setHighlight(int start, int end)
void setHighlightColors(Color ... colors)
float computeTextWidth(String in)
void setBulletWidth(Float bulletWidth)
void setBulletColor(Color bulletColor)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)
void setBulletedListMode(String itemPrefix)