1
0
Fork 0

Error Correction

This commit is contained in:
kauron 2015-02-20 23:36:01 +01:00
commit 9aeb975ffb
9 changed files with 152 additions and 58 deletions

View file

@ -11,7 +11,7 @@ import android.widget.Toast;
public class Introduction extends ActionBarActivity {
EditText name, className, raceName, level, maxPg;
EditText name, className, raceName, level, maxPg, curativeEfforts, maxCurativeEfforts, pgE;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -23,6 +23,9 @@ public class Introduction extends ActionBarActivity {
raceName = (EditText) findViewById(R.id.editRaceIntro);
level = (EditText) findViewById(R.id.editLevelIntro);
maxPg = (EditText) findViewById(R.id.editMaxPgIntro);
curativeEfforts = (EditText) findViewById(R.id.editEffortIntro);
maxCurativeEfforts = (EditText) findViewById(R.id.editMaxEffortIntro);
pgE = (EditText) findViewById(R.id.editPgIntro);
}
@ -61,42 +64,58 @@ public class Introduction extends ActionBarActivity {
private boolean finished() {
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
SharedPreferences.Editor ed = p.edit();
String nameString = name.getText().toString();
String classString = className.getText().toString();
String raceString = raceName.getText().toString();
int levelInt = 0, maxPgInt = 0;
try {
int levelInt = 0, maxPgInt = 0, pg = 0, curEff = 0, mCurEff = 0;
if (!level.getText().toString().isEmpty())
levelInt = Integer.parseInt(level.getText().toString());
maxPgInt = Integer.parseInt(level.getText().toString());
} catch (Exception e) {}
if (!maxPg.getText().toString().isEmpty())
maxPgInt = Integer.parseInt(maxPg.getText().toString());
if (!pgE.getText().toString().isEmpty())
pg = Integer.parseInt(pgE.getText().toString());
if (!curativeEfforts.getText().toString().isEmpty())
curEff = Integer.parseInt(curativeEfforts.getText().toString());
if (!maxCurativeEfforts.getText().toString().isEmpty())
mCurEff = Integer.parseInt(maxCurativeEfforts.getText().toString());
if(getIntent().getExtras().getBoolean("first_time")) {
if (!nameString.isEmpty() &&
if (
!nameString.isEmpty() &&
!classString.isEmpty() &&
!raceString.isEmpty() &&
levelInt != 0 &&
maxPgInt != 0) {
maxPgInt != 0 &&
pg != 0 &&
curEff != 0 &&
mCurEff != 0
) {
//first save it all
ed.putString("playerName", nameString);
ed.putString("className", classString);
ed.putString("raceName", raceString);
if(p.getInt("pg", Integer.MIN_VALUE) == Integer.MIN_VALUE)
ed.putInt("pg", maxPgInt);
ed.putInt("level", levelInt);
ed.putInt("maxPg", maxPgInt);
ed.putInt("pg", pg);
ed.putInt("maxCurativeEfforts", mCurEff);
ed.putInt("curativeEfforts", curEff);
ed.putBoolean("saved", true);
ed.apply();
return true;
} else {
return false;
}
} else {
if(!nameString.isEmpty()) ed.putString("playerName", nameString);
if(!classString.isEmpty()) ed.putString("className", classString);
if(!raceString.isEmpty()) ed.putString("raceName", raceString);
if(levelInt != 0) ed.putInt("level", levelInt);
if(maxPgInt != 0) ed.putInt("maxPg", maxPgInt);
ed.apply();
return true;
if (!nameString.isEmpty()) ed.putString("playerName", nameString);
if (!classString.isEmpty()) ed.putString("className", classString);
if (!raceString.isEmpty()) ed.putString("raceName", raceString);
if (levelInt != 0) ed.putInt("level", levelInt);
if (maxPgInt != 0) ed.putInt("maxPg", maxPgInt);
if (pg != 0) ed.putInt("pg", pg);
if (mCurEff != 0) ed.putInt("maxCurativeEfforts", mCurEff);
if (curEff != 0) ed.putInt("curativeEfforts", curEff);
}
ed.apply();
return true;
}
}

View file

@ -9,6 +9,7 @@ import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -63,6 +64,7 @@ public class MainActivity extends ActionBarActivity
showHealthDialog();
return true;
} else if (id == R.id.action_edit_basics) {
//TODO: try this startChildActivity()
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
Intent intent = new Intent(this, Introduction.class);
startActivity(intent.putExtra(
@ -103,6 +105,33 @@ public class MainActivity extends ActionBarActivity
dialog.show(getFragmentManager(), "HealthDialogFragment");
}
@Override
protected void onPause() {
super.onPause();
Log.e("UTIL", "pause");
}
@Override
protected void onResume() {
super.onResume();
Log.e("UTIL", "resume");
restoreData();
}
@Override
protected void onStop() {
super.onStop();
Log.e("UTIL", "stop");
saveData();
}
@Override
protected void onDestroy() {
super.onDestroy();
saveData();
Log.e("UTIL", "destroy");
}
@Override
public void curativeEffort(DialogFragment dialog, boolean uses) {
int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses);
@ -182,19 +211,23 @@ public class MainActivity extends ActionBarActivity
private void restoreData(){
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
//restore state
player = new Player(
p.getString("playerName", getString(R.string.adventurer_name)),
p.getString("className", getString(R.string.class_name)),
p.getString("raceName", getString(R.string.race_name)),
p.getInt("level", 1),
p.getInt("maxPg", 15),
p.getInt("pg", 15),
p.getInt("maxCurativeEfforts", 5),
p.getInt("curativeEfforts", 5),
new int[6],
new int[3],
new int[18],
new Power[4]);
if(player == null) {
player = new Player(
p.getString("playerName", getString(R.string.adventurer_name)),
p.getString("className", getString(R.string.class_name)),
p.getString("raceName", getString(R.string.race_name)),
p.getInt("level", 1),
p.getInt("maxPg", 15),
p.getInt("pg", 15),
p.getInt("maxCurativeEfforts", 5),
p.getInt("curativeEfforts", 5),
new int[6],
new int[3],
new int[18],
new Power[4]);
} else {
}
//set restored values to the respective fields
((TextView) findViewById(R.id.nameText)).setText(player.getName());
((TextView) findViewById(R.id.raceText)).setText(player.getRaceName());
@ -204,6 +237,15 @@ public class MainActivity extends ActionBarActivity
}
private void saveData() {
getSharedPreferences("basics", MODE_PRIVATE).edit()
.putString("playerName", player.getName())
.putString("className", player.getClassName())
.putString("raceName", player.getRaceName())
.putInt("level", player.getLevel())
.putInt("maxPg", player.getMaxPg())
.putInt("pg", player.getPg())
.putInt("maxCurativeEfforts", player.getMaxCurativeEfforts())
.putInt("curativeEfforts", player.getCurativeEfforts())
.apply();
}
}

View file

@ -60,6 +60,8 @@ public class Player {
}
public int getMaxCurativeEfforts() {return maxCurativeEfforts;}
public int getCurativeEfforts() {return curativeEfforts;}
public void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;}