Starsector API
Loading...
Searching...
No Matches
GenericCampaignEntitySprite.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.awt.Color;
4
5import org.lwjgl.opengl.GL11;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.SectorEntityToken;
9import com.fs.starfarer.api.graphics.SpriteAPI;
10import com.fs.starfarer.api.impl.campaign.ids.Tags;
11import com.fs.starfarer.api.util.Misc;
12
14
15 //public static final float CELL_SIZE = 32;
16
18 protected SpriteAPI sprite;
19 protected SpriteAPI glow;
20 protected SpriteAPI overlay;
21 private float overlayAngleOffset = 0f;
22
23 private float scale;
24
25
27
28 public GenericCampaignEntitySprite(SectorEntityToken entity, String spriteName, float scale) {
29 this.entity = entity;
30 this.scale = scale;
31 sprite = Global.getSettings().getSprite(spriteName);
32
33 float width = sprite.getWidth() * scale;
34 float height = sprite.getHeight() * scale;
35 sprite.setSize(width, height);
36
37 shadowMask = Global.getSettings().getSprite("graphics/fx/ship_shadow_mask.png");
38 float max = Math.max(width, height);
39 shadowMask.setSize(max * 1.5f, max * 1.5f);
40 }
41
42 public SpriteAPI getGlow() {
43 return glow;
44 }
45
46 public void setGlow(SpriteAPI glow) {
47 this.glow = glow;
48 }
49
51 return overlay;
52 }
53
55 this.overlay = overlay;
56 }
57
58 public float getOverlayAngleOffset() {
59 return overlayAngleOffset;
60 }
61
62 public void setOverlayAngleOffset(float overlayAngleOffset) {
63 this.overlayAngleOffset = overlayAngleOffset;
64 }
65
66 public void render(float cx, float cy, float facing, float alphaMult) {
67 if (alphaMult <= 0) return;
68
69 GL11.glPushMatrix();
70 GL11.glTranslatef(entity.getLocation().x, entity.getLocation().y, 0);
71
73
74 if (lightSource != null && entity.getLightColor() != null) {
76 if (overlay != null) {
78 }
79 } else {
80 sprite.setColor(Color.white);
81 if (overlay != null) {
82 overlay.setColor(Color.white);
83 }
84 }
85
86 sprite.setAngle(facing - 90f);
88 sprite.setAlphaMult(alphaMult);
89 sprite.renderAtCenter(cx, cy);
90
91 if (glow != null) {
92 glow.setAngle(facing - 90f);
94 glow.setAlphaMult(alphaMult);
95 glow.renderAtCenter(cx, cy);
96 }
97
98 if (overlay != null) {
99// overlay.setAngle(facing - 90f);
100// overlay.setNormalBlend();
101// overlay.setAlphaMult(alphaMult);
102// overlay.renderAtCenter(cx, cy);
103
104 float w = overlay.getWidth() * 1.41f;
105 float h = w;
106
107 // clear out destination alpha in area we care about
108 GL11.glColorMask(false, false, false, true);
109 Misc.renderQuadAlpha(0 - w/2f - 1f, 0 - h/2f - 1f, w + 2f, h + 2f, Misc.zeroColor, 0f);
110
111 sprite.setBlendFunc(GL11.GL_ONE, GL11.GL_ZERO);
112 sprite.renderAtCenter(cx, cy);
113
114 overlay.setAlphaMult(alphaMult);
115 overlay.setAngle(facing - 90f + overlayAngleOffset);
116 overlay.setBlendFunc(GL11.GL_ZERO, GL11.GL_SRC_ALPHA);
117 overlay.renderAtCenter(cx, cy);
118
119 GL11.glColorMask(true, true, true, false);
120 overlay.setBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ONE_MINUS_DST_ALPHA);
121 overlay.renderAtCenter(cx, cy);
122 }
123
124 if (lightSource != null && !entity.getLightSource().hasTag(Tags.AMBIENT_LS)) {
125 float w = shadowMask.getWidth() * 1.41f;
126 float h = w;
127
128 // clear out destination alpha in area we care about
129 GL11.glColorMask(false, false, false, true);
130 Misc.renderQuadAlpha(0 - w/2f - 1f, 0 - h/2f - 1f, w + 2f, h + 2f, Misc.zeroColor, 0f);
131
132 sprite.setBlendFunc(GL11.GL_ONE, GL11.GL_ZERO);
133 sprite.renderAtCenter(cx, cy);
134
135 float lightDir = Misc.getAngleInDegreesStrict(entity.getLocation(), lightSource.getLocation());
136 shadowMask.setAlphaMult(alphaMult);
137 shadowMask.setAngle(lightDir);
138 shadowMask.setBlendFunc(GL11.GL_ZERO, GL11.GL_SRC_ALPHA);
140
141 GL11.glColorMask(true, true, true, false);
142 shadowMask.setBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ONE_MINUS_DST_ALPHA);
144 }
145
146 GL11.glPopMatrix();
147 }
148
149
150}
151
152
153
154
155
156
157
158
159
160
161
162
163
164
static SettingsAPI getSettings()
Definition Global.java:57
GenericCampaignEntitySprite(SectorEntityToken entity, String spriteName, float scale)
void render(float cx, float cy, float facing, float alphaMult)
static void renderQuadAlpha(float x, float y, float width, float height, Color color, float alphaMult)
Definition Misc.java:3111
static float getAngleInDegreesStrict(Vector2f v)
Definition Misc.java:1115
SpriteAPI getSprite(String filename)
void setSize(float width, float height)
void setBlendFunc(int src, int dest)
void renderAtCenter(float x, float y)