mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-11 19:44:52 +00:00
Refactors all references to EssentialsRoomBase and EssentialsHuddleSpaceRoom to use the new interfaces instead
94 lines
2.5 KiB
C#
94 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Crestron.SimplSharp;
|
|
using Crestron.SimplSharpPro;
|
|
using Crestron.SimplSharpPro.DeviceSupport;
|
|
|
|
using PepperDash.Essentials.Core;
|
|
using PepperDash.Essentials.Core.SmartObjects;
|
|
|
|
namespace PepperDash.Essentials
|
|
{
|
|
public class SmartObjectRoomsList : SmartObjectDynamicList
|
|
{
|
|
public uint StatusSigOffset { get; private set; }
|
|
List<SmartObjectRoomsListItem> Items;
|
|
|
|
public SmartObjectRoomsList(SmartObject so, uint nameSigOffset, uint statusSigOffset)
|
|
: base(so, true, nameSigOffset)
|
|
{
|
|
StatusSigOffset = statusSigOffset;
|
|
Items = new List<SmartObjectRoomsListItem>();
|
|
}
|
|
|
|
public void AddRoomItem(SmartObjectRoomsListItem item)
|
|
{
|
|
Items.Add(item);
|
|
}
|
|
|
|
public void SetItemStatusText(uint index, string text)
|
|
{
|
|
if (index > MaxCount) return;
|
|
// The list item template defines CIPS tags that refer to standard joins
|
|
(SmartObject.Device as BasicTriList).StringInput[StatusSigOffset + index].StringValue = text;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets feedback for the given room
|
|
/// </summary>
|
|
public void SetFeedbackForRoom(IEssentialsHuddleSpaceRoom room)
|
|
{
|
|
var itemToSet = Items.FirstOrDefault(i => i.Room == room);
|
|
if (itemToSet != null)
|
|
SetFeedback(itemToSet.Index, true);
|
|
}
|
|
}
|
|
|
|
public class SmartObjectRoomsListItem
|
|
{
|
|
public IEssentialsHuddleSpaceRoom Room { get; private set; }
|
|
SmartObjectRoomsList Parent;
|
|
public uint Index { get; private set; }
|
|
|
|
public SmartObjectRoomsListItem(IEssentialsHuddleSpaceRoom room, uint index, SmartObjectRoomsList parent,
|
|
Action<bool> buttonAction)
|
|
{
|
|
Room = room;
|
|
Parent = parent;
|
|
Index = index;
|
|
if (room == null) return;
|
|
|
|
// Set "now" states
|
|
parent.SetItemMainText(index, room.Name);
|
|
UpdateItem(room.CurrentSourceInfo);
|
|
// Watch for later changes
|
|
room.CurrentSourceChange += new SourceInfoChangeHandler(room_CurrentSourceInfoChange);
|
|
parent.SetItemButtonAction(index, buttonAction);
|
|
}
|
|
|
|
void room_CurrentSourceInfoChange(SourceListItem info, ChangeType type)
|
|
{
|
|
UpdateItem(info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper to handle source events and startup syncing with room's current source
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
void UpdateItem(SourceListItem info)
|
|
{
|
|
if (info == null || info.Type == eSourceListItemType.Off)
|
|
{
|
|
Parent.SetItemStatusText(Index, "");
|
|
Parent.SetItemIcon(Index, "Blank");
|
|
}
|
|
else
|
|
{
|
|
Parent.SetItemStatusText(Index, info.PreferredName);
|
|
Parent.SetItemIcon(Index, info.AltIcon);
|
|
}
|
|
}
|
|
}
|
|
} |