diff --git a/.idea/misc.xml b/.idea/misc.xml index b0c0cbc..4eca83f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,7 +13,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b7cd214..6c9d5cd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,17 +8,17 @@ android:label="@string/app_name" android:theme="@style/AppTheme" > - + - + { AttackAdapter(Context context, Power[] powers) { super(context, R.layout.attack_row, powers); @@ -32,24 +37,45 @@ class AttackAdapter extends ArrayAdapter { ((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); + mView.findViewById(R.id.delete); +// mView.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) { +// //delete the item +// String name = p.getString("power" + position, ""); +// if (name != null && !name.isEmpty()) { +// getContext().getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().apply(); +// Log.d("Tag", activity.getApplicationContext().getFilesDir().getParent() +// + File.separator + "shared_prefs" + File.separator + name + ".xml"); +// try { +// if (!new File(activity.getApplicationContext().getFilesDir().getParent() +// + File.separator + "shared_prefs" + File.separator + name + ".xml").delete()) +// throw new Exception(); +// } catch (Exception e) { +// Toast.makeText(getContext(), "Error deleting player files", Toast.LENGTH_SHORT).show(); +// } +// int max = p.getInt("powers", 0); +// SharedPreferences.Editor ed = p.edit(); +// for (int i = position; i < max - 1; i++) +// ed.putString("power" + i, p.getString("power" + (i + 1), "max")); +// ed.putInt("powers", max - 1).apply(); +// load(); +// ed.remove("power" + (max - 1)).apply(); +// } +// } +// +// )); +// //TODO: convert text to resource +// } +// } +// +// ); +// }; } - return mView; } } diff --git a/app/src/main/java/com/kauron/dungeonmanager/Player.java b/app/src/main/java/com/kauron/dungeonmanager/Player.java index 782470d..5fd08c9 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Player.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Player.java @@ -1,7 +1,6 @@ package com.kauron.dungeonmanager; import android.content.SharedPreferences; - import java.io.Serializable; class Player implements Serializable { @@ -110,10 +109,8 @@ class Player implements Serializable { private String name; private int level; //TODO: use dice dialogs - private int[] atk, def, abilities; - private boolean[] abilitiesTrained; + private int[] atk, def; //TODO: implement fully operational powers displayed as cards - private Power[] powers; Player (SharedPreferences p) { this.name = p.getString(NAME, "Player"); @@ -133,40 +130,6 @@ class Player implements Serializable { 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, Power[] powers){ - this.name = name; - this.px = px; - setLevel(); - this.raceInt = raceInt; - this.classInt = classInt; - this.def = new int[4]; - setAtk(atk); - setState(); - pg = maxPg; - curativeEfforts = maxCurativeEfforts; - - this.powers = powers; - } - - /** Constructor for restoring the Player in the middle of the game*/ - Player( int pg, int px, int curativeEfforts, int classInt, int raceInt, int[] atk, String name, Power[] powers) { - this.px = px; - setLevel(); - setAtk(atk); - this.classInt = classInt; - this.raceInt = raceInt; - setClass(); - this.name = name; - this.powers = powers; - this.pg = pg; - this.curativeEfforts = curativeEfforts; - setState(); } int getPx() {return px;} @@ -241,34 +204,11 @@ class Player implements Serializable { } String getName() {return name;} - void setName(String name) {this.name = name;} - - int getClassInt() {return classInt;} - void setClassInt(int classInt) { - this.classInt = classInt; - if (atk != null) setClass(); - } String getClassName() {return CLASS_STRINGS[classInt];} - 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 - void rest(boolean isLong) { - if(isLong) { - pg = maxPg; - curativeEfforts = maxCurativeEfforts; - for (Power p : powers) - if (p != null) - p.recover(Power.DIARIO); - setState(); - } - for (Power p : powers) - if (p != null) - p.recover(Power.ENCUENTRO); - } - void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();} int getFue() {return atk[FUE];} diff --git a/app/src/main/java/com/kauron/dungeonmanager/Introduction.java b/app/src/main/java/com/kauron/dungeonmanager/PlayerEditor.java similarity index 97% rename from app/src/main/java/com/kauron/dungeonmanager/Introduction.java rename to app/src/main/java/com/kauron/dungeonmanager/PlayerEditor.java index 85477fa..3d99b2d 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Introduction.java +++ b/app/src/main/java/com/kauron/dungeonmanager/PlayerEditor.java @@ -15,7 +15,7 @@ import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; -public class Introduction extends ActionBarActivity { +public class PlayerEditor extends ActionBarActivity { private EditText name, level; private EditText fue, con, des, sab, intel, car; @@ -25,7 +25,7 @@ public class Introduction extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setContentView(R.layout.activity_introduction); + setContentView(R.layout.activity_player_editor); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); name = (EditText) findViewById(R.id.editNameIntro); @@ -61,7 +61,7 @@ public class Introduction extends ActionBarActivity { @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_introduction, menu); + getMenuInflater().inflate(R.menu.menu_player_editor, menu); return true; } diff --git a/app/src/main/java/com/kauron/dungeonmanager/Power.java b/app/src/main/java/com/kauron/dungeonmanager/Power.java index 0914c78..fce7882 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Power.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Power.java @@ -1,5 +1,7 @@ package com.kauron.dungeonmanager; +import android.content.SharedPreferences; + import java.io.Serializable; class Power implements Serializable{ @@ -15,37 +17,33 @@ class Power implements Serializable{ /**dies * They are represented by its max size * 0 corresponds to [A], the weapon - * any other is represented by d2, d4, d6, d8, d10, d12, d20, d100 + * any other is represented by [A], d2, d4, d6, d8, d10, d12, d20, d100, extra damage */ - public static final int[] DIE = {0, 2, 4, 6, 8, 10, 12, 20, 100}; + public static final int[] DIE = {0, 2, 4, 6, 8, 10, 12, 20, 100, 0}; private boolean used; private int freq, action, distance, range, objectives; - private String name, description; - private String[] keywords; //fire, spell... + private String name, impact, objective; + private String keywords; //fire, spell... private int atk, def; //constants from Player to denote atk and defense - private int[] damage; //the max sizes of the different dies + Power ( SharedPreferences p ) { + this.name = p.getString("s0", "Name"); + this.keywords = p.getString("s1", "Keywords"); + this.impact = p.getString("s2", "2d10"); + this.distance = Integer.parseInt(p.getString("s3", "10")); + this.objective = p.getString("s4", "One creature"); - Power(String name, String desc, int freq, int action, int distance, String[] keywords, - int atk, int def, int[] damage){ - used = false; - this.name = name; this.description = desc; - this.freq = freq; this.action = action; - this.distance = distance; - this.keywords = keywords; + this.used = p.getBoolean("used", false); + this.freq = p.getInt("i0", 0); + this.range = p.getInt("i1", 0); + this.atk = p.getInt("i2", 0); + this.def = p.getInt("i3", 0); + this.action = p.getInt("i4", 0); } - String getKeywords() { - if ( keywords != null && keywords.length != 0 ) { - String r = keywords[0]; - for (String k : keywords) r += ", " + k; - return r; - } else { - return ""; - } - } + String getKeywords() {return keywords;} String getFrequencyString() {return FREQ[freq];} int getFreq() {return freq;} @@ -56,7 +54,7 @@ class Power implements Serializable{ int getDistance() {return distance;} String getName(){return name;} - String getDescription() {return description;} + String getImpact() {return impact;} boolean isUsed(){return used;} @@ -68,13 +66,6 @@ class Power implements Serializable{ } int rollAttack() {return atk + (int)(Math.random()*20) + 1;} - int rollDamage() { - int roll = 0; - for(int i : damage) { - roll += (int)(Math.random()*i + 1); - } - return roll; - } void recover(int type){ if(this.freq <= type) used = false; diff --git a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java index 00e7681..3dbad31 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java +++ b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java @@ -1,23 +1,134 @@ 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.View; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.Spinner; 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 Spinner [] spinners = new Spinner[5]; + + private String[] strings = new String[5]; + private int[] ints = new int[5]; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_power_editor); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); + + + + //EditText + edits[0] = (EditText) findViewById(R.id.nameEdit); + edits[0].requestFocus(); + edits[1] = (EditText) findViewById(R.id.keywordsEdit); + edits[2] = (EditText) findViewById(R.id.impactEdit); + edits[3] = (EditText) findViewById(R.id.distanceNumEdit); + edits[4] = (EditText) findViewById(R.id.objectiveEdit); + + //Spinners + spinners[0] = (Spinner) findViewById(R.id.freqSpinner); + spinners[0].setAdapter( + new ArrayAdapter<>( + this, + android.R.layout.simple_spinner_dropdown_item, + getResources().getStringArray(R.array.freq_array) + ) + ); + spinners[1] = (Spinner) findViewById(R.id.rangeSpinner); + spinners[1].setAdapter( + new ArrayAdapter<>( + this, + android.R.layout.simple_spinner_dropdown_item, + getResources().getStringArray(R.array.ranges_array) + ) + ); + spinners[2] = (Spinner) findViewById(R.id.atkSpinner); + spinners[2].setAdapter( + new ArrayAdapter<>( + this, + android.R.layout.simple_spinner_dropdown_item, + getResources().getStringArray(R.array.atk_array) + ) + ); + spinners[3] = (Spinner) findViewById(R.id.defSpinner); + spinners[3].setAdapter( + new ArrayAdapter<>( + this, + android.R.layout.simple_spinner_dropdown_item, + getResources().getStringArray(R.array.def_array) + ) + ); + spinners[4] = (Spinner) findViewById(R.id.actionTypeSpinner); + spinners[4].setAdapter( + new ArrayAdapter<>( + this, + android.R.layout.simple_spinner_dropdown_item, + getResources().getStringArray(R.array.actions_array) + ) + ); + } + public void saveClick(View view) { - //TODO: save powers + //TODO: change strings per resources + boolean readyToSave = true; + + for ( int i = 0; i < edits.length; i++ ) + if ( edits[i].getText().toString().trim().length() == 0 ) { + edits[i].setError("This field is required"); + readyToSave = false; + } else { + strings[i] = edits[i].getText().toString().trim(); + } + + + for ( int i = 0; i < spinners.length; i++) + if ( spinners[i].getSelectedItemPosition() == 0 ) { + spinners[i].setBackgroundColor(getResources().getColor(R.color.red)); + readyToSave = false; + } else { + ints[i] = spinners[i].getSelectedItemPosition(); + spinners[i].setBackgroundColor(getResources().getColor(R.color.green)); + } + + if ( readyToSave ) { + String player = getIntent().getStringExtra("player"); + SharedPreferences p = getSharedPreferences(player, MODE_PRIVATE); + + int powers = p.getInt("powers", 0); + + for (int i = 0; i < powers; i++) { + if ( p.getString("power" + i, "") == strings[0] ) { + edits[0].setError("This power has already been defined. Use another name."); + return; + } + } + + p.edit().putString("power" + powers, strings[0]) + .putInt("powers", powers + 1) + .apply(); + + SharedPreferences.Editor ed = getSharedPreferences(strings[0], MODE_PRIVATE).edit(); + + for (int i = 0; i < strings.length; i++) + ed.putString("s" + i, strings[i]); + for (int i = 0; i < ints.length; i++) + ed.putInt("i" + i, ints[i]); + ed.apply(); + + finish(); + } } } diff --git a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java b/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java similarity index 63% rename from app/src/main/java/com/kauron/dungeonmanager/MainActivity.java rename to app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java index e418566..560c533 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java +++ b/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java @@ -1,11 +1,10 @@ package com.kauron.dungeonmanager; -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; @@ -15,8 +14,9 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.EditorInfo; -import android.widget.Button; +import android.widget.AdapterView; import android.widget.EditText; +import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -25,26 +25,27 @@ import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.SnackbarManager; import com.nispok.snackbar.listeners.ActionClickListener; -public class MainActivity extends ActionBarActivity { +public class ShowPlayer extends ActionBarActivity { public static final int CURRENT_PG = 1, NULL = 0; public Player player; private boolean undo; + //TODO: fix undo (show snackbar with button in each case, without timing). private int undoObject, undoPreviousValue; private ProgressBar pgBar, negPgBar, xpBar, curativeEffortsBar; - private Button pgCurrent; - private TextView currentPg, currentXp, currentCurativeEfforts, lvl; + private TextView currentPg, currentXp, currentCurativeEfforts; private SharedPreferences p; + private Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Initializing activity (setting toolbar as actionbar) - setContentView(R.layout.activity_main); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setContentView(R.layout.activity_show_player); + toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //Loading player @@ -63,9 +64,6 @@ public class MainActivity extends ActionBarActivity { pgBar = (ProgressBar) findViewById(R.id.pgBar); negPgBar = (ProgressBar) findViewById(R.id.negPgBar); - pgCurrent = (Button) findViewById(R.id.pgCurrent); - - lvl = (TextView) findViewById(R.id.lvl); currentPg = (TextView) findViewById(R.id.currentPg); currentXp = (TextView) findViewById(R.id.currentXp); currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts); @@ -83,18 +81,19 @@ public class MainActivity extends ActionBarActivity { @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_main, menu); + getMenuInflater().inflate(R.menu.menu_show_player, menu); return true; } @Override public boolean onPrepareOptionsMenu (Menu menu) { - MenuItem menuUndo = menu.findItem(R.id.action_undo); - menuUndo.setEnabled(undo); - if (undo) - menuUndo.getIcon().setAlpha(255); + MenuItem menuHeal = menu.findItem(R.id.action_cure); + boolean maxed = player.getPg() == player.getMaxPg(); + menuHeal.setEnabled(!maxed); + if (maxed) + menuHeal.getIcon().setAlpha(128); else - menuUndo.getIcon().setAlpha(128); + menuHeal.getIcon().setAlpha(255); return true; } @@ -112,14 +111,12 @@ public class MainActivity extends ActionBarActivity { Snackbar .with(this) .text(R.string.maxed_curative) + .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) ); } else { healDialog(); } return true; - } else if (id == R.id.action_undo) { - undo(); - return true; } else if (id == R.id.action_time_encounter_end) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.px_awarded_title); @@ -137,9 +134,6 @@ public class MainActivity extends ActionBarActivity { //levelUp //TODO: improve leveling up by using a sliding guide player.setMaxPgOnLevelUp(); - lvl.setText( - String.valueOf(player.getLevel()) - ); } p.edit().putInt("px", player.getPx()).apply(); if(levelUp) @@ -148,12 +142,6 @@ public class MainActivity extends ActionBarActivity { pxUpdate(); ceUpdate(); pgUpdate(); -// incrementProgressBar( -// xpBar, currentXp, -// 1, levelUp, Player.LEVEL_PX[player.getLevel()] - -// Player.LEVEL_PX[player.getLevel() - 1], -// true, player.getPx() - Player.LEVEL_PX[player.getLevel() - 1] -// ); } catch(Exception e) { Toast.makeText(getApplicationContext(), "There was an error leveling up", Toast.LENGTH_LONG).show(); } @@ -162,28 +150,31 @@ public class MainActivity extends ActionBarActivity { alert.show(); input.requestFocus(); return true; - } else if (id == R.id.action_time_long_rest) { - player.rest(true); - SnackbarManager.show( - Snackbar - .with(this) - .text(R.string.long_rest_done) - ); - p.edit() - .putInt("pg", player.getPg()) - .putInt("curativeEfforts", player.getCurativeEfforts()) - .apply(); - pgUpdate(); - ceUpdate(); - } else if (id == R.id.action_time_rest) { - player.rest(false); - SnackbarManager.show( - Snackbar - .with(this) - .text(R.string.rest_done) - ); - pgUpdate(); - ceUpdate(); + //TODO: the player no longer contains the powers, therefore the +// } else if (id == R.id.action_time_long_rest) { +// player.rest(true); +// SnackbarManager.show( +// Snackbar +// .with(this) +// .text(R.string.long_rest_done) +// .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) +// ); +// p.edit() +// .putInt("pg", player.getPg()) +// .putInt("curativeEfforts", player.getCurativeEfforts()) +// .apply(); +// pgUpdate(); +// ceUpdate(); +// } else if (id == R.id.action_time_rest) { +// player.rest(false); +// SnackbarManager.show( +// Snackbar +// .with(this) +// .text(R.string.rest_done) +// .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) +// ); +// pgUpdate(); +// ceUpdate(); } return super.onOptionsItemSelected(item); @@ -205,6 +196,7 @@ public class MainActivity extends ActionBarActivity { Snackbar .with(this) .text(R.string.no_curative_efforts_error) + .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) ); } else { if(hasCured == Player.MAXED){ @@ -212,17 +204,13 @@ public class MainActivity extends ActionBarActivity { Snackbar .with(this) .text(R.string.maxed_curative) + .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) ); } SharedPreferences.Editor e = p.edit(); e.putInt("pg", player.getPg()); if(usesEffort) { e.putInt("curativeEfforts", player.getCurativeEfforts()); -// incrementProgressBar( -// curativeEffortsBar, currentCurativeEfforts, -// 100, false, 0, -// true, player.getCurativeEfforts() -// ); ceUpdate(); } e.apply(); @@ -266,21 +254,14 @@ public class MainActivity extends ActionBarActivity { alert.setView(input); final Context context = getApplicationContext(); - final MainActivity activity = this; + final ShowPlayer activity = this; alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { - int preValue = Integer.parseInt(pgCurrent.getText().toString()); + int preValue = player.getPg(); int damage = Integer.parseInt(input.getText().toString()); player.losePg(damage); - pgCurrent.setText(String.valueOf(player.getPg())); -// incrementProgressBar( -// pgBar, currentPg, -// 100, false, 0, -// true, player.getPg() -// ); - //finished correctly, then apply values to undo's undo = true; undoPreviousValue = preValue; undoObject = CURRENT_PG; @@ -294,6 +275,7 @@ public class MainActivity extends ActionBarActivity { } }) .actionColor(getResources().getColor(R.color.yellow)) + .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) ,activity); // action button's p.edit().putInt("pg", player.getPg()).apply(); pgUpdate(); @@ -315,104 +297,43 @@ public class MainActivity extends ActionBarActivity { private void pgUpdate() { int status = player.getState(); - int lastState = player.getLastState(); int pg = player.getPg(); if (pg < 0) { + if (status == Player.MUERTO) + negPgBar.setProgress(negPgBar.getMax()); + else + negPgBar.setProgress(-pg); pgBar.setProgress(0); - negPgBar.setProgress(-pg); - } else if (pg > 0) { + } else { pgBar.setProgress(pg); negPgBar.setProgress(0); - } else { - pgBar.setProgress(0); - negPgBar.setProgress(0); } + currentPg.setText(player.getPg() + " / " + player.getMaxPg()); -// incrementProgressBar( -// pgBar, currentPg, -// 100, false, 0, -// true, Math.abs(player.getPg()) -// ); - pgCurrent.setText(String.valueOf(player.getPg())); + if (status == Player.MUERTO) { - pgCurrent.setTextColor(Color.BLACK); - pgCurrent.setBackgroundColor(getResources().getColor(R.color.red)); - - AlertDialog.Builder alert = new AlertDialog.Builder(this); - alert.setTitle(getString(R.string.reset_confirmation_title)); - alert.setMessage(getString(R.string.reset_confirmation)); - alert.setPositiveButton(R.string.action_undo, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - undo(); - } - }); - final Activity activity = this; - alert.setNegativeButton(R.string.die, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - SnackbarManager.show( - Snackbar - .with(activity) - .text(R.string.message_death) - ); - p.edit().clear().apply(); - restoreData(); - } - }); - - alert.show(); + pgBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.black), PorterDuff.Mode.SRC_IN); } else if (status == Player.DEBILITADO) { - pgCurrent.setBackgroundColor(android.R.drawable.btn_default); - 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 - .with(this) - .text(R.string.state_changed_debilitado) - ); - } } else if (status == Player.MALHERIDO) { - pgCurrent.setBackgroundColor(android.R.drawable.btn_default); - 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 - .with(this) - .text(R.string.state_changed_malherido) - ); - } } else { - pgCurrent.setTextColor(getResources().getColor(R.color.green)); - pgCurrent.setBackgroundColor(android.R.drawable.btn_default); 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 ); - } else { - 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", 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()) - }); - } + //Loading player + + player = new Player( p ); + pxUpdate(); xpBar.setMax( Player.LEVEL_PX[player.getLevel()] - - Player.LEVEL_PX[player.getLevel() - 1] + Player.LEVEL_PX[player.getLevel() - 1] ); if (player.getMaxPg() == 0) { @@ -427,44 +348,50 @@ public class MainActivity extends ActionBarActivity { pgUpdate(); ceUpdate(); //set restored values to the respective fields - ((TextView) findViewById(R.id.nameText)).setText(player.getName()); - ((TextView) findViewById(R.id.raceText)).setText(player.getRaceName()); - ((TextView) findViewById(R.id.classText)).setText(player.getClassName()); - lvl.setText(String.valueOf(player.getLevel())); - - //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() + toolbar.setTitle(player.getName()); + toolbar.setSubtitle( + player.getClassName() + " " + player.getRaceName() + " " + player.getLevel() ); + toolbar.setTitleTextColor(getResources().getColor(R.color.white)); + toolbar.setSubtitleTextColor(getResources().getColor(R.color.white)); +// +// //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) + refreshList(); } private void ceUpdate() { @@ -487,7 +414,6 @@ public class MainActivity extends ActionBarActivity { private void undo() { String message = ""; if(undoObject == CURRENT_PG){ - pgCurrent.setText(String.valueOf(undoPreviousValue)); player.setPg(undoPreviousValue); undoObject = NULL; message = getString(R.string.action_undo_current_pg); @@ -497,6 +423,7 @@ public class MainActivity extends ActionBarActivity { Snackbar .with(this) .text(message) + .duration(Snackbar.SnackbarDuration.LENGTH_INDEFINITE) ); } pgUpdate(); @@ -526,4 +453,40 @@ public class MainActivity extends ActionBarActivity { dialog.show(); input.requestFocus(); } + + public void addToList (View view) { startActivity(new Intent(this, PowerEditor.class).putExtra("player", player.getName())); } + + private void refreshList() { + //TODO: check which is active (now there is only a power list), so there is only one possibility + + int n = p.getInt("powers",0); + int elements = 0; + ListView attackList = (ListView) findViewById(R.id.attackList); + AttackAdapter adapter = (AttackAdapter) attackList.getAdapter(); + + if ( adapter != null ) + elements = adapter.getCount(); + if ( elements < n && adapter != null ) { + for ( int i = elements; i < n; i++ ) { + SharedPreferences sav = getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE); + adapter.add( new Power ( sav ) ); + } + } else if ( n != 0 ) { + Power[] powers = new Power[n]; + for (int i = 0; i < n; i++) { + SharedPreferences sav = getSharedPreferences(p.getString("power" + i, ""), MODE_PRIVATE); + powers[i] = new Power(sav); + } + + attackList.setAdapter(new AttackAdapter(this, powers)); + + attackList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Toast.makeText(getApplicationContext(), ((Power)parent.getItemAtPosition(position)).getName(), Toast.LENGTH_LONG).show(); + //TODO: show here dialog with power's complete information, and buttons to use, recharge or delete + } + }); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java index 9e183b1..d72d980 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java @@ -49,7 +49,7 @@ public class Welcome extends ActionBarActivity { //noinspection SimplifiableIfStatement if ( id == R.id.action_add_player ) { - startActivity(new Intent(this, Introduction.class).putExtra("first_time", true)); + startActivity(new Intent(this, PlayerEditor.class).putExtra("first_time", true)); } return super.onOptionsItemSelected(item); @@ -61,7 +61,7 @@ public class Welcome extends ActionBarActivity { load(); } - //TODO: load all players with secondary constructor (except the ones created by introduction and haven't passed by MainActivity) + //TODO: load all players with secondary constructor (except the ones created by introduction and haven't passed by ShowPlayer) private void load() { int n = p.getInt("players",0); ListView playerList = (ListView) findViewById(R.id.listView); @@ -86,7 +86,6 @@ public class Welcome extends ActionBarActivity { 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 SharedPreferences sav = getSharedPreferences(p.getString("player" + i, ""), MODE_PRIVATE); if (sav.contains(Player.NAME)) players[i] = new Player( sav ); @@ -98,7 +97,7 @@ public class Welcome extends ActionBarActivity { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { startActivity(new Intent( - getApplicationContext(), MainActivity.class + getApplicationContext(), ShowPlayer.class ).putExtra("player", position)); } }); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index ef928ab..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,423 +0,0 @@ - - - - - - - - - - - - - - -