public void SetupFantasySlots()
 {
     foreach (var player in FantasyManager.Instance.FantasyPlayersList)
     {
         FantasyPlayersSlot playerSlot = Instantiate(FantasySlotPrefab) as FantasyPlayersSlot;
         if (playerSlot != null)
         {
             playerSlot.Configure(player.Name, player.Salary, player.Team, player.Points);
             playerSlot.transform.SetParent(SlotsContentParent);
             playerSlot.transform.localScale    = Vector3.one;
             playerSlot.transform.localPosition = Vector3.zero;
             playerSlot.transform.localRotation = Quaternion.identity;
         }
     }
 }
Exemple #2
0
    public override void Initialize(object[] optionalParams)
    {
        base.Initialize(optionalParams);


        if (optionalParams == null)
        {
            Logging.LogError("Tried to initialize LineupView with optional params but the array was null!");
            return;
        }

        // Try to get a contest from the optional parameters (should never be null)
        contest = (ContestInfo)optionalParams[0];

        if (contest != null)
        {
            ContestName.text = contest.contestTitle;

            int i = 0;

            // Configure the player choices (on the lineup popup) based on the teams in the contest and hte players on those teams
            foreach (var team in contest.Teams)
            {
                foreach (var player in team.Players)
                {
                    FantasyPlayerChoices[i].gameObject.SetActive(true);

                    FantasyPlayerChoices[i].Configure(player);
                    player.OptionSlot = i;

                    FantasyPlayer fPlayer = player; // Avoid Boxing
                    FantasyPlayerChoices[i].AddButton.onClick.RemoveAllListeners();
                    FantasyPlayerChoices[i].AddButton.onClick.AddListener(() => AddFantasyPlayerToEntry(fPlayer));

                    FantasyPlayersSlot slot = FantasyPlayerChoices[i]; // Boxing
                    FantasyPlayerChoices[i].AddButton.onClick.AddListener(() => slot.gameObject.SetActive(false));

                    i++;
                }
            }

            // Turn off the remaining unused choices
            for (; i < FantasyPlayerChoices.Count; i++)
            {
                FantasyPlayerChoices[i].gameObject.SetActive(false);
            }


            for (int index = 0; index < FantasyPlayerChoices.Count; index++)
            {
                FantasyPlayerChoices[index].transform.SetSiblingIndex(index);
            }

            // Configure the current lineup slots with default parameters, including an empty name
            for (int j = 0; j < CurrentLineupSlots.Count; j++)
            {
                CurrentLineupSlots[j].Configure(EMPTY, string.Empty, string.Empty, string.Empty, null);
            }

            CurrentContestEntry.SlotPlayer1.Name = EMPTY;
            CurrentContestEntry.SlotPlayer2.Name = EMPTY;
            CurrentContestEntry.SlotPlayer3.Name = EMPTY;
            CurrentContestEntry.SlotPlayer4.Name = EMPTY;
            CurrentContestEntry.SlotTeam1        = EMPTY;
            CurrentContestEntry.CurrentSalary    = 0;
            currentTotalFPPG = 0;
            fullSlots        = 0;

            RemainingSalaryText.text  = "$" + (baseSalary - CurrentContestEntry.CurrentSalary).ToString();
            AvgFantasyPointsText.text = "0.00";

            SubmitButton.interactable = false;
        }
    }
Exemple #3
0
    public ListenerResult HandleEvent(IEvent evt)
    {
        var evtName = evt.GetName();

        switch (evtName)
        {
        case EventContestEntryPlayerAdded.EventName:
            var addedPlayer = (FantasyPlayer)evt.GetData();

            // Update the player list to find an empty slot and fill it wiht the info of the player that was just selected
            if (addedPlayer != null)
            {
                fullSlots++;

                if (fullSlots == Backend.Utility.maxSlotsPerContest)
                {
                    SubmitButton.interactable = true;
                }
                else
                {
                    SubmitButton.interactable = false;
                }

                CurrentContestEntry.CurrentSalary += int.Parse(addedPlayer.Salary);

                currentTotalFPPG += int.Parse(addedPlayer.Points);

                float avgFPPG = currentTotalFPPG / fullSlots;

                AvgFantasyPointsText.text = avgFPPG.ToString("F");

                RemainingSalaryText.text = "$" + (baseSalary - CurrentContestEntry.CurrentSalary).ToString();

                FantasyPlayersSlot freeSlot = CurrentLineupSlots[currentEntryIndex];
                freeSlot.Configure(addedPlayer);
                freeSlot.AddButton.gameObject.SetActive(false);
                freeSlot.RemoveButton.gameObject.SetActive(true);

                freeSlot.RemoveButton.onClick.RemoveAllListeners();
                int slotIndex = currentEntryIndex;     // Boxing
                freeSlot.RemoveButton.onClick.AddListener(() => OnPressRemovePlayer(slotIndex));
                freeSlot.RemoveButton.onClick.AddListener(() => RemoveFantasyPlayerFromEntry(addedPlayer));
            }

            break;

        case EventContestEntryPlayerRemoved.EventName:
            var removedPlayer = (FantasyPlayer)evt.GetData();

            // Update the player list to find the removed slot and fill it with empty info
            if (removedPlayer != null)
            {
                fullSlots--;

                if (fullSlots == Backend.Utility.maxSlotsPerContest)
                {
                    SubmitButton.interactable = true;
                }
                else
                {
                    SubmitButton.interactable = false;
                }

                currentTotalFPPG -= int.Parse(removedPlayer.Points);

                float avgFPPG = 0f;

                if (fullSlots > 0)
                {
                    avgFPPG = currentTotalFPPG / fullSlots;
                }
                else
                {
                    avgFPPG = 0f;
                }
                AvgFantasyPointsText.text = avgFPPG.ToString("F");

                CurrentContestEntry.CurrentSalary -= int.Parse(removedPlayer.Salary);


                RemainingSalaryText.text = "$" + (baseSalary - CurrentContestEntry.CurrentSalary).ToString();


                FantasyPlayersSlot removedSlot = CurrentLineupSlots[currentEntryIndex];
                removedSlot.Configure(EMPTY, string.Empty, string.Empty, string.Empty, null);
                removedSlot.RemoveButton.gameObject.SetActive(false);
                removedSlot.AddButton.gameObject.SetActive(true);

                FantasyPlayerChoices[removedPlayer.OptionSlot].Configure(removedPlayer);
                FantasyPlayerChoices[removedPlayer.OptionSlot].gameObject.SetActive(true);
            }

            break;
        }

        return(ListenerResult.Cascade);
    }