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="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

@ -38,7 +38,10 @@ 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()));
mView.getBackground().setAlpha((position % 2) * 127 + 128); if (attack.isUsed())
mView.getBackground().setAlpha(0);
else
mView.getBackground().setAlpha((position % 2) * 127 + 128);
} }
return mView; return mView;
} }

View file

@ -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");

View file

@ -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,14 +131,13 @@ 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";
} }
p.edit().putString("power" + powers, saveName)
.putInt("powers", powers + 1)
.apply();
} else { } else {
saveName = originalName; saveName = originalName;
} }
p.edit().putString("power" + powers, saveName)
.putInt("powers", powers + 1)
.apply();
SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit(); SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit();
for (int i = 0; i < strings.length; i++) for (int i = 0; i < strings.length; i++)

View file

@ -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,18 +500,18 @@ 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);
((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()] ((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()]
+ " " + getResources().getString(R.string.vs) + " " + getResources().getString(R.string.vs)
@ -519,15 +520,17 @@ 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));
useButton.setOnClickListener(new View.OnClickListener() { if (power.isUsed()) {
@Override useButton.getBackground().setAlpha(0);
public void onClick(View v) { useButton.setOnClickListener(new View.OnClickListener() {
//TODO: use power @Override
Toast.makeText(getApplicationContext(), "Power used!", Toast.LENGTH_LONG).show(); public void onClick(View v) {
power.use(); //TODO: use power
} Toast.makeText(getApplicationContext(), "Power used!", Toast.LENGTH_LONG).show();
}); power.use();
//TODO: edit power }
});
}
dialog.show(); dialog.show();
} }
}); });

View file

@ -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
} }
} }
}); });

View file

@ -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"

View file

@ -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>

View file

@ -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>