public void TappedInviteFromList(Tournament t) { // TODO : move tournament Target to this class TacoManager.SetTarget(t); TacoManager.OpenModalWithPreFab(TacoConfig.TacoInviteFriendsModalHeader, TournamentInvitePrefab, TacoConfig.InviteSprite, ModalFunctions.InviteFriends, TacoConfig.CloseSprite, null); if (t.played) { TournamentManager.Instance.ShowTournamentPanel(PanelNames.MyLeaderboardPanel); } else if (t.memberlength == t.size) { Double prize = double.Parse(t.prize.ToString()); string replacedString = TacoConfig.TacoSurePlayModalBody.Replace("&prize", TacoManager.FormatMoney(prize)); TacoManager.OpenModal(TacoConfig.TacoSurePlayModalHeader, replacedString, TacoConfig.PlaySprite, ModalFunctions.StartPlay, TacoConfig.CloseSprite, null); } else { TacoManager.OpenModalWithPreFab(TacoConfig.TacoInviteFriendsModalHeader, TournamentInvitePrefab, TacoConfig.InviteSprite, ModalFunctions.InviteFriends, TacoConfig.CloseSprite, null); TacoModalPanel.Instance.SetModalButtonEnabled(false); TournamentInvite tournamentInvite = TacoModalPanel.Instance.GetPreFab().GetComponent <TournamentInvite> (); } }
public void InviteFriend() { TacoManager.OpenMessage(TacoConfig.TacoSending); Action <string> success = (string data) => { TacoManager.CloseMessage(); }; Action <string, string> fail = (string data, string error) => { TacoConfig.print("Error getting open tournaments : " + data); if (!string.IsNullOrEmpty(error)) { TacoConfig.print("Error : " + error); } }; string fromEmail = TacoManager.User.email; string baseUrl = "baysidegames.com"; GameObject invitePreFab = TacoModalPanel.Instance.GetPreFab(); TournamentInvite _TournamentInvite = invitePreFab.GetComponent <TournamentInvite>(); string emails = _TournamentInvite.GetEmail(); int tournamentId = TacoManager.Target.id; TacoConfig.print("emails : " + emails); StartCoroutine(ApiManager.Instance.InviteFriend(fromEmail, baseUrl, emails, tournamentId, success, fail)); }
private void RemoveDuplidateError() { TournamentInvite nearestDuplidate = NearestDuplicateError(); if (nearestDuplidate != null) { nearestDuplidate.ToggleEmailOkay(true); } }
private void UnFocusEmailList() { TournamentInvite current = next; while (current != null) { current.SetUnfocus(); current = current.next; } current = prev; while (current != null) { current.SetUnfocus(); current = current.prev; } }
private void FocusOnNearestField() { if (isInManage) { EmailStatusHead.sprite = TacoConfig.EmailIconRemove; EmailRemove.onClick.AddListener(() => { EmailStatusHead.sprite = TacoConfig.EmailIconInactive; EmailInput.text = string.Empty; EmailInput.Select(); EmailRemove.onClick.RemoveAllListeners(); }); } else { EmailStatusHead.sprite = TacoConfig.EmailIconActive; } TournamentInvite current = prev; TournamentInvite target = null; while (current != null) { if (string.IsNullOrEmpty(current.EmailInput.text)) { target = current; } current = current.prev; } if (target != null) { target.SetFocus(); return; } current = next; while (current != null) { if (string.IsNullOrEmpty(current.EmailInput.text)) { current.SetFocus(); break; } current = current.next; } }
public void AddRemoveEmailEvent(GameObject ob, RectTransform r, string email, TournamentInvite replaced = null) { if (!invitedEmails.Contains(email)) { invitedEmails.Add(email); } if (replaced != null) { Destroy(replaced.gameObject); inviteEmailTexts.Remove(replaced); } ob.transform.Find("EmailInput/Remove").GetComponent <Button>().onClick.AddListener(() => { Action removeAction = () => { Destroy(ob); GameObject newOb = Instantiate(TacoConfig.InviteInputPrefab, Vector3.zero, Quaternion.identity, emailsPanel) as GameObject; RectTransform newRect = newOb.GetComponent <RectTransform>(); newRect.localPosition = r.localPosition; newRect.sizeDelta = r.sizeDelta; List <TournamentInvite> nearPrevs = inviteEmailTexts.Where(x => x.gameObject.transform.position.y > newOb.transform.position.y).ToList(); List <TournamentInvite> nearNexts = inviteEmailTexts.Where(x => x.gameObject.transform.position.y < newOb.transform.position.y).ToList(); TournamentInvite newInvite = newOb.GetComponent <TournamentInvite>(); invitedEmails.Remove(email); newInvite.reservedEmails = invitedEmails; newInvite.isInManage = true; if (nearPrevs.Count > 0) { TournamentInvite newPrev = nearPrevs.OrderBy(x => Mathf.Abs(x.gameObject.transform.position.y - newOb.transform.position.y)).First(); newInvite.prev = newPrev; newPrev.next = newInvite; } if (nearNexts.Count > 0) { TournamentInvite newNext = nearNexts.OrderBy(x => Mathf.Abs(x.gameObject.transform.position.y - newOb.transform.position.y)).First(); newInvite.next = newNext; newNext.prev = newInvite; } inviteEmailTexts.Add(newInvite); }; TacoManager.OpenModalRemovePlayerConfirmPanel(email, removeAction); }); }
private bool ValidateDuplidateEmail(string emailToCheck) { TournamentInvite current = next; while (current != null) { if (current.GetEmail() == emailToCheck) { return(false); } current = current.next; } current = prev; while (current != null) { if (current.GetEmail() == emailToCheck) { return(false); } current = current.prev; } return(true); }
private TournamentInvite NearestDuplicateError() { TournamentInvite current = prev; while (current != null) { if (current.GetEmail() == previousValidEmailValue) { return(current); } current = current.prev; } current = next; while (current != null) { if (current.GetEmail() == previousValidEmailValue) { return(current); } current = current.next; } return(null); }
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; }
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); } }