27 private static enum OptionId {
37 private InteractionDialogAPI dialog;
38 private TextPanelAPI textPanel;
39 private OptionPanelAPI options;
40 private VisualPanelAPI visual;
42 private CampaignFleetAPI playerFleet;
43 private SectorEntityToken station;
47 public void init(InteractionDialogAPI dialog) {
49 textPanel = dialog.getTextPanel();
50 options = dialog.getOptionPanel();
51 visual = dialog.getVisualPanel();
54 station = (SectorEntityToken) dialog.getInteractionTarget();
57 visual.setVisualFade(0.25f, 0.25f);
61 dialog.setOptionOnEscape(
"Leave", OptionId.LEAVE);
70 private EngagementResultAPI lastResult =
null;
76 if (optionData ==
null)
return;
78 OptionId option = (OptionId) optionData;
82 dialog.addOptionSelectedText(option);
88 if (desc !=
null && desc.hasText3()) {
89 addText(desc.getText3());
91 addText(getString(
"approach"));
93 createInitialOptions();
94 if (station.getCustomInteractionDialogImageVisual() !=
null) {
95 visual.showImageVisual(station.getCustomInteractionDialogImageVisual());
97 if (station instanceof PlanetAPI) {
98 visual.showPlanetInfo(station);
101 visual.showImagePortion(
"illustrations",
"hound_hangar", 640, 400, 0, 0, 480, 300);
106 addText(getString(
"tradeCargo"));
107 options.clearOptions();
108 visual.showCore(CoreUITabId.CARGO, station,
this);
111 addText(getString(
"tradeShips"));
112 options.clearOptions();
113 visual.showCore(CoreUITabId.FLEET, station,
this);
116 addText(getString(
"refit"));
117 options.clearOptions();
118 visual.showCore(CoreUITabId.REFIT, station,
this);
122 createInitialOptions();
131 private void performRepairs() {
132 addText(getString(
"repair"));
133 float supplies = playerFleet.getCargo().getSupplies();
134 float needed = playerFleet.getLogistics().getTotalRepairAndRecoverySupplyCost();
136 textPanel.highlightLastInLastPara(
"" + (
int) needed, HIGHLIGHT_COLOR);
138 for (FleetMemberAPI member : playerFleet.getFleetData().getMembersListCopy()) {
139 member.getStatus().repairFully();
140 float max = member.getRepairTracker().getMaxCR();
141 float curr = member.getRepairTracker().getBaseCR();
143 member.getRepairTracker().applyCREvent(max - curr,
"Repaired at station");
147 playerFleet.getCargo().removeSupplies(needed);
148 playerFleet.getLogistics().updateRepairUtilizationForUI();
152 private void createInitialOptions() {
153 options.clearOptions();
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);
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);
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);
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);
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);
193 options.addOption(
"Leave", OptionId.LEAVE);
197 private OptionId lastOptionMousedOver =
null;
206 private void addText(String text) {
207 textPanel.addParagraph(text);
210 private void appendText(String text) {
211 textPanel.appendToLastParagraph(
" " + text);
214 private String getString(String
id) {
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";
224 str = str.replaceAll(
"\\$fleetOrShip", fleetOrShip);
225 str = str.replaceAll(
"\\$stationName", station.getName());
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));