1
0
Fork 0

Completed PlayerAdapter

Untested, but the multiplayer load is complete
Saving as multiplayer is needed
This commit is contained in:
Carlos Galindo 2015-04-06 17:10:46 +02:00
parent a3831597d0
commit 0459c14d91
7 changed files with 78 additions and 23 deletions

View file

@ -46,7 +46,7 @@ public class MainActivity extends ActionBarActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
p = getSharedPreferences("basics", MODE_PRIVATE); p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
xpBar = (ProgressBar) findViewById(R.id.xpBar); xpBar = (ProgressBar) findViewById(R.id.xpBar);
curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar); curativeEffortsBar = (ProgressBar) findViewById(R.id.curativeEffortsBar);
pgBar = (ProgressBar) findViewById(R.id.pgBar); pgBar = (ProgressBar) findViewById(R.id.pgBar);
@ -59,6 +59,7 @@ public class MainActivity extends ActionBarActivity {
currentXp = (TextView) findViewById(R.id.currentXp); currentXp = (TextView) findViewById(R.id.currentXp);
currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts); currentCurativeEfforts = (TextView) findViewById(R.id.currentCurativeEfforts);
//TODO: change references to xml and do not change progressbar background
xpBar.getProgressDrawable() xpBar.getProgressDrawable()
.setColorFilter(Color.parseColor("#62BACE"), PorterDuff.Mode.SRC_IN); .setColorFilter(Color.parseColor("#62BACE"), PorterDuff.Mode.SRC_IN);
curativeEffortsBar.getProgressDrawable() curativeEffortsBar.getProgressDrawable()

View file

@ -2,6 +2,8 @@ package com.kauron.dungeonmanager;
class Player { class Player {
public static final String NAME = "playerName", CLASS = "classInt", RACE = "raceInt", PX = "px";
/** /**
* Names for the classes * Names for the classes
*/ */

View file

@ -21,17 +21,18 @@ class PlayerAdapter extends ArrayAdapter<Player> {
final Player player = getItem(position); final Player player = getItem(position);
if ( player != null ) {
((TextView) mView.findViewById(R.id.name)).setText(player.getName()); ((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.other)).setText(player.getClassName() + " " + player.getRaceName());
((TextView) mView.findViewById(R.id.level)) ((TextView) mView.findViewById(R.id.level))
.setText( .setText(
getContext().getResources().getString(R.string.level) getContext().getResources().getString(R.string.level) + " " + player.getLevel()
+ " " + player.getLevel()
); );
ProgressBar pg = (ProgressBar) mView.findViewById(R.id.progressBar); ProgressBar pg = (ProgressBar) mView.findViewById(R.id.progressBar);
pg.setMax(player.getMaxPg()); pg.setMax(player.getMaxPg());
pg.setProgress(player.getPg()); pg.setProgress(player.getPg());
}
return mView; return mView;
} }

View file

@ -7,7 +7,10 @@ import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager; import com.nispok.snackbar.SnackbarManager;
@ -15,6 +18,8 @@ import com.nispok.snackbar.SnackbarManager;
public class Welcome extends ActionBarActivity { public class Welcome extends ActionBarActivity {
public static final String PREFERENCES = "basics";
private Button load; private Button load;
private SharedPreferences p; private SharedPreferences p;
@ -22,7 +27,7 @@ public class Welcome extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome); setContentView(R.layout.activity_welcome);
p = getSharedPreferences("basics", MODE_PRIVATE); p = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
load = (Button) findViewById(R.id.loadCharacter); load = (Button) findViewById(R.id.loadCharacter);
if (p.getBoolean("saved", false)) { if (p.getBoolean("saved", false)) {
load.setEnabled(true); load.setEnabled(true);
@ -31,15 +36,49 @@ public class Welcome extends ActionBarActivity {
load.setEnabled(false); load.setEnabled(false);
load.setText(R.string.load_character); 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) { public void onNewClick(View view) {startActivity(new Intent(this, Introduction.class).putExtra("first_time", true));}
startActivity(new Intent(this, Introduction.class).putExtra("first_time", true)); public void onLoadClick(View view) {startActivity(new Intent(this, MainActivity.class).putExtra("player", -1));}
}
public void onLoadClick(View view) {
startActivity(new Intent(this, MainActivity.class));
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
@ -57,7 +96,12 @@ public class Welcome extends ActionBarActivity {
//noinspection SimplifiableIfStatement //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) { if (id == R.id.action_settings) {
SnackbarManager.show(
Snackbar.with(getApplicationContext()).text("This doesn't work yet")
);
return true; return true;
} else if ( id == R.id.action_add_player ) {
startActivity(new Intent(this, Introduction.class).putExtra("first_time", true));
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

View file

@ -50,7 +50,7 @@
<ListView <ListView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/listView2" android:id="@+id/listView"
android:layout_gravity="center_horizontal" /> android:layout_gravity="center_horizontal" />
</LinearLayout> </LinearLayout>

View file

@ -6,9 +6,15 @@
android:id="@+id/action_settings" android:id="@+id/action_settings"
android:title="@string/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:orderInCategory="100"
app:showAsAction="ifRoom" app:showAsAction="never"
android:icon="@drawable/ic_action_settings" android:icon="@drawable/ic_action_settings"
android:alpha="10" android:visible="false"/>
android:enabled="false"/>
<item
android:id="@+id/action_add_player"
android:title="@string/add_player"
android:orderInCategory="10"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_add_user"/>
</menu> </menu>

View file

@ -87,4 +87,5 @@
<string name="title_activity_power_editor">PowerEditor</string> <string name="title_activity_power_editor">PowerEditor</string>
<string name="hello_world">Hello world!</string> <string name="hello_world">Hello world!</string>
<string name="add_player">Add player</string>
</resources> </resources>