Corrected some progressBar errors
Created some others
This commit is contained in:
parent
99e044dfad
commit
4815aaf12a
1 changed files with 57 additions and 37 deletions
|
@ -123,7 +123,8 @@ public class MainActivity extends ActionBarActivity{
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
try {
|
try {
|
||||||
if (player.addPx(Integer.parseInt(input.getText().toString()))) {
|
boolean levelUp = player.addPx(Integer.parseInt(input.getText().toString()));
|
||||||
|
if (levelUp) {
|
||||||
//levelUp
|
//levelUp
|
||||||
//TODO: update defenses
|
//TODO: update defenses
|
||||||
//TODO: add attack points when necessary
|
//TODO: add attack points when necessary
|
||||||
|
@ -133,11 +134,6 @@ public class MainActivity extends ActionBarActivity{
|
||||||
((TextView) findViewById(R.id.lvl)).setText(
|
((TextView) findViewById(R.id.lvl)).setText(
|
||||||
String.valueOf(player.getLevel())
|
String.valueOf(player.getLevel())
|
||||||
);
|
);
|
||||||
((ProgressBar) findViewById(R.id.xpBar))
|
|
||||||
.setMax(
|
|
||||||
Player.LEVEL_PX[player.getLevel()] -
|
|
||||||
Player.LEVEL_PX[player.getLevel() - 1]
|
|
||||||
);
|
|
||||||
healthStatusCheck();
|
healthStatusCheck();
|
||||||
updateCurativeString();
|
updateCurativeString();
|
||||||
}
|
}
|
||||||
|
@ -146,8 +142,9 @@ public class MainActivity extends ActionBarActivity{
|
||||||
incrementProgressBar(
|
incrementProgressBar(
|
||||||
(ProgressBar) findViewById(R.id.xpBar),
|
(ProgressBar) findViewById(R.id.xpBar),
|
||||||
(TextView) findViewById(R.id.currentXp),
|
(TextView) findViewById(R.id.currentXp),
|
||||||
player.getPx() - Player.LEVEL_PX[player.getLevel() - 1],
|
1, levelUp, Player.LEVEL_PX[player.getLevel()] -
|
||||||
1
|
Player.LEVEL_PX[player.getLevel() - 1],
|
||||||
|
true, player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]
|
||||||
);
|
);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
|
@ -205,8 +202,8 @@ public class MainActivity extends ActionBarActivity{
|
||||||
incrementProgressBar(
|
incrementProgressBar(
|
||||||
(ProgressBar) findViewById(R.id.curativeEffortsBar),
|
(ProgressBar) findViewById(R.id.curativeEffortsBar),
|
||||||
(TextView) findViewById(R.id.currentCurativeEfforts),
|
(TextView) findViewById(R.id.currentCurativeEfforts),
|
||||||
player.getCurativeEfforts(),
|
100, false, 0,
|
||||||
100
|
true, player.getCurativeEfforts()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
e.apply();
|
e.apply();
|
||||||
|
@ -285,14 +282,15 @@ public class MainActivity extends ActionBarActivity{
|
||||||
private void healthStatusCheck() {
|
private void healthStatusCheck() {
|
||||||
int status = player.getState();
|
int status = player.getState();
|
||||||
int lastState = player.getLastState();
|
int lastState = player.getLastState();
|
||||||
ProgressBar pgBar = (ProgressBar) findViewById(R.id.pgBar);
|
// ProgressBar pgBar = (ProgressBar) findViewById(R.id.pgBar);
|
||||||
incrementProgressBar(
|
// incrementProgressBar(
|
||||||
pgBar,
|
// pgBar,
|
||||||
(TextView) findViewById(R.id.currentPg),
|
// (TextView) findViewById(R.id.currentPg),
|
||||||
Math.abs(player.getPg()),
|
// Math.abs(player.getPg()),
|
||||||
100
|
// 100,
|
||||||
);
|
// false,
|
||||||
pgBar.setProgress(Math.abs(player.getPg()));
|
// CURRENT_PG
|
||||||
|
// );
|
||||||
Button pg = (Button) findViewById(R.id.pgCurrent);
|
Button pg = (Button) findViewById(R.id.pgCurrent);
|
||||||
pg.setText(String.valueOf(player.getPg()));
|
pg.setText(String.valueOf(player.getPg()));
|
||||||
if (status == Player.MUERTO) {
|
if (status == Player.MUERTO) {
|
||||||
|
@ -324,7 +322,7 @@ public class MainActivity extends ActionBarActivity{
|
||||||
} else if (status == Player.DEBILITADO) {
|
} else if (status == Player.DEBILITADO) {
|
||||||
pg.setBackgroundColor(android.R.drawable.btn_default);
|
pg.setBackgroundColor(android.R.drawable.btn_default);
|
||||||
pg.setTextColor(Color.RED);
|
pg.setTextColor(Color.RED);
|
||||||
pgBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
|
// pgBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
|
||||||
if(lastState != Player.SAME) {
|
if(lastState != Player.SAME) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
getApplicationContext(),
|
getApplicationContext(),
|
||||||
|
@ -335,7 +333,7 @@ public class MainActivity extends ActionBarActivity{
|
||||||
} else if (status == Player.MALHERIDO) {
|
} else if (status == Player.MALHERIDO) {
|
||||||
pg.setBackgroundColor(android.R.drawable.btn_default);
|
pg.setBackgroundColor(android.R.drawable.btn_default);
|
||||||
pg.setTextColor(Color.YELLOW);
|
pg.setTextColor(Color.YELLOW);
|
||||||
pgBar.getProgressDrawable().setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_IN);
|
// pgBar.getProgressDrawable().setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_IN);
|
||||||
if(lastState != Player.SAME) {
|
if(lastState != Player.SAME) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
getApplicationContext(),
|
getApplicationContext(),
|
||||||
|
@ -351,7 +349,7 @@ public class MainActivity extends ActionBarActivity{
|
||||||
R.color.abc_primary_text_material_dark
|
R.color.abc_primary_text_material_dark
|
||||||
));
|
));
|
||||||
pg.setBackgroundColor(android.R.drawable.btn_default);
|
pg.setBackgroundColor(android.R.drawable.btn_default);
|
||||||
pgBar.getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
|
// pgBar.getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,17 +399,24 @@ public class MainActivity extends ActionBarActivity{
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
if(player.getLevel() != 1 && player.getMaxPg() == 0) {
|
if(player.getMaxPg() == 0) {
|
||||||
pgDialog();
|
pgDialog();
|
||||||
}
|
}
|
||||||
player.setCurativeEffort(p.getInt("curativeEfforts", player.getCurativeEfforts()));
|
player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxCurativeEfforts()));
|
||||||
player.setPg(p.getInt("pg", player.getPg()));
|
player.setPg(p.getInt("pg", player.getMaxPg()));
|
||||||
((ProgressBar) findViewById(R.id.pgBar)).setMax(player.getMaxPg()*100);
|
incrementProgressBar(
|
||||||
((ProgressBar) findViewById(R.id.xpBar))
|
(ProgressBar) findViewById(R.id.pgBar),
|
||||||
.setProgress(player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]);
|
(TextView) findViewById(R.id.currentPg),
|
||||||
|
100, true, player.getMaxPg(),
|
||||||
|
true, player.getPg()
|
||||||
|
);
|
||||||
ProgressBar curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
|
ProgressBar curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
|
||||||
curativeEffortsBar.setMax(player.getMaxCurativeEfforts()*100);
|
incrementProgressBar(
|
||||||
curativeEffortsBar.setProgress(player.getCurativeEfforts());
|
curativeEffortsBar,
|
||||||
|
(TextView) findViewById(R.id.currentCurativeEfforts),
|
||||||
|
100, true, player.getMaxCurativeEfforts(),
|
||||||
|
true, player.getCurativeEfforts()
|
||||||
|
);
|
||||||
healthStatusCheck();
|
healthStatusCheck();
|
||||||
updateCurativeString();
|
updateCurativeString();
|
||||||
//set restored values to the respective fields
|
//set restored values to the respective fields
|
||||||
|
@ -517,23 +522,38 @@ public class MainActivity extends ActionBarActivity{
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: implement level-up animation and expand the max dynamically
|
//TODO: implement level-up animation and expand the max dynamically
|
||||||
private void incrementProgressBar(final ProgressBar progressBar, final TextView textView, final int end, final int factor) {
|
private void incrementProgressBar(final ProgressBar progressBar, final TextView textView,
|
||||||
if(progressBar.getProgress() - end == 0) return;
|
final int factor,
|
||||||
|
final boolean setMax, int max,
|
||||||
|
final boolean setVal, int end) {
|
||||||
|
if(setMax) progressBar.setMax(factor*max);
|
||||||
|
if(!setVal) return;
|
||||||
|
if(progressBar.getProgress() - end*factor == 0) return;
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
final int time = 3000 / Math.abs(progressBar.getProgress() - end);
|
final int finalEnd = end * factor;
|
||||||
|
final int time = 2000 / Math.abs(progressBar.getProgress() - finalEnd);
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
int current = progressBar.getProgress()*factor;
|
int current = progressBar.getProgress();
|
||||||
boolean bigger = current < end;
|
boolean bigger = current < finalEnd;
|
||||||
while ((bigger && current <= end) || (!bigger && current >= end)) {
|
while ((bigger && current < finalEnd) || (!bigger && current > finalEnd)) {
|
||||||
current += bigger ? 1 : -1;
|
if(bigger) current++;
|
||||||
|
else current--;
|
||||||
// Update the progress bar and display the
|
// Update the progress bar and display the
|
||||||
//current value in the text view
|
//current value in the text view
|
||||||
final int finalCurrent = current;
|
final int finalCurrent = current;
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
progressBar.setProgress(finalCurrent);
|
progressBar.setProgress(finalCurrent);
|
||||||
textView.setText((finalCurrent/factor) +" / "+(progressBar.getMax()/factor));
|
if(factor == 1){
|
||||||
|
textView.setText(
|
||||||
|
(finalCurrent + Player.LEVEL_PX[player.getLevel() - 1])
|
||||||
|
+ " / " +
|
||||||
|
(progressBar.getMax() + Player.LEVEL_PX[player.getLevel()])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
textView.setText((finalCurrent/factor) +" / "+(progressBar.getMax()/factor));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
|
Reference in a new issue