1
0
Fork 0

Player: can now be edited

This commit is contained in:
Carlos Galindo 2015-07-20 19:34:01 +02:00
parent c87641a921
commit ef14a452f6
4 changed files with 55 additions and 45 deletions

View file

@ -13,7 +13,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View file

@ -203,6 +203,8 @@ class Player implements Serializable {
String getName() {return name;} String getName() {return name;}
String getClassName() {return CLASS_STRINGS[classInt];} String getClassName() {return CLASS_STRINGS[classInt];}
String getRaceName() {return RACE_STRINGS[raceInt];} String getRaceName() {return RACE_STRINGS[raceInt];}
int getClassInt() {return classInt;}
int getRaceInt() {return raceInt;}
private void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();} private void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();}

View file

@ -17,14 +17,13 @@ import com.nispok.snackbar.SnackbarManager;
public class PlayerEditor extends ActionBarActivity { public class PlayerEditor extends ActionBarActivity {
private EditText name, level; private EditText name, xp;
private EditText str, con, dex, wis, intel, cha; private EditText[] atk = new EditText[7];
private Spinner classSpinner, raceSpinner; private Spinner classSpinner, raceSpinner;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_player_editor); setContentView(R.layout.activity_player_editor);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -32,13 +31,13 @@ public class PlayerEditor extends ActionBarActivity {
name = (EditText) findViewById(R.id.namePlayerEdit); name = (EditText) findViewById(R.id.namePlayerEdit);
name.requestFocus(); name.requestFocus();
level = (EditText) findViewById(R.id.xpEdit); xp = (EditText) findViewById(R.id.xpEdit);
str = (EditText) findViewById(R.id.STR); atk[Player.STR] = (EditText) findViewById(R.id.STR);
con = (EditText) findViewById(R.id.CON); atk[Player.CON] = (EditText) findViewById(R.id.CON);
dex = (EditText) findViewById(R.id.DEX); atk[Player.DEX] = (EditText) findViewById(R.id.DEX);
wis = (EditText) findViewById(R.id.WIS); atk[Player.WIS] = (EditText) findViewById(R.id.WIS);
intel = (EditText) findViewById(R.id.INT); atk[Player.INT] = (EditText) findViewById(R.id.INT);
cha = (EditText) findViewById(R.id.CHA); atk[Player.CHA] = (EditText) findViewById(R.id.CHA);
classSpinner = (Spinner) findViewById(R.id.classSpinner); classSpinner = (Spinner) findViewById(R.id.classSpinner);
classSpinner.setAdapter( classSpinner.setAdapter(
@ -57,6 +56,17 @@ public class PlayerEditor extends ActionBarActivity {
Player.RACE_STRINGS Player.RACE_STRINGS
) )
); );
int position = getIntent().getExtras().getInt("player", -1);
if ( position != -1 ) {
Player p = new Player(getSharedPreferences("player" + position, MODE_PRIVATE));
name.setText(p.getName());
xp.setText(p.getXp());
int[] attack = p.getAtk();
for (int i = Player.STR; i < Player.CHA + 1; i++)
atk[i].setText(attack[i]);
classSpinner.setSelection(p.getClassInt());
raceSpinner.setSelection(p.getRaceInt());
}
} }
@ -104,34 +114,28 @@ public class PlayerEditor extends ActionBarActivity {
int raceInt = raceSpinner.getSelectedItemPosition(); int raceInt = raceSpinner.getSelectedItemPosition();
int pxInt = -1; int pxInt = -1;
if (!level.getText().toString().isEmpty()) if (!xp.getText().toString().isEmpty())
pxInt = Integer.parseInt(level.getText().toString()); pxInt = Integer.parseInt(xp.getText().toString());
else
xp.setError(getString(R.string.required));
int fue = 0, con = 0, des = 0, intel = 0, sab = 0, car = 0; int[] atkInts = new int[7];
if (!this.cha.getText().toString().isEmpty()) for (int i = Player.STR; i <= Player.CHA; i++)
car = Integer.parseInt(this.cha.getText().toString()); if (!atk[i].getText().toString().isEmpty())
if (!this.str.getText().toString().isEmpty()) atkInts[i] = Integer.parseInt(atk[i].getText().toString());
fue = Integer.parseInt(this.str.getText().toString()); boolean validAtk = true;
if (!this.con.getText().toString().isEmpty()) for (int i : atkInts)
con = Integer.parseInt(this.con.getText().toString()); if (i == 0) {
if (!this.dex.getText().toString().isEmpty()) validAtk = false;
des = Integer.parseInt(this.dex.getText().toString()); break;
if (!this.intel.getText().toString().isEmpty()) }
intel = Integer.parseInt(this.intel.getText().toString());
if (!this.wis.getText().toString().isEmpty())
sab = Integer.parseInt(this.wis.getText().toString());
if ( if (
!nameString.isEmpty() && !nameString.isEmpty() &&
classInt != Player.NULL && classInt != Player.NULL &&
raceInt != Player.NULL && raceInt != Player.NULL &&
pxInt != -1 && pxInt != -1 &&
car != 0 && validAtk
fue != 0 &&
con != 0 &&
des != 0 &&
intel != 0 &&
sab != 0
) { ) {
SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE); SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
int i = p.getInt("players", 0); int i = p.getInt("players", 0);
@ -149,12 +153,12 @@ public class PlayerEditor extends ActionBarActivity {
ed.putInt("raceInt", raceInt); ed.putInt("raceInt", raceInt);
ed.putInt("px", pxInt); ed.putInt("px", pxInt);
ed.putInt("fue", fue); ed.putInt("str", atkInts[Player.STR]);
ed.putInt("car", car); ed.putInt("cha", atkInts[Player.CHA]);
ed.putInt("int", intel); ed.putInt("int", atkInts[Player.INT]);
ed.putInt("sab", sab); ed.putInt("wis", atkInts[Player.WIS]);
ed.putInt("con", con); ed.putInt("con", atkInts[Player.CON]);
ed.putInt("des", des); ed.putInt("dex", atkInts[Player.DEX]);
//TEMP //TEMP
ed.putBoolean("new", true); ed.putBoolean("new", true);
ed.apply(); ed.apply();

View file

@ -80,9 +80,9 @@ public class Welcome extends ActionBarActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == 0) { if (which == 0) {
startActivity(new Intent(activity, PlayerEditor.class).putExtra("first_time", true)); startActivity(new Intent(activity, PlayerEditor.class).putExtra("player", -1));
} else if (which == 1) { } else if (which == 1) {
startActivity(new Intent(activity, PlayerEditor.class).putExtra("first_time", false)); startActivity(new Intent(activity, PlayerEditor.class).putExtra("player", -1));
} else if (which == 2) { } else if (which == 2) {
AlertDialog.Builder importDialog = new AlertDialog.Builder(activity); AlertDialog.Builder importDialog = new AlertDialog.Builder(activity);
final EditText input = new EditText(activity); final EditText input = new EditText(activity);
@ -192,7 +192,7 @@ public class Welcome extends ActionBarActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == 0) { if (which == 0) { //delete
//delete the item //delete the item
SnackbarManager.show( SnackbarManager.show(
Snackbar.with(getApplicationContext()) Snackbar.with(getApplicationContext())
@ -227,13 +227,17 @@ public class Welcome extends ActionBarActivity {
}), }),
activity activity
); );
} else if (which == 1) { } else if (which == 1) { //edit
//TODO: edit the player //TODO: edit the player
/**TEMP*/ /**TEMP*/
Toast.makeText( Toast.makeText(
activity, "Editor not implemented yet", Toast.LENGTH_LONG) activity, "Consumed PG and surges won't be restored by the editor", Toast.LENGTH_LONG)
.show(); .show();
} else if (which == 2) { startActivity(new Intent(
getApplicationContext(),
PlayerEditor.class
).putExtra("player", position));
} else if (which == 2) { //export
//TODO: export as files //TODO: export as files
String name = p.getString("player" + position, ""); String name = p.getString("player" + position, "");
// File file = new File(getCacheDir() + File.separator + name + ".dm"); // File file = new File(getCacheDir() + File.separator + name + ".dm");
@ -282,7 +286,7 @@ public class Welcome extends ActionBarActivity {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
} else { } else { //experimental
/**TEMP*/ /**TEMP*/
startActivity(new Intent( startActivity(new Intent(
getApplicationContext(), Display.class getApplicationContext(), Display.class