Exemple #1
0
        public void LoadInformation(Tournament t)
        {
            TacoManager.OpenMessage(TacoConfig.TacoRefreshing);

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

                TacoManager.CloseMessage();
            };

            Action <string, string> fail = (string data, string error) => {
                TacoManager.OpenModalGeneralResultPanel(false, TacoConfig.Error, TacoConfig.TacoTournamentError);
            };

            var url = "api/tournament/getTourById";

            StartCoroutine(ApiManager.Instance.GetManageTournament(url, t.id, success, fail));
        }
Exemple #2
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;
        }