Starsector API
Loading...
Searching...
No Matches
TestIndustryOptionProvider.java
Go to the documentation of this file.
1package com.fs.starfarer.api.campaign.listeners;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.BaseCustomDialogDelegate;
9import com.fs.starfarer.api.campaign.CustomDialogDelegate;
10import com.fs.starfarer.api.campaign.PlanetAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.campaign.StoryPointActionDelegate;
13import com.fs.starfarer.api.campaign.econ.Industry;
14import com.fs.starfarer.api.campaign.econ.Industry.IndustryTooltipMode;
15import com.fs.starfarer.api.impl.campaign.PlanetInteractionDialogPluginImpl;
16import com.fs.starfarer.api.impl.campaign.ids.Industries;
17import com.fs.starfarer.api.impl.campaign.ids.Sounds;
18import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption.BaseOptionStoryPointActionDelegate;
19import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption.StoryOptionParams;
20import com.fs.starfarer.api.ui.Alignment;
21import com.fs.starfarer.api.ui.CustomPanelAPI;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
24
26
27 public static Object INTERACTION_PLUGIN = new Object();
28 public static Object INTERACTION_TRIGGER = new Object();
29 public static Object CUSTOM_PLUGIN = new Object();
30 public static Object STORY_ACTION = new Object();
31 public static Object IMMEDIATE_ACTION = new Object();
32 public static Object DISABLED_OPTION = new Object();
33
34 @Override
35 public List<IndustryOptionData> getIndustryOptions(Industry ind) {
36 if (isUnsuitable(ind, false)) return null;
37
38
39 if (ind.getMarket().getId().equals("jangala") && ind.getId().equals(Industries.POPULATION)) {
40
41 List<IndustryOptionData> result = new ArrayList<IndustryOptionData>();
42
43 IndustryOptionData opt = new IndustryOptionData("Interaction dialog with plugin", INTERACTION_PLUGIN, ind, this);
44 opt.color = Color.GREEN;
45 result.add(opt);
46
47 opt = new IndustryOptionData("Interaction dialog with rule trigger", INTERACTION_TRIGGER, ind, this);
48 opt.color = Color.MAGENTA;
49 result.add(opt);
50
51 opt = new IndustryOptionData("Custom dialog plugin", CUSTOM_PLUGIN, ind, this);
52 opt.color = Color.ORANGE;
53 result.add(opt);
54
55 opt = new IndustryOptionData("Story point action dialog", STORY_ACTION, ind, this);
56 opt.color = Misc.getStoryOptionColor();
57 result.add(opt);
58
59 opt = new IndustryOptionData("Take an immediate action", IMMEDIATE_ACTION, ind, this);
60 opt.color = Color.RED;
61 result.add(opt);
62
63 opt = new IndustryOptionData("Disabled option", DISABLED_OPTION, ind, this);
64 opt.enabled = false;
65 result.add(opt);
66
67 return result;
68 }
69 return null;
70 }
71
72 @Override
73 public void createTooltip(IndustryOptionData opt, TooltipMakerAPI tooltip, float width) {
74 if (opt.id == INTERACTION_PLUGIN) {
75 tooltip.addPara("This option shows a standard interaction dialog with a custom plugin. "
76 + "In this case, the dialog used is the PlanetInteractionDialogPluginImpl,"
77 + " with Corvus - the star - as the target.", 0f);
78 } else if (opt.id == INTERACTION_TRIGGER) {
79 tooltip.addPara("This option shows a rule-driven interaction dialog. In this case, "
80 + "the dialog targets the Asharu Terraforming Platform and fires the "
81 + "OpenInteractionDialog trigger to start the interaction.", 0f);
82 } else if (opt.id == CUSTOM_PLUGIN) {
83 tooltip.addPara("This option shows a custom dialog driven by a CustomDialogDelegate implementation.", 0f);
84 } else if (opt.id == STORY_ACTION) {
85 tooltip.addPara("This option brings up a dialog where the player may spend some number "
86 + "of story points to perform an action, and possibly receive bonus experience.", 0f);
87 } else if (opt.id == IMMEDIATE_ACTION) {
88 tooltip.addPara("This option will not show a dialog but instead prints some text to standard out.", 0f);
89 } else if (opt.id == DISABLED_OPTION) {
90 tooltip.addPara("This option is disabled.", 0f);
91 }
92 }
93
94 @Override
96 if (opt.id == INTERACTION_PLUGIN) {
97 PlanetAPI planet = Global.getSector().getStarSystem("corvus").getStar();
99 // unpausing when exiting this dialog makes the outer interaction dialog
100 // (for the initial interaction with th market) unresponsive
101 // since this is not a valid thing to do anyway - the game should not be unpaused
102 // while the market dialog is open - the cause remains uninvestigated -am
103 plugin.setUnpauseOnExit(false);
104 ui.showDialog(planet, plugin);
105 } else if (opt.id == INTERACTION_TRIGGER) {
106 SectorEntityToken station = Global.getSector().getEntityById("corvus_abandoned_station");
107 ui.showDialog(station, "OpenInteractionDialog");
108 } else if (opt.id == CUSTOM_PLUGIN) {
110 @Override
111 public void createCustomDialog(CustomPanelAPI panel, CustomDialogCallback callback) {
112 TooltipMakerAPI info = panel.createUIElement(800f, 500f, false);
113 info.addPara("Minimalistic custom dialog implementation.", 0f);
114 panel.addUIElement(info).inTL(0, 0);
115 }
116
117 @Override
118 public boolean hasCancelButton() {
119 return true;
120 }
121
122 @Override
123 public void customDialogConfirm() {
124 System.out.println("customDialogConfirm() called");
125 }
126
127 @Override
128 public void customDialogCancel() {
129 System.out.println("customDialogCancel() called");
130 }
131 };
132 ui.showDialog(800f, 500f, delegate);
133 } else if (opt.id == STORY_ACTION) {
134 StoryOptionParams params = new StoryOptionParams(null, 1, "bonusXP_if_any_in_settings.json",
136 "Performed a test action in TestIndustryOptionProvider");
137 StoryPointActionDelegate delegate = new BaseOptionStoryPointActionDelegate(null, params) {
138 @Override
139 public void confirm() {
140 }
141
142 @Override
143 public String getTitle() {
144 return null;
145 }
146 @Override
147 public void createDescription(TooltipMakerAPI info) {
149 info.addPara("Test action that costs one story point.", -10f);
150 info.addSpacer(20f);
151 super.createDescription(info);
152 }
153 };
154 ui.showDialog(delegate);
155 } else if (opt.id == IMMEDIATE_ACTION) {
156 System.out.println("IMMEDIATE ACTION TAKEN");
157 }
158
159 }
160
161 @Override
162 public void addToIndustryTooltip(Industry ind, IndustryTooltipMode mode, TooltipMakerAPI tooltip, float width, boolean expanded) {
163 if (getIndustryOptions(ind) == null) return;
164
165 float opad = 10f;
166 tooltip.addSectionHeading("TestIndustryOptionProvider", Alignment.MID, opad);
167 tooltip.addPara("Information about changes made to the this industry by "
168 + "any of the custom options would go here.", opad);
169 }
170
171}
172
173
174
175
static SectorAPI getSector()
Definition Global.java:65
boolean isUnsuitable(Industry ind, boolean allowUnderConstruction)
void addToIndustryTooltip(Industry ind, IndustryTooltipMode mode, TooltipMakerAPI tooltip, float width, boolean expanded)
void createTooltip(IndustryOptionData opt, TooltipMakerAPI tooltip, float width)
static Color getStoryOptionColor()
Definition Misc.java:782
StarSystemAPI getStarSystem(String name)
SectorEntityToken getEntityById(String id)
void showDialog(SectorEntityToken target, InteractionDialogPlugin plugin)
TooltipMakerAPI createUIElement(float width, float height, boolean withScroller)
PositionAPI addUIElement(TooltipMakerAPI element)
PositionAPI inTL(float xPad, float yPad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)
LabelAPI addSectionHeading(String str, Alignment align, float pad)