Second progress bar added. Now fills based on how much time is left in the day.

This commit is contained in:
Alex Huddleston 2018-04-29 22:53:51 -05:00
parent 843bed5bce
commit dde52effed
5 changed files with 78 additions and 40 deletions

Binary file not shown.

Binary file not shown.

View file

@ -7,32 +7,48 @@ using UnityEngine.UI;
using System.Text; using System.Text;
//Pretty much a copy of GetData... //Pretty much a copy of GetData...
namespace PedometerU.Tests { namespace PedometerU.Tests
{
public class GetGoals : MonoBehaviour
{
// Goals Progress Bar
public Image pbbg;
public Image pbf;
// Monster Progress Bar
public Image mpbbg;
public Image mpbf;
public class GetGoals : MonoBehaviour {
public Image background;
public Image fill;
private string[] items = { "circle_eye", "crazy_hair", "circle_head", "gap_mouth", "pig_nose", "crown" }; private string[] items = { "circle_eye", "crazy_hair", "circle_head", "gap_mouth", "pig_nose", "crown" };
// Display Text
public Text goalText; public Text goalText;
public Text stepText;
public Text pointsText;
public Text remainingText;
// Goal information.
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
public string prefKey; public string prefKey;
// Used for time calculation.
private int timeUsed;
private int timeRemaining;
private const int secondsperday = 86400;
//Progress Bar... //Progress Bar...
public float barDisplay; //current progress public float barDisplay; //current progress
//private Vector2 barPos; //private Vector2 barPos;
// This gets overwritten later by the background's size values.
private Vector2 barSize = new Vector2(5000, 10); private Vector2 barSize = new Vector2(5000, 10);
//Pedometer //Pedometer
private Pedometer pedometer; private Pedometer pedometer;
int userSteps; int userSteps;
int userPoints; int userPoints;
//double userDistance;
int stepsGoal = 100; int stepsGoal = 100;
public Text stepText;
public Text pointsText;
private int savedSteps; private int savedSteps;
private int savedPoints; private int savedPoints;
@ -58,9 +74,6 @@ namespace PedometerU.Tests {
void Start () void Start ()
{ {
fill.type = Image.Type.Filled;
fill.fillMethod = Image.FillMethod.Horizontal;
fill.type = Image.Type.Sliced;
savedSteps = PlayerPrefs.GetInt("currentSteps"); savedSteps = PlayerPrefs.GetInt("currentSteps");
savedPoints = PlayerPrefs.GetInt("totalPoints"); savedPoints = PlayerPrefs.GetInt("totalPoints");
// Create a new pedometer // Create a new pedometer
@ -85,9 +98,9 @@ namespace PedometerU.Tests {
//goalText.text = prefKey; //goalText.text = prefKey;
goalText.color = new Color(0f, 0f, 0f); goalText.color = new Color(0f, 0f, 0f);
Debug.Log(background.rectTransform.anchoredPosition.x.ToString() + " " + background.rectTransform.anchoredPosition.y.ToString()); Debug.Log(pbbg.rectTransform.anchoredPosition.x.ToString() + " " + pbbg.rectTransform.anchoredPosition.y.ToString());
//barPos = new Vector2(background.transform.position.x, 1895 - background.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"); goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
@ -97,11 +110,6 @@ namespace PedometerU.Tests {
savePersistantGoalDate("daily"); savePersistantGoalDate("daily");
} }
//Texture the progress bar using these parameters
public Texture2D emptyTex;
public Texture2D fullTex;
//on a button press? begin a goal? //on a button press? begin a goal?
void startGoal() void startGoal()
{ {
@ -119,45 +127,75 @@ namespace PedometerU.Tests {
return false; return false;
return true; return true;
} }
/*
void OnGUI() {
Debug.Log (background.rectTransform.rect.width);
barSize = new Vector2 (background.rectTransform.rect.width, background.rectTransform.rect.height);
//draw the background:
GUI.BeginGroup(new Rect(barPos.x, barPos.y, barSize.x, barSize.y));
GUI.Box(new Rect(0,0, barSize.x, barSize.y), emptyTex);
//draw the filled-in part:
GUI.BeginGroup(new Rect(0,0, barSize.x * barDisplay, barSize.y));
GUI.Box(new Rect(0,0, barSize.x, barSize.y), fullTex);
GUI.EndGroup();
GUI.EndGroup();
}
*/
// Was used for testing. // Was used for testing.
//private float tempcounter = 0.1f; private float tempcounter = 0.1f;
// Call this to update the goals progress bar.
public void updateProgressBar() public void updateProgressBar()
{ {
//Debug.Log (background.rectTransform.rect.width + " " + background.rectTransform.rect.height); //Debug.Log (pbbg.rectTransform.rect.width + " " + pbbg.rectTransform.rect.height);
barSize.x = background.rectTransform.rect.width; barSize.x = pbbg.rectTransform.rect.width;
barSize.y = background.rectTransform.rect.height;
//tempcounter += 0.0005f; //tempcounter += 0.0005f;
// resize the fill. // resize the fill.
RectTransform temp = fill.rectTransform; RectTransform temp = pbf.rectTransform;
temp.sizeDelta = new Vector2 (barSize.x * barDisplay, barSize.y); //temp.sizeDelta = new Vector2 (-barSize.x + barSize.x * tempcounter, 0);
temp.sizeDelta = new Vector2 (-barSize.x + (barSize.x * barDisplay), 0);
temp.anchoredPosition = new Vector2 (temp.rect.width * 0.5f - (barSize.x * 0.5f),0); temp.anchoredPosition = new Vector2 (temp.rect.width * 0.5f - (barSize.x * 0.5f),0);
} }
// Call this to update the monster's progress bar.
public void updateMonsterProgressBar()
{
float fractionused = (float)(timeUsed) / (float)(secondsperday);
//Debug.Log (dayleft);
barSize.x = mpbbg.rectTransform.rect.width;
//tempcounter += 0.0005f;
// resize the fill.
RectTransform temp = mpbf.rectTransform;
//temp.sizeDelta = new Vector2 (-barSize.x + barSize.x * tempcounter, 0);
temp.sizeDelta = new Vector2 (-barSize.x + (barSize.x * fractionused), 0);
temp.anchoredPosition = new Vector2 (temp.rect.width * 0.5f - (barSize.x * 0.5f),0);
}
// Calculates the time remaining for the day.
// Will likely make a separate function for smaller timed goals if we have time.
public void updateTimeRemaining()
{
timeUsed = ((System.DateTime.Now.Hour * 60 * 60) + (System.DateTime.Now.Minute * 60) + System.DateTime.Now.Second);
timeRemaining = secondsperday - timeUsed;
}
// Format the time remaining variable to a proper string.
public string formatTimeRemaining()
{
string output = "Time remaining: ";
output += "" + (timeRemaining / 3600);
output += ":" + (timeRemaining % 3600 / 60);
output += ":" + (timeRemaining % 60);
return output;
}
void Update() void Update()
{ {
updateTimeRemaining ();
updateProgressBar (); updateProgressBar ();
updateMonsterProgressBar ();
//needs current points counting toward this goal (daily?) //needs current points counting toward this goal (daily?)
//needs the total required points for this goal //needs the total required points for this goal
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
remainingText.text = formatTimeRemaining ();
//barDisplay = Time.time*0.05f; //put actual progress here (current/total) //barDisplay = Time.time*0.05f; //put actual progress here (current/total)
barDisplay = (float)userSteps/(float)stepsGoal; barDisplay = (float)userSteps/(float)stepsGoal;

View file

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