Error Correction
This commit is contained in:
parent
0677fbf059
commit
9aeb975ffb
9 changed files with 152 additions and 58 deletions
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
|
@ -7,7 +7,7 @@
|
|||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<output url="file://$MODULE_DIR$/build/classes/main" />
|
||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||
<exclude-output />
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="DungeonManager" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
|
@ -9,6 +9,7 @@
|
|||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
|
||||
|
@ -24,6 +25,7 @@
|
|||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;}
|
||||
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
android:inputType="textPersonName"
|
||||
android:ems="10"
|
||||
android:id="@+id/editRaceIntro"
|
||||
android:layout_below="@+id/editClassIntro"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:hint="@string/race_name" />
|
||||
android:hint="@string/race_name"
|
||||
android:layout_below="@+id/editNameIntro"
|
||||
android:layout_toRightOf="@+id/editClassIntro"
|
||||
android:layout_toEndOf="@+id/editClassIntro" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -46,12 +46,10 @@
|
|||
android:ems="10"
|
||||
android:id="@+id/editLevelIntro"
|
||||
android:hint="@string/level"
|
||||
android:width="70dp"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignLeft="@+id/editMaxPgIntro"
|
||||
android:layout_alignStart="@+id/editMaxPgIntro" />
|
||||
android:layout_toRightOf="@+id/editNameIntro"
|
||||
android:layout_alignRight="@+id/editRaceIntro"
|
||||
android:layout_alignEnd="@+id/editRaceIntro" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -59,10 +57,13 @@
|
|||
android:inputType="number"
|
||||
android:ems="10"
|
||||
android:id="@+id/editMaxPgIntro"
|
||||
android:layout_below="@+id/editLevelIntro"
|
||||
android:hint="@string/max_pg"
|
||||
android:layout_alignLeft="@+id/editMaxEffortIntro"
|
||||
android:layout_alignStart="@+id/editMaxEffortIntro" />
|
||||
android:width="70dp"
|
||||
android:layout_below="@+id/editClassIntro"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_toLeftOf="@+id/editMaxEffortIntro"
|
||||
android:layout_toStartOf="@+id/editMaxEffortIntro" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -70,8 +71,33 @@
|
|||
android:inputType="number"
|
||||
android:ems="10"
|
||||
android:id="@+id/editMaxEffortIntro"
|
||||
android:layout_alignTop="@+id/editRaceIntro"
|
||||
android:layout_toEndOf="@+id/editRaceIntro"
|
||||
android:hint="@string/max_curative_efforts"
|
||||
android:layout_toRightOf="@+id/editRaceIntro" />
|
||||
android:layout_below="@+id/editRaceIntro"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:ems="10"
|
||||
android:id="@+id/editPgIntro"
|
||||
android:width="70dp"
|
||||
android:hint="@string/pg"
|
||||
android:layout_below="@+id/editMaxPgIntro"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_toLeftOf="@+id/editEffortIntro"
|
||||
android:layout_toStartOf="@+id/editEffortIntro" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:ems="10"
|
||||
android:id="@+id/editEffortIntro"
|
||||
android:layout_below="@+id/editMaxEffortIntro"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:hint="@string/curative_efforts" />
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
android:layout_alignParentTop="true"
|
||||
android:layout_toLeftOf="@+id/pgCurrent"
|
||||
android:layout_toStartOf="@+id/pgCurrent"
|
||||
android:id="@+id/linearLayout">
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_alignBottom="@+id/pgCurrent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/adventurer_name"
|
||||
android:id="@+id/nameText"
|
||||
android:layout_alignParentTop="true"
|
||||
|
@ -38,7 +39,7 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/race_name"
|
||||
android:id="@+id/raceText"
|
||||
android:layout_alignTop="@+id/classText"
|
||||
|
@ -49,7 +50,7 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/class_name"
|
||||
android:id="@+id/classText"
|
||||
android:layout_below="@+id/nameText"
|
||||
|
@ -59,7 +60,7 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/level"
|
||||
android:id="@+id/lvlText"
|
||||
android:layout_alignParentBottom="false"
|
||||
|
@ -71,7 +72,7 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:id="@+id/lvl"
|
||||
android:layout_alignParentBottom="false"
|
||||
android:layout_toRightOf="@+id/lvlText"
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
<string name="app_name" translatable="false">DungeonManager</string>
|
||||
<string name="action_cure">Cure</string>
|
||||
<string name="action_undo">Undo</string>
|
||||
<string name="pg">PG</string>
|
||||
<string name="curative_efforts">Curative efforts</string>
|
||||
<string name="dungeons_and_dragons">Dungeons and Dragons</string>
|
||||
<string name="action_save">Save</string>
|
||||
<string name="action_calendar_activity">Create event</string>
|
||||
|
@ -26,7 +28,7 @@
|
|||
<string name="action_finish">Done</string>
|
||||
|
||||
<string name="level">Level</string>
|
||||
<string name="max_curative_efforts">Curative efforts</string>
|
||||
<string name="max_curative_efforts">Max curative efforts</string>
|
||||
<string name="max_pg">Max PG</string>
|
||||
<string name="missing_info_error">You need to fill all the information</string>
|
||||
<string name="no_curative_efforts_error">You don\'t have any curative efforts left!</string>
|
||||
|
|
Reference in a new issue