1
0
Fork 0

Refactored the naming to proper English

This commit is contained in:
Carlos Galindo 2015-04-29 13:58:38 +02:00
commit cc86ecc276
45 changed files with 626 additions and 920 deletions

View file

@ -2,34 +2,29 @@ package com.kauron.dungeonmanager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import java.io.Serializable;
class Player implements Serializable {
public static final String NAME = "playerName", CLASS = "classInt", RACE = "raceInt", PX = "px";
public static final String NAME = "playerName", CLASS = "classInt", RACE = "raceInt", XP = "px";
/**
* Names for the classes
*/
public static final String[] CLASS_STRINGS = {
"Clase", "Ardiente", "Brujo", "Buscador", "Clérigo", "Explorador",
"Guerrero", "Mago", "Mente de Batalla", "Monje", "Paladín", "Pícaro", "Psiónico",
"Sacerdote Rúnico", "Señor de la guerra"
};
public static String[] CLASS_STRINGS;
// "Clase", "Ardiente", "Brujo", "Buscador", "Clérigo", "Explorador",
// "Guerrero", "Mago", "Mente de Batalla", "Monje", "Paladín", "Pícaro", "Psiónico",
// "Sacerdote Rúnico", "Señor de la guerra"
public static final int NULL = 0;
// /**
// * Values for classes
// */
// public static final int ARDIENTE = 1, BRUJO = 2, BUSCADOR = 3, CLÉRIGO = 4,
// EXPLORADOR = 5, GUERRERO = 6, MAGO = 7, MENTE_DE_BATALLA = 8, MONJE = 9, PALADÍN = 10,
// PÍCARO = 11, PSIÓNICO = 12, SACERDOTE_RÚNICO = 13, SEÑOR_DE_LA_GUERRA = 14;
/**
* Values for level - px computation
* Values for level - xp computation
*/
public static final int[] LEVEL_PX = new int[]{
public static final int[] LEVEL_XP = new int[]{
0, 1000, 2250, 3750, 5500, 7500, 10000, 13000, 16500, 20500, 26000,
32000, 39000, 47000, 57000, 69000, 83000, 99000, 119000, 143000, 175000,
210000, 255000, 310000, 375000, 450000, 550000, 675000, 825000, 1000000
@ -39,13 +34,13 @@ class Player implements Serializable {
* Values for each class' characteristics
*/
public static final int[][] CLASS_STATS = new int[][] {
//pg on level up
//hp on level up
{0, 5, 5, 5, 5, 5, 6, 4, 6, 5, 6, 5, 4, 5, 5},
//defenses bonus: fort, ref, vol
//defenses bonus: fort, ref, will
{0, 1, 0, 0, 0, 1, 2, 0, 0, 1, 1, 0, 0, 0, 1},
{0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 2, 0, 0, 0},
{0, 1, 1, 1, 2, 0, 0, 2, 2, 1, 1, 0, 2, 2, 1},
//initial pg bonus
//initial hp bonus
{0,12,12,12,12,12,15,10,15,12,15,12,12,12,12},
//daily curative efforts
{0, 7, 6, 7, 7, 6, 9, 6, 9, 7,10, 6, 6, 7, 7}
@ -54,58 +49,51 @@ class Player implements Serializable {
/**
* Identifiers for each class characteristic
*/
public static final int PG_ON_LEVEL_UP = 0, DEF_FORT = 1, DEF_REF = 2, DEF_VOL = 3,
INITIAL_PG = 4, DAILY_CURATIVE_EFFORTS = 5;
public static final int HP_ON_LEVEL_UP = 0, DEF_FORT = 1, DEF_REF = 2, DEF_WILL = 3,
INITIAL_HP = 4, DAILY_SURGES = 5;
/**
* Names for the races
*/
public static final String[] RACE_STRINGS = new String[] {
"Raza", "Dracónido", "Eladrín", "Elfo", "Enano", "Gitzherai", "Humano", "Mediano",
"Mente del Fragmento", "Minotauro", "Salvaje", "Semielfo", "Tiflin"
};
public static String[] RACE_STRINGS;
// "Raza", "Dracónido", "Eladrín", "Elfo", "Enano", "Gitzherai", "Humano", "Mediano",
// "Mente del Fragmento", "Minotauro", "Salvaje", "Semielfo", "Tiflin"
/**
* Values for attack
*/
public static final int FUE = 0, CON = 1, DES = 2, INT = 3, SAB = 4, CAR = 5;
public static final int STR = 0, CON = 1, DEX = 2, INT = 3, WIS = 4, CHA = 5;
/**
* Values for defenses
*/
public static final int CA = 0, FORT = 1, REF = 2, VOL = 3;
public static final int AC = 0, FORT = 1, REF = 2, WILL = 3;
//TODO: develop abilities like attacks, with a popup
//could be introduced by the player in a introduction screen, with ticks for train and bonuses
// /**
// * Values for abilities
// */
// public static final int ACROBACIAS = 1, AGUANTE = 2, ARCANOS = 3, ATLETISMO = 4, DIPLOMACIA = 5,
// DUNGEONS = 6, ENGAÑAR = 7, HISTORIA = 8, HURTO = 9, INTIMIDAR = 10, NATURALEZA = 11,
// PERCEPCIÓN = 12, PERSPICACIA = 13, RECURSOS = 14, RELIGIÓN = 15, SANAR = 16, SIGILO = 17;
/**
* Names for the abilities
*/
public static final String[] ABILITY_STRING = new String[] {
public static String[] ABILITY_STRING = new String[] {
"Habilidades", "Acrobacias", "Aguante", "Arcanos", "Atletismo", "Diplomacia", "Dungeons", "Engañar",
"Historia", "Hurto", "Intimidar", "Naturaleza", "Percepción", "Perspicacia", "Recursos",
"Religión", "Sanar", "Sigilo"
};
public static final int[] ABILITY_BOOST = new int[] {
-1, DES, CON, INT, FUE, CAR, SAB, CAR, INT, CAR, DES, SAB, SAB, SAB, CAR, INT, SAB, DES
-1, DEX, CON, INT, STR, CHA, WIS, CHA, INT, CHA, DEX, WIS, WIS, WIS, CHA, INT, WIS, DEX
};
/**
* Values for the current living state
*/
public static final int OK = 1, MALHERIDO = 2, DEBILITADO = 3, MUERTO = 4, SAME = 5,
public static final int OK = 1, BLOODIED = 2, DYING = 3, DEAD = 4, SAME = 5,
USE_CURATIVE_EFFORT = -1, CURED = 1, NOT_CURED = 0, MAXED = -1;
private int pg, maxPg, px;
private int hp, maxHp, xp;
private int state, lastState;
private int curativeEfforts, maxCurativeEfforts;
private int surges, maxSurges;
private int classInt, raceInt;
private String name;
private int level;
@ -118,7 +106,7 @@ class Player implements Serializable {
*/
Player (SharedPreferences p) {
this.name = p.getString(NAME, "Player");
this.px = p.getInt(PX, 0);
this.xp = p.getInt(XP, 0);
setLevel();
this.raceInt = p.getInt(RACE, 0);
this.classInt = p.getInt(CLASS, 0);
@ -132,66 +120,73 @@ class Player implements Serializable {
p.getInt("car", 10)}
);
setState();
this.pg = p.getInt( "pg" , maxPg);
this.curativeEfforts = p.getInt( "curativeEfforts" , maxCurativeEfforts );
this.hp = p.getInt( "pg" , maxHp);
this.surges = p.getInt( "curativeEfforts" , maxSurges);
}
int getPx() {return px;}
void setPx (int px) {this.px = px; setLevel();}
boolean addPx(int px) {
public static void setStrings ( Resources res ) {
CLASS_STRINGS = res.getStringArray(R.array.classes);
RACE_STRINGS = res.getStringArray(R.array.races);
ABILITY_STRING = res.getStringArray(R.array.abilities);
}
int getXp() {return xp;}
void setXp(int xp) {this.xp = xp; setLevel();}
boolean addPx(int xp) {
int lastLevel = level;
setPx(this.px + px);
setXp(this.xp + xp);
return lastLevel < level;
}
int getMaxCurativeEfforts() {return maxCurativeEfforts;}
void setMaxCurativeEfforts(int maxCurativeEfforts) {this.maxCurativeEfforts = maxCurativeEfforts;}
int getMaxSurges() {return maxSurges;}
void setMaxSurges(int maxSurges) {this.maxSurges = maxSurges;}
int getCurativeEfforts() {return curativeEfforts;}
void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;}
int getSurges() {return surges;}
void setCurativeEffort(int surges) {this.surges = surges;}
int getLevel() {return level;}
void setLevel() {
for (int i = 0; i < LEVEL_PX.length; i++)
if(px < LEVEL_PX[i]) {level = i; return;}
level = LEVEL_PX.length;
for (int i = 0; i < LEVEL_XP.length; i++)
if(xp < LEVEL_XP[i]) {level = i; return;}
level = LEVEL_XP.length;
}
int getMaxPg() {return maxPg;}
void setMaxPg(int maxPg) {
if(this.maxPg == 0)
this.pg = maxPg;
this.maxPg = maxPg;
int getMaxHp() {return maxHp;}
void setMaxHp(int maxHp) {
if(this.maxHp == 0)
this.hp = maxHp;
this.maxHp = maxHp;
}
int getPg() {return pg;}
void setPg(int pg) {this.pg = pg; setState();}
int getHp() {return hp;}
void setHp(int hp) {this.hp = hp; setState();}
void losePg(int damage) {
pg -= damage;
hp -= damage;
setState();
}
int recoverPg(int recovered, boolean uses) {
if(recovered == USE_CURATIVE_EFFORT){
if(uses && curativeEfforts <= 0) return NOT_CURED;
if(uses && surges <= 0) return NOT_CURED;
else {
if(uses && pg < maxPg) curativeEfforts--;
if (pg < 0) {
pg = 0;
if(uses && hp < maxHp) surges--;
if (hp < 0) {
hp = 0;
} else {
pg += maxPg / 4;
hp += maxHp / 4;
}
}
} else {
if (pg < 0) {
pg = 0;
if (hp < 0) {
hp = 0;
} else {
pg += recovered;
hp += recovered;
}
}
setState();
if (pg > maxPg) {pg = maxPg; return MAXED;}
if (hp > maxHp) {
hp = maxHp; return MAXED;}
return CURED;
}
@ -200,9 +195,9 @@ class Player implements Serializable {
int getState() {return state;}
private void setState() {
lastState = state;
if (pg <= maxPg / -2) state = MUERTO;
else if (pg <= 0) state = DEBILITADO;
else if(pg <= maxPg / 2) state = MALHERIDO;
if (hp <= maxHp / -2) state = DEAD;
else if (hp <= 0) state = DYING;
else if(hp <= maxHp / 2) state = BLOODIED;
else state = OK;
}
@ -212,51 +207,51 @@ class Player implements Serializable {
private void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();}
int getFue() {return atk[FUE];}
int getFue() {return atk[STR];}
int getCon() {return atk[CON];}
int getSab() {return atk[SAB];}
int getCar() {return atk[CAR];}
int getDes() {return atk[DES];}
int getSab() {return atk[WIS];}
int getCar() {return atk[CHA];}
int getDes() {return atk[DEX];}
int getInt() {return atk[INT];}
int getCa() {return def[CA];}
int getCa() {return def[AC];}
int getFort() {return def[FORT];}
int getRef() {return def[REF];}
int getVol() {return def[VOL];}
int getVol() {return def[WILL];}
private void setClass() {
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];
maxHp = atk[CON] + CLASS_STATS[INITIAL_HP][classInt]
+ ( level - 1 ) * CLASS_STATS[HP_ON_LEVEL_UP][classInt];
maxSurges =
Player.getModifier(atk[CON]) + CLASS_STATS[DAILY_SURGES][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])) +
def[AC] = 10 + level / 2 + Math.max(0, Player.getModifier(Math.max(atk[DEX], atk[INT])));
def[FORT] = 10 + level / 2 + Player.getModifier(Math.max(atk[CON], atk[STR])) +
CLASS_STATS[DEF_FORT][classInt];
def[REF] = 10 + level / 2 + Player.getModifier(Math.max(atk[DES], atk[INT])) +
def[REF] = 10 + level / 2 + Player.getModifier(Math.max(atk[DEX], atk[INT])) +
CLASS_STATS[DEF_REF][classInt];
def[VOL] = 10 + level / 2 + Player.getModifier(Math.max(atk[CAR], atk[SAB])) +
CLASS_STATS[DEF_VOL][classInt];
def[WILL] = 10 + level / 2 + Player.getModifier(Math.max(atk[CHA], atk[WIS])) +
CLASS_STATS[DEF_WILL][classInt];
}
static int getModifier(int i) {
return i / 2 - 5;
}
int getStatusColor(Context context) {
if (pg > maxPg / 2)
return context.getResources().getColor(R.color.green);
else if (pg > 0)
return context.getResources().getColor(R.color.yellow);
else if (pg > - maxPg / 2)
return context.getResources().getColor(R.color.red);
int getStatusColor(Resources res) {
if (hp > maxHp / 2)
return res.getColor(R.color.green);
else if (hp > 0)
return res.getColor(R.color.yellow);
else if (hp > -maxHp / 2)
return res.getColor(R.color.red);
else
return context.getResources().getColor(R.color.black);
return res.getColor(R.color.black);
}
void rest (boolean isLong) {
if ( isLong ) {
pg = maxPg;
curativeEfforts = maxCurativeEfforts;
hp = maxHp;
surges = maxSurges;
}
//TODO: here implement action points!
}

View file

@ -1,8 +1,6 @@
package com.kauron.dungeonmanager;
import android.content.Context;
import android.graphics.AvoidXfermode;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.view.LayoutInflater;
import android.view.View;
@ -28,23 +26,23 @@ class PlayerAdapter extends ArrayAdapter<Player> {
if ( player != null ) {
((TextView) mView.findViewById(R.id.name)).setText(player.getName());
((TextView) mView.findViewById(R.id.other)).setText(player.getClassName() + " " + player.getRaceName());
((TextView) mView.findViewById(R.id.level))
((TextView) mView.findViewById(R.id.class_and_race)).setText(player.getClassName() + " " + player.getRaceName());
((TextView) mView.findViewById(R.id.levelText))
.setText(
getContext().getResources().getString(R.string.level) + " " + player.getLevel()
);
int pg = player.getPg();
int maxPg = player.getMaxPg();
ProgressBar neg = (ProgressBar) mView.findViewById(R.id.negPgBar);
ProgressBar pos = (ProgressBar) mView.findViewById(R.id.pgBar);
int hp = player.getHp();
int maxHp = player.getMaxHp();
ProgressBar neg = (ProgressBar) mView.findViewById(R.id.negative_hp_bar);
ProgressBar pos = (ProgressBar) mView.findViewById(R.id.positive_hp_bar);
neg.setMax(maxPg / 2);
pos.setMax(maxPg);
neg.setMax(maxHp / 2);
pos.setMax(maxHp);
neg.setProgress(pg < 0 ? -pg : 0);
pos.setProgress(pg > 0 ? pg : 0);
neg.setProgress(hp < 0 ? -hp : 0);
pos.setProgress(hp > 0 ? hp : 0);
int color = player.getStatusColor(getContext());
int color = player.getStatusColor(getContext().getResources());
neg.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
pos.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}

View file

@ -11,8 +11,8 @@ public class PlayerDBHandler extends SQLiteOpenHelper {
public static final String TABLE_PLAYERS = "players";
public static final String C_ID="_id", C_NAME="name", C_CLASS="class", C_RACE="race";
public static final String C_PG="pg", C_PG_MAX="pgMax", C_SURGES="surges", C_SURGES_MAX="surgesMax";
public static final String C_PX = "px", C_ATK = "atk", C_ABILITY = "ability", C_POWER_ID="powerID";
public static final String C_HP ="hp", C_HP_MAX ="hpMax", C_SURGES="surges", C_SURGES_MAX="surgesMax";
public static final String C_XP = "px", C_ATK = "atk", C_ABILITY = "ability", C_POWER_ID="powerID";
//TODO: complete class and implement database to save the players instead of sharedprefs
//TODO: not using it at the moment

View file

@ -18,7 +18,7 @@ import com.nispok.snackbar.SnackbarManager;
public class PlayerEditor extends ActionBarActivity {
private EditText name, level;
private EditText fue, con, des, sab, intel, car;
private EditText str, con, dex, wis, intel, cha;
private Spinner classSpinner, raceSpinner;
@Override
@ -30,15 +30,15 @@ public class PlayerEditor extends ActionBarActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
name = (EditText) findViewById(R.id.editNameIntro);
name = (EditText) findViewById(R.id.namePlayerEdit);
name.requestFocus();
level = (EditText) findViewById(R.id.editPxIntro);
fue = (EditText) findViewById(R.id.FUE);
level = (EditText) findViewById(R.id.xpEdit);
str = (EditText) findViewById(R.id.STR);
con = (EditText) findViewById(R.id.CON);
des = (EditText) findViewById(R.id.DES);
sab = (EditText) findViewById(R.id.SAB);
dex = (EditText) findViewById(R.id.DEX);
wis = (EditText) findViewById(R.id.WIS);
intel = (EditText) findViewById(R.id.INT);
car = (EditText) findViewById(R.id.CAR);
cha = (EditText) findViewById(R.id.CHA);
classSpinner = (Spinner) findViewById(R.id.classSpinner);
classSpinner.setAdapter(
@ -108,74 +108,59 @@ public class PlayerEditor extends ActionBarActivity {
pxInt = Integer.parseInt(level.getText().toString());
int fue = 0, con = 0, des = 0, intel = 0, sab = 0, car = 0;
if (!this.car.getText().toString().isEmpty())
car = Integer.parseInt(this.car.getText().toString());
if (!this.fue.getText().toString().isEmpty())
fue = Integer.parseInt(this.fue.getText().toString());
if (!this.cha.getText().toString().isEmpty())
car = Integer.parseInt(this.cha.getText().toString());
if (!this.str.getText().toString().isEmpty())
fue = Integer.parseInt(this.str.getText().toString());
if (!this.con.getText().toString().isEmpty())
con = Integer.parseInt(this.con.getText().toString());
if (!this.des.getText().toString().isEmpty())
des = Integer.parseInt(this.des.getText().toString());
if (!this.dex.getText().toString().isEmpty())
des = Integer.parseInt(this.dex.getText().toString());
if (!this.intel.getText().toString().isEmpty())
intel = Integer.parseInt(this.intel.getText().toString());
if (!this.sab.getText().toString().isEmpty())
sab = Integer.parseInt(this.sab.getText().toString());
if (!this.wis.getText().toString().isEmpty())
sab = Integer.parseInt(this.wis.getText().toString());
// if(first) {
if (
!nameString.isEmpty() &&
classInt != Player.NULL &&
raceInt != Player.NULL &&
pxInt != -1 &&
car != 0 &&
fue != 0 &&
con != 0 &&
des != 0 &&
intel != 0 &&
sab != 0
) {
SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
int i = p.getInt("players", 0);
String saveName = nameString;
for (int j = 0; j < i; j++) {
if (p.getString("player" + j, "").equals(saveName))
saveName += "2";
}
p.edit().putString("player" + i, saveName).putInt("players", i + 1).apply();
SharedPreferences.Editor ed = getSharedPreferences(saveName, MODE_PRIVATE).edit();
//first save it all
ed.putString("playerName", nameString);
ed.putInt("classInt", classInt);
ed.putInt("raceInt", raceInt);
ed.putInt("px", pxInt);
ed.putInt("fue", fue);
ed.putInt("car", car);
ed.putInt("int", intel);
ed.putInt("sab", sab);
ed.putInt("con", con);
ed.putInt("des", des);
//TEMP
ed.putBoolean("new", true);
ed.apply();
} else {
return false;
if (
!nameString.isEmpty() &&
classInt != Player.NULL &&
raceInt != Player.NULL &&
pxInt != -1 &&
car != 0 &&
fue != 0 &&
con != 0 &&
des != 0 &&
intel != 0 &&
sab != 0
) {
SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
int i = p.getInt("players", 0);
String saveName = nameString;
for (int j = 0; j < i; j++) {
if (p.getString("player" + j, "").equals(saveName))
saveName += "2";
}
// } else {
// if (!nameString.isEmpty()) ed.putString("playerName", nameString);
// if (classInt != Player.NULL) ed.putInt("classInt", classInt);
// if (raceInt != Player.NULL) ed.putInt("raceInt", raceInt);
// if (pxInt != -1) ed.putInt("px", pxInt);
//
// if (fue != 0) ed.putInt("fue", fue);
// if (car != 0) ed.putInt("car", car);
// if (intel != 0) ed.putInt("int", intel);
// if (sab != 0) ed.putInt("sab", sab);
// if (con != 0) ed.putInt("con", con);
// if (des != 0) ed.putInt("des", des);
// }
p.edit().putString("player" + i, saveName).putInt("players", i + 1).apply();
SharedPreferences.Editor ed = getSharedPreferences(saveName, MODE_PRIVATE).edit();
return true;
//first save it all
ed.putString("playerName", nameString);
ed.putInt("classInt", classInt);
ed.putInt("raceInt", raceInt);
ed.putInt("px", pxInt);
ed.putInt("fue", fue);
ed.putInt("car", car);
ed.putInt("int", intel);
ed.putInt("sab", sab);
ed.putInt("con", con);
ed.putInt("des", des);
//TEMP
ed.putBoolean("new", true);
ed.apply();
return true;
} else {
return false;
}
}
}

View file

@ -2,20 +2,22 @@ package com.kauron.dungeonmanager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.content.res.Resources;
import java.io.Serializable;
class Power implements Serializable{
/**frequencies*/
public static final int OPORTUNIDAD = 1, A_VOLUNTAD = 2, ENCUENTRO = 3, DIARIO = 4;
public static final String[] FREQ = {"Nada", "Oportunidad", "A voluntad", "Encuentro", "Diario"};
public static final int AT_WILL = 2, ENCOUNTER = 3, DAILY = 4;
/*{"Nada", "A voluntad", "Encuentro", "Diario"}*/
/**actions*/
public static final int ESTANDAR = 1, MOVIMIENTO = 2, MENOR = 3, GRATUITA = 4;
public static final String[] ACTIONS = {"Nada", "Estándar", "Movimiento", "Menor", "Gratuita"};
public static final int STANDARD = 1, MOVEMENT = 2, MINOR = 3, FREE = 4;
/*{"Nada", "Estándar", "Movimiento", "Menor", "Gratuita"}*/
/**distances*/
public static final int CUERPO_A_CUERPO = 1, A_DISTANCIA = 2, EXPLOSION = 3, ESTALLIDO = 4;
public static final String[] DISTANCES = {"Nada", "Cuerpo a cuerpo", "A distancia", "Explosión", "Estallido"};
public static final int MELEE = 1, RANGED = 2, EXPLOSION = 3, AREA = 4, CLOSE = 5, AURA = 6;
/* {"Nada", "Cuerpo a cuerpo", "A distancia", "Explosión", "Estallido"};*/
public static String[] RANGES, ACTIONS, FREQ, ATK, DEF, ATTACK, DEFENSE;
/**dies
* They are represented by its max size
* 0 corresponds to [A], the weapon
@ -45,11 +47,21 @@ class Power implements Serializable{
this.action = p.getInt("i4", 0);
}
static void setStrings(Resources res) {
FREQ = res.getStringArray(R.array.frequencies);
ACTIONS = res.getStringArray(R.array.actions);
RANGES = res.getStringArray(R.array.ranges);
ATK = res.getStringArray(R.array.atk);
DEF = res.getStringArray(R.array.def);
ATTACK = res.getStringArray(R.array.attack);
DEFENSE = res.getStringArray(R.array.defense);
}
String getKeywords() {return keywords;}
String getTypeString() {return ACTIONS[action];}
String getFrequencyString() {return FREQ[freq];}
String getRangeString() {return DISTANCES[range];}
String getRangeString() {return RANGES[range];}
int getAtk() {return atk;}
int getDef() {return def;}
@ -67,7 +79,7 @@ class Power implements Serializable{
boolean use(){
if (!used) {
if (freq >= ENCUENTRO) used = true;
if (freq >= ENCOUNTER) used = true;
return true;
} else {return false;}
}
@ -80,9 +92,9 @@ class Power implements Serializable{
int getFreqColor(Context context) {
switch (freq) {
case DIARIO:
case DAILY:
return context.getResources().getColor(R.color.daily);
case ENCUENTRO:
case ENCOUNTER:
return context.getResources().getColor(R.color.encounter);
default:
return context.getResources().getColor(R.color.at_will);

View file

@ -1,43 +1,30 @@
package com.kauron.dungeonmanager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
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;
class AttackAdapter extends ArrayAdapter<Power> {
AttackAdapter(Context context, ArrayList<Power> powers) {
super(context, R.layout.attack_row, powers);
class PowerAdapter extends ArrayAdapter<Power> {
PowerAdapter(Context context, ArrayList<Power> powers) {
super(context, R.layout.power_row, powers);
}
@Override
public View getView(final int position, final View convertView, ViewGroup parent) {
LayoutInflater mInflater = LayoutInflater.from(getContext());
View mView = mInflater.inflate(R.layout.attack_row, parent, false);
View mView = mInflater.inflate(R.layout.power_row, parent, false);
final Power attack = getItem(position);
if ( attack != null ) {
((TextView) mView.findViewById(R.id.name)).setText(attack.getName());
((TextView) mView.findViewById(R.id.keywords)).setText(attack.getKeywords());
((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.range_and_distance)).setText(attack.getRangeString() + " " + attack.getDistance());
mView.setBackgroundColor(attack.getFreqColor(getContext()));
if (attack.isUsed())
mView.getBackground().setAlpha(0);

View file

@ -2,7 +2,6 @@ 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;
import android.support.v7.widget.Toolbar;
@ -14,8 +13,6 @@ import android.widget.Spinner;
public class PowerEditor extends ActionBarActivity {
public static final String NAME="name", FREQ="freq", KEYWORDS="keywords", RANGE="range", DISTANCE="distance";
private EditText [] edits = new EditText[5];
private Spinner [] spinners = new Spinner[5];
@ -53,7 +50,7 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.freq_array)
Power.FREQ
)
);
spinners[1] = (Spinner) findViewById(R.id.rangeSpinner);
@ -61,7 +58,7 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.ranges_array)
Power.RANGES
)
);
spinners[2] = (Spinner) findViewById(R.id.atkSpinner);
@ -69,7 +66,7 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.atk_array)
Power.ATK
)
);
spinners[3] = (Spinner) findViewById(R.id.defSpinner);
@ -77,26 +74,26 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.def_array)
Power.DEF
)
);
spinners[4] = (Spinner) findViewById(R.id.actionTypeSpinner);
spinners[4] = (Spinner) findViewById(R.id.actionSpinner);
spinners[4].setAdapter(
new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.actions_array)
Power.ACTIONS
)
);
background = spinners[0].getBackground();
if (power != -1) {
SharedPreferences pp = getSharedPreferences(p.getString("power" + power, ""), MODE_PRIVATE);
SharedPreferences powerPrefs = getSharedPreferences(p.getString("power" + power, ""), MODE_PRIVATE);
for ( int i = 0; i < spinners.length; i++ )
spinners[i].setSelection(pp.getInt("i" + i, 0));
spinners[i].setSelection(powerPrefs.getInt("i" + i, 0));
for ( int i = 0; i < edits.length; i++ )
edits[i].setText(pp.getString("s" + i, ""));
edits[i].setText(powerPrefs.getString("s" + i, ""));
originalName = edits[0].getText().toString();
}

View file

@ -40,16 +40,15 @@ public class ShowPlayer extends ActionBarActivity {
public Player player;
private boolean undo;
//TODO: fix undo (show snackbar with button in each case, without timing).
private int undoObject, undoPreviousValue;
private ProgressBar posPgBar, negPgBar, xpBar, curativeEffortsBar;
private TextView currentPg, currentXp, currentCurativeEfforts, level;
private ProgressBar posHpBar, negHpBar, xpBar, surgesBar;
private TextView hpText, xpText, surgesText, levelText;
private SharedPreferences p;
private Toolbar toolbar;
private ListView attackList;
private ListView powerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -70,19 +69,19 @@ public class ShowPlayer extends ActionBarActivity {
}
//Performing all the findViewById commands
xpBar = (ProgressBar) findViewById(R.id.xpBar);
curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
posPgBar = (ProgressBar) findViewById(R.id.pgBar);
negPgBar = (ProgressBar) findViewById(R.id.negPgBar);
xpBar = (ProgressBar) findViewById(R.id.xpBar);
surgesBar = (ProgressBar) findViewById(R.id.surgesBar);
posHpBar = (ProgressBar) findViewById(R.id.positive_hp_bar);
negHpBar = (ProgressBar) findViewById(R.id.negative_hp_bar);
currentPg = (TextView) findViewById(R.id.currentPg);
currentXp = (TextView) findViewById(R.id.currentXp);
currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts);
level = (TextView) findViewById(R.id.level);
hpText = (TextView) findViewById(R.id.hpText);
xpText = (TextView) findViewById(R.id.xpText);
surgesText = (TextView) findViewById(R.id.surgesText);
levelText = (TextView) findViewById(R.id.levelText);
xpBar.getProgressDrawable()
.setColorFilter(getResources().getColor(R.color.px_bar), PorterDuff.Mode.SRC_IN);
curativeEffortsBar.getProgressDrawable()
surgesBar.getProgressDrawable()
.setColorFilter(getResources().getColor(R.color.surges_bar), PorterDuff.Mode.SRC_IN);
undo = false;
@ -100,7 +99,7 @@ public class ShowPlayer extends ActionBarActivity {
@Override
public boolean onPrepareOptionsMenu (Menu menu) {
MenuItem menuHeal = menu.findItem(R.id.action_cure);
boolean maxed = player.getPg() == player.getMaxPg();
boolean maxed = player.getHp() == player.getMaxHp();
menuHeal.setEnabled(!maxed);
if (maxed)
menuHeal.getIcon().setAlpha(128);
@ -112,10 +111,10 @@ public class ShowPlayer extends ActionBarActivity {
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();
p.edit().putInt("px", player.getXp()).apply();
xpUpdate();
surgeUpdate();
hpUpdate();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "There was an error leveling up", Toast.LENGTH_LONG).show();
}
@ -130,7 +129,7 @@ public class ShowPlayer extends ActionBarActivity {
//noinspection SimplifiableIfStatement
if (id == R.id.action_cure) {
if(player.getMaxPg() <= player.getPg()){
if(player.getMaxHp() <= player.getHp()){
SnackbarManager.show(
Snackbar
.with(this)
@ -167,23 +166,22 @@ public class ShowPlayer extends ActionBarActivity {
alert.setNegativeButton(R.string.level_up, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
player.setPx(Player.LEVEL_PX[player.getLevel()]);
player.setXp(Player.LEVEL_XP[player.getLevel()]);
levelUp();
p.edit().putInt(Player.PX, player.getPx()).apply();
pxUpdate();
p.edit().putInt(Player.XP, player.getXp()).apply();
xpUpdate();
}
});
alert.show();
input.requestFocus();
return true;
//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);
PowerAdapter powerAdapter = (PowerAdapter) powerList.getAdapter();
if (powerAdapter != null) {
for (int i = 0; i < powerAdapter.getCount(); i++) {
Power power = powerAdapter.getItem(i);
if ( power.getFreq() != Power.AT_WILL) {
power.recover(Power.DAILY);
getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE)
.edit().putBoolean("used", false);
}
@ -199,18 +197,18 @@ public class ShowPlayer extends ActionBarActivity {
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
);
p.edit()
.putInt("pg", player.getPg())
.putInt("curativeEfforts", player.getCurativeEfforts())
.putInt("pg", player.getHp())
.putInt("curativeEfforts", player.getSurges())
.apply();
pgUpdate();
ceUpdate();
hpUpdate();
surgeUpdate();
} 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);
PowerAdapter powerAdapter = (PowerAdapter) powerList.getAdapter();
if (powerAdapter != null) {
for (int i = 0; i < powerAdapter.getCount(); i++) {
Power power = powerAdapter.getItem(i);
if ( power.getFreq() == Power.ENCOUNTER) {
power.recover(Power.ENCOUNTER);
getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE)
.edit().putBoolean("used", false);
}
@ -224,8 +222,8 @@ public class ShowPlayer extends ActionBarActivity {
.text(R.string.rest_done)
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
);
pgUpdate();
ceUpdate();
hpUpdate();
surgeUpdate();
}
return super.onOptionsItemSelected(item);
@ -233,17 +231,17 @@ public class ShowPlayer extends ActionBarActivity {
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]);
xpBar.setMax(Player.LEVEL_XP[player.getLevel()] -
Player.LEVEL_XP[player.getLevel() - 1]);
}
@Override
protected void onResume() {
super.onResume();
restoreData();
pgUpdate();
ceUpdate();
pxUpdate();
hpUpdate();
surgeUpdate();
xpUpdate();
}
/**
@ -263,13 +261,13 @@ public class ShowPlayer extends ActionBarActivity {
return false;
} else {
SharedPreferences.Editor e = p.edit();
e.putInt("pg", player.getPg());
e.putInt("pg", player.getHp());
if(usesEffort) {
e.putInt("curativeEfforts", player.getCurativeEfforts());
ceUpdate();
e.putInt("curativeEfforts", player.getSurges());
surgeUpdate();
}
e.apply();
pgUpdate();
hpUpdate();
return true;
}
}
@ -285,24 +283,24 @@ public class ShowPlayer extends ActionBarActivity {
.setTitle(R.string.new_energies)
.setPositiveButton(R.string.me, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
undoPreviousValue = player.getPg();
if (heal(true)) {
undoPreviousValue = player.getHp();
if (heal(true)) { //a surge has been used
SnackbarManager.show(
Snackbar.with(getApplicationContext())
.text(String.format(getString(R.string.healed), player.getMaxPg() / 4))
.text(String.format(getString(R.string.healed), player.getMaxHp() / 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);
player.setHp(undoPreviousValue);
player.setCurativeEffort(player.getSurges() + 1);
p.edit().putInt("pg", undoPreviousValue)
.putInt("curativeEfforts", player.getCurativeEfforts())
.putInt("curativeEfforts", player.getSurges())
.apply();
pgUpdate();
ceUpdate();
hpUpdate();
surgeUpdate();
SnackbarManager.show(
Snackbar
.with(getApplicationContext())
@ -320,18 +318,18 @@ public class ShowPlayer extends ActionBarActivity {
.setNegativeButton(R.string.other, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
undoPreviousValue = player.getPg();
undoPreviousValue = player.getHp();
heal(false);
SnackbarManager.show(
Snackbar.with(getApplicationContext())
.text(String.format(getString(R.string.healed), player.getMaxPg() / 4))
.text(String.format(getString(R.string.healed), player.getMaxHp() / 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.setHp(undoPreviousValue);
p.edit().putInt("pg", undoPreviousValue).apply();
SnackbarManager.show(
Snackbar
@ -340,7 +338,7 @@ public class ShowPlayer extends ActionBarActivity {
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE),
activity
);
pgUpdate();
hpUpdate();
}
}),
activity
@ -379,7 +377,7 @@ public class ShowPlayer extends ActionBarActivity {
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
int preValue = player.getPg();
int preValue = player.getHp();
int damage = Integer.parseInt(input.getText().toString());
player.losePg(damage);
undo = true;
@ -397,8 +395,8 @@ public class ShowPlayer extends ActionBarActivity {
.actionColor(getResources().getColor(R.color.yellow))
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
,activity); // action button's
p.edit().putInt("pg", player.getPg()).apply();
pgUpdate();
p.edit().putInt("pg", player.getHp()).apply();
hpUpdate();
invalidateOptionsMenu();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "There was an error", Toast.LENGTH_LONG).show();
@ -419,82 +417,46 @@ public class ShowPlayer extends ActionBarActivity {
* 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 pg = player.getPg();
negPgBar.setProgress(pg < 0 ? -pg : 0);
posPgBar.setProgress(pg > 0 ? pg : 0);
private void hpUpdate() {
int hp = player.getHp();
negHpBar.setProgress(hp < 0 ? -hp : 0);
posHpBar.setProgress(hp > 0 ? hp : 0);
currentPg.setText(player.getPg() + " / " + player.getMaxPg());
hpText.setText(player.getHp() + " / " + player.getMaxHp());
int color = player.getStatusColor(getApplicationContext());
posPgBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
negPgBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
int color = player.getStatusColor(getApplicationContext().getResources());
posHpBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
negHpBar.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.
* This includes an update for the powerList layout.
*/
private void restoreData(){
//Loading player
player = new Player( p );
pxUpdate();
xpUpdate();
xpBar.setMax(
Player.LEVEL_PX[player.getLevel()] -
Player.LEVEL_PX[player.getLevel() - 1]
Player.LEVEL_XP[player.getLevel()] -
Player.LEVEL_XP[player.getLevel() - 1]
);
player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxCurativeEfforts()));
player.setPg(p.getInt("pg", player.getMaxPg()));
player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxSurges()));
player.setHp(p.getInt("pg", player.getMaxHp()));
posPgBar.setMax(player.getMaxPg());
negPgBar.setMax(player.getMaxPg() / 2);
curativeEffortsBar.setMax(player.getMaxCurativeEfforts());
pgUpdate();
ceUpdate();
posHpBar.setMax(player.getMaxHp());
negHpBar.setMax(player.getMaxHp() / 2);
surgesBar.setMax(player.getMaxSurges());
hpUpdate();
surgeUpdate();
//set restored values to the respective fields
toolbar.setTitle(player.getName());
toolbar.setSubtitle(
player.getClassName() + " " + player.getRaceName()
);
// //attacks
// ((TextView) findViewById(R.id.FUE)).setText(
// getString(R.string.FUE) + ":" + player.getFue()
// );
// ((TextView) findViewById(R.id.CON)).setText(
// getString(R.string.CON) + ":" + player.getCon()
// );
// ((TextView) findViewById(R.id.DES)).setText(
// getString(R.string.DES) + ":" + player.getDes()
// );
// ((TextView) findViewById(R.id.INT)).setText(
// getString(R.string.INT) + ":" + player.getInt()
// );
// ((TextView) findViewById(R.id.SAB)).setText(
// getString(R.string.SAB) + ":" + player.getSab()
// );
// ((TextView) findViewById(R.id.CAR)).setText(
// getString(R.string.CAR) + ":" + player.getCar()
// );
//
// //defenses
// ((TextView) findViewById(R.id.CA)).setText(
// getString(R.string.CA) + ":" + player.getCa()
// );
// ((TextView) findViewById(R.id.FORT)).setText(
// getString(R.string.FORT) + ":" + player.getFort()
// );
// ((TextView) findViewById(R.id.REF)).setText(
// getString(R.string.REF) + ":" + player.getRef()
// );
// ((TextView) findViewById(R.id.VOL)).setText(
// getString(R.string.VOL) + ":" + player.getVol()
// );
//
//
//Loading powers and abilities (not implemented yet)
refreshList();
}
@ -502,34 +464,35 @@ public class ShowPlayer extends ActionBarActivity {
/**
* This updates the progress and indicator text of the available surges.
*/
private void ceUpdate() {
curativeEffortsBar.setProgress(player.getCurativeEfforts());
currentCurativeEfforts.setText(
player.getCurativeEfforts() + " / " +
player.getMaxCurativeEfforts()
private void surgeUpdate() {
surgesBar.setProgress(player.getSurges());
surgesText.setText(
player.getSurges() + " / " +
player.getMaxSurges()
);
}
/**
* Updates the progress and indicator text of the XP
*/
private void pxUpdate() {
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()]
private void xpUpdate() {
xpBar.setProgress(player.getXp() - Player.LEVEL_XP[player.getLevel() - 1]);
levelText.setText(getString(R.string.level) + " " + player.getLevel());
xpText.setText(
player.getXp() + " / " +
Player.LEVEL_XP[player.getLevel()]
);
}
/**
* Undoes the last change done by the player. Only used in damage(). Healing is not yet included
* Undoes the last change done by the player. Only used in damage().
* Healing is undone in the health dialog
*/
private void undo() {
String message = "";
if(undoObject == CURRENT_PG){
player.setPg(undoPreviousValue);
player.setHp(undoPreviousValue);
undoObject = NULL;
message = getString(R.string.restored);
}
@ -541,7 +504,7 @@ public class ShowPlayer extends ActionBarActivity {
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
);
}
pgUpdate();
hpUpdate();
undo = false;
invalidateOptionsMenu();
}
@ -575,8 +538,8 @@ public class ShowPlayer extends ActionBarActivity {
int n = p.getInt("powers",0);
int elements = 0;
attackList = (ListView) findViewById(R.id.attackList);
final AttackAdapter adapter = (AttackAdapter) attackList.getAdapter();
powerList = (ListView) findViewById(R.id.powerList);
final PowerAdapter adapter = (PowerAdapter) powerList.getAdapter();
if ( adapter != null )
elements = adapter.getCount();
@ -593,24 +556,15 @@ public class ShowPlayer extends ActionBarActivity {
powers.add( new Power(sav) );
}
attackList.setAdapter(new AttackAdapter(this, powers));
powerList.setAdapter(new PowerAdapter(this, powers));
final Activity activity = this;
attackList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
powerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
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);
dialog.setContentView(R.layout.attack_display);
// set the custom dialog components - text, image and button
// Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// // if button is clicked, close the custom dialog
// dialogButton.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// dialog.dismiss();
// }
// });
//identify all the elements from the VIEW and then add LISTENERS
final Power power = (Power) parent.getItemAtPosition(position);
@ -628,8 +582,8 @@ public class ShowPlayer extends ActionBarActivity {
((TextView) dialog.findViewById(R.id.impactText)).setText(power.getImpact());
((TextView) dialog.findViewById(R.id.otherText)).setText(power.getOther());
String[] attack = getResources().getStringArray(R.array.attack_array);
String[] defense = getResources().getStringArray(R.array.defense_array);
String[] attack = getResources().getStringArray(R.array.attack);
String[] defense = getResources().getStringArray(R.array.defense);
((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()]
+ " " + getResources().getString(R.string.vs)
+ " " + defense[power.getDef()]);
@ -657,7 +611,7 @@ public class ShowPlayer extends ActionBarActivity {
useButton.setEnabled(false);
useButton.setClickable(false);
getSharedPreferences(p.getString("power" + position, ""), MODE_PRIVATE)
.edit().putBoolean("used", true).apply();
.edit().putBoolean("used", true).apply();
refreshList();
SnackbarManager.show(
Snackbar.with(getApplicationContext())
@ -665,7 +619,7 @@ public class ShowPlayer extends ActionBarActivity {
.actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
power.recover(Power.DIARIO);
power.recover(Power.DAILY);
useButton.setBackgroundColor(color);
useButton.setTextColor(getResources().getColor(R.color.white));
useButton.getBackground().setAlpha(255);
@ -700,17 +654,16 @@ public class ShowPlayer extends ActionBarActivity {
}
final Activity thisActivity = this;
attackList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
powerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@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[]{getString(R.string.delete), getString(R.string.edit)},
new DialogInterface.OnClickListener()
{
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if ( which == 0 ) {
if (which == 0) {
SnackbarManager.show(
Snackbar.with(getApplicationContext())
.text(R.string.sure)
@ -754,7 +707,7 @@ public class ShowPlayer extends ActionBarActivity {
);
}
}
});
});
alert.show();
return true;
}

View file

@ -4,7 +4,6 @@ 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;
@ -35,7 +34,10 @@ public class Welcome extends ActionBarActivity {
setContentView(R.layout.activity_welcome);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
Player.setStrings(getResources());
Power .setStrings(getResources());
p = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
load();
}
@ -68,10 +70,9 @@ public class Welcome extends ActionBarActivity {
load();
}
//TODO: load all players with secondary constructor (except the ones created by introduction and haven't passed by ShowPlayer)
private void load() {
int n = p.getInt("players",0);
ListView playerList = (ListView) findViewById(R.id.listView);
ListView playerList = (ListView) findViewById(R.id.playersList);
final PlayerAdapter adapter = (PlayerAdapter) playerList.getAdapter();
int elements = 0;
if ( adapter != null )
@ -93,7 +94,7 @@ public class Welcome extends ActionBarActivity {
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)) //TODO: adding a second player causes an error
if (sav.contains(Player.NAME))
players.add( new Player( sav ) );
}