First achievements screen and new progress activity

This commit is contained in:
Ruben 2016-09-11 22:35:38 +01:00
parent 1f5c96816b
commit 4fe13ba57c
13 changed files with 274 additions and 27 deletions

View file

@ -55,12 +55,18 @@
android:name=".ReviewActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".MirrorMenuActivity" />
<activity android:name=".ReviewAchievementsActivity"
<activity
android:name=".ReviewAchievementsActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.rubenvandeven.emotionhero.ReviewActivity" />
</activity>
<activity android:name=".ProgressActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.rubenvandeven.emotionhero.MirrorMenuActivity" />
</activity>
</application>
</manifest>

View file

@ -10,12 +10,12 @@ import java.util.ArrayList;
public class AchievementCollection {
private ArrayList<Achievement> achievements = new ArrayList<Achievement>(){{
// fill the collection :-)
add(new Achievement("Microexpressor", null, null));
add(new Achievement("\"In pursuit of happiness\"", null, null));
add(new Achievement("CEO", null, null));
add(new Achievement("Kuleshov", null, null));
add(new Achievement("Soap opera", null, null));
add(new Achievement("Stock photo model", null, null));
add(new Achievement("Microexpressor", "...", null));
add(new Achievement("\"In pursuit of happiness\"", "...", null));
add(new Achievement("CEO", "...", null));
add(new Achievement("Kuleshov", "...", null));
add(new Achievement("Soap opera", "...", null));
add(new Achievement("Stock photo model", "...", null));
}};
private static AchievementCollection ourInstance = new AchievementCollection();

View file

@ -2,6 +2,7 @@ package com.rubenvandeven.emotionhero;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@ -233,10 +234,10 @@ public class GameOpenHelper extends SQLiteOpenHelper {
public Game[] getGamesForLevel(int lvl_id) {
Scenario scenario = new Scenario(lvl_id, null);
return getGamesForScenario(scenario);
return getGamesForScenario(scenario, null);
}
public Game[] getGamesForScenario(Scenario s) {
public Game[] getGamesForScenario(Scenario s, Integer limit) {
SQLiteDatabase db = getReadableDatabase();
String selection = "lvl_id = ?";
@ -252,7 +253,7 @@ public class GameOpenHelper extends SQLiteOpenHelper {
null, // don't group the rows
null, // don't filter by row groups
sortOrder, // The sort order
null // no limit!
limit == null ? null : Integer.toString(limit) // no limit!
);
return cursorToGames(c, s);
}
@ -366,6 +367,14 @@ public class GameOpenHelper extends SQLiteOpenHelper {
hit.id = newRowId;
}
public Game getHighscoreGameForScenario(Scenario scenario) {
Game[] games = getGamesForScenario(scenario, 1);
if(games == null || games.length == 0) {
return null;
}
return games[0];
}
public ArrayList<Hit> getHitsForGame(Game game) {
SQLiteDatabase db = getReadableDatabase();
@ -462,7 +471,7 @@ public class GameOpenHelper extends SQLiteOpenHelper {
Cursor c = getReadableDatabase().rawQuery("SELECT achievement_id FROM games g INNER JOIN game_achievements ga ON ga.game_id = g.id WHERE g.id = ?", params);
int count = c.getCount();
if(count < 1)
return null;
return new ArrayList<Achievement>();
ArrayList<Achievement> achievements = new ArrayList<>(count);
c.moveToFirst();

View file

@ -155,14 +155,16 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL
createSoundPool(); // instantiate SoundPool in sound
soundIds.put(SOUND_SCORE, sound.load(this, R.raw.score2, 1));
StoryDialogFragment storyDialog = new StoryDialogFragment();
storyDialog.show(getSupportFragmentManager(), "StoryDialog");
// StoryDialogFragment storyDialog = new StoryDialogFragment();
// storyDialog.show(getSupportFragmentManager(), "StoryDialog");
Typeface font = Typeface.createFromAsset(getAssets(), "unifont-9.0.02.ttf");
mContentView.setTypeface(font);
titleText.setText(currentScenario.game.toString());
titleText.setText(currentScenario.toString());
titleText.setTypeface(font);
startGame();
}
public void startGame() {

View file

@ -37,6 +37,7 @@ public class HighscoreActivity extends AppCompatActivity {
public final static String INTENT_EXTRA_SCORE_ID = "com.rubenvandeven.emotionhero.SCORE_ID";
public final static String INTENT_EXTRA_GAME_ID = "com.rubenvandeven.emotionhero.GAME_ID";
public final static String INTENT_EXTRA_LVL_ID = "com.rubenvandeven.emotionhero.LVL_ID";
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
@ -82,6 +83,7 @@ public class HighscoreActivity extends AppCompatActivity {
// }
// get game from Intent
String gameIdString = getIntent().getStringExtra(INTENT_EXTRA_GAME_ID);
int providedLvlId = getIntent().getIntExtra(INTENT_EXTRA_LVL_ID, 0);
if(gameIdString != null) {
long gameId = Long.valueOf(gameIdString);
Game game = player.getGameOpenHelper().getGameByid(gameId);
@ -112,6 +114,10 @@ public class HighscoreActivity extends AppCompatActivity {
if(game != null) {
int levelpage = Scenario.SCENARIOS.indexOf(game.scenario.id);
mViewPager.setCurrentItem(levelpage);
} else if(providedLvlId != 0) {
int levelpage = Scenario.SCENARIOS.indexOf(providedLvlId);
Log.e("HIGHSCORE", "page: "+levelpage);
mViewPager.setCurrentItem(levelpage);
}
@ -186,7 +192,7 @@ public class HighscoreActivity extends AppCompatActivity {
Player player = Player.getInstance(getContext());
GameOpenHelper gameOpenHelper = player.getGameOpenHelper();
Game[] games = gameOpenHelper.getGamesForScenario(scenario);
Game[] games = gameOpenHelper.getGamesForScenario(scenario, null);
if(gameId != 0) {
Log.d("Highscore", "Request game: " + gameId);

View file

@ -174,7 +174,7 @@ public class MirrorMenuActivity extends AppCompatActivity implements Detector.Im
highscoresButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MirrorMenuActivity.this, HighscoreActivity.class);
Intent intent = new Intent(MirrorMenuActivity.this, ProgressActivity.class);
// intent.putExtra(HighscoreActivity.INTENT_EXTRA_LEVEL, player.getPlayerInfo().reachedLevelId);
startActivity(intent);
}

View file

@ -0,0 +1,161 @@
package com.rubenvandeven.emotionhero;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class ProgressActivity extends AppCompatActivity {
Player player;
LinearLayout levelsLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_progress);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Progress");
levelsLayout = (LinearLayout) findViewById(R.id.levelsLayout);
player = Player.getInstance(getApplicationContext());
}
@Override
protected void onResume() {
super.onResume();
// rebuild layout on each onResume, so that updated scores are refreshed
buildLayout();
}
public void buildLayout() {
levelsLayout.removeAllViews();
Typeface font = Typeface.createFromAsset(getAssets(), "unifont-9.0.02.ttf");
int defaultMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);
TextView introText = new TextView(this);
introText.setText("0. Introduction");
introText.setTextSize(getResources().getDimensionPixelSize(R.dimen.gametitle_textsize));
introText.setTextColor(getResources().getColor(R.color.textHighlight));
introText.setPadding(defaultMargin,defaultMargin,defaultMargin,defaultMargin);
introText.setId(R.id.textView);
introText.setTypeface(font);
introText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ProgressActivity.this, IntroActivity.class);
startActivity(intent);
}
});
levelsLayout.addView(introText);
int si = 1;
for(int lvl_id: Scenario.SCENARIOS) {
final Scenario scenario = new Scenario(lvl_id, null);
boolean hasAccess = player.getPlayerInfo().hasAccessToLevel(scenario.id);
Log.d("PROGRESS", "scenario: "+scenario.id);
final Game highscoreGame = player.getGameOpenHelper().getHighscoreGameForScenario(scenario);
int playerAchievementCount = player.getGameOpenHelper().countAchievementsForLevel(scenario.id);
int totalAchievementCount = scenario.achievements.size();
RelativeLayout lvlLayout = new RelativeLayout(this);
lvlLayout.setPadding(defaultMargin,defaultMargin,defaultMargin,defaultMargin);
lvlLayout.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
TextView titleText = new TextView(this);
// titleText.setText(hasAccess ? scenario.toString() : "= LOCKED =");
titleText.setText(String.format("%1$d. %2$s", si, scenario.toString()));
titleText.setTextSize(getResources().getDimensionPixelSize(R.dimen.gametitle_textsize));
titleText.setTextColor(getResources().getColor(hasAccess ? R.color.textHighlight : R.color.textSecondary));
titleText.setId(R.id.textView);
titleText.setTypeface(font);
lvlLayout.addView(titleText);
TextView scoreText = new TextView(this);
String scoreString = (highscoreGame != null) ? String.format("%1$.2f", highscoreGame.score + highscoreGame.bonus) : (hasAccess ? "play now!" : "locked");
scoreText.setText(scoreString);
scoreText.setTextColor(getResources().getColor(hasAccess ? R.color.textPrimary : R.color.textSecondary));
scoreText.setTextSize(getResources().getDimensionPixelSize(R.dimen.highscore_textsize));
RelativeLayout.LayoutParams scoreTextParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
scoreTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
scoreTextParams.addRule(RelativeLayout.BELOW, titleText.getId());
scoreText.setId(R.id.scoreText);
scoreText.setLayoutParams(scoreTextParams);
lvlLayout.addView(scoreText);
if(playerAchievementCount > 0) {
TextView achievementText = new TextView(this);
achievementText.setText(String.format("+%1$d achievements", playerAchievementCount));
achievementText.setTextColor(getResources().getColor(R.color.textSecondary));
RelativeLayout.LayoutParams achievementTextParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
achievementTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
achievementTextParams.addRule(RelativeLayout.BELOW, scoreText.getId());
achievementText.setLayoutParams(achievementTextParams);
lvlLayout.addView(achievementText);
}
if(hasAccess) {
lvlLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent;
// TODO: is this behaviour confusing?
if(highscoreGame != null) {
// Clicking score -> highscores
intent = new Intent(ProgressActivity.this, HighscoreActivity.class);
intent.putExtra(HighscoreActivity.INTENT_EXTRA_LVL_ID, scenario.id);
} else {
// "PLAY NOW!"
intent = new Intent(ProgressActivity.this, GamingActivity.class);
intent.putExtra(GamingActivity.INTENT_EXTRA_SCENARIO, scenario.id);
}
startActivity(intent);
}
});
}
levelsLayout.addView(lvlLayout);
si++;
}
TextView outroText = new TextView(this);
outroText.setText(String.format("Ending: %1$s", "\"All hail the Emotion Hero!\""));
// outroText.setText(String.format("%1$d. %2$s", si, "Em07i0n H3r0!"));
outroText.setTextSize(getResources().getDimensionPixelSize(R.dimen.gametitle_textsize));
outroText.setTextColor(getResources().getColor(R.color.textHighlight));
outroText.setPadding(defaultMargin,defaultMargin,defaultMargin,defaultMargin);
outroText.setId(R.id.textView);
outroText.setTypeface(font);
// TODO: check if last level was sufficient (minscore/achievements)
levelsLayout.addView(outroText);
}
}

View file

@ -2,6 +2,7 @@ package com.rubenvandeven.emotionhero;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.WindowManager;
@ -56,6 +57,7 @@ public class ReviewAchievementsActivity extends AppCompatActivity {
addAchievement(achievement);
}
int toDiscover = game.scenario.achievements.size() - game.achievements.size();
if(toDiscover > 0) {
@ -63,19 +65,28 @@ public class ReviewAchievementsActivity extends AppCompatActivity {
} else {
toDiscoverText.setText("Wow, you obtained all achievements in one run!!");
}
}
public void addAchievement(Achievement achievement) {
TextView titleText = new TextView(this);
TextView descriptionText = new TextView(this);
AppCompatTextView titleText = new AppCompatTextView(this);
AppCompatTextView descriptionText = new AppCompatTextView(this);
// ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
titleText.setText(achievement.title);
// titleText.setText("mwa");
titleText.setTextColor(getResources().getColor(R.color.textHighlight));
titleText.setTextSize(R.dimen.highscore_textsize);
titleText.setTextSize(getResources().getDimensionPixelSize(R.dimen.highscore_textsize));
titleText.setLayoutParams(params);
descriptionText.setText(achievement.description);
descriptionText.setTextColor(getResources().getColor(R.color.textPrimary));
descriptionText.setLayoutParams(params);
achievementsLayout.addView(titleText);
achievementsLayout.addView(descriptionText);

View file

@ -167,6 +167,7 @@ public class ReviewActivity extends AppCompatActivity {
lvlNameText.setTypeface(font);
overallScorePercText.setTypeface(font);
achievementArrow.setTypeface(font);
achievementText.setTypeface(font);
retryArrow.setTypeface(font);
improveArrow.setTypeface(font);
nextLvlArrow.setTypeface(font);
@ -216,7 +217,7 @@ public class ReviewActivity extends AppCompatActivity {
}
public void checkAchievements() {
if(game.achievements.size() > 0) {
if(game.achievements != null && game.achievements.size() > 0) {
achievementTitle.setVisibility(View.VISIBLE);
achievementLayout.setVisibility(View.VISIBLE);
@ -225,7 +226,7 @@ public class ReviewActivity extends AppCompatActivity {
if(achievementString.length() > 0) {
achievementString += "\n";
}
achievementString += String.format("%2$s", achievement.title);
achievementString += String.format("%1$s", achievement.title);
}
achievementText.setText(achievementString);
achievementLayout.setOnClickListener(new View.OnClickListener() {

View file

@ -468,13 +468,13 @@ public class Scenario {
switch(id) {
case LVL_ANGER:
return "CEO";
return "\"Smile like you mean it\"";
case LVL_JOY:
return "The Conversation";
return "The seven";
case LVL_SURPRISE:
return "Party time!";
return "\"Let's talk business\"";
case LVL_SADDNESS:
return "Six feet under";
return "A sad sad situation";
}
return "...";
}

View file

@ -288,8 +288,6 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback
canvas.drawRect(0, height*0.95f, bonusWidth, height*0.975f, bonusBarPaint);
}
}
// TODO: create AttributeScoreCollection class, with this method.

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.rubenvandeven.emotionhero.ProgressActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_marginBottom="10dp"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextColor="@color/textHighlight">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:id="@+id/levelsScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/levelsLayout" >
</LinearLayout>
</ScrollView>
</RelativeLayout>

View file

@ -5,4 +5,5 @@
<dimen name="fab_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
<dimen name="highscore_textsize">15sp</dimen>
<dimen name="gametitle_textsize">12sp</dimen>
</resources>