added new progress bar, should all work...

This commit is contained in:
asleal2 2018-04-30 21:30:05 -05:00
parent 008b327c9d
commit 499a0aedfd
2 changed files with 35 additions and 21 deletions

Binary file not shown.

View file

@ -60,14 +60,17 @@ namespace PedometerU.Tests
private int savedSteps; private int savedSteps;
private int savedPoints; private int savedPoints;
public string currentStepsKey;
public string totalPointsKey;
void OnStep (int steps, double distance) { void OnStep (int steps, double distance) {
//userDistance = (distance * 3.28084); //userDistance = (distance * 3.28084);
userSteps = steps + savedSteps; userSteps = steps + savedSteps;
PlayerPrefs.SetInt("currentSteps",userSteps); PlayerPrefs.SetInt(currentStepsKey,userSteps);
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString(); stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
userPoints = steps*5 + savedPoints; userPoints = steps*5 + savedPoints;
PlayerPrefs.SetInt("totalPoints",userPoints); PlayerPrefs.SetInt(totalPointsKey,userPoints);
pointsText.text = "Points: " + userPoints.ToString (); pointsText.text = "Points: " + userPoints.ToString ();
} }
@ -82,30 +85,38 @@ namespace PedometerU.Tests
void Start () void Start ()
{ {
PlayerPrefs.DeleteAll(); //danger!!
if(prefKey == "daily") if(prefKey == "daily")
{ {
// This should later only get called per goal // This should later only get called per goal
StartCoroutine(updateRival()); StartCoroutine(updateRival());
currentStepsKey = "currentSteps";
totalPointsKey = "totalPoints";
}
else
{
currentStepsKey = "currentSteps_p";
totalPointsKey = "totalPoints_p";
} }
savedSteps = PlayerPrefs.GetInt("currentSteps"); savedSteps = PlayerPrefs.GetInt(currentStepsKey);
savedPoints = PlayerPrefs.GetInt("totalPoints"); savedPoints = PlayerPrefs.GetInt(totalPointsKey);
// Create a new pedometer // Create a new pedometer
pedometer = new Pedometer(OnStep); pedometer = new Pedometer(OnStep);
// Reset UI // Reset UI
stepText.text = savedSteps.ToString () + "/" + stepsGoal.ToString(); stepText.text = savedSteps.ToString () + "/" + stepsGoal.ToString();
if(prefKey == "daily") if(PlayerPrefs.HasKey(totalPointsKey))
if(PlayerPrefs.HasKey("totalPoints"))
{ {
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString ();
} }
else else
{ {
PlayerPrefs.SetInt("totalPoints", 0); PlayerPrefs.SetInt(totalPointsKey, 0);
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString ();
} }
if(prefKey == "daily")
{ {
if(PlayerPrefs.HasKey("goalDate")) if(PlayerPrefs.HasKey("goalDate"))
{ {
@ -217,7 +228,7 @@ namespace PedometerU.Tests
updateTimeRemaining (); updateTimeRemaining ();
updateProgressBar (); updateProgressBar ();
updateMyGoalProgressBar (); //updateMyGoalProgressBar ();
if(prefKey == "daily") if(prefKey == "daily")
{ {
@ -226,9 +237,10 @@ namespace PedometerU.Tests
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
} }
//userSteps = (int)(Time.time); //userSteps = (int)(Time.time*10.0f);
//barDisplay = Time.time*0.05f; //barDisplay = Time.time*0.05f;
barDisplay = (float)userSteps/(float)stepsGoal; barDisplay = (float)userSteps/(float)stepsGoal;
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
//check if the current date matches the goal date //check if the current date matches the goal date
if(prefKey == "daily" && currentDayStr == goalDayStr) if(prefKey == "daily" && currentDayStr == goalDayStr)
@ -243,23 +255,25 @@ namespace PedometerU.Tests
//reset steps... //reset steps...
userSteps = 0; userSteps = 0;
PlayerPrefs.SetInt("currentSteps", userSteps); PlayerPrefs.SetInt(currentStepsKey, userSteps);
} }
//goal complete //goal complete
if(barDisplay >= 1.0f) if(barDisplay >= 1.0f)
{ {
Debug.Log("Goal complete! +100pts!"); Debug.Log(prefKey + "... Goal complete! +100pts!");
userSteps = 0; userSteps = 0;
PlayerPrefs.SetInt("currentSteps", userSteps); PlayerPrefs.SetInt(currentStepsKey, userSteps);
savedSteps = 0; savedSteps = 0;
//OnStep(0,0); //OnStep(0,0);
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString(); stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
//destroy the goal and set a new one? //destroy the goal and set a new one?
savedPoints += stepsGoal*10; savedPoints += stepsGoal*10;
PlayerPrefs.SetInt("totalPoints", savedPoints); PlayerPrefs.SetInt(totalPointsKey, savedPoints);
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); pointsText.text = "Points: " + PlayerPrefs.GetInt(totalPointsKey).ToString ();
if(!PlayerPrefs.HasKey("inventory"))
PlayerPrefs.SetString("inventory", "");
//Random item //Random item
StringBuilder invList = new StringBuilder (); StringBuilder invList = new StringBuilder ();
invList.Append(PlayerPrefs.GetString ("inventory")); invList.Append(PlayerPrefs.GetString ("inventory"));