001package com.fs.starfarer.api.campaign.impl.items;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import java.awt.Color;
007
008import com.fs.starfarer.api.Global;
009import com.fs.starfarer.api.campaign.CargoTransferHandlerAPI;
010import com.fs.starfarer.api.campaign.SpecialItemData;
011import com.fs.starfarer.api.campaign.econ.Industry;
012import com.fs.starfarer.api.campaign.econ.InstallableIndustryItemPlugin.InstallableItemDescriptionMode;
013import com.fs.starfarer.api.impl.campaign.econ.impl.InstallableItemEffect;
014import com.fs.starfarer.api.impl.campaign.econ.impl.ItemEffectsRepo;
015import com.fs.starfarer.api.loading.IndustrySpecAPI;
016import com.fs.starfarer.api.ui.LabelAPI;
017import com.fs.starfarer.api.ui.TooltipMakerAPI;
018import com.fs.starfarer.api.util.Misc;
019
020public class GenericSpecialItemPlugin extends BaseSpecialItemPlugin {
021        
022        protected void addInstalledInSection(TooltipMakerAPI tooltip, float pad) {
023                String list = "";
024                String [] params = spec.getParams().split(",");
025                String [] array = new String[params.length];
026                int i = 0;
027                for (String curr : params) {
028                        curr = curr.trim();
029                        IndustrySpecAPI ind = Global.getSettings().getIndustrySpec(curr);
030                        if (ind == null) continue;
031                        list += ind.getName() + ", ";
032                        array[i] = ind.getName();
033                        i++;
034                }
035                if (!list.isEmpty()) {
036                        list = list.substring(0, list.length() - 2);
037                        tooltip.addPara(list, pad, 
038                                        Misc.getGrayColor(), Misc.getBasePlayerColor(), array);
039                                        //Misc.getGrayColor(), Misc.getHighlightColor(), array);
040                                        //Misc.getGrayColor(), Misc.getTextColor(), array);
041                }
042        }
043        
044        public static void addReqsSection(Industry industry, InstallableItemEffect effect, TooltipMakerAPI tooltip, boolean withRequiresText, float pad) {
045                List<String> reqs = effect.getRequirements(industry);
046                List<String> unmet = effect.getUnmetRequirements(industry);
047                
048                if (reqs == null) reqs = new ArrayList<String>();
049                if (unmet == null) unmet = new ArrayList<String>();
050                
051                Color [] hl = new Color[reqs.size()];
052                
053                int i = 0;
054                String list = "";
055                for (String curr : reqs) {
056                        list += curr + ", ";
057                        
058                        if (unmet.contains(curr)) {
059                                hl[i] = Misc.getNegativeHighlightColor();
060                        } else {
061                                hl[i] = Misc.getBasePlayerColor();
062                                //hl[i] = Misc.getHighlightColor();
063                                //hl[i] = Misc.getTextColor();
064                        }
065                        i++;
066                }
067                if (!list.isEmpty()) {
068                        list = list.substring(0, list.length() - 2);
069                        list = Misc.ucFirst(list);
070                        reqs.set(0, Misc.ucFirst(reqs.get(0)));
071                        
072                        float bulletWidth = 70f;
073                        if (withRequiresText) {
074                                tooltip.setBulletWidth(bulletWidth);
075                                tooltip.setBulletColor(Misc.getGrayColor());
076                                tooltip.setBulletedListMode("Requires:");
077                        }
078                        
079                        LabelAPI label = tooltip.addPara(list, Misc.getGrayColor(), pad);
080                        label.setHighlightColors(hl);
081                        label.setHighlight(reqs.toArray(new String[0]));
082                        
083                        if (withRequiresText) {
084                                tooltip.setBulletedListMode(null);
085                        }
086                }
087                
088        }
089        
090        public static void addSpecialNotesSection(Industry industry, InstallableItemEffect effect, TooltipMakerAPI tooltip, boolean withRequiresText, float pad) {
091                String name = effect.getSpecialNotesName();
092                if (name == null) return;
093                
094                List<String> reqs = effect.getSpecialNotes(industry);
095                if (reqs == null) return;
096
097                Color [] hl = new Color[reqs.size()];
098                
099                int i = 0;
100                String list = "";
101                for (String curr : reqs) {
102                        list += curr + ", ";
103                        hl[i] = Misc.getBasePlayerColor();
104                        i++;
105                }
106                if (!list.isEmpty()) {
107                        list = list.substring(0, list.length() - 2);
108                        list = Misc.ucFirst(list);
109                        reqs.set(0, Misc.ucFirst(reqs.get(0)));
110                        
111                        float bulletWidth = 70f;
112                        if (withRequiresText) {
113                                tooltip.setBulletWidth(bulletWidth);
114                                tooltip.setBulletColor(Misc.getGrayColor());
115                                tooltip.setBulletedListMode(name + ":");
116                        }
117                        
118                        LabelAPI label = tooltip.addPara(list, Misc.getGrayColor(), pad);
119                        label.setHighlightColors(hl);
120                        label.setHighlight(reqs.toArray(new String[0]));
121                        
122                        if (withRequiresText) {
123                                tooltip.setBulletedListMode(null);
124                        }
125                }
126                
127        }
128        
129        protected transient boolean tooltipIsForPlanetSearch = false;
130        public boolean isTooltipIsForPlanetSearch() {
131                return tooltipIsForPlanetSearch;
132        }
133        public void setTooltipIsForPlanetSearch(boolean tooltipIsForPlanetSearch) {
134                this.tooltipIsForPlanetSearch = tooltipIsForPlanetSearch;
135        }
136        
137
138        @Override
139        public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource) {
140                //super.createTooltip(tooltip, expanded, transferHandler, stackSource, false);
141                
142                // doing this in core code instead where it catches all special items not just colony ones
143//              if (!Global.CODEX_TOOLTIP_MODE) {
144//                      if (getSpec().hasTag(Items.TAG_COLONY_ITEM) || getSpec().hasTag(Tags.CODEX_UNLOCKABLE)) {
145//                              SharedUnlockData.get().reportPlayerAwareOfSpecialItem(getId(), true);
146//                      }
147//              }
148                
149                float pad = 0f;
150                float opad = 10f;
151                
152                if (!Global.CODEX_TOOLTIP_MODE) {
153                        tooltip.addTitle(getName());
154                } else {
155                        tooltip.addSpacer(-opad);
156                }
157                
158                LabelAPI design = null;
159                
160                if (!tooltipIsForPlanetSearch) {
161                        design = Misc.addDesignTypePara(tooltip, getDesignType(), opad);
162                }
163                
164                float bulletWidth = 86f;
165                if (design != null) {
166                        bulletWidth = design.computeTextWidth("Design type: ");
167                }
168                
169                InstallableItemEffect effect = ItemEffectsRepo.ITEM_EFFECTS.get(getId());
170                if (effect != null) {
171                        tooltip.setBulletWidth(bulletWidth);
172                        tooltip.setBulletColor(Misc.getGrayColor());
173                        
174                        tooltip.setBulletedListMode("Installed in:");
175                        addInstalledInSection(tooltip, opad);
176                        tooltip.setBulletedListMode("Requires:");
177                        addReqsSection(null, effect, tooltip, false, pad);
178                        if (effect.getSpecialNotesName() != null) {
179                                tooltip.setBulletedListMode(effect.getSpecialNotesName() + ":");
180                                addSpecialNotesSection(null, effect, tooltip, false, pad);
181                        }
182                        
183                        tooltip.setBulletedListMode(null);
184                        
185                        if (Global.CODEX_TOOLTIP_MODE) {
186                                tooltip.setParaSmallInsignia();
187                        }
188                        
189                        if (!tooltipIsForPlanetSearch) {
190                                if (!spec.getDesc().isEmpty()) {
191                                        Color c = Misc.getTextColor();
192                                        //if (useGray) c = Misc.getGrayColor();
193                                        tooltip.addPara(spec.getDesc(), c, opad);
194                                }
195                        }
196                        
197                        if (!tooltipIsForPlanetSearch) {
198                                effect.addItemDescription(null, tooltip, new SpecialItemData(getId(), null), InstallableItemDescriptionMode.CARGO_TOOLTIP);
199                        }
200                } else {
201                        if (!spec.getDesc().isEmpty() && !tooltipIsForPlanetSearch) {
202                                Color c = Misc.getTextColor();
203                                if (Global.CODEX_TOOLTIP_MODE) {
204                                        tooltip.setParaSmallInsignia();
205                                }
206                                tooltip.addPara(spec.getDesc(), c, opad);
207                        }
208                }
209                        
210                addCostLabel(tooltip, opad, transferHandler, stackSource);
211        }
212        
213}
214
215
216
217