001package com.fs.starfarer.api.impl.campaign.intel;
002
003import java.awt.Color;
004import java.util.Set;
005
006import org.lwjgl.input.Keyboard;
007
008import com.fs.starfarer.api.Global;
009import com.fs.starfarer.api.campaign.FactionAPI;
010import com.fs.starfarer.api.campaign.InteractionDialogAPI;
011import com.fs.starfarer.api.campaign.SectorEntityToken;
012import com.fs.starfarer.api.campaign.TextPanelAPI;
013import com.fs.starfarer.api.impl.campaign.ids.Factions;
014import com.fs.starfarer.api.impl.campaign.ids.Tags;
015import com.fs.starfarer.api.impl.campaign.intel.events.LuddicChurchHostileActivityFactor;
016import com.fs.starfarer.api.impl.campaign.rulecmd.HA_CMD;
017import com.fs.starfarer.api.ui.ButtonAPI;
018import com.fs.starfarer.api.ui.IntelUIAPI;
019import com.fs.starfarer.api.ui.SectorMapAPI;
020import com.fs.starfarer.api.ui.TooltipMakerAPI;
021import com.fs.starfarer.api.util.Misc;
022
023public class LuddicChurchImmigrationDeal extends BaseIntelPlugin {
024        
025        public static enum AgreementEndingType {
026                BROKEN,
027        }
028        
029        public static float REP_FOR_BREAKING_DEAL = 0.25f;
030        
031        public static String KEY = "$luddicChurchDeal_ref";
032        public static LuddicChurchImmigrationDeal get() {
033                return (LuddicChurchImmigrationDeal) Global.getSector().getMemoryWithoutUpdate().get(KEY);
034        }
035        
036        public static String BUTTON_END = "End";
037        
038        public static String UPDATE_PARAM_ACCEPTED = "update_param_accepted";
039        
040        protected FactionAPI faction = null;
041        protected AgreementEndingType endType = null;
042        
043        public LuddicChurchImmigrationDeal(InteractionDialogAPI dialog) {
044                this.faction = Global.getSector().getFaction(Factions.LUDDIC_CHURCH);
045                
046                setImportant(true);
047                LuddicChurchHostileActivityFactor.setMadeDeal(true);
048                
049                TextPanelAPI text = null;
050                if (dialog != null) text = dialog.getTextPanel();
051                
052                //Global.getSector().getListenerManager().addListener(this);
053                Global.getSector().getMemoryWithoutUpdate().set(KEY, this);
054                
055                Global.getSector().getIntelManager().addIntel(this, true);
056                
057                sendUpdate(UPDATE_PARAM_ACCEPTED, text);
058                
059                HA_CMD.avertOrEndKOLTakeoverAsNecessary();
060        }
061        
062        @Override
063        protected void notifyEnding() {
064                super.notifyEnding();
065                
066                LuddicChurchHostileActivityFactor.setMadeDeal(false);
067                Global.getSector().getMemoryWithoutUpdate().unset(KEY);
068        }
069        
070        @Override
071        protected void notifyEnded() {
072                super.notifyEnded();
073        }
074
075        protected Object readResolve() {
076                return this;
077        }
078        
079        public String getBaseName() {
080                return "Luddic Church Immigration Controls";
081        }
082
083        public String getAcceptedPostfix() {
084                return "Accepted";
085        }
086                
087        public String getBrokenPostfix() {
088                return "Ended";
089
090        }
091        
092        public String getName() {
093                String postfix = "";
094                if (isEnding() && endType != null) {
095                        switch (endType) {
096                        case BROKEN:
097                                postfix = " - " + getBrokenPostfix();
098                                break;
099                        }
100                }
101                if (isSendingUpdate() && getListInfoParam() == UPDATE_PARAM_ACCEPTED) {
102                        postfix =  " - " + getAcceptedPostfix();
103                }
104                return getBaseName() + postfix;
105        }
106        
107        @Override
108        public FactionAPI getFactionForUIColors() {
109                return faction;
110        }
111
112        public String getSmallDescriptionTitle() {
113                return getName();
114        }
115        
116        protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
117                Color h = Misc.getHighlightColor();
118                Color g = Misc.getGrayColor();
119                float pad = 3f;
120                float opad = 10f;
121                
122                float initPad = pad;
123                if (mode == ListInfoMode.IN_DESC) initPad = opad;
124                
125                Color tc = getBulletColorForMode(mode);
126                
127                bullet(info);
128                boolean isUpdate = getListInfoParam() != null;
129                
130//              if (getListInfoParam() == UPDATE_PARAM_ACCEPTED) {
131//                      return;
132//              }
133                
134                
135        
136                unindent(info);
137        }
138        
139        
140        public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
141                Color h = Misc.getHighlightColor();
142                Color g = Misc.getGrayColor();
143                Color tc = Misc.getTextColor();
144                float pad = 3f;
145                float opad = 10f;
146
147                info.addImage(getFaction().getLogo(), width, 128, opad);
148                
149                if (isEnding() || isEnded()) {
150                        info.addPara("You are no longer abiding by your agreement with the Luddic Church.", opad);
151                        return;
152                }
153                
154                info.addPara("You've made an agreement with the Luddic Church, curtailing "
155                                + "excessive immigration from their worlds. In exchange, the Knights of Ludd \"protector\" "
156                                + "fleets no longer operate in your volume.", 
157                                opad, faction.getBaseUIColor(), "Luddic Church", "Knights of Ludd");
158                
159                info.addPara("You can end this agreement, but there "
160                                + "would be no possibility of re-negotiating a similar agreement after "
161                                + "demonstrating such faithlessness.", opad);
162        
163                ButtonAPI button = info.addButton("End the agreement", BUTTON_END, 
164                                getFactionForUIColors().getBaseUIColor(), getFactionForUIColors().getDarkUIColor(),
165                                (int)(width), 20f, opad * 1f);
166                button.setShortcut(Keyboard.KEY_U, true);
167                
168        }
169        
170        
171        public String getIcon() {
172                return faction.getCrest();
173        }
174        
175        public Set<String> getIntelTags(SectorMapAPI map) {
176                Set<String> tags = super.getIntelTags(map);
177                tags.add(Tags.INTEL_AGREEMENTS);
178                tags.add(faction.getId());
179                return tags;
180        }
181        
182        @Override
183        public String getImportantIcon() {
184                return Global.getSettings().getSpriteName("intel", "important_accepted_mission");
185        }
186
187        @Override
188        public SectorEntityToken getMapLocation(SectorMapAPI map) {
189                return null;
190        }
191
192        
193        public FactionAPI getFaction() {
194                return faction;
195        }
196        
197        public void endAgreement(AgreementEndingType type, InteractionDialogAPI dialog) {
198                if (!isEnded() && !isEnding()) {
199                        endType = type;
200                        setImportant(false);
201                        //endAfterDelay();
202                        endImmediately();
203                        
204                        if (dialog != null) {
205                                sendUpdate(new Object(), dialog.getTextPanel());
206                        }
207
208                        if (type == AgreementEndingType.BROKEN) {
209                                LuddicChurchHostileActivityFactor.setBrokeDeal(true);
210                                Misc.incrUntrustwortyCount();
211                                TextPanelAPI text = dialog == null ? null : dialog.getTextPanel();
212                                Misc.adjustRep(Factions.LUDDIC_CHURCH, -REP_FOR_BREAKING_DEAL, text);
213                        }
214                }
215        }
216        
217        
218        @Override
219        public void buttonPressConfirmed(Object buttonId, IntelUIAPI ui) {
220                if (buttonId == BUTTON_END) {
221                        endAgreement(AgreementEndingType.BROKEN, null);
222                }
223                super.buttonPressConfirmed(buttonId, ui);
224        }
225
226
227        @Override
228        public void createConfirmationPrompt(Object buttonId, TooltipMakerAPI prompt) {
229                if (buttonId == BUTTON_END) {
230                        prompt.addPara("You can end this agreement, but taking this action would "
231                                        + "hurt your standing with the %s, and there "
232                                        + "would be no possibility of re-negotiating a similar agreement after "
233                                        + "demonstrating such faithlessness.", 0f,
234                                        faction.getBaseUIColor(), faction.getDisplayName());                            
235                }
236                        
237        }
238        
239        @Override
240        public boolean doesButtonHaveConfirmDialog(Object buttonId) {
241                if (buttonId == BUTTON_END) {
242                        return true;
243                }
244                return super.doesButtonHaveConfirmDialog(buttonId);
245        }
246        
247        
248}
249
250
251
252
253
254