Completed PlayerAdapter
Untested, but the multiplayer load is complete Saving as multiplayer is needed
This commit is contained in:
parent
a3831597d0
commit
0459c14d91
7 changed files with 78 additions and 23 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -21,17 +21,18 @@ class PlayerAdapter extends ArrayAdapter<Player> {
|
|||
|
||||
final Player player = getItem(position);
|
||||
|
||||
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()
|
||||
getContext().getResources().getString(R.string.level) + " " + player.getLevel()
|
||||
);
|
||||
|
||||
ProgressBar pg = (ProgressBar) mView.findViewById(R.id.progressBar);
|
||||
pg.setMax(player.getMaxPg());
|
||||
pg.setProgress(player.getPg());
|
||||
}
|
||||
|
||||
return mView;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/listView2"
|
||||
android:id="@+id/listView"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -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"/>
|
||||
|
||||
<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>
|
||||
|
|
|
@ -87,4 +87,5 @@
|
|||
<string name="title_activity_power_editor">PowerEditor</string>
|
||||
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="add_player">Add player</string>
|
||||
</resources>
|
||||
|
|
Reference in a new issue