Starsector API
Loading...
Searching...
No Matches
MapMarkerIntel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.misc;
2
3import java.util.Set;
4
5import java.awt.Color;
6
7import org.lwjgl.input.Keyboard;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.CampaignFleetAPI;
11import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
12import com.fs.starfarer.api.campaign.FactionAPI;
13import com.fs.starfarer.api.campaign.SectorEntityToken;
14import com.fs.starfarer.api.campaign.TextPanelAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Tags;
16import com.fs.starfarer.api.impl.campaign.terrain.DebrisFieldTerrainPlugin;
17import com.fs.starfarer.api.loading.Description;
18import com.fs.starfarer.api.loading.Description.Type;
19import com.fs.starfarer.api.ui.ButtonAPI;
20import com.fs.starfarer.api.ui.IntelUIAPI;
21import com.fs.starfarer.api.ui.SectorMapAPI;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
24
29public class MapMarkerIntel extends FleetLogIntel {
30
31 public static String BUTTON_EDIT = "button_edit";
32
35
36 protected String title;
37 protected String text;
38 private boolean withDesc;
39
40 private boolean withDeleteButton = true;
41 private boolean withTimestamp = true;
42
43
44 public MapMarkerIntel() {
45 }
46
47 public MapMarkerIntel(SectorEntityToken entity, String title, String text, String icon, boolean withDesc) {
48 super();
49 init(entity, title, text, icon, withDesc);
50 }
51
52 protected void init(SectorEntityToken entity, String title, String text, String icon, boolean withDesc) {
53 init(entity, title, text, icon, withDesc, null);
54 }
55 protected void init(SectorEntityToken entity, String title, String text, String icon, boolean withDesc, TextPanelAPI textPanel) {
56 this.entity = entity;
57 this.withDesc = withDesc;
58 //setRemoveTrigger(this.entity);
59
60 // otherwise a marker on an already-explored debris field auto-removes immediately
61 if (entity instanceof CampaignTerrainAPI) {
63 if (terrain.getPlugin() instanceof DebrisFieldTerrainPlugin) {
65 if (debris.isScavenged()) {
67 }
68 }
69 }
70
71
72 if (entity instanceof CampaignFleetAPI && !((CampaignFleetAPI) entity).isStationMode()) {
76 } else {
77 setRemoveTrigger(this.entity);
78 }
79
80 this.title = title;
81 this.text = text;
83
85 Global.getSector().getIntelManager().addIntel(this, false, textPanel);
86 setListInfoParam(null);
87 }
88
89 @Override
90 public void reportRemovedIntel() {
91 super.reportRemovedIntel();
92 if (copy != null && copy.getContainingLocation() != null) {
94 }
95 }
96
104
105
106 public String getTitle() {
107 return title;
108 }
109
110 public void setTitle(String title) {
111 this.title = title;
112 }
113
115 return entity;
116 }
117
119 this.entity = entity;
120 }
121
122 public String getText() {
123 return text;
124 }
125
126 public void setText(String text) {
127 this.text = text;
128 }
129
130 public boolean isWithDesc() {
131 return withDesc;
132 }
133
134 public void setWithDesc(boolean withDesc) {
135 this.withDesc = withDesc;
136 }
137
138 @Override
139 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
140 Color c = getTitleColor(mode);
141 info.addPara(getName(), c, 0f);
142 addBulletPoints(info, mode);
143 }
144
145 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
146 //if (text == null || text.trim().isEmpty()) return;
147
148
149 Color h = Misc.getHighlightColor();
150 Color g = Misc.getGrayColor();
151 float pad = 3f;
152 float opad = 10f;
153
154 float initPad = pad;
155 if (mode == ListInfoMode.IN_DESC) initPad = opad;
156
157 Color tc = getBulletColorForMode(mode);
158 boolean isUpdate = getListInfoParam() != null;
159
160 bullet(info);
161 if (text != null && !text.isEmpty()) {
162 String str = text;
163 if (endsInPunct(str, true)) {
164 str = str.substring(0, str.length() - 1);
165 }
166 info.addPara(str, tc, initPad);
167 initPad = 0f;
168 }
169 addExtraBulletPoints(info, tc, initPad, mode);
170 unindent(info);
171 }
172
173 protected void addExtraBulletPoints(TooltipMakerAPI info, Color tc, float initPad, ListInfoMode mode) {
174
175 }
176
177 protected boolean endsInPunct(String str, boolean forBulletPoint) {
178 String punct = ",.?!:;";
179 if (forBulletPoint) {
180 punct = ",.:;";
181 }
182 String end = "" + str.charAt(str.length() - 1);
183 return punct.contains(end);
184 }
185
186
187
188 protected boolean withTextInDesc() {
189 return true;
190 }
191 protected boolean withCustomVisual() {
192 return false;
193 }
194 protected boolean withCustomDescription() {
195 return false;
196 }
197
198 protected void addCustomVisual(TooltipMakerAPI info, float width, float height) {
199
200 }
201 protected void addCustomDescription(TooltipMakerAPI info, float width, float height) {
202
203 }
204
205 protected void addPostDescriptionSection(TooltipMakerAPI info, float width, float height, float opad) {
206
207 }
208
209 public boolean isWithDeleteButton() {
210 return withDeleteButton;
211 }
212
213 public void setWithDeleteButton(boolean withDeleteButton) {
214 this.withDeleteButton = withDeleteButton;
215 }
216
217 public boolean isWithTimestamp() {
218 return withTimestamp;
219 }
220
221 public void setWithTimestamp(boolean withTimestamp) {
222 this.withTimestamp = withTimestamp;
223 }
224
225 @Override
226 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
227 Color h = Misc.getHighlightColor();
228 Color g = Misc.getGrayColor();
229 Color tc = Misc.getTextColor();
230 float pad = 3f;
231 float opad = 10f;
232
233
234 boolean addedDesc = false;
235 if (withDesc) {
236 if (withCustomVisual()) {
237 addCustomVisual(info, width, height);
238 } else if (entity.getCustomInteractionDialogImageVisual() != null) {
240 }
241
242 if (withCustomDescription()) {
243 addCustomDescription(info, width, height);
244 addedDesc = true;
245 } else if (entity.getCustomDescriptionId() != null) {
247 info.addPara(desc.getText1(), opad);
248 addedDesc = true;
249 }
250 }
251
252 if (text != null && !text.trim().isEmpty() && withTextInDesc()) {
253 if (addedDesc) {
254 addBulletPoints(info, ListInfoMode.IN_DESC);
255 } else {
256 info.addPara(text + (endsInPunct(text, false) ? "" : "."), opad);
257 }
258 }
259
260 addPostDescriptionSection(info, width, height, opad);
261 //target.getOrbit().updateLocation();
262
263 if (isWithTimestamp()) {
264 addLogTimestamp(info, tc, opad);
265 }
266
267
268 if (getClass() == MapMarkerIntel.class) {
269 ButtonAPI button = info.addButton("Edit", BUTTON_EDIT,
270 getFactionForUIColors().getBaseUIColor(), getFactionForUIColors().getDarkUIColor(),
271 (int)(width), 20f, opad * 2f);
272 button.setShortcut(Keyboard.KEY_T, true);
273 if (isWithDeleteButton()) {
274 info.addSpacer(-opad);
275 }
276 }
277
278 if (isWithDeleteButton()) {
279 addDeleteButton(info, width);
280 }
281 }
282
283
284 @Override
285 public void buttonPressConfirmed(Object buttonId, IntelUIAPI ui) {
286 if (buttonId == BUTTON_EDIT) {
288 return;
289 }
290 super.buttonPressConfirmed(buttonId, ui);
291 }
292
293 @Override
294 public boolean doesButtonHaveConfirmDialog(Object buttonId) {
295 return super.doesButtonHaveConfirmDialog(buttonId);
296 }
297
298 @Override
299 public Set<String> getIntelTags(SectorMapAPI map) {
300 Set<String> tags = super.getIntelTags(map);
301 if (getClass() == MapMarkerIntel.class) {
302 tags.add(Tags.INTEL_MARKER);
303 }
304 return tags;
305 }
306
307 public String getSortString() {
308 return super.getSortString();
309 }
310
311 protected transient String discoveredPrefixOverride = null;
312
315 }
316
318 this.discoveredPrefixOverride = discoveredPrefixOverride;
319 }
320
321 public String getName() {
322 String prefix = "";
323 if (getListInfoParam() == DISCOVERED_PARAM && getClass() != MapMarkerIntel.class) {
324 prefix = "Discovered: ";
325 if (discoveredPrefixOverride != null) {
327 }
328 }
329 return prefix + title;
330 }
331
332 @Override
334 return super.getFactionForUIColors();
335 }
336
337 public String getSmallDescriptionTitle() {
338 return getName();
339 }
340
341 @Override
343// if (copy != null && copy.getStarSystem() != null) {
344// return copy.getStarSystem().getCenter();
345// } else if (copy != null) {
346// return copy;
347// }
348 if (copy != null) return copy;
349 return entity;
350 }
351
352 @Override
353 public boolean shouldRemoveIntel() {
354 return super.shouldRemoveIntel();
355 }
356
357 public boolean isHidden() {
358 return hidden != null;
359 }
360
361
362}
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
void addLogTimestamp(TooltipMakerAPI info, Color tc, float opad)
void addDeleteButton(TooltipMakerAPI info, float width)
void setKeepExploredDebrisField(Boolean keepExploredDebrisField)
void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode)
static SectorEntityToken makeDoubleWithSameOrbit(SectorEntityToken entity)
void addPostDescriptionSection(TooltipMakerAPI info, float width, float height, float opad)
boolean endsInPunct(String str, boolean forBulletPoint)
void init(SectorEntityToken entity, String title, String text, String icon, boolean withDesc, TextPanelAPI textPanel)
void addCustomDescription(TooltipMakerAPI info, float width, float height)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
void init(SectorEntityToken entity, String title, String text, String icon, boolean withDesc)
void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode)
void addCustomVisual(TooltipMakerAPI info, float width, float height)
MapMarkerIntel(SectorEntityToken entity, String title, String text, String icon, boolean withDesc)
void setDiscoveredPrefixOverride(String discoveredPrefixOverride)
void addExtraBulletPoints(TooltipMakerAPI info, Color tc, float initPad, ListInfoMode mode)
static Color getTextColor()
Definition Misc.java:839
static Color getGrayColor()
Definition Misc.java:826
static Color getHighlightColor()
Definition Misc.java:792
Description getDescription(String id, Type type)
void addEntity(SectorEntityToken entity)
SectorEntityToken createToken(float x, float y)
void removeEntity(SectorEntityToken entity)
InteractionDialogImageVisual getCustomInteractionDialogImageVisual()
void setShortcut(int key, boolean putLast)
void showEditIntelMarkerDialog(MapMarkerIntel intel)
void addImage(String spriteName, float pad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)
ButtonAPI addButton(String text, Object data, float width, float height, float pad)