From 0459c14d919d5f85f1f17c446f186659302c61be Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Mon, 6 Apr 2015 17:10:46 +0200 Subject: [PATCH] Completed PlayerAdapter Untested, but the multiplayer load is complete Saving as multiplayer is needed --- .../kauron/dungeonmanager/MainActivity.java | 3 +- .../com/kauron/dungeonmanager/Player.java | 2 + .../kauron/dungeonmanager/PlayerAdapter.java | 21 +++---- .../com/kauron/dungeonmanager/Welcome.java | 60 ++++++++++++++++--- app/src/main/res/layout/activity_welcome.xml | 2 +- app/src/main/res/menu/menu_welcome.xml | 12 +++- app/src/main/res/values/strings.xml | 1 + 7 files changed, 78 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java b/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java index a4e448e..44bc860 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java +++ b/app/src/main/java/com/kauron/dungeonmanager/MainActivity.java @@ -46,7 +46,7 @@ public class MainActivity extends ActionBarActivity { setSupportActionBar(toolbar); setContentView(R.layout.activity_main); - p = getSharedPreferences("basics", MODE_PRIVATE); + p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE); xpBar = (ProgressBar) findViewById(R.id.xpBar); curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar); pgBar = (ProgressBar) findViewById(R.id.pgBar); @@ -59,6 +59,7 @@ 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 xpBar.getProgressDrawable() .setColorFilter(Color.parseColor("#62BACE"), PorterDuff.Mode.SRC_IN); curativeEffortsBar.getProgressDrawable() diff --git a/app/src/main/java/com/kauron/dungeonmanager/Player.java b/app/src/main/java/com/kauron/dungeonmanager/Player.java index af33672..6d18bf0 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Player.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Player.java @@ -2,6 +2,8 @@ package com.kauron.dungeonmanager; class Player { + public static final String NAME = "playerName", CLASS = "classInt", RACE = "raceInt", PX = "px"; + /** * Names for the classes */ diff --git a/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java b/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java index 46019f0..226e588 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java +++ b/app/src/main/java/com/kauron/dungeonmanager/PlayerAdapter.java @@ -21,17 +21,18 @@ class PlayerAdapter extends ArrayAdapter { 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() - ); + if ( player != null ) { + ((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()); + ProgressBar pg = (ProgressBar) mView.findViewById(R.id.progressBar); + pg.setMax(player.getMaxPg()); + pg.setProgress(player.getPg()); + } 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 cf80498..421f2ca 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java @@ -7,7 +7,10 @@ import android.os.Bundle; 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; @@ -15,6 +18,8 @@ import com.nispok.snackbar.SnackbarManager; public class Welcome extends ActionBarActivity { + public static final String PREFERENCES = "basics"; + private Button load; private SharedPreferences p; @@ -22,7 +27,7 @@ public class Welcome extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); - p = getSharedPreferences("basics", MODE_PRIVATE); + p = getSharedPreferences(PREFERENCES, MODE_PRIVATE); load = (Button) findViewById(R.id.loadCharacter); if (p.getBoolean("saved", false)) { load.setEnabled(true); @@ -31,15 +36,49 @@ public class Welcome extends ActionBarActivity { load.setEnabled(false); load.setText(R.string.load_character); } + + int n = p.getInt("players",0); + if ( n != 0 ) { + Player[] players = new Player[n]; + for ( int i = 0; i < n; i++ ) { + //TODO: fill the information for the player creation + SharedPreferences sav = getSharedPreferences("player" + i, MODE_PRIVATE); + 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] + ); + } + ListView playerList = (ListView) findViewById(R.id.listView); + ListAdapter adapter = new PlayerAdapter(this, players); + playerList.setAdapter(adapter); + + playerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + startActivity(new Intent( + getApplicationContext(), MainActivity.class + ).putExtra("player", position)); + } + }); + } 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)); - } + 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) { @@ -57,7 +96,12 @@ public class Welcome extends ActionBarActivity { //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); diff --git a/app/src/main/res/layout/activity_welcome.xml b/app/src/main/res/layout/activity_welcome.xml index 5df66dc..5a5bbc0 100644 --- a/app/src/main/res/layout/activity_welcome.xml +++ b/app/src/main/res/layout/activity_welcome.xml @@ -50,7 +50,7 @@ diff --git a/app/src/main/res/menu/menu_welcome.xml b/app/src/main/res/menu/menu_welcome.xml index aae6186..58401c8 100644 --- a/app/src/main/res/menu/menu_welcome.xml +++ b/app/src/main/res/menu/menu_welcome.xml @@ -6,9 +6,15 @@ android:id="@+id/action_settings" android:title="@string/action_settings" android:orderInCategory="100" - app:showAsAction="ifRoom" + app:showAsAction="never" android:icon="@drawable/ic_action_settings" - android:alpha="10" - android:enabled="false"/> + android:visible="false"/> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f6348f9..e51626d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -87,4 +87,5 @@ PowerEditor Hello world! + Add player