private void AddEventToButton(LeaderboardDetail item, Button objButton, Button favButton, Button shareButton)
    {
        objButton.onClick.AddListener(() =>
        {
            MenuSoundManager.Instance.PlayMenuClick();
            UIStateManager.Manager.SwapToKeyValidationPage(null, null, item, KeyValiationStatesBack.FromFav);
        });

        favButton.onClick.AddListener(() =>
        {
            MenuSoundManager.Instance.PlayMenuClick();
            UIStateManager.Manager.SettingsSystem.RemoveFromFav(UIStateManager.Manager.PlayerId, item.Id);
            GameObject.DestroyImmediate(objButton.gameObject);
            GameObject.DestroyImmediate(favButton.gameObject);
            GameObject.DestroyImmediate(shareButton.gameObject);

            StartCoroutine(RefreshPanelSize());

            if (ListerPanel_Leaderboards.transform.childCount <= 0)
            {
                Message.SetActive(true);
            }
        });

        shareButton.onClick.AddListener(() =>
        {
            MenuSoundManager.Instance.PlayMenuClick();
            Debug.Log("Implement your share mechanism here");
        });
    }
    private void AddEventToButton(LeaderboardDetail item, Button objButton, Toggle favToggle, Button shareButton)
    {
        objButton.onClick.AddListener(() =>
        {
            MenuSoundManager.Instance.PlayMenuClick();
            UIStateManager.Manager.SwapToKeyValidationPage(null, null, item, KeyValiationStatesBack.MyTournaments);
        });

        favToggle.onValueChanged.AddListener((isOn) =>
        {
            MenuSoundManager.Instance.PlayMenuClick();
            if (isOn)
            {
                UIStateManager.Manager.SettingsSystem.AddToLeaderboardCache(UIStateManager.Manager.PlayerId, item, "", true);
            }
            else
            {
                UIStateManager.Manager.SettingsSystem.RemoveFromFav(UIStateManager.Manager.PlayerId, item.Id);
            }
        });

        shareButton.onClick.AddListener(() =>
        {
            MenuSoundManager.Instance.PlayMenuClick();
            Debug.Log("Implement your share mechanism here");
        });
    }
 void OnGetLeaderboardDetails(string errorString, LeaderboardDetail[] result, params object[] userParam)
 {
     if (result != null && result.Length > 0 && result[0].Active)
     {
         StartCoroutine(UIStateManager.GameAPI.GetGameLevelDetails(result[0].ParentLevelId, OnGetGameLevelDetail, result));
         StartCoroutine(UIStateManager.GameAPI.MakeLeaderboardLive(
             leaderBoardId: result[0].Id,
             onMakeLeaderboardLive: onMakeLeaderboardLive));
     }
     else
     {
         Message.text = "Please enter a valid tournament ID";
     }
     UIStateManager.Manager.SetLoading(false);
 }
    void AddLeaderboardEntry(LeaderboardDetail leaderboardDetail)
    {
        GameObject obj = GameObject.Instantiate(UIStateManager.Manager.ListItemTemplate_LeaderboardTiles);
        GameObject obj_2 = GameObject.Instantiate(UIStateManager.Manager.ListItemSelectionTemplate);
        GameObject obj_3 = GameObject.Instantiate(UIStateManager.Manager.ListItemSelectionTemplate);
        obj.transform.SetParent(ListerPanel_Leaderboards.transform, false);
        obj.GetComponentInChildren<Text>().fontSize = ButtonFontSize;
        obj_2.transform.SetParent(ListerPanel_Remove.transform, false);
        obj_3.transform.SetParent(ListerPanel_Share.transform, false);
        obj.name = leaderboardDetail.Id;

        Button objButton = obj.GetComponent<Button>();
        UIStateManager.Manager.SetLeaderboardName(leaderboardDetail, objButton);

        Button favButton = obj_2.GetComponent<Button>();
        Image favSprite = favButton.GetComponentInChildren<Image>();
        favSprite.sprite = UIStateManager.Manager.RemoveTexture;
        Button shareButton = obj_3.GetComponent<Button>();
        shareButton.GetComponent<Image>().sprite = UIStateManager.Manager.ShareTexture;
        AddEventToButton(leaderboardDetail, objButton, favButton, shareButton);
    }
 void SetHighScoreOffline(LeaderboardDetail detail)
 {
     ToggleConnectionMode.sprite = OfflineModeSprite;
     BestScoreText.text = UIStateManager.Manager.ScoreHistorySystem.GetHighScore(UIStateManager.Manager.PlayerId, detail).ToString();
 }
    //public static void SetBanner(RawImage banner)
    //{
    //    if (UIStateManager.Manager.CurrentGamePlayMode)
    //    {
    //        UIStateManager.Manager.StartCoroutine
    //        (
    //            UIStateManager.GameAPI.GetBannerDetails
    //            (
    //                UIStateManager.Manager.PlayerId,
    //                UIStateManager.Manager.CurrentLeaderboardDetail.Id,
    //                LeaderboardListScript.OnGetBannerDetails,
    //                banner
    //            )
    //        );
    //    }
    //}
    public static void SetBanner(RawImage banner, LeaderboardDetail detail)
    {
        if (UIStateManager.Manager.CurrentGamePlayMode)
        {
            if (UIStateManager.Manager.CurrentLeaderboardDetail.IsSponsored)
            {
                string BannerFilePath;
                string BannerUrlSaveName;
                BannerUrlSaveName = detail.Id + "_Banner";
                BannerFilePath = Path.Combine(Application.persistentDataPath, detail.Id + "_Banner.png");
                byte[] dataToLoad;
                if (File.Exists(BannerFilePath))
                {
                    dataToLoad = File.ReadAllBytes(BannerFilePath);
                    BannerTexture = new Texture2D(320, 50);
                    BannerTexture.LoadImage(dataToLoad);
                    banner.texture = BannerTexture;
                }

                if (PlayerPrefs.HasKey(BannerUrlSaveName))
                {
                    BannerClickURL = PlayerPrefs.GetString(BannerUrlSaveName);
                }

                if (banner.gameObject != null && BannerTexture != null)
                {
                    banner.gameObject.SetActive(true);
                }
                else
                {
                    banner.gameObject.SetActive(false);
                }

                Button button = banner.gameObject.GetComponent<Button>();
                button.onClick.RemoveAllListeners();

                if (!string.IsNullOrEmpty(BannerClickURL))
                {
                    button.onClick.AddListener(() =>
                    {
                        Application.OpenURL(BannerClickURL);
                    });
                }
            }
        }
    }
 IEnumerator SetInterstitial(LeaderboardDetail leaderboardDetail)
 {
     yield return null;
     UIStateManager.Manager.StartCoroutine
     (
         UIStateManager.GameAPI.GetBannerDetails
         (
             UIStateManager.Manager.PlayerId,
             leaderboardDetail.Id,
             OnGetBannerDetails
         )
     );
 }
    void OnGetGameLevelDetail(string errorString, GameLevelDetail result, params object[] userParam)
    {
        if (result != null && result.Active)
        {
            LeaderboardDetail leaderboardDetail = userParam[0] as LeaderboardDetail;
            LeaderboardDetail = leaderboardDetail;

            string key = KeyField.text.Trim();
            entryKey = key;
            string BannerFilePath = Path.Combine(Application.persistentDataPath, leaderboardDetail.Id + "_Banner.png");
            filePath = BannerFilePath;

            if (File.Exists(BannerFilePath))
            {
                UIStateManager.Manager.SwapToGame(LeaderboardDetail, true, entryKey);
            }

            if (leaderboardDetail.IsSponsored)
            {
                StartCoroutine(SetInterstitial(leaderboardDetail));
            }
        }
        else
        {
            Message.text = "Invalid key entered!";
        }
    }
 void OnGetLeaderboardsDetail(string errorString, LeaderboardDetail[] result, params object[] userParam)
 {
     if (result != null && result.Length > 0 && result[0].Active)
     {
         StartCoroutine (UIStateManager.GameAPI.GetGameLevelDetails (result[0].ParentLevelId, OnGetGameLevelDetail, result));
     }
     UIStateManager.Manager.SetLoading (false);
 }
 public void SwapToKeyValidationPage(
 GameLevelDetail grandParentLevelDetail,
 GameLevelDetail parentLevelDetail,
 LeaderboardDetail leaderboardDetail,
 KeyValiationStatesBack backType)
 {
     KeyValidationScript.BackType = backType;
     KeyValidationScript.GrandParentLevelDetail = grandParentLevelDetail;
     KeyValidationScript.ParentLevelDetail = parentLevelDetail;
     KeyValidationScript.LeaderboardDetail = leaderboardDetail;
     SwapToPage(KeyValidationPage);
 }
    public void SwapToGame(LeaderboardDetail leaderboardDetail, bool isGamePlayMode, string activationKey)
    {
        this.CurrentLeaderboardDetail = leaderboardDetail;
        this.CurrentGamePlayMode = isGamePlayMode;
        this.CurrentActivationKey = activationKey;
        string playName = string.Empty;
        if (leaderboardDetail != null)
        {
            SplitExtras(leaderboardDetail.Extras);
        }
        CancelInvoke("ProcessScoreQue");
        GameLoaded = true;
        if (!string.IsNullOrEmpty(playName))
        {
            Application.LoadLevel(playName);
            ShowLoadingPanel();
        }
        else
        {
            Application.LoadLevel(GamePlaySceneName);
            ShowLoadingPanel();

        }
    }
    public double GetHighScore(string userId, LeaderboardDetail detail)
    {
        double score = 0;

        foreach (ScoreHistoryItem item in Items)
        {
            if (userId == item.UserId && item.LeaderboardId == detail.Id)
            {
                if (score < item.Score)
                {
                    score = item.Score;
                }
            }
        }

        return score;
    }
    public void SetLeaderboardName(LeaderboardDetail item, Button objButton)
    {
        DateTime localTime = GetLeaderboardValidity(item, item.LifeTime / 60);
        Text objText = objButton.GetComponentInChildren<Text>();
        GameObject sponsoredFlag = objButton.transform.FindChild("Image").gameObject;
        objText.text = string.Format("{0}\nJoining Point: {1}, Reward Points: {2}\nValid till: {3}",
                 item.Name,
                 item.JoiningPoint,
                 item.TotalRewardPoints > 0 ? string.Format("{0}+", item.TotalRewardPoints.ToString()) : "0",
                 localTime);

        if (item.IsSponsored)
        {
            sponsoredFlag.SetActive(true);
            sponsoredFlag.GetComponent<Image>().sprite = SponsoredIcon;
        }
        else if (item.InviteOnly)
        {
            sponsoredFlag.SetActive(true);
            sponsoredFlag.GetComponent<Image>().sprite = UserTournamentIcon;
        }
        else
        {
            sponsoredFlag.SetActive(false);
        }

        //objText.text += string.Format("\nValid upto : {0}", localTime);
    }
 public bool isLeaderboardExpired(LeaderboardDetail item)
 {
     DateTime leaderboardExpiration = DateTime.Parse(item.LiveTime).AddMinutes((item.LifeTime / 60));
     DateTime localTime = TimeZone.CurrentTimeZone.ToLocalTime(leaderboardExpiration);
     return localTime <= DateTime.Now;
 }
 public List<ScoreHistoryItem> GetEntries(string userId, LeaderboardDetail detail)
 {
     List<ScoreHistoryItem> historyList = new List<ScoreHistoryItem>();
     foreach (ScoreHistoryItem item in Items)
     {
         if (userId == item.UserId && item.LeaderboardId == detail.Id)
         {
             historyList.Add(item);
         }
     }
     return historyList;
 }
 public DateTime GetLeaderboardValidity(LeaderboardDetail item, double lifeTime)
 {
     DateTime leaderboardExpiration = DateTime.Parse(item.LiveTime).AddMinutes(lifeTime);
     DateTime localTime = TimeZone.CurrentTimeZone.ToLocalTime(leaderboardExpiration);
     return localTime;
 }
 public List<ScoreHistoryItem> GetUserScoreHistory(LeaderboardDetail detail)
 {
     return ScoreHistorySystem.GetEntries(PlayerId, detail);
 }
 public void SwapToLeaderboardListPage(LeaderboardDetail leaderboardDetail, double score, string activationKey)
 {
     if (score == -1)
     {
         ShowScore = false;
         StartCoroutine(GameAPI.IsActivePlayer(PlayerId, OnAuthenticationDuringLeaderboardList, leaderboardDetail, score));
     }
     else
     {
         ShowScore = true;
         StartCoroutine(GameAPI.UpdatePlayerScore(
             userName: PlayerId,
             participationKey: activationKey,
             leaderBoardId: leaderboardDetail.Id,
             score: score,
             updateIfBetterThanPrevious: true,
             onUpdatePlayerScoreFn: OnUpdateScore));
         ScoreHistorySystem.AddEntry(PlayerId, score, leaderboardDetail.Id, DateTime.Now.ToString());
     }
 }
    void onCreateLeaderboard(string errorString, string result, params object[] userParam)
    {
        if (string.IsNullOrEmpty(errorString) && result != null)
        {
            LeaderboardDetail leaderboardDetail = new LeaderboardDetail();
            leaderboardDetail.Id = result;
            UIStateManager.Manager.SettingsSystem.AddToLeaderboardCache(UIStateManager.Manager.PlayerId, leaderboardDetail, "", true);
            UIStateManager.Manager.SwapToPostCreateLeaderboardPage(leaderboardDetail, CurrentLevel);
            StartCoroutine(UIStateManager.GameAPI.MakeLeaderboardLive(
                leaderBoardId: result,
                onMakeLeaderboardLive: onMakeLeaderboardLive));
        }

        UIStateManager.Manager.SetLoading(false);
    }
 public void SwapToPostCreateLeaderboardPage(LeaderboardDetail leaderboardDetail, GameLevelDetail levelDetail)
 {
     PostCreateLeaderboardScript.LeaderboardDetail = leaderboardDetail;
     PostCreateLeaderboardScript.LevelDetail = levelDetail;
     SwapToPage(PostCreateLeaderboardPage);
 }
 void OnGetLeaderboardDetail(string errorString, LeaderboardDetail result, params object[] userParam)
 {
     if (result != null && result.Active)
     {
         StartCoroutine(UIStateManager.GameAPI.GetGameLevelDetails(result.ParentLevelId, OnGetGameLevelDetail, result));
     }
     else
     {
         Message.text = "Invalid key entered!";
     }
 }
 void OnGetLeaderboardDetail(string errorString, LeaderboardDetail result, params object[] userParam)
 {
     ScoreHistoryItem item = userParam[0] as ScoreHistoryItem;
     if (string.IsNullOrEmpty(errorString))
     {
         if (result != null && result.Active)
         {
             Items.Add(item);
             Save();
         }
     }
     else
     {
         Items.Add(item);
         Save();
     }
 }
    public LeaderboardStorage AddToLeaderboardCache(string playerId, LeaderboardDetail detail, string accessKey, bool fav)
    {
        LeaderboardStorage item = GetLeaderboardCache(playerId, detail.Id);
        if (item != null)
        {
            if (fav)
            {
                FavStorageSystem.Remove(item);
            }
            else
            {
                LeaderboardStorageSystem.Remove(item);
            }

        }
        item = new LeaderboardStorage();
        item.Leaderboard = detail;
        item.PlayerId = playerId;
        item.AccessKey = accessKey;
        if (fav)
        {
            FavStorageSystem.Add(item);
        }
        else
        {
            LeaderboardStorageSystem.Add(item);
        }
        Save();
        return item;
    }
 public void AddToProcessQue(LeaderboardDetail detail, string accessKey, double score)
 {
     if (detail.Active)
     {
         PlayerScoreStorage store = new PlayerScoreStorage();
         store.Leaderboard = detail;
         store.PlayerId = UIStateManager.Manager.PlayerId;
         store.AccessKey = accessKey;
         store.Score = score;
         PlayerScoreStorageSystem.Add(store);
         Save();
     }
 }
    private void Refresh(bool leaderBaordOn)
    {
        for (int i = 0, childCount = LeaderBoardNameLister.transform.childCount; i < childCount; i++)
        {
            GameObject.Destroy(LeaderBoardNameLister.transform.GetChild(i).gameObject);
        }

        for (int i = 0, childCount = LeaderBoardScoreLister.transform.childCount; i < childCount; i++)
        {
            GameObject.Destroy(LeaderBoardScoreLister.transform.GetChild(i).gameObject);
        }

        ForwardButton.interactable = false;
        BackwardButton.interactable = false;
        CurrentScoreText.text = Score.ToString();

        LeaderboardListScript.SetBanner(BannerArea, LeaderboardDetail);

        UIStateManager.Manager.SettingsSystem.AddToLeaderboardCache(
            UIStateManager.Manager.PlayerId,
            UIStateManager.Manager.CurrentLeaderboardDetail,
            UIStateManager.Manager.CurrentActivationKey,
            false);

        LeaderboardStorage storage = UIStateManager.Manager.SettingsSystem.GetLeaderboardCache(UIStateManager.Manager.PlayerId, LeaderboardListScript.LeaderboardDetail.Id);
        if (storage != null)
        {
            LeaderboardListScript.LeaderboardDetail = storage.Leaderboard;
            WinningPlayers.text = "Top " + LeaderboardDetail.TopWinnersCount.ToString();
            RewardPoints.text = LeaderboardDetail.TotalRewardPoints.ToString() + "+";
        }

        if (leaderBaordOn)
        {
            UIStateManager.Manager.SetLoading(true);
            StartCoroutine
            (
                UIStateManager.GameAPI.GetLeaderboardCurrentStatus
                (
                    LeaderboardDetail.Id,
                    ((ItemPerPages * m_PageNo) - ItemPerPages) + 1,
                    (ItemPerPages * m_PageNo) + 1,
                    OnGetLeaderboardStatus,
                    LeaderboardDetail)
            );
        }
        else
        {
            StartCoroutine(PropagateScoreBoard());
        }
    }
    void OnGetLeaderboardDetail(string errorString, LeaderboardDetail result, params object[] userParam)
    {
        bool isFav = (bool)userParam[1];

        LeaderboardStorage item = userParam[0] as LeaderboardStorage;
        if (string.IsNullOrEmpty(errorString))
        {
            if (result != null)
            {
                item.Leaderboard = result;
                UIStateManager.Manager.StartCoroutine(UIStateManager.GameAPI.GetCurrentTime(
                    OnGetServerTime,
                    isFav,
                    item));
            }
        }
        else
        {
            if (isFav)
            {
                FavStorageSystem.Add(item);
            }
            else
            {
                LeaderboardStorageSystem.Add(item);
            }
            Save();
        }
    }
Example #27
0
    LeaderboardDetail ToLeaderboardDetail(XmlNode node, ref string errorString)
    {
        try
        {
            LeaderboardDetail board = null;
            if (node != null && !string.IsNullOrEmpty(node.InnerXml))
            {
                board = new LeaderboardDetail();
                board.Id = node["Id"].InnerText;
                board.Name = node["Name"].InnerText;
                board.Comment = node["Comment"].InnerText;
                board.Country = node["Country"].InnerText;
                board.Region = node["Region"].InnerText;
                board.City = node["City"].InnerText;
                board.GameId = node["GameId"].InnerText;
                board.ParentLevelId = node["ParentLevelId"].InnerText;
                board.ClosedTime = node["ClosedTime"].InnerText;
                board.CreatedTime = node["CreatedTime"].InnerText;
                board.LiveTime = node["LiveTime"].InnerText;
                bool boolVal = false;
                if (bool.TryParse(node["Active"].InnerText, out boolVal))
                {
                    board.Active = boolVal;
                }

                if (bool.TryParse(node["Live"].InnerText, out boolVal))
                {
                    board.Live = boolVal;
                }

                long longVal = -1;
                if (long.TryParse(node["JoiningPoint"].InnerText, out longVal))
                {
                    board.JoiningPoint = longVal;
                }

                if (bool.TryParse(node["IsPlayerParticipated"].InnerText, out boolVal))
                {
                    board.IsPlayerParticipated = boolVal;
                }

                if (bool.TryParse(node["IsFreePlayerWillBeAwarded"].InnerText, out boolVal))
                {
                    board.IsFreePlayerWillBeAwarded = boolVal;
                }

                if (long.TryParse(node["PlayerCountLimit"].InnerText, out longVal))
                {
                    board.PlayerCountLimit = longVal;
                }

                if (long.TryParse(node["CurrentPlayerCount"].InnerText, out longVal))
                {
                    board.CurrentPlayerCount = longVal;
                }
                board.RestrictByDateOfBirthStart = node["RestrictByDateOfBirthStart"].InnerText;
                board.RestrictByDateOfBirthEnd = node["RestrictByDateOfBirthEnd"].InnerText;
                if (bool.TryParse(node["UseRestrictByDateOfBirthStart"].InnerText, out boolVal))
                {
                    board.UseRestrictByDateOfBirthStart = boolVal;
                }
                if (bool.TryParse(node["UseRestrictByDateOfBirthEnd"].InnerText, out boolVal))
                {
                    board.UseRestrictByDateOfBirthEnd = boolVal;
                }
                board.Reference = node["Reference"].InnerText;
                int intVal = -1;
                if (int.TryParse(node["Gender"].InnerText, out intVal))
                {
                    board.Gender = intVal;
                }
                List<string> availableOnlyToPlayerUserNames = new List<string>();
                XmlNodeList playerNodes = node["AvailableOnlyToPlayerUserNames"].ChildNodes;
                foreach (XmlNode playerNode in playerNodes)
                {
                    availableOnlyToPlayerUserNames.Add(playerNode.InnerText);
                }

                board.AvailableOnlyToPlayerUserNames = availableOnlyToPlayerUserNames.ToArray();
                board.CurrentTime = node["CurrentTime"].InnerText;

                long rewardPoints = -1;
                if (long.TryParse(node["TotalRewardPoints"].InnerText, out rewardPoints))
                {
                    board.TotalRewardPoints = rewardPoints;
                }

                if (bool.TryParse(node["IsSponsored"].InnerText, out boolVal))
                {
                    board.IsSponsored = boolVal;
                }
                board.Extras = node["Extras"].InnerText;

                long topWinnersCount = 0;
                if (long.TryParse(node["TopWinnersCount"].InnerText, out topWinnersCount))
                {
                    board.TopWinnersCount = topWinnersCount;
                }
                board.Tag = node["Tag"].InnerText;
                board.AdminName = node["AdminName"].InnerText;

                long lifetime = 0;
                board.LifeTime = lifetime;
                board.UseAutoClose = false;
                boolVal = false;
                if (bool.TryParse(node["UseAutoClose"].InnerText, out boolVal))
                {
                    board.UseAutoClose = boolVal;
                }
                if (long.TryParse(node["LifeTime"].InnerText, out lifetime))
                {
                    board.LifeTime = lifetime;
                }
                if (bool.TryParse(node["InviteOnly"].InnerText, out boolVal))
                {
                    board.InviteOnly = boolVal;
                }

                return board;
            }
        }
        catch (Exception ex)
        {
            errorString = ex.Message;
        }
        return null;
    }
 public string GetLeaderboardData(GameLevelDetail detail, LeaderboardDetail leaderboardDetail)
 {
     if (!string.IsNullOrEmpty(leaderboardDetail.Extras))
     {
         return SplitExtras(leaderboardDetail.Extras);
     }
     return SplitExtras(detail.Extras);
 }
 void GetHighScoreOffline(LeaderboardDetail detail)
 {
     BestScore = UIStateManager.Manager.ScoreHistorySystem.GetHighScore(UIStateManager.Manager.PlayerId, detail).ToString();
 }
 private void AddEventToToggle(LeaderboardDetail item, Toggle favToggle)
 {
     favToggle.onValueChanged.AddListener((isOn) =>
     {
         MenuSoundManager.Instance.PlayMenuClick();
         if (isOn)
         {
             UIStateManager.Manager.SettingsSystem.AddToLeaderboardCache(UIStateManager.Manager.PlayerId, item, "", true);
         }
         else
         {
             UIStateManager.Manager.SettingsSystem.RemoveFromFav(UIStateManager.Manager.PlayerId, item.Id);
         }
     });
 }