From c3e1b733fc45bd9f0b88bfb560cfa87a270b079b Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期三, 09 九月 2020 17:33:58 +0800
Subject: [PATCH] 20200909

---
 HDL_ON/UI/UI2/3-Intelligence/SceneEditPage.cs |  274 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 221 insertions(+), 53 deletions(-)

diff --git a/HDL_ON/UI/UI2/3-Intelligence/SceneEditPage.cs b/HDL_ON/UI/UI2/3-Intelligence/SceneEditPage.cs
index 1566968..9504644 100644
--- a/HDL_ON/UI/UI2/3-Intelligence/SceneEditPage.cs
+++ b/HDL_ON/UI/UI2/3-Intelligence/SceneEditPage.cs
@@ -2,6 +2,7 @@
 using HDL_ON.UI.CSS;
 using Shared;
 using HDL_ON.Entity;
+using System.Collections.Generic;
 
 namespace HDL_ON.UI
 {
@@ -17,10 +18,24 @@
         /// </summary>
         VerticalScrolViewLayout functionListView;
         /// <summary>
+        /// 鍦烘櫙鍚嶇Оrow
+        /// </summary>
+        FrameLayout sceneNameView;
+
+        /// <summary>
         /// 鍦烘櫙鍚嶇О鏄剧ず鏂囨湰
         /// </summary>
-        EditText etSceneName;
+        Button btnSceneName;
+        /// <summary>
+        /// 鍦烘櫙鍚嶇О淇敼鍥炬爣
+        /// </summary>
+        Button btnEditSceneNameIcon;
 
+        /// <summary>
+        /// 鎵�灞炲尯鍩焤ow
+        /// </summary>
+        FrameLayout belongToZoneRow;
+        Button btnBelongToZoneRight;
         Button btnZoneName;
 
         Button btnAddFunctionTitle;
@@ -73,17 +88,30 @@
             bodyView = this;
             scene = s;
             backAction = act;
+
+
+            refreshFunctionRowAction = () => {
+                LoadFunctionRow(functionListView);
+            };
+        }
+
+        public void LoadPage(int titleId,Action backRefresh)
+        {
+            pageTitleId = titleId;
+            new TopViewDiv(bodyView, Language.StringByID(pageTitleId)).LoadTopView(backRefresh);
+            initPage();
         }
 
         public void LoadPage(int titleId)
         {
-            refreshFunctionRowAction = () => {
-                LoadFunctionRow(functionListView);
-            };
-
-            bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
             pageTitleId = titleId;
             new TopViewDiv(bodyView, Language.StringByID(pageTitleId)).LoadTopView();
+            initPage();
+        }
+
+        void initPage()
+        {
+            bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
 
             VerticalScrolViewLayout contentView = new VerticalScrolViewLayout()
             {
@@ -91,25 +119,13 @@
                 Height = Application.GetRealHeight(603-50),
             };
             bodyView.AddChidren(contentView);
-
-            Button btnBaseInfoText = new Button()
-            {
-                X = Application.GetRealWidth(16),
-                Height = Application.GetRealWidth(46),
-                TextAlignment = TextAlignment.CenterLeft,
-                TextColor = CSS_Color.FirstLevelTitleColor,
-                TextID = StringId.BaseInfo,
-                TextSize = CSS_FontSize.SubheadingFontSize,
-                BackgroundColor = CSS_Color.MainBackgroundColor,
-            };
-            contentView.AddChidren(btnBaseInfoText);
+            contentView.AddChidren(new Button() { Height = Application.GetRealWidth(12) });
 
             FrameLayout sceneBgView = new FrameLayout()
             {
                 Gravity = Gravity.CenterHorizontal,
-                Y = btnBaseInfoText.Bottom,
-                Width = Application.GetRealWidth(343),
-                Height = Application.GetRealWidth(184),
+                Width = Application.GetRealWidth(252),
+                Height = Application.GetRealWidth(188 + 24),
                 Radius = (uint)Application.GetRealWidth(12),
                 BackgroundColor = CSS_Color.MainBackgroundColor,
             };
@@ -124,10 +140,8 @@
             };
             sceneBgView.AddChidren(addSceneImageView);
 
-            contentView.AddChidren(new Button() { Height = Application.GetRealWidth(16) ,BackgroundColor = CSS_Color.MainBackgroundColor});
-
             #region 鍦烘櫙鍚嶇Оrow
-            FrameLayout sceneNameView = new FrameLayout()
+            sceneNameView = new FrameLayout()
             {
                 Height = Application.GetRealWidth(50),
             };
@@ -144,15 +158,26 @@
             };
             sceneNameView.AddChidren(btnSceneTitle);
 
-            etSceneName = new EditText()
+            btnEditSceneNameIcon = new Button()
             {
-                X = btnSceneTitle.Right,
-                TextAlignment = TextAlignment.CenterLeft,
-                TextColor = CSS_Color.TextualColor,
+                X = Application.GetRealWidth(333),
+                Gravity = Gravity.CenterVertical,
+                Width = Application.GetMinRealAverage(28),
+                Height = Application.GetMinRealAverage(28),
+                UnSelectedImagePath = "Public/EditIcon.png",
+            };
+            sceneNameView.AddChidren(btnEditSceneNameIcon);
+
+            btnSceneName = new Button()
+            {
+                X = Application.GetRealWidth(100),
+                Width = Application.GetRealWidth(230),
+                TextAlignment = TextAlignment.CenterRight,
+                TextColor = CSS_Color.PromptingColor1,
                 TextSize = CSS_FontSize.TextFontSize,
                 Text = scene.name
             };
-            sceneNameView.AddChidren(etSceneName);
+            sceneNameView.AddChidren(btnSceneName);
 
             Button btnSceneNameLine = new Button()
             {
@@ -166,7 +191,7 @@
             #endregion
 
             #region 鎵�灞炲尯鍩焤ow
-            FrameLayout belongToZoneRow = new FrameLayout()
+            belongToZoneRow = new FrameLayout()
             {
                 Y = sceneNameView.Bottom,
                 Height = Application.GetRealWidth(50),
@@ -184,7 +209,7 @@
             };
             belongToZoneRow.AddChidren(btnBelongToTitle);
 
-            Button btnBelongToZoneRight = new Button()
+            btnBelongToZoneRight = new Button()
             {
                 X = Application.GetRealWidth(339),
                 Gravity = Gravity.CenterVertical,
@@ -196,9 +221,10 @@
 
             btnZoneName = new Button()
             {
-                X = btnSceneTitle.Right,
-                TextAlignment = TextAlignment.CenterLeft,
-                TextColor = CSS_Color.TextualColor,
+                X = Application.GetRealWidth(100),
+                Width = Application.GetRealWidth(230),
+                TextAlignment = TextAlignment.CenterRight,
+                TextColor = CSS_Color.PromptingColor1,
                 TextSize = CSS_FontSize.TextFontSize,
                 Text = scene.GetRoomListName() == "" ? Language.StringByID(StringId.WholeHouseScene) : scene.GetRoomListName()
             };
@@ -332,14 +358,14 @@
 
             btnComplete = new Button()
             {
-                Y = Application.GetRealHeight(667-50),
+                Y = Application.GetRealHeight(667 - 50),
                 Height = Application.GetRealHeight(50),
                 TextAlignment = TextAlignment.Center,
-                TextColor = CSS_Color.MainColor,
+                TextColor = pageTitleId == StringId.NewScene ? CSS_Color.MainColor : CSS_Color.WarningColor,
                 TextSize = CSS_FontSize.SubheadingFontSize,
-                TextID = StringId.Complete,
+                TextID = pageTitleId == StringId.NewScene ? StringId.Complete : StringId.Del,
                 BackgroundColor = CSS_Color.MainBackgroundColor,
-                IsBold = true
+                //IsBold = true
             };
             bodyView.AddChidren(btnComplete);
 
@@ -451,6 +477,21 @@
                 };
 
 
+                Button btnDelSceneFunction = new Button() {
+                    BackgroundColor = CSS_Color.WarningColor,
+                    TextColor = CSS_Color.MainBackgroundColor,
+                    TextID = StringId.Del,
+                };
+                row.AddRightView(btnDelSceneFunction);
+                btnDelSceneFunction.MouseUpEventHandler = (sender, e) => {
+                    scene.sceneFunctionList.Remove(function);
+                    scene.SaveFunctionData();
+                    row.RemoveFromParent();
+                    functionListView.Height = Application.GetRealWidth(65 * scene.sceneFunctionList.Count);
+                    //LoadFunctionRow(functionListView);
+                };
+
+
             }
         }
 
@@ -464,7 +505,9 @@
             if (sceneFunction.trait_on_off.value.ToString() == "off")
                 return sceneFunctionInfo;
             sceneFunctionInfo = "";
-            switch(sceneFunction.functionType)
+            Trait perTrait;
+
+            switch (sceneFunction.functionType)
             {
                 case FunctionType.AC:
                     var addAC = sceneFunction as AC;
@@ -478,19 +521,43 @@
                          sceneFunction.function.Find((obj) => obj.name == "temperature").uintString;
                     break;
                 case FunctionType.Dimmer:
-                    sceneFunctionInfo += Language.StringByID(StringId.Brightness) + " " + sceneFunction.function.Find((obj) => obj.name == "brightness").value.ToString() + "%";
+                    perTrait = sceneFunction.function.Find((obj) => obj.name == "percent");
+                    if (perTrait != null)
+                    {
+                        sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.function.Find((obj) => obj.name == "brightness").value.ToString() + "%";
+                    }
+                    else
+                    {
+                        sceneFunctionInfo += Language.StringByID(StringId.Open);
+                    }
                     break;
                 case FunctionType.Relay:
                     sceneFunctionInfo += Language.StringByID(StringId.Open);
                     break;
                 case FunctionType.RGB:
-                    sceneFunctionInfo += Language.StringByID(StringId.Brightness) + " " + sceneFunction.function.Find((obj) => obj.name == "brightness").value.ToString() + "%";
+                    perTrait = sceneFunction.function.Find((obj) => obj.name == "percent");
+                    if (perTrait != null)
+                    {
+                        sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.function.Find((obj) => obj.name == "brightness").value.ToString() + "%";
+                    }
+                    else
+                    {
+                        sceneFunctionInfo += Language.StringByID(StringId.Open);
+                    }
                     break;
                 case FunctionType.Curtain:
                     sceneFunctionInfo += Language.StringByID(StringId.Open);
                     break;
                 case FunctionType.MotorCurtain:
-                    sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.function.Find((obj) => obj.name == "percent").value.ToString() + "%";
+                    perTrait = sceneFunction.function.Find((obj) => obj.name == "percent");
+                    if (perTrait != null)
+                    {
+                        sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.function.Find((obj) => obj.name == "percent").value.ToString() + "%";
+                    }
+                    else
+                    {
+                        sceneFunctionInfo += Language.StringByID(StringId.Open);
+                    }
                     break;
             }
             return sceneFunctionInfo;
@@ -537,7 +604,7 @@
             };
             optionView.AddChidren(btnDefaultGallery);
 
-            optionView.AddChidren(new Button() { X = Application.GetRealWidth(16), Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor });
+            optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor });
 
             btnTakePicture = new Button()
             {
@@ -594,6 +661,7 @@
             LoadEvent_ChangeSceneZone();
             LoadEvent_ChangeFunctionList();
             LoadEvent_CompleteEvent();
+            LoadEvent_EditRoomName();
         }
 
         /// <summary>
@@ -601,7 +669,7 @@
         /// </summary>
         void LoadEvent_ChangeSceneZone()
         {
-            btnZoneName.MouseUpEventHandler = (sender, e) =>
+            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
             {
                 Action backAction = () => {
                     btnZoneName.Text = scene.GetRoomListName();
@@ -611,6 +679,10 @@
                 ssl.LoadPage();
                 MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
             };
+            btnZoneName.MouseUpEventHandler = eventHandler;
+            belongToZoneRow.MouseUpEventHandler = eventHandler;
+            btnBelongToZoneRight.MouseUpEventHandler = eventHandler;
+
         }
 
         /// <summary>
@@ -669,8 +741,11 @@
                         scene.ImagePath = addSceneImageView.ImagePath;
                         MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath);
                     }
-                }, pid.ToString(), 16, 9);
-                scene.SaveFunctionData();
+                }, pid.ToString(), 4, 3);
+                if (pageTitleId == StringId.EditScene)
+                {
+                    scene.SaveFunctionData();
+                }
                 pictureOptionView.Parent.RemoveFromParent();
             };
             btnAlbum.MouseDownEventHandler = (sender, e) => {
@@ -689,24 +764,117 @@
                         scene.ImagePath = addSceneImageView.ImagePath;
                         MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath);
                     }
-                }, pid.ToString(), 16, 9);
+                }, pid.ToString(), 4, 3);
+                if (pageTitleId == StringId.EditScene)
+                {
                     scene.SaveFunctionData();
+                }
                 pictureOptionView.Parent.RemoveFromParent();
             };
+
+            btnDefaultGallery.MouseUpEventHandler = (sender, e) => {
+                pictureOptionView.Parent.RemoveFromParent();
+                Action<string> action = (obj) => {
+                    scene.ImagePath = obj;
+                    addSceneImageView.ImagePath = scene.ImagePath;
+                    if (pageTitleId == StringId.EditScene)
+                    {
+                        scene.SaveFunctionData();
+                    }
+                };
+
+                var galleryPage = new GalleryPage(scene.ImagePath,action);
+                MainPage.BasePageView.AddChidren(galleryPage);
+                galleryPage.LoadPage(true);
+                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+            };
+
         }
 
         /// <summary>
-        /// 鎸夐挳鎸夐挳鐐瑰嚮浜嬩欢
+        /// 瀹屾垚鎸夐挳鐐瑰嚮浜嬩欢
         /// </summary>
         void LoadEvent_CompleteEvent()
         {
-            btnComplete.MouseUpEventHandler = (sender, e) =>
+            btnComplete.MouseUpEventHandler += (sender, e) =>
             {
-                scene.SaveFunctionData();
-                DB_ResidenceData.functionList.scenes.Add(scene);
-                this.RemoveFromParent();
-                backAction();
+                if (btnComplete.TextID == StringId.Complete)
+                {
+                    if (string.IsNullOrEmpty(scene.name))
+                    {
+                        new Tip()
+                        {
+                            CloseTime = 1,
+                            Text = Language.StringByID(StringId.SceneNameCannotBeEmpty),
+                            Direction = AMPopTipDirection.None,
+                        }.Show(bodyView);
+                        return;
+                    }
+                    foreach (var tempRoom in DB_ResidenceData.functionList.scenes)
+                    {
+                        if (scene.name == tempRoom.name)
+                        {
+                            new PublicAssmebly().TipMsg(StringId.Tip, StringId.SceneNameAlreadyExists);
+                            return;
+                        }
+                    }
+                    scene.SaveFunctionData();
+                    DB_ResidenceData.functionList.scenes.Add(scene);
+                    backAction();
+                    this.RemoveFromParent();
+                }
+                if (btnComplete.TextID == StringId.Del)
+                {
+                    Action action = () =>
+                    {
+                        DB_ResidenceData.DelSceneFunction(scene.sid);
+                        backAction();
+                        this.RemoveFromParent();
+                    };
+                    new PublicAssmebly().TipMsg(StringId.Tip, StringId.DeleteSceneTip, action);
+                };
             };
         }
+
+
+        /// <summary>
+        /// 鍔犺浇淇敼鍦烘櫙鍚嶇О绐楀彛浜嬩欢
+        /// </summary>
+        void LoadEvent_EditRoomName()
+        {
+            Action<string> callBack = (str) =>
+            {
+                //鍚嶇О涓嶈兘涓虹┖
+                if (string.IsNullOrEmpty(str))
+                {
+                    new Tip()
+                    {
+                        CloseTime = 1,
+                        Text = Language.StringByID(StringId.SceneNameCannotBeEmpty),
+                        Direction = AMPopTipDirection.None,
+                    }.Show(bodyView);
+                    return;
+                }
+                btnSceneName.Text = str;
+                scene.name = str;
+                if (pageTitleId == StringId.EditScene)
+                {
+                    scene.SaveFunctionData();
+                }
+            };
+            EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
+            {
+                List<string> sceneNameList = new List<string>();
+                foreach (var tempScene in DB_ResidenceData.functionList.scenes)
+                {
+                    sceneNameList.Add(tempScene.name);
+                }
+                new PublicAssmebly().LoadDialog_EditParater(StringId.SceneName, scene.name, callBack, StringId.SceneNameCannotBeEmpty, StringId.SceneNameAlreadyExists, sceneNameList);
+            };
+            sceneNameView.MouseUpEventHandler = eventHandler;
+            btnSceneName.MouseUpEventHandler = eventHandler;
+            btnEditSceneNameIcon.MouseUpEventHandler = eventHandler;
+        }
+
     }
 }

--
Gitblit v1.8.0