1package com.fs.starfarer.api.campaign.impl.items;
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.Comparator;
7import java.util.Iterator;
8import java.util.LinkedHashSet;
12import com.fs.starfarer.api.Global;
13import com.fs.starfarer.api.campaign.CargoStackAPI;
14import com.fs.starfarer.api.campaign.CargoTransferHandlerAPI;
15import com.fs.starfarer.api.campaign.FactionAPI;
16import com.fs.starfarer.api.campaign.econ.MarketAPI;
17import com.fs.starfarer.api.campaign.econ.SubmarketAPI;
18import com.fs.starfarer.api.combat.ShipHullSpecAPI;
19import com.fs.starfarer.api.graphics.SpriteAPI;
20import com.fs.starfarer.api.loading.FighterWingSpecAPI;
21import com.fs.starfarer.api.loading.WeaponSpecAPI;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
28 protected Set<String>
tags =
new LinkedHashSet<String>();
34 if (!param.isEmpty()) {
35 for (String tag : param.split(
",")) {
37 if (tag.isEmpty())
continue;
72 public void render(
float x,
float y,
float w,
float h,
float alphaMult,
76 if (sprite.getTextureId() == 0)
return;
86 float blX = cx - 12f - p;
87 float blY = cy - 22f - p;
88 float tlX = cx - 26f - p;
89 float tlY = cy + 19f + p;
90 float trX = cx + 20f + p;
91 float trY = cy + 24f + p;
92 float brX = cx + 34f + p;
93 float brY = cy - 9f - p;
98 boolean known =
areAllKnown(ships, weapons, fighters);
102 sprite.setAlphaMult(alphaMult * mult);
103 sprite.setNormalBlend();
104 sprite.renderWithCorners(blX, blY, tlX, tlY, trX, trY, brX, brY);
107 sprite.setAlphaMult(alphaMult * glowMult * 0.5f * mult);
108 sprite.setAdditiveBlend();
109 sprite.renderWithCorners(blX, blY, tlX, tlY, trX, trY, brX, brY);
114 alphaMult * 0.5f, 0f,
false);
121 public int getPrice(MarketAPI market, SubmarketAPI submarket) {
122 return super.getPrice(market, submarket);
127 return super.getName();
137 super.createTooltip(tooltip, expanded, transferHandler, stackSource);
142 Color h = Misc.getHighlightColor();
143 Color g = Misc.getGrayColor();
144 Color b = Misc.getButtonTextColor();
145 b = Misc.getPositiveHighlightColor();
154 float shipWeight = 0f;
155 float weaponWeight = 0f;
156 float fighterWeight = 0f;
160 float knownWeight = 0.25f;
161 for (String
id : ships) {
163 shipWeight += knownWeight;
168 for (String
id : weapons) {
170 weaponWeight += knownWeight;
175 for (String
id : fighters) {
177 fighterWeight += knownWeight;
183 float totalWeight = shipWeight + weaponWeight + fighterWeight;
184 if (totalWeight < knownWeight) totalWeight = knownWeight;
186 int maxShips = (int) Math.max(minPer, (shipWeight / totalWeight) * maxTotal);
187 int maxWeapons = (int) Math.max(minPer, (weaponWeight / totalWeight) * maxTotal);
188 int maxFighters = (int) Math.max(minPer, (fighterWeight / totalWeight) * maxTotal);
191 if (!ships.isEmpty()) {
192 addShipList(tooltip,
"Ship hulls:", ships, maxShips, opad);
194 if (!weapons.isEmpty()) {
195 addWeaponList(tooltip,
"Weapons:", weapons, maxWeapons, opad);
197 if (!fighters.isEmpty()) {
198 addFighterList(tooltip,
"Fighters:", fighters, maxFighters, opad);
202 addCostLabel(tooltip, opad, transferHandler, stackSource);
204 boolean known =
areAllKnown(ships, weapons, fighters);
206 tooltip.addPara(
"All blueprints in package already known", g, opad);
208 tooltip.addPara(
"Right-click to learn", b, opad);
212 protected boolean areAllKnown(List<String> ships, List<String> weapons, List<String> fighters) {
214 for (String hullId : ships) {
219 for (String weaponId : weapons) {
224 for (String wingId : fighters) {
234 return super.getTooltipWidth();
263 "All blueprints in package already known");
270 for (String
id : ships) {
274 for (String
id : weapons) {
278 for (String
id : fighters) {
285 "Acquired " + sCount +
" ship blueprints", Misc.getTooltipTitleAndLightHighlightColor(),
286 "" + sCount, Misc.getHighlightColor());
290 "Acquired " + wCount +
" weapon blueprints", Misc.getTooltipTitleAndLightHighlightColor(),
291 "" + wCount, Misc.getHighlightColor());
295 "Acquired " + fCount +
" fighter blueprints", Misc.getTooltipTitleAndLightHighlightColor(),
296 "" + fCount, Misc.getHighlightColor());
305 Iterator<WeaponSpecAPI> iter = specs.iterator();
313 if (!
tags.isEmpty()) {
314 iter = specs.iterator();
315 while (iter.hasNext()) {
316 WeaponSpecAPI curr = iter.next();
317 for (String tag :
tags) {
318 boolean not = tag.startsWith(
"!");
319 tag = not ? tag.substring(1) : tag;
320 boolean has = curr.hasTag(tag);
329 Collections.sort(specs,
new Comparator<WeaponSpecAPI>() {
330 public int compare(WeaponSpecAPI o1, WeaponSpecAPI o2) {
331 return o2.getSize().ordinal() - o1.getSize().ordinal();
335 List<String> result =
new ArrayList<String>();
336 for (WeaponSpecAPI
spec : specs) {
337 result.add(
spec.getWeaponId());
346 Iterator<ShipHullSpecAPI> iter = specs.iterator();
348 if (!
tags.isEmpty()) {
349 iter = specs.iterator();
350 while (iter.hasNext()) {
351 ShipHullSpecAPI curr = iter.next();
364 for (String tag :
tags) {
365 boolean not = tag.startsWith(
"!");
366 tag = not ? tag.substring(1) : tag;
367 boolean has = curr.hasTag(tag);
378 Collections.sort(specs,
new Comparator<ShipHullSpecAPI>() {
379 public int compare(ShipHullSpecAPI o1, ShipHullSpecAPI o2) {
380 return o2.getHullSize().ordinal() - o1.getHullSize().ordinal();
384 List<String> result =
new ArrayList<String>();
385 for (ShipHullSpecAPI
spec : specs) {
386 result.add(
spec.getHullId());
395 Iterator<FighterWingSpecAPI> iter = specs.iterator();
397 if (!
tags.isEmpty()) {
398 iter = specs.iterator();
399 while (iter.hasNext()) {
400 FighterWingSpecAPI curr = iter.next();
401 for (String tag :
tags) {
402 boolean not = tag.startsWith(
"!");
403 tag = not ? tag.substring(1) : tag;
404 boolean has = curr.hasTag(tag);
413 List<String> result =
new ArrayList<String>();
414 for (FighterWingSpecAPI
spec : specs) {
static SettingsAPI getSettings()
static SoundPlayerAPI getSoundPlayer()
static SectorAPI getSector()
void addCostLabel(TooltipMakerAPI tooltip, float pad, CargoTransferHandlerAPI transferHandler, Object stackSource)
void addWeaponList(TooltipMakerAPI tooltip, String title, List< String > weapons, int max, float opad)
void addShipList(TooltipMakerAPI tooltip, String title, List< String > hulls, int max, float opad)
void addFighterList(TooltipMakerAPI tooltip, String title, List< String > wings, int max, float opad)
List< String > getProvidedFighters()
void init(CargoStackAPI stack)
void performRightClickAction()
static List< String > getWeaponIds(Set< String > tags)
transient List< String > cachedWeapons
boolean areAllKnown(List< String > ships, List< String > weapons, List< String > fighters)
boolean isTooltipExpandable()
int getPrice(MarketAPI market, SubmarketAPI submarket)
void render(float x, float y, float w, float h, float alphaMult, float glowMult, SpecialItemRendererAPI renderer)
boolean hasRightClickAction()
List< String > getProvidedShips()
transient List< String > cachedFighters
static List< String > getWingIds(Set< String > tags)
static List< String > getShipIds(Set< String > tags)
List< String > getProvidedIndustries()
boolean shouldRemoveOnRightClickAction()
transient List< String > cachedShips
List< String > getProvidedWeapons()
void createTooltip(TooltipMakerAPI tooltip, boolean expanded, CargoTransferHandlerAPI transferHandler, Object stackSource)
List< WeaponSpecAPI > getAllWeaponSpecs()
List< ShipHullSpecAPI > getAllShipHullSpecs()
SpriteAPI getSprite(String filename)
List< FighterWingSpecAPI > getAllFighterWingSpecs()
SoundAPI playUISound(String id, float pitch, float volume)
boolean knowsWeapon(String weaponId)
void addKnownShip(String hullId, boolean setTimestamp)
void addKnownFighter(String wingId, boolean setTimestamp)
void addKnownWeapon(String weaponId, boolean setTimestamp)
boolean knowsFighter(String wingId)
boolean knowsShip(String hullId)
void renderScanlinesWithCorners(float blX, float blY, float tlX, float tlY, float trX, float trY, float brX, float brY, float alphaMult, boolean additive)
void renderBGWithCorners(Color bgColor, float blX, float blY, float tlX, float tlY, float trX, float trY, float brX, float brY, float alphaMult, float glowMult, boolean additive)