Browse Source

even nicer speech bubble

Fabio Arnold 9 years ago
parent
commit
23e3a6cc93

BIN
assets/fonts/komika.bin


BIN
assets/fonts/komika.png


+ 2 - 23
src/de/tudarmstadt/informatik/hostage/ui/fragment/HomeFragment.java

@@ -265,30 +265,9 @@ public class HomeFragment extends Fragment {
 				float relx = event.getX() / (float)v.getWidth();
 				float rely = event.getY() / (float)v.getHeight();
 				if (relx < 0.25f || relx > 0.75f) return false;
-				if (rely < 0.25f || rely > 0.75f) return false;
+				if (rely < 0.25f || rely > 0.9f) return false;
 
-				ThreatIndicatorGLRenderer.showSpeechBubble = true;
-
-				String message = "???";
-				switch (mThreatLevel) {
-					case NOT_MONITORING:
-						message = getString(R.string.honeypot_not_monitoring);
-						break;
-					case NO_THREAT:
-						message = getString(R.string.honeypot_no_threat);
-						break;
-					case PAST_THREAT:
-						message = getString(R.string.honeypot_past_threat);
-						break;
-					case LIVE_THREAT:
-						message = getString(R.string.honeypot_live_threat);
-						break;
-				}
-				AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.getInstance());
-				builder.setMessage(Html.fromHtml(message));
-				builder.setCancelable(true);
-				AlertDialog alert = builder.create();
-				alert.show();
+				ThreatIndicatorGLRenderer.showSpeechBubble();
 
 				return false;
 			}

+ 30 - 8
src/de/tudarmstadt/informatik/hostage/ui/fragment/opengl/ThreatIndicatorGLRenderer.java

@@ -49,7 +49,9 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		mNextThreatLevel = threatLevel;
 	}
 
-	public static boolean showSpeechBubble = true;
+	public static void showSpeechBubble() {
+		bubbleWait = 3.0f; // 3 seconds;
+	}
 
 	/**
 	 * Match the background color of the view holding this renderer
@@ -77,6 +79,8 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 	private int mQuadVertexBuffer;
 
 	private GLFont font = null;
+	private static float bubbleAlpha = 0.0f;
+	private static float bubbleWait = 0.0f;
 	
 	// threat state
 	private static ThreatLevel mNextThreatLevel = ThreatLevel.NO_THREAT;
@@ -153,12 +157,13 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 
 		mTexturedProgram = loadProgram(
 				  "uniform vec2 resolution;" // vertex
+				+ "uniform float scale;"
 				+ "attribute vec2 position;"
 				+ "attribute vec2 texCoord;"
 				+ "varying vec2 vertexTexCoord;"
 				+ "void main() {"
 				+ "	vertexTexCoord = texCoord;"
-				+ "	gl_Position = vec4(2.0 * (position / resolution) - 1.0, 0.0, 1.0);"
+				+ "	gl_Position = vec4(scale * (2.0 * (position / resolution) - 1.0), 0.0, 1.0);"
 				+ "}",
 				  "precision mediump float;"
 				+ "uniform sampler2D colormap;" // fragment
@@ -303,7 +308,10 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 			beeMesh.draw(mAnimatedProgram);
 		}
 	}
-	
+
+	private float easeInOut(float alpha) {
+		return 3.0f*alpha*alpha - 2.0f*alpha*alpha*alpha;
+	}
 	/**
 	 * Tries to render at 30 Hz (see bottom part)
 	 */
@@ -312,6 +320,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 
 		long timeMillis = System.currentTimeMillis() - mStartTimeMillis;
 		double animTime = 0.001 * (double)timeMillis; // in seconds
+		float dt = 1.0f/30.0f;
 		
 		// OpenGL drawing
 		GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
@@ -319,8 +328,19 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 		updateAndroidAndBee();
 		drawAndroidAndBee(animTime);
 
-		if (showSpeechBubble) {
-			Log.i("GL", "drawing bubble");
+		if (bubbleWait > 0.0f) {
+			bubbleAlpha += 4.0f * dt;
+			if (bubbleAlpha >= 1.0f) {
+				bubbleAlpha = 1.0f;
+				bubbleWait -= dt;
+			}
+		} else if (bubbleAlpha > 0.0f) {
+			bubbleAlpha -= 4.0f * dt;
+			if (bubbleAlpha < 0.0f) {
+				bubbleAlpha = 0.0f;
+			}
+		}
+		if (bubbleAlpha > 0.0f) {
 			GLES20.glDisable(GLES20.GL_DEPTH_TEST);
 			GLES20.glEnable(GLES20.GL_BLEND);
 			GLES20.glDisable(GLES20.GL_CULL_FACE);
@@ -329,9 +349,11 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 			int resolutionUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "resolution");
 			int textureUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "colormap");
 			int colorUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "color");
+			int scaleUniformLoc = GLES20.glGetUniformLocation(mTexturedProgram, "scale");
 			GLES20.glUniform2f(resolutionUniformLoc, 1024.0f, 1024.0f);
 			GLES20.glUniform1i(textureUniformLoc, 0);
 			GLES20.glUniform4f(colorUniformLoc, 1.0f, 1.0f, 1.0f, 0.8f);
+			GLES20.glUniform1f(scaleUniformLoc, easeInOut(bubbleAlpha));
 			String message = "???";
 			switch (mNextThreatLevel) {
 				case NOT_MONITORING:
@@ -350,9 +372,9 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 			float textWidth = font.getTextWidth(message);
 			float textHeight = 40.0f;
 			float bubbleDiameter = 256.0f;
-			float bubbleWidth = textWidth + bubbleDiameter;
+			float bubbleWidth = textWidth + 0.75f*bubbleDiameter;
 			float bubbleHeight = bubbleDiameter;
-			float y = 0.75f * 1024.0f + 32.0f * (float) Math.sin(2.0 * animTime);
+			float y = 0.8f * 1024.0f + 32.0f * (float) Math.sin(2.0 * animTime);
 			float x = 0.5f * 1024.0f + 16.0f * (float) Math.cos(1.0 * animTime);
 			drawSpeechBubble(speechBubbleTexture, x - 0.5f * bubbleWidth, y - 0.5f * bubbleHeight,
 					bubbleWidth, bubbleHeight);
@@ -363,7 +385,7 @@ public class ThreatIndicatorGLRenderer implements Renderer {
 			GLES20.glEnable(GLES20.GL_DEPTH_TEST);
 			GLES20.glDisable(GLES20.GL_BLEND);
 		}
-		
+
 		long deltaTime = System.currentTimeMillis() - mStartTimeMillis - timeMillis; // time for one frame
 		if (deltaTime < 33) {
 			try {