Example #1
0
///// Popup updater functions and generators /////

    private bool NewMatchRequestUpdater(MatchRequestEventArgs matchRequest)
    {
        if (matchRequest.Status == MatchRequestEventArgs.EStatus.New)
        {
            // Set popup
            var popup = PopupPanel.InstanciateTimeoutPopup();
            popup.Text = "New match request from \n<color=#66FFD9><b>" + matchRequest.User.UserName + "</b></color>";

            popup.AcceptButton.onClick.AddListener(() =>
            {
                popup.StatorAnimation.Interrupt();
                popup.AcceptButton.interactable  = false;
                popup.DeclineButton.interactable = false;
                popup.StatorAnimation.StartPulse(Color.green, 0.5f, 4);
                popup.StatorAnimation.Finished.UnsubscribeAll();
                popup.StatorAnimation.Finished.Subscribe((sender, e) =>
                {
                    Destroy(popup.gameObject);
                    UIController.RaiseReadyToGame();
                });
                MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(matchRequest.User, MatchRequestEventArgs.EStatus.Accepted));
                popupUpdaters.Add(MatchRequestEchoHandlerGen(matchRequest.User));
            });

            popup.DeclineButton.onClick.AddListener(() =>
            {
                Destroy(popup.gameObject);
                MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(matchRequest.User, MatchRequestEventArgs.EStatus.Declined));
                popupUpdaters.Add(MatchRequestEchoHandlerGen(matchRequest.User));
            });

            popup.StatorAnimation.StartTimeout(5);
            popup.StatorAnimation.Finished.Subscribe((sender, e) =>
            {
                Destroy(popup.gameObject);
                Debug.Log("Sending automatic decline answer [TIMEOUT]");
                MatchRequestUpdated?.Invoke(this, new MatchRequestEventArgs(matchRequest.User, MatchRequestEventArgs.EStatus.Declined));
            });

            // Set popup updater function
            var popupUpdater = NewMatchRequestCanceledUpdaterGen(popup, matchRequest.User);
            popupUpdaters.Add(popupUpdater);
            popup.Disabled += (sender, e) => popupUpdaters.Remove(popupUpdater);

            return(true);
        }
        return(false);
    }