Пример #1
0
        /// <summary>
        /// Creates a <see cref="ToastConfig"/> with a value for <see cref="ToastConfig.BackgroundColor"/> and <see cref="ToastConfig.MessageTextColor"/> set.
        /// The created <see cref="ToastConfig"/> contains the given message.
        /// </summary>
        /// <param name="message">Message to be shown by the toast.</param>
        /// <param name="state">The state (Success, Failure, Neutral) to be shown.</param>
        /// <returns></returns>
        ToastConfig CreateToastConfig(string message, ToastState state = ToastState.Neutral)
        {
            var config = new ToastConfig(message);

            /*
             * Set different colors depending on the ToastState.
             */
            switch (state)
            {
            case ToastState.Success:
                config.BackgroundColor  = ((Color)Application.Current.Resources["SuccessColor"]).ToSystemDrawingColor();
                config.MessageTextColor = ((Color)Application.Current.Resources["SuccessTextColor"]).ToSystemDrawingColor();
                break;

            case ToastState.Failure:
                config.BackgroundColor  = ((Color)Application.Current.Resources["FailureColor"]).ToSystemDrawingColor();
                config.MessageTextColor = ((Color)Application.Current.Resources["FailureTextColor"]).ToSystemDrawingColor();
                break;

            case ToastState.Neutral:
                config.BackgroundColor  = ((Color)Application.Current.Resources["NeutralColor"]).ToSystemDrawingColor();
                config.MessageTextColor = ((Color)Application.Current.Resources["NeutralTextColor"]).ToSystemDrawingColor();
                break;
            }
            return(config);
        }
Пример #2
0
 private void ResetToastPosition()
 {
     this.transform.position = offScreenPosition.transform.position;
     toastTimer       = 0f;
     toastState       = ToastState.Offscreen;
     titleText.text   = "";
     mPointsText.text = "";
     messageText.text = "";
 }
Пример #3
0
        private void TransitionTo(ToastState state)
        {
            Timer.Stop();
            State = state;

            switch (state)
            {
            case ToastState.Showing:
                if (Options.ShowTransitionDuration <= 0)
                {
                    TransitionTo(ToastState.Visible);
                }
                else
                {
                    Timer.Start(Options.ShowTransitionDuration);
                }
                break;

            case ToastState.Visible:
                if (Options.RequireInteraction)
                {
                    TransitionState = TransitionState.ForRequiredInteraction(Options.MaximumOpacity);
                    OnUpdate?.Invoke();
                    return;
                }
                else if (Options.VisibleStateDuration < 0)
                {
                    TransitionTo(ToastState.Hiding);
                }
                else
                {
                    Timer.Start(Options.VisibleStateDuration);
                }
                break;

            case ToastState.Hiding:
                if (Options.HideTransitionDuration <= 0)
                {
                    OnClose?.Invoke(this);
                    return;
                }
                else
                {
                    Timer.Start(Options.HideTransitionDuration);
                }
                break;

            case ToastState.MouseOver:
                break;
            }

            UpdateTransitionState();
            OnUpdate?.Invoke();
        }
        private void UpdateState(PointerRoutedEventArgs e)
        {
            this.UpdateDismissTimer(e);

            if (this.state == ToastState.FadingOut)
            {
                this.state = ToastState.Displayed;
                this.fadeInOutAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(100));
                this.fadeInOutAnimation.Start(1);
            }
        }
Пример #5
0
    //Helper Methods

    private void LerpToast()
    {
        float positionPercentage = 1f;

        switch (toastState)
        {
        case ToastState.Toasting:
            toastTimer        += Time.deltaTime;
            positionPercentage = toastTimer / TOAST_ANIMATION_TIME;

            if (positionPercentage > 1f)
            {
                positionPercentage = 1f;
                toastState         = ToastState.Displaying;
                toastTimer         = 0f;
            }

            this.transform.position = Vector3.Lerp(offScreenPosition.position, onScreenPosition.position, positionPercentage);
            break;

        case ToastState.Displaying:
            toastTimer += Time.deltaTime;

            if (toastTimer > TOAST_DISPLAY_TIME)
            {
                toastState = ToastState.Untoasting;
                toastTimer = 0f;
            }
            break;

        case ToastState.Untoasting:
            toastTimer        += Time.deltaTime;
            positionPercentage = toastTimer / TOAST_ANIMATION_TIME;

            if (positionPercentage > 1f)
            {
                positionPercentage = 1f;
                toastState         = ToastState.Offscreen;
                toastTimer         = 0f;

                //Our Native Achievement has come and gone without the user clicking on it
                //We need to notify SessionM that the achievment was dismissed.
                SessionM.GetInstance().NotifyDismissed();
            }

            this.transform.position = Vector3.Lerp(onScreenPosition.position, offScreenPosition.position, positionPercentage);
            break;

        default:
            Debug.LogWarning("Invalid Toast State in LerpToast.");
            break;
        }
    }
    //Exposed Methods
    public void ShowAchievementToast(string achievementTitle, int mPointValue)
    {
        //Exit this call if there is currently an active Toast
        //(This shouldn't occur because we have notified SessionM we are currently displaying an achievement.)
        if(toastState != ToastState.Offscreen)
            return;

        titleText.text = achievementTitle;
        mPointsText.text = "mPoints: " + mPointValue.ToString();
        toastState = ToastState.Toasting;
        toastTimer = 0f;

        //Notify SessionM We are about to display the achievment.
        SessionM.GetInstance().NotifyPresented();
    }
    //Helper Methods
    private void LerpToast()
    {
        float positionPercentage = 1f;

        switch(toastState) {
        case ToastState.Toasting:
            toastTimer += Time.deltaTime;
            positionPercentage = toastTimer / TOAST_ANIMATION_TIME;

            if(positionPercentage > 1f) {
                positionPercentage = 1f;
                toastState = ToastState.Displaying;
                toastTimer = 0f;
            }

            this.transform.position = Vector3.Lerp(offScreenPosition.position, onScreenPosition.position, positionPercentage);
            break;
        case ToastState.Displaying:
            toastTimer += Time.deltaTime;

            if(toastTimer > TOAST_DISPLAY_TIME) {
                toastState = ToastState.Untoasting;
                toastTimer = 0f;
            }
            break;
        case ToastState.Untoasting:
            toastTimer += Time.deltaTime;
            positionPercentage = toastTimer / TOAST_ANIMATION_TIME;

            if(positionPercentage > 1f) {
                positionPercentage = 1f;
                toastState = ToastState.Offscreen;
                toastTimer = 0f;

                //Our Native Achievement has come and gone without the user clicking on it
                //We need to notify SessionM that the achievment was dismissed.
                SessionM.GetInstance().NotifyDismissed();
            }

            this.transform.position = Vector3.Lerp(onScreenPosition.position, offScreenPosition.position, positionPercentage);
            break;
        default:
            Debug.LogWarning("Invalid Toast State in LerpToast.");
            break;
        }
    }
Пример #8
0
    //Exposed Methods
    public void ShowAchievementToast(string achievementTitle, int mPointValue, string achievementMessage)
    {
        //Exit this call if there is currently an active Toast
        //(This shouldn't occur because we have notified SessionM we are currently displaying an achievement.)
        if (toastState != ToastState.Offscreen)
        {
            return;
        }

        titleText.text   = achievementTitle;
        mPointsText.text = "mPoints: " + mPointValue.ToString();
        messageText.text = achievementMessage;
        toastState       = ToastState.Toasting;
        toastTimer       = 0f;

        //Notify SessionM We are about to display the achievment.
        SessionM.GetInstance().NotifyPresented();
    }
Пример #9
0
        private void TransitionTo(ToastState state)
        {
            StopTimer();
            State.ToastState = state;
            var options = State.Options;

            if (state.IsShowing())
            {
                if (options.ShowTransitionDuration <= 0)
                {
                    TransitionTo(ToastState.Visible);
                }
                else
                {
                    StartTimer(options.ShowTransitionDuration);
                }
            }
            else if (state.IsVisible() && !options.RequireInteraction)
            {
                if (options.VisibleStateDuration <= 0)
                {
                    TransitionTo(ToastState.Hiding);
                }
                else
                {
                    StartTimer(options.VisibleStateDuration);
                }
            }
            else if (state.IsHiding())
            {
                if (options.HideTransitionDuration <= 0)
                {
                    OnClose?.Invoke(this);
                }
                else
                {
                    StartTimer(options.HideTransitionDuration);
                }
            }

            OnUpdate?.Invoke();
        }
Пример #10
0
 public State(ToastOptions options)
 {
     Options     = options;
     AnimationId = $"toaster-{Guid.NewGuid()}";
     ToastState  = ToastState.Init;
 }
 private void DismissWithFadeOut()
 {
     this.state = ToastState.FadingOut;
     this.fadeInOutAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
     this.fadeInOutAnimation.Start(0);
 }
 private void DismissWithTranslate()
 {
     this.state = ToastState.UserDismissed;
     this.translateAnimation.Start(this.ActualWidth);
 }
 protected virtual void AddToast(IToastNotification Toast) => ToastState.AddNotification(Toast);
 private void ResetToastPosition()
 {
     this.transform.position = offScreenPosition.transform.position;
     toastTimer = 0f;
     toastState = ToastState.Offscreen;
     titleText.text = "";
     mPointsText.text = "";
 }
 public static bool IsHiding(this ToastState state) => state == ToastState.Hiding;
 public static bool IsVisible(this ToastState state) => state == ToastState.Visible;
 public static bool IsShowing(this ToastState state) => state == ToastState.Showing;