1package com.fs.starfarer.api.impl.campaign.intel.events;
3import java.util.ArrayList;
4import java.util.Collections;
6import java.util.Random;
11import com.fs.starfarer.api.Global;
12import com.fs.starfarer.api.campaign.InteractionDialogAPI;
13import com.fs.starfarer.api.campaign.TextPanelAPI;
14import com.fs.starfarer.api.campaign.listeners.EconomyTickListener;
15import com.fs.starfarer.api.impl.campaign.ids.Tags;
16import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
17import com.fs.starfarer.api.ui.Alignment;
18import com.fs.starfarer.api.ui.CustomPanelAPI;
19import com.fs.starfarer.api.ui.EventProgressBarAPI;
20import com.fs.starfarer.api.ui.SectorMapAPI;
21import com.fs.starfarer.api.ui.TooltipMakerAPI;
22import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
23import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipLocation;
24import com.fs.starfarer.api.ui.UIComponentAPI;
25import com.fs.starfarer.api.util.Misc;
43 public static enum StageIconSize {
48 public static enum RandomizedStageType {
57 public static class EventStageDisplayData {
59 public float downLineLength;
62 public Color iconColor = Color.white;
64 public Color labelColor;
65 public int importance = 0;
68 public static class EventStageData {
71 public boolean isOneOffEvent;
72 public boolean wasEverReached =
false;
73 public boolean isRepeatable =
true;
74 public boolean sendIntelUpdateOnReaching =
true;
75 public boolean hideIconWhenPastStageUnlessLastActive =
false;
76 public boolean keepIconBrightWhenLaterStageReached =
false;
77 public StageIconSize iconSize = StageIconSize.MEDIUM;
79 public boolean randomized =
false;
80 public RandomizedStageType randomType = RandomizedStageType.NEUTRAL;
81 public int progressToResetAt;
82 public int progressToRollAt;
83 public Object rollData;
85 public EventStageData(Object
id,
int progress,
boolean isOneOffEvent) {
86 this(id, progress, isOneOffEvent, StageIconSize.MEDIUM);
88 public EventStageData(Object
id,
int progress,
boolean isOneOffEvent, StageIconSize iconSize) {
90 this.progress = progress;
91 this.isOneOffEvent = isOneOffEvent;
92 this.iconSize = iconSize;
96 tooltip.
addPara(
"Requires %s points of event progress.",
97 pad, Misc.getHighlightColor(),
"" + progress);
99 public void addResetReq(TooltipMakerAPI tooltip,
float pad) {
100 addResetReq(tooltip,
false, pad);
102 public void beginResetReqList(TooltipMakerAPI tooltip,
boolean withAvertInfo,
float initPad) {
103 beginResetReqList(tooltip, withAvertInfo,
"outcome", initPad);
105 public void beginResetReqList(TooltipMakerAPI tooltip,
boolean withAvertInfo, String outcome,
float initPad) {
108 tooltip.addPara(
"This " + outcome +
" will be averted if:", initPad);
111 tooltip.addPara(
"Event progress is reduced to %s points or below",
112 pad, Misc.getHighlightColor(),
"" + progressToResetAt);
116 public void endResetReqList(TooltipMakerAPI tooltip,
boolean withTriggeredResetInfo) {
117 endResetReqList(tooltip, withTriggeredResetInfo,
"outcome", -1, -1);
119 public void endResetReqList(TooltipMakerAPI tooltip,
boolean withTriggeredResetInfo, String outcome,
int min,
int max) {
120 tooltip.setBulletedListMode(
null);
121 if (withTriggeredResetInfo) {
123 if (min < 0 || max < 0) {
124 tooltip.addPara(
"If this " + outcome +
" is triggered, event progress will be reset to a much lower value afterwards.",
127 tooltip.addPara(
"If this " + outcome +
" is triggered, event progress will be reset to between %s and %s points.",
128 opad, Misc.getHighlightColor(),
"" + min,
"" + max);
133 public void addResetReq(TooltipMakerAPI tooltip,
boolean withResetIfTriggered,
float pad) {
134 addResetReq(tooltip, withResetIfTriggered,
"outcome", -1, -1, pad);
136 public void addResetReq(TooltipMakerAPI tooltip,
boolean withResetIfTriggered, String outcome,
int min,
int max,
float pad) {
137 if (withResetIfTriggered) {
138 if (min < 0 || max < 0) {
139 tooltip.addPara(
"This " + outcome +
" will be averted if event progress is reduced to %s points or below. "
140 +
"If this " + outcome +
" is triggered, event progress will be reset to a lower value afterwards.",
141 pad, Misc.getHighlightColor(),
"" + progressToResetAt);
143 tooltip.addPara(
"This " + outcome +
" will be averted if event progress is reduced to %s points or below. "
144 +
"If this " + outcome +
" is triggered, event progress will be reset to between %s and %s points.",
145 pad, Misc.getHighlightColor(),
"" + progressToResetAt,
"" + min,
"" + max);
148 tooltip.addPara(
"This " + outcome +
" will be averted if event progress is reduced to %s points or below.",
149 pad, Misc.getHighlightColor(),
"" + progressToResetAt);
158 protected List<EventStageData>
stages =
new ArrayList<EventStageData>();
161 protected List<EventFactor>
factors =
new ArrayList<EventFactor>();
180 super.advanceImpl(amount);
182 List<EventFactor>
remove =
new ArrayList<EventFactor>();
184 if (curr.isExpired()) {
189 curr.advance(amount);
191 if (curr.isExpired()) {
206 boolean large =
true;
215 Color tc,
float initPad) {
252 for (EventStageData curr :
stages) {
253 if (curr.progress <= 0)
continue;
256 if (curr.wasEverReached && curr.isOneOffEvent && !curr.isRepeatable)
continue;
258 if (curr.hideIconWhenPastStageUnlessLastActive &&
271 main.
addTooltipTo(tc, marker, TooltipLocation.LEFT,
false);
285 for (EventStageData curr :
stages) {
286 if (curr.wasEverReached && curr.isOneOffEvent && !curr.isRepeatable)
continue;
294 float factorWidth = (barW - opad) / 2f;
298 factorWidth = (int) (barW * 0.6f);
311 "Monthly factors", factorWidth - strW - 3,
316 if (factor.isOneTime())
continue;
317 if (!factor.shouldShow(
this))
continue;
319 String desc = factor.getDesc(
this);
322 Alignment.
RMID, factor.getProgressColor(
this), factor.getProgressStr(
this));
328 factor.addExtraRows(mFac,
this);
342 "One-time factors", factorWidth - strW - 3,
346 List<EventFactor> reversed =
new ArrayList<EventFactor>(
factors);
347 Collections.reverse(reversed);
349 if (!factor.isOneTime())
continue;
350 if (!factor.shouldShow(
this))
continue;
352 String desc = factor.getDesc(
this);
355 Alignment.
RMID, factor.getProgressColor(
this), factor.getProgressStr(
this));
361 factor.addExtraRows(oFac,
this);
390 public boolean isTooltipExpandable(Object tooltipParam) {
393 public float getTooltipWidth(Object tooltipParam) {
397 public void createTooltip(
TooltipMakerAPI tooltip,
boolean expanded, Object tooltipParam) {
403 String pStr =
"" + p;
404 if (p > 0) pStr =
"+" + p;
407 tooltip.
addPara(
"Event progress is influenced by various factors. Some of these apply over time, "
408 +
"and some only apply once. As the event progresses, "
409 +
"different stages and outcomes may unfold.", opad);
414 final EventStageData esd =
getDataFor(stageId);
415 if (esd ==
null || (esd.randomized && (esd.rollData ==
null ||
RANDOM_EVENT_NONE.equals(esd.rollData)))) {
417 public boolean isTooltipExpandable(Object tooltipParam) {
420 public float getTooltipWidth(Object tooltipParam) {
424 public void createTooltip(
TooltipMakerAPI tooltip,
boolean expanded, Object tooltipParam) {
428 tooltip.
addPara(
"Something might occur when event progress reaches %s points. "
429 +
"What that is, if anything, will be determined when event progress reaches "
431 h,
"" + esd.progress,
"" + esd.progressToRollAt);
433 if (esd.isRepeatable) {
434 tooltip.
addPara(
"This event is repeatable.", opad);
436 tooltip.
addPara(
"This event is not repeatable.", opad);
488 EventStageDisplayData data =
new EventStageDisplayData();
502 if (esd ==
null || (esd.randomized && (esd.rollData ==
null ||
RANDOM_EVENT_NONE.equals(esd.rollData)))) {
503 if (esd.randomType == RandomizedStageType.GOOD) {
505 }
else if (esd.randomType == RandomizedStageType.BAD) {
519 if (esd !=
null && esd.iconSize == StageIconSize.SMALL)
return 32;
520 if (esd !=
null && esd.iconSize == StageIconSize.LARGE)
return 48;
529 if (esd !=
null && esd.iconSize == StageIconSize.SMALL)
return 48;
530 if (esd !=
null && esd.iconSize == StageIconSize.LARGE)
return 40;
584 boolean grayItOut =
false;
585 if (last !=
null && esd !=
null && last != esd && !esd.isOneOffEvent &&
586 !esd.keepIconBrightWhenLaterStageReached &&
587 esd.progress < last.progress) {
591 if (esd !=
null && esd.randomized && esd.rollData !=
null) {
605 boolean grayItOut =
false;
606 if (last !=
null && esd !=
null && last != esd && !esd.isOneOffEvent &&
607 !esd.keepIconBrightWhenLaterStageReached &&
608 esd.progress < last.progress) {
612 if (esd !=
null && esd.randomized && esd.rollData !=
null) {
617 return new Color(255,255,255,155);
626 int min = Integer.MAX_VALUE;
627 for (EventStageData curr :
stages) {
628 int req = curr.progress;
634 if (stageId.equals(least)) {
645 Set<String> tags = super.getIntelTags(map);
683 if (data ==
null)
return false;
684 return data.id == stageId;
710 public void addStage(Object
id,
int progress,
boolean isOneOffEvent, StageIconSize iconSize) {
711 stages.add(
new EventStageData(
id,
progress, isOneOffEvent, iconSize));
716 if (data ==
null)
return false;
721 EventStageData last =
null;
722 int max = Integer.MIN_VALUE;
723 for (EventStageData curr :
stages) {
724 if (!includeOneOffEvents && curr.isOneOffEvent)
continue;
726 int req = curr.progress;
736 for (EventStageData curr :
stages) {
737 if (stageId.equals(curr.id))
return curr;
745 return data ==
null ? 0 : data.progress;
764 factor.notifyEventEnded();
771 super.notifyEnding();
779 factor.notifyEventEnding();
816 if (f.getClass() == c) {
829 List<EventFactor>
remove =
new ArrayList<EventFactor>();
831 if (c.isInstance(curr)) {
854 if (factor.isOneTime())
continue;
855 total += factor.getProgress(
this);
856 mult *= factor.getAllProgressMult(
this);
860 float sign = Math.signum(total);
861 total = Math.round(sign * Math.abs(total) * mult);
862 if (total == 0) total = (int) Math.round(1f * sign);
880 float f = 1f / numIter;
885 int apply = (int) delta;
899 if (this.progress ==
progress)
return;
924 if (esd.wasEverReached && esd.isOneOffEvent && !esd.isRepeatable)
continue;
926 if (esd.randomized) {
932 if (esd.rollData ==
null) {
942 for (EventStageData curr :
getStages()) {
943 if (curr.progress <= prev.progress && !prev.wasEverReached &&
949 boolean laterThanPrev = prev ==
null || ((Enum)prev.id).ordinal() < ((Enum)curr.id).ordinal();
950 if (curr !=
null && (laterThanPrev || !prev.wasEverReached)) {
951 if (curr.sendIntelUpdateOnReaching && curr.progress > 0 && (prev ==
null || prev.progress < curr.progress)) {
955 curr.rollData =
null;
956 curr.wasEverReached =
true;
1021 if (esd ==
null)
return;
1022 esd.hideIconWhenPastStageUnlessLastActive =
true;
1025 public void setRandomized(Object stageId, RandomizedStageType type,
int resetAt,
int rollAt,
boolean sendUpdateWhenReached) {
1026 setRandomized(stageId, type, resetAt, rollAt, sendUpdateWhenReached,
true);
1028 public void setRandomized(Object stageId, RandomizedStageType type,
int resetAt,
int rollAt,
boolean sendUpdateWhenReached,
boolean repeatable) {
1030 if (esd ==
null)
return;
1031 esd.sendIntelUpdateOnReaching = sendUpdateWhenReached;
1032 esd.isRepeatable = repeatable;
1033 esd.isOneOffEvent =
true;
1034 esd.randomized =
true;
1035 esd.rollData =
null;
1036 esd.progressToResetAt = resetAt;
1037 esd.progressToRollAt = rollAt;
1038 esd.randomType = type;
1050 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)
void afterStageDescriptions(TooltipMakerAPI main)
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)
static Color getNegativeHighlightColor()
static Color getBasePlayerColor()
static Color getHighlightColor()
static Color interpolateColor(Color from, Color to, float progress)
static Color getPositiveHighlightColor()
String getSpriteName(String category, String id)
float getFloat(String key)
TextPanelAPI getTextPanel()
void addScript(EveryFrameScript script)
void removeScript(EveryFrameScript script)
ListenerManagerAPI getListenerManager()
void addListener(Object listener)
void removeListener(Object listener)
void notifyFactorRemoved()
int getProgress(BaseEventIntel intel)
void addBulletPointForOneTimeFactor(BaseEventIntel intel, TooltipMakerAPI info, Color tc, float initPad)
TooltipMakerAPI createUIElement(float width, float height, boolean withScroller)
PositionAPI addUIElement(TooltipMakerAPI element)
float getXCoordinateForProgress(float progress)
PositionAPI getPosition()
PositionAPI inTL(float xPad, float yPad)
PositionAPI setXAlignOffset(float xAlignOffset)
PositionAPI aboveLeft(UIComponentAPI sibling, float yPad)
PositionAPI rightOfTop(UIComponentAPI sibling, float xPad)
PositionAPI belowLeft(UIComponentAPI sibling, float yPad)
PositionAPI getPosition()