Fixed power editing saving
This commit is contained in:
parent
943d98f867
commit
3b9fc620b4
9 changed files with 40 additions and 32 deletions
|
@ -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">
|
||||||
|
|
|
@ -38,6 +38,9 @@ class AttackAdapter extends ArrayAdapter<Power> {
|
||||||
((TextView) mView.findViewById(R.id.frequency)).setText(attack.getFrequencyString());
|
((TextView) mView.findViewById(R.id.frequency)).setText(attack.getFrequencyString());
|
||||||
((TextView) mView.findViewById(R.id.extra)).setText(attack.getRangeString() + " " + attack.getDistance());
|
((TextView) mView.findViewById(R.id.extra)).setText(attack.getRangeString() + " " + attack.getDistance());
|
||||||
mView.setBackgroundColor(attack.getFreqColor(getContext()));
|
mView.setBackgroundColor(attack.getFreqColor(getContext()));
|
||||||
|
if (attack.isUsed())
|
||||||
|
mView.getBackground().setAlpha(0);
|
||||||
|
else
|
||||||
mView.getBackground().setAlpha((position % 2) * 127 + 128);
|
mView.getBackground().setAlpha((position % 2) * 127 + 128);
|
||||||
}
|
}
|
||||||
return mView;
|
return mView;
|
||||||
|
|
|
@ -109,9 +109,8 @@ class Player implements Serializable {
|
||||||
private int classInt, raceInt;
|
private int classInt, raceInt;
|
||||||
private String name;
|
private String name;
|
||||||
private int level;
|
private int level;
|
||||||
//TODO: use dice dialogs
|
|
||||||
private int[] atk, def;
|
private int[] atk, def;
|
||||||
//TODO: implement fully operational powers displayed as cards
|
//TODO: implement fully operational powers (die rolling)
|
||||||
|
|
||||||
Player (SharedPreferences p) {
|
Player (SharedPreferences p) {
|
||||||
this.name = p.getString(NAME, "Player");
|
this.name = p.getString(NAME, "Player");
|
||||||
|
|
|
@ -99,13 +99,12 @@ public class PowerEditor extends ActionBarActivity {
|
||||||
|
|
||||||
|
|
||||||
public void saveClick(View view) {
|
public void saveClick(View view) {
|
||||||
//TODO: change strings per resources
|
|
||||||
boolean readyToSave = true;
|
boolean readyToSave = true;
|
||||||
|
|
||||||
for ( int i = 0; i < edits.length; i++ ) {
|
for ( int i = 0; i < edits.length; i++ ) {
|
||||||
String s = edits[i].getText().toString().trim();
|
String s = edits[i].getText().toString().trim();
|
||||||
if (s.length() == 0) {
|
if (s.length() == 0) {
|
||||||
edits[i].setError("This field is required");
|
edits[i].setError(getString(R.string.required));
|
||||||
readyToSave = false;
|
readyToSave = false;
|
||||||
} else {
|
} else {
|
||||||
strings[i] = s;
|
strings[i] = s;
|
||||||
|
@ -132,13 +131,12 @@ public class PowerEditor extends ActionBarActivity {
|
||||||
for (int i = 0; i < powers; i++) {
|
for (int i = 0; i < powers; i++) {
|
||||||
if (p.getString("power" + power, "").equals(saveName)) saveName += "2";
|
if (p.getString("power" + power, "").equals(saveName)) saveName += "2";
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
saveName = originalName;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.edit().putString("power" + powers, saveName)
|
p.edit().putString("power" + powers, saveName)
|
||||||
.putInt("powers", powers + 1)
|
.putInt("powers", powers + 1)
|
||||||
.apply();
|
.apply();
|
||||||
|
} else {
|
||||||
|
saveName = originalName;
|
||||||
|
}
|
||||||
|
|
||||||
SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit();
|
SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit();
|
||||||
|
|
||||||
|
|
|
@ -460,13 +460,14 @@ public class ShowPlayer extends ActionBarActivity {
|
||||||
int n = p.getInt("powers",0);
|
int n = p.getInt("powers",0);
|
||||||
int elements = 0;
|
int elements = 0;
|
||||||
ListView attackList = (ListView) findViewById(R.id.attackList);
|
ListView attackList = (ListView) findViewById(R.id.attackList);
|
||||||
AttackAdapter adapter = (AttackAdapter) attackList.getAdapter();
|
final AttackAdapter adapter = (AttackAdapter) attackList.getAdapter();
|
||||||
|
|
||||||
if ( adapter != null )
|
if ( adapter != null )
|
||||||
elements = adapter.getCount();
|
elements = adapter.getCount();
|
||||||
if ( elements < n && adapter != null ) {
|
if ( elements < n && adapter != null ) {
|
||||||
for ( int i = elements; i < n; i++ ) {
|
for ( int i = elements; i < n; i++ ) {
|
||||||
SharedPreferences sav = getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE);
|
SharedPreferences sav = getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE);
|
||||||
|
//TODO: solve error when closing the editor
|
||||||
adapter.add( new Power ( sav ) );
|
adapter.add( new Power ( sav ) );
|
||||||
}
|
}
|
||||||
} else if ( n != 0 ) {
|
} else if ( n != 0 ) {
|
||||||
|
@ -499,16 +500,16 @@ public class ShowPlayer extends ActionBarActivity {
|
||||||
View nameText = dialog.findViewById(R.id.nameText);
|
View nameText = dialog.findViewById(R.id.nameText);
|
||||||
int color = power.getFreqColor(getApplicationContext());
|
int color = power.getFreqColor(getApplicationContext());
|
||||||
nameText.setBackgroundColor(color);
|
nameText.setBackgroundColor(color);
|
||||||
//TODO: fix the title gap
|
|
||||||
((TextView) nameText) .setText(power.getName());
|
((TextView) nameText).setText(power.getName());
|
||||||
((TextView) dialog.findViewById(R.id.typeText)) .setText(power.getTypeString());
|
((TextView) dialog.findViewById(R.id.typeText)).setText(power.getTypeString());
|
||||||
((TextView) dialog.findViewById(R.id.rangeText)) .setText(power.getRangeString() + " ");
|
((TextView) dialog.findViewById(R.id.rangeText)).setText(power.getRangeString() + " ");
|
||||||
((TextView) dialog.findViewById(R.id.freqText)) .setText(power.getFrequencyString());
|
((TextView) dialog.findViewById(R.id.freqText)).setText(power.getFrequencyString());
|
||||||
((TextView) dialog.findViewById(R.id.keywordsText)) .setText(power.getKeywords());
|
((TextView) dialog.findViewById(R.id.keywordsText)).setText(power.getKeywords());
|
||||||
((TextView) dialog.findViewById(R.id.distanceText)) .setText(String.valueOf(power.getDistance()));
|
((TextView) dialog.findViewById(R.id.distanceText)).setText(String.valueOf(power.getDistance()));
|
||||||
((TextView) dialog.findViewById(R.id.objectiveText)).setText(power.getObjective());
|
((TextView) dialog.findViewById(R.id.objectiveText)).setText(power.getObjective());
|
||||||
((TextView) dialog.findViewById(R.id.impactText)).setText(power.getImpact());
|
((TextView) dialog.findViewById(R.id.impactText)).setText(power.getImpact());
|
||||||
((TextView) dialog.findViewById(R.id.otherText)) .setText(power.getOther());
|
((TextView) dialog.findViewById(R.id.otherText)).setText(power.getOther());
|
||||||
|
|
||||||
String[] attack = getResources().getStringArray(R.array.attack_array);
|
String[] attack = getResources().getStringArray(R.array.attack_array);
|
||||||
String[] defense = getResources().getStringArray(R.array.defense_array);
|
String[] defense = getResources().getStringArray(R.array.defense_array);
|
||||||
|
@ -519,6 +520,8 @@ public class ShowPlayer extends ActionBarActivity {
|
||||||
Button useButton = (Button) dialog.findViewById(R.id.useButton);
|
Button useButton = (Button) dialog.findViewById(R.id.useButton);
|
||||||
useButton.setBackgroundColor(color);
|
useButton.setBackgroundColor(color);
|
||||||
useButton.setTextColor(getResources().getColor(R.color.white));
|
useButton.setTextColor(getResources().getColor(R.color.white));
|
||||||
|
if (power.isUsed()) {
|
||||||
|
useButton.getBackground().setAlpha(0);
|
||||||
useButton.setOnClickListener(new View.OnClickListener() {
|
useButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -527,7 +530,7 @@ public class ShowPlayer extends ActionBarActivity {
|
||||||
power.use();
|
power.use();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//TODO: edit power
|
}
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class Welcome extends ActionBarActivity {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {
|
public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(activity);
|
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
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if ( which == 0 ) {
|
if ( which == 0 ) {
|
||||||
|
@ -131,11 +131,13 @@ public class Welcome extends ActionBarActivity {
|
||||||
load();
|
load();
|
||||||
ed.remove("player" + (max - 1)).apply();
|
ed.remove("player" + (max - 1)).apply();
|
||||||
}
|
}
|
||||||
} else {
|
} else if (which == 1) {
|
||||||
//edit the item
|
//TODO: edit the player
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
activity, "Editor not implemented yet", Toast.LENGTH_LONG)
|
activity, "Editor not implemented yet", Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
|
} else {
|
||||||
|
//TODO: export as filesh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<!--TODO: organize the input similarly to the output-->
|
<!--TODO: organize the input similarly to the output-->
|
||||||
|
<!--TODO: add "other" element to input further information-->
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<android.support.v7.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
|
|
|
@ -156,4 +156,5 @@
|
||||||
<item>Reflejos</item>
|
<item>Reflejos</item>
|
||||||
<item>Voluntad</item>
|
<item>Voluntad</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string name="required">Este campo es obligatorio</string>
|
||||||
</resources>
|
</resources>
|
|
@ -105,6 +105,7 @@
|
||||||
<string name="objectiveHint">One creature</string>
|
<string name="objectiveHint">One creature</string>
|
||||||
<string name="power_editor">Power Editor</string>
|
<string name="power_editor">Power Editor</string>
|
||||||
<string name="save_player">Save player</string>
|
<string name="save_player">Save player</string>
|
||||||
|
<string name="required">This field is required</string>
|
||||||
|
|
||||||
<string-array name="freq_array">
|
<string-array name="freq_array">
|
||||||
<item>Frequency</item>
|
<item>Frequency</item>
|
||||||
|
|
Reference in a new issue