using UnityEngine;
using System.Collections;
using Holoville.HOTween;

public class ScoreViewer : MonoBehaviour
{
		UILabel scoreLabel;
		UITweener scoreTweener;	
		int _scoreLabelDisplay;
	
		
		// Use this for initialization
		void Start ()
		{
				scoreLabel = this.GetComponent<UILabel> ();
				scoreTweener = this.GetComponent<UITweener> ();
				ScoreHandler.onUpdate += HandleonUpdate;
		}

		void HandleonUpdate (int score)
		{
				HOTween.To (this, 1, new TweenParms ()
		            .Prop ("scoreLabelDisplay", score)
		            .OnComplete (OnScoreTweenComplete));
				
				if (scoreTweener != null) {    
						scoreTweener.style = UITweener.Style.PingPong;
						scoreTweener.PlayForward ();
				}
		}
		
		void OnScoreTweenComplete ()
		{
				if (scoreTweener != null) { 
						scoreTweener.style = UITweener.Style.Once;
						scoreTweener.PlayReverse ();
				}
		}
	
		public int scoreLabelDisplay {
				get {
						return _scoreLabelDisplay;
				}
		
				set {
						_scoreLabelDisplay = value;
						scoreLabel.text = _scoreLabelDisplay.ToString ();
				}
		}
	
}
