Fixed remove and add Player and Power
Also improved Power display and use. Set basis for the tutorial for creating players.
This commit is contained in:
parent
3b9fc620b4
commit
3fc3dbdd37
26 changed files with 1000 additions and 545 deletions
|
@ -20,9 +20,10 @@ import com.nispok.snackbar.SnackbarManager;
|
|||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class AttackAdapter extends ArrayAdapter<Power> {
|
||||
AttackAdapter(Context context, Power[] powers) {
|
||||
AttackAdapter(Context context, ArrayList<Power> powers) {
|
||||
super(context, R.layout.attack_row, powers);
|
||||
}
|
||||
|
||||
|
@ -41,7 +42,7 @@ class AttackAdapter extends ArrayAdapter<Power> {
|
|||
if (attack.isUsed())
|
||||
mView.getBackground().setAlpha(0);
|
||||
else
|
||||
mView.getBackground().setAlpha((position % 2) * 127 + 128);
|
||||
mView.getBackground().setAlpha((position % 2) * 50 + 205);
|
||||
}
|
||||
return mView;
|
||||
}
|
||||
|
|
|
@ -112,6 +112,10 @@ class Player implements Serializable {
|
|||
private int[] atk, def;
|
||||
//TODO: implement fully operational powers (die rolling)
|
||||
|
||||
/**
|
||||
* Builds a whole player from its saved stats
|
||||
* @param p SharedPreferences object containing data for a player.
|
||||
*/
|
||||
Player (SharedPreferences p) {
|
||||
this.name = p.getString(NAME, "Player");
|
||||
this.px = p.getInt(PX, 0);
|
||||
|
@ -160,7 +164,6 @@ class Player implements Serializable {
|
|||
this.pg = maxPg;
|
||||
this.maxPg = maxPg;
|
||||
}
|
||||
private void setMaxPgOnLevelUp() {maxPg += CLASS_STATS[PG_ON_LEVEL_UP][classInt];}
|
||||
|
||||
int getPg() {return pg;}
|
||||
void setPg(int pg) {this.pg = pg; setState();}
|
||||
|
@ -221,8 +224,10 @@ class Player implements Serializable {
|
|||
int getVol() {return def[VOL];}
|
||||
|
||||
private void setClass() {
|
||||
if(level == 1) maxPg = atk[CON] + CLASS_STATS[INITIAL_PG][classInt];
|
||||
maxCurativeEfforts = Player.getModifier(atk[CON]) + CLASS_STATS[DAILY_CURATIVE_EFFORTS][classInt];
|
||||
maxPg = atk[CON] + CLASS_STATS[INITIAL_PG][classInt]
|
||||
+ ( level - 1 ) * CLASS_STATS[PG_ON_LEVEL_UP][classInt];
|
||||
maxCurativeEfforts =
|
||||
Player.getModifier(atk[CON]) + CLASS_STATS[DAILY_CURATIVE_EFFORTS][classInt];
|
||||
//TODO: implement armor!
|
||||
def[CA] = 10 + level / 2 + Math.max(0, Player.getModifier(Math.max(atk[DES], atk[INT])));
|
||||
def[FORT] = 10 + level / 2 + Player.getModifier(Math.max(atk[CON], atk[FUE])) +
|
||||
|
@ -247,4 +252,12 @@ class Player implements Serializable {
|
|||
else
|
||||
return context.getResources().getColor(R.color.black);
|
||||
}
|
||||
|
||||
void rest (boolean isLong) {
|
||||
if ( isLong ) {
|
||||
pg = maxPg;
|
||||
curativeEfforts = maxCurativeEfforts;
|
||||
}
|
||||
//TODO: here implement action points!
|
||||
}
|
||||
}
|
|
@ -11,9 +11,11 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
class PlayerAdapter extends ArrayAdapter<Player> {
|
||||
|
||||
PlayerAdapter(Context context, Player[] players) {
|
||||
PlayerAdapter(Context context, ArrayList<Player> players) {
|
||||
super(context, R.layout.player_row, players);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.app.FragmentManager;
|
||||
import android.support.v13.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
|
||||
public class PlayerCreator extends FragmentActivity {
|
||||
|
||||
/**
|
||||
* The number of pages (wizard steps) to show in this demo.
|
||||
*/
|
||||
private static final int NUM_PAGES = 5;
|
||||
|
||||
/**
|
||||
* The pager widget, which handles animation and allows swiping horizontally to access previous
|
||||
* and next wizard steps.
|
||||
*/
|
||||
private ViewPager mPager;
|
||||
|
||||
/**
|
||||
* The pager adapter, which provides the pages to the view pager widget.
|
||||
*/
|
||||
private PagerAdapter mPagerAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_player_creator);
|
||||
|
||||
// Instantiate a ViewPager and a PagerAdapter.
|
||||
mPager = (ViewPager) findViewById(R.id.pager);
|
||||
mPagerAdapter = new PlayerCreatorPagerAdapter(getFragmentManager());
|
||||
mPager.setAdapter(mPagerAdapter);
|
||||
mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
// When changing pages, reset the action bar actions since they are dependent
|
||||
// on which page is currently active. An alternative approach is to have each
|
||||
// fragment expose actions itself (rather than the activity exposing actions),
|
||||
// but for simplicity, the activity provides the actions in this sample.
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.menu_player_creator, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple pager adapter that represents 5 {@link PlayerCreatorFragment} objects, in
|
||||
* sequence.
|
||||
*/
|
||||
private class PlayerCreatorPagerAdapter extends FragmentStatePagerAdapter {
|
||||
public PlayerCreatorPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return PlayerCreatorFragment.create(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return NUM_PAGES;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public class PlayerCreatorFragment extends Fragment {
|
||||
|
||||
/**
|
||||
* The argument key for the page number this fragment represents.
|
||||
*/
|
||||
public static final String ARG_PAGE = "page";
|
||||
|
||||
/**
|
||||
* The fragment's page number, which is set to the argument value for {@link #ARG_PAGE}.
|
||||
*/
|
||||
private int mPageNumber;
|
||||
|
||||
/**
|
||||
* Factory method for this fragment class. Constructs a new fragment for the given page number.
|
||||
*/
|
||||
public static PlayerCreatorFragment create(int pageNumber) {
|
||||
PlayerCreatorFragment fragment = new PlayerCreatorFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_PAGE, pageNumber);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public PlayerCreatorFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mPageNumber = getArguments().getInt(ARG_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout containing a title and body text.
|
||||
ViewGroup rootView = (ViewGroup) inflater
|
||||
.inflate(R.layout.fragment_player_creator, container, false);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page number represented by this fragment object.
|
||||
*/
|
||||
public int getPageNumber() {
|
||||
return mPageNumber;
|
||||
}
|
||||
}
|
|
@ -26,7 +26,9 @@ public class PlayerEditor extends ActionBarActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
setContentView(R.layout.activity_player_editor);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
|
||||
|
||||
name = (EditText) findViewById(R.id.editNameIntro);
|
||||
name.requestFocus();
|
||||
|
|
|
@ -24,8 +24,8 @@ class Power implements Serializable{
|
|||
public static final int[] DIE = {0, 2, 4, 6, 8, 10, 12, 20, 100, 0};
|
||||
|
||||
private boolean used;
|
||||
private int freq, action, distance, range, objectives;
|
||||
private String name, impact, objective;
|
||||
private int freq, action, range;
|
||||
private String name, impact, objective, distance;
|
||||
private String keywords; //fire, spell...
|
||||
private int atk, def; //constants from Player to denote atk and defense
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Power implements Serializable{
|
|||
this.name = p.getString("s0", "Name");
|
||||
this.keywords = p.getString("s1", "Keywords");
|
||||
this.impact = p.getString("s2", "2d10");
|
||||
this.distance = Integer.parseInt(p.getString("s3", "10"));
|
||||
this.distance = p.getString("s3", "10");
|
||||
this.objective = p.getString("s4", "One creature");
|
||||
|
||||
this.used = p.getBoolean("used", false);
|
||||
|
@ -55,8 +55,7 @@ class Power implements Serializable{
|
|||
int getDef() {return def;}
|
||||
int getFreq() {return freq;}
|
||||
|
||||
int getDistance() {return distance;}
|
||||
|
||||
String getDistance() {return distance;}
|
||||
String getName(){return name;}
|
||||
String getImpact() {return impact;}
|
||||
String getObjective() {return objective;}
|
||||
|
@ -85,10 +84,8 @@ class Power implements Serializable{
|
|||
return context.getResources().getColor(R.color.daily);
|
||||
case ENCUENTRO:
|
||||
return context.getResources().getColor(R.color.encounter);
|
||||
case A_VOLUNTAD:
|
||||
return context.getResources().getColor(R.color.at_will);
|
||||
default:
|
||||
return context.getResources().getColor(R.color.green); //TODO: find other color
|
||||
return context.getResources().getColor(R.color.at_will);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
|
@ -24,12 +25,15 @@ public class PowerEditor extends ActionBarActivity {
|
|||
private String originalName;
|
||||
private int power;
|
||||
private SharedPreferences p;
|
||||
private Drawable background;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_power_editor);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
|
||||
|
||||
power = getIntent().getIntExtra("power", -1);
|
||||
|
||||
|
@ -84,6 +88,7 @@ public class PowerEditor extends ActionBarActivity {
|
|||
getResources().getStringArray(R.array.actions_array)
|
||||
)
|
||||
);
|
||||
background = spinners[0].getBackground();
|
||||
|
||||
|
||||
if (power != -1) {
|
||||
|
@ -97,7 +102,6 @@ public class PowerEditor extends ActionBarActivity {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public void saveClick(View view) {
|
||||
boolean readyToSave = true;
|
||||
|
||||
|
@ -116,8 +120,9 @@ public class PowerEditor extends ActionBarActivity {
|
|||
if ( n == 0) {
|
||||
spinners[i].setBackgroundColor(getResources().getColor(R.color.red));
|
||||
readyToSave = false;
|
||||
//TODO: remove the color when the user has made a choice
|
||||
//TODO: TEST THIS remove the color when the user has made a choice
|
||||
} else {
|
||||
spinners[i].setBackground(background);
|
||||
ints[i] = n;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.os.Bundle;
|
|||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
@ -31,6 +32,7 @@ import com.nispok.snackbar.SnackbarManager;
|
|||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ShowPlayer extends ActionBarActivity {
|
||||
|
||||
|
@ -42,11 +44,13 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
private int undoObject, undoPreviousValue;
|
||||
|
||||
private ProgressBar posPgBar, negPgBar, xpBar, curativeEffortsBar;
|
||||
private TextView currentPg, currentXp, currentCurativeEfforts;
|
||||
private TextView currentPg, currentXp, currentCurativeEfforts, level;
|
||||
private SharedPreferences p;
|
||||
private Toolbar toolbar;
|
||||
|
||||
|
||||
private ListView attackList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -54,7 +58,7 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
setContentView(R.layout.activity_show_player);
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
//Loading player
|
||||
try{
|
||||
String name = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE)
|
||||
|
@ -74,6 +78,7 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
currentPg = (TextView) findViewById(R.id.currentPg);
|
||||
currentXp = (TextView) findViewById(R.id.currentXp);
|
||||
currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts);
|
||||
level = (TextView) findViewById(R.id.level);
|
||||
|
||||
xpBar.getProgressDrawable()
|
||||
.setColorFilter(getResources().getColor(R.color.px_bar), PorterDuff.Mode.SRC_IN);
|
||||
|
@ -104,6 +109,18 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void addPx(EditText input) {
|
||||
try {
|
||||
if (player.addPx(Integer.parseInt(input.getText().toString()))) levelUp();
|
||||
p.edit().putInt("px", player.getPx()).apply();
|
||||
pxUpdate();
|
||||
ceUpdate();
|
||||
pgUpdate();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getApplicationContext(), "There was an error leveling up", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
|
@ -129,63 +146,97 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
alert.setTitle(R.string.px_awarded_title);
|
||||
final EditText input = new EditText(this);
|
||||
input.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
input.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
addPx(input);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
input.setHint(R.string.px_awarded_hint);
|
||||
alert.setCancelable(false);
|
||||
alert.setView(input);
|
||||
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
try {
|
||||
boolean levelUp = player.addPx(Integer.parseInt(input.getText().toString()));
|
||||
if (levelUp) {
|
||||
//TODO: improve leveling up by using a sliding guide
|
||||
}
|
||||
p.edit().putInt("px", player.getPx()).apply();
|
||||
if(levelUp)
|
||||
xpBar.setMax(Player.LEVEL_PX[player.getLevel()] -
|
||||
Player.LEVEL_PX[player.getLevel() - 1]);
|
||||
pxUpdate();
|
||||
ceUpdate();
|
||||
pgUpdate();
|
||||
} catch(Exception e) {
|
||||
Toast.makeText(getApplicationContext(), "There was an error leveling up", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
addPx(input);
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton(R.string.level_up, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
player.setPx(Player.LEVEL_PX[player.getLevel()]);
|
||||
levelUp();
|
||||
p.edit().putInt(Player.PX, player.getPx()).apply();
|
||||
pxUpdate();
|
||||
}
|
||||
});
|
||||
alert.show();
|
||||
input.requestFocus();
|
||||
return true;
|
||||
//TODO: the player no longer contains the powers, therefore the resting action affects the array of powers
|
||||
//TODO: fix restoring powers
|
||||
// } else if (id == R.id.action_time_long_rest) {
|
||||
// player.rest(true);
|
||||
// SnackbarManager.show(
|
||||
// Snackbar
|
||||
// .with(this)
|
||||
// .text(R.string.long_rest_done)
|
||||
// .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
// );
|
||||
// p.edit()
|
||||
// .putInt("pg", player.getPg())
|
||||
// .putInt("curativeEfforts", player.getCurativeEfforts())
|
||||
// .apply();
|
||||
// pgUpdate();
|
||||
// ceUpdate();
|
||||
// } else if (id == R.id.action_time_rest) {
|
||||
// player.rest(false);
|
||||
// SnackbarManager.show(
|
||||
// Snackbar
|
||||
// .with(this)
|
||||
// .text(R.string.rest_done)
|
||||
// .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
// );
|
||||
// pgUpdate();
|
||||
// ceUpdate();
|
||||
//TODO: TEST fix restoring powers
|
||||
} else if (id == R.id.action_time_long_rest) {
|
||||
AttackAdapter attackAdapter = (AttackAdapter)attackList.getAdapter();
|
||||
if (attackAdapter != null) {
|
||||
for (int i = 0; i < attackAdapter.getCount(); i++) {
|
||||
Power power = attackAdapter.getItem(i);
|
||||
if ( power.getFreq() != Power.A_VOLUNTAD ) {
|
||||
power.recover(Power.DIARIO);
|
||||
getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE)
|
||||
.edit().putBoolean("used", false);
|
||||
}
|
||||
}
|
||||
//TODO: substitute all calls to refreshList for an update on the single view that changed
|
||||
refreshList();
|
||||
}
|
||||
player.rest(true);
|
||||
SnackbarManager.show(
|
||||
Snackbar
|
||||
.with(this)
|
||||
.text(R.string.long_rest_done)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
);
|
||||
p.edit()
|
||||
.putInt("pg", player.getPg())
|
||||
.putInt("curativeEfforts", player.getCurativeEfforts())
|
||||
.apply();
|
||||
pgUpdate();
|
||||
ceUpdate();
|
||||
} else if (id == R.id.action_time_rest) {
|
||||
AttackAdapter attackAdapter = (AttackAdapter) attackList.getAdapter();
|
||||
if (attackAdapter != null) {
|
||||
for (int i = 0; i < attackAdapter.getCount(); i++) {
|
||||
Power power = attackAdapter.getItem(i);
|
||||
if ( power.getFreq() == Power.ENCUENTRO) {
|
||||
power.recover(Power.ENCUENTRO);
|
||||
getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE)
|
||||
.edit().putBoolean("used", false);
|
||||
}
|
||||
}
|
||||
refreshList();
|
||||
}
|
||||
// player.rest(false); TODO: this isn't needed without action points
|
||||
SnackbarManager.show(
|
||||
Snackbar
|
||||
.with(this)
|
||||
.text(R.string.rest_done)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
);
|
||||
pgUpdate();
|
||||
ceUpdate();
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void levelUp() {
|
||||
//TODO: improve leveling up by using a sliding guide
|
||||
xpBar.setMax(Player.LEVEL_PX[player.getLevel()] -
|
||||
Player.LEVEL_PX[player.getLevel() - 1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -195,7 +246,12 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
pxUpdate();
|
||||
}
|
||||
|
||||
public void heal(boolean usesEffort) {
|
||||
/**
|
||||
* Heals the player and displays an error if the healing wasn't possible
|
||||
* @param usesEffort boolean Whether if the healing consumes a surge or not
|
||||
* @return boolean ! ( usesEffort && error )
|
||||
*/
|
||||
public boolean heal(boolean usesEffort) {
|
||||
int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, usesEffort);
|
||||
if (hasCured == Player.NOT_CURED) {
|
||||
SnackbarManager.show(
|
||||
|
@ -204,15 +260,8 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
.text(R.string.no_curative_efforts_error)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
);
|
||||
return false;
|
||||
} else {
|
||||
if(hasCured == Player.MAXED){
|
||||
SnackbarManager.show(
|
||||
Snackbar
|
||||
.with(this)
|
||||
.text(R.string.maxed_curative)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
);
|
||||
}
|
||||
SharedPreferences.Editor e = p.edit();
|
||||
e.putInt("pg", player.getPg());
|
||||
if(usesEffort) {
|
||||
|
@ -221,22 +270,81 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
}
|
||||
e.apply();
|
||||
pgUpdate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Healing dialog that let's the player choose between using or not a surge to heal themselves.
|
||||
* If the healing action is successful, a Snackbar is displayed to let the player undo it.
|
||||
*/
|
||||
public void healDialog() {
|
||||
final Activity activity = this;
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setMessage(R.string.new_energies_message)
|
||||
.setTitle(R.string.new_energies)
|
||||
.setPositiveButton(R.string.me, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
heal(true);
|
||||
undoPreviousValue = player.getPg();
|
||||
if (heal(true)) {
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(getApplicationContext())
|
||||
.text(String.format(getString(R.string.healed), player.getMaxPg() / 4))
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
.actionLabel(R.string.action_undo)
|
||||
.actionColor(getResources().getColor(R.color.yellow))
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
player.setPg(undoPreviousValue);
|
||||
player.setCurativeEffort(player.getCurativeEfforts() + 1);
|
||||
p.edit().putInt("pg", undoPreviousValue)
|
||||
.putInt("curativeEfforts", player.getCurativeEfforts())
|
||||
.apply();
|
||||
pgUpdate();
|
||||
ceUpdate();
|
||||
SnackbarManager.show(
|
||||
Snackbar
|
||||
.with(getApplicationContext())
|
||||
.text(R.string.restored)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE),
|
||||
activity
|
||||
);
|
||||
}
|
||||
}),
|
||||
activity
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.other, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
undoPreviousValue = player.getPg();
|
||||
heal(false);
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(getApplicationContext())
|
||||
.text(String.format(getString(R.string.healed), player.getMaxPg() / 4))
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
.actionLabel(R.string.action_undo)
|
||||
.actionColor(getResources().getColor(R.color.yellow))
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
player.setPg(undoPreviousValue);
|
||||
p.edit().putInt("pg", undoPreviousValue).apply();
|
||||
SnackbarManager.show(
|
||||
Snackbar
|
||||
.with(getApplicationContext())
|
||||
.text(R.string.restored)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE),
|
||||
activity
|
||||
);
|
||||
pgUpdate();
|
||||
}
|
||||
}),
|
||||
activity
|
||||
);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
|
@ -248,6 +356,12 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
alert.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Damage dialog with an Edittext to input a number (damage), which then is done to the player
|
||||
* If the input is not empty, the hit points are updated and an undo Snackbar is added
|
||||
*
|
||||
* @param view View pressed to trigger this method (onClick attribute on xml)
|
||||
*/
|
||||
public void damage(final View view){
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(R.string.suffer_damage);
|
||||
|
@ -272,16 +386,16 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
undoPreviousValue = preValue;
|
||||
undoObject = CURRENT_PG;
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(context).text("Lost " + damage + " PG's")
|
||||
.actionLabel("Undo") // action button label
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
undo();
|
||||
}
|
||||
})
|
||||
.actionColor(getResources().getColor(R.color.yellow))
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
Snackbar.with(context).text(String.format(getString(R.string.lost_hp), damage))
|
||||
.actionLabel(R.string.action_undo) // action button label
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
undo();
|
||||
}
|
||||
})
|
||||
.actionColor(getResources().getColor(R.color.yellow))
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
,activity); // action button's
|
||||
p.edit().putInt("pg", player.getPg()).apply();
|
||||
pgUpdate();
|
||||
|
@ -301,8 +415,11 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
alert.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hit points progress bars to the adequate value and color.
|
||||
* Sets the text indicating the numerical value of the hit points
|
||||
*/
|
||||
private void pgUpdate() {
|
||||
int status = player.getState();
|
||||
int pg = player.getPg();
|
||||
negPgBar.setProgress(pg < 0 ? -pg : 0);
|
||||
posPgBar.setProgress(pg > 0 ? pg : 0);
|
||||
|
@ -314,6 +431,10 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
negPgBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recovers the player's data from the sharedPreferences and then updates all the layouts
|
||||
* This includes an update for the attackList layout.
|
||||
*/
|
||||
private void restoreData(){
|
||||
//Loading player
|
||||
|
||||
|
@ -325,9 +446,6 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
Player.LEVEL_PX[player.getLevel() - 1]
|
||||
);
|
||||
|
||||
if (player.getMaxPg() == 0) {
|
||||
pgDialog();
|
||||
}
|
||||
player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxCurativeEfforts()));
|
||||
player.setPg(p.getInt("pg", player.getMaxPg()));
|
||||
|
||||
|
@ -339,11 +457,9 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
//set restored values to the respective fields
|
||||
toolbar.setTitle(player.getName());
|
||||
toolbar.setSubtitle(
|
||||
player.getClassName() + " " + player.getRaceName() + " " + player.getLevel()
|
||||
player.getClassName() + " " + player.getRaceName()
|
||||
);
|
||||
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
|
||||
toolbar.setSubtitleTextColor(getResources().getColor(R.color.white));
|
||||
//
|
||||
|
||||
// //attacks
|
||||
// ((TextView) findViewById(R.id.FUE)).setText(
|
||||
// getString(R.string.FUE) + ":" + player.getFue()
|
||||
|
@ -383,6 +499,9 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
refreshList();
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates the progress and indicator text of the available surges.
|
||||
*/
|
||||
private void ceUpdate() {
|
||||
curativeEffortsBar.setProgress(player.getCurativeEfforts());
|
||||
currentCurativeEfforts.setText(
|
||||
|
@ -391,8 +510,12 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the progress and indicator text of the XP
|
||||
*/
|
||||
private void pxUpdate() {
|
||||
xpBar.setProgress(player.getPx());
|
||||
xpBar.setProgress(player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]);
|
||||
level.setText(getString(R.string.level) + " " + player.getLevel());
|
||||
currentXp.setText(
|
||||
player.getPx() + " / " +
|
||||
Player.LEVEL_PX[player.getLevel()]
|
||||
|
@ -400,12 +523,15 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Undoes the last change done by the player. Only used in damage(). Healing is not yet included
|
||||
*/
|
||||
private void undo() {
|
||||
String message = "";
|
||||
if(undoObject == CURRENT_PG){
|
||||
player.setPg(undoPreviousValue);
|
||||
undoObject = NULL;
|
||||
message = getString(R.string.action_undo_current_pg);
|
||||
message = getString(R.string.restored);
|
||||
}
|
||||
if (!message.isEmpty()) {
|
||||
SnackbarManager.show(
|
||||
|
@ -420,29 +546,11 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void pgDialog() {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
||||
final EditText input = new EditText(this);
|
||||
input.setHint(R.string.dialog_resolve_max_pg_hint);
|
||||
input.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
input.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
dialog
|
||||
.setView(input)
|
||||
.setCancelable(false)
|
||||
.setTitle(R.string.dialog_resolve_max_pg_title)
|
||||
.setMessage(R.string.dialog_resolve_max_pg_message)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (!input.getText().toString().isEmpty()) {
|
||||
player.setMaxPg(Integer.parseInt(input.getText().toString()));
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
input.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the PowerEditor to create a new attack inside the current player
|
||||
* @param view View Button that called this method (onClick)
|
||||
*/
|
||||
public void addToList (View view) {
|
||||
startActivity(
|
||||
new Intent(
|
||||
|
@ -454,12 +562,20 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks which list is currently displayed and shows on screen a list of the elements in that list
|
||||
* No abilities are displayed yet, INCOMING FEATURE
|
||||
*
|
||||
* Also has a popup for the attacks (displaying all info)
|
||||
* INCOMING FEATURE: onClicking one ability a dialog with a d20 appears and onClicking rolls,
|
||||
* then displays the sum of the dice result plus the player's ability bonus
|
||||
*/
|
||||
private void refreshList() {
|
||||
//TODO: check which is active (now there is only a power list), so there is only one possibility
|
||||
|
||||
int n = p.getInt("powers",0);
|
||||
int elements = 0;
|
||||
ListView attackList = (ListView) findViewById(R.id.attackList);
|
||||
attackList = (ListView) findViewById(R.id.attackList);
|
||||
final AttackAdapter adapter = (AttackAdapter) attackList.getAdapter();
|
||||
|
||||
if ( adapter != null )
|
||||
|
@ -471,16 +587,17 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
adapter.add( new Power ( sav ) );
|
||||
}
|
||||
} else if ( n != 0 ) {
|
||||
Power[] powers = new Power[n];
|
||||
ArrayList<Power> powers = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
SharedPreferences sav = getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE);
|
||||
powers[i] = new Power(sav);
|
||||
powers.add( new Power(sav) );
|
||||
}
|
||||
|
||||
attackList.setAdapter(new AttackAdapter(this, powers));
|
||||
final Activity activity = this;
|
||||
attackList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||
|
||||
final Dialog dialog = new Dialog(ShowPlayer.this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
@ -498,7 +615,7 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
//identify all the elements from the VIEW and then add LISTENERS
|
||||
final Power power = (Power) parent.getItemAtPosition(position);
|
||||
View nameText = dialog.findViewById(R.id.nameText);
|
||||
int color = power.getFreqColor(getApplicationContext());
|
||||
final int color = power.getFreqColor(getApplicationContext());
|
||||
nameText.setBackgroundColor(color);
|
||||
|
||||
((TextView) nameText).setText(power.getName());
|
||||
|
@ -517,17 +634,63 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
+ " " + getResources().getString(R.string.vs)
|
||||
+ " " + defense[power.getDef()]);
|
||||
|
||||
Button useButton = (Button) dialog.findViewById(R.id.useButton);
|
||||
useButton.setBackgroundColor(color);
|
||||
useButton.setTextColor(getResources().getColor(R.color.white));
|
||||
final Button useButton = (Button) dialog.findViewById(R.id.useButton);
|
||||
|
||||
if (power.isUsed()) {
|
||||
useButton.getBackground().setAlpha(0);
|
||||
useButton.getBackground().setAlpha(128);
|
||||
useButton.setEnabled(false);
|
||||
useButton.setClickable(false);
|
||||
} else {
|
||||
useButton.setBackgroundColor(color);
|
||||
useButton.setTextColor(getResources().getColor(R.color.white));
|
||||
useButton.getBackground().setAlpha(255);
|
||||
useButton.setEnabled(true);
|
||||
useButton.setClickable(true);
|
||||
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();
|
||||
if (power.isUsed()) {
|
||||
useButton.getBackground().setAlpha(128);
|
||||
useButton.setTextColor(getResources().getColor(R.color.black));
|
||||
useButton.setEnabled(false);
|
||||
useButton.setClickable(false);
|
||||
getSharedPreferences(p.getString("power" + position, ""), MODE_PRIVATE)
|
||||
.edit().putBoolean("used", true).apply();
|
||||
refreshList();
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(getApplicationContext())
|
||||
.text(getString(R.string.used) + " " + power.getName())
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
power.recover(Power.DIARIO);
|
||||
useButton.setBackgroundColor(color);
|
||||
useButton.setTextColor(getResources().getColor(R.color.white));
|
||||
useButton.getBackground().setAlpha(255);
|
||||
useButton.setEnabled(true);
|
||||
useButton.setClickable(true);
|
||||
getSharedPreferences(p.getString("power" + position, ""), MODE_PRIVATE)
|
||||
.edit().putBoolean("used", false).apply();
|
||||
refreshList();
|
||||
}
|
||||
})
|
||||
.actionLabel(getString(R.string.action_undo))
|
||||
.actionColor(getResources().getColor(R.color.yellow))
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE),
|
||||
activity
|
||||
);
|
||||
} else {
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(getApplicationContext())
|
||||
.text(getString(R.string.used) + " " + power.getName())
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE),
|
||||
activity
|
||||
);
|
||||
}
|
||||
dialog.dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -541,40 +704,56 @@ public class ShowPlayer extends ActionBarActivity {
|
|||
@Override
|
||||
public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity);
|
||||
alert.setItems(new String[]{"Delete", "Edit"}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if ( which == 0 ) {
|
||||
//delete the item
|
||||
String name = p.getString("power" + position, "");
|
||||
if (name != null && !name.isEmpty()) {
|
||||
getSharedPreferences(name, MODE_PRIVATE).edit().clear().apply();
|
||||
Log.d("Tag", thisActivity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml");
|
||||
try {
|
||||
if(!new File(thisActivity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml").delete())
|
||||
throw new Exception();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getApplicationContext(), "Error deleting attack files", Toast.LENGTH_SHORT).show();
|
||||
alert.setItems(
|
||||
new String[]{getString(R.string.delete), getString(R.string.edit)},
|
||||
new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if ( which == 0 ) {
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(getApplicationContext())
|
||||
.text(R.string.sure)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
.actionLabel(R.string.delete)
|
||||
.actionColor(getResources().getColor(R.color.yellow))
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
//delete the item
|
||||
String name = p.getString("power" + position, "");
|
||||
if (name != null && !name.isEmpty()) {
|
||||
getSharedPreferences(name, MODE_PRIVATE).edit().clear().apply();
|
||||
Log.d("Tag", thisActivity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml");
|
||||
try {
|
||||
if (!new File(thisActivity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml").delete())
|
||||
throw new Exception();
|
||||
} catch (Exception e) {
|
||||
Log.e("POWER:DELETION", "Error deleting attack files\n" + e.getMessage() + "\n" + e.getStackTrace().toString());
|
||||
}
|
||||
int max = p.getInt("powers", 0);
|
||||
SharedPreferences.Editor ed = p.edit();
|
||||
for (int i = position; i < max - 1; i++)
|
||||
ed.putString("power" + i, p.getString("power" + (i + 1), "max"));
|
||||
ed.putInt("powers", max - 1).apply();
|
||||
refreshList();
|
||||
ed.remove("power" + (max - 1)).apply();
|
||||
}
|
||||
}
|
||||
}),
|
||||
thisActivity
|
||||
);
|
||||
} else {
|
||||
//edit the item
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), PowerEditor.class)
|
||||
.putExtra("power", position)
|
||||
.putExtra("player", player.getName())
|
||||
);
|
||||
}
|
||||
int max = p.getInt("powers", 0);
|
||||
SharedPreferences.Editor ed = p.edit();
|
||||
for (int i = position; i < max - 1; i++)
|
||||
ed.putString("power" + i, p.getString("power" + (i + 1), "max"));
|
||||
ed.putInt("powers", max - 1).apply();
|
||||
refreshList();
|
||||
ed.remove("power" + (max - 1)).apply();
|
||||
}
|
||||
} else {
|
||||
//edit the item
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), PowerEditor.class)
|
||||
.putExtra("power", position)
|
||||
.putExtra("player", player.getName())
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
alert.show();
|
||||
return true;
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.AlertDialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
@ -15,7 +16,12 @@ import android.widget.AdapterView;
|
|||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nispok.snackbar.Snackbar;
|
||||
import com.nispok.snackbar.SnackbarManager;
|
||||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Welcome extends ActionBarActivity {
|
||||
|
||||
|
@ -23,12 +29,13 @@ public class Welcome extends ActionBarActivity {
|
|||
|
||||
private SharedPreferences p;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_welcome);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
|
||||
p = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
|
||||
load();
|
||||
}
|
||||
|
@ -65,7 +72,7 @@ public class Welcome extends ActionBarActivity {
|
|||
private void load() {
|
||||
int n = p.getInt("players",0);
|
||||
ListView playerList = (ListView) findViewById(R.id.listView);
|
||||
PlayerAdapter adapter = (PlayerAdapter) playerList.getAdapter();
|
||||
final PlayerAdapter adapter = (PlayerAdapter) playerList.getAdapter();
|
||||
int elements = 0;
|
||||
if ( adapter != null )
|
||||
elements = adapter.getCount();
|
||||
|
@ -78,17 +85,16 @@ public class Welcome extends ActionBarActivity {
|
|||
if (sav.contains(Player.NAME))
|
||||
adapter.add( new Player( sav ) );
|
||||
}
|
||||
//int pg, int maxPg, int px, int curativeEfforts, int maxCurativeEfforts, int classInt,
|
||||
//int raceInt, String name, int[] atk, int[] def, int[] abilities, Power[] powers
|
||||
adapter.notifyDataSetChanged();
|
||||
} else if ( n != 0 ) {
|
||||
playerList.setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.help_text).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.no_players_text).setVisibility(View.GONE);
|
||||
Player[] players = new Player[n];
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
for ( int i = 0; i < n; i++ ) {
|
||||
SharedPreferences sav = getSharedPreferences(p.getString("player" + i, ""), MODE_PRIVATE);
|
||||
if (sav.contains(Player.NAME))
|
||||
players[i] = new Player( sav );
|
||||
if (sav.contains(Player.NAME)) //TODO: adding a second player causes an error
|
||||
players.add( new Player( sav ) );
|
||||
}
|
||||
|
||||
playerList.setAdapter(new PlayerAdapter(this, players));
|
||||
|
@ -106,45 +112,70 @@ 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", "Export"}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if ( which == 0 ) {
|
||||
//delete the item
|
||||
String name = p.getString("player" + position, "");
|
||||
if (name != null && !name.isEmpty()) {
|
||||
getSharedPreferences(name, MODE_PRIVATE).edit().clear().apply();
|
||||
Log.d("Tag", activity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml");
|
||||
try {
|
||||
if(!new File(activity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml").delete())
|
||||
throw new Exception();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getApplicationContext(), "Error deleting player files", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
int max = p.getInt("players", 0);
|
||||
SharedPreferences.Editor ed = p.edit();
|
||||
for (int i = position; i < max - 1; i++)
|
||||
ed.putString("player" + i, p.getString("player" + (i + 1), "max"));
|
||||
ed.putInt("players", max - 1).apply();
|
||||
load();
|
||||
ed.remove("player" + (max - 1)).apply();
|
||||
alert.setItems(
|
||||
new String[]{
|
||||
getString(R.string.delete),
|
||||
getString(R.string.edit),
|
||||
getString(R.string.export)},
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == 0) {
|
||||
//delete the item
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(getApplicationContext())
|
||||
.text(R.string.sure)
|
||||
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
|
||||
.actionLabel(R.string.delete)
|
||||
.actionColor(getResources().getColor(R.color.yellow))
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
String name = p.getString("player" + position, "");
|
||||
if (name != null && !name.isEmpty()) {
|
||||
getSharedPreferences(name, MODE_PRIVATE).edit().clear().apply();
|
||||
Log.d("Tag", activity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml");
|
||||
try {
|
||||
if (!new File(activity.getApplicationContext().getFilesDir().getParent()
|
||||
+ File.separator + "shared_prefs" + File.separator + name + ".xml").delete())
|
||||
throw new Exception();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getApplicationContext(), "Error deleting player files", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
int max = p.getInt("players", 0);
|
||||
SharedPreferences.Editor ed = p.edit();
|
||||
for (int i = position; i < max - 1; i++)
|
||||
ed.putString("player" + i, p.getString("player" + (i + 1), "max"));
|
||||
ed.putInt("players", max - 1).apply();
|
||||
load();
|
||||
ed.remove("player" + (max - 1)).apply();
|
||||
}
|
||||
}
|
||||
}),
|
||||
activity
|
||||
);
|
||||
} else if(which==1) {
|
||||
//TODO: edit the player
|
||||
/**TEMP*/
|
||||
Toast.makeText(
|
||||
activity, "Editor not implemented yet", Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} else {
|
||||
//TODO: export as files
|
||||
/**TEMP*/
|
||||
Toast.makeText(
|
||||
activity, "Exporting feature not implemented yet", Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
} else if (which == 1) {
|
||||
//TODO: edit the player
|
||||
Toast.makeText(
|
||||
activity, "Editor not implemented yet", Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} else {
|
||||
//TODO: export as filesh
|
||||
}
|
||||
}
|
||||
});
|
||||
alert.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
);
|
||||
alert.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
playerList.setVisibility(View.GONE);
|
||||
findViewById(R.id.help_text).setVisibility(View.GONE);
|
||||
|
|
Reference in a new issue