From 2fc2ff61ba88feebd7a0c8f3e246d8bc62a39031 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Thu, 23 Apr 2015 15:39:45 +0200 Subject: [PATCH] Powers display --- .idea/misc.xml | 2 +- .../kauron/dungeonmanager/AttackAdapter.java | 39 ---- .../com/kauron/dungeonmanager/Player.java | 8 +- .../java/com/kauron/dungeonmanager/Power.java | 13 +- .../com/kauron/dungeonmanager/ShowPlayer.java | 81 +++++++- .../main/res/layout/activity_power_editor.xml | 6 +- app/src/main/res/layout/attack_display.xml | 193 ++++++++++++++++++ app/src/main/res/layout/attack_row.xml | 12 -- app/src/main/res/values-es/strings.xml | 61 ++++++ app/src/main/res/values/colors.xml | 5 + app/src/main/res/values/strings.xml | 18 ++ 11 files changed, 370 insertions(+), 68 deletions(-) create mode 100644 app/src/main/res/layout/attack_display.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 4eca83f..b0c0cbc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,7 +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 d9cf934..cb569d7 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java +++ b/app/src/main/java/com/kauron/dungeonmanager/AttackAdapter.java @@ -36,45 +36,6 @@ class AttackAdapter extends ArrayAdapter { ((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; - 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 5fd08c9..86feef3 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Player.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Player.java @@ -160,7 +160,7 @@ class Player implements Serializable { this.pg = maxPg; this.maxPg = maxPg; } - void setMaxPgOnLevelUp() {maxPg += CLASS_STATS[PG_ON_LEVEL_UP][classInt];} + private void setMaxPgOnLevelUp() {maxPg += CLASS_STATS[PG_ON_LEVEL_UP][classInt];} int getPg() {return pg;} void setPg(int pg) {this.pg = pg; setState();} @@ -206,10 +206,8 @@ class Player implements Serializable { String getName() {return name;} String getClassName() {return CLASS_STRINGS[classInt];} String getRaceName() {return RACE_STRINGS[raceInt];} - void setRaceInt(int raceInt) {this.raceInt = raceInt;} - int getRaceInt() {return raceInt;} - void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();} + private void setAtk(int[] atk) {this.atk = atk; if(classInt != NULL) setClass();} int getFue() {return atk[FUE];} int getCon() {return atk[CON];} @@ -222,7 +220,7 @@ class Player implements Serializable { int getRef() {return def[REF];} int getVol() {return def[VOL];} - void setClass() { + private 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: implement armor! diff --git a/app/src/main/java/com/kauron/dungeonmanager/Power.java b/app/src/main/java/com/kauron/dungeonmanager/Power.java index fce7882..e05881a 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Power.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Power.java @@ -1,6 +1,7 @@ package com.kauron.dungeonmanager; import android.content.SharedPreferences; +import android.graphics.Color; import java.io.Serializable; @@ -45,16 +46,22 @@ class Power implements Serializable{ String getKeywords() {return keywords;} + String getTypeString() {return ACTIONS[action];} String getFrequencyString() {return FREQ[freq];} - int getFreq() {return freq;} - String getRangeString() {return DISTANCES[range];} - int getRange() {return range;} + + int getAtk() {return atk;} + int getDef() {return def;} + int getFreq() {return freq;} int getDistance() {return distance;} String getName(){return name;} String getImpact() {return impact;} + String getObjective() {return objective;} + String getOther() {return "";} + + //TODO: add other element to include further description boolean isUsed(){return used;} diff --git a/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java b/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java index 560c533..91fb68d 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java +++ b/app/src/main/java/com/kauron/dungeonmanager/ShowPlayer.java @@ -1,10 +1,13 @@ package com.kauron.dungeonmanager; +import android.app.Activity; import android.app.AlertDialog; +import android.app.Dialog; 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; @@ -131,9 +134,7 @@ public class ShowPlayer extends ActionBarActivity { try { boolean levelUp = player.addPx(Integer.parseInt(input.getText().toString())); if (levelUp) { - //levelUp //TODO: improve leveling up by using a sliding guide - player.setMaxPgOnLevelUp(); } p.edit().putInt("px", player.getPx()).apply(); if(levelUp) @@ -479,12 +480,82 @@ public class ShowPlayer extends ActionBarActivity { } attackList.setAdapter(new AttackAdapter(this, powers)); - + final Activity thisActivity = this; 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 + + final Dialog dialog = new Dialog(ShowPlayer.this); + dialog.setContentView(R.layout.attack_display); + // set the custom dialog components - text, image and button +// Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); +// // if button is clicked, close the custom dialog +// dialogButton.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// dialog.dismiss(); +// } +// }); + + //identify all the elements from the VIEW and then add LISTENERS + Power power = (Power) parent.getItemAtPosition(position); + View nameText = dialog.findViewById(R.id.nameText); + switch(power.getFreq()){ + case Power.A_VOLUNTAD: + nameText.setBackgroundColor(getResources().getColor(R.color.at_will)); + break; + case Power.ENCUENTRO: + nameText.setBackgroundColor(getResources().getColor(R.color.encounter)); + break; + case Power.DIARIO: + nameText.setBackgroundColor(getResources().getColor(R.color.daily)); + break; + default: + nameText.setBackgroundColor(getResources().getColor(R.color.green)); + } + //TODO: fix the title gap + ((TextView) nameText) .setText(power.getName()); + ((TextView) dialog.findViewById(R.id.typeText)) .setText(power.getTypeString()); + ((TextView) dialog.findViewById(R.id.rangeText)) .setText(power.getRangeString() + " "); + ((TextView) dialog.findViewById(R.id.freqText)) .setText(power.getFrequencyString()); + ((TextView) dialog.findViewById(R.id.keywordsText)) .setText(power.getKeywords()); + ((TextView) dialog.findViewById(R.id.distanceText)) .setText(String.valueOf(power.getDistance())); + ((TextView) dialog.findViewById(R.id.objectiveText)).setText(power.getObjective()); + ((TextView) dialog.findViewById(R.id.impactText)) .setText(power.getImpact()); + ((TextView) dialog.findViewById(R.id.otherText)) .setText(power.getOther()); + + String[] attack = getResources().getStringArray(R.array.attack_array); + String[] defense = getResources().getStringArray(R.array.defense_array); + //TODO: add attack and defense array + ((TextView) dialog.findViewById(R.id.attackText)) .setText(attack[power.getAtk()] + + " " + getResources().getString(R.string.vs) + + " " + defense[power.getDef()]); + + dialog.findViewById(R.id.useButton).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //TODO: use power + Toast.makeText(getApplicationContext(), "Use it", Toast.LENGTH_LONG).show(); + } + }); + + dialog.findViewById(R.id.deleteButton).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //TODO: delete power + Toast.makeText(getApplicationContext(), "Delete it", Toast.LENGTH_LONG).show(); + } + }); + + dialog.findViewById(R.id.editButton).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //TODO: edit power + Toast.makeText(getApplicationContext(), "Edit it", Toast.LENGTH_LONG).show(); + } + }); + + dialog.show(); } }); } diff --git a/app/src/main/res/layout/activity_power_editor.xml b/app/src/main/res/layout/activity_power_editor.xml index 9f54d9b..e58e04e 100644 --- a/app/src/main/res/layout/activity_power_editor.xml +++ b/app/src/main/res/layout/activity_power_editor.xml @@ -147,8 +147,8 @@ android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:hint="@string/impactEditHint" - android:layout_toRightOf="@+id/impactText" - android:layout_toEndOf="@+id/impactText" /> + android:layout_toRightOf="@+id/attackText" + android:layout_toEndOf="@+id/attackText" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +