| 16 |
16 |
import android.graphics.Paint;
|
| 17 |
17 |
|
| 18 |
18 |
import org.distorted.library.effect.EffectQuality;
|
| 19 |
|
import org.distorted.library.effect.MatrixEffectMove;
|
| 20 |
|
import org.distorted.library.effect.MatrixEffectScale;
|
|
19 |
import org.distorted.library.effect.FragmentEffectAlpha;
|
| 21 |
20 |
import org.distorted.library.effect.PostprocessEffectGlow;
|
| 22 |
21 |
import org.distorted.library.effect.VertexEffectMove;
|
| 23 |
22 |
import org.distorted.library.effect.VertexEffectScale;
|
| ... | ... | |
| 30 |
29 |
import org.distorted.library.mesh.MeshQuad;
|
| 31 |
30 |
import org.distorted.library.message.EffectListener;
|
| 32 |
31 |
import org.distorted.library.type.Dynamic;
|
|
32 |
import org.distorted.library.type.Dynamic1D;
|
| 33 |
33 |
import org.distorted.library.type.Dynamic2D;
|
| 34 |
34 |
import org.distorted.library.type.Dynamic3D;
|
| 35 |
35 |
import org.distorted.library.type.Dynamic4D;
|
|
36 |
import org.distorted.library.type.Static1D;
|
| 36 |
37 |
import org.distorted.library.type.Static2D;
|
| 37 |
38 |
import org.distorted.library.type.Static3D;
|
| 38 |
39 |
import org.distorted.library.type.Static4D;
|
| ... | ... | |
| 44 |
45 |
|
| 45 |
46 |
public class OverlayStars extends OverlayGeneric implements EffectListener
|
| 46 |
47 |
{
|
|
48 |
private static final int DUR_APP = 1000;
|
| 47 |
49 |
private static final int DUR_MOV = 4000;
|
| 48 |
50 |
private static final int DUR_GLO = 2000;
|
| 49 |
51 |
|
| ... | ... | |
| 51 |
53 |
private static final int INDEX = 5;
|
| 52 |
54 |
|
| 53 |
55 |
private ListenerOverlay mListener;
|
| 54 |
|
private DistortedNode mStarsNode, mCountNode;
|
|
56 |
private DistortedNode mNode;
|
| 55 |
57 |
private DistortedScreen mScreen;
|
| 56 |
|
private DistortedTexture mStarsTexture, mCountTexture;
|
| 57 |
|
private Bitmap mCountBitmap;
|
|
58 |
private DistortedTexture mTexture;
|
|
59 |
private Bitmap mCountBitmap, mStarBitmap;
|
| 58 |
60 |
private Canvas mCountCanvas;
|
| 59 |
61 |
private Paint mPaint;
|
| 60 |
62 |
private int mBmpW, mBmpH;
|
| 61 |
63 |
private float mWidth, mHeight;
|
| 62 |
64 |
private Random mRandom;
|
| 63 |
|
private long mMoveID, mGlowID;
|
|
65 |
private long mMoveID, mGlowID, mAlphaID;
|
| 64 |
66 |
private int mTotalStars, mNewStars;
|
|
67 |
private FragmentEffectAlpha mAlpha;
|
|
68 |
private Dynamic1D mAlphaStrength;
|
| 65 |
69 |
|
| 66 |
70 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 67 |
71 |
|
| ... | ... | |
| 90 |
94 |
|
| 91 |
95 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 92 |
96 |
|
| 93 |
|
private DistortedNode createStarsNode(Resources res)
|
|
97 |
private void createAlphaEffect(boolean appear)
|
|
98 |
{
|
|
99 |
if( mAlpha==null )
|
|
100 |
{
|
|
101 |
mAlphaStrength = new Dynamic1D();
|
|
102 |
mAlphaStrength.setMode(Dynamic.MODE_PATH);
|
|
103 |
mAlphaStrength.setDuration(DUR_APP);
|
|
104 |
mAlphaStrength.setCount(0.5f);
|
|
105 |
equipAlpha(mAlphaStrength,appear);
|
|
106 |
mAlpha = new FragmentEffectAlpha(mAlphaStrength);
|
|
107 |
}
|
|
108 |
else
|
|
109 |
{
|
|
110 |
mAlphaStrength.resetToBeginning();
|
|
111 |
equipAlpha(mAlphaStrength,appear);
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
116 |
|
|
117 |
private void equipAlpha(Dynamic1D alpha, boolean appear)
|
|
118 |
{
|
|
119 |
Static1D point0 = new Static1D(0.0f);
|
|
120 |
Static1D point1 = new Static1D(1.0f);
|
|
121 |
|
|
122 |
alpha.removeAll();
|
|
123 |
|
|
124 |
if( appear )
|
|
125 |
{
|
|
126 |
alpha.add(point0);
|
|
127 |
alpha.add(point1);
|
|
128 |
}
|
|
129 |
else
|
|
130 |
{
|
|
131 |
alpha.add(point1);
|
|
132 |
alpha.add(point0);
|
|
133 |
}
|
|
134 |
}
|
|
135 |
|
|
136 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
137 |
|
|
138 |
private DistortedNode createNode(Resources res, int numStars)
|
| 94 |
139 |
{
|
| 95 |
140 |
// texture /////////////////////////////////////////////////////
|
| 96 |
|
if( mStarsTexture==null )
|
|
141 |
if( mTexture==null )
|
| 97 |
142 |
{
|
| 98 |
|
mStarsTexture = new DistortedTexture();
|
| 99 |
|
Bitmap star = BitmapFactory.decodeResource(res, R.drawable.star);
|
| 100 |
|
mBmpW = star.getWidth();
|
| 101 |
|
mBmpH = star.getHeight();
|
| 102 |
|
mStarsTexture.setTexture(star);
|
|
143 |
mTexture = new DistortedTexture();
|
|
144 |
mStarBitmap = BitmapFactory.decodeResource(res, R.drawable.star);
|
|
145 |
mBmpW = mStarBitmap.getWidth();
|
|
146 |
mBmpH = mStarBitmap.getHeight();
|
|
147 |
mCountBitmap = Bitmap.createBitmap(2*mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
|
|
148 |
mCountCanvas = new Canvas(mCountBitmap);
|
|
149 |
mPaint = new Paint();
|
|
150 |
mPaint.setColor(0xff000000);
|
|
151 |
mPaint.setTextSize(mBmpH*0.28f);
|
|
152 |
mPaint.setAntiAlias(true);
|
|
153 |
mPaint.setTextAlign(Paint.Align.CENTER);
|
|
154 |
renderStars(numStars);
|
| 103 |
155 |
}
|
| 104 |
156 |
|
| 105 |
157 |
// mesh ////////////////////////////////////////////////////////
|
| 106 |
158 |
MeshQuad[] mesh = new MeshQuad[mNewStars+1];
|
| 107 |
159 |
|
|
160 |
Static4D[] mapMain = new Static4D[1];
|
|
161 |
Static4D[] mapStar = new Static4D[1];
|
|
162 |
|
|
163 |
mapMain[0] = new Static4D(0.5f,0.0f,0.5f,1.0f);
|
|
164 |
mapStar[0] = new Static4D(0.0f,0.0f,0.5f,1.0f);
|
|
165 |
|
| 108 |
166 |
for(int i=0; i<mNewStars+1; i++)
|
| 109 |
167 |
{
|
| 110 |
168 |
mesh[i] = new MeshQuad();
|
| 111 |
|
mesh[i].setEffectAssociation(0,(i>=mNewStars?2:1),i);
|
|
169 |
|
|
170 |
if( i>=mNewStars )
|
|
171 |
{
|
|
172 |
mesh[i].setEffectAssociation(0,2,i);
|
|
173 |
mesh[i].setTextureMap(mapMain,0);
|
|
174 |
}
|
|
175 |
else
|
|
176 |
{
|
|
177 |
mesh[i].setEffectAssociation(0,1,i);
|
|
178 |
mesh[i].setTextureMap(mapStar,0);
|
|
179 |
}
|
| 112 |
180 |
}
|
| 113 |
181 |
|
| 114 |
182 |
MeshJoined wholeMesh = new MeshJoined(mesh);
|
| ... | ... | |
| 148 |
216 |
effects.apply(mainMove);
|
| 149 |
217 |
effects.apply(mainScale);
|
| 150 |
218 |
|
| 151 |
|
return new DistortedNode(mStarsTexture,effects,wholeMesh);
|
|
219 |
createAlphaEffect(true);
|
|
220 |
effects.apply(mAlpha);
|
|
221 |
|
|
222 |
return new DistortedNode(mTexture,effects,wholeMesh);
|
| 152 |
223 |
}
|
| 153 |
224 |
|
| 154 |
225 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| ... | ... | |
| 156 |
227 |
private void renderStars(int numStars)
|
| 157 |
228 |
{
|
| 158 |
229 |
String txt = ""+numStars;
|
| 159 |
|
mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*0.64f,mPaint);
|
| 160 |
|
mCountTexture.setTexture(mCountBitmap);
|
| 161 |
|
}
|
| 162 |
|
|
| 163 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 164 |
|
|
| 165 |
|
private DistortedNode createCountNode()
|
| 166 |
|
{
|
| 167 |
|
// texture /////////////////////////////////////////////////////
|
| 168 |
|
if( mCountTexture==null )
|
| 169 |
|
{
|
| 170 |
|
mCountTexture = new DistortedTexture();
|
| 171 |
|
|
| 172 |
|
mCountBitmap = Bitmap.createBitmap(mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
|
| 173 |
|
mCountCanvas = new Canvas(mCountBitmap);
|
| 174 |
|
mPaint = new Paint();
|
| 175 |
|
mPaint.setColor(0xff000000);
|
| 176 |
|
mPaint.setTextSize(mBmpH*0.28f);
|
| 177 |
|
mPaint.setAntiAlias(true);
|
| 178 |
|
mPaint.setTextAlign(Paint.Align.CENTER);
|
| 179 |
|
renderStars(mTotalStars);
|
| 180 |
|
}
|
| 181 |
|
|
| 182 |
|
// mesh ////////////////////////////////////////////////////////
|
| 183 |
|
MeshQuad mesh = new MeshQuad();
|
| 184 |
|
|
| 185 |
|
// effects: main ///////////////////////////////////////////////
|
| 186 |
|
DistortedEffects effects = new DistortedEffects();
|
| 187 |
|
|
| 188 |
|
float scaleM = mWidth*0.40f;
|
| 189 |
|
Static3D moveM= new Static3D(0,0,1);
|
| 190 |
|
|
| 191 |
|
MatrixEffectMove mainMove = new MatrixEffectMove(moveM);
|
| 192 |
|
MatrixEffectScale mainScale= new MatrixEffectScale(scaleM);
|
| 193 |
|
|
| 194 |
|
// main effect queue ///////////////////////////////////////////
|
| 195 |
|
effects.apply(mainMove);
|
| 196 |
|
effects.apply(mainScale);
|
| 197 |
|
|
| 198 |
|
return new DistortedNode(mCountTexture,effects,mesh);
|
|
230 |
mCountBitmap.eraseColor(0x00000000);
|
|
231 |
mCountCanvas.drawBitmap(mStarBitmap,0,0,null);
|
|
232 |
mCountCanvas.drawBitmap(mStarBitmap,mBmpW,0,null);
|
|
233 |
mCountCanvas.drawText(txt,mBmpW*1.5f,mBmpH*0.64f,mPaint);
|
|
234 |
mTexture.setTexture(mCountBitmap);
|
| 199 |
235 |
}
|
| 200 |
236 |
|
| 201 |
237 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| ... | ... | |
| 214 |
250 |
mWidth = mScreen.getWidth();
|
| 215 |
251 |
mHeight= mScreen.getHeight();
|
| 216 |
252 |
|
| 217 |
|
mStarsNode = createStarsNode(res);
|
| 218 |
|
mStarsNode.glDepthMask(false);
|
| 219 |
|
mStarsNode.glStencilMask(0);
|
| 220 |
|
mStarsNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
|
| 221 |
|
mScreen.attach(mStarsNode);
|
| 222 |
|
|
| 223 |
|
mCountNode = createCountNode();
|
| 224 |
|
mCountNode.glDepthMask(false);
|
| 225 |
|
mCountNode.glStencilMask(0);
|
| 226 |
|
mCountNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
|
| 227 |
|
mScreen.attach(mCountNode);
|
|
253 |
mNode = createNode(res,mTotalStars);
|
|
254 |
mNode.glDepthMask(false);
|
|
255 |
mNode.glStencilMask(0);
|
|
256 |
mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
|
|
257 |
mScreen.attach(mNode);
|
| 228 |
258 |
|
| 229 |
259 |
return 0;
|
| 230 |
260 |
}
|
| ... | ... | |
| 251 |
281 |
glow.setQuality(EffectQuality.MEDIUM);
|
| 252 |
282 |
mGlowID = glow.getID();
|
| 253 |
283 |
glow.notifyWhenFinished(this);
|
| 254 |
|
DistortedEffects effects = mStarsNode.getEffects();
|
|
284 |
DistortedEffects effects = mNode.getEffects();
|
| 255 |
285 |
effects.apply(glow);
|
| 256 |
286 |
|
| 257 |
287 |
renderStars(mTotalStars+mNewStars);
|
| 258 |
288 |
}
|
| 259 |
289 |
if( id==mGlowID )
|
| 260 |
290 |
{
|
| 261 |
|
mScreen.detach(mStarsNode);
|
| 262 |
|
mStarsNode.markForDeletion();
|
| 263 |
|
mStarsNode=null;
|
| 264 |
|
mScreen.detach(mCountNode);
|
| 265 |
|
mCountNode.markForDeletion();
|
| 266 |
|
mCountNode=null;
|
|
291 |
createAlphaEffect(false);
|
|
292 |
mAlphaID = mAlpha.getID();
|
|
293 |
mAlpha.notifyWhenFinished(this);
|
|
294 |
}
|
|
295 |
if( id==mAlphaID )
|
|
296 |
{
|
|
297 |
mScreen.detach(mNode);
|
|
298 |
mNode.markForDeletion();
|
|
299 |
mNode=null;
|
| 267 |
300 |
mListener.overlayFinished(id);
|
| 268 |
301 |
}
|
| 269 |
302 |
}
|
| ... | ... | |
| 273 |
306 |
@SuppressWarnings("unused")
|
| 274 |
307 |
public static void enableEffects()
|
| 275 |
308 |
{
|
|
309 |
FragmentEffectAlpha.enable();
|
| 276 |
310 |
VertexEffectMove.enable();
|
| 277 |
311 |
VertexEffectScale.enable();
|
| 278 |
312 |
PostprocessEffectGlow.enable();
|
The 'stars earned' effect is done. Works only for newStars>0.
Also, there is a crash in the graphics driver on my physical LG phone.