1
0
Fork 0

Fixed power editing saving

This commit is contained in:
Carlos Galindo 2015-04-24 13:41:52 +02:00
parent 943d98f867
commit 3b9fc620b4
9 changed files with 40 additions and 32 deletions

View file

@ -13,7 +13,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</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" />
</component>
<component name="ProjectType">

View file

@ -38,6 +38,9 @@ class AttackAdapter extends ArrayAdapter<Power> {
((TextView) mView.findViewById(R.id.frequency)).setText(attack.getFrequencyString());
((TextView) mView.findViewById(R.id.extra)).setText(attack.getRangeString() + " " + attack.getDistance());
mView.setBackgroundColor(attack.getFreqColor(getContext()));
if (attack.isUsed())
mView.getBackground().setAlpha(0);
else
mView.getBackground().setAlpha((position % 2) * 127 + 128);
}
return mView;

View file

@ -109,9 +109,8 @@ class Player implements Serializable {
private int classInt, raceInt;
private String name;
private int level;
//TODO: use dice dialogs
private int[] atk, def;
//TODO: implement fully operational powers displayed as cards
//TODO: implement fully operational powers (die rolling)
Player (SharedPreferences p) {
this.name = p.getString(NAME, "Player");

View file

@ -99,13 +99,12 @@ public class PowerEditor extends ActionBarActivity {
public void saveClick(View view) {
//TODO: change strings per resources
boolean readyToSave = true;
for ( int i = 0; i < edits.length; i++ ) {
String s = edits[i].getText().toString().trim();
if (s.length() == 0) {
edits[i].setError("This field is required");
edits[i].setError(getString(R.string.required));
readyToSave = false;
} else {
strings[i] = s;
@ -132,13 +131,12 @@ public class PowerEditor extends ActionBarActivity {
for (int i = 0; i < powers; i++) {
if (p.getString("power" + power, "").equals(saveName)) saveName += "2";
}
} else {
saveName = originalName;
}
p.edit().putString("power" + powers, saveName)
.putInt("powers", powers + 1)
.apply();
} else {
saveName = originalName;
}
SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit();

View file

@ -460,13 +460,14 @@ public class ShowPlayer extends ActionBarActivity {
int n = p.getInt("powers",0);
int elements = 0;
ListView attackList = (ListView) findViewById(R.id.attackList);
AttackAdapter adapter = (AttackAdapter) attackList.getAdapter();
final AttackAdapter adapter = (AttackAdapter) attackList.getAdapter();
if ( adapter != null )
elements = adapter.getCount();
if ( elements < n && adapter != null ) {
for ( int i = elements; i < n; i++ ) {
SharedPreferences sav = getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE);
//TODO: solve error when closing the editor
adapter.add( new Power ( sav ) );
}
} else if ( n != 0 ) {
@ -499,7 +500,7 @@ public class ShowPlayer extends ActionBarActivity {
View nameText = dialog.findViewById(R.id.nameText);
int color = power.getFreqColor(getApplicationContext());
nameText.setBackgroundColor(color);
//TODO: fix the title gap
((TextView) nameText).setText(power.getName());
((TextView) dialog.findViewById(R.id.typeText)).setText(power.getTypeString());
((TextView) dialog.findViewById(R.id.rangeText)).setText(power.getRangeString() + " ");
@ -519,6 +520,8 @@ public class ShowPlayer extends ActionBarActivity {
Button useButton = (Button) dialog.findViewById(R.id.useButton);
useButton.setBackgroundColor(color);
useButton.setTextColor(getResources().getColor(R.color.white));
if (power.isUsed()) {
useButton.getBackground().setAlpha(0);
useButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -527,7 +530,7 @@ public class ShowPlayer extends ActionBarActivity {
power.use();
}
});
//TODO: edit power
}
dialog.show();
}
});

View file

@ -106,7 +106,7 @@ public class Welcome extends ActionBarActivity {
@Override
public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
alert.setItems(new String[]{"Delete", "Edit"}, new DialogInterface.OnClickListener() {
alert.setItems(new String[]{"Delete", "Edit", "Export"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if ( which == 0 ) {
@ -131,11 +131,13 @@ public class Welcome extends ActionBarActivity {
load();
ed.remove("player" + (max - 1)).apply();
}
} else {
//edit the item
} else if (which == 1) {
//TODO: edit the player
Toast.makeText(
activity, "Editor not implemented yet", Toast.LENGTH_LONG)
.show();
} else {
//TODO: export as filesh
}
}
});

View file

@ -6,6 +6,7 @@
android:orientation="vertical">
<!--TODO: organize the input similarly to the output-->
<!--TODO: add "other" element to input further information-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"

View file

@ -156,4 +156,5 @@
<item>Reflejos</item>
<item>Voluntad</item>
</string-array>
<string name="required">Este campo es obligatorio</string>
</resources>

View file

@ -105,6 +105,7 @@
<string name="objectiveHint">One creature</string>
<string name="power_editor">Power Editor</string>
<string name="save_player">Save player</string>
<string name="required">This field is required</string>
<string-array name="freq_array">
<item>Frequency</item>