Starsector API
Loading...
Searching...
No Matches
AbandonMarketPluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CoreUITabId;
7import com.fs.starfarer.api.campaign.FactionAPI;
8import com.fs.starfarer.api.campaign.InteractionDialogAPI;
9import com.fs.starfarer.api.campaign.RuleBasedDialog;
10import com.fs.starfarer.api.campaign.econ.AbandonMarketPlugin;
11import com.fs.starfarer.api.campaign.econ.MarketAPI;
12import com.fs.starfarer.api.campaign.listeners.ListenerUtil;
13import com.fs.starfarer.api.impl.campaign.intel.deciv.DecivTracker;
14import com.fs.starfarer.api.impl.campaign.rulecmd.FireAll;
15import com.fs.starfarer.api.impl.campaign.rulecmd.ShowDefaultVisual;
16import com.fs.starfarer.api.ui.LabelAPI;
17import com.fs.starfarer.api.ui.TooltipMakerAPI;
18import com.fs.starfarer.api.util.Misc;
19
20public class AbandonMarketPluginImpl extends BaseGenericPlugin implements AbandonMarketPlugin {
21
22 public static int MAX_SIZE = 4;
23 public static int COST_PER_SIZE_MINUS_2 = 50000;
24
25 public boolean canAbandon(MarketAPI market) {
26 return market.getSize() <= MAX_SIZE;// && market.getPlanetEntity() != null;
27 }
28
29 public int getAbandonCost(MarketAPI market) {
30 return Math.max(1, market.getSize() - 2) * COST_PER_SIZE_MINUS_2;
31 }
32
33 public void createAbandonButtonTooltip(TooltipMakerAPI info, float width, boolean expanded, MarketAPI market) {
34 info.addPara("Can only abandon colonies of size %s or smaller.", 0f,
35 Misc.getNegativeHighlightColor(), Misc.getHighlightColor(),
36 "" + MAX_SIZE);
37 }
38
39 public boolean isAbandonButtonTooltipExpandable(MarketAPI market) {
40 return false;
41 }
42
43 public boolean abandonButtonHasTooltip(MarketAPI market) {
44 return !canAbandon(market);
45 }
46
47
48 public void createConfirmationPrompt(MarketAPI market, TooltipMakerAPI prompt) {
49 float opad = 10f;
50
51 int cost = getAbandonCost(market);
52 int refund = Misc.computeTotalShutdownRefund(market);
53 int credits = (int) Global.getSector().getPlayerFleet().getCargo().getCredits().get();
54
55 Color h = Misc.getHighlightColor();
56 Color cc = h;
57
58 String costStr = "cost";
59 if (refund > cost) {
60 costStr = "payout";
61 }
62
63 if (cost - refund > credits) {
64 cc = Misc.getNegativeHighlightColor();
65 }
66
67// prompt.setParaFontDefault();
68// prompt.setParaSmallInsignia();
69
70 FactionAPI faction = market.getFaction();
71// LabelAPI label = prompt.addPara("You can abandon %s, a size %s colony, for a cost of %s in evacuation expenses.", 0f,
72// h, market.getName(), "" + market.getSize(), Misc.getDGSCredits(cost));
73 LabelAPI label = prompt.addPara("Abandoning %s, a size %s colony, requires %s in evacuation expenses. " +
74 "Shutting down all operations will generate %s credits, for a net " + costStr + " of %s.",
75 0f,
76 h,
77 market.getName(),
78 "" + market.getSize(),
79 Misc.getDGSCredits(cost),
80 Misc.getDGSCredits(refund),
81 Misc.getDGSCredits(Math.abs(cost - refund))
82 );
83 label.setHighlightColors(faction.getBaseUIColor(), h, h, h, cc);
84
85
86 prompt.addPara("You have %s credits.", opad, h, Misc.getDGSCredits(credits));
87
88 prompt.addPara("This action can not be undone. All items in storage and in use by industries will be lost.", opad);
89 }
90
91 public boolean isConfirmEnabled(MarketAPI market) {
92 int cost = getAbandonCost(market);
93 int refund = Misc.computeTotalShutdownRefund(market);
94
95 return Global.getSector().getPlayerFleet().getCargo().getCredits().get() >= (cost - refund);
96 }
97
98 public float getConfirmationPromptWidth(MarketAPI market) {
99 return 550f;
100 }
101
102 public void abandonConfirmed(MarketAPI market) {
103
104 int cost = getAbandonCost(market);
105 int refund = Misc.computeTotalShutdownRefund(market);
106
107 int diff = cost - refund;
108
109 Global.getSector().getPlayerFleet().getCargo().getCredits().subtract(diff);
110
111 if (diff > 0) {
112 Global.getSector().getCampaignUI().getMessageDisplay().addMessage(
113 String.format("Spent %s", Misc.getDGSCredits(diff)),
114 Misc.getTooltipTitleAndLightHighlightColor(), Misc.getDGSCredits(diff), Misc.getHighlightColor());
115 } else if (diff < 0) {
116 Global.getSector().getCampaignUI().getMessageDisplay().addMessage(
117 String.format("Received %s", Misc.getDGSCredits(-diff)),
118 Misc.getTooltipTitleAndLightHighlightColor(), Misc.getDGSCredits(-diff), Misc.getHighlightColor());
119 }
120
121 DecivTracker.removeColony(market, false);
122
123 ListenerUtil.reportPlayerAbandonedColony(market);
124
125 InteractionDialogAPI dialog = Global.getSector().getCampaignUI().getCurrentInteractionDialog();
126 if (dialog != null && dialog.getPlugin() instanceof RuleBasedDialog) {
127 //dialog.dismiss();
128 //dialog.getVisualPanel().closeCoreUI();
129 RuleBasedDialog rbd = ((RuleBasedDialog) dialog.getPlugin());
130 rbd.updateMemory();
131 market.getMemoryWithoutUpdate().unset("$tradeMode");
132 if (market.getPrimaryEntity() != null) {
133 market.getPrimaryEntity().getMemoryWithoutUpdate().unset("$tradeMode");
134 }
135 //FireBest.fire(null, dialog, rbd.getMemoryMap(), "OpenInteractionDialog");
136
137 new ShowDefaultVisual().execute(null, dialog, Misc.tokenize(""), rbd.getMemoryMap());
138
139 //FireAll.fire(null, dialog, memoryMap, "MarketPostOpen");
140 dialog.getInteractionTarget().getMemoryWithoutUpdate().set("$menuState", "main", 0);
141 dialog.getInteractionTarget().getMemoryWithoutUpdate().set("$tradeMode", "NONE", 0);
142 dialog.getInteractionTarget().getMemoryWithoutUpdate().unset("$hasMarket");
143 //FireAll.fire(null, dialog, rbd.getMemoryMap(), "PopulateOptions");
144
145 dialog.getVisualPanel().closeCoreUI();
146
147 rbd.updateMemory();
148 FireAll.fire(null, dialog, rbd.getMemoryMap(), "OpenInteractionDialog");
149 } else {
150 // if abandoned from command tab (rather than by interacting with colony), go back to colony list
151 Global.getSector().getCampaignUI().showCoreUITab(CoreUITabId.OUTPOSTS);
152 }
153 }
154
155}
156
157
158
159
160
161
static SectorAPI getSector()
Definition Global.java:59
void createConfirmationPrompt(MarketAPI market, TooltipMakerAPI prompt)
void createAbandonButtonTooltip(TooltipMakerAPI info, float width, boolean expanded, MarketAPI market)