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;
// Goal information.
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
private string currentDayStr;
private string goalDayStr;
public string prefKey;
// Used for time calculation.
@ -43,7 +43,7 @@ namespace PedometerU.Tests
private const int secondsperday = 86400;
//Progress Bar...
public float barDisplay; //current progress
private float barDisplay; //current progress
//private Vector2 barPos;
// This gets overwritten later by the background's size values.
private Vector2 barSize = new Vector2(5000, 10);
@ -52,7 +52,7 @@ namespace PedometerU.Tests
private Pedometer pedometer;
int userSteps;
int userPoints;
int stepsGoal = 100;
public int stepsGoal;
private int savedSteps;
private int savedPoints;
@ -78,8 +78,11 @@ namespace PedometerU.Tests
void Start ()
{
// This should later only get called per goal
StartCoroutine(updateRival());
if(prefKey == "daily")
{
// This should later only get called per goal
StartCoroutine(updateRival());
}
savedSteps = PlayerPrefs.GetInt("currentSteps");
savedPoints = PlayerPrefs.GetInt("totalPoints");
@ -97,15 +100,18 @@ namespace PedometerU.Tests
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
}
if(PlayerPrefs.HasKey("goalDate"))
{
goalDayStr = PlayerPrefs.GetString("goalDate");
}
else
{
PlayerPrefs.SetString("goalDate",
System.DateTime.Now.AddMinutes(1).ToString("MM/dd/yyyy"));
goalDayStr = PlayerPrefs.GetString("goalDate");
if(prefKey == "daily")
{
if(PlayerPrefs.HasKey("goalDate"))
{
goalDayStr = PlayerPrefs.GetString("goalDate");
}
else
{
PlayerPrefs.SetString("goalDate",
System.DateTime.Now.AddDays(1).ToString("MM/dd/yyyy"));
goalDayStr = PlayerPrefs.GetString("goalDate");
}
}
userSteps = savedSteps;
userPoints = savedPoints;
@ -121,7 +127,6 @@ namespace PedometerU.Tests
//barPos = new Vector2(pbbg.transform.position.x, 1895 - pbbg.transform.position.y);
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
}
// Was used for testing.
@ -193,27 +198,31 @@ namespace PedometerU.Tests
{
updateTimeRemaining ();
updateProgressBar ();
updateMonsterProgressBar ();
if(prefKey == "daily")
{
updateMonsterProgressBar ();
remainingText.text = formatTimeRemaining ();
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
}
//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 ();
//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;
//check if the current date matches the goal date
if(currentDayStr == goalDayStr)
if(prefKey == "daily" && currentDayStr == goalDayStr)
{
Debug.Log("current: " + currentDayStr);
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",
System.DateTime.Now.AddMinutes(1).ToString("MM/dd/yyyy"));
System.DateTime.Now.AddDays(1).ToString("MM/dd/yyyy"));
goalDayStr = PlayerPrefs.GetString("goalDate");
Debug.Log("new goal: " + goalDayStr);
//reset steps...
userSteps = 0;
PlayerPrefs.SetInt("currentSteps", userSteps);
}
//goal complete
if(barDisplay >= 1.0f)
@ -230,18 +239,12 @@ namespace PedometerU.Tests
PlayerPrefs.SetInt("totalPoints", savedPoints);
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
//Random item
StringBuilder invList = new StringBuilder ();
invList.Append(PlayerPrefs.GetString ("inventory"));
invList.Append(items[(int)Math.Round(UnityEngine.Random.value*6.0f)]).Append(" ");
PlayerPrefs.SetString ("inventory", invList.ToString());
}
//only applies if "daily" goal
if(prefKey == "daily")
{
//Random item
StringBuilder invList = new StringBuilder ();
invList.Append(PlayerPrefs.GetString ("inventory"));
invList.Append(items[(int)Math.Round(UnityEngine.Random.value*6.0f)]).Append(" ");
PlayerPrefs.SetString ("inventory", invList.ToString());
}
}
}
}

View file

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