171 lines
7.5 KiB
Java
171 lines
7.5 KiB
Java
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, IntroductionActivity.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++;
|
|
|
|
}
|
|
|
|
boolean completedAll = player.getPlayerInfo().completedAll;
|
|
|
|
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(completedAll ? getResources().getColor(R.color.textHighlight) : getResources().getColor(R.color.textSecondary) );
|
|
outroText.setPadding(defaultMargin,defaultMargin,defaultMargin,defaultMargin);
|
|
outroText.setId(R.id.textView);
|
|
outroText.setTypeface(font);
|
|
|
|
if(completedAll) {
|
|
outroText.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
// TODO: .. handle onclick!!
|
|
}
|
|
});
|
|
}
|
|
|
|
levelsLayout.addView(outroText);
|
|
}
|
|
}
|