From 4187be4eafb4cc9b860f7107ced69e079321b026 Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 15 Sep 2016 16:17:20 +0100 Subject: [PATCH] minor gameflow changes --- .../rubenvandeven/emotionhero/Emotion.java | 2 +- .../emotionhero/MirrorMenuActivity.java | 72 ++++++++++++++----- .../emotionhero/ProgressActivity.java | 22 +++++- .../emotionhero/ScenarioView.java | 20 +++++- .../main/res/layout/activity_mirror_menu.xml | 53 +++++++++++++- app/src/main/res/values/strings.xml | 2 +- 6 files changed, 144 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/Emotion.java b/app/src/main/java/com/rubenvandeven/emotionhero/Emotion.java index 35c8a7f..9ea587b 100644 --- a/app/src/main/java/com/rubenvandeven/emotionhero/Emotion.java +++ b/app/src/main/java/com/rubenvandeven/emotionhero/Emotion.java @@ -47,7 +47,7 @@ public enum Emotion { case ANGER: return Color.RED; case CONTEMPT: - return Color.BLUE; + return Color.WHITE; case DISGUST: return Color.GREEN; case FEAR: diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/MirrorMenuActivity.java b/app/src/main/java/com/rubenvandeven/emotionhero/MirrorMenuActivity.java index 3240dd3..a78e716 100644 --- a/app/src/main/java/com/rubenvandeven/emotionhero/MirrorMenuActivity.java +++ b/app/src/main/java/com/rubenvandeven/emotionhero/MirrorMenuActivity.java @@ -20,6 +20,7 @@ import android.view.WindowManager; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; @@ -37,6 +38,8 @@ public class MirrorMenuActivity extends AppCompatActivity implements Detector.Im final static String LOG_TAG = "EmotionHero-Mirror"; + public final static String INTENT_EXTRA_SHOW_INTRO = "com.rubenvandeven.emotionhero.INTRO"; + private CameraDetector detector; @@ -47,7 +50,12 @@ public class MirrorMenuActivity extends AppCompatActivity implements Detector.Im SurfaceView cameraPreview; ScenarioView scenarioView; + LinearLayout mainMenu; TextView messageText; + TextView nextButton; + TextView readyButton; + TextView text1; + TextView text2; boolean has_camera_permission = false; @@ -74,12 +82,19 @@ public class MirrorMenuActivity extends AppCompatActivity implements Detector.Im final TextView startButton = (TextView) findViewById(R.id.startButton); TextView highscoresButton = (TextView) findViewById(R.id.highscoresButton); TextView creditsButton = (TextView) findViewById(R.id.creditsButton); + mainMenu = (LinearLayout) findViewById(R.id.mainMenu); + nextButton = (TextView) findViewById(R.id.nextButton); + readyButton = (TextView) findViewById(R.id.readyButton); + text1 = (TextView) findViewById(R.id.introText1); + text2 = (TextView) findViewById(R.id.introText2); Typeface font = Typeface.createFromAsset(getAssets(), "unifont-9.0.02.ttf"); startButton .setTypeface(font); highscoresButton .setTypeface(font); creditsButton .setTypeface(font); messageText.setTypeface(font); + nextButton.setTypeface(font); + readyButton.setTypeface(font); //We create a custom SurfaceView that resizes itself to match the aspect ratio of the incoming camera frames cameraPreview = new SurfaceView(this) { @@ -162,23 +177,6 @@ public class MirrorMenuActivity extends AppCompatActivity implements Detector.Im colorAnimation.start(); - startButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(MirrorMenuActivity.this, IntroductionActivity.class); -// if(!player.getPlayerInfo().canContinueLevel()) { -// intent = new Intent(MirrorMenuActivity.this, IntroductionActivity.class); -// } else { -// loadGameDialog = ProgressDialog.show(MirrorMenuActivity.this, "", -// MirrorMenuActivity.this.getResources().getString(R.string.load_game_activity), true); -// intent = new Intent(MirrorMenuActivity.this, GamingActivity.class); -// } - startActivity(intent); - detector.stop(); - detector = null; - - } - }); // merge with 'start button' @@ -206,6 +204,46 @@ public class MirrorMenuActivity extends AppCompatActivity implements Detector.Im rs = RenderScript.create(this); + + startButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + gotoIntro(); + } + }); + + nextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + nextButton.setVisibility(View.GONE); + readyButton.setVisibility(View.VISIBLE); + text1.setVisibility(View.GONE); + text2.setVisibility(View.VISIBLE); + } + }); + + readyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(MirrorMenuActivity.this, ProgressActivity.class); + finish(); + startActivity(intent); + } + }); + + + + // all setup, see wheter we immediately continue to intro: + boolean showIntro = getIntent().getBooleanExtra(INTENT_EXTRA_SHOW_INTRO, false); + if(showIntro) { + gotoIntro(); + } + } + + protected void gotoIntro() { + nextButton.setVisibility(View.VISIBLE); + text1.setVisibility(View.VISIBLE); + mainMenu.setVisibility(View.GONE); } @Override diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/ProgressActivity.java b/app/src/main/java/com/rubenvandeven/emotionhero/ProgressActivity.java index 0c45f13..a6ab7b1 100644 --- a/app/src/main/java/com/rubenvandeven/emotionhero/ProgressActivity.java +++ b/app/src/main/java/com/rubenvandeven/emotionhero/ProgressActivity.java @@ -43,6 +43,20 @@ public class ProgressActivity extends AppCompatActivity { super.onResume(); // rebuild layout on each onResume, so that updated scores are refreshed buildLayout(); + hideLoadingDialog(); + } + + protected ProgressDialog dialog; + + public void showLoadingDialog() { + dialog = ProgressDialog.show(ProgressActivity.this, "", + getApplicationContext().getResources().getString(R.string.load_game_activity), true); + } + + public void hideLoadingDialog() { + if(dialog != null) { + dialog.cancel(); + } } public void buildLayout() { @@ -63,8 +77,11 @@ public class ProgressActivity extends AppCompatActivity { introText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(ProgressActivity.this, IntroductionActivity.class); + showLoadingDialog(); + Intent intent = new Intent(ProgressActivity.this, MirrorMenuActivity.class); + intent.putExtra(MirrorMenuActivity.INTENT_EXTRA_SHOW_INTRO, true); startActivity(intent); + finish(); } }); @@ -131,8 +148,7 @@ public class ProgressActivity extends AppCompatActivity { intent.putExtra(HighscoreActivity.INTENT_EXTRA_LVL_ID, scenario.id); } else { // "PLAY NOW!" - ProgressDialog dialog = ProgressDialog.show(getApplicationContext(), "", - getApplicationContext().getResources().getString(R.string.load_game_activity), true); + showLoadingDialog(); intent = new Intent(ProgressActivity.this, GamingActivity.class); intent.putExtra(GamingActivity.INTENT_EXTRA_SCENARIO, scenario.id); } diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java b/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java index 55a5647..8b452c0 100644 --- a/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java +++ b/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java @@ -44,6 +44,7 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback private Paint attrScoreLinePaint = new Paint(); private Paint linePaint = new Paint(); private Paint scorePaint = new Paint(); + private Paint bonusScorePaint = new Paint(); private Paint scoreFinishedPaint = new Paint(); private Paint bonusBarPaint = new Paint(); @@ -103,9 +104,13 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback _scenario = s; scorePaint.setColor(Color.YELLOW); - scorePaint.setTextSize(50); + scorePaint.setTextSize(40); scorePaint.setTypeface(Typeface.DEFAULT_BOLD); + bonusScorePaint.setColor(Color.rgb(132, 0, 255)); + bonusScorePaint.setTextSize(20); + bonusScorePaint.setTypeface(Typeface.DEFAULT_BOLD); + bonusBarPaint.setColor(Color.rgb(132, 0, 255)); scoreFinishedPaint.setColor(Color.YELLOW); @@ -118,7 +123,7 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback linePaint.setColor(Color.GRAY); linePaint.setStrokeWidth(5); - attrScorePaint.setColor(Color.DKGRAY); + attrScorePaint.setColor(Color.GRAY); attrScoreLinePaint.setColor(Color.DKGRAY); attrScoreLinePaint.setStrokeWidth(2); @@ -266,6 +271,7 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback // canvas.drawText(scoreText, (width - scoreTextBounds.width()) / 2, height - 10, usedScorePaint); + canvas.restore(); float hitWidth = width*(_scenario.getHitPercentage()/100); float misWidth = width*(_scenario.getMissedPercentage()/100); @@ -274,7 +280,15 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback String scoreText = String.format("%1$.0f", _scenario.getHitTotalValue()); Rect scoreTextBounds = new Rect(); scorePaint.getTextBounds(scoreText, 0, scoreText.length(), scoreTextBounds); - canvas.drawText(scoreText, hitWidth, height*0.95f-scoreTextBounds.height()-5, scorePaint); + canvas.drawText(scoreText, hitWidth, height*0.95f-scoreTextBounds.height(), scorePaint); + + float bonus =_scenario.getBonusTotalValue(); + if(bonus > 0) { + String bonusText = String.format("+ %1$.0f", bonus); + Rect bonusTextBounds = new Rect(); + bonusScorePaint.getTextBounds(bonusText, 0, bonusText.length(), bonusTextBounds); + canvas.drawText(bonusText, hitWidth+scoreTextBounds.width()+3, height*0.95f-bonusTextBounds.height()-10, bonusScorePaint); + } canvas.drawRect(0, height*0.95f, width, height, mainPaint); diff --git a/app/src/main/res/layout/activity_mirror_menu.xml b/app/src/main/res/layout/activity_mirror_menu.xml index 34c75e4..a9112a0 100644 --- a/app/src/main/res/layout/activity_mirror_menu.xml +++ b/app/src/main/res/layout/activity_mirror_menu.xml @@ -15,6 +15,7 @@ + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 530f6bb..b9c1aa8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,5 +15,5 @@ Hello World from section: %1$d Loading training... Are you ready to become the next Emotion Hero? With this program you train for the right emotional response in every situation. - Feel the emotions as they are given by the dots on screen. If you feel them, we detect them.\nNote that you do not always need to go full throttle, we can detect eg. a 47% surprise score! + The bar belows shows your current feelings.\nFeel the emotions as they are given by the dots on screen. If you feel them, we detect them!