Added PlayerAdapter
Still need to complete Power creation, edition and listing. Need to complete Player listing and deletion.
This commit is contained in:
parent
9ca863a607
commit
a3831597d0
25 changed files with 399 additions and 113 deletions
|
@ -1,10 +1,19 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
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 com.nispok.snackbar.Snackbar;
|
||||
import com.nispok.snackbar.SnackbarManager;
|
||||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
|
||||
class AttackAdapter extends ArrayAdapter<Power> {
|
||||
AttackAdapter(Context context, Power[] powers) {
|
||||
|
@ -12,11 +21,32 @@ class AttackAdapter extends ArrayAdapter<Power> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
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);
|
||||
|
||||
Power attack = getItem(position);
|
||||
final Power attack = getItem(position);
|
||||
|
||||
((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());
|
||||
final AttackAdapter current = this;
|
||||
((ImageView) mView.findViewById(R.id.delete)).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SnackbarManager.show(
|
||||
Snackbar.with(getContext()).text("¿Quieres borrarlo?").actionLabel("Sí").actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
current.remove(attack);
|
||||
}
|
||||
})
|
||||
);
|
||||
//TODO: convert text to resource
|
||||
}
|
||||
});
|
||||
|
||||
return mView;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
public class Player {
|
||||
class Player {
|
||||
|
||||
/**
|
||||
* Names for the classes
|
||||
|
@ -107,7 +107,7 @@ public class Player {
|
|||
//TODO: implement fully operational powers displayed as cards
|
||||
private Power[] powers;
|
||||
|
||||
public Player(
|
||||
Player(
|
||||
String name, int classInt, int raceInt,
|
||||
int px, int[] atk, int[] abilities,
|
||||
Power[] powers
|
||||
|
@ -128,22 +128,22 @@ public class Player {
|
|||
}
|
||||
|
||||
|
||||
public int getPx() {return px;}
|
||||
public void setPx (int px) {this.px = px; setLevel();}
|
||||
public boolean addPx(int px) {
|
||||
int getPx() {return px;}
|
||||
void setPx (int px) {this.px = px; setLevel();}
|
||||
boolean addPx(int px) {
|
||||
int lastLevel = level;
|
||||
setPx(this.px + px);
|
||||
return lastLevel < level;
|
||||
}
|
||||
|
||||
public int getMaxCurativeEfforts() {return maxCurativeEfforts;}
|
||||
public void setMaxCurativeEfforts(int maxCurativeEfforts) {this.maxCurativeEfforts = maxCurativeEfforts;}
|
||||
int getMaxCurativeEfforts() {return maxCurativeEfforts;}
|
||||
void setMaxCurativeEfforts(int maxCurativeEfforts) {this.maxCurativeEfforts = maxCurativeEfforts;}
|
||||
|
||||
public int getCurativeEfforts() {return curativeEfforts;}
|
||||
public void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;}
|
||||
int getCurativeEfforts() {return curativeEfforts;}
|
||||
void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;}
|
||||
|
||||
public int getLevel() {return level;}
|
||||
public void setLevel() {
|
||||
int getLevel() {return level;}
|
||||
void setLevel() {
|
||||
for (int i = 0; i < LEVEL_PX.length; i++){
|
||||
if(px < LEVEL_PX[i]) {
|
||||
level = i; return;
|
||||
|
@ -154,21 +154,21 @@ public class Player {
|
|||
}
|
||||
|
||||
|
||||
public int getMaxPg() {return maxPg;}
|
||||
public void setMaxPg(int maxPg) {
|
||||
int getMaxPg() {return maxPg;}
|
||||
void setMaxPg(int maxPg) {
|
||||
if(this.maxPg == 0)
|
||||
this.pg = maxPg;
|
||||
this.maxPg = maxPg;
|
||||
}
|
||||
public void setMaxPgOnLevelUp() {maxPg += CLASS_STATS[PG_ON_LEVEL_UP][classInt];}
|
||||
void setMaxPgOnLevelUp() {maxPg += CLASS_STATS[PG_ON_LEVEL_UP][classInt];}
|
||||
|
||||
public int getPg() {return pg;}
|
||||
public void setPg(int pg) {this.pg = pg; setState();}
|
||||
public void losePg(int damage) {
|
||||
int getPg() {return pg;}
|
||||
void setPg(int pg) {this.pg = pg; setState();}
|
||||
void losePg(int damage) {
|
||||
pg -= damage;
|
||||
setState();
|
||||
}
|
||||
public int recoverPg(int recovered, boolean uses) {
|
||||
int recoverPg(int recovered, boolean uses) {
|
||||
if(recovered == USE_CURATIVE_EFFORT){
|
||||
if(uses && curativeEfforts <= 0) return NOT_CURED;
|
||||
else {
|
||||
|
@ -193,8 +193,8 @@ public class Player {
|
|||
return CURED;
|
||||
}
|
||||
|
||||
public int getLastState() {return lastState == state ? SAME : lastState;}
|
||||
public int getState() {return state;}
|
||||
int getLastState() {return lastState == state ? SAME : lastState;}
|
||||
int getState() {return state;}
|
||||
private void setState() {
|
||||
lastState = state;
|
||||
if (pg <= maxPg / -2) state = MUERTO;
|
||||
|
@ -203,49 +203,49 @@ public class Player {
|
|||
else state = OK;
|
||||
}
|
||||
|
||||
public String getName() {return name;}
|
||||
public void setName(String name) {this.name = name;}
|
||||
String getName() {return name;}
|
||||
void setName(String name) {this.name = name;}
|
||||
|
||||
public int getClassInt() {return classInt;}
|
||||
public void setClassInt(int classInt) {
|
||||
int getClassInt() {return classInt;}
|
||||
void setClassInt(int classInt) {
|
||||
this.classInt = classInt;
|
||||
if (atk != null) setClass();
|
||||
}
|
||||
public String getClassName() {return CLASS_STRINGS[classInt];}
|
||||
String getClassName() {return CLASS_STRINGS[classInt];}
|
||||
|
||||
public String getRaceName() {return RACE_STRINGS[raceInt];}
|
||||
public void setRaceInt(int raceInt) {this.raceInt= raceInt;}
|
||||
public int getRaceInt() {return raceInt;}
|
||||
String getRaceName() {return RACE_STRINGS[raceInt];}
|
||||
void setRaceInt(int raceInt) {this.raceInt= raceInt;}
|
||||
int getRaceInt() {return raceInt;}
|
||||
|
||||
//TODO: implement turns (for bonuses and continuous damage in the app
|
||||
public void rest(boolean isLong) {
|
||||
void rest(boolean isLong) {
|
||||
if(isLong) {
|
||||
pg = maxPg;
|
||||
curativeEfforts = maxCurativeEfforts;
|
||||
for (Power p : powers)
|
||||
if (p != null && p.getType() == Power.DIARIO)
|
||||
if (p != null && p.getFrequency() == Power.DIARIO)
|
||||
p.recover();
|
||||
setState();
|
||||
}
|
||||
for (Power p : powers)
|
||||
if (p != null && p.getType() == Power.ENCUENTRO)
|
||||
if (p != null && p.getFrequency() == Power.ENCUENTRO)
|
||||
p.recover();
|
||||
}
|
||||
|
||||
public void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();}
|
||||
void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();}
|
||||
|
||||
public int getFue() {return atk[FUE];}
|
||||
public int getCon() {return atk[CON];}
|
||||
public int getSab() {return atk[SAB];}
|
||||
public int getCar() {return atk[CAR];}
|
||||
public int getDes() {return atk[DES];}
|
||||
public int getInt() {return atk[INT];}
|
||||
public int getCa() {return def[CA];}
|
||||
public int getFort() {return def[FORT];}
|
||||
public int getRef() {return def[REF];}
|
||||
public int getVol() {return def[VOL];}
|
||||
int getFue() {return atk[FUE];}
|
||||
int getCon() {return atk[CON];}
|
||||
int getSab() {return atk[SAB];}
|
||||
int getCar() {return atk[CAR];}
|
||||
int getDes() {return atk[DES];}
|
||||
int getInt() {return atk[INT];}
|
||||
int getCa() {return def[CA];}
|
||||
int getFort() {return def[FORT];}
|
||||
int getRef() {return def[REF];}
|
||||
int getVol() {return def[VOL];}
|
||||
|
||||
public void setClass() {
|
||||
void setClass() {
|
||||
if(level == 1) maxPg = atk[CON] + CLASS_STATS[INITIAL_PG][classInt];
|
||||
maxCurativeEfforts = Player.getModifier(atk[CON]) + CLASS_STATS[DAILY_CURATIVE_EFFORTS][classInt];
|
||||
//TODO: fix ca bonuses!
|
||||
|
@ -258,7 +258,7 @@ public class Player {
|
|||
CLASS_STATS[DEF_VOL][classInt];
|
||||
}
|
||||
|
||||
public static int getModifier(int i) {
|
||||
static int getModifier(int i) {
|
||||
return i / 2 - 5;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
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.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
class PlayerAdapter extends ArrayAdapter<Player> {
|
||||
|
||||
PlayerAdapter(Context context, Player[] players) {
|
||||
super(context, R.layout.player_row, players);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater mInflater = LayoutInflater.from(getContext());
|
||||
View mView = mInflater.inflate(R.layout.player_row, parent, false);
|
||||
|
||||
final Player player = getItem(position);
|
||||
|
||||
((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))
|
||||
.setText(
|
||||
getContext().getResources().getString(R.string.level)
|
||||
+ " " + player.getLevel()
|
||||
);
|
||||
|
||||
ProgressBar pg = (ProgressBar) mView.findViewById(R.id.progressBar);
|
||||
pg.setMax(player.getMaxPg());
|
||||
pg.setProgress(player.getPg());
|
||||
|
||||
return mView;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,28 +1,64 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
public class Power {
|
||||
class Power {
|
||||
public static final int MELEE = 1, AREA = 2, RANGED = 3;
|
||||
public static final int DIARIO = 4, A_VOLUNTAD = 2, ENCUENTRO = 3, OPORTUNIDAD = 1;
|
||||
|
||||
private boolean used;
|
||||
private int type;
|
||||
private String name;
|
||||
private int atk, def, damage;
|
||||
private int frequency, range, distance;
|
||||
private String name, keywords;
|
||||
private int atk, def;
|
||||
/** An array filled with the maximum damage of each die.
|
||||
* The position 0 is the damage that doesn't depend on dies.
|
||||
* Example: 1d6 + 1d4 + 4 is stored as {4, 4, 6}*/
|
||||
private int[] damage;
|
||||
//TODO: modify this so that it takes an array of the same size always, each with each kind of damage
|
||||
|
||||
|
||||
public Power(String name, int type){
|
||||
Power(String name, int frequency, int range, int distance, String keywords, int atk, int def, int[] damage){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.keywords = keywords;
|
||||
this.frequency = frequency;
|
||||
this.range = range;
|
||||
this.distance = distance;
|
||||
this.atk = atk;
|
||||
this.def = def;
|
||||
this.damage = damage;
|
||||
used = false;
|
||||
}
|
||||
|
||||
public String getName(){return name;}
|
||||
public int getType(){return type;}
|
||||
String getName(){return name;}
|
||||
int getFrequency() {return frequency;}
|
||||
String getFrequencyString(){
|
||||
//TODO: change lists to arrays in resources
|
||||
switch(frequency) {
|
||||
case 1: return "Oportunidad";
|
||||
case 2: return "A voluntad";
|
||||
case 3: return "Encuentro";
|
||||
case 4: return "Diario";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
int getRange() {return range;}
|
||||
String getRangeString() {
|
||||
switch(range){
|
||||
case 1: return "Cuerpo a cuerpo";
|
||||
case 2: return "Área";
|
||||
case 3: return "A distancia";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
int getDistance() {return distance;}
|
||||
String getKeywords() {return keywords;}
|
||||
int getAtk() {return atk;}
|
||||
int getDef() {return def;}
|
||||
int[] getDamage() {return damage;}
|
||||
|
||||
public boolean isUsed(){return used;}
|
||||
boolean isUsed(){return used;}
|
||||
|
||||
public void use(){
|
||||
if(type >= ENCUENTRO && !used)
|
||||
void use(){
|
||||
if(frequency >= ENCUENTRO && !used)
|
||||
used = true;
|
||||
}
|
||||
public void recover(){used = false;}
|
||||
void recover(){used = false;}
|
||||
}
|
41
app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java
Normal file
41
app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
|
||||
public class PowerEditor extends ActionBarActivity {
|
||||
|
||||
public static final String NAME="name", FREQ="freq", KEYWORDS="keywords", RANGE="range", DISTANCE="distance";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_power_editor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_power_editor, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
Reference in a new issue