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;
         }
     }
 }
Exemplo n.º 2
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);
    }