using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;

public class TM_TestDreamloBoards : MonoBehaviour
{
    public TM_LeaderboardManager_Dreamlo theLeaderboards;
    private IList<TM_LeaderboardEntry> currentEntries;

    private string strID = "";
    private string strScore = "";

    private string strRangeAbove = "";
    private string strRangeBelow = "";

	// Use this for initialization
	void Start ()
	{
		
	}
	
	// Update is called once per frame
	void Update ()
	{
	    if (theLeaderboards.GetDataState() == ELeaderboardDataState.ready)
	    {
	        currentEntries = theLeaderboards.GetLoadedLeaderboardEntries();
	    }
	}

    void OnGUI()
    {
        GUI.Label(new Rect(8,8,256,32),  "State: " + theLeaderboards.GetDataState().ToString());
        strID = GUI.TextField( new Rect(140, 40, 200, 20),strID);

        if (GUI.Button(new Rect(8, 40, 120, 20), "Init"))
        {
            theLeaderboards.Initialize(strID);
        }

        strScore = GUI.TextField( new Rect(490, 40, 200, 20),strScore);

        if (GUI.Button(new Rect(362, 40, 120, 20), "Send Score"))
        {
            theLeaderboards.SendNewEntry(Int32.Parse(strScore));
        }

        if (GUI.Button(new Rect(8, 70, 120, 20), "Get All"))
        {
            theLeaderboards.RequestLeaderboardEntries(1,100);
        }

        strRangeAbove = GUI.TextField( new Rect(300, 70, 32, 20),strRangeAbove);
        strRangeBelow = GUI.TextField( new Rect(340, 70, 32, 20),strRangeBelow);


        if (GUI.Button(new Rect(140, 70, 120, 20), "Around Player"))
        {
            theLeaderboards.RequestLeaderboardEntriesNearPlayer(Int32.Parse(strRangeAbove), Int32.Parse(strRangeBelow));
        }

        if (currentEntries != null && theLeaderboards.GetDataState() == ELeaderboardDataState.ready)
        {
            Rect rectLabel = new Rect(8, 110, 800, 30);
            for (int t = 0; t < currentEntries.Count; t++)
            {
                TM_LeaderboardEntry le = currentEntries[t];
                GUI.Label( rectLabel, le.iRank.ToString() + ")" + le.strName + " " + le.iScore);
                rectLabel.y += 30;
            }
        }

    }
}
