public static void AddCooldownText(string text, float duration, Tuple <string, string, EventInfo> eventInfo)
        {
            CustomText cooldownText = new CustomText(text, duration, 0, true);

            cooldownText.SetEvent(eventInfo);
            cooldownTexts.Add(new KeyValuePair <string, CustomText>(text, cooldownText));
        }
        public static void AddCooldown(string text, float duration, Tuple <string, string, EventInfo> eventInfo)
        {
            if (!initialised)
            {
                Initialise();
            }

            CustomText cooldownText = new CustomText(text, duration, 0, true);

            cooldownText.SetEvent(eventInfo);
            customTimerTexts.Add(cooldownText);
        }
Exemple #3
0
        public static void AddCooldown(string text, float duration, EventInfo eventInfo)
        {
            if (!initialised)
            {
                Initialise();
            }

            CustomText cooldownText = new CustomText(text, duration, 0, true);

            cooldownText.SetEvent(new KeyValuePair <string, EventInfo>(text, eventInfo));
            customTimerTexts.Add(cooldownText);
        }
        public static void AddCooldown(string text, Tuple <string, string, TimedEventInfo> eventInfo)
        {
            if (!initialised)
            {
                Initialise();
            }

            CustomText cooldownText = new CustomText(text, eventInfo.Item3.TimerLength, 0, true);

            cooldownText.SetTimedEvent(eventInfo);
            EventLookup.RunningEventIDs.Add(text);
            customTimerTexts.Add(cooldownText);
        }
Exemple #5
0
        public static void AddCooldown(string text, TimedEventInfo timedEvent)
        {
            if (!initialised)
            {
                Initialise();
            }

            CustomText cooldownText = new CustomText(text, timedEvent.TimerLength, 0, true);

            cooldownText.SetTimedEvent(new KeyValuePair <string, TimedEventInfo>(text, timedEvent));
            EventLookup.RunningEventIDs.Add(text);
            customTimerTexts.Add(cooldownText);
        }
        public static void AddQueueText(string text, string User, int Bits = -1)
        {
            CustomText cooldownText = new CustomText(text, float.MaxValue);

            actionQueueTexts.Add(new KeyValuePair <string, CustomText>(text, cooldownText));

            if (MainPatcher.secrets.showRedemptionMessages)
            {
                string redeptionMessage = "";
                if (Bits == -1)
                {
                    redeptionMessage = User + " has redeemed " + text + "!";
                }
                else
                {
                    redeptionMessage = User + " has redeemed " + text + " using " + Bits + " bits!";
                }
                redemptionTexts.Enqueue(redeptionMessage);
            }
        }
        public static void Initialise()
        {
            customTimerTexts  = new List <CustomText>();
            actionQueueTexts  = new List <KeyValuePair <string, CustomText> >();
            cooldownTexts     = new List <KeyValuePair <string, CustomText> >();
            activeEffectsText = new CustomText("Active", float.MaxValue);
            activeEffectsText.SetSize(24);
            queueText = new CustomText("Queue", float.MaxValue);
            queueText.SetSize(24);
            cooldownText = new CustomText("Cooldowns", float.MaxValue);
            cooldownText.SetSize(24);

            newEventsList = new ConcurrentQueue <string>();

            initialised = true;

            EventLookup.ActionQueue       = new List <KeyValuePair <string, EventInfo> >();
            EventLookup.Cooldowns         = new Dictionary <string, float>();
            EventLookup.RunningEventIDs   = new List <string>();
            EventLookup.TimedActionsQueue = new List <Action>();
        }
        public static void Update()
        {
            float newWidestText = 0;

            if (!initialised)
            {
                Initialise();
            }

            // First step is to add actions to the queue based on newly added events.
            CreateNewText();

            try
            {
                activeEffectsText.Update(-((actionQueueTexts.Count + cooldownTexts.Count + customTimerTexts.Count - 1) * ActualTimerTextHeight()) - 5 * ActualTimerHeadingHeight());
                cooldownText.Update(-((actionQueueTexts.Count + cooldownTexts.Count - 1) * ActualTimerTextHeight()) - 3 * ActualTimerHeadingHeight());
                queueText.Update(-((actionQueueTexts.Count - 1) * ActualTimerTextHeight() + ActualTimerHeadingHeight()));

                if (activeEffectsText.getTextWidth() > newWidestText)
                {
                    newWidestText = activeEffectsText.getTextWidth();
                }
                if (cooldownText.getTextWidth() > newWidestText)
                {
                    newWidestText = cooldownText.getTextWidth();
                }
                if (queueText.getTextWidth() > newWidestText)
                {
                    newWidestText = queueText.getTextWidth();
                }
            }
            catch (Exception)
            {
                Initialise();
                activeEffectsText.Update(-((actionQueueTexts.Count + cooldownTexts.Count + customTimerTexts.Count - 1) * ActualTimerTextHeight()) - 5 * ActualTimerHeadingHeight());
                cooldownText.Update(-((actionQueueTexts.Count + cooldownTexts.Count - 1) * ActualTimerTextHeight()) - 3 * ActualTimerHeadingHeight());
                queueText.Update(-((actionQueueTexts.Count - 1) * ActualTimerTextHeight() + ActualTimerHeadingHeight()));
            }

            // Redemption messages
            if (currentRedemptionText != null)
            {
                currentRedemptionText.Update(-((actionQueueTexts.Count + cooldownTexts.Count + customTimerTexts.Count) * ActualTimerTextHeight()) - 6 * ActualTimerHeadingHeight());

                if (currentRedemptionText.IsFinished())
                {
                    currentRedemptionText.Destroy();
                    currentRedemptionText = null;
                }
            }
            if (currentRedemptionText == null)
            {
                string newRedemptionText;
                if (redemptionTexts.TryDequeue(out newRedemptionText))
                {
                    currentRedemptionText = new CustomText(newRedemptionText, 5, 0, false, false);

                    // Only do this in the main thread, to hopefully prevent errors
                    if (MainPatcher.secrets.saveRedemptionMessages)
                    {
                        string filePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "redemptions.txt");
                        using (StreamWriter sw = File.AppendText(filePath))
                        {
                            sw.WriteLine(newRedemptionText);
                        }
                    }
                }
            }

            // Active effects
            for (int i = 0; i < customTimerTexts.Count; i++)
            {
                customTimerTexts[i].Update(-((actionQueueTexts.Count + cooldownTexts.Count + i) * ActualTimerTextHeight()) - 4 * ActualTimerHeadingHeight());

                if (customTimerTexts[i].getTextWidth() > newWidestText)
                {
                    newWidestText = customTimerTexts[i].getTextWidth();
                }

                if (customTimerTexts[i].IsFinished())
                {
                    if (customTimerTexts[i].HasTimedEvent())
                    {
                        Tuple <string, string, TimedEventInfo> timedEvent = customTimerTexts[i].GetTimedEvent();
                        EventLookup.RunningEventIDs.Remove(timedEvent.Item1);
                        EventLookup.TimedActionsQueue.Add(timedEvent);
                        EventLookup.Cooldowns.Add(timedEvent.Item1, Time.time);
                        AddCooldownText(timedEvent.Item1, timedEvent.Item3.CooldownSeconds, new Tuple <string, string, EventInfo>(timedEvent.Item1, timedEvent.Item2, timedEvent.Item3));
                    }

                    customTimerTexts[i].Destroy();
                    customTimerTexts.RemoveAt(i);
                    i--;
                }
            }

            // Queue
            int j = 0;

            foreach (KeyValuePair <string, CustomText> actionQueueText in actionQueueTexts)
            {
                actionQueueText.Value.Update(-(j * ActualTimerTextHeight()));
                j++;

                if (actionQueueText.Value.getTextWidth() > newWidestText)
                {
                    newWidestText = actionQueueText.Value.getTextWidth();
                }
            }

            // Cooldown
            List <string> finishedCooldowns = new List <string>();

            int k = 0;

            foreach (KeyValuePair <string, CustomText> cooldownText in cooldownTexts)
            {
                cooldownText.Value.Update(-((actionQueueTexts.Count + k) * ActualTimerTextHeight()) - 2 * ActualTimerHeadingHeight());
                k++;

                Tuple <string, string, EventInfo> eventInfo = cooldownText.Value.GetEvent();
                float currentCooldownDuration = Time.time - EventLookup.Cooldowns[eventInfo.Item1];
                if (currentCooldownDuration >= eventInfo.Item3.CooldownSeconds)
                {
                    finishedCooldowns.Add(eventInfo.Item1);
                }

                if (cooldownText.Value.getTextWidth() > newWidestText)
                {
                    newWidestText = cooldownText.Value.getTextWidth();
                }
            }

            foreach (string finishedCooldown in finishedCooldowns)
            {
                RemoveCooldownText(finishedCooldown);
                EventLookup.Cooldowns.Remove(finishedCooldown);
            }

            widestText = newWidestText;
        }
        private static void AddQueueText(string text)
        {
            CustomText cooldownText = new CustomText(text, float.MaxValue);

            actionQueueTexts.Add(new KeyValuePair <string, CustomText>(text, cooldownText));
        }