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
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,
36 "" + MAX_SIZE);
37 }
38
40 return false;
41 }
42
43 public boolean abandonButtonHasTooltip(MarketAPI market) {
44 return !canAbandon(market);
45 }
46
47
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) {
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
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
110
111 if (diff > 0) {
113 String.format("Spent %s", Misc.getDGSCredits(diff)),
115 } else if (diff < 0) {
117 String.format("Received %s", Misc.getDGSCredits(-diff)),
119 }
120
121 DecivTracker.removeColony(market, false);
122
124
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
152 }
153 }
154
155}
156
157
158
159
160
161
static SectorAPI getSector()
Definition Global.java:65
static void reportPlayerAbandonedColony(MarketAPI colony)
void createConfirmationPrompt(MarketAPI market, TooltipMakerAPI prompt)
void createAbandonButtonTooltip(TooltipMakerAPI info, float width, boolean expanded, MarketAPI market)
static void removeColony(MarketAPI market, boolean withRuins)
static boolean fire(String ruleId, InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap, String params)
Definition FireAll.java:55
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
static String getDGSCredits(float num)
Definition Misc.java:1390
static int computeTotalShutdownRefund(MarketAPI market)
Definition Misc.java:5104
static Color getNegativeHighlightColor()
Definition Misc.java:802
static List< Token > tokenize(String string)
Definition Misc.java:425
static Color getHighlightColor()
Definition Misc.java:792
static Color getTooltipTitleAndLightHighlightColor()
Definition Misc.java:799
InteractionDialogAPI getCurrentInteractionDialog()
Map< String, MemoryAPI > getMemoryMap()
void set(String key, Object value)
void setHighlightColors(Color ... colors)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)