diff --git a/app/src/main/java/com/kauron/dungeonmanager/Introduction.java b/app/src/main/java/com/kauron/dungeonmanager/Introduction.java index 6fde151..85477fa 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Introduction.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Introduction.java @@ -6,7 +6,6 @@ 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; @@ -21,7 +20,6 @@ public class Introduction extends ActionBarActivity { private EditText name, level; private EditText fue, con, des, sab, intel, car; private Spinner classSpinner, raceSpinner; - private boolean first; @Override protected void onCreate(Bundle savedInstanceState) { @@ -57,8 +55,6 @@ public class Introduction extends ActionBarActivity { Player.RACE_STRINGS ) ); - - first = getIntent().getExtras() == null || getIntent().getExtras().getBoolean("first_time"); } @@ -91,28 +87,15 @@ public class Introduction extends ActionBarActivity { if(finished()) { finish(); } else { - Toast.makeText( - getApplicationContext(), - R.string.missing_info_error, - Toast.LENGTH_LONG - ).show(); + SnackbarManager.show( + Snackbar.with(getApplicationContext()).text(R.string.missing_info_error), this + ); } return true; } - 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() { String nameString = name.getText().toString().trim(); int classInt = classSpinner.getSelectedItemPosition(); @@ -171,6 +154,7 @@ public class Introduction extends ActionBarActivity { ed.putInt("con", con); ed.putInt("des", des); //TEMP + ed.putBoolean("new", true); ed.apply(); } else { return false; diff --git a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java b/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java index 1692541..e418566 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java +++ b/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java @@ -4,13 +4,11 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.PorterDuff; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; -import android.os.Handler; import android.support.v7.widget.Toolbar; import android.text.InputType; import android.view.Menu; @@ -39,7 +37,6 @@ public class MainActivity extends ActionBarActivity { private Button pgCurrent; private TextView currentPg, currentXp, currentCurativeEfforts, lvl; private SharedPreferences p; - private Toolbar toolbar; @Override @@ -47,7 +44,7 @@ public class MainActivity extends ActionBarActivity { super.onCreate(savedInstanceState); //Initializing activity (setting toolbar as actionbar) setContentView(R.layout.activity_main); - toolbar = (Toolbar) findViewById(R.id.toolbar); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //Loading player @@ -73,7 +70,6 @@ public class MainActivity extends ActionBarActivity { currentXp = (TextView) findViewById(R.id.currentXp); currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts); - //TODO: do not change progressbar background xpBar.getProgressDrawable() .setColorFilter(getResources().getColor(R.color.px_bar), PorterDuff.Mode.SRC_IN); curativeEffortsBar.getProgressDrawable() @@ -303,6 +299,7 @@ public class MainActivity extends ActionBarActivity { pgUpdate(); invalidateOptionsMenu(); } catch (Exception e) { + Toast.makeText(getApplicationContext(), "There was an error", Toast.LENGTH_LONG).show(); } } }); @@ -339,7 +336,7 @@ public class MainActivity extends ActionBarActivity { pgCurrent.setText(String.valueOf(player.getPg())); if (status == Player.MUERTO) { pgCurrent.setTextColor(Color.BLACK); - pgCurrent.setBackgroundColor(Color.RED); + pgCurrent.setBackgroundColor(getResources().getColor(R.color.red)); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(getString(R.string.reset_confirmation_title)); @@ -365,9 +362,9 @@ public class MainActivity extends ActionBarActivity { alert.show(); } else if (status == Player.DEBILITADO) { pgCurrent.setBackgroundColor(android.R.drawable.btn_default); - pgCurrent.setTextColor(Color.RED); - pgBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN); - negPgBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN); + pgCurrent.setTextColor(getResources().getColor(R.color.red)); + pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_IN); + negPgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_IN); if(lastState != Player.SAME) { SnackbarManager.show( Snackbar @@ -377,9 +374,9 @@ public class MainActivity extends ActionBarActivity { } } else if (status == Player.MALHERIDO) { pgCurrent.setBackgroundColor(android.R.drawable.btn_default); - pgCurrent.setTextColor(Color.YELLOW); - pgBar.getProgressDrawable().setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_IN); - negPgBar.getProgressDrawable().setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_IN); + pgCurrent.setTextColor(getResources().getColor(R.color.yellow)); + pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.yellow), PorterDuff.Mode.SRC_IN); + negPgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.yellow), PorterDuff.Mode.SRC_IN); if(lastState != Player.SAME) { SnackbarManager.show( Snackbar @@ -388,42 +385,28 @@ public class MainActivity extends ActionBarActivity { ); } } else { - pgCurrent.setTextColor(Color.GREEN); + pgCurrent.setTextColor(getResources().getColor(R.color.green)); pgCurrent.setBackgroundColor(android.R.drawable.btn_default); - pgBar.getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN); - negPgBar.getProgressDrawable().setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN); + pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_IN); + negPgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_IN); } } private void restoreData(){ if (player == null) { - player = new Player( - p.getString("playerName", getString(R.string.adventurer_name)), - p.getInt("classInt", Player.NULL), - p.getInt("raceInt", Player.NULL), - p.getInt("px", 0), - new int[]{ - p.getInt("fue", 10), - p.getInt("con", 10), - p.getInt("des", 10), - p.getInt("int", 10), - p.getInt("sab", 10), - p.getInt("car", 10) - }, - new int[18], - new Power[4]); + player = new Player( p ); } else { - player.setName(p.getString("playerName", getString(R.string.adventurer_name))); - player.setClassInt(p.getInt("classInt", Player.NULL)); - player.setRaceInt(p.getInt("raceInt", Player.NULL)); - player.setPx(p.getInt("px", player.getPx())); + player.setName(p.getString(Player.NAME, player.getName())); + player.setClassInt(p.getInt(Player.CLASS, player.getClassInt())); + player.setRaceInt(p.getInt(Player.RACE, player.getRaceInt())); + player.setPx(p.getInt(Player.PX, player.getPx())); player.setAtk(new int[]{ - p.getInt("fue", 10), - p.getInt("con", 10), - p.getInt("des", 10), - p.getInt("int", 10), - p.getInt("sab", 10), - p.getInt("car", 10) + p.getInt("fue", player.getFue()), + p.getInt("con", player.getCon()), + p.getInt("des", player.getDes()), + p.getInt("int", player.getInt()), + p.getInt("sab", player.getSab()), + p.getInt("car", player.getCar()) }); } pxUpdate(); @@ -440,17 +423,7 @@ public class MainActivity extends ActionBarActivity { pgBar.setMax(player.getMaxPg()); negPgBar.setMax(player.getMaxPg() / 2); -// incrementProgressBar( -// pgBar, currentPg, -// 100, true, player.getMaxPg(), -// true, player.getPg() -// ); curativeEffortsBar.setMax(player.getMaxCurativeEfforts()); -// incrementProgressBar( -// curativeEffortsBar, currentCurativeEfforts, -// 100, true, player.getMaxCurativeEfforts(), -// true, player.getCurativeEfforts() -// ); pgUpdate(); ceUpdate(); //set restored values to the respective fields @@ -553,90 +526,4 @@ public class MainActivity extends ActionBarActivity { dialog.show(); input.requestFocus(); } - - //TODO: fix incrementeProgressBar - //set up a partial barCommand to raise only between the ratios, then a manager, then another - //if pgBar, change color accordingly with the pg - private void incrementProgressBar(final ProgressBar progressBar, final TextView textView, - final int factor, - final boolean setMax, int max, - final boolean setVal, int end) { - if(factor == 1){ - textView.setText( - (progressBar.getProgress() + Player.LEVEL_PX[player.getLevel() - 1]) - + " / " + - (progressBar.getMax() + Player.LEVEL_PX[player.getLevel() - 1]) - ); - } else { - textView.setText( - (progressBar.getProgress()/factor) + " / " + - (progressBar.getMax()/factor) - ); - } - - if(setMax) progressBar.setMax(factor*max); - if(!setVal) return; - if(progressBar.getProgress() - end*factor == 0) return; - final Handler handler = new Handler(); - final int finalEnd = (end < 0 ? 0 : -1) * end * factor; - final int time = Math.max(2000 / Math.abs(progressBar.getProgress() - finalEnd), 1); - new Thread(new Runnable() { - public void run() { - int current = progressBar.getProgress(); - boolean bigger = current < finalEnd; - while ((bigger && current < finalEnd) || (!bigger && current > finalEnd)) { - if(bigger) current += 2; - else current -= 2; - // Update the progress bar and display the - //current value in the text view - final int finalCurrent = Math.abs(current); - handler.post(new Runnable() { - public void run() { - progressBar.setProgress(finalCurrent); - if(factor == 1){ - textView.setText( - (finalCurrent + Player.LEVEL_PX[player.getLevel() - 1]) - + " / " + - (progressBar.getMax() + Player.LEVEL_PX[player.getLevel() - 1]) - ); - } else { - textView.setText((finalCurrent/factor) +" / "+(progressBar.getMax()/factor)); - } - } - }); - try { - // Sleep for 200 milliseconds. - //Just to display the progress slowly - Thread.sleep(time); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - }).start(); - } - - -// if(progressBar.getId() == R.id.pgBar) { -// double rate = (double)current / progressBar.getMax() * (negative ? -1:1); -// if (rate <= 0) { -// progressBar.getProgressDrawable() -// .setColorFilter( -// Color.RED, -// PorterDuff.Mode.SRC_IN -// ); -// } else if (rate <= 0.5) { -// progressBar.getProgressDrawable() -// .setColorFilter( -// Color.YELLOW, -// PorterDuff.Mode.SRC_IN -// ); -// } else { -// progressBar.getProgressDrawable() -// .setColorFilter( -// Color.GREEN, -// PorterDuff.Mode.SRC_IN -// ); -// } -// } } \ No newline at end of file diff --git a/app/src/main/java/com/kauron/dungeonmanager/Player.java b/app/src/main/java/com/kauron/dungeonmanager/Player.java index 5e5aee5..782470d 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Player.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Player.java @@ -1,6 +1,10 @@ package com.kauron.dungeonmanager; -class Player { +import android.content.SharedPreferences; + +import java.io.Serializable; + +class Player implements Serializable { public static final String NAME = "playerName", CLASS = "classInt", RACE = "raceInt", PX = "px"; @@ -107,15 +111,35 @@ class Player { private int level; //TODO: use dice dialogs private int[] atk, def, abilities; + private boolean[] abilitiesTrained; //TODO: implement fully operational powers displayed as cards private Power[] powers; + Player (SharedPreferences p) { + this.name = p.getString(NAME, "Player"); + this.px = p.getInt(PX, 0); + setLevel(); + this.raceInt = p.getInt(RACE, 0); + this.classInt = p.getInt(CLASS, 0); + this.def = new int[4]; + setAtk(new int[] { + p.getInt("fue", 10), + p.getInt("con", 10), + p.getInt("des", 10), + p.getInt("int", 10), + p.getInt("sab", 10), + p.getInt("car", 10)} + ); + setState(); + this.pg = p.getInt( "pg" , maxPg); + this.curativeEfforts = p.getInt( "curativeEfforts" , maxCurativeEfforts ); + + //TODO: load powers from wherever they are saved + } + /** Constructor for creating a new character*/ - Player( - String name, int classInt, int raceInt, - int px, int[] atk, int[] abilities, - Power[] powers - ){ + Player( String name, int classInt, int raceInt, + int px, int[] atk, Power[] powers){ this.name = name; this.px = px; setLevel(); @@ -127,28 +151,22 @@ class Player { pg = maxPg; curativeEfforts = maxCurativeEfforts; - this.abilities = abilities; 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; + Player( int pg, int px, int curativeEfforts, int classInt, int raceInt, int[] atk, String name, Power[] powers) { this.px = px; setLevel(); - setState(); - this.curativeEfforts = curativeEfforts; - this.maxCurativeEfforts = maxCurativeEfforts; + setAtk(atk); this.classInt = classInt; this.raceInt = raceInt; + setClass(); this.name = name; - this.atk = atk; - this.def = def; - this.abilities = abilities; this.powers = powers; + this.pg = pg; + this.curativeEfforts = curativeEfforts; + setState(); } int getPx() {return px;} @@ -167,11 +185,8 @@ class Player { int getLevel() {return level;} void setLevel() { - for (int i = 0; i < LEVEL_PX.length; i++){ - if(px < LEVEL_PX[i]) { - level = i; return; - } - } + for (int i = 0; i < LEVEL_PX.length; i++) + if(px < LEVEL_PX[i]) {level = i; return;} level = LEVEL_PX.length; } diff --git a/app/src/main/java/com/kauron/dungeonmanager/Power.java b/app/src/main/java/com/kauron/dungeonmanager/Power.java index 97bf043..0914c78 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Power.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Power.java @@ -1,6 +1,8 @@ package com.kauron.dungeonmanager; -class Power { +import java.io.Serializable; + +class Power implements Serializable{ /**frequencies*/ public static final int OPORTUNIDAD = 1, A_VOLUNTAD = 2, ENCUENTRO = 3, DIARIO = 4; public static final String[] FREQ = {"Nada", "Oportunidad", "A voluntad", "Encuentro", "Diario"}; diff --git a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java index ba48561..00e7681 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java +++ b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java @@ -2,8 +2,8 @@ package com.kauron.dungeonmanager; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; +import android.support.v7.widget.Toolbar; +import android.view.View; public class PowerEditor extends ActionBarActivity { @@ -14,28 +14,10 @@ public class PowerEditor extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_power_editor); + setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); } - - @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); + public void saveClick(View view) { + //TODO: save powers } } diff --git a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java index cffc331..9e183b1 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java @@ -76,24 +76,10 @@ public class Welcome extends ActionBarActivity { for ( int i = elements; i < n; i++ ) { SharedPreferences sav = getSharedPreferences(p.getString("player" + i, ""), MODE_PRIVATE); if (sav.contains(Player.NAME)) - 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] - )); + adapter.add( new Player( sav ) ); } + //int pg, int maxPg, int px, int curativeEfforts, int maxCurativeEfforts, int classInt, + //int raceInt, String name, int[] atk, int[] def, int[] abilities, Power[] powers } else if ( n != 0 ) { playerList.setVisibility(View.VISIBLE); findViewById(R.id.help_text).setVisibility(View.VISIBLE); @@ -103,22 +89,7 @@ public class Welcome extends ActionBarActivity { //TODO: fill the information for the player creation SharedPreferences sav = getSharedPreferences(p.getString("player" + i, ""), MODE_PRIVATE); if (sav.contains(Player.NAME)) - players[i] = 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] - ); + players[i] = new Player( sav ); } playerList.setAdapter(new PlayerAdapter(this, players)); diff --git a/app/src/main/res/drawable-hdpi/fab_ic_add.png b/app/src/main/res/drawable-hdpi/fab_ic_add.png new file mode 100644 index 0000000..4a072bb Binary files /dev/null and b/app/src/main/res/drawable-hdpi/fab_ic_add.png differ diff --git a/app/src/main/res/drawable-mdpi/fab_ic_add.png b/app/src/main/res/drawable-mdpi/fab_ic_add.png new file mode 100644 index 0000000..e4249ed Binary files /dev/null and b/app/src/main/res/drawable-mdpi/fab_ic_add.png differ diff --git a/app/src/main/res/drawable-xhdpi/fab_ic_add.png b/app/src/main/res/drawable-xhdpi/fab_ic_add.png new file mode 100644 index 0000000..aec47a0 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/fab_ic_add.png differ diff --git a/app/src/main/res/drawable-xxhdpi/fab_ic_add.png b/app/src/main/res/drawable-xxhdpi/fab_ic_add.png new file mode 100644 index 0000000..82c2002 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/fab_ic_add.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/fab_ic_add.png b/app/src/main/res/drawable-xxxhdpi/fab_ic_add.png new file mode 100644 index 0000000..e8e0826 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/fab_ic_add.png differ diff --git a/app/src/main/res/drawable/fab_button.xml b/app/src/main/res/drawable/fab_button.xml new file mode 100644 index 0000000..4ca30fc --- /dev/null +++ b/app/src/main/res/drawable/fab_button.xml @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_introduction.xml b/app/src/main/res/layout/activity_introduction.xml index 711099b..5ab057a 100644 --- a/app/src/main/res/layout/activity_introduction.xml +++ b/app/src/main/res/layout/activity_introduction.xml @@ -13,191 +13,186 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - - + - - - + + + android:inputType="textPersonName|textCapWords" + android:layout_weight="0.5" + android:id="@+id/editNameIntro" + android:hint="@string/adventurer_name" + android:nextFocusDown="@+id/editPxIntro" + android:nextFocusForward="@+id/editPxIntro"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - -