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,7 +38,10 @@ 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()));
mView.getBackground().setAlpha((position % 2) * 127 + 128);
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,14 +131,13 @@ public class PowerEditor extends ActionBarActivity {
for (int i = 0; i < powers; i++) {
if (p.getString("power" + power, "").equals(saveName)) saveName += "2";
}
p.edit().putString("power" + powers, saveName)
.putInt("powers", powers + 1)
.apply();
} else {
saveName = originalName;
}
p.edit().putString("power" + powers, saveName)
.putInt("powers", powers + 1)
.apply();
SharedPreferences.Editor ed = getSharedPreferences( saveName, MODE_PRIVATE).edit();
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 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,18 +500,18 @@ 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() + " ");
((TextView) dialog.findViewById(R.id.freqText)) .setText(power.getFrequencyString());
((TextView) dialog.findViewById(R.id.keywordsText)) .setText(power.getKeywords());
((TextView) dialog.findViewById(R.id.distanceText)) .setText(String.valueOf(power.getDistance()));
((TextView) nameText).setText(power.getName());
((TextView) dialog.findViewById(R.id.typeText)).setText(power.getTypeString());
((TextView) dialog.findViewById(R.id.rangeText)).setText(power.getRangeString() + " ");
((TextView) dialog.findViewById(R.id.freqText)).setText(power.getFrequencyString());
((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.objectiveText)).setText(power.getObjective());
((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);
((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()]
+ " " + getResources().getString(R.string.vs)
@ -519,15 +520,17 @@ public class ShowPlayer extends ActionBarActivity {
Button useButton = (Button) dialog.findViewById(R.id.useButton);
useButton.setBackgroundColor(color);
useButton.setTextColor(getResources().getColor(R.color.white));
useButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO: use power
Toast.makeText(getApplicationContext(), "Power used!", Toast.LENGTH_LONG).show();
power.use();
}
});
//TODO: edit power
if (power.isUsed()) {
useButton.getBackground().setAlpha(0);
useButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO: use power
Toast.makeText(getApplicationContext(), "Power used!", Toast.LENGTH_LONG).show();
power.use();
}
});
}
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>