diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5f5255e..b0c0cbc 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -13,8 +13,7 @@
-
-
+
diff --git a/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java b/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java
index f427afc..c949bdb 100644
--- a/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java
+++ b/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java
@@ -26,26 +26,29 @@ class AttackAdapter extends ArrayAdapter {
View mView = mInflater.inflate(R.layout.attack_row, parent, false);
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
- }
- });
+ if ( attack != null ) {
+ ((TextView) mView.findViewById(R.id.name)).setText(attack.getName());
+ ((TextView) mView.findViewById(R.id.keywords)).setText(attack.getKeywords());
+ ((TextView) mView.findViewById(R.id.frequency)).setText(attack.getFrequencyString());
+ ((TextView) mView.findViewById(R.id.extra)).setText(attack.getRangeString() + " " + attack.getDistance());
+ 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
+ }
+ });
+ } else {
+ this.remove(attack);
+ }
return mView;
}
diff --git a/app/src/main/java/com/kauron/dungeonmanager/Introduction.java b/app/src/main/java/com/kauron/dungeonmanager/Introduction.java
index a118c2f..e045b4d 100644
--- a/app/src/main/java/com/kauron/dungeonmanager/Introduction.java
+++ b/app/src/main/java/com/kauron/dungeonmanager/Introduction.java
@@ -3,13 +3,18 @@ package com.kauron.dungeonmanager;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
+import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
+import com.nispok.snackbar.Snackbar;
+import com.nispok.snackbar.SnackbarManager;
+
public class Introduction extends ActionBarActivity {
@@ -23,6 +28,8 @@ public class Introduction extends ActionBarActivity {
super.onCreate(savedInstanceState);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_introduction);
+ setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
+
name = (EditText) findViewById(R.id.editNameIntro);
name.requestFocus();
level = (EditText) findViewById(R.id.editPxIntro);
@@ -96,9 +103,20 @@ public class Introduction extends ActionBarActivity {
return super.onOptionsItemSelected(item);
}
+ public void finishButton(View view){
+ if(finished()) {
+ finish();
+ } else {
+ SnackbarManager.show(
+ Snackbar.with(getApplicationContext()).text(R.string.missing_info_error), this
+ );
+ }
+ }
+
private boolean finished() {
SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
- SharedPreferences.Editor ed = p.edit();
+ int i = p.getInt("players", 0);
+ SharedPreferences.Editor ed = getSharedPreferences("player" + i, MODE_PRIVATE).edit();
String nameString = name.getText().toString().trim();
int classInt = classSpinner.getSelectedItemPosition();
int raceInt = raceSpinner.getSelectedItemPosition();
@@ -146,8 +164,6 @@ public class Introduction extends ActionBarActivity {
ed.putInt("sab", sab);
ed.putInt("con", con);
ed.putInt("des", des);
-
- ed.putBoolean("saved", true);
} else {
return false;
}
@@ -165,6 +181,8 @@ public class Introduction extends ActionBarActivity {
if (des != 0) ed.putInt("des", des);
}
ed.apply();
+ getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE).edit()
+ .putInt("players", i + 1).apply();
return true;
}
}
diff --git a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java b/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java
index e320026..dd36625 100644
--- a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java
+++ b/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java
@@ -1,6 +1,7 @@
package com.kauron.dungeonmanager;
import android.app.AlertDialog;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -43,11 +44,10 @@ public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- setContentView(R.layout.activity_main);
-
- p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
+ p = getSharedPreferences("player" + getIntent().getIntExtra("player", 0), MODE_PRIVATE);
xpBar = (ProgressBar) findViewById(R.id.xpBar);
curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
pgBar = (ProgressBar) findViewById(R.id.pgBar);
@@ -60,11 +60,11 @@ public class MainActivity extends ActionBarActivity {
currentXp = (TextView) findViewById(R.id.currentXp);
currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts);
- //TODO: change references to xml and do not change progressbar background
+ //TODO: do not change progressbar background
xpBar.getProgressDrawable()
- .setColorFilter(Color.parseColor("#62BACE"), PorterDuff.Mode.SRC_IN);
+ .setColorFilter(getResources().getColor(R.color.px_bar), PorterDuff.Mode.SRC_IN);
curativeEffortsBar.getProgressDrawable()
- .setColorFilter(Color.parseColor("#FFD700"), PorterDuff.Mode.SRC_IN);
+ .setColorFilter(getResources().getColor(R.color.surges_bar), PorterDuff.Mode.SRC_IN);
undo = false;
//begin
restoreData();
@@ -257,6 +257,9 @@ public class MainActivity extends ActionBarActivity {
alert.setView(input);
+ final Context context = getApplicationContext();
+ final MainActivity activity = this;
+
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
@@ -274,15 +277,16 @@ public class MainActivity extends ActionBarActivity {
undoPreviousValue = preValue;
undoObject = CURRENT_PG;
SnackbarManager.show(
- Snackbar.with(getApplicationContext()).text("Lost " + damage + " PG's")
+ Snackbar.with(context).text("Lost " + damage + " PG's")
.actionLabel("Undo") // action button label
.actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
undo();
}
- })
- ,getParent()); // action button's
+ })
+ .actionColor(getResources().getColor(R.color.yellow))
+ ,activity); // action button's
p.edit().putInt("pg", player.getPg()).apply();
pgUpdate();
invalidateOptionsMenu();
@@ -383,12 +387,14 @@ public class MainActivity extends ActionBarActivity {
}
private void restoreData(){
+ int i = getIntent().getIntExtra("player", 0);
if (!p.getBoolean("saved", false)) {
- Intent intent = new Intent(this, Introduction.class);
- startActivity(intent.putExtra(
- "first_time",
- !p.getBoolean("saved", false)
- ));
+ if (i == -1) {
+ Intent intent = new Intent(this, Introduction.class);
+ startActivity(intent.putExtra(
+ "first_time",
+ !p.getBoolean("saved", false)
+ ));
}
if (player == null) {
player = new Player(
@@ -431,6 +437,7 @@ public class MainActivity extends ActionBarActivity {
}
player.setCurativeEffort(p.getInt("curativeEfforts", player.getMaxCurativeEfforts()));
player.setPg(p.getInt("pg", player.getMaxPg()));
+
pgBar.setMax(player.getMaxPg());
negPgBar.setMax(player.getMaxPg() / 2);
// incrementProgressBar(
diff --git a/app/src/main/java/com/kauron/dungeonmanager/Player.java b/app/src/main/java/com/kauron/dungeonmanager/Player.java
index fadc6b5..5e5aee5 100644
--- a/app/src/main/java/com/kauron/dungeonmanager/Player.java
+++ b/app/src/main/java/com/kauron/dungeonmanager/Player.java
@@ -57,7 +57,7 @@ class Player {
* Names for the races
*/
public static final String[] RACE_STRINGS = new String[] {
- "Raza", "Dracónido", "Eladrín", "Elfo", "Enano", "Gitzherai", "Humanos", "Medianos",
+ "Raza", "Dracónido", "Eladrín", "Elfo", "Enano", "Gitzherai", "Humano", "Mediano",
"Mente del Fragmento", "Minotauro", "Salvaje", "Semielfo", "Tiflin"
};
@@ -110,6 +110,7 @@ class Player {
//TODO: implement fully operational powers displayed as cards
private Power[] powers;
+ /** Constructor for creating a new character*/
Player(
String name, int classInt, int raceInt,
int px, int[] atk, int[] abilities,
@@ -130,6 +131,25 @@ class Player {
this.powers = powers;
}
+ /** Constructor for restoring the Player in the middle of the game*/
+ Player(
+ int pg, int maxPg, int px, int curativeEfforts, int maxCurativeEfforts, int classInt,
+ int raceInt, String name, int[] atk, int[] def, int[] abilities, Power[] powers) {
+ this.pg = pg;
+ this.maxPg = maxPg;
+ this.px = px;
+ setLevel();
+ setState();
+ this.curativeEfforts = curativeEfforts;
+ this.maxCurativeEfforts = maxCurativeEfforts;
+ this.classInt = classInt;
+ this.raceInt = raceInt;
+ this.name = name;
+ this.atk = atk;
+ this.def = def;
+ this.abilities = abilities;
+ this.powers = powers;
+ }
int getPx() {return px;}
void setPx (int px) {this.px = px; setLevel();}
@@ -216,7 +236,7 @@ class Player {
String getClassName() {return CLASS_STRINGS[classInt];}
String getRaceName() {return RACE_STRINGS[raceInt];}
- void setRaceInt(int raceInt) {this.raceInt= raceInt;}
+ void setRaceInt(int raceInt) {this.raceInt = raceInt;}
int getRaceInt() {return raceInt;}
//TODO: implement turns (for bonuses and continuous damage in the app
diff --git a/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java b/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java
index 226e588..04f6013 100644
--- a/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java
+++ b/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java
@@ -1,6 +1,9 @@
package com.kauron.dungeonmanager;
import android.content.Context;
+import android.graphics.AvoidXfermode;
+import android.graphics.Color;
+import android.graphics.PorterDuff;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -28,10 +31,27 @@ class PlayerAdapter extends ArrayAdapter {
.setText(
getContext().getResources().getString(R.string.level) + " " + player.getLevel()
);
+ int pg = player.getPg();
+ int maxPg = player.getMaxPg();
+ ProgressBar neg = (ProgressBar) mView.findViewById(R.id.negPgBar);
+ ProgressBar pos = (ProgressBar) mView.findViewById(R.id.pgBar);
- ProgressBar pg = (ProgressBar) mView.findViewById(R.id.progressBar);
- pg.setMax(player.getMaxPg());
- pg.setProgress(player.getPg());
+ neg.setMax(maxPg / 2);
+ pos.setMax(maxPg);
+
+ neg.setProgress(pg < 0 ? -pg : 0);
+ pos.setProgress(pg > 0 ? pg : 0);
+
+ int c;
+ if ( pg <= 0 )
+ c = getContext().getResources().getColor(R.color.red);
+ else if ( pg <= maxPg / 2 )
+ c = getContext().getResources().getColor(R.color.yellow);
+ else
+ c = getContext().getResources().getColor(R.color.green);
+
+ neg.getProgressDrawable().setColorFilter(c, PorterDuff.Mode.SRC_IN);
+ pos.getProgressDrawable().setColorFilter(c, PorterDuff.Mode.SRC_IN);
}
return mView;
diff --git a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java
index 421f2ca..69475c9 100644
--- a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java
+++ b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java
@@ -4,41 +4,90 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
+import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
-import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
-import com.nispok.snackbar.Snackbar;
-import com.nispok.snackbar.SnackbarManager;
-
-
public class Welcome extends ActionBarActivity {
public static final String PREFERENCES = "basics";
- private Button load;
private SharedPreferences p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
+ setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
p = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
- load = (Button) findViewById(R.id.loadCharacter);
- if (p.getBoolean("saved", false)) {
- load.setEnabled(true);
- load.setText(String.format(getString(R.string.load_text), p.getString("playerName", "")));
- } else {
- load.setEnabled(false);
- load.setText(R.string.load_character);
+ load();
+ }
+
+ @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_welcome, 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_add_player ) {
+ startActivity(new Intent(this, Introduction.class).putExtra("first_time", true));
}
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ load();
+ }
+
+ private void load() {
int n = p.getInt("players",0);
- if ( n != 0 ) {
+ ListView playerList = (ListView) findViewById(R.id.listView);
+ PlayerAdapter adapter = (PlayerAdapter) playerList.getAdapter();
+ int elements = 0;
+ if ( adapter != null )
+ elements = adapter.getCount();
+ if ( elements < n && adapter != null ) {
+ playerList.setVisibility(View.VISIBLE);
+ findViewById(R.id.no_players_text).setVisibility(View.GONE);
+ for ( int i = elements; i < n; i++ ) {
+ SharedPreferences sav = getSharedPreferences("player" + i, MODE_PRIVATE);
+ adapter.add(
+ new Player(
+ sav.getString(Player.NAME, "player" + i),
+ sav.getInt(Player.CLASS, 0),
+ sav.getInt(Player.RACE, 0),
+ sav.getInt(Player.PX, 0),
+ new int[] {
+ sav.getInt("fue", 10),
+ sav.getInt("con", 10),
+ sav.getInt("des", 10),
+ sav.getInt("int", 10),
+ sav.getInt("sab", 10),
+ sav.getInt("car", 10)
+ },
+ new int[18],
+ new Power[4]
+ ));
+ }
+ } else if ( n != 0 ) {
+ playerList.setVisibility(View.VISIBLE);
+ findViewById(R.id.no_players_text).setVisibility(View.GONE);
Player[] players = new Player[n];
for ( int i = 0; i < n; i++ ) {
//TODO: fill the information for the player creation
@@ -60,9 +109,8 @@ public class Welcome extends ActionBarActivity {
new Power[4]
);
}
- ListView playerList = (ListView) findViewById(R.id.listView);
- ListAdapter adapter = new PlayerAdapter(this, players);
- playerList.setAdapter(adapter);
+
+ playerList.setAdapter(new PlayerAdapter(this, players));
playerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
@@ -73,49 +121,8 @@ public class Welcome extends ActionBarActivity {
}
});
} else {
- findViewById(R.id.listView).setVisibility(View.GONE);
- }
- }
-
- public void onNewClick(View view) {startActivity(new Intent(this, Introduction.class).putExtra("first_time", true));}
- public void onLoadClick(View view) {startActivity(new Intent(this, MainActivity.class).putExtra("player", -1));}
-
- @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_welcome, 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) {
- SnackbarManager.show(
- Snackbar.with(getApplicationContext()).text("This doesn't work yet")
- );
- return true;
- } else if ( id == R.id.action_add_player ) {
- startActivity(new Intent(this, Introduction.class).putExtra("first_time", true));
- }
-
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (p.getBoolean("saved", false)) {
- load.setEnabled(true);
- load.setText(String.format(getString(R.string.load_text), p.getString("playerName", "")));
- } else {
- load.setEnabled(false);
- load.setText(R.string.load_character);
+ playerList.setVisibility(View.GONE);
+ findViewById(R.id.no_players_text).setVisibility(View.VISIBLE);
}
}
}
diff --git a/app/src/main/res/layout/activity_introduction.xml b/app/src/main/res/layout/activity_introduction.xml
index 3af7ebe..e221901 100644
--- a/app/src/main/res/layout/activity_introduction.xml
+++ b/app/src/main/res/layout/activity_introduction.xml
@@ -1,168 +1,211 @@
-
-
+
-
+ android:layout_height="fill_parent">
-
-
+
+
+
-
+ android:id="@+id/finish_button"
+ android:onClick="finishButton"
+ android:layout_gravity="center_horizontal"
+ android:text="Save character" />
-
+
+
+
+ android:id="@+id/firstLayout"
+ android:orientation="horizontal">
-
+
+
+
+
+
-
+ android:orientation="horizontal"
+ android:id="@+id/secondLayout"
+ android:layout_below="@+id/firstLayout">
-
-
+
+
+
+
+
+
+ android:id="@+id/FUE"
+ android:hint="@string/FUE"
+ android:nextFocusDown="@+id/DES"/>
-
+ android:id="@+id/CON"
+ android:hint="@string/CON"
+ android:nextFocusDown="@+id/INT" />
-
+ android:id="@+id/DES"
+ android:hint="@string/DES"
+ android:nextFocusDown="@+id/SAB"/>
-
+ android:id="@+id/INT"
+ android:hint="@string/INT"
+ android:nextFocusDown="@+id/CAR"/>
-
+ android:id="@+id/SAB"
+ android:hint="@string/SAB"
+ android:nextFocusDown="@+id/CON"/>
-
-
+ android:id="@+id/CAR"
+ android:hint="@string/CAR"/>
+
-
+
-
+
-
-
+
+
-
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index a59ef49..ef928ab 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -52,7 +52,6 @@
+ android:text="@string/zero"/>
@@ -232,7 +231,7 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_welcome.xml b/app/src/main/res/layout/activity_welcome.xml
index a41a49f..f7f08a4 100644
--- a/app/src/main/res/layout/activity_welcome.xml
+++ b/app/src/main/res/layout/activity_welcome.xml
@@ -33,20 +33,13 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical">
-
-
-
-
+ android:layout_height="fill_parent"
+ android:id="@+id/no_players_text"
+ android:text="@string/no_players"
+ android:gravity="center"
+ android:visibility="gone"/>
+ android:layout_height="wrap_content"
+ android:id="@+id/relativeLayout"
+ android:paddingTop="5dp"
+ android:paddingBottom="5dp">
-
+ android:layout_alignParentStart="true"
+ android:id="@+id/progressBar"
+ android:orientation="horizontal">
+
+
+
+
#727272
#FFFFFF
#B6B6B6
+
+ #F00
+ #ff0
+ #0f0
+
+ #FFD700
+ #62BACE
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e51626d..44bcfd1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -88,4 +88,6 @@
Hello world!
Add player
+ 0
+ No players, please add one