using System; using System.Collections.Generic; using Shared.Common; using Shared.Phone.Device.CommonForm; namespace Shared.Phone.Device.Category { public class SelectScene : FrameLayout { #region ◆ 变量____________________________ /// /// bodyFrameLayout /// private FrameLayout bodyFrameLayout; /// /// selectedTimeAction /// public Action selectedAction; /// /// sceneTargetDevice /// public SceneTargetDeviceUI sceneTargetDevice; /// /// BeforesceneTargetDeviceUIs /// public List beforeSceneTargetDeviceUIs = new List { }; /// /// 楼层 /// private Button floorBtn; /// /// 当前楼层id /// private string curFloorId; /// /// 选择楼层 /// private Button selectFloorBtn; /// /// 场景功能中部背景bodyView /// public FrameLayout functionSceneBodyView; /// /// sceneUI /// public SceneUI sceneUI; /// /// 当前场景本身,添加场景时使用 /// public SceneUI currentSceneUI; #endregion /// /// SelectScene /// public SelectScene() { BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; } /// /// Show /// public void Show() { if (sceneTargetDevice == null) { sceneTargetDevice = new SceneTargetDeviceUI { Type = 1 }; } AddTop(); AddBodyView(); RefreshBodyView(Config.Instance.Home.CurrentFloorId); } #region Add____________________________________ /// /// AddTop /// private void AddTop() { var top = new TopFrameLayout(); AddChidren(top); top.InitTopview(); top.SetTopTitle(R.MyInternationalizationString.AddScence); top.backButton.MouseUpEventHandler += (sender, e) => { RemoveFromParent(); }; floorBtn = new Button() { X = Application.GetRealWidth(750), Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(60), Gravity = Gravity.CenterVertical, TextAlignment = TextAlignment.CenterRight, TextColor = ZigbeeColor.Current.GXCTextBlackColor, TextSize = 14, IsBold = true }; selectFloorBtn = new Button() { X = Application.GetRealWidth(950), Width = Application.GetMinRealAverage(69), Height = Application.GetMinRealAverage(69), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Drop_Down.png" }; if (Config.Instance.Home.FloorDics.Count > 0) { floorBtn.Text = Config.Instance.Home.GetCurrentFloorName; top.topView.AddChidren(floorBtn); top.topView.AddChidren(selectFloorBtn); floorBtn.MouseUpEventHandler += SelectedFloor_MouseUpEventHandler; selectFloorBtn.MouseUpEventHandler += SelectedFloor_MouseUpEventHandler; } } /// /// 选择楼层 /// /// Sender. /// The ${ParameterType} instance containing the event data. private void SelectedFloor_MouseUpEventHandler(object sender, MouseEventArgs mouseEventArgs) { var floors = new SelectFloor(); AddChidren(floors); floors.changeFloor = false; floors.CurFloorId = curFloorId; floors.Init(580, 184, Direction.Right); floors.FloorAction += (floorId) => { curFloorId = floorId; floorBtn.Text = Config.Instance.Home.GetFloorNameById(floorId); RefreshBodyView(floorId); }; } /// /// AddBodyView /// private void AddBodyView() { bodyFrameLayout = new FrameLayout() { Y = Application.GetRealHeight(184), Height = Application.GetRealHeight(1737), BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor, }; AddChidren(bodyFrameLayout); var confirmBtn = new CommonForm.CompleteButton(1656, 907, 127); AddChidren(confirmBtn); confirmBtn.SetTitle(R.MyInternationalizationString.Save); confirmBtn.MouseUpEventHandler += (sender, e) => { sceneTargetDevice.ElseScenesId = sceneUI.Id; sceneTargetDevice.SceneUI = sceneUI; sceneTargetDevice.SceneName = sceneUI.Name; selectedAction?.Invoke(sceneTargetDevice); RemoveFromParent(); }; } #endregion /// /// RefreshBodyView /// private void RefreshBodyView(string floorId) { AddRoomView(floorId); } /// /// AddRoomView /// private void AddRoomView(string floorId) { var roomFL = new HorizontalScrolViewLayout() { X = Application.GetRealWidth(CommonFormResouce.X_Left), Height = Application.GetRealHeight(204), Width = Application.GetRealWidth(CommonPage.AppRealWidth - CommonFormResouce.X_Left), BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor }; bodyFrameLayout.AddChidren(roomFL); //功能和场景bodyView functionSceneBodyView = new FrameLayout() { Y = roomFL.Bottom, Height = Application.GetRealHeight(1080 + 452), BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor }; bodyFrameLayout.AddChidren(functionSceneBodyView); RoomButton curBtn = new RoomButton(0,0); foreach (var room in Common.Room.CurrentRoom.GetRoomsByFloorIdAppendLoveRoom(floorId)) { var row = new FrameLayout() { Width = Application.GetRealWidth(255), Height = Application.GetRealHeight(167) }; roomFL.AddChidren(row); RoomButton roomBtn = new RoomButton(0, 0); roomBtn.Gravity = Gravity.Center; roomBtn.Init(); roomBtn.SetTitle(room.Name); row.AddChidren(roomBtn); if (room.IsLove) { roomBtn.IsSelected = true; curBtn = roomBtn; RefreshScene(room); } roomBtn.ButtonClickEvent += (sender, e) => { if (sender == curBtn) { return; } sender.IsSelected = true; curBtn.IsSelected = false; curBtn = sender; RefreshScene(room); }; } } /// /// RefreshScene /// /// public void RefreshScene(Common.Room room) { functionSceneBodyView.RemoveAll(); var sceneList = room.SceneUIList; if (sceneList.Count == 0) { ShowNoSceneTip(); } else { var sceneScrolView = new VerticalScrolViewLayout { //Y = Application.GetRealHeight(58) }; functionSceneBodyView.AddChidren(sceneScrolView); SelectSceneRow tempSceneRow = new SelectSceneRow(); EventHandler selectScene = (sender, e) => { tempSceneRow.IsSelected = false; tempSceneRow = ((sender as Button).Parent as SelectSceneRow); ((sender as Button).Parent as SelectSceneRow).IsSelected = true; tempSceneRow.IsSelected = true; sceneUI = (sender as Button).Tag as SceneUI; }; for (int i = 0; i < sceneList.Count; i++) { var scene = sceneList[i]; if (currentSceneUI?.Id == scene.Id) { continue; } if (beforeSceneTargetDeviceUIs.Find((obj) => obj.SceneUI.Id == scene.Id) != null) { continue; } var sceneFL = new FrameLayout() { Height = Application.GetRealHeight(127 + 23), BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, Tag = scene }; sceneScrolView.AddChidren(sceneFL); var sceneRowLayout = new SelectSceneRow(0, 23); sceneFL.AddChidren(sceneRowLayout); sceneRowLayout.Init(); sceneRowLayout.SetTitle(scene.Name); sceneRowLayout.ClickButton.Tag = scene; if (sceneUI == null) { if (i == 0) { tempSceneRow = sceneRowLayout; sceneUI = scene; sceneRowLayout.IsSelected = true; } } else { if (sceneUI.Id == scene.Id) { tempSceneRow = sceneRowLayout; sceneUI = scene; sceneRowLayout.IsSelected = true; } } sceneRowLayout.ClickButton.MouseUpEventHandler += selectScene; } if (sceneList.Count > 8) { var frame = new FrameLayout { Height = Application.GetRealHeight(300) }; sceneScrolView.AddChidren(frame); } } } /// /// 显示没有场景 /// private void ShowNoSceneTip() { var noFunction = new Button() { Y = Application.GetRealHeight(320), Width = Application.GetMinRealAverage(757), Height = Application.GetMinRealAverage(435), UnSelectedImagePath = "Item/NoFunction.png", Gravity = Gravity.CenterHorizontal }; functionSceneBodyView.AddChidren(noFunction); var noScenceTip = new Button() { Y = noFunction.Bottom + Application.GetRealHeight(32), Height = Application.GetRealHeight(200), Width = Application.GetRealWidth(700), Gravity = Gravity.CenterHorizontal, Text = Language.StringByID(R.MyInternationalizationString.NoScene_Tip).Replace("{\\r\\n}", "\r\n"), TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextAlignment = TextAlignment.Center, IsMoreLines = true }; functionSceneBodyView.AddChidren(noScenceTip); } } }