using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.UI; using PepperDash.Essentials.Core; namespace PepperDash.Essentials { public class SubpageReferenceListSourceItem : SubpageReferenceListItem { public SourceListItem SourceItem { get; private set; } private IHasCurrentSourceInfoChange _room; public SubpageReferenceListSourceItem(uint index, SubpageReferenceList owner, SourceListItem sourceItem, Action routeAction) : base(index, owner) { SourceItem = sourceItem; owner.GetBoolFeedbackSig(index, 1).UserObject = new Action(routeAction); owner.StringInputSig(index, 1).StringValue = SourceItem.PreferredName; } public void RegisterForSourceChange(IHasCurrentSourceInfoChange room) { _room = room; room.CurrentSourceChange -= room_CurrentSourceInfoChange; room.CurrentSourceChange += room_CurrentSourceInfoChange; } void room_CurrentSourceInfoChange(SourceListItem info, ChangeType type) { if (type == ChangeType.WillChange && info == SourceItem) ClearFeedback(); else if (type == ChangeType.DidChange && info == SourceItem) SetFeedback(); } /// /// Called by SRL to release all referenced objects /// public override void Clear() { Owner.BoolInputSig(Index, 1).UserObject = null; Owner.StringInputSig(Index, 1).StringValue = ""; if(_room != null) _room.CurrentSourceChange -= room_CurrentSourceInfoChange; } /// /// Sets the selected feedback on the button /// public void SetFeedback() { Owner.BoolInputSig(Index, 1).BoolValue = true; } /// /// Clears the selected feedback on the button /// public void ClearFeedback() { Owner.BoolInputSig(Index, 1).BoolValue = false; } } }