Functioning welcome activity
This commit is contained in:
parent
c5c5daef07
commit
0670be555f
6 changed files with 56 additions and 74 deletions
|
@ -100,41 +100,9 @@ public class MainActivity extends ActionBarActivity{
|
|||
healDialog();
|
||||
}
|
||||
return true;
|
||||
} else if (id == R.id.action_edit_basics) {
|
||||
Intent intent = new Intent(this, Introduction.class);
|
||||
startActivity(intent.putExtra(
|
||||
"first_time",
|
||||
!p.getBoolean("saved", false)
|
||||
));
|
||||
restoreData();
|
||||
return true;
|
||||
} else if (id == R.id.action_undo) {
|
||||
undo();
|
||||
return true;
|
||||
} else if (id == R.id.action_reset) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(R.string.reset_confirmation_title);
|
||||
alert.setMessage(R.string.reset_confirmation);
|
||||
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
R.string.message_reset,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
p.edit().clear().apply();
|
||||
player = null;
|
||||
restoreData();
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
// Canceled.
|
||||
}
|
||||
});
|
||||
|
||||
alert.show();
|
||||
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);
|
||||
|
@ -184,14 +152,6 @@ public class MainActivity extends ActionBarActivity{
|
|||
alert.show();
|
||||
input.requestFocus();
|
||||
return true;
|
||||
} else if (id == R.id.action_download) {
|
||||
//TODO: create self-updater
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
"This function is not ready yet",
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
return true;
|
||||
} else if (id == R.id.action_time_long_rest) {
|
||||
player.rest(true);
|
||||
Toast.makeText(
|
||||
|
|
|
@ -1,35 +1,44 @@
|
|||
package com.kauron.dungeonmanager;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class Welcome extends ActionBarActivity {
|
||||
|
||||
private Button load, newChar;
|
||||
private Button load;
|
||||
private SharedPreferences p;
|
||||
private TextView newText;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_welcome);
|
||||
newChar = (Button) findViewById(R.id.newCharacter);
|
||||
p = getSharedPreferences("basics", MODE_PRIVATE);
|
||||
load = (Button) findViewById(R.id.loadCharacter);
|
||||
load.setEnabled(
|
||||
getSharedPreferences("basics", MODE_PRIVATE).getBoolean("basics", false)
|
||||
);
|
||||
newText = (TextView) findViewById(R.id.newText);
|
||||
if (p.getBoolean("saved", false)) {
|
||||
load.setEnabled(true);
|
||||
load.setText(String.format(getString(R.string.load_text), p.getString("playerName", "")));
|
||||
newText.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
load.setEnabled(false);
|
||||
load.setText(R.string.load_character);
|
||||
newText.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: putBoolean in the intent correctly
|
||||
public void onNewClick(View view) {
|
||||
startActivity(new Intent(this, Introduction.class).putExtra("first_time", true));
|
||||
}
|
||||
|
||||
//TODO: get correctly the state of the saved game
|
||||
public void onLoadClick(View view) {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
}
|
||||
|
@ -55,4 +64,18 @@ public class Welcome extends ActionBarActivity {
|
|||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (p.getBoolean("saved", false)) {
|
||||
load.setEnabled(true);
|
||||
load.setText(String.format(getString(R.string.load_text), p.getString("playerName", "")));
|
||||
newText.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
load.setEnabled(false);
|
||||
load.setText(R.string.load_character);
|
||||
newText.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue