001package com.fs.starfarer.api.ui;
002
003import java.awt.Color;
004import java.util.ArrayList;
005import java.util.HashSet;
006import java.util.List;
007import java.util.Set;
008
009import org.lwjgl.util.vector.Vector2f;
010
011import com.fs.starfarer.api.Global;
012import com.fs.starfarer.api.campaign.CampaignFleetAPI;
013import com.fs.starfarer.api.campaign.LocationAPI;
014import com.fs.starfarer.api.campaign.SectorEntityToken;
015import com.fs.starfarer.api.campaign.StarSystemAPI;
016import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
017import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ArrowData;
018import com.fs.starfarer.api.campaign.econ.MarketAPI;
019import com.fs.starfarer.api.impl.campaign.procgen.Constellation;
020import com.fs.starfarer.api.util.Misc;
021
022public class MapParams {
023        public static final float GRID_SIZE_MAP_UNITS = 2000;
024        public static final float GRID_SIZE_PIXELS = 75f;
025        
026        
027        public SectorEntityToken entityToShow;
028        
029        public MapFilterData filterData = null;
030        
031        public boolean smallConstellations = false;
032        public List<ArrowData> arrows = new ArrayList<IntelInfoPlugin.ArrowData>();
033        
034        public boolean showFilter = true;
035        public boolean smallFilter = false;
036        public boolean showTabs = true;
037        
038        public float starSelectionRadiusMult = 1f;
039        public float starAlphaMult = 1f;
040        public boolean useFullAlphaForShownSystems = false;
041        
042        public Color borderColor = null;
043        public boolean renderTopBorder = true;
044
045        public float maxZoomMapSizePadding = 4000f;
046        public float zoomLevel = 0f;
047        public LocationAPI location = null;
048        public Set<StarSystemAPI> showSystems = null;
049        public Set<Constellation> showConsellations = null;
050        public Vector2f centerOn = null;
051        
052        public List<MarkerData> markers = null;
053        public boolean withLayInCourse = false;
054        public boolean skipCurrLocMarkerRendering = false;
055        
056        
057        public MapParams() {
058                filterData = new MapFilterData(false);
059                showFilter = false;
060                smallFilter = true;
061                showTabs = false;
062                filterData.starscape = true;
063                filterData.names = true;
064                
065                //showSystems = new HashSet<StarSystemAPI>();
066                
067                starSelectionRadiusMult = 0.8f;
068                starAlphaMult = 0.5f;
069                
070                borderColor = Misc.getDarkPlayerColor();
071                renderTopBorder = true;
072                
073                location = Global.getSector().getHyperspace();
074                //skipCurrLocMarkerRendering = true;
075                
076                //markers = new ArrayList<MarkerData>();
077//              CampaignFleetAPI player = Global.getSector().getPlayerFleet();
078//              markers.add(new MarkerData(player.getLocationInHyperspace(), null, null));
079                
080                zoomLevel = 1f;
081                
082                Vector2f loc = Global.getSector().getPlayerFleet().getLocationInHyperspace();
083                centerOn = new Vector2f(loc);
084        }
085        
086        public void positionToShowAllMarkersAndSystems(boolean showPlayerFleet, float heightOnScreen) {
087                Vector2f center = new Vector2f();
088                float total = 0f;
089                CampaignFleetAPI player = Global.getSector().getPlayerFleet();
090                MarkerData playerMarker = null;
091                if (showPlayerFleet) {
092                        skipCurrLocMarkerRendering = true;
093                        if (markers == null) {
094                                markers = new ArrayList<MarkerData>();
095                        }
096                        playerMarker = new MarkerData(player.getLocationInHyperspace(), null, null);
097                        markers.add(playerMarker);
098//                      Vector2f.add(center, player.getLocationInHyperspace(), center);
099//                      total++;
100                }
101                
102                Vector2f min = new Vector2f();
103                Vector2f max = new Vector2f();
104                if (showSystems != null) {
105                        for (StarSystemAPI curr : showSystems) {
106                                Vector2f p = curr.getLocation();
107                                min.x = Math.min(min.x, p.x);
108                                min.y = Math.min(min.y, p.y);
109                                max.x = Math.max(max.x, p.x);
110                                max.y = Math.max(max.y, p.y);
111                                
112                                Vector2f.add(center, p, center);
113                                total++;
114                        }
115                }
116                
117                if (markers != null) {
118                        for (MarkerData curr : markers) {
119                                if (curr == playerMarker) continue;
120                                Vector2f p = curr.coordinates;
121                                min.x = Math.min(min.x, p.x);
122                                min.y = Math.min(min.y, p.y);
123                                max.x = Math.max(max.x, p.x);
124                                max.y = Math.max(max.y, p.y);
125                                
126                                Vector2f.add(center, p, center);
127                                total++;
128                        }
129                }
130                
131                if (total > 0) {
132                        center.scale(1f / total);
133                }
134                
135                float factor = GRID_SIZE_PIXELS / GRID_SIZE_MAP_UNITS;
136                float distance = Misc.getDistance(player.getLocationInHyperspace(), center);
137                Vector2f diff = Vector2f.sub(max, min, new Vector2f());
138                distance += diff.length() * 0.5f;
139                
140                distance *= 1.2f;
141                distance *= factor;
142                
143                float maxShown = heightOnScreen;
144                
145                float zoom = (float) (Math.ceil(distance / maxShown)) + 1;
146                if (zoom < 3) zoom = 3;
147                
148                zoomLevel = zoom;
149                
150                Vector2f loc = Misc.interpolateVector(Global.getSector().getPlayerFleet().getLocationInHyperspace(),
151                                                                                          center, 0.5f);
152                
153                centerOn = loc;
154                
155//              zoomLevel = 100;
156//              centerOn = new Vector2f();
157        }
158        
159        public void showSystem(StarSystemAPI system) {
160                if (showSystems == null) {
161                        showSystems = new HashSet<StarSystemAPI>();
162                }
163                showSystems.add(system);
164        }
165        
166        public void showMarket(MarketAPI market) {
167                float scale = 1f;
168                if (market != null && !market.isPlanetConditionMarketOnly()) {
169                        scale = MarkerData.getScaleForMarket(market);
170                }
171                showMarket(market, scale);
172        }
173        public void showMarket(MarketAPI market, float scale) {
174                if (markers == null) {
175                        markers = new ArrayList<MarkerData>();
176                }
177                
178                markers.add(new MarkerData(
179                                                market.getLocationInHyperspace(), 
180                                                null, 
181                                                market.getFaction().getBaseUIColor(), 
182                                                scale));
183        }
184}
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199