Watch
1
0
Fork
You've already forked DungeonManager
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 642 additions and 936 deletions

View file

@ -1,6 +1,7 @@
<component name="ProjectDictionaryState"> <component name="ProjectDictionaryState">
<dictionary name="Carlos"> <dictionary name="Carlos">
<words> <words>
<w>dungeoneering</w>
<w>snackbar</w> <w>snackbar</w>
</words> </words>
</dictionary> </dictionary>

2
.idea/misc.xml generated
View file

@ -13,7 +13,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View file

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

View file

@ -1,8 +1,6 @@
package com.kauron.dungeonmanager; package com.kauron.dungeonmanager;
import android.content.Context; import android.content.Context;
import android.graphics.AvoidXfermode;
import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -28,23 +26,23 @@ class PlayerAdapter extends ArrayAdapter<Player> {
if ( player != null ) { if ( player != null ) {
((TextView) mView.findViewById(R.id.name)).setText(player.getName()); ((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.class_and_race)).setText(player.getClassName() + " " + player.getRaceName());
((TextView) mView.findViewById(R.id.level)) ((TextView) mView.findViewById(R.id.levelText))
.setText( .setText(
getContext().getResources().getString(R.string.level) + " " + player.getLevel() getContext().getResources().getString(R.string.level) + " " + player.getLevel()
); );
int pg = player.getPg(); int hp = player.getHp();
int maxPg = player.getMaxPg(); int maxHp = player.getMaxHp();
ProgressBar neg = (ProgressBar) mView.findViewById(R.id.negPgBar); ProgressBar neg = (ProgressBar) mView.findViewById(R.id.negative_hp_bar);
ProgressBar pos = (ProgressBar) mView.findViewById(R.id.pgBar); ProgressBar pos = (ProgressBar) mView.findViewById(R.id.positive_hp_bar);
neg.setMax(maxPg / 2); neg.setMax(maxHp / 2);
pos.setMax(maxPg); pos.setMax(maxHp);
neg.setProgress(pg < 0 ? -pg : 0); neg.setProgress(hp < 0 ? -hp : 0);
pos.setProgress(pg > 0 ? pg : 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); neg.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
pos.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 TABLE_PLAYERS = "players";
public static final String C_ID="_id", C_NAME="name", C_CLASS="class", C_RACE="race"; 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_HP ="hp", C_HP_MAX ="hpMax", 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_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: complete class and implement database to save the players instead of sharedprefs
//TODO: not using it at the moment //TODO: not using it at the moment

View file

@ -18,7 +18,7 @@ import com.nispok.snackbar.SnackbarManager;
public class PlayerEditor extends ActionBarActivity { public class PlayerEditor extends ActionBarActivity {
private EditText name, level; private EditText name, level;
private EditText fue, con, des, sab, intel, car; private EditText str, con, dex, wis, intel, cha;
private Spinner classSpinner, raceSpinner; private Spinner classSpinner, raceSpinner;
@Override @Override
@ -30,15 +30,15 @@ public class PlayerEditor extends ActionBarActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true); getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
name = (EditText) findViewById(R.id.editNameIntro); name = (EditText) findViewById(R.id.namePlayerEdit);
name.requestFocus(); name.requestFocus();
level = (EditText) findViewById(R.id.editPxIntro); level = (EditText) findViewById(R.id.xpEdit);
fue = (EditText) findViewById(R.id.FUE); str = (EditText) findViewById(R.id.STR);
con = (EditText) findViewById(R.id.CON); con = (EditText) findViewById(R.id.CON);
des = (EditText) findViewById(R.id.DES); dex = (EditText) findViewById(R.id.DEX);
sab = (EditText) findViewById(R.id.SAB); wis = (EditText) findViewById(R.id.WIS);
intel = (EditText) findViewById(R.id.INT); 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 = (Spinner) findViewById(R.id.classSpinner);
classSpinner.setAdapter( classSpinner.setAdapter(
@ -108,20 +108,19 @@ public class PlayerEditor extends ActionBarActivity {
pxInt = Integer.parseInt(level.getText().toString()); pxInt = Integer.parseInt(level.getText().toString());
int fue = 0, con = 0, des = 0, intel = 0, sab = 0, car = 0; int fue = 0, con = 0, des = 0, intel = 0, sab = 0, car = 0;
if (!this.car.getText().toString().isEmpty()) if (!this.cha.getText().toString().isEmpty())
car = Integer.parseInt(this.car.getText().toString()); car = Integer.parseInt(this.cha.getText().toString());
if (!this.fue.getText().toString().isEmpty()) if (!this.str.getText().toString().isEmpty())
fue = Integer.parseInt(this.fue.getText().toString()); fue = Integer.parseInt(this.str.getText().toString());
if (!this.con.getText().toString().isEmpty()) if (!this.con.getText().toString().isEmpty())
con = Integer.parseInt(this.con.getText().toString()); con = Integer.parseInt(this.con.getText().toString());
if (!this.des.getText().toString().isEmpty()) if (!this.dex.getText().toString().isEmpty())
des = Integer.parseInt(this.des.getText().toString()); des = Integer.parseInt(this.dex.getText().toString());
if (!this.intel.getText().toString().isEmpty()) if (!this.intel.getText().toString().isEmpty())
intel = Integer.parseInt(this.intel.getText().toString()); intel = Integer.parseInt(this.intel.getText().toString());
if (!this.sab.getText().toString().isEmpty()) if (!this.wis.getText().toString().isEmpty())
sab = Integer.parseInt(this.sab.getText().toString()); sab = Integer.parseInt(this.wis.getText().toString());
// if(first) {
if ( if (
!nameString.isEmpty() && !nameString.isEmpty() &&
classInt != Player.NULL && classInt != Player.NULL &&
@ -159,23 +158,9 @@ public class PlayerEditor extends ActionBarActivity {
//TEMP //TEMP
ed.putBoolean("new", true); ed.putBoolean("new", true);
ed.apply(); ed.apply();
return true;
} else { } else {
return false; return false;
} }
// } 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);
// }
return true;
} }
} }

View file

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

View file

@ -0,0 +1,36 @@
package com.kauron.dungeonmanager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
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.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.range_and_distance)).setText(attack.getRangeString() + " " + attack.getDistance());
mView.setBackgroundColor(attack.getFreqColor(getContext()));
if (attack.isUsed())
mView.getBackground().setAlpha(0);
else
mView.getBackground().setAlpha((position % 2) * 50 + 205);
}
return mView;
}
}

View file

@ -2,7 +2,6 @@ package com.kauron.dungeonmanager;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -14,8 +13,6 @@ import android.widget.Spinner;
public class PowerEditor extends ActionBarActivity { 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 EditText [] edits = new EditText[5];
private Spinner [] spinners = new Spinner[5]; private Spinner [] spinners = new Spinner[5];
@ -53,7 +50,7 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>( new ArrayAdapter<>(
this, this,
android.R.layout.simple_spinner_dropdown_item, android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.freq_array) Power.FREQ
) )
); );
spinners[1] = (Spinner) findViewById(R.id.rangeSpinner); spinners[1] = (Spinner) findViewById(R.id.rangeSpinner);
@ -61,7 +58,7 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>( new ArrayAdapter<>(
this, this,
android.R.layout.simple_spinner_dropdown_item, android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.ranges_array) Power.RANGES
) )
); );
spinners[2] = (Spinner) findViewById(R.id.atkSpinner); spinners[2] = (Spinner) findViewById(R.id.atkSpinner);
@ -69,7 +66,7 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>( new ArrayAdapter<>(
this, this,
android.R.layout.simple_spinner_dropdown_item, android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.atk_array) Power.ATK
) )
); );
spinners[3] = (Spinner) findViewById(R.id.defSpinner); spinners[3] = (Spinner) findViewById(R.id.defSpinner);
@ -77,26 +74,26 @@ public class PowerEditor extends ActionBarActivity {
new ArrayAdapter<>( new ArrayAdapter<>(
this, this,
android.R.layout.simple_spinner_dropdown_item, 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( spinners[4].setAdapter(
new ArrayAdapter<>( new ArrayAdapter<>(
this, this,
android.R.layout.simple_spinner_dropdown_item, android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.actions_array) Power.ACTIONS
) )
); );
background = spinners[0].getBackground(); background = spinners[0].getBackground();
if (power != -1) { 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++ ) 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++ ) 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(); originalName = edits[0].getText().toString();
} }

View file

@ -40,16 +40,15 @@ public class ShowPlayer extends ActionBarActivity {
public Player player; public Player player;
private boolean undo; private boolean undo;
//TODO: fix undo (show snackbar with button in each case, without timing).
private int undoObject, undoPreviousValue; private int undoObject, undoPreviousValue;
private ProgressBar posPgBar, negPgBar, xpBar, curativeEffortsBar; private ProgressBar posHpBar, negHpBar, xpBar, surgesBar;
private TextView currentPg, currentXp, currentCurativeEfforts, level; private TextView hpText, xpText, surgesText, levelText;
private SharedPreferences p; private SharedPreferences p;
private Toolbar toolbar; private Toolbar toolbar;
private ListView attackList; private ListView powerList;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -71,18 +70,18 @@ public class ShowPlayer extends ActionBarActivity {
//Performing all the findViewById commands //Performing all the findViewById commands
xpBar = (ProgressBar) findViewById(R.id.xpBar); xpBar = (ProgressBar) findViewById(R.id.xpBar);
curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar); surgesBar = (ProgressBar) findViewById(R.id.surgesBar);
posPgBar = (ProgressBar) findViewById(R.id.pgBar); posHpBar = (ProgressBar) findViewById(R.id.positive_hp_bar);
negPgBar = (ProgressBar) findViewById(R.id.negPgBar); negHpBar = (ProgressBar) findViewById(R.id.negative_hp_bar);
currentPg = (TextView) findViewById(R.id.currentPg); hpText = (TextView) findViewById(R.id.hpText);
currentXp = (TextView) findViewById(R.id.currentXp); xpText = (TextView) findViewById(R.id.xpText);
currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts); surgesText = (TextView) findViewById(R.id.surgesText);
level = (TextView) findViewById(R.id.level); levelText = (TextView) findViewById(R.id.levelText);
xpBar.getProgressDrawable() xpBar.getProgressDrawable()
.setColorFilter(getResources().getColor(R.color.px_bar), PorterDuff.Mode.SRC_IN); .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); .setColorFilter(getResources().getColor(R.color.surges_bar), PorterDuff.Mode.SRC_IN);
undo = false; undo = false;
@ -100,7 +99,7 @@ public class ShowPlayer extends ActionBarActivity {
@Override @Override
public boolean onPrepareOptionsMenu (Menu menu) { public boolean onPrepareOptionsMenu (Menu menu) {
MenuItem menuHeal = menu.findItem(R.id.action_cure); MenuItem menuHeal = menu.findItem(R.id.action_cure);
boolean maxed = player.getPg() == player.getMaxPg(); boolean maxed = player.getHp() == player.getMaxHp();
menuHeal.setEnabled(!maxed); menuHeal.setEnabled(!maxed);
if (maxed) if (maxed)
menuHeal.getIcon().setAlpha(128); menuHeal.getIcon().setAlpha(128);
@ -112,10 +111,10 @@ public class ShowPlayer extends ActionBarActivity {
private void addPx(EditText input) { private void addPx(EditText input) {
try { try {
if (player.addPx(Integer.parseInt(input.getText().toString()))) levelUp(); if (player.addPx(Integer.parseInt(input.getText().toString()))) levelUp();
p.edit().putInt("px", player.getPx()).apply(); p.edit().putInt("px", player.getXp()).apply();
pxUpdate(); xpUpdate();
ceUpdate(); surgeUpdate();
pgUpdate(); hpUpdate();
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(getApplicationContext(), "There was an error leveling up", Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), "There was an error leveling up", Toast.LENGTH_LONG).show();
} }
@ -130,7 +129,7 @@ public class ShowPlayer extends ActionBarActivity {
//noinspection SimplifiableIfStatement //noinspection SimplifiableIfStatement
if (id == R.id.action_cure) { if (id == R.id.action_cure) {
if(player.getMaxPg() <= player.getPg()){ if(player.getMaxHp() <= player.getHp()){
SnackbarManager.show( SnackbarManager.show(
Snackbar Snackbar
.with(this) .with(this)
@ -167,23 +166,22 @@ public class ShowPlayer extends ActionBarActivity {
alert.setNegativeButton(R.string.level_up, new DialogInterface.OnClickListener() { alert.setNegativeButton(R.string.level_up, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
player.setPx(Player.LEVEL_PX[player.getLevel()]); player.setXp(Player.LEVEL_XP[player.getLevel()]);
levelUp(); levelUp();
p.edit().putInt(Player.PX, player.getPx()).apply(); p.edit().putInt(Player.XP, player.getXp()).apply();
pxUpdate(); xpUpdate();
} }
}); });
alert.show(); alert.show();
input.requestFocus(); input.requestFocus();
return true; return true;
//TODO: TEST fix restoring powers
} else if (id == R.id.action_time_long_rest) { } else if (id == R.id.action_time_long_rest) {
AttackAdapter attackAdapter = (AttackAdapter)attackList.getAdapter(); PowerAdapter powerAdapter = (PowerAdapter) powerList.getAdapter();
if (attackAdapter != null) { if (powerAdapter != null) {
for (int i = 0; i < attackAdapter.getCount(); i++) { for (int i = 0; i < powerAdapter.getCount(); i++) {
Power power = attackAdapter.getItem(i); Power power = powerAdapter.getItem(i);
if ( power.getFreq() != Power.A_VOLUNTAD ) { if ( power.getFreq() != Power.AT_WILL) {
power.recover(Power.DIARIO); power.recover(Power.DAILY);
getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE) getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE)
.edit().putBoolean("used", false); .edit().putBoolean("used", false);
} }
@ -199,18 +197,18 @@ public class ShowPlayer extends ActionBarActivity {
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
); );
p.edit() p.edit()
.putInt("pg", player.getPg()) .putInt("pg", player.getHp())
.putInt("curativeEfforts", player.getCurativeEfforts()) .putInt("curativeEfforts", player.getSurges())
.apply(); .apply();
pgUpdate(); hpUpdate();
ceUpdate(); surgeUpdate();
} else if (id == R.id.action_time_rest) { } else if (id == R.id.action_time_rest) {
AttackAdapter attackAdapter = (AttackAdapter) attackList.getAdapter(); PowerAdapter powerAdapter = (PowerAdapter) powerList.getAdapter();
if (attackAdapter != null) { if (powerAdapter != null) {
for (int i = 0; i < attackAdapter.getCount(); i++) { for (int i = 0; i < powerAdapter.getCount(); i++) {
Power power = attackAdapter.getItem(i); Power power = powerAdapter.getItem(i);
if ( power.getFreq() == Power.ENCUENTRO) { if ( power.getFreq() == Power.ENCOUNTER) {
power.recover(Power.ENCUENTRO); power.recover(Power.ENCOUNTER);
getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE) getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE)
.edit().putBoolean("used", false); .edit().putBoolean("used", false);
} }
@ -224,8 +222,8 @@ public class ShowPlayer extends ActionBarActivity {
.text(R.string.rest_done) .text(R.string.rest_done)
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
); );
pgUpdate(); hpUpdate();
ceUpdate(); surgeUpdate();
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -233,17 +231,17 @@ public class ShowPlayer extends ActionBarActivity {
private void levelUp() { private void levelUp() {
//TODO: improve leveling up by using a sliding guide //TODO: improve leveling up by using a sliding guide
xpBar.setMax(Player.LEVEL_PX[player.getLevel()] - xpBar.setMax(Player.LEVEL_XP[player.getLevel()] -
Player.LEVEL_PX[player.getLevel() - 1]); Player.LEVEL_XP[player.getLevel() - 1]);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
restoreData(); restoreData();
pgUpdate(); hpUpdate();
ceUpdate(); surgeUpdate();
pxUpdate(); xpUpdate();
} }
/** /**
@ -263,13 +261,13 @@ public class ShowPlayer extends ActionBarActivity {
return false; return false;
} else { } else {
SharedPreferences.Editor e = p.edit(); SharedPreferences.Editor e = p.edit();
e.putInt("pg", player.getPg()); e.putInt("pg", player.getHp());
if(usesEffort) { if(usesEffort) {
e.putInt("curativeEfforts", player.getCurativeEfforts()); e.putInt("curativeEfforts", player.getSurges());
ceUpdate(); surgeUpdate();
} }
e.apply(); e.apply();
pgUpdate(); hpUpdate();
return true; return true;
} }
} }
@ -285,24 +283,24 @@ public class ShowPlayer extends ActionBarActivity {
.setTitle(R.string.new_energies) .setTitle(R.string.new_energies)
.setPositiveButton(R.string.me, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.me, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
undoPreviousValue = player.getPg(); undoPreviousValue = player.getHp();
if (heal(true)) { if (heal(true)) { //a surge has been used
SnackbarManager.show( SnackbarManager.show(
Snackbar.with(getApplicationContext()) 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) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
.actionLabel(R.string.action_undo) .actionLabel(R.string.action_undo)
.actionColor(getResources().getColor(R.color.yellow)) .actionColor(getResources().getColor(R.color.yellow))
.actionListener(new ActionClickListener() { .actionListener(new ActionClickListener() {
@Override @Override
public void onActionClicked(Snackbar snackbar) { public void onActionClicked(Snackbar snackbar) {
player.setPg(undoPreviousValue); player.setHp(undoPreviousValue);
player.setCurativeEffort(player.getCurativeEfforts() + 1); player.setCurativeEffort(player.getSurges() + 1);
p.edit().putInt("pg", undoPreviousValue) p.edit().putInt("pg", undoPreviousValue)
.putInt("curativeEfforts", player.getCurativeEfforts()) .putInt("curativeEfforts", player.getSurges())
.apply(); .apply();
pgUpdate(); hpUpdate();
ceUpdate(); surgeUpdate();
SnackbarManager.show( SnackbarManager.show(
Snackbar Snackbar
.with(getApplicationContext()) .with(getApplicationContext())
@ -320,18 +318,18 @@ public class ShowPlayer extends ActionBarActivity {
.setNegativeButton(R.string.other, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.other, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
undoPreviousValue = player.getPg(); undoPreviousValue = player.getHp();
heal(false); heal(false);
SnackbarManager.show( SnackbarManager.show(
Snackbar.with(getApplicationContext()) 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) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
.actionLabel(R.string.action_undo) .actionLabel(R.string.action_undo)
.actionColor(getResources().getColor(R.color.yellow)) .actionColor(getResources().getColor(R.color.yellow))
.actionListener(new ActionClickListener() { .actionListener(new ActionClickListener() {
@Override @Override
public void onActionClicked(Snackbar snackbar) { public void onActionClicked(Snackbar snackbar) {
player.setPg(undoPreviousValue); player.setHp(undoPreviousValue);
p.edit().putInt("pg", undoPreviousValue).apply(); p.edit().putInt("pg", undoPreviousValue).apply();
SnackbarManager.show( SnackbarManager.show(
Snackbar Snackbar
@ -340,7 +338,7 @@ public class ShowPlayer extends ActionBarActivity {
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE), .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE),
activity activity
); );
pgUpdate(); hpUpdate();
} }
}), }),
activity activity
@ -379,7 +377,7 @@ public class ShowPlayer extends ActionBarActivity {
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
try { try {
int preValue = player.getPg(); int preValue = player.getHp();
int damage = Integer.parseInt(input.getText().toString()); int damage = Integer.parseInt(input.getText().toString());
player.losePg(damage); player.losePg(damage);
undo = true; undo = true;
@ -397,8 +395,8 @@ public class ShowPlayer extends ActionBarActivity {
.actionColor(getResources().getColor(R.color.yellow)) .actionColor(getResources().getColor(R.color.yellow))
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
,activity); // action button's ,activity); // action button's
p.edit().putInt("pg", player.getPg()).apply(); p.edit().putInt("pg", player.getHp()).apply();
pgUpdate(); hpUpdate();
invalidateOptionsMenu(); invalidateOptionsMenu();
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(getApplicationContext(), "There was an error", Toast.LENGTH_LONG).show(); 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 hit points progress bars to the adequate value and color.
* Sets the text indicating the numerical value of the hit points * Sets the text indicating the numerical value of the hit points
*/ */
private void pgUpdate() { private void hpUpdate() {
int pg = player.getPg(); int hp = player.getHp();
negPgBar.setProgress(pg < 0 ? -pg : 0); negHpBar.setProgress(hp < 0 ? -hp : 0);
posPgBar.setProgress(pg > 0 ? pg : 0); posHpBar.setProgress(hp > 0 ? hp : 0);
currentPg.setText(player.getPg() + " / " + player.getMaxPg()); hpText.setText(player.getHp() + " / " + player.getMaxHp());
int color = player.getStatusColor(getApplicationContext()); int color = player.getStatusColor(getApplicationContext().getResources());
posPgBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); posHpBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
negPgBar.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 * 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(){ private void restoreData(){
//Loading player //Loading player
player = new Player( p ); player = new Player( p );
pxUpdate(); xpUpdate();
xpBar.setMax( xpBar.setMax(
Player.LEVEL_PX[player.getLevel()] - Player.LEVEL_XP[player.getLevel()] -
Player.LEVEL_PX[player.getLevel() - 1] Player.LEVEL_XP[player.getLevel() - 1]
); );
player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxCurativeEfforts())); player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxSurges()));
player.setPg(p.getInt("pg", player.getMaxPg())); player.setHp(p.getInt("pg", player.getMaxHp()));
posPgBar.setMax(player.getMaxPg()); posHpBar.setMax(player.getMaxHp());
negPgBar.setMax(player.getMaxPg() / 2); negHpBar.setMax(player.getMaxHp() / 2);
curativeEffortsBar.setMax(player.getMaxCurativeEfforts()); surgesBar.setMax(player.getMaxSurges());
pgUpdate(); hpUpdate();
ceUpdate(); surgeUpdate();
//set restored values to the respective fields //set restored values to the respective fields
toolbar.setTitle(player.getName()); toolbar.setTitle(player.getName());
toolbar.setSubtitle( toolbar.setSubtitle(
player.getClassName() + " " + player.getRaceName() 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) //Loading powers and abilities (not implemented yet)
refreshList(); refreshList();
} }
@ -502,34 +464,35 @@ public class ShowPlayer extends ActionBarActivity {
/** /**
* This updates the progress and indicator text of the available surges. * This updates the progress and indicator text of the available surges.
*/ */
private void ceUpdate() { private void surgeUpdate() {
curativeEffortsBar.setProgress(player.getCurativeEfforts()); surgesBar.setProgress(player.getSurges());
currentCurativeEfforts.setText( surgesText.setText(
player.getCurativeEfforts() + " / " + player.getSurges() + " / " +
player.getMaxCurativeEfforts() player.getMaxSurges()
); );
} }
/** /**
* Updates the progress and indicator text of the XP * Updates the progress and indicator text of the XP
*/ */
private void pxUpdate() { private void xpUpdate() {
xpBar.setProgress(player.getPx() - Player.LEVEL_PX[player.getLevel() - 1]); xpBar.setProgress(player.getXp() - Player.LEVEL_XP[player.getLevel() - 1]);
level.setText(getString(R.string.level) + " " + player.getLevel()); levelText.setText(getString(R.string.level) + " " + player.getLevel());
currentXp.setText( xpText.setText(
player.getPx() + " / " + player.getXp() + " / " +
Player.LEVEL_PX[player.getLevel()] 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() { private void undo() {
String message = ""; String message = "";
if(undoObject == CURRENT_PG){ if(undoObject == CURRENT_PG){
player.setPg(undoPreviousValue); player.setHp(undoPreviousValue);
undoObject = NULL; undoObject = NULL;
message = getString(R.string.restored); message = getString(R.string.restored);
} }
@ -541,7 +504,7 @@ public class ShowPlayer extends ActionBarActivity {
.duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE)
); );
} }
pgUpdate(); hpUpdate();
undo = false; undo = false;
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
@ -575,8 +538,8 @@ public class ShowPlayer extends ActionBarActivity {
int n = p.getInt("powers",0); int n = p.getInt("powers",0);
int elements = 0; int elements = 0;
attackList = (ListView) findViewById(R.id.attackList); powerList = (ListView) findViewById(R.id.powerList);
final AttackAdapter adapter = (AttackAdapter) attackList.getAdapter(); final PowerAdapter adapter = (PowerAdapter) powerList.getAdapter();
if ( adapter != null ) if ( adapter != null )
elements = adapter.getCount(); elements = adapter.getCount();
@ -593,24 +556,15 @@ public class ShowPlayer extends ActionBarActivity {
powers.add( new Power(sav) ); powers.add( new Power(sav) );
} }
attackList.setAdapter(new AttackAdapter(this, powers)); powerList.setAdapter(new PowerAdapter(this, powers));
final Activity activity = this; final Activity activity = this;
attackList.setOnItemClickListener(new AdapterView.OnItemClickListener() { powerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
final Dialog dialog = new Dialog(ShowPlayer.this); final Dialog dialog = new Dialog(ShowPlayer.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.attack_display); 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 //identify all the elements from the VIEW and then add LISTENERS
final Power power = (Power) parent.getItemAtPosition(position); 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.impactText)).setText(power.getImpact());
((TextView) dialog.findViewById(R.id.otherText)).setText(power.getOther()); ((TextView) dialog.findViewById(R.id.otherText)).setText(power.getOther());
String[] attack = getResources().getStringArray(R.array.attack_array); String[] attack = getResources().getStringArray(R.array.attack);
String[] defense = getResources().getStringArray(R.array.defense_array); String[] defense = getResources().getStringArray(R.array.defense);
((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()] ((TextView) dialog.findViewById(R.id.attackText)).setText(attack[power.getAtk()]
+ " " + getResources().getString(R.string.vs) + " " + getResources().getString(R.string.vs)
+ " " + defense[power.getDef()]); + " " + defense[power.getDef()]);
@ -665,7 +619,7 @@ public class ShowPlayer extends ActionBarActivity {
.actionListener(new ActionClickListener() { .actionListener(new ActionClickListener() {
@Override @Override
public void onActionClicked(Snackbar snackbar) { public void onActionClicked(Snackbar snackbar) {
power.recover(Power.DIARIO); power.recover(Power.DAILY);
useButton.setBackgroundColor(color); useButton.setBackgroundColor(color);
useButton.setTextColor(getResources().getColor(R.color.white)); useButton.setTextColor(getResources().getColor(R.color.white));
useButton.getBackground().setAlpha(255); useButton.getBackground().setAlpha(255);
@ -700,14 +654,13 @@ public class ShowPlayer extends ActionBarActivity {
} }
final Activity thisActivity = this; final Activity thisActivity = this;
attackList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { powerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override @Override
public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) { public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {
AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity); AlertDialog.Builder alert = new AlertDialog.Builder(thisActivity);
alert.setItems( alert.setItems(
new String[]{getString(R.string.delete), getString(R.string.edit)}, new String[]{getString(R.string.delete), getString(R.string.edit)},
new DialogInterface.OnClickListener() new DialogInterface.OnClickListener() {
{
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == 0) { if (which == 0) {

View file

@ -4,7 +4,6 @@ import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -35,7 +34,10 @@ public class Welcome extends ActionBarActivity {
setContentView(R.layout.activity_welcome); setContentView(R.layout.activity_welcome);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
Player.setStrings(getResources());
Power .setStrings(getResources());
p = getSharedPreferences(PREFERENCES, MODE_PRIVATE); p = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
load(); load();
} }
@ -68,10 +70,9 @@ public class Welcome extends ActionBarActivity {
load(); load();
} }
//TODO: load all players with secondary constructor (except the ones created by introduction and haven't passed by ShowPlayer)
private void load() { private void load() {
int n = p.getInt("players",0); 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(); final PlayerAdapter adapter = (PlayerAdapter) playerList.getAdapter();
int elements = 0; int elements = 0;
if ( adapter != null ) if ( adapter != null )
@ -93,7 +94,7 @@ public class Welcome extends ActionBarActivity {
ArrayList<Player> players = new ArrayList<>(); ArrayList<Player> players = new ArrayList<>();
for ( int i = 0; i < n; i++ ) { for ( int i = 0; i < n; i++ ) {
SharedPreferences sav = getSharedPreferences(p.getString("player" + i, ""), MODE_PRIVATE); 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 ) ); players.add( new Player( sav ) );
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 757 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 492 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

Some files were not shown because too many files have changed in this diff Show more