Starsector API
Loading...
Searching...
No Matches
OrbitalStationInteractionDialogPluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.awt.Color;
4import java.util.Map;
5
6import org.lwjgl.input.Keyboard;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.CoreInteractionListener;
11import com.fs.starfarer.api.campaign.CoreUITabId;
12import com.fs.starfarer.api.campaign.InteractionDialogAPI;
13import com.fs.starfarer.api.campaign.InteractionDialogPlugin;
14import com.fs.starfarer.api.campaign.OptionPanelAPI;
15import com.fs.starfarer.api.campaign.PlanetAPI;
16import com.fs.starfarer.api.campaign.SectorEntityToken;
17import com.fs.starfarer.api.campaign.TextPanelAPI;
18import com.fs.starfarer.api.campaign.VisualPanelAPI;
19import com.fs.starfarer.api.campaign.rules.MemoryAPI;
20import com.fs.starfarer.api.combat.EngagementResultAPI;
21import com.fs.starfarer.api.fleet.FleetMemberAPI;
22import com.fs.starfarer.api.loading.Description;
23import com.fs.starfarer.api.loading.Description.Type;
24
26
27 private static enum OptionId {
28 INIT,
29 INIT_NO_TEXT,
30 TRADE_CARGO,
31 TRADE_SHIPS,
32 REFIT,
33 REPAIR_ALL,
34 LEAVE,
35 }
36
37 private InteractionDialogAPI dialog;
38 private TextPanelAPI textPanel;
39 private OptionPanelAPI options;
40 private VisualPanelAPI visual;
41
42 private CampaignFleetAPI playerFleet;
43 private SectorEntityToken station;
44
45 private static final Color HIGHLIGHT_COLOR = Global.getSettings().getColor("buttonShortcut");
46
47 public void init(InteractionDialogAPI dialog) {
48 this.dialog = dialog;
49 textPanel = dialog.getTextPanel();
50 options = dialog.getOptionPanel();
51 visual = dialog.getVisualPanel();
52
53 playerFleet = Global.getSector().getPlayerFleet();
54 station = (SectorEntityToken) dialog.getInteractionTarget();
55
56
57 visual.setVisualFade(0.25f, 0.25f);
58
59 //dialog.setTextHeight(100);
60
61 dialog.setOptionOnEscape("Leave", OptionId.LEAVE);
62
63 optionSelected(null, OptionId.INIT);
64 }
65
66 public Map<String, MemoryAPI> getMemoryMap() {
67 return null;
68 }
69
70 private EngagementResultAPI lastResult = null;
72 // no combat here, so this won't get called
73 }
74
75 public void optionSelected(String text, Object optionData) {
76 if (optionData == null) return;
77
78 OptionId option = (OptionId) optionData;
79
80 if (text != null) {
81 //textPanel.addParagraph(text, Global.getSettings().getColor("buttonText"));
82 dialog.addOptionSelectedText(option);
83 }
84
85 switch (option) {
86 case INIT:
88 if (desc != null && desc.hasText3()) {
89 addText(desc.getText3());
90 }
91 addText(getString("approach"));
92 case INIT_NO_TEXT:
93 createInitialOptions();
94 if (station.getCustomInteractionDialogImageVisual() != null) {
96 } else {
97 if (station instanceof PlanetAPI) {
98 visual.showPlanetInfo(station);
99 } else {
100 //visual.showImagePortion("illustrations", "hound_hangar", 1280, 800, 0, 0, 480, 300);
101 visual.showImagePortion("illustrations", "hound_hangar", 640, 400, 0, 0, 480, 300);
102 }
103 }
104 break;
105 case TRADE_CARGO:
106 addText(getString("tradeCargo"));
107 options.clearOptions();
108 visual.showCore(CoreUITabId.CARGO, station, this);
109 break;
110 case TRADE_SHIPS:
111 addText(getString("tradeShips"));
112 options.clearOptions();
113 visual.showCore(CoreUITabId.FLEET, station, this);
114 break;
115 case REFIT:
116 addText(getString("refit"));
117 options.clearOptions();
118 visual.showCore(CoreUITabId.REFIT, station, this);
119 break;
120 case REPAIR_ALL:
121 performRepairs();
122 createInitialOptions();
123 break;
124 case LEAVE:
125 Global.getSector().setPaused(false);
126 dialog.dismiss();
127 break;
128 }
129 }
130
131 private void performRepairs() {
132 addText(getString("repair"));
133 float supplies = playerFleet.getCargo().getSupplies();
134 float needed = playerFleet.getLogistics().getTotalRepairAndRecoverySupplyCost();
135
136 textPanel.highlightLastInLastPara("" + (int) needed, HIGHLIGHT_COLOR);
137
138 for (FleetMemberAPI member : playerFleet.getFleetData().getMembersListCopy()) {
139 member.getStatus().repairFully();
140 float max = member.getRepairTracker().getMaxCR();
141 float curr = member.getRepairTracker().getBaseCR();
142 if (max > curr) {
143 member.getRepairTracker().applyCREvent(max - curr, "Repaired at station");
144 }
145 }
146 if (needed > 0) {
147 playerFleet.getCargo().removeSupplies(needed);
149 }
150 }
151
152 private void createInitialOptions() {
153 options.clearOptions();
154
155
156 if (station.getFaction().isNeutralFaction()) {
157 options.addOption("Transfer cargo or personnel", OptionId.TRADE_CARGO);
158 options.setShortcut(OptionId.TRADE_CARGO, Keyboard.KEY_I, false, false, false, true);
159 options.addOption("Transfer ships to or from this station", OptionId.TRADE_SHIPS);
160 options.setShortcut(OptionId.TRADE_SHIPS, Keyboard.KEY_F, false, false, false, true);
161 options.addOption("Make use of the dockyard's refitting facilities", OptionId.REFIT);
162 options.setShortcut(OptionId.REFIT, Keyboard.KEY_R, false, false, false, true);
163 } else {
164 options.addOption("Trade, or hire personnel", OptionId.TRADE_CARGO);
165 options.setShortcut(OptionId.TRADE_CARGO, Keyboard.KEY_I, false, false, false, true);
166 options.addOption("Buy or sell ships", OptionId.TRADE_SHIPS, null);
167 options.setShortcut(OptionId.TRADE_SHIPS, Keyboard.KEY_F, false, false, false, true);
168 options.addOption("Make use of the dockyard's refitting facilities", OptionId.REFIT);
169 options.setShortcut(OptionId.REFIT, Keyboard.KEY_R, false, false, false, true);
170 }
171
172 if (station.getFaction().getRelationship(playerFleet.getFaction().getId()) >= 0) {
173 float needed = playerFleet.getLogistics().getTotalRepairAndRecoverySupplyCost();
174 float supplies = playerFleet.getCargo().getSupplies();
175 options.addOption("Repair your ships at the station's dockyard", OptionId.REPAIR_ALL);
176 options.setShortcut(OptionId.REPAIR_ALL, Keyboard.KEY_A, false, false, false, true);
177
178 if (needed <= 0) {
179 options.setEnabled(OptionId.REPAIR_ALL, false);
180 options.setTooltip(OptionId.REPAIR_ALL, getString("repairTooltipAlreadyRepaired"));
181 } else if (supplies < needed) {
182 options.setEnabled(OptionId.REPAIR_ALL, false);
183 options.setTooltip(OptionId.REPAIR_ALL, getString("repairTooltipNotEnough"));
184 options.setTooltipHighlightColors(OptionId.REPAIR_ALL, HIGHLIGHT_COLOR, HIGHLIGHT_COLOR);
185 options.setTooltipHighlights(OptionId.REPAIR_ALL, "" + (int) Math.ceil(needed), "" + (int) supplies);
186 } else {
187 options.setTooltip(OptionId.REPAIR_ALL, getString("repairTooltip"));
188 options.setTooltipHighlightColors(OptionId.REPAIR_ALL, HIGHLIGHT_COLOR, HIGHLIGHT_COLOR);
189 options.setTooltipHighlights(OptionId.REPAIR_ALL, "" + (int) Math.ceil(needed), "" + (int) supplies);
190 }
191 }
192
193 options.addOption("Leave", OptionId.LEAVE);
194 }
195
196
197 private OptionId lastOptionMousedOver = null;
198 public void optionMousedOver(String optionText, Object optionData) {
199
200 }
201
202 public void advance(float amount) {
203
204 }
205
206 private void addText(String text) {
207 textPanel.addParagraph(text);
208 }
209
210 private void appendText(String text) {
211 textPanel.appendToLastParagraph(" " + text);
212 }
213
214 private String getString(String id) {
215 String str = Global.getSettings().getString("stationInteractionDialog", id);
216
217 String fleetOrShip = "fleet";
218 if (playerFleet.getFleetData().getMembersListCopy().size() == 1) {
219 fleetOrShip = "ship";
220 if (playerFleet.getFleetData().getMembersListCopy().get(0).isFighterWing()) {
221 fleetOrShip = "fighter wing";
222 }
223 }
224 str = str.replaceAll("\\$fleetOrShip", fleetOrShip);
225 str = str.replaceAll("\\$stationName", station.getName());
226
227 float needed = playerFleet.getLogistics().getTotalRepairAndRecoverySupplyCost();
228 float supplies = playerFleet.getCargo().getSupplies();
229 str = str.replaceAll("\\$supplies", "" + (int) supplies);
230 str = str.replaceAll("\\$repairSupplyCost", "" + (int) Math.ceil(needed));
231
232 return str;
233 }
234
235
236 public Object getContext() {
237 return null;
238 }
239
240 public void coreUIDismissed() {
241 optionSelected(null, OptionId.INIT_NO_TEXT);
242 }
243}
244
245
246
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
Description getDescription(String id, Type type)
String getString(String category, String id)
List< FleetMemberAPI > getMembersListCopy()
void setOptionOnEscape(String text, Object optionId)
void setTooltip(Object data, String tooltipText)
void setTooltipHighlightColors(Object data, Color ... colors)
void setTooltipHighlights(Object data, String ... highlights)
void addOption(String text, Object data)
void setEnabled(Object data, boolean enabled)
void setShortcut(Object data, int code, boolean ctrl, boolean alt, boolean shift, boolean putLast)
InteractionDialogImageVisual getCustomInteractionDialogImageVisual()
void highlightLastInLastPara(String text, Color color)
void showCore(CoreUITabId tabId, SectorEntityToken other, boolean noCost, CoreInteractionListener listener)
void showPlanetInfo(SectorEntityToken planet)
void setVisualFade(float in, float out)
void showImagePortion(String category, String id, float x, float y, float w, float h, float xOffset, float yOffset, float displayWidth, float displayHeight)
void showImageVisual(InteractionDialogImageVisual visual)