Ejemplo n.º 1
0
        private void UpdateUIValue(ManageTournamentResult data)
        {
            tournament = data.tournament;
            List <string> joinedPlayers = new List <string>()
            {
                TacoManager.User.email
            };
            List <string> notJoinedPlayers = new List <string>();

            invitedEmails = new List <string>()
            {
                TacoManager.User.email
            };
            for (int i = 0; i < tournament.friendEmails.Length; i++)
            {
                if (tournament.friendStatuses[i] == "invited")
                {
                    if (!notJoinedPlayers.Contains(tournament.friendEmails[i]))
                    {
                        notJoinedPlayers.Add(tournament.friendEmails[i]);
                    }
                    if (!invitedEmails.Contains(tournament.friendEmails[i]))
                    {
                        invitedEmails.Add(tournament.friendEmails[i]);
                    }
                }
                else if (tournament.friendStatuses[i] == "accepted")
                {
                    if (!joinedPlayers.Contains(tournament.friendEmails[i]))
                    {
                        joinedPlayers.Add(tournament.friendEmails[i]);
                    }
                    if (!invitedEmails.Contains(tournament.friendEmails[i]))
                    {
                        invitedEmails.Add(tournament.friendEmails[i]);
                    }
                }
            }
            string infos = string.Empty;


            for (int i = 0; i < MoneyTypeImages.Count; i++)
            {
                MoneyTypeImages[i].sprite = TacoConfig.currencySprites[tournament.typeCurrency];
            }

            string createdTime = TacoManager.FormatDate(tournament.createdAt);

            infos += TacoConfig.ManageTournamentCreatedOn.Replace("&day", createdTime);
            infos += TacoConfig.LeaderboardResultTournamentID.Replace("&id", tournament.id.ToString());

            if (tournament.typeCurrency == 0)
            {
                prizePoolText.text = TacoManager.FormatCash(tournament.prize);
                entryFeeText.text  = TacoManager.FormatCash(tournament.entryFee);
            }
            else
            {
                prizePoolText.text = TacoManager.FormatGTokens(tournament.prize);
                entryFeeText.text  = TacoManager.FormatGTokens(tournament.entryFee);
            }
            winnerText.text            = TacoConfig.Pluralize(tournament.prize_structure, "Winner");
            playeredJoinedText.text    = tournament.memberIds.Length + "/" + tournament.size + " Players Joined";
            tournamentDetailsText.text = infos;
            countdownTime = (double)Mathf.Max((float)tournament.RemainingTimeSpan.TotalSeconds, -1);
            if (countdownTime < 0)
            {
                remainingTime.text = "00:00:00";
            }

            seeResultButton.interactable = tournament.entryIds.Contains(TacoManager.User.userId);

            //destroy old email fields
            float contentWidth = contentPanel.rect.width;

            for (int i = 1; i < emailsPanel.childCount; i++)
            {
                Destroy(emailsPanel.GetChild(i).gameObject);
            }

            //generate new email fields
            float spacing = 35;
            float width   = (contentPanel.rect.width - spacing);
            float height  = 150;

            inviteEmailTexts = new List <TournamentInvite>();

            for (int i = 0; i < notJoinedPlayers.Count; i++)
            {
                GameObject ob = Instantiate(TacoConfig.NotJoinedPlayerPrefab, Vector3.zero, Quaternion.identity, emailsPanel) as GameObject;
                Text       inviteeEmailText = ob.transform.Find("EmailInput/NameInput").GetComponent <Text>();
                inviteeEmailText.text = notJoinedPlayers[i];
                RectTransform r = ob.GetComponent <RectTransform>();
                r.localPosition = new Vector3(0, height * (-0.5f - i) - spacing);
                r.sizeDelta     = new Vector2(width - spacing * 5, height - spacing);

                ob.transform.Find("EmailInput/Send").GetComponent <Button>().onClick.AddListener(() => {
                    ob.transform.Find("EmailInput/Send").gameObject.SetActive(false);
                    Debug.Log("send reminder");
                    TournamentManager.Instance.InviteFriend(inviteeEmailText.text);
                    if (!invitedEmails.Contains(inviteeEmailText.text))
                    {
                        invitedEmails.Add(inviteeEmailText.text);
                    }
                });

                AddRemoveEmailEvent(ob, r, inviteeEmailText.text);
            }
            float offset = height * (-notJoinedPlayers.Count);


            int newEmailCount = tournament.size - joinedPlayers.Count - notJoinedPlayers.Count;

            for (int i = 0; i < newEmailCount; i++)
            {
                GameObject    ob = Instantiate(TacoConfig.InviteInputPrefab, Vector3.zero, Quaternion.identity, emailsPanel) as GameObject;
                RectTransform r  = ob.GetComponent <RectTransform>();
                r.localPosition = new Vector3(0, height * (-0.5f - i) - spacing + offset);
                r.sizeDelta     = new Vector2(width - spacing * 5, height - spacing);

                TournamentInvite invite = ob.GetComponent <TournamentInvite>();
                invite.reservedEmails = invitedEmails;
                invite.isInManage     = true;
                if (i > 0)
                {
                    inviteEmailTexts[i - 1].next = invite;
                    invite.prev = inviteEmailTexts[i - 1];
                    invite.SetInteractable(false);
                }

                if (i == 0)
                {
                    invite.SetFocus();
                }

                inviteEmailTexts.Add(invite);
            }
            //fix if invite more people than tournament size
            offset = height * (-0.5f - Mathf.Max((notJoinedPlayers.Count + newEmailCount), notJoinedPlayers.Count));
            Vector3 linePos = new Vector3(0, offset);

            //joined players
            for (int i = 0; i < joinedPlayers.Count; i++)
            {
                GameObject ob = Instantiate(joinedPlayerPrefab, Vector3.zero, Quaternion.identity, emailsPanel) as GameObject;
                ob.transform.Find("EmailInput/NameInput").GetComponent <Text>().text = joinedPlayers[i];
                RectTransform r = ob.GetComponent <RectTransform>();
                r.localPosition = new Vector3(0, height * (-1.5f - i) - spacing + offset);
                r.sizeDelta     = new Vector2(width - spacing * 5, height - spacing);
            }
            contentPanel.sizeDelta     = new Vector2(contentPanel.sizeDelta.x, Mathf.Max(5 * height, (int)(Mathf.Max(tournament.size, notJoinedPlayers.Count + joinedPlayers.Count) + 4.5f) * height + spacing));
            contentPanel.localPosition = new Vector3(contentPanel.localPosition.x, 0);
            line.localPosition         = linePos;
        }
Ejemplo n.º 2
0
        public void ValidateUserOrEmail(string emailToCheck)
        {
            if (string.IsNullOrEmpty(emailToCheck))
            {
                if (next != null && string.IsNullOrEmpty(next.EmailInput.text) && next.IsInteractable())
                {
                    next.SetInteractable(false);
                }
                return;
            }

            if (next != null && !next.IsInteractable())
            {
                next.SetInteractable(true);
            }

            if (!TacoManager.ValidateEmail(emailToCheck))
            {
                ToggleEmailOkay(false);
                RemoveDuplidateError();
                errorMessage.text = TacoConfig.EnterInvalidEmailError;
                return;
            }

            if (reservedEmails.Contains(GetEmail()))
            {
                ToggleEmailOkay(false);
                RemoveDuplidateError();
                errorMessage.text = TacoConfig.EnterExistingEmailError;
                return;
            }

            Action <string> success = (string data) => {
                GameFeaturedResult r = JsonUtility.FromJson <GameFeaturedResult>(data);

                if (r.success)
                {
                    if (data.Contains("true"))
                    {
                        if (!ValidateDuplidateEmail(emailToCheck))
                        {
                            ToggleEmailOkay(false);
                            errorMessage.text = TacoConfig.EnterExistingEmailError;
                        }
                        else
                        {
                            ToggleEmailOkay(true);
                        }
                        RemoveDuplidateError();
                        previousValidEmailValue = emailToCheck;
                    }
                }
                else
                {
                    ToggleEmailOkay(false);
                    RemoveDuplidateError();

                    errorMessage.text = TacoConfig.NotInSystemEmailError;
                }
            };

            Action <string, string> fail = (string errorData, string error) => {
                Debug.Log("Error on get : " + errorData);
                if (!string.IsNullOrEmpty(error))
                {
                    Debug.Log("Error : " + error);
                }
                TacoManager.CloseMessage();
                //string msg = errorData + (string.IsNullOrEmpty (error) ? "" : " : " + error);
                TacoManager.OpenModalLoginFailedPanel(TacoConfig.TacoLoginErrorEmailPassword);
                //TacoManager.OpenModal (TacoConfig.TacoLoginErrorHeader, TacoConfig.TacoLoginErrorMessage01);
            };


            string url = "api/user/verify?u=" + emailToCheck;

            StartCoroutine(ApiManager.Instance.GetWithToken(url, success, fail));
        }
Ejemplo n.º 3
0
        private void ShowInviteFriendPanelForCreateTournament()
        {
            bool status = !creatingTournament.IsPublic;

            if (inviteEmailTexts.Count > 0)
            {
                List <TournamentInvite> temp = inviteEmailTexts.Where(x => !string.IsNullOrEmpty(x.EmailInput.text)).ToList();
                creatingTournament.invitedEmails = temp.Select(x => x.EmailInput.text).ToArray();
                cachedEmailValidate  = temp.Select(x => x.IsValid()).ToList();
                cachedEmailErrorMsg  = temp.Select(x => x.errorMessage.text).ToList();
                cachedPrevValidEmail = temp.Select(x => x.previousValidEmailValue).ToList();
            }
            for (int i = 1; i < createTournamentInviteFriend.transform.childCount; i++)
            {
                Destroy(createTournamentInviteFriend.transform.GetChild(i).gameObject);
            }

            createTournamentInviteFriend.SetActive(status);

            // switch to top stretch to handle scroll when expanding the content
            // (default value is stretch stretch so unity will auto-scale for different resolutions
            RectTransform panelWrapperRect  = createTournamentDropDownList.transform.parent.GetComponent <RectTransform> ();
            RectTransform scrollContentRect = createTournamentDropDownList.transform.parent.parent.GetComponent <RectTransform> ();

            float wrapperHeight = panelWrapperRect.rect.height;

            panelWrapperRect.anchorMin = new Vector2(0, 1);
            panelWrapperRect.sizeDelta = new Vector2(panelWrapperRect.sizeDelta.x, wrapperHeight);

            scrollContentRect.anchorMin = new Vector2(0, 1);

            if (status)
            {
                RectTransform contentPanel = createTournamentInviteFriend.GetComponent <RectTransform> ();
                float         spacing      = 35;
                float         width        = (contentPanel.rect.width - spacing);
                float         pWidth       = contentPanel.parent.GetComponent <RectTransform> ().rect.width - spacing;
                if (contentPanel.rect.width < pWidth - spacing)// check contentPanel has correct width
                {
                    width = pWidth;
                }
                float height            = 150;
                float requirementHeight = 200;
                int   field             = creatingTournament.size;
                inviteEmailTexts = new List <TournamentInvite> ();

                for (int i = 0; i < field; i++)
                {
                    GameObject    ob = Instantiate(TacoConfig.InviteInputPrefab, Vector3.zero, Quaternion.identity, createTournamentInviteFriend.transform) as GameObject;
                    RectTransform r  = ob.GetComponent <RectTransform> ();
                    if (contentPanel.rect.width < pWidth - spacing)
                    {
                        r.localPosition = new Vector3(spacing, height * (-0.5f - i) - requirementHeight);
                    }
                    else
                    {
                        r.localPosition = new Vector3(spacing, height * (-0.5f - i) - requirementHeight);
                    }

                    r.sizeDelta = new Vector2(width - spacing * 3, height - spacing);
                    TournamentInvite invite = ob.GetComponent <TournamentInvite> ();

                    if (i > creatingTournament.invitedEmails.Length)
                    {
                        invite.SetInteractable(false);
                    }

                    if (i > 0)
                    {
                        inviteEmailTexts [i - 1].next = invite;
                        invite.prev = inviteEmailTexts [i - 1];
                    }

                    if (i < creatingTournament.invitedEmails.Length && !string.IsNullOrEmpty(creatingTournament.invitedEmails [i]))
                    {
                        invite.FillWithValidateData(creatingTournament.invitedEmails [i], cachedEmailValidate [i], cachedEmailErrorMsg [i], cachedPrevValidEmail [i]);
                    }

                    if (i == 0 && creatingTournament.invitedEmails.Length == 0)
                    {
                        invite.SetFocus();
                    }
                    else if (i > 0 && string.IsNullOrEmpty(invite.EmailInput.text) && !string.IsNullOrEmpty(inviteEmailTexts [i - 1].EmailInput.text))
                    {
                        invite.SetFocus();
                    }

                    inviteEmailTexts.Add(invite);
                }
                float extendedHeight = field * height + spacing + requirementHeight;
                contentPanel.sizeDelta      = new Vector2(contentPanel.sizeDelta.x, extendedHeight);
                scrollContentRect.sizeDelta = new Vector2(scrollContentRect.sizeDelta.x, wrapperHeight + extendedHeight + spacing * 2);
            }
            else
            {
                scrollContentRect.sizeDelta = new Vector2(scrollContentRect.sizeDelta.x, wrapperHeight);
            }
        }