124 lines
2.8 KiB
C#
124 lines
2.8 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
//Pretty much a copy of GetData...
|
|
|
|
public class GetGoals : MonoBehaviour {
|
|
|
|
public Text goalText;
|
|
|
|
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
|
|
public string prefKey;
|
|
|
|
public float goalValue;
|
|
|
|
//Progress Bar...
|
|
public float barDisplay; //current progress
|
|
public Vector2 barPos;
|
|
Vector2 barSize = new Vector2(227,20);
|
|
|
|
void Start () {
|
|
//goalText.text = prefKey;
|
|
goalText.color = new Color(0f, 0f, 0f);
|
|
|
|
goalText.transform.position = new Vector2(barPos.x + 45.0f,barPos.y + 55.0f);
|
|
|
|
|
|
//barPos.x = goalText.transform.position.x;
|
|
//barPos.y = goalText.transform.position.y + 10.0f;
|
|
|
|
//Debug.Log(barPos.x + " " + barPos.y);
|
|
|
|
//barPos.x = 0;
|
|
//barPos.y = 0;
|
|
|
|
|
|
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
Debug.Log(goalDayStr);
|
|
Debug.Log("hauaouou");
|
|
|
|
if(prefKey == "daily")
|
|
savePersistantGoalDate("daily");
|
|
}
|
|
|
|
|
|
//Texture the progress bar using these parameters
|
|
public Texture2D emptyTex;
|
|
public Texture2D fullTex;
|
|
|
|
//on a button press? begin a goal?
|
|
void startGoal()
|
|
{
|
|
}
|
|
|
|
void savePersistantGoalDate(string key)
|
|
{
|
|
PlayerPrefs.SetString(key, goalDayStr);
|
|
}
|
|
|
|
bool checkNewDay(string key)
|
|
{
|
|
string checkDay = PlayerPrefs.GetString(key);
|
|
if(checkDay == currentDayStr)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
void OnGUI() {
|
|
//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();
|
|
}
|
|
|
|
void Update() {
|
|
//needs current points counting toward this goal (daily?)
|
|
//needs the total required points for this goal
|
|
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
barDisplay = Time.time*0.05f; //put actual progress here (current/total)
|
|
|
|
//failed to complete goal
|
|
if(currentDayStr != goalDayStr)
|
|
{
|
|
Debug.Log(currentDayStr);
|
|
Debug.Log(goalDayStr);
|
|
|
|
Debug.Log("DAY HAS PASSED!!");
|
|
|
|
//make it so user dismisses the goal instead!
|
|
//Destroy(this);
|
|
//destroy the goal and set a new one?
|
|
|
|
}
|
|
//goal complete
|
|
if(barDisplay >= 1.0f)
|
|
{
|
|
Debug.Log("Goal complete! +100pts!");
|
|
|
|
//destroy the goal and set a new one?
|
|
}
|
|
|
|
//only applies if "daily" goal
|
|
if(prefKey == "daily")
|
|
{
|
|
if(checkNewDay(prefKey))
|
|
{
|
|
Debug.Log("You failed your goal"); //not true if progress is actually complete!
|
|
goalDayStr = currentDayStr;
|
|
savePersistantGoalDate("daily");
|
|
}
|
|
}
|
|
}
|
|
}
|