Starsector API
Loading...
Searching...
No Matches
WarningBeaconEntityPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.awt.Color;
4
5import org.lwjgl.util.vector.Vector2f;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignEngineLayers;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.CustomEntitySpecAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.campaign.SectorEntityToken.VisibilityLevel;
13import com.fs.starfarer.api.combat.ViewportAPI;
14import com.fs.starfarer.api.graphics.SpriteAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Pings;
16import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
17import com.fs.starfarer.api.impl.campaign.procgen.themes.RemnantThemeGenerator.RemnantSystemType;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19import com.fs.starfarer.api.util.Misc;
20
22
23 public static String GLOW_COLOR_KEY = "$core_beaconGlowColor";
24 public static String PING_COLOR_KEY = "$core_beaconPingColor";
25 public static String PING_ID_KEY = "$core_beaconPingId";
26 public static String PING_FREQ_KEY = "$core_beaconPingFreq";
27
28 public static float GLOW_FREQUENCY = 1f; // on/off cycles per second
29
30
31 //private SectorEntityToken entity;
32
33 transient private SpriteAPI sprite;
34 transient private SpriteAPI glow;
35
36 public void init(SectorEntityToken entity, Object pluginParams) {
37 super.init(entity, pluginParams);
38 //this.entity = entity;
39 entity.setDetectionRangeDetailsOverrideMult(0.75f);
40 readResolve();
41 }
42
43 Object readResolve() {
44 sprite = Global.getSettings().getSprite("campaignEntities", "warning_beacon");
45 glow = Global.getSettings().getSprite("campaignEntities", "warning_beacon_glow");
46 return this;
47 }
48
49 private float phase = 0f;
50 private float freqMult = 1f;
51 private float sincePing = 10f;
52 public void advance(float amount) {
53 phase += amount * GLOW_FREQUENCY * freqMult;
54 while (phase > 1) phase --;
55
56 if (entity.isInCurrentLocation()) {
57 sincePing += amount;
58 if (sincePing >= 6f && phase > 0.1f && phase < 0.2f) {
59 sincePing = 0f;
60 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
61 if (playerFleet != null &&
62 entity.getVisibilityLevelTo(playerFleet) == VisibilityLevel.COMPOSITION_AND_FACTION_DETAILS) {
63
64 String pingId = Pings.WARNING_BEACON1;
65 freqMult = 1f;
66 if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.SUPPRESSED.getBeaconFlag())) {
67 pingId = Pings.WARNING_BEACON2;
68 freqMult = 1.25f;
69 } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.RESURGENT.getBeaconFlag())) {
70 pingId = Pings.WARNING_BEACON3;
71 freqMult = 1.5f;
72 }
73
74 if (entity.getMemoryWithoutUpdate().contains(PING_ID_KEY)) {
75 pingId = entity.getMemoryWithoutUpdate().getString(PING_ID_KEY);
76 }
77 if (entity.getMemoryWithoutUpdate().contains(PING_FREQ_KEY)) {
78 freqMult = entity.getMemoryWithoutUpdate().getFloat(PING_FREQ_KEY);
79 }
80
81 //Global.getSector().addPing(entity, pingId);
82
83 //Color pingColor = entity.getFaction().getBrightUIColor();
84 Color pingColor = null;
85 if (entity.getMemoryWithoutUpdate().contains(PING_COLOR_KEY)) {
86 pingColor = (Color) entity.getMemoryWithoutUpdate().get(PING_COLOR_KEY);
87 }
88
89 Global.getSector().addPing(entity, pingId, pingColor);
90 }
91 }
92 }
93 }
94
95 public float getRenderRange() {
96 return entity.getRadius() + 100f;
97 }
98
99 public void render(CampaignEngineLayers layer, ViewportAPI viewport) {
100 float alphaMult = viewport.getAlphaMult();
101 alphaMult *= entity.getSensorFaderBrightness();
102 alphaMult *= entity.getSensorContactFaderBrightness();
103 if (alphaMult <= 0f) return;
104
105 CustomEntitySpecAPI spec = entity.getCustomEntitySpec();
106 if (spec == null) return;
107
108 float w = spec.getSpriteWidth();
109 float h = spec.getSpriteHeight();
110
111 Vector2f loc = entity.getLocation();
112
113 sprite.setAngle(entity.getFacing() - 90f);
114 sprite.setSize(w, h);
115 sprite.setAlphaMult(alphaMult);
116 sprite.setNormalBlend();
117 sprite.renderAtCenter(loc.x, loc.y);
118
119
120 float glowAlpha = 0f;
121 if (phase < 0.5f) glowAlpha = phase * 2f;
122 if (phase >= 0.5f) glowAlpha = (1f - (phase - 0.5f) * 2f);
123
124 float glowAngle1 = (((phase * 1.3f) % 1) - 0.5f) * 12f;
125 float glowAngle2 = (((phase * 1.9f) % 1) - 0.5f) * 12f;
126// glowAngle1 = 0f;
127// glowAngle2 = 0f;
128
129 boolean glowAsLayer = true;
130 if (glowAsLayer) {
131 //glow.setAngle(entity.getFacing() - 90f);
132 Color glowColor = new Color(255,200,0,255);
133 //Color glowColor = entity.getFaction().getBrightUIColor();
134 if (entity.getMemoryWithoutUpdate().contains(GLOW_COLOR_KEY)) {
135 glowColor = (Color) entity.getMemoryWithoutUpdate().get(GLOW_COLOR_KEY);
136 }
137
138 //glow.setColor(Color.white);
139 glow.setColor(glowColor);
140
141 glow.setSize(w, h);
142 glow.setAlphaMult(alphaMult * glowAlpha);
143 glow.setAdditiveBlend();
144
145 glow.setAngle(entity.getFacing() - 90f + glowAngle1);
146 glow.renderAtCenter(loc.x, loc.y);
147
148 glow.setAngle(entity.getFacing() - 90f + glowAngle2);
149 glow.setAlphaMult(alphaMult * glowAlpha * 0.5f);
150 glow.renderAtCenter(loc.x, loc.y);
151 } else {
152 glow.setAngle(entity.getFacing() - 90f);
153 glow.setColor(new Color(255,165,100));
154 float gs = w * 3;
155 glow.setSize(gs, gs);
156 glow.setAdditiveBlend();
157
158 float spacing = 10;
159 glow.setAlphaMult(alphaMult * glowAlpha * 0.5f);
160 glow.renderAtCenter(loc.x - spacing, loc.y);
161 glow.renderAtCenter(loc.x + spacing, loc.y);
162
163 glow.setAlphaMult(alphaMult * glowAlpha);
164 glow.setSize(gs * 0.25f, gs * 0.25f);
165 glow.renderAtCenter(loc.x - spacing, loc.y);
166 glow.renderAtCenter(loc.x + spacing, loc.y);
167 }
168 }
169
170 @Override
171 public void createMapTooltip(TooltipMakerAPI tooltip, boolean expanded) {
172 String post = "";
173 Color color = entity.getFaction().getBaseUIColor();
174 Color postColor = color;
175 if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.DESTROYED.getBeaconFlag())) {
176 post = " - Low";
177 postColor = Misc.getPositiveHighlightColor();
178 } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.SUPPRESSED.getBeaconFlag())) {
179 post = " - Medium";
180 postColor = Misc.getHighlightColor();
181 } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.RESURGENT.getBeaconFlag())) {
182 post = " - High";
183 postColor = Misc.getNegativeHighlightColor();
184 }
185
186 tooltip.addPara(entity.getName() + post, 0f, color, postColor, post.replaceFirst(" - ", ""));
187 }
188
189 @Override
190 public boolean hasCustomMapTooltip() {
191 return true;
192 }
193
194 @Override
195 public void appendToCampaignTooltip(TooltipMakerAPI tooltip, VisibilityLevel level) {
196 if (level == VisibilityLevel.COMPOSITION_AND_FACTION_DETAILS ||
197 level == VisibilityLevel.COMPOSITION_DETAILS) {
198
199 String post = "";
200 Color color = Misc.getTextColor();
201 Color postColor = color;
202 if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.DESTROYED.getBeaconFlag())) {
203 post = "low";
204 postColor = Misc.getPositiveHighlightColor();
205 } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.SUPPRESSED.getBeaconFlag())) {
206 post = "medium";
207 postColor = Misc.getHighlightColor();
208 } else if (entity.getMemoryWithoutUpdate().getBoolean(RemnantSystemType.RESURGENT.getBeaconFlag())) {
209 post = "high";
210 postColor = Misc.getNegativeHighlightColor();
211 }
212 if (!post.isEmpty()) {
213 tooltip.setParaFontDefault();
214 tooltip.addPara(BaseIntelPlugin.BULLET + "Danger level: " + post, 10f, color, postColor, post);
215 }
216 }
217
218 }
219}
220
221
222
223
224
225
226
227
228
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void render(CampaignEngineLayers layer, ViewportAPI viewport)
void appendToCampaignTooltip(TooltipMakerAPI tooltip, VisibilityLevel level)
void createMapTooltip(TooltipMakerAPI tooltip, boolean expanded)
void init(SectorEntityToken entity, Object pluginParams)
SpriteAPI getSprite(String filename)