protected void AddOnOffUpDownCombination(Transform layoutGroup, List <DeviceFunctionality> onOffUpDownFunc) { DeviceFunctionality onCommandFunc = onOffUpDownFunc .Where(f => f.Commands.Any(c => TYPE_ON_COMMAND == c.CommandType)) .First(); DeviceFunctionality offCommandFunc = onOffUpDownFunc .Where(f => f.Commands.Any(c => TYPE_OFF_COMMAND == c.CommandType)) .First(); DeviceFunctionality upCommandFunc = onOffUpDownFunc .Where(f => f.Commands.Any(c => TYPE_UP_COMMAND == c.CommandType)) .First(); DeviceFunctionality downCommandFunc = onOffUpDownFunc .Where(f => f.Commands.Any(c => TYPE_DOWN_COMMAND == c.CommandType)) .First(); //buttons are visible in this order from top to bottom GameObject btnObject = Instantiate(PrefabHolder.Instance.devices.onOffUpDownButton); OnOffUpDownButton btnScript = btnObject.GetComponent <OnOffUpDownButton>(); btnScript.SetDownButtonData(downCommandFunc.ItemId, downCommandFunc.Commands.First(c => TYPE_DOWN_COMMAND == c.CommandType).RealCommandName); btnScript.SetUpButtonData(upCommandFunc.ItemId, upCommandFunc.Commands.First(c => TYPE_UP_COMMAND == c.CommandType).RealCommandName); btnScript.SetOnButtonData(onCommandFunc.ItemId, onCommandFunc.Commands.First(c => TYPE_ON_COMMAND == c.CommandType).RealCommandName); btnScript.SetOffButtonData(offCommandFunc.ItemId, offCommandFunc.Commands.First(c => TYPE_OFF_COMMAND == c.CommandType).RealCommandName); btnObject.transform.SetParent(layoutGroup, false); }
private void AddButtonsToGroup(IGrouping <string, DeviceFunctionality> funcs) { GroupBoxHolder holder = GetHolderById(funcs.Key); List <DeviceFunctionality> onOffUpDown = GetOffUpDownFunctionalities(funcs.ToList()); if (onOffUpDown.Count > 0) { AddOnOffUpDownCombination(holder.transform, onOffUpDown); } DeviceFunctionality colorFunc = funcs.Where(f => FUNC_TYPE_COLOR_CONTROL == f.FunctionalityType).FirstOrDefault(); if (colorFunc != null) { AddColorButtons(colorFunc, holder.transform); } //foreach (var func in funcs) //{ // if (onOffUpDown.Contains(func)) continue; // if (func.Commands == null) continue; // foreach (var cmd in func.Commands) // { // SpawnButton(func, cmd, holder.transform); // } //} }
protected bool AddButtonsToLayoutGroup(Transform layoutGroup, DeviceInfo info) { if (layoutGroup == null || layoutGroup.GetComponent <VerticalLayoutGroup>() == null) { return(false); } List <DeviceFunctionality> onOffUpDownFunc = GetOffUpDownFunctionalities(info); if (onOffUpDownFunc.Any()) { AddOnOffUpDownCombination(layoutGroup, onOffUpDownFunc); } DeviceFunctionality colorFunc = info.Functionalities.Where(f => FUNC_TYPE_COLOR_CONTROL == f.FunctionalityType).FirstOrDefault(); if (colorFunc != null) { AddColorButtons(colorFunc, layoutGroup); } //foreach (var func in info.Functionalities) //{ // if (onOffUpDownFunc.Contains(func)) continue; // if (func.Commands == null) continue; // foreach (var cmd in func.Commands) // { // SpawnButton(func, cmd, layoutGroup); // } //} return(true); }
public void SetFunctionality(DeviceFunctionality func) { if (redBtn == null) { InitButtons(); } redBtn.DeviceId = func.ItemId; redBtn.RealCommandName = "359,100,100"; purpleBtn.DeviceId = func.ItemId; purpleBtn.RealCommandName = "302,96,100"; blueBtn.DeviceId = func.ItemId; blueBtn.RealCommandName = "240,100,100"; greenBtn.DeviceId = func.ItemId; greenBtn.RealCommandName = "125,100,100"; yellowBtn.DeviceId = func.ItemId; yellowBtn.RealCommandName = "60,100,100"; whiteBtn.DeviceId = func.ItemId; whiteBtn.RealCommandName = "0,0,100"; }
private DeviceInfo CreateHomematicDimmer() { DeviceInfo homematicDimmer = new DeviceInfo() { Uid = "homematic_dimmer_1", DisplayName = "Homematic Dimmer" }; GroupBox box = new GroupBox() { Uid = "box_dimmer_1", Name = "Dimmer 1", IconName = "dimmer" }; DeviceCommand onCommand = new DeviceCommand() { Name = "DEFAULT_ON_COMMAND", RealCommandName = "ON", CommandType = "dogont:OnCommand" }; DeviceCommand offCommand = new DeviceCommand() { Name = "DEFAULT_OFF_COMMAND", RealCommandName = "OFF", CommandType = "dogont:OffCommand" }; DeviceCommand upCommand = new DeviceCommand() { Name = "DEFAULT_UP_COMMAND", RealCommandName = "UP", CommandType = "dogont:UpCommand" }; DeviceCommand downCommand = new DeviceCommand() { Name = "DEFAULT_DOWN_COMMAND", RealCommandName = "DOWN", CommandType = "dogont:DownCommand" }; DeviceFunctionality f1 = new DeviceFunctionality() { FunctionalityType = "dogont:LevelControlFunctionality", ItemId = "homematic_dimmer_dimmer_1", Commands = new[] { onCommand, offCommand, upCommand, downCommand }, GroupBox = box }; homematicDimmer.Functionalities = new[] { f1 }; homematicDimmer.GroupBoxes = new[] { box }; return(homematicDimmer); }
protected void AddColorButtons(DeviceFunctionality colorFunc, Transform target) { GameObject colorPickerPrefab = PrefabHolder.Instance.devices.poorColorPicker; GameObject colorPicker = Instantiate(colorPickerPrefab); colorPicker.transform.SetParent(target, false); colorPicker.SetActive(true); DefaultColorPickerButton btn = colorPicker.GetComponent <DefaultColorPickerButton>(); btn.SetFunctionality(colorFunc); }
protected GameObject SpawnButton(DeviceFunctionality functionality, DeviceCommand command, Transform parent) { GameObject buttonPrefab = GetTypeSpecificButtonPrefab(command); GameObject buttonInstance = Instantiate(buttonPrefab); buttonInstance.transform.SetParent(parent, false); DefaultDeviceButtonBehavior behavior = buttonInstance.GetComponent <DefaultDeviceButtonBehavior>(); behavior.CommandDisplayName = command.Name; behavior.RealCommandName = command.RealCommandName; behavior.DeviceId = functionality.ItemId; return(buttonInstance); }
//TODO create Hue stuff private DeviceInfo CreateHue() { DeviceInfo info = new DeviceInfo() { DisplayName = "Hue Bulb 1", Uid = "hue_bulb210_1" }; GroupBox box = new GroupBox() { Uid = "box_hue_1", Name = "Hue Bulb 1", IconName = "color_light" }; DeviceState state = new DeviceState() { ItemId = "hue_bulb210_light_1", Label = "State", RealStateValue = "OFF", GroupBox = box }; DeviceCommand onCommand = new DeviceCommand() { Name = "DEFAULT_ON_COMMAND", RealCommandName = "ON", CommandType = "dogont:OnCommand" }; DeviceCommand offCommand = new DeviceCommand() { Name = "DEFAULT_OFF_COMMAND", RealCommandName = "OFF", CommandType = "dogont:OffCommand" }; DeviceCommand upCommand = new DeviceCommand() { Name = "DEFAULT_UP_COMMAND", RealCommandName = "INCREASE", CommandType = "dogont:UpCommand" }; DeviceCommand downCommand = new DeviceCommand() { Name = "DEFAULT_DOWN_COMMAND", RealCommandName = "DECREASE", CommandType = "dogont:DownCommand" }; DeviceCommand colorCommand = new DeviceCommand() { Name = "DEFAULT_COLOR_COMMAND", RealCommandName = "359,100,100", CommandType = "dogont:SetColorHSBCommand" }; DeviceFunctionality lightOnOff = new DeviceFunctionality() { FunctionalityType = "dogont:OnOffFunctionality", Commands = new[] { onCommand, offCommand }, ItemId = "hue_bulb210_light_1", GroupBox = box }; DeviceFunctionality lightDimm = new DeviceFunctionality() { FunctionalityType = "dogont:LevelControlFunctionality", Commands = new[] { upCommand, downCommand }, ItemId = "hue_bulb210_dimmer_1", GroupBox = box }; DeviceFunctionality color = new DeviceFunctionality() { FunctionalityType = "dogont:ColorControlFunctionality", Commands = new[] { colorCommand }, ItemId = "hue_bulb210_color_1", GroupBox = box }; info.Functionalities = new[] { lightOnOff, lightDimm, color }; info.States = new[] { state }; info.GroupBoxes = new[] { box }; return(info); }