1package com.fs.starfarer.api.impl.campaign.intel.events;
4import java.util.ArrayList;
5import java.util.Collections;
7import java.util.Random;
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.InteractionDialogAPI;
12import com.fs.starfarer.api.campaign.TextPanelAPI;
13import com.fs.starfarer.api.campaign.listeners.EconomyTickListener;
14import com.fs.starfarer.api.impl.campaign.ids.Tags;
15import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
16import com.fs.starfarer.api.ui.Alignment;
17import com.fs.starfarer.api.ui.CustomPanelAPI;
18import com.fs.starfarer.api.ui.EventProgressBarAPI;
19import com.fs.starfarer.api.ui.SectorMapAPI;
20import com.fs.starfarer.api.ui.TooltipMakerAPI;
21import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
22import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipLocation;
23import com.fs.starfarer.api.ui.UIComponentAPI;
24import com.fs.starfarer.api.util.Misc;
42 public static enum StageIconSize {
47 public static enum RandomizedStageType {
56 public static class EventStageDisplayData {
58 public float downLineLength;
61 public Color iconColor = Color.white;
63 public Color labelColor;
64 public int importance = 0;
67 public static class EventStageData {
70 public boolean isOneOffEvent;
71 public boolean wasEverReached =
false;
72 public boolean isRepeatable =
true;
73 public boolean sendIntelUpdateOnReaching =
true;
74 public boolean hideIconWhenPastStageUnlessLastActive =
false;
75 public boolean keepIconBrightWhenLaterStageReached =
false;
76 public StageIconSize iconSize = StageIconSize.MEDIUM;
78 public boolean randomized =
false;
79 public RandomizedStageType randomType = RandomizedStageType.NEUTRAL;
80 public int progressToResetAt;
81 public int progressToRollAt;
82 public Object rollData;
84 public EventStageData(Object
id,
int progress,
boolean isOneOffEvent) {
85 this(id, progress, isOneOffEvent, StageIconSize.MEDIUM);
87 public EventStageData(Object
id,
int progress,
boolean isOneOffEvent, StageIconSize iconSize) {
89 this.progress = progress;
90 this.isOneOffEvent = isOneOffEvent;
91 this.iconSize = iconSize;
94 public void addProgressReq(TooltipMakerAPI tooltip,
float pad) {
95 tooltip.addPara(
"Requires %s points of event progress.",
96 pad, Misc.getHighlightColor(),
"" + progress);
98 public void addResetReq(TooltipMakerAPI tooltip,
float pad) {
99 addResetReq(tooltip,
false, pad);
101 public void beginResetReqList(TooltipMakerAPI tooltip,
boolean withAvertInfo,
float initPad) {
102 beginResetReqList(tooltip, withAvertInfo,
"outcome", initPad);
104 public void beginResetReqList(TooltipMakerAPI tooltip,
boolean withAvertInfo, String outcome,
float initPad) {
107 tooltip.addPara(
"This " + outcome +
" will be averted if:", initPad);
110 tooltip.addPara(
"Event progress is reduced to %s points or below",
111 pad, Misc.getHighlightColor(),
"" + progressToResetAt);
115 public void endResetReqList(TooltipMakerAPI tooltip,
boolean withTriggeredResetInfo) {
116 endResetReqList(tooltip, withTriggeredResetInfo,
"outcome", -1, -1);
118 public void endResetReqList(TooltipMakerAPI tooltip,
boolean withTriggeredResetInfo, String outcome,
int min,
int max) {
119 tooltip.setBulletedListMode(
null);
120 if (withTriggeredResetInfo) {
122 if (min < 0 || max < 0) {
123 tooltip.addPara(
"If this " + outcome +
" is triggered, event progress will be reset to a much lower value afterwards.",
126 tooltip.addPara(
"If this " + outcome +
" is triggered, event progress will be reset to between %s and %s points.",
127 opad, Misc.getHighlightColor(),
"" + min,
"" + max);
132 public void addResetReq(TooltipMakerAPI tooltip,
boolean withResetIfTriggered,
float pad) {
133 addResetReq(tooltip, withResetIfTriggered,
"outcome", -1, -1, pad);
135 public void addResetReq(TooltipMakerAPI tooltip,
boolean withResetIfTriggered, String outcome,
int min,
int max,
float pad) {
136 if (withResetIfTriggered) {
137 if (min < 0 || max < 0) {
138 tooltip.addPara(
"This " + outcome +
" will be averted if event progress is reduced to %s points or below. "
139 +
"If this " + outcome +
" is triggered, event progress will be reset to a lower value afterwards.",
140 pad, Misc.getHighlightColor(),
"" + progressToResetAt);
142 tooltip.addPara(
"This " + outcome +
" will be averted if event progress is reduced to %s points or below. "
143 +
"If this " + outcome +
" is triggered, event progress will be reset to between %s and %s points.",
144 pad, Misc.getHighlightColor(),
"" + progressToResetAt,
"" + min,
"" + max);
147 tooltip.addPara(
"This " + outcome +
" will be averted if event progress is reduced to %s points or below.",
148 pad, Misc.getHighlightColor(),
"" + progressToResetAt);
157 protected List<EventStageData>
stages =
new ArrayList<EventStageData>();
160 protected List<EventFactor>
factors =
new ArrayList<EventFactor>();
179 super.advanceImpl(amount);
181 List<EventFactor>
remove =
new ArrayList<EventFactor>();
183 if (curr.isExpired()) {
188 curr.advance(amount);
190 if (curr.isExpired()) {
196 factor.notifyFactorRemoved();
205 boolean large =
true;
206 if (large) info.setParaSmallInsignia();
207 info.addPara(
getName(), c, 0f);
209 if (large) info.setParaFontDefault();
214 Color tc,
float initPad) {
240 TooltipMakerAPI main = panel.createUIElement(width, height,
true);
242 main.setTitleOrbitronVeryLarge();
243 main.addTitle(
getName(), Misc.getBasePlayerColor());
245 EventProgressBarAPI bar = main.addEventProgressBar(
this, 100f);
248 main.addTooltipToPrevious(barTC, TooltipLocation.BELOW,
false);
251 for (EventStageData curr :
stages) {
252 if (curr.progress <= 0)
continue;
255 if (curr.wasEverReached && curr.isOneOffEvent && !curr.isRepeatable)
continue;
257 if (curr.hideIconWhenPastStageUnlessLastActive &&
264 UIComponentAPI marker = main.addEventStageMarker(data);
265 float xOff = bar.getXCoordinateForProgress(curr.progress) - bar.getPosition().getX();
266 marker.getPosition().aboveLeft(bar, data.downLineLength).setXAlignOffset(xOff - data.size / 2f - 1);
270 main.addTooltipTo(tc, marker, TooltipLocation.LEFT,
false);
276 UIComponentAPI marker = main.addEventProgressMarker(
this);
277 float xOff = bar.getXCoordinateForProgress(
progress) - bar.getPosition().getX();
282 main.addSpacer(opad);
283 main.addSpacer(opad);
284 for (EventStageData curr :
stages) {
285 if (curr.wasEverReached && curr.isOneOffEvent && !curr.isRepeatable)
continue;
292 float factorWidth = (barW - opad) / 2f;
296 factorWidth = (int) (barW * 0.6f);
299 TooltipMakerAPI mFac = main.beginSubTooltip(factorWidth);
303 mFac.addSectionHeading(
"Monthly factors", c, bg, Alignment.MID, opad).getPosition().setXAlignOffset(0);
309 "Monthly factors", factorWidth - strW - 3,
314 if (factor.isOneTime())
continue;
315 if (!factor.shouldShow(
this))
continue;
317 String desc = factor.getDesc(
this);
319 mFac.addRowWithGlow(Alignment.LMID, factor.getDescColor(
this), desc,
320 Alignment.RMID, factor.getProgressColor(
this), factor.getProgressStr(
this));
321 TooltipCreator t = factor.getMainRowTooltip(
this);
323 mFac.addTooltipToAddedRow(t, TooltipLocation.RIGHT,
false);
326 factor.addExtraRows(mFac,
this);
330 mFac.addTable(
"None", -1, opad);
331 mFac.getPrev().getPosition().setXAlignOffset(-5);
333 main.endSubTooltip();
335 TooltipMakerAPI oFac = main.beginSubTooltip(factorWidth);
337 oFac.addSectionHeading(
"Recent one-time factors", c, bg, Alignment.MID, opad).getPosition().setXAlignOffset(0);
340 "One-time factors", factorWidth - strW - 3,
344 List<EventFactor> reversed =
new ArrayList<EventFactor>(
factors);
345 Collections.reverse(reversed);
347 if (!factor.isOneTime())
continue;
348 if (!factor.shouldShow(
this))
continue;
350 String desc = factor.getDesc(
this);
352 oFac.addRowWithGlow(Alignment.LMID, factor.getDescColor(
this), desc,
353 Alignment.RMID, factor.getProgressColor(
this), factor.getProgressStr(
this));
354 TooltipCreator t = factor.getMainRowTooltip(
this);
356 oFac.addTooltipToAddedRow(t, TooltipLocation.LEFT);
359 factor.addExtraRows(oFac,
this);
362 oFac.addTable(
"None", -1, opad);
363 oFac.getPrev().getPosition().setXAlignOffset(-5);
364 main.endSubTooltip();
367 float factorHeight = Math.max(mFac.getHeightSoFar(), oFac.getHeightSoFar());
368 mFac.setHeightSoFar(factorHeight);
369 oFac.setHeightSoFar(factorHeight);
373 main.addCustom(mFac, opad * 2f);
374 main.addCustomDoNotSetPosition(oFac).getPosition().rightOfTop(mFac, opad);
376 main.addCustom(mFac, opad * 2f);
378 main.addCustom(oFac, opad * 2f);
383 panel.addUIElement(main).inTL(0, 0);
387 return new TooltipCreator() {
388 public boolean isTooltipExpandable(Object tooltipParam) {
391 public float getTooltipWidth(Object tooltipParam) {
395 public void createTooltip(TooltipMakerAPI tooltip,
boolean expanded, Object tooltipParam) {
397 Color h = Misc.getHighlightColor();
399 tooltip.addPara(
"Event progress: %s out of %s points.", 0f, h,
"" +
progress,
"" +
maxProgress);
401 String pStr =
"" + p;
402 if (p > 0) pStr =
"+" + p;
403 tooltip.addPara(
"Projected monthly progress: %s points.", opad,
getProgressColor(p), pStr);
405 tooltip.addPara(
"Event progress is influenced by various factors. Some of these apply over time, "
406 +
"and some only apply once. As the event progresses, "
407 +
"different stages and outcomes may unfold.", opad);
412 final EventStageData esd =
getDataFor(stageId);
413 if (esd ==
null || (esd.randomized && (esd.rollData ==
null ||
RANDOM_EVENT_NONE.equals(esd.rollData)))) {
414 return new TooltipCreator() {
415 public boolean isTooltipExpandable(Object tooltipParam) {
418 public float getTooltipWidth(Object tooltipParam) {
422 public void createTooltip(TooltipMakerAPI tooltip,
boolean expanded, Object tooltipParam) {
424 Color h = Misc.getHighlightColor();
426 tooltip.addPara(
"Something might occur when event progress reaches %s points. "
427 +
"What that is, if anything, will be determined when event progress reaches "
429 h,
"" + esd.progress,
"" + esd.progressToRollAt);
431 if (esd.isRepeatable) {
432 tooltip.addPara(
"This event is repeatable.", opad);
434 tooltip.addPara(
"This event is not repeatable.", opad);
468 TooltipMakerAPI info = main.beginImageWithText(icon, imageSize, width,
true);
471 if (info.getHeightSoFar() > 0) {
472 main.addImageWithText(opad).getPosition().setXAlignOffset(
indent);
473 main.addSpacer(0).getPosition().setXAlignOffset(-
indent);
483 EventStageDisplayData data =
new EventStageDisplayData();
497 if (esd ==
null || (esd.randomized && (esd.rollData ==
null ||
RANDOM_EVENT_NONE.equals(esd.rollData)))) {
498 if (esd.randomType == RandomizedStageType.GOOD) {
500 }
else if (esd.randomType == RandomizedStageType.BAD) {
514 if (esd !=
null && esd.iconSize == StageIconSize.SMALL)
return 32;
515 if (esd !=
null && esd.iconSize == StageIconSize.LARGE)
return 48;
524 if (esd !=
null && esd.iconSize == StageIconSize.SMALL)
return 48;
525 if (esd !=
null && esd.iconSize == StageIconSize.LARGE)
return 40;
550 return Misc.getHighlightColor();
556 if (
true)
return Misc.getBasePlayerColor();
561 Color color = Misc.getBasePlayerColor();
562 color = Misc.interpolateColor(color, Color.black, 0.25f);
571 color = Misc.interpolateColor(color, Color.black, 0.5f);
579 boolean grayItOut =
false;
580 if (last !=
null && esd !=
null && last != esd && !esd.isOneOffEvent &&
581 !esd.keepIconBrightWhenLaterStageReached &&
582 esd.progress < last.progress) {
586 if (esd !=
null && esd.randomized && esd.rollData !=
null) {
600 boolean grayItOut =
false;
601 if (last !=
null && esd !=
null && last != esd && !esd.isOneOffEvent &&
602 !esd.keepIconBrightWhenLaterStageReached &&
603 esd.progress < last.progress) {
607 if (esd !=
null && esd.randomized && esd.rollData !=
null) {
612 return new Color(255,255,255,155);
621 int min = Integer.MAX_VALUE;
622 for (EventStageData curr :
stages) {
623 int req = curr.progress;
629 if (stageId.equals(least)) {
635 return Misc.getHighlightColor();
640 Set<String> tags = super.getIntelTags(map);
641 tags.add(Tags.INTEL_MAJOR_EVENT);
678 if (data ==
null)
return false;
679 return data.id == stageId;
705 public void addStage(Object
id,
int progress,
boolean isOneOffEvent, StageIconSize iconSize) {
706 stages.add(
new EventStageData(
id,
progress, isOneOffEvent, iconSize));
711 if (data ==
null)
return false;
716 EventStageData last =
null;
717 int max = Integer.MIN_VALUE;
718 for (EventStageData curr :
stages) {
719 if (!includeOneOffEvents && curr.isOneOffEvent)
continue;
721 int req = curr.progress;
731 for (EventStageData curr :
stages) {
732 if (stageId.equals(curr.id))
return curr;
740 return data ==
null ? 0 : data.progress;
759 factor.notifyEventEnded();
766 super.notifyEnding();
774 factor.notifyEventEnding();
793 TextPanelAPI textPanel = dialog ==
null ? null : dialog.getTextPanel();
811 if (f.getClass() == c) {
824 List<EventFactor>
remove =
new ArrayList<EventFactor>();
826 if (c.isInstance(curr)) {
832 factor.notifyFactorRemoved();
849 if (factor.isOneTime())
continue;
850 total += factor.getProgress(
this);
851 mult *= factor.getAllProgressMult(
this);
855 float sign = Math.signum(total);
856 total = Math.round(sign * Math.abs(total) * mult);
857 if (total == 0) total = (int) Math.round(1f * sign);
875 float f = 1f / numIter;
880 int apply = (int) delta;
894 if (this.progress ==
progress)
return;
919 if (esd.wasEverReached && esd.isOneOffEvent && !esd.isRepeatable)
continue;
921 if (esd.randomized) {
927 if (esd.rollData ==
null) {
937 for (EventStageData curr :
getStages()) {
938 if (curr.progress <= prev.progress && !prev.wasEverReached &&
944 boolean laterThanPrev = prev ==
null || ((Enum)prev.id).ordinal() < ((Enum)curr.id).ordinal();
945 if (curr !=
null && (laterThanPrev || !prev.wasEverReached)) {
946 if (curr.sendIntelUpdateOnReaching && curr.progress > 0 && (prev ==
null || prev.progress < curr.progress)) {
950 curr.rollData =
null;
951 curr.wasEverReached =
true;
1004 return Misc.getPositiveHighlightColor();
1008 return Misc.getNegativeHighlightColor();
1011 return Misc.getHighlightColor();
1016 if (esd ==
null)
return;
1017 esd.hideIconWhenPastStageUnlessLastActive =
true;
1020 public void setRandomized(Object stageId, RandomizedStageType type,
int resetAt,
int rollAt,
boolean sendUpdateWhenReached) {
1021 setRandomized(stageId, type, resetAt, rollAt, sendUpdateWhenReached,
true);
1023 public void setRandomized(Object stageId, RandomizedStageType type,
int resetAt,
int rollAt,
boolean sendUpdateWhenReached,
boolean repeatable) {
1025 if (esd ==
null)
return;
1026 esd.sendIntelUpdateOnReaching = sendUpdateWhenReached;
1027 esd.isRepeatable = repeatable;
1028 esd.isOneOffEvent =
true;
1029 esd.randomized =
true;
1030 esd.rollData =
null;
1031 esd.progressToResetAt = resetAt;
1032 esd.progressToRollAt = rollAt;
1033 esd.randomType = type;
1045 stage.rollData =
null;
static SettingsAPI getSettings()
static SectorAPI getSector()
boolean isSendingUpdate()
void indent(TooltipMakerAPI info)
void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode)
static String getSoundStandardUpdate()
static String getSoundStandardPosting()
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
Object getListInfoParam()
static String getSoundMajorPosting()
FactionAPI getFactionForUIColors()
Color getTitleColor(ListInfoMode mode)
static float TOOLTIP_WIDTH
void addStageDescriptionText(TooltipMakerAPI info, float width, Object stageId)
void reportEconomyMonthEnd()
boolean putBarProgressIndicatorLabelOnRight()
float getImageSizeForStageDesc(Object stageId)
float getBarProgressIndicatorHeight()
Color getBarProgressIndicatorColor()
transient boolean prevProgressDeltaWasPositive
IntelSortTier getSortTier()
String getSoundForOtherUpdate(Object param)
EventFactor getFactorOfClass(Class c)
EventStageData getLastActiveStage(boolean includeOneOffEvents)
Color getStageLabelColor(Object stageId)
void setSortTier(IntelSortTier sortTier)
boolean hasLargeDescription()
void createLargeDescription(CustomPanelAPI panel, float width, float height)
void addFactor(EventFactor factor)
List< EventFactor > getFactors()
float getProgressFraction()
void addStageDescriptionWithImage(TooltipMakerAPI main, Object stageId)
String getSoundForStageReachedUpdate(Object stageId)
TooltipCreator getStageTooltip(Object stageId)
void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode)
String getStageLabel(Object stageId)
boolean withMonthlyFactors()
int getMaxMonthlyProgress()
List< EventStageData > getStages()
transient InteractionDialogAPI addingFactorDialog
TextPanelAPI getTextPanelForStageChange()
void resetRandomizedStage(EventStageData stage)
void advanceImpl(float amount)
Color getBaseStageColor(Object stageId)
Set< String > getIntelTags(SectorMapAPI map)
static final String RANDOM_EVENT_NONE
void addFactor(EventFactor factor, InteractionDialogAPI dialog)
String getStageIcon(Object stageId)
TooltipCreator getBarTooltip()
void setRandomized(Object stageId, RandomizedStageType type, int resetAt, int rollAt, boolean sendUpdateWhenReached, boolean repeatable)
Color getBarProgressIndicatorLabelColor()
void setHideStageWhenPastIt(Object stageId)
void addStage(Object id, int progress)
String getCommMessageSound()
Color getBarBracketColor()
boolean withOneTimeFactors()
void rollRandomizedStage(EventStageData stage)
void addStage(Object id, int progress, StageIconSize iconSize)
int getRequiredProgress(Object stageId)
float progressDeltaRemainder
Color getDarkStageColor(Object stageId)
boolean isStageActive(Object stageId)
boolean isEventProgressANegativeThingForThePlayer()
void setRandomized(Object stageId, RandomizedStageType type, int resetAt, int rollAt, boolean sendUpdateWhenReached)
int getStageImportance(Object stageId)
String getSoundForOneTimeFactorUpdate(EventFactor factor)
float getBarProgressIndicatorWidth()
void setMaxProgress(int maxProgress)
void removeFactorOfClass(Class< EventFactor > c)
EventStageData getDataFor(Object stageId)
void addStage(Object id, int progress, boolean isOneOffEvent, StageIconSize iconSize)
Color getProgressColor(int delta)
boolean isStageOrOneOffEventReached(Object stageId)
Color getStageColor(Object stageId)
void setProgress(int progress)
float getStageDownLineLength(Object stageId)
String getStageIconImpl(Object stageId)
Color getStageIconColor(Object stageId)
boolean addEventFactorBulletPoints(TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
void reportEconomyTick(int iterIndex)
boolean isStageActiveAndLast(Object stageId, boolean includeOneOffEvents)
List< EventStageData > stages
List< EventFactor > factors
TooltipCreator getStageTooltipImpl(Object stageId)
void removeFactor(EventFactor factor)
void setRandom(Random random)
void addStage(Object id, int progress, boolean isOneOffEvent)
EventStageDisplayData createDisplayData(Object stageId)
void notifyStageReached(EventStageData stage)
boolean isStageActiveAndLast(Object stageId)
boolean hasSmallDescription()
float getImageIndentForStageDesc(Object stageId)
float getStageIconSize(Object stageId)
String getSpriteName(String category, String id)
float getFloat(String key)
void notifyFactorRemoved()
int getProgress(BaseEventIntel intel)
void addBulletPointForOneTimeFactor(BaseEventIntel intel, TooltipMakerAPI info, Color tc, float initPad)