<commit_before>﻿using FlatRedBall.Managers;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FlatRedBall.Forms.Controls.Popups
{
    public static class ToastManager 
    {
        static BlockingCollection<string> toastMessages = new BlockingCollection<string>();

        static bool hasBeenStarted;
        static void Start()
        {
            if(!hasBeenStarted)
            {
                hasBeenStarted = true;
                var thread = new Thread(new ThreadStart(DoLoop));
                thread.Start();
            }
        }

        public static void Show(string message)
        {
            if(!hasBeenStarted)
            {
                if(FlatRedBallServices.IsThreadPrimary())
                {
                    Start();
                }
                else
                {
                    Instructions.InstructionManager.AddSafe(Start);
                }
            }
            toastMessages.Add(message);
        }

        private static async void DoLoop()
        {
            Toast toast = null;

            foreach (var message in toastMessages.GetConsumingEnumerable(CancellationToken.None))
            {
                if(toast == null)
                {
                    toast = new FlatRedBall.Forms.Controls.Popups.Toast();
                }

                toast.Text = message;
                toast.Show();
                await Task.Delay(2000);
                toast.Close();
                // so there's a small gap between toasts
                await Task.Delay(100);
            }
        }
    }
}<commit_msg>ToastManager can now take a layer to show toast.<commit_after>﻿using FlatRedBall.Graphics;
using FlatRedBall.Managers;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FlatRedBall.Forms.Controls.Popups
{
    class ToastInfo
    {
        public string Message { get; set; }
        public Layer FrbLayer { get; set; }
    }

    public static class ToastManager 
    {
        static BlockingCollection<ToastInfo> toastMessages = new BlockingCollection<ToastInfo>();

        static bool hasBeenStarted;
        static void Start()
        {
            if(!hasBeenStarted)
            {
                hasBeenStarted = true;
                var thread = new Thread(new ThreadStart(DoLoop));
                thread.Start();
            }
        }

        public static void Show(string message, Layer frbLayer = null)
        {
            if(!hasBeenStarted)
            {
                if(FlatRedBallServices.IsThreadPrimary())
                {
                    Start();
                }
                else
                {
                    Instructions.InstructionManager.AddSafe(Start);
                }
            }

            var toastInfo = new ToastInfo { Message = message, FrbLayer = frbLayer };

            toastMessages.Add(toastInfo);
        }

        private static async void DoLoop()
        {
            Toast toast = null;

            foreach (var message in toastMessages.GetConsumingEnumerable(CancellationToken.None))
            {
                if(toast == null)
                {
                    toast = new FlatRedBall.Forms.Controls.Popups.Toast();
                }

                toast.Text = message.Message;
                toast.Show(message.FrbLayer);
                await Task.Delay(2000);
                toast.Close();
                // so there's a small gap between toasts
                await Task.Delay(100);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07965784549585672, 'fraction_numerical': 0.0037423148890670943, 'mean_word_length': 1.4095299420476497, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5030440', 'n_tokens_mistral': 972, 'n_tokens_neox': 903, 'n_words': 201}