Starsector API
Loading...
Searching...
No Matches
CodexEntryV2.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.codex;
2
3import java.util.ArrayList;
4import java.util.LinkedHashSet;
5import java.util.List;
6import java.util.Set;
7
8import com.fs.starfarer.api.ModSpecAPI;
9import com.fs.starfarer.api.campaign.CustomUIPanelPlugin;
10import com.fs.starfarer.api.impl.campaign.ids.Tags;
11import com.fs.starfarer.api.loading.WithSourceMod;
12import com.fs.starfarer.api.ui.CustomPanelAPI;
13import com.fs.starfarer.api.ui.TagDisplayAPI;
14import com.fs.starfarer.api.ui.TooltipMakerAPI;
15import com.fs.starfarer.api.ui.UIPanelAPI;
16import com.fs.starfarer.api.util.Misc;
17
18public class CodexEntryV2 implements CodexEntryPlugin {
19
20 protected String id;
21 protected String title;
22 protected String icon;
24 protected Object param;
25 protected Object param2;
26 protected List<CodexEntryPlugin> children = new ArrayList<>();
27 //protected Set<CodexEntryPlugin> related = new LinkedHashSet<>();
28 protected Set<String> related = new LinkedHashSet<>();
29 protected boolean retainOrderOfChildren = false;
30 protected boolean retainOrderOfRelatedEntries = false;
31 protected float categorySortTierForRelatedEntries = 1000;
32 protected Set<String> tags = new LinkedHashSet<>();
33
34 public CodexEntryV2(String id, String title, String icon) {
35 this.id = id;
36 this.title = title;
37 this.icon = icon;
38 }
39
40 public CodexEntryV2(String id, String title, String icon, Object param) {
41 this.id = id;
42 this.title = title;
43 this.icon = icon;
44 this.param = param;
45 }
46
47 @Override
48 public String getId() {
49 return id;
50 }
51
52 @Override
53 public String getTitle() {
54 return title;
55 }
56
57 @Override
58 public String getSortTitle() {
59 return getTitle();
60 }
61
62 @Override
63 public String getSearchString() {
64 return getTitle();
65 }
66
67 @Override
68 public String getIcon() {
69 return icon;
70 }
71
72 @Override
73 public void setIcon(String icon) {
74 this.icon = icon;
75 }
76
77 @Override
79 return parent;
80 }
81
82 @Override
84 this.parent = parent;
85 }
86
87 @Override
88 public Object getParam() {
89 return param;
90 }
91
92 public void setParam(Object param) {
93 this.param = param;
94 }
95
96 @Override
97 public List<CodexEntryPlugin> getChildren() {
98 return children;
99 }
100
101 @Override
102 public void addChild(CodexEntryPlugin entry) {
103 if (entry == null) return;
104 entry.setParent(this);
105 children.add(entry);
106 }
107
108 @Override
109 public boolean isRetainOrderOfChildren() {
111 }
112
113 @Override
115 this.retainOrderOfChildren = retainOrderOfChildren;
116 }
117
118 @Override
119 public boolean isCategory() {
120 return !getChildren().isEmpty() || getParam() == null;
121 }
122
123
124 @Override
125 public void createTitleForList(TooltipMakerAPI info, float width, ListMode mode) {
126 if (isCategory()) {
128 }
130 }
131
132 @Override
133 public boolean hasDetail() {
134 return !isCategory();
135 }
136
137
138 @Override
139 public boolean matchesTags(Set<String> tags) {
140 return true;
141 }
142
143 @Override
144 public boolean hasTagDisplay() {
145 return false;
146 }
147
148 @Override
150
151 }
152
153 @Override
154 public Set<String> getRelatedEntryIds() {
155 return related;
156 }
157
158 @Override
159 public Set<CodexEntryPlugin> getRelatedEntries() {
160 Set<CodexEntryPlugin> result = new LinkedHashSet<>();
161 for (String id : related) {
163 if (entry != null && entry != this) {
164 result.add(entry);
165 }
166 }
167 return result;
168 }
169
170 @Override
172 if (entry == null || entry.getId().equals(getId())) return;
173 //related.add(entry);
174 related.add(entry.getId());
175 }
176
177 @Override
178 public void addRelatedEntry(String id) {
179 if (id == null) return;
180 //related.add(entry);
181 related.add(id);
182 }
183
185 if (entry == null) return;
186 related.remove(entry.getId());
187 }
188
189 public void removeRelatedEntry(String id) {
190 related.remove(id);
191 }
192
193 @Override
196 }
197
198 @Override
200 this.retainOrderOfRelatedEntries = retainOrderOfRelatedEntries;
201 }
202
203 @Override
207
208 @Override
210 this.categorySortTierForRelatedEntries = categorySortTierForRelatedEntries;
211 }
212
213
214 @Override
215 public List<CodexEntryPlugin> getChildrenRecursive(boolean includeCategories) {
216 List<CodexEntryPlugin> result = new ArrayList<>();
217 findChildren(this, result, includeCategories);
218 return result;
219 }
220
221 public void findChildren(CodexEntryPlugin curr, List<CodexEntryPlugin> result, boolean includeCategories) {
222 if (includeCategories || !curr.isCategory()) {
223 result.add(curr);
224 }
225 for (CodexEntryPlugin child : curr.getChildren()) {
226 findChildren(child, result, includeCategories);
227 }
228 }
229
230
231 @Override
232 public boolean hasCustomDetailPanel() {
233 return false;
234 }
235
236 @Override
238 return null;
239 }
240
241 @Override
242 public void createCustomDetail(CustomPanelAPI panel, UIPanelAPI relatedEntries, CodexDialogAPI codex) {
243
244 }
245
246 public void destroyCustomDetail() {
247
248 }
249
250 @Override
251 public boolean isVignetteIcon() {
252 return false;
253 }
254
255 protected boolean checking = false;
257 // recursed back to this entry due to something else circularly checking its visibility
258 if (checking) return false;
259 checking = true;
260 boolean found = false;
261 for (CodexEntryPlugin rel : getRelatedEntries()) {
262 if (rel.isVisible()) {
263 found = true;
264 break;
265 }
266 }
267 checking = false;
268 return found;
269 }
270
272 // recursed back to this entry due to something else circularly checking its locked status
274 checking = true;
275 boolean found = false;
276 for (CodexEntryPlugin rel : getRelatedEntries()) {
277 if (!rel.isLocked()) {
278 found = true;
279 break;
280 }
281 }
282 checking = false;
283 return found;
284 }
285
286 @Override
290
291 @Override
295
296 @Override
297 public boolean checkTagsWhenLocked() {
298 return false;
299 }
300
301 public Set<String> getUnlockRelatedTags() {
302 return null;
303 }
304
305 public boolean isUnlockedIfRequiresUnlock() {
306 return true;
307 }
308
309 public boolean isVisibleStandard(Set<String> tags, boolean thingUnlocked) {
310 if (tags == null) return true;
311
312 if (tags.contains(Tags.INVISIBLE_IN_CODEX)) return false;
313 if (tags.contains(Tags.CODEX_UNLOCKABLE)) return true;
314
315 if (tags.contains(Tags.CODEX_REQUIRE_RELATED)) {
317 }
318 return true;
319 }
320
321 public boolean isLockedStandard(Set<String> tags, boolean thingUnlocked) {
322 if (tags == null) return false;
323
324 if (CodexDataV2.codexFullyUnlocked()) return false;
325 if (tags.contains(Tags.CODEX_UNLOCKABLE) && !thingUnlocked) {
326 return true;
327 }
328 if (tags.contains(Tags.CODEX_REQUIRE_RELATED)) {
330 }
331 return false;
332 }
333
334 @Override
335 public Object getParam2() {
336 return param2;
337 }
338
339 public void setParam2(Object param2) {
340 this.param2 = param2;
341 }
342
343 @Override
344 public boolean skipForTags() {
345 return false;
346 }
347
348
349 @Override
350 public Set<String> getTags() {
351 return tags;
352 }
353
354 @Override
355 public void addTag(String tag) {
356 tags.add(tag);
357 }
358
359 @Override
360 public boolean hasTag(String tag) {
361 return tags.contains(tag);
362 }
363
364 @Override
366 if (getParam() instanceof WithSourceMod) {
367 return ((WithSourceMod)getParam()).getSourceMod();
368 }
369 return null;
370 }
371}
372
373
374
375
376
377
378
379
380
381
382
383
static final String CODEX_REQUIRE_RELATED
Definition Tags.java:518
static CodexEntryPlugin getEntry(String id)
void setParent(CodexEntryPlugin parent)
List< CodexEntryPlugin > getChildrenRecursive(boolean includeCategories)
void setCategorySortTierForRelatedEntries(float categorySortTierForRelatedEntries)
void setRetainOrderOfRelatedEntries(boolean retainOrderOfRelatedEntries)
void setRetainOrderOfChildren(boolean retainOrderOfChildren)
void removeRelatedEntry(CodexEntryPlugin entry)
void createCustomDetail(CustomPanelAPI panel, UIPanelAPI relatedEntries, CodexDialogAPI codex)
void addRelatedEntry(CodexEntryPlugin entry)
CodexEntryV2(String id, String title, String icon, Object param)
void createTitleForList(TooltipMakerAPI info, float width, ListMode mode)
CodexEntryV2(String id, String title, String icon)
void findChildren(CodexEntryPlugin curr, List< CodexEntryPlugin > result, boolean includeCategories)
boolean isVisibleStandard(Set< String > tags, boolean thingUnlocked)
boolean isLockedStandard(Set< String > tags, boolean thingUnlocked)
static Color getBasePlayerColor()
Definition Misc.java:833
void setParent(CodexEntryPlugin parent)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)