1
0
Fork 0

Added PlayerAdapter

Still need to complete Power creation, edition and listing.
Need to complete Player listing and deletion.
This commit is contained in:
Carlos Galindo 2015-04-06 13:27:49 +02:00
parent 9ca863a607
commit a3831597d0
25 changed files with 399 additions and 113 deletions

View file

@ -29,6 +29,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PowerEditor"
android:label="@string/title_activity_power_editor" >
</activity>
</application>
</manifest>

View file

@ -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("").actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
current.remove(attack);
}
})
);
//TODO: convert text to resource
}
});
return mView;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;}
}

View 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);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

View file

@ -11,6 +11,17 @@
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:text="Kauron"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<ScrollView
@ -240,6 +251,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:onClick="onAttackClick"
android:orientation="vertical">
<TextView
@ -275,7 +287,7 @@
android:layout_row="0"
android:layout_column="0"
android:id="@+id/FUE"
android:hint="@string/FUE" />
tools:text="@string/FUE" />
<TextView
android:layout_width="wrap_content"
@ -286,7 +298,7 @@
android:layout_row="1"
android:layout_column="0"
android:id="@+id/CON"
android:hint="@string/CON" />
tools:text="@string/CON" />
<TextView
android:layout_width="wrap_content"
@ -297,7 +309,7 @@
android:layout_row="0"
android:layout_column="1"
android:id="@+id/DES"
android:hint="@string/DES" />
tools:text="@string/DES" />
<TextView
android:layout_width="wrap_content"
@ -308,7 +320,7 @@
android:layout_row="1"
android:layout_column="1"
android:id="@+id/INT"
android:hint="@string/INT" />
tools:text="@string/INT" />
<TextView
android:layout_width="wrap_content"
@ -319,7 +331,7 @@
android:layout_row="0"
android:layout_column="2"
android:id="@+id/SAB"
android:hint="@string/SAB" />
tools:text="@string/SAB" />
<TextView
android:layout_width="wrap_content"
@ -330,7 +342,7 @@
android:layout_row="1"
android:layout_column="2"
android:id="@+id/CAR"
android:hint="@string/CAR" />
tools:text="@string/CAR" />
</GridLayout>
</HorizontalScrollView>
</LinearLayout>
@ -372,7 +384,7 @@
android:layout_row="0"
android:layout_column="0"
android:id="@+id/CA"
android:hint="@string/CA" />
tools:text="@string/CA" />
<TextView
android:layout_width="wrap_content"
@ -383,7 +395,7 @@
android:layout_row="0"
android:layout_column="1"
android:id="@+id/FORT"
android:hint="@string/FORT" />
tools:text="@string/FORT" />
<TextView
android:layout_width="wrap_content"
@ -394,7 +406,7 @@
android:layout_row="1"
android:layout_column="0"
android:id="@+id/REF"
android:hint="@string/REF" />
tools:text="@string/REF" />
<TextView
android:layout_width="wrap_content"
@ -405,7 +417,7 @@
android:layout_row="1"
android:layout_column="1"
android:id="@+id/VOL"
android:hint="@string/VOL" />
tools:text="@string/VOL" />
</GridLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,9 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.kauron.dungeonmanager.PowerEditor">
</RelativeLayout>

View file

@ -2,29 +2,57 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.kauron.dungeonmanager.Welcome"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:text="DungeonManager"
android:id="@+id/title" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.kauron.dungeonmanager.Welcome"
android:orientation="vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/new_character"
android:id="@+id/newCharacter"
android:onClick="onNewClick"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
android:onClick="onNewClick"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/load_character"
android:id="@+id/loadCharacter"
android:onClick="onLoadClick"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
android:onClick="onLoadClick"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView2"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</LinearLayout>

View file

@ -1,33 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="wrap_content">
<TextView
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/delete"
android:src="@drawable/ic_delete"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:contentDescription="@string/edit" />
<TextView
tools:text="Happiness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Extra info"
tools:text="Melee 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/extra" />
</LinearLayout>
android:id="@+id/extra"
android:layout_below="@+id/name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
<TextView
android:layout_width="wrap_content"
tools:image="@drawable/delete"
android:layout_height="wrap_content"
android:id="@+id/imageView" />
</LinearLayout>
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/keywords"
tools:text="(fire, explosion)"
android:paddingLeft="10dp"
android:layout_alignBottom="@id/extra"
android:layout_toRightOf="@+id/extra"
android:layout_toEndOf="@+id/extra" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/frequency"
android:layout_alignBottom="@+id/name"
android:layout_toRightOf="@+id/name"
android:layout_toEndOf="@+id/name"
android:paddingLeft="10dp"
tools:text="At will"/>
</RelativeLayout>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:text="Kauron"
android:id="@+id/name"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_below="@+id/name"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="Brujo Tiflin"
android:id="@+id/other"
android:layout_above="@+id/progressBar"
android:layout_toRightOf="@+id/name"
android:layout_toEndOf="@+id/name"
android:paddingLeft="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="LVL 1"
android:id="@+id/level"
android:layout_above="@+id/progressBar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>

View file

@ -0,0 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.kauron.dungeonmanager.PowerEditor">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>

View file

@ -82,4 +82,9 @@
<string name="load_character">Load character</string>
<string name="new_character_warning">This will erase any previously existing data saved</string>
<string name="new_attack">New attack</string>
<string name="edit">Edit</string>
<string name="delete">Delete</string>
<string name="title_activity_power_editor">PowerEditor</string>
<string name="hello_world">Hello world!</string>
</resources>