fixed daily goal, added personal progress bar

This commit is contained in:
asleal2 2018-04-30 18:48:10 -05:00
parent 736e9c3376
commit 83fbdcd8ed
3 changed files with 42 additions and 39 deletions

Binary file not shown.

View file

@ -33,8 +33,8 @@ namespace PedometerU.Tests
public Text remainingText; public Text remainingText;
// Goal information. // Goal information.
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); private string currentDayStr;
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); private string goalDayStr;
public string prefKey; public string prefKey;
// Used for time calculation. // Used for time calculation.
@ -43,7 +43,7 @@ namespace PedometerU.Tests
private const int secondsperday = 86400; private const int secondsperday = 86400;
//Progress Bar... //Progress Bar...
public float barDisplay; //current progress private float barDisplay; //current progress
//private Vector2 barPos; //private Vector2 barPos;
// This gets overwritten later by the background's size values. // This gets overwritten later by the background's size values.
private Vector2 barSize = new Vector2(5000, 10); private Vector2 barSize = new Vector2(5000, 10);
@ -52,7 +52,7 @@ namespace PedometerU.Tests
private Pedometer pedometer; private Pedometer pedometer;
int userSteps; int userSteps;
int userPoints; int userPoints;
int stepsGoal = 100; public int stepsGoal;
private int savedSteps; private int savedSteps;
private int savedPoints; private int savedPoints;
@ -77,9 +77,12 @@ namespace PedometerU.Tests
//write usersteps + saved val to pref in ONSTEP //write usersteps + saved val to pref in ONSTEP
void Start () void Start ()
{
if(prefKey == "daily")
{ {
// This should later only get called per goal // This should later only get called per goal
StartCoroutine(updateRival()); StartCoroutine(updateRival());
}
savedSteps = PlayerPrefs.GetInt("currentSteps"); savedSteps = PlayerPrefs.GetInt("currentSteps");
savedPoints = PlayerPrefs.GetInt("totalPoints"); savedPoints = PlayerPrefs.GetInt("totalPoints");
@ -97,6 +100,8 @@ namespace PedometerU.Tests
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString (); pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
} }
if(prefKey == "daily")
{
if(PlayerPrefs.HasKey("goalDate")) if(PlayerPrefs.HasKey("goalDate"))
{ {
goalDayStr = PlayerPrefs.GetString("goalDate"); goalDayStr = PlayerPrefs.GetString("goalDate");
@ -104,9 +109,10 @@ namespace PedometerU.Tests
else else
{ {
PlayerPrefs.SetString("goalDate", PlayerPrefs.SetString("goalDate",
System.DateTime.Now.AddMinutes(1).ToString("MM/dd/yyyy")); System.DateTime.Now.AddDays(1).ToString("MM/dd/yyyy"));
goalDayStr = PlayerPrefs.GetString("goalDate"); goalDayStr = PlayerPrefs.GetString("goalDate");
} }
}
userSteps = savedSteps; userSteps = savedSteps;
userPoints = savedPoints; userPoints = savedPoints;
@ -121,7 +127,6 @@ namespace PedometerU.Tests
//barPos = new Vector2(pbbg.transform.position.x, 1895 - pbbg.transform.position.y); //barPos = new Vector2(pbbg.transform.position.x, 1895 - pbbg.transform.position.y);
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
} }
// Was used for testing. // Was used for testing.
@ -193,27 +198,31 @@ namespace PedometerU.Tests
{ {
updateTimeRemaining (); updateTimeRemaining ();
updateProgressBar (); updateProgressBar ();
if(prefKey == "daily")
{
updateMonsterProgressBar (); updateMonsterProgressBar ();
//needs current points counting toward this goal (daily?)
//needs the total required points for this goal
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
remainingText.text = formatTimeRemaining (); remainingText.text = formatTimeRemaining ();
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
}
//barDisplay = Time.time*0.05f; //put actual progress here (current/total) userSteps = (int)(Time.time*10.0f);
//barDisplay = Time.time*0.05f;
barDisplay = (float)userSteps/(float)stepsGoal; barDisplay = (float)userSteps/(float)stepsGoal;
//check if the current date matches the goal date //check if the current date matches the goal date
if(currentDayStr == goalDayStr) if(prefKey == "daily" && currentDayStr == goalDayStr)
{ {
Debug.Log("current: " + currentDayStr); Debug.Log("current: " + currentDayStr);
Debug.Log("goal: " + goalDayStr); Debug.Log("goal: " + goalDayStr);
Debug.Log("DAY HAS PASSED!! SETTING GOAL TO NEXT DAY!!"); Debug.Log(prefKey + "...DAY HAS PASSED!! SETTING GOAL TO NEXT DAY!!");
PlayerPrefs.SetString("goalDate", PlayerPrefs.SetString("goalDate",
System.DateTime.Now.AddMinutes(1).ToString("MM/dd/yyyy")); System.DateTime.Now.AddDays(1).ToString("MM/dd/yyyy"));
goalDayStr = PlayerPrefs.GetString("goalDate"); goalDayStr = PlayerPrefs.GetString("goalDate");
Debug.Log("new goal: " + goalDayStr); Debug.Log("new goal: " + goalDayStr);
//reset steps...
userSteps = 0;
PlayerPrefs.SetInt("currentSteps", userSteps);
} }
//goal complete //goal complete
if(barDisplay >= 1.0f) if(barDisplay >= 1.0f)
@ -236,12 +245,6 @@ namespace PedometerU.Tests
invList.Append(items[(int)Math.Round(UnityEngine.Random.value*6.0f)]).Append(" "); invList.Append(items[(int)Math.Round(UnityEngine.Random.value*6.0f)]).Append(" ");
PlayerPrefs.SetString ("inventory", invList.ToString()); PlayerPrefs.SetString ("inventory", invList.ToString());
} }
//only applies if "daily" goal
if(prefKey == "daily")
{
} }
} }
} }
}

View file

@ -1 +1 @@
m_EditorVersion: 2017.3.1f1 m_EditorVersion: 2017.4.0f1