/// <summary>
        /// Play a single clip on an AudioSource; if Looping forever, return InfiniteLoop for the event time.
        /// </summary>
        /// <param name="audioClip">The audio clip to play.</param>
        /// <param name="emitter">The emitter to use.</param>
        /// <param name="activeEvent">The persistent reference to the event as long as it is playing.</param>
        /// <returns>The amount of delay, if any, we are waiting before playing the clip. A Looping clip will always return InfiniteLoop.</returns>
        private float PlayClipAndGetTime(UAudioClip audioClip, AudioSource emitter, ActiveEvent activeEvent)
        {
            if (audioClip.DelayCenter == 0)
            {
                emitter.PlayClip(audioClip.Sound, audioClip.Looping);

                if (audioClip.Looping)
                {
                    return(InfiniteLoop);
                }

                return(0);
            }
            else
            {
                float rndDelay = Random.Range(audioClip.DelayCenter - audioClip.DelayRandomization, audioClip.DelayCenter + audioClip.DelayRandomization);

                StartCoroutine(PlayClipDelayedCoroutine(audioClip, emitter, rndDelay, activeEvent));

                if (audioClip.Looping)
                {
                    return(InfiniteLoop);
                }

                return(rndDelay);
            }
        }
        /// <summary>
        /// Keep an event in the "ActiveEvents" list for the amount of time we think it will be playing, plus the instance buffer.
        /// This is mostly done for instance limiting purposes.
        /// </summary>
        /// <param name="activeEvent">The persistent reference to the event as long as it is playing.</param>
        /// <returns>The coroutine.</returns>
        private IEnumerator RecordEventInstanceCoroutine(ActiveEvent activeEvent)
        {
            // Unity has no callback for an AudioClip ending, so we have to estimate it ahead of time.
            // Changing the pitch during playback will alter actual playback time.
            ActiveEvents.Add(activeEvent);

            // Only return active time if sound is not Looping/continuous.
            if (activeEvent.ActiveTime > 0)
            {
                yield return(new WaitForSeconds(activeEvent.ActiveTime));

                // Mark this event so it no longer counts against the instance limit.
                activeEvent.IsActiveTimeComplete = true;

                // Since the ActiveTime estimate may not be enough time to complete the clip (due to pitch changes during playback, or a negative instanceBuffer value, for example)
                // wait here until it is finished, so that we don't cut off the end.
                if (activeEvent.IsPlaying)
                {
                    yield return(null);
                }
            }
            // Otherwise, continue at next frame.
            else
            {
                yield return(null);
            }

            if (activeEvent.ActiveTime != InfiniteLoop)
            {
                RemoveEventInstance(activeEvent);
            }
        }
        /// <summary>
        /// Play one sound from a container based on container behavior.
        /// </summary>
        /// <param name="currentContainer"></param>
        /// <param name="activeEvent"></param>
        /// <returns>The estimated ActiveTime for the clip, or InfiniteLoop if the container and/or clip are set to loop.</returns>
        private float PlaySingleClip(AudioContainer currentContainer, ActiveEvent activeEvent)
        {
            float tempDelay = 0;

            if (currentContainer.ContainerType == AudioContainerType.Random)
            {
                currentContainer.CurrentClip = Random.Range(0, currentContainer.Sounds.Length);
            }
            UAudioClip currentClip = currentContainer.Sounds[currentContainer.CurrentClip];

            // Trigger sound and save the delay (in seconds) to add to the total amount of time the event will be considered active.
            tempDelay = PlayClipAndGetTime(currentClip, activeEvent.PrimarySource, activeEvent);

            // Ready the next clip in the series if sequence container.
            if (currentContainer.ContainerType == AudioContainerType.Sequence)
            {
                currentContainer.CurrentClip++;
                if (currentContainer.CurrentClip >= currentContainer.Sounds.Length)
                {
                    currentContainer.CurrentClip = 0;
                }
            }

            // Return active time based on Looping or clip time.
            return(GetActiveTimeEstimate(currentClip, activeEvent, tempDelay));
        }
Exemple #4
0
        private void ActOnEnd(TPayload payload, TKey key, int hash, long start, long endTime)
        {
            var matchSmall = new KHP
            {
                Hash    = hash,
                Key     = key,
                Payload = payload
            };
            var item = RemoveOne(this.OpenEvents, matchSmall, start);


            // and add it to the End list
            item.End = endTime;

            if (!this.ClosedEvents.ContainsKey(endTime))
            {
                // For performance, we pull this out of a pool rather than consing a new one.
                // Make very sure to reset the object before restoring it to the pool, or it'll carry garbage
                this.dictPool.Get(out FastDictionary2 <KHP, List <ActiveEvent> > entry);
                this.ClosedEvents[endTime] = entry;
            }

            var activeEvt = ActiveEvent.FromExt(item);

            InsertOrAppend(this.ClosedEvents[endTime], matchSmall, activeEvt);
        }
        /// <summary>
        /// Play a non-continuous container.
        /// </summary>
        private float PlayOneOffContainer(ActiveEvent activeEvent)
        {
            AudioContainer currentContainer = activeEvent.AudioEvent.Container;

            // Fading or Looping overrides immediate volume settings.
            if (activeEvent.AudioEvent.FadeInTime == 0 && !activeEvent.AudioEvent.Container.Looping)
            {
                activeEvent.VolDest = activeEvent.PrimarySource.volume;
            }

            // Simultaneous sounds.
            float clipTime = 0;

            if (currentContainer.ContainerType == AudioContainerType.Simultaneous)
            {
                clipTime = PlaySimultaneousClips(currentContainer, activeEvent);
            }
            // Sequential and Random sounds.
            else
            {
                clipTime = PlaySingleClip(currentContainer, activeEvent);
            }

            activeEvent.ActiveTime = clipTime;
            return(clipTime);
        }
        /// <summary>
        /// Play all clips in container simultaneously
        /// </summary>
        private float PlaySimultaneousClips(AudioContainer currentContainer, ActiveEvent activeEvent)
        {
            float tempDelay       = 0;
            float finalActiveTime = 0f;

            if (currentContainer.Looping)
            {
                finalActiveTime = InfiniteLoop;
            }

            for (int i = 0; i < currentContainer.Sounds.Length; i++)
            {
                tempDelay = PlayClipAndGetTime(currentContainer.Sounds[i], activeEvent.PrimarySource, activeEvent);

                if (finalActiveTime != InfiniteLoop)
                {
                    float estimatedActiveTimeNeeded = GetActiveTimeEstimate(currentContainer.Sounds[i], activeEvent, tempDelay);

                    if (estimatedActiveTimeNeeded == InfiniteLoop || estimatedActiveTimeNeeded > finalActiveTime)
                    {
                        finalActiveTime = estimatedActiveTimeNeeded;
                    }
                }
            }

            return(finalActiveTime);
        }
        private async void RecoversEvent(string evtId, ISession session)
        {
            int         num      = 0;
            ActiveEvent newEvt   = null;
            string      newEvtId = null;

            while (true)
            {
                if (newEvtId == null)
                {
                    newEvt = session.Get <ActiveEvent>(evtId);
                }
                else
                {
                    newEvt = session.Get <ActiveEvent>(newEvtId);
                }

                if (newEvt == null)
                {
                    break;
                }
                newEvtId = $"{evtId}_{num++}";
                if (newEvt.HasRecovered)
                {
                    continue;
                }
                newEvt.HasRecovered     = true;
                newEvt.RecoverTimestamp = DateTime.Now;
                await session.SaveOrUpdateAsync(newEvt);
            }
        }
Exemple #8
0
        private void Emit(ActiveEvent evt)
        {
            var dest_vsync  = this.batch.vsync.col;
            var dest_vother = this.batch.vother.col;
            var destkey     = this.batch.key.col;
            var dest_hash   = this.batch.hash.col;

            var tempOutputCount = this.outputCount;

            if (evt.End == StreamEvent.InfinitySyncTime)
            { // start event
                dest_vsync[tempOutputCount]  = evt.Start;
                dest_vother[tempOutputCount] = evt.End;
            }
            else // issue an end event
            {
                dest_vsync[tempOutputCount]  = evt.End;
                dest_vother[tempOutputCount] = evt.Start;
            }

            this.batch[tempOutputCount] = evt.Payload;
            destkey[tempOutputCount]    = evt.Key;
            dest_hash[tempOutputCount]  = evt.Hash;

            this.outputCount++;
            tempOutputCount = this.outputCount;

            if (tempOutputCount == Config.DataBatchSize)
            {
                FlushContents();
            }
        }
Exemple #9
0
    void Awake()
    {
        _currentState = GameState.WAITING;
        _playersReady = new bool[4];

        HouseLevelChange = new HouseChangeEvent();
        GameEnd          = new IntEvent();
        GameStart        = new UnityEvent();
        Score            = new ScoreEvent();
        PlayerActive     = new ActiveEvent();

        GameEnd.AddListener(OnGameEnd);
        GameStart.AddListener(OnGameStart);
        HouseLevelChange.AddListener(OnHouseLevelChange);
        PlayerActive.AddListener(OnPlayerActive);
        Score.AddListener(OnScore);

        cameraAudioSource      = GetComponent <AudioSource>();
        cameraAudioSource.clip = loopingClips[0];
        cameraAudioSource.Play();

        SceneManager.sceneLoaded += OnSceneLoaded;

        if (GameOverText)
        {
            GameOverText.SetActive(true);

            string newGameOverText = $"All players press any button to play";
            GameOverText.GetComponent <TextMeshProUGUI>().text = newGameOverText;
        }
    }
        private void Emit(ActiveEvent evt)
        {
            var dest_vsync  = this.batch.vsync.col;
            var dest_vother = this.batch.vother.col;
            var destkey     = this.batch.key.col;
            var dest_hash   = this.batch.hash.col;

            var tempOutputCount = this.outputCount;

            if (evt.End == StreamEvent.InfinitySyncTime)
            {
                throw new InvalidOperationException("Only intervals allowed in Emit");
            }
            dest_vsync[this.outputCount]  = evt.Start;
            dest_vother[this.outputCount] = evt.End;

            this.batch[tempOutputCount] = this.computeResult(evt.state);
            destkey[tempOutputCount]    = evt.Key;
            dest_hash[tempOutputCount]  = evt.Hash;

            this.outputCount++;
            tempOutputCount = this.outputCount;

            if (tempOutputCount == Config.DataBatchSize)
            {
                FlushContents();
            }
        }
        /// <summary>
        /// Coroutine for fading out an AudioSource, and stopping the event once fade is complete.
        /// </summary>
        /// <param name="activeEvent">The persistent reference to the event as long as it is playing.</param>
        /// <param name="fadeTime">The amount of time, in seconds, to completely fade out the sound.</param>
        /// <returns>The coroutine.</returns>
        protected IEnumerator StopEventWithFadeCoroutine(ActiveEvent activeEvent, float fadeTime)
        {
            if (activeEvent.IsStoppable)
            {
                activeEvent.IsStoppable = false;
                activeEvent.VolDest     = 0f;
                activeEvent.AltVolDest  = 0f;
                activeEvent.CurrentFade = fadeTime;

                yield return(new WaitForSeconds(fadeTime));

                if (activeEvent.PrimarySource != null)
                {
                    activeEvent.PrimarySource.Stop();
                }

                if (activeEvent.SecondarySource != null)
                {
                    activeEvent.SecondarySource.Stop();
                }

                activeEvent.CancelEvent = true;
                RemoveEventInstance(activeEvent);
            }
        }
 public override void SaveLayer(BinaryWriter BW)
 {
     BW.Write(DicTimelineEvent[0].Count);
     foreach (Timeline ActiveEvent in DicTimelineEvent[0])
     {
         ActiveEvent.Save(BW);
     }
 }
Exemple #13
0
        public static void StartEvent()
        {
            if (ActiveEvent == null)
            {
                return;
            }

            foreach (var registeredClient in EventManager.GetRegisteredClients())
            {
                Story story = new Story(Guid.NewGuid().ToString());
                StoryBuilderSegment segment = StoryBuilder.BuildStory();
                StoryBuilder.AppendSaySegment(segment, $"This event is... {ActiveEvent.Name}!", -1, 0, 0);
                StoryBuilder.AppendSaySegment(segment, ActiveEvent.IntroductionMessage, -1, 0, 0);

                foreach (var rule in ActiveEvent.Rules)
                {
                    StoryBuilder.AppendSaySegment(segment, rule, -1, 0, 0);
                }

                if (ActiveEvent.Duration.HasValue)
                {
                    StoryBuilder.AppendSaySegment(segment, $"The event will end in {ActiveEvent.Duration.Value.TotalMinutes} minutes.", -1, 0, 0);
                }
                if (Main.IsTestingEvent)
                {
                    StoryBuilder.AppendSaySegment(segment, $"This event is currently being tested and winners will not receive any prizes.", -1, 0, 0);
                }
                else if (!string.IsNullOrEmpty(ActiveEvent.RewardMessage))
                {
                    StoryBuilder.AppendSaySegment(segment, ActiveEvent.RewardMessage, -1, 0, 0);
                }

                StoryBuilder.AppendSaySegment(segment, "The event has now begun!", -1, 0, 0);
                segment.AppendToStory(story);
                StoryManager.PlayStory(registeredClient, story);
            }

            ActiveEvent.Start();

            var eventStartMessage = new StringBuilder();

            if (Main.IsTestingEvent)
            {
                eventStartMessage.Append("[Testing] ");
            }
            eventStartMessage.Append($"{ActiveEvent.Name} has started!");

            Task.Run(() => DiscordManager.Instance.SendAnnouncement(eventStartMessage.ToString()));
            Messenger.SendAnnouncement("Weekly Event", eventStartMessage.ToString());

            if (ActiveEvent.Duration.HasValue)
            {
                var endTime = DateTime.UtcNow.Add(ActiveEvent.Duration.Value);

                SetGlobalCountdown(new Countdown("The event ends in...", endTime));
                TimedEventManager.CreateTimer("endevent", endTime, null);
            }
        }
        public override bool?Execute()
        {
            ActiveEvent ae = new ActiveEvent();

            ae.Condition = new ScriptWrapper(line.Condition);
            ae.Result    = new ScriptWrapper(line.Result);
            MainViewModel.GetMainViewModelStatic().CurrentGame.ActiveEvents.Add(ae);
            return(null);
        }
        /// <summary>
        /// Plays an AudioEvent.
        /// </summary>
        /// <param name="audioEvent">The AudioEvent to play.</param>
        /// <param name="emitter">The GameObject on which the AudioEvent is to be played.</param>
        /// <param name="primarySource">The AudioSource component to use as the primary source for the event.</param>
        /// <param name="secondarySource">The AudioSource component to use as the secondary source for the event.</param>
        /// <param name="messageOnAudioEnd">The Message to Send to the GameObject when the sound has finished playing.</param>
        private void PlayEvent(AudioEvent audioEvent,
                               GameObject emitter,
                               AudioSource primarySource,
                               AudioSource secondarySource,
                               string messageOnAudioEnd = null)
        {
            ActiveEvent tempEvent = new ActiveEvent(audioEvent, emitter, primarySource, secondarySource, messageOnAudioEnd);

            // The base class owns this event once we pass it to PlayContainer, and may dispose it if it cannot be played.
            PlayContainer(tempEvent);
        }
        /// <summary>
        /// Remove event from the currently active events.
        /// </summary>
        /// <param name="activeEvent">The persistent reference to the event as long as it is playing.</param>
        private void RemoveEventInstance(ActiveEvent activeEvent)
        {
            ActiveEvents.Remove(activeEvent);

            // Send message notifying user that sound is complete
            if (!string.IsNullOrEmpty(activeEvent.MessageOnAudioEnd))
            {
                activeEvent.AudioEmitter.SendMessage(activeEvent.MessageOnAudioEnd);
            }

            activeEvent.Dispose();
        }
        /// <summary>
        /// Stop event by gameObject.
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="gameObjectToStop"></param>
        /// <param name="fadeOutTime"></param>
        public void StopEventsOnGameObject(string eventName, GameObject gameObjectToStop, float fadeOutTime = 0f)
        {
            for (int i = ActiveEvents.Count - 1; i >= 0; i--)
            {
                ActiveEvent activeEvent = ActiveEvents[i];

                if (activeEvent.AudioEmitter == gameObjectToStop)
                {
                    StopEvent(activeEvent.AudioEvent.Name, gameObjectToStop, fadeOutTime);
                }
            }
        }
Exemple #18
0
            public static ActiveEvent FromExt(ActiveEventExt item)
            {
                var rv = new ActiveEvent()
                {
                    Start   = item.OriginalStart,
                    End     = item.End,
                    Hash    = item.Hash,
                    Key     = item.Key,
                    Payload = item.Payload
                };

                return(rv);
            }
        /// <summary>
        /// Stops the first (oldest) instance of an event with the matching name
        /// </summary>
        /// <param name="eventName">The name associated with the AudioEvent to stop.</param>
        private void KillOldestInstance(string eventName)
        {
            for (int i = 0; i < ActiveEvents.Count; i++)
            {
                ActiveEvent tempEvent = ActiveEvents[i];

                if (tempEvent.AudioEvent.Name == eventName)
                {
                    StopEvent(tempEvent);
                    return;
                }
            }
        }
Exemple #20
0
        public static void FinishEvent()
        {
            if (ActiveEvent != null)
            {
                ActiveEvent.AnnounceWinner();

                ActiveEvent = null;
                EventManager.ActiveEventIdentifier = null;
                TimedEventManager.CreateTimer("eventdeschedule", DateTime.UtcNow.AddDays(1), null);
            }

            EventManager.RegisteredCharacters.Clear();
        }
Exemple #21
0
        public void Update(GameTime gameTime, string EventName)
        {
            ListReturnValue.Clear();
            List <object> FollowingScriptResult = new List <object>();

            foreach (ScriptEvent ActiveEvent in ListEvent)
            {
                if (ActiveEvent.Name == EventName)
                {
                    ActiveEvent.OnCalled(gameTime, out FollowingScriptResult);
                    ListReturnValue.AddRange(FollowingScriptResult);
                }
            }
        }
        /// <summary>
        /// Begin playing a non-continuous container, loop if applicable.
        /// </summary>
        private void StartOneOffEvent(ActiveEvent activeEvent)
        {
            if (activeEvent.AudioEvent.Container.Looping)
            {
                StartCoroutine(PlayLoopingOneOffContainerCoroutine(activeEvent));
                activeEvent.ActiveTime = InfiniteLoop;
            }
            else
            {
                PlayOneOffContainer(activeEvent);
            }

            StartCoroutine(RecordEventInstanceCoroutine(activeEvent));
        }
        /// <summary>
        /// Calculates the estimated active time for an ActiveEvent playing the given clip.
        /// </summary>
        /// <param name="audioClip">The clip being played.</param>
        /// <param name="activeEvent">The event being played.</param>
        /// <param name="additionalDelay">The delay before playing in seconds.</param>
        /// <returns>The estimated active time of the event based on Looping or clip time. If Looping, this will return InfiniteLoop.</returns>
        private static float GetActiveTimeEstimate(UAudioClip audioClip, ActiveEvent activeEvent, float additionalDelay)
        {
            if (audioClip.Looping || activeEvent.AudioEvent.Container.Looping || additionalDelay == InfiniteLoop)
            {
                return(InfiniteLoop);
            }
            else
            {
                float pitchAdjustedClipLength = activeEvent.PrimarySource.pitch != 0 ? (audioClip.Sound.length / activeEvent.PrimarySource.pitch) : 0;

                // Restrict non-Looping ActiveTime values to be non-negative.
                return(Mathf.Max(0.0f, pitchAdjustedClipLength + activeEvent.AudioEvent.InstanceTimeBuffer + additionalDelay));
            }
        }
 public void AddActiveEvent(Event postedEvent, Component component)
 {
     if (component != null && (postedEvent.eventStatus == EventStatus.Handled || postedEvent.eventStatus == EventStatus.Handled_Virtualized))
     {
         ActiveEvent activeEvent = _activeEvents.Find((ActiveEvent x) => component == x._component);
         if (activeEvent == null)
         {
             activeEvent            = new ActiveEvent();
             activeEvent._eventName = postedEvent._eventName;
             activeEvent._component = component;
             _activeEvents.Add(activeEvent);
         }
     }
 }
        /// <summary>
        /// Stop audio sources in an event, and clean up instance references.
        /// </summary>
        /// <param name="activeEvent">The persistent reference to the event as long as it is playing.</param>
        protected void StopEvent(ActiveEvent activeEvent)
        {
            if (activeEvent.PrimarySource != null)
            {
                activeEvent.PrimarySource.Stop();
            }

            if (activeEvent.SecondarySource != null)
            {
                activeEvent.SecondarySource.Stop();
            }

            activeEvent.CancelEvent = true;
            RemoveEventInstance(activeEvent);
        }
        /// <summary>
        /// Repeatedly trigger the one-off container based on the loop time.
        /// </summary>
        private IEnumerator PlayLoopingOneOffContainerCoroutine(ActiveEvent activeEvent)
        {
            while (!activeEvent.CancelEvent)
            {
                float tempLoopTime  = PlayOneOffContainer(activeEvent);
                float eventLoopTime = activeEvent.AudioEvent.Container.LoopTime;

                // Protect against containers Looping every frame by defaulting to the length of the audio clip.
                if (eventLoopTime != 0)
                {
                    tempLoopTime = eventLoopTime;
                }

                yield return(new WaitForSeconds(tempLoopTime));
            }
        }
Exemple #27
0
        private string CreateEventId(NHibernate.IStatelessSession session, EventSummary summary, ushort Code)
        {
            int         num      = 0;
            ActiveEvent newEvt   = null;
            string      newEvtId = null;

            while (true)
            {
                newEvtId = $"{summary.SiteId}.{summary.DeviceName}.{Code}.{num++}";
                newEvt   = session.Get <ActiveEvent>(newEvtId);
                if (newEvt == null)
                {
                    break;
                }
            }
            return(newEvtId);
        }
        private string GetNextEventId(string evtId, ISession session)
        {
            int         num      = 0;
            ActiveEvent newEvt   = null;
            string      newEvtId = null;

            while (true)
            {
                newEvtId = $"{evtId}_{num++}";
                newEvt   = session.Get <ActiveEvent>(newEvtId);
                if (newEvt == null)
                {
                    break;
                }
            }
            return(newEvtId);
        }
        /// <summary>
        /// Sets the pitch value on active AudioEvents.
        /// </summary>
        /// <param name="eventName">The name associated with the AudioEvents.</param>
        /// <param name="newPitch">The value to set the pitch, between 0 (exclusive) and 3 (inclusive).</param>
        public void SetPitch(string eventName, float newPitch)
        {
            if (newPitch <= 0 || newPitch > 3)
            {
                Debug.LogErrorFormat(this, "Invalid pitch {0} set for event \"{1}\"", newPitch, eventName);
                return;
            }

            for (int i = ActiveEvents.Count - 1; i >= 0; i--)
            {
                ActiveEvent activeEvent = ActiveEvents[i];
                if (activeEvent.AudioEvent.Name == eventName)
                {
                    activeEvent.SetPitch(newPitch);
                }
            }
        }
 public void UpdateInternal()
 {
     profiler.Begin();
     for (int i = 0; i < _eventQueue.Count; i++)
     {
         Event @event = _eventQueue[i];
         if (@event.parentGameObject == null)
         {
             _eventQueue.RemoveAt(i);
         }
         else if (@event._delayTimer < @event._delay)
         {
             @event._delayTimer += FabricTimer.GetRealtimeDelta();
         }
         else if (ProcessEvent(@event))
         {
             _eventQueue.RemoveAt(i);
         }
     }
     _eventEditor.Update();
     _globalParameterManager.Update();
     if (Application.isEditor)
     {
         for (int j = 0; j < _activeEvents.Count; j++)
         {
             ActiveEvent activeEvent = _activeEvents[j];
             if (activeEvent._component == null || !activeEvent._component.IsComponentActive())
             {
                 if (activeEvent._time == 0f)
                 {
                     activeEvent._time = _activeEventPersistenceTime;
                 }
                 else
                 {
                     activeEvent._time -= FabricTimer.GetRealtimeDelta();
                 }
                 if (activeEvent._time <= 0f)
                 {
                     _activeEvents.Remove(activeEvent);
                     activeEvent._time = 0f;
                 }
             }
         }
     }
     profiler.End();
 }
        private void DispatcherUpdateDial(ActiveEvent activeEvent)
        {
            if (activeEvent.Type == "Yield" && (activeEvent.ReadingDescription == "Meter Yield" || activeEvent.ReadingDescription == "CC Yield"))
            {
                if (!GaugeCCYieldBound)
                {
                    BindGauge(gaugeCCYield, activeEvent, GaugeType.Yield, false);
                    GaugeCCYieldBound = true;
                }
                gaugeCCYield.DataContext = activeEvent;
            }
            else if (activeEvent.Type == "Consumption" && activeEvent.ReadingDescription == "Consumption")
            {
                if (!GaugeConsumptionBound)
                {
                    BindGauge(gaugeConsume, activeEvent, GaugeType.Consumption, false);
                    GaugeConsumptionBound = true;
                }
                gaugeConsume.DataContext = activeEvent;
            }
            else if (activeEvent.Type == "Yield" && (activeEvent.ReadingDescription == "Inverter Yield"
                || activeEvent.ReadingDescription == "Yield" || activeEvent.ReadingDescription == "Inverter_Yield"))
            {
                if (!GaugeYieldBound)
                {
                    BindGauge(gaugeYield, activeEvent, GaugeType.Yield, false);
                    GaugeYieldBound = true;
                }
                gaugeYield.DataContext = activeEvent;
            }
            else if (activeEvent.Type == "FeedIn")
            {
                if (!GaugeFeedInBound)
                {
                    BindGauge(gaugeFeedIn, activeEvent, GaugeType.FeedIn, false);
                    GaugeFeedInBound = true;
                }
                gaugeFeedIn.DataContext = activeEvent;
            }
            else
            {
                EnergyDisplayControls.PowerGauge gauge = GetDial(activeEvent.ReadingDescription);
                if (gauge == null)
                {
                    gauge = new EnergyDisplayControls.PowerGauge();
                    gauge.DialArc = 210.0;
                    gauge.DialWidth = 180.0;
                    gauge.DialRadiusY = 80;
                    gauge.Margin = new Thickness(4.0);
                    gauge.GaugeDescription = activeEvent.ReadingDescription;

                    if (activeEvent.Type == "Yield")
                    {
                        gauge.DialStyle = EnergyDisplayControls.DialVisualStyle.Generation;
                        BindGauge(gauge, activeEvent, GaugeType.Yield, true);
                    }
                    else if (activeEvent.Type == "Consumption")
                    {
                        gauge.DialStyle = EnergyDisplayControls.DialVisualStyle.Consumption;
                        BindGauge(gauge, activeEvent, GaugeType.Consumption, true);
                    }
                    else
                    {
                        gauge.DialStyle = EnergyDisplayControls.DialVisualStyle.Generic;
                        BindGauge(gauge, activeEvent, GaugeType.Unknown, true);
                    }

                    stackDials.Children.Add(gauge);
                }
                gauge.DataContext = activeEvent;
            }
        }
        private void BindGauge(EnergyDisplayControls.PowerGauge gauge, ActiveEvent activeEvent, GaugeType type, bool bindDescription)
        {
            gauge.DataContext = Subscriber;
            Binding binding = new Binding();
            binding.Source = activeEvent;
            binding.Path = new PropertyPath("CurrentPower");
            binding.Mode = BindingMode.TwoWay;
            gauge.SetBinding(EnergyDisplayControls.PowerGauge.Scale1ValueProperty, binding);

            binding = new Binding();
            binding.Source = Subscriber;
            if (type == GaugeType.Yield || type == GaugeType.FeedIn)
                binding.Path = new PropertyPath("MaxYield");
            else if (type == GaugeType.Consumption)
                binding.Path = new PropertyPath("MaxConsumption");
            else if (type == GaugeType.Unknown)
                binding.Path = new PropertyPath("MaxYield");
            binding.Mode = BindingMode.TwoWay;
            gauge.SetBinding(EnergyDisplayControls.PowerGauge.Scale1MaxProperty, binding);

            if (type == GaugeType.FeedIn)
            {
                binding = new Binding();
                binding.Source = Subscriber;
                binding.Path = new PropertyPath("MaxConsumptionNegative");
                binding.Mode = BindingMode.TwoWay;
                gauge.SetBinding(EnergyDisplayControls.PowerGauge.Scale1MinProperty, binding);
            }

            if (bindDescription)
            {
                binding = new Binding();
                binding.Source = activeEvent;
                binding.Path = new PropertyPath("ReadingDescription");
                binding.Mode = BindingMode.TwoWay;
                gauge.SetBinding(EnergyDisplayControls.PowerGauge.GaugeDescriptionProperty, binding);
            }
        }
 public void UpdateDial(ActiveEvent activeEvent)
 {
     this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate() { DispatcherUpdateDial(activeEvent); } );
 }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = new RequiredMessageHeader();
     Field0.Parse(buffer);
     Field1 = new ActiveEvent();
     Field1.Parse(buffer);
 }
 public override void Parse(GameBitBuffer buffer)
 {
     Field0 = new ActiveEvent();
     Field0.Parse(buffer);
 }