001package com.fs.starfarer.api.ui;
002
003import java.util.List;
004import java.util.Set;
005
006import java.awt.Color;
007
008import com.fs.starfarer.api.campaign.CampaignFleetAPI;
009import com.fs.starfarer.api.campaign.CargoAPI;
010import com.fs.starfarer.api.campaign.FactionAPI;
011import com.fs.starfarer.api.campaign.PersonImportance;
012import com.fs.starfarer.api.campaign.PlanetAPI;
013import com.fs.starfarer.api.campaign.StarSystemAPI;
014import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
015import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
016import com.fs.starfarer.api.characters.PersonAPI;
017import com.fs.starfarer.api.combat.MutableStat;
018import com.fs.starfarer.api.combat.MutableStat.StatMod;
019import com.fs.starfarer.api.combat.StatBonus;
020import com.fs.starfarer.api.fleet.FleetMemberAPI;
021import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel;
022import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageDisplayData;
023import com.fs.starfarer.api.impl.codex.CodexEntryPlugin;
024import com.fs.starfarer.api.ui.ButtonAPI.UICheckboxSize;
025
026
027
028/**
029 * Not just for tooltips; used for normal UI elements as well.
030 * 
031 * @author Alex Mosolov
032 *
033 * Copyright 2018 Fractal Softworks, LLC
034 */
035public interface TooltipMakerAPI extends UIPanelAPI {
036        
037        public static enum TooltipLocation {
038                LEFT,
039                RIGHT,
040                ABOVE,
041                BELOW;
042        }
043        
044        public static interface ActionListenerDelegate {
045                void actionPerformed(Object data, Object source);
046        }
047        
048        public static class PlanetInfoParams {
049                public boolean scaleEvenWhenShowingName = false;
050                public boolean showName;
051                public boolean withClass;
052                public String classStrOverride = null;
053                public boolean showConditions;
054                public float conditionsYOffset = 0f;
055                public float conditionsHeight = 32f;
056                public boolean showHazardRating = false;
057        }
058        
059        public interface TooltipCreator {
060                boolean isTooltipExpandable(Object tooltipParam);
061                float getTooltipWidth(Object tooltipParam);
062                void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam);
063        }
064        
065        public interface StatModValueGetter {
066                String getFlatValue(StatMod mod);
067                String getPercentValue(StatMod mod);
068                String getMultValue(StatMod mod);
069                Color getModColor(StatMod mod);
070        }
071        
072        public interface FleetMemberValueGetter {
073                boolean skipMember(FleetMemberAPI member);
074                float getValue(FleetMemberAPI member);
075                String getDisplayValue(FleetMemberAPI member);
076                Color getValueColor(FleetMemberAPI member);
077        }
078        
079        LabelAPI addTitle(String text);
080        void setTitleFont(String titleFont);
081        void setTitleSmallOrbitron();
082        void setTitleFontColor(Color titleFontColor);
083        
084        void setParaFont(String paraFont);
085        void setParaFontColor(Color paraFontColor);
086        void setParaSmallInsignia();
087        
088        LabelAPI addPara(String format, float pad, Color hl, String... highlights);
089        LabelAPI addPara(String str, float pad);
090        LabelAPI addPara(String str, Color color, float pad);
091        LabelAPI addSectionHeading(String str, Alignment align, float pad);
092        LabelAPI addSectionHeading(String str, Color textColor, Color bgColor, Alignment align, float pad);
093        
094        void beginGrid(float itemWidth, int cols);
095        void beginGrid(float itemWidth, int cols, Color labelColor);
096        Object addToGrid(int x, int y, String label, String value);
097        Object addToGrid(int x, int y, String label, String value, Color valueColor);
098        void setGridLabelColor(Color nameColor);
099        void addGrid(float pad);
100        void beginGridFlipped(float itemWidth, int cols, float valueWidth, float valuePad);
101        void beginGridFlipped(float itemWidth, int cols, Color labelColor, float valueWidth, float valuePad);
102        void addStatModGrid(float width, float valueWidth, float valuePad, float pad, MutableStat stat);
103        void addStatModGrid(float width, float valueWidth, float valuePad, float pad, StatBonus stat);
104        void addStatGridForShips(float width, float valueWidth, float valuePad, float pad,
105                                                         CampaignFleetAPI fleet, int maxNum, boolean ascending,
106                                                         FleetMemberValueGetter getter);
107        void setGridFontDefault();
108        void setGridFont(String gridFont);
109        void addStatModGrid(float width, float valueWidth, float valuePad,
110                        float pad, MutableStat stat, StatModValueGetter getter);
111        void addStatModGrid(float width, float valueWidth, float valuePad,
112                        float pad, StatBonus stat, StatModValueGetter getter);
113        void setParaSmallOrbitron();
114        LabelAPI addTitle(String text, Color color);
115        void setParaFontVictor14();
116        
117        void addImage(String spriteName, float pad);
118        void addImage(String spriteName, float width, float pad);
119        void setParaFontDefault();
120        
121        void setParaOrbitronLarge();
122        void setParaOrbitronVeryLarge();
123        void setParaInsigniaLarge();
124        void setParaInsigniaVeryLarge();
125        void setTitleOrbitronLarge();
126        void setTitleOrbitronVeryLarge();
127        
128        void beginIconGroup();
129        void setIconSpacingMedium();
130        void setIconSpacingWide();
131        void addIcons(CommodityOnMarketAPI com, int num, IconRenderMode mode);
132        void addIcons(CommoditySpecAPI com, int num, IconRenderMode mode);
133        void addIconGroup(float pad);
134        void addIconGroup(float rowHeight, float pad);
135        void cancelGrid();
136        
137        /**
138         * Assumes a single icon, hacky.
139         * @param pad
140         */
141        void addIconGroupAndCenter(float pad);
142        void addStatModGrid(float width, float valueWidth, float valuePad, float pad, StatBonus stat, boolean showNonMods, StatModValueGetter getter);
143        
144        /**
145         * Sort is based on stack size.
146         * @param cargo
147         * @param max
148         * @param sort
149         * @param pad
150         */
151        void showCargo(CargoAPI cargo, int max, boolean sort, float pad);
152        void showShips(List<FleetMemberAPI> ships, int max, boolean sort, float pad);
153        
154        /**
155         * Columns are pairs of <string name> <Float|Integer width>
156         * @param faction
157         * @param itemHeight
158         * @param columns
159         */
160        UIPanelAPI beginTable(FactionAPI faction, float itemHeight, Object ... columns);
161        UIPanelAPI beginTable2(FactionAPI faction, float itemHeight, boolean withBorder, boolean withHeader, Object ... columns);       
162        
163        /**
164         * Columns are pairs of <string name> <Float|Integer width>
165         */
166        UIPanelAPI beginTable(Color base, Color dark, Color bright, float itemHeight, Object ... columns);
167        UIPanelAPI beginTable(Color base, Color dark, Color bright, float itemHeight, boolean withBorder, boolean withHeader, Object ... columns);
168        
169        /**
170         * Possible sets of data for a column:
171         * string |
172         * color, string |
173         * alignment, color, string |
174         * alignment, color, LabelAPI
175         * 
176         * @param data
177         */
178        Object addRow(Object ... data);
179        /**
180         * Possible sets of data for a column:
181         * string
182         * color, string
183         * alignment, color, string
184         * alignment, color, LabelAPI
185         * 
186         * @param data
187         */
188        Object addRowWithGlow(Object ... data);
189        void addTooltipToAddedRow(TooltipCreator tc, TooltipLocation loc);
190        void addTooltipToAddedRow(TooltipCreator tc, TooltipLocation loc, boolean recreateEveryFrame);
191        
192        void addTable(String emptyText, int andMore, float pad);
193        void setGridValueColor(Color valueColor);
194        
195        TooltipMakerAPI beginImageWithText(String spriteName, float imageHeight);
196        UIPanelAPI addImageWithText(float pad);
197        void addIconGroup(float rowHeight, int rows, float pad);
198        LabelAPI addPara(String format, float pad, Color color, Color hl, String ... highlights);
199        
200        void setButtonFontDefault();
201        void setButtonFontVictor10();
202        void setButtonFontVictor14();
203        ButtonAPI addButton(String text, Object data, float width, float height, float pad);
204        ButtonAPI addButton(String text, Object data, Color base, Color bg, float width, float height, float pad);
205        ButtonAPI addButton(String text, Object data, Color base, Color bg, Alignment align, CutStyle style, float width, float height, float pad);
206        void setBulletedListMode(String itemPrefix);
207        void setBulletWidth(Float bulletWidth);
208        
209        UIComponentAPI addCustom(UIComponentAPI comp, float pad);
210        String getBulletedListPrefix();
211        void addImage(String spriteName, float width, float height, float pad);
212        
213        float getTextWidthOverride();
214        void setTextWidthOverride(float textWidthOverride);
215        void addImages(float width, float height, float pad, float imagePad, String ... spriteNames);
216        void resetGridRowHeight();
217        void setLowGridRowHeight();
218        void setGridRowHeight(float gridSize);
219        
220        String shortenString(String in, float maxWidth);
221        void addStatModGrid(float width, float valueWidth, float valuePad,
222                        float pad, MutableStat stat, boolean showNonMods,
223                        StatModValueGetter getter);
224        void addShipList(int cols, int rows, float iconSize, Color baseColor, List<FleetMemberAPI> ships, float pad);
225        void setParaFontOrbitron();
226        LabelAPI addPara(String format, float pad, Color[] hl, String ... highlights);
227        UIComponentAPI addSpacer(float height);
228        void addStoryPointUseInfo(float pad, float bonusXPFraction, boolean withNoSPNotification);
229        void addStoryPointUseInfo(float pad, int numPoints, float bonusXPFraction, boolean withNoSPNotification);
230
231        void setForceProcessInput(boolean forceProcessInput);
232        
233        void addPlaythroughDataPanel(float width, float height);
234        void setBulletColor(Color bulletColor);
235        void addRelationshipBar(PersonAPI person, float pad);
236        void addRelationshipBar(PersonAPI person, float width, float pad);
237        void addRelationshipBar(FactionAPI faction, float pad);
238        void addRelationshipBar(FactionAPI faction, float width, float pad);
239        void addRelationshipBar(float value, float pad);
240        void addRelationshipBar(float value, float width, float pad);
241        void addImportanceIndicator(PersonImportance importance, float width, float pad);
242        void addTooltipToPrevious(TooltipCreator tc, TooltipLocation loc);
243        ButtonAPI addAreaCheckbox(String text, Object data, Color base, Color bg,
244                        Color bright, float width, float height, float pad);
245        void showShips(List<FleetMemberAPI> ships, int max, boolean sort, boolean showBaseHullForDHulls, float pad);
246        void setGridFontSmallInsignia();
247        void showFullSurveyReqs(PlanetAPI planet, boolean withText, float pad);
248        void showCost(String title, boolean withAvailable, float widthOverride, Color color, Color dark, float pad,
249                                  String[] res, int[] quantities, boolean[] consumed);
250        void showCost(String title, boolean withAvailable, Color color, Color dark, float pad, String[] res,
251                                  int[] quantities);
252        void showCost(Color color, Color dark, float pad, String[] res, int[] quantities);
253        void showCost(String title, boolean withAvailable, float widthOverride, float heightOverride, Color color,
254                        Color dark, float pad, String[] res, int[] quantities, boolean[] consumed);     
255        UIComponentAPI getPrev();
256        ButtonAPI addAreaCheckbox(String text, Object data, Color base, Color bg, Color bright, float width, float height,
257                        float pad, boolean leftAlign);
258        UIComponentAPI addSkillPanel(PersonAPI person, float pad);
259        UIComponentAPI addSkillPanelOneColumn(PersonAPI person, float pad);
260        float computeStringWidth(String in);
261        TextFieldAPI addTextField(float width, float pad);
262        TextFieldAPI addTextField(float width, String font, float pad);
263        TextFieldAPI addTextField(float width, float height, String font, float pad);
264        /**
265         * Use the method with the Object data param
266         */
267        @Deprecated ButtonAPI addCheckbox(float width, float height, String text, UICheckboxSize size, float pad);
268        /**
269         * Use the method with the Object data param
270         */
271        @Deprecated ButtonAPI addCheckbox(float width, float height, String text, String font, Color textColor, UICheckboxSize size,
272                        float pad);
273        void setAreaCheckboxFont(String areaCheckboxFont);
274        void setAreaCheckboxFontDefault();
275        UIComponentAPI addLabelledValue(String label, String value, Color labelColor, Color valueColor, float width, float pad);
276        float getHeightSoFar();
277        
278        /**
279         * Returns the intel UI; only works when creating small intel descriptions.
280         * @return
281         */
282        IntelUIAPI getIntelUI();
283        EventProgressBarAPI addEventProgressBar(BaseEventIntel intel, float pad);
284        
285        /**
286         * Add a custom component without appending it to the bottom of the tooltip. Will need to call one of the 
287         * .getPosition().inXXX methods to actually place it somewhere specific within the tooltip.
288         * @param comp
289         * @return
290         */
291        UIComponentAPI addCustomDoNotSetPosition(UIComponentAPI comp);
292        
293        UIComponentAPI addEventStageMarker(EventStageDisplayData data);
294        UIComponentAPI addEventProgressMarker(BaseEventIntel intel);
295        TooltipMakerAPI beginImageWithText(String spriteName, float imageHeight, float widthWithImage, boolean midAlignImage);
296        LabelAPI addSectionHeading(String str, Color textColor, Color bgColor, Alignment align, float width, float pad);
297        TooltipMakerAPI beginSubTooltip(float width);
298        /**
299         * Tooltip still needs to be added using addCustom() or similar.
300         */
301        void endSubTooltip();
302        void setHeightSoFar(float height);
303        
304        /**
305         * TODO: maps don't seem to work right if the tooltip is recreated every frame,
306         * for now make sure to use the addTooltipToPrevious method that takes a boolean to turn that off. 
307         */
308        UIPanelAPI createSectorMap(float w, float h, MapParams p, String title);
309        
310        /**
311         * TODO: maps don't seem to work right if the tooltip is recreated every frame,
312         * for now make sure to use the addTooltipToPrevious method that takes a boolean to turn that off. 
313         */
314        UIPanelAPI createSectorMap(float w, float h, MapParams p, String title, Color color, Color dark);
315        float getWidthSoFar();
316        void addTooltipToPrevious(TooltipCreator tc, TooltipLocation loc, boolean recreateEveryFrame);
317        
318        
319        /**
320         * Create a label without adding it to the tooltip, so it can be added via addCustom() or passed in to 
321         * a table row. Uses the current paragraph font.
322         */
323        LabelAPI createLabel(String str, Color color);
324        
325        /**
326         * Create a label without adding it to the tooltip, so it can be added via addCustom() or passed in to 
327         * a table row. Uses the current paragraph font.
328         */
329        LabelAPI createLabel(String str, Color color, float maxTextWidth);
330        void addTableHeaderTooltip(int colIndex, TooltipCreator tc);
331        void addTableHeaderTooltip(int colIndex, String text);
332        UIPanelAPI addSectorMap(float w, float h, StarSystemAPI system, float pad);
333        void addTooltipTo(TooltipCreator tc, UIComponentAPI to, TooltipLocation loc);
334        void addTooltipTo(TooltipCreator tc, UIComponentAPI to, TooltipLocation loc, boolean recreateEveryFrame);
335        UIComponentAPI createRect(Color color, float thickness);
336        
337        void makeTableItemsClickable();
338        /**
339         * To identify which row was clicked on.
340         * @param id
341         */
342        void setIdForAddedRow(Object id);
343        
344        
345        void setExternalScroller(ScrollPanelAPI scroller);
346        
347        /**
348         * Only non-null if this tooltip was added to a CustomPanelAPI using addUIElement().
349         * @return
350         */
351        ScrollPanelAPI getExternalScroller();
352
353        /**
354         * Default is 0.85f.
355         */
356        void setBgAlpha(float bgAlpha);
357        
358        void setButtonFontOrbitron20();
359        void setButtonFontOrbitron20Bold();
360        void setButtonFontOrbitron24();
361        void setButtonFontOrbitron24Bold();
362
363        void showPlanetInfo(PlanetAPI planet, float pad);
364        void showPlanetInfo(PlanetAPI planet, float w, float h, boolean withName, float pad);
365        void showPlanetInfo(PlanetAPI planet, float w, float h, PlanetInfoParams params, float pad);
366        
367        ButtonAPI addCheckbox(float width, float height, String text, Object data, UICheckboxSize size, float pad);
368        ButtonAPI addCheckbox(float width, float height, String text, Object data, String font, Color textColor,
369                        UICheckboxSize size, float pad);
370        UIComponentAPI addSkillPanel(PersonAPI person, boolean admin, float pad);
371        UIComponentAPI addSkillPanelOneColumn(PersonAPI person, boolean admin, float pad);
372        void addCodexEntries(String title, Set<String> entryIds, boolean sort, float pad);
373        
374        /**
375         * ID of codex entry to open with F2 when this tooltip is shown.
376         * Setting it to something and then back to null will not remove the "press F2" prompt etc.
377         * See: CodexDataV2.getXXXXEntryId() methods for how to get entry ids. 
378         * @param codexEntryId
379         */
380        void setCodexEntryId(String codexEntryId);
381        String getCodexEntryId();
382        void setCodexEntryFleetMember(FleetMemberAPI member);
383        void setCodexTempEntry(CodexEntryPlugin tempCodexEntry);
384        //UIPanelAPI beginTable(float itemHeight, Object[] columns);
385        LabelAPI addParaWithMarkup(String str, float pad);
386        LabelAPI addParaWithMarkup(String str, Color color, float pad);
387        LabelAPI addParaWithMarkup(String str, float pad, String... tokens);
388        
389        /**
390         * Markup:
391         * {{string}} -> highlights it
392         * {{color:<color>|string}} -> highlights it with color
393         * color can be h|good|bad|text|gray|blue or a color in settings.json
394         * If passing in tokens and needing to use a % in the base string: use %% (tokens means a String.format call)
395         * If NOT passing in tokens and needing to use a % in the base string: use % (no String.format call)
396         * 
397         * @param str
398         * @param color
399         * @param pad
400         * @param tokens
401         * @return
402         */
403        LabelAPI addParaWithMarkup(String str, Color color, float pad, String... tokens);
404        void showCargo(CargoAPI cargo, int max, boolean sort, float pad, float itemHeight, float itemPad);
405        
406        
407        /**
408         * Needs to be called *before* any methods that create UI elements 
409         * that call the action listener (such as addButton) are called.
410         * Warning: If the TooltipMakerAPI already has an action listener, it will be overridden.
411         * @param delegate
412         */
413        void setActionListenerDelegate(ActionListenerDelegate delegate);
414        
415        //LabelAPI addParaWithIndent(String text, Color color, float indent, String format, float pad, Color hl, String... highlights);
416}
417
418
419
420