From a59663c4981c498f007307f7115f6850ab73e239 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 21 七月 2023 21:06:51 +0800
Subject: [PATCH] 群控界面修复  1.9版本bug修复

---
 HDL_ON/UI/UI2/FuntionControlView/Light/GroupControlPage_V2.cs |  412 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 314 insertions(+), 98 deletions(-)

diff --git a/HDL_ON/UI/UI2/FuntionControlView/Light/GroupControlPage_V2.cs b/HDL_ON/UI/UI2/FuntionControlView/Light/GroupControlPage_V2.cs
index 5ecba87..b71e0c6 100644
--- a/HDL_ON/UI/UI2/FuntionControlView/Light/GroupControlPage_V2.cs
+++ b/HDL_ON/UI/UI2/FuntionControlView/Light/GroupControlPage_V2.cs
@@ -1,5 +1,7 @@
 锘縰sing System;
 using System.Collections.Generic;
+using HDL_ON.Common;
+using HDL_ON.DriverLayer;
 using HDL_ON.Entity;
 using HDL_ON.UI.CSS;
 using Shared;
@@ -93,7 +95,7 @@
 
 
             //鍥為��鍒锋柊淇℃伅浜嬩欢
-            new TopViewDiv(bodyView, Language.StringByID(StringId.CombinedDimming)).LoadTopView_SettingIcon( () => {
+            new TopViewDiv(bodyView, Language.StringByID(StringId.GroupControl)).LoadTopView_SettingIcon( () => {
                 var page = new AddGroupControlPage(function,
                         (newGC) => {
                             try
@@ -116,7 +118,7 @@
                             try
                             {
                                 this.RemoveFromParent();
-                                UI.HomePage.RefreshFunctionView();
+                                UI.HomePage.RefreshGroupControlView();
                                 UI.RoomPage.bodyView?.ReLoadPage();
                                 UI.FunctionPage.bodyView?.ReLoadPage();
                             }
@@ -157,10 +159,12 @@
                         }
                     }
                     hadRGB = true;
+                    hadDimming = true;
                 }
                 else if (temp.spk == SPK.LightCCT)
                 {
                     hadCCT = true;
+                    hadDimming = true;
                 }
                 else if (temp.spk == SPK.LightDimming)
                 {
@@ -187,25 +191,7 @@
             controlView.AddChidren(attrView);
             attrView.AddChidren(new Button() { Height = Application.GetRealHeight(18) });
 
-
-            if (hadRGB)
-            {
-                hadCCT = true;
-                LoadRgbAttrView(hadCCT,hadColorful);
-            }
-            else if (hadCCT)
-            {
-                LoadCctAttrView(attrView);
-            }
-            else if (hadDimming)
-            {
-                LoadDimmingAttrView(attrView);
-            }
-            
-
-
-
-            var btnSwitch = new Button()
+            btnSwitch = new Button()
             {
                 Gravity = Gravity.CenterHorizontal,
                 Y = Application.GetRealHeight(466),
@@ -233,7 +219,61 @@
             };
 
 
+
+            if (hadRGB)
+            {
+                LoadRgbAttrView(hadCCT,hadColorful);
+            }
+            else if (hadCCT)
+            {
+                LoadCctAttrView(attrView);
+            }
+            else if (hadDimming)
+            {
+                LoadDimmingAttrView(attrView);
+            }
+            else
+            {
+                attrView.AddChidren(new Button() { Height = Application.GetRealHeight(30) });
+                var btnSwitchIcon = new Button()
+                {
+                    Gravity = Gravity.CenterHorizontal,
+                    Y = Application.GetRealHeight(102),
+                    Width = Application.GetRealWidth(168),
+                    Height = Application.GetRealWidth(288),
+                    UnSelectedImagePath = "FunctionIcon/Light/RelayBg.png",
+                    SelectedImagePath = "FunctionIcon/Light/RelayOnBg.png",
+                    IsSelected = function.trait_on_off.curValue.ToString() == "on"
+                };
+                attrView.AddChidren(btnSwitchIcon);
+
+                btnSwitchIcon.MouseUpEventHandler = (sender, e) => {
+                    if (btnSwitchIcon.IsSelected)
+                    {
+                        btnSwitchIcon.IsSelected = btnSwitch.IsSelected = false;
+                        var d = new Dictionary<string, string>();
+                        d.Add(FunctionAttributeKey.OnOff, "off");
+                        function.Control(d);
+                    }
+                    else
+                    {
+                        btnSwitchIcon.IsSelected = btnSwitch.IsSelected = true;
+                        var d = new Dictionary<string, string>();
+                        d.Add(FunctionAttributeKey.OnOff, "on");
+                        function.Control(d);
+                    }
+                };
+                btnSwitch.MouseUpEventHandler += (sender, e) => {
+                    btnSwitchIcon.IsSelected = btnSwitch.IsSelected;
+                };
+            }
+
+
+
+
+
         }
+        Button btnSwitch;
 
         /// <summary>
         /// 鍔犺浇璋冨厜灞炴�ц缃帶浠�
@@ -241,88 +281,98 @@
         /// <param name="attrView"></param>
         void LoadDimmingAttrView(VerticalScrolViewLayout attrView)
         {
-            var dimmingView = new FrameLayout()
-            {
-                Height = Application.GetRealHeight(54 + 11)
-            };
-            attrView.AddChidren(dimmingView);
 
-            #region 浜害璋冭妭
+
+
+            attrView.AddChidren(new Button
+            {
+                Height = Application.GetRealHeight(50),
+            });
+
+            var dimmerView = new FrameLayout()
+            {
+                Height = Application.GetRealHeight(280)
+            };
+            attrView.AddChidren(dimmerView);
+
+            var dimmerBar = new WaveSeekBarOn()
+            {
+                Gravity = Gravity.CenterHorizontal,
+                Width = Application.GetRealWidth(168 - 40),
+                Height = Application.GetRealHeight(288 - 16 - 16),
+                BorderColor = 0x00000000,
+                CornerRadius = Application.GetRealWidth(30),
+                BorderWidth = 0,
+                Progress = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)),
+                IsProgressTextShow = false,
+            };
+            dimmerView.AddChidren(dimmerBar);
+
             var btnBrightnessText = new Button()
             {
-                X = Application.GetRealWidth(35),
-                Y = Application.GetRealHeight(1),
-                Width = Application.GetRealWidth(224),
-                Height = Application.GetRealHeight(25),
-                TextAlignment = TextAlignment.CenterLeft,
+                Gravity = Gravity.CenterHorizontal,
+                Y = ((100 - Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(222 - 16) / 100),
+                Width = Application.GetRealWidth(56),
+                Height = Application.GetRealWidth(46),
+                UnSelectedImagePath = "FunctionIcon/Light/BrightnessBg.png",
                 TextColor = CSS_Color.FirstLevelTitleColor,
-                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
-                TextID = StringId.Brightness,
+                TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
+                Text = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)) + "%",
             };
-            btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + function.GetAttrState(FunctionAttributeKey.Brightness) + "%";
-            dimmingView.AddChidren(btnBrightnessText);
+            dimmerView.AddChidren(btnBrightnessText);
 
-
-            var btnMinValuesText = new Button()
-            {
-                X = Application.GetRealWidth(35),
-                Y = btnBrightnessText.Bottom,
-                Width = Application.GetRealWidth(40),
-                Height = Application.GetRealHeight(21),
-                Text = "0%",
-                TextAlignment = TextAlignment.CenterLeft,
-                TextColor = CSS_Color.PromptingColor1,
-                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
-            };
-            dimmingView.AddChidren(btnMinValuesText);
-
-            var dimmerBar = new DiyImageSeekBar()
-            {
-                X = Application.GetRealWidth(45 + 10),
-                Y = Application.GetRealHeight(11),
-                Width = Application.GetRealWidth(220),
-                Height = Application.GetRealHeight(54),
-                SeekBarViewHeight = Application.GetRealHeight(8),
-                ThumbImagePath = "Public/ThumbImage.png",
-                ThumbImageHeight = Application.GetRealHeight(54),
-                ProgressTextColor = CSS_Color.FirstLevelTitleColor,
-                ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel,
-                ProgressBarColor = CSS_Color.AuxiliaryColor1,
-                MaxValue = 100,
-                SeekBarPadding = Application.GetRealWidth(20),
-                IsProgressTextShow = false,
-                ProgressChangeDelayTime = 0,
-            };
-            dimmingView.AddChidren(dimmerBar);
             dimmerBar.OnProgressChangedEvent = (sender, e) =>
             {
-                btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + e + "%";
-            };
-            dimmerBar.OnStopTrackingTouchEvent = (sender, e) =>
-            {
-                btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + e + "%";
-
-                var d = new Dictionary<string, string>();
-                d.Add(FunctionAttributeKey.Brightness, e.ToString());
-                function.Control(d);
-            };
+                if (e == 0 && lastBrightness != 0)
+                {
+                    btnSwitch.IsSelected = false;
+                    lastBrightness = 0;
+                }
+                else
+                {
+                    if (lastBrightness == 0)
+                        lastBrightness = e;
+                    btnSwitch.IsSelected = true;
+                }
+                if (e == 0 || e == 100)
+                {
+                    var d = new Dictionary<string, string>();
+                    d.Add(FunctionAttributeKey.Brightness, e.ToString());
+                    function.Control(d);
+                }
+                else
+                {
+                    if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
+                    {
+                        function.refreshTime = DateTime.Now;
+                        new System.Threading.Thread(() =>
+                        {
+                            var d = new Dictionary<string, string>();
+                            d.Add(FunctionAttributeKey.Brightness, e.ToString());
+                            function.Control(d);
+                        })
+                        { IsBackground = true }.Start();
+                    }
+                }
 
 
-            var btnMaxValuesText = new Button()
-            {
-                X = dimmerBar.Right,
-                Y = btnBrightnessText.Bottom,
-                Width = Application.GetRealWidth(55),
-                Height = Application.GetRealHeight(21),
-                Text = "100%",
-                TextAlignment = TextAlignment.CenterLeft,
-                TextColor = CSS_Color.PromptingColor1,
-                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
+                btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
+                btnBrightnessText.Text = dimmerBar.Progress + "%";
             };
-            dimmingView.AddChidren(btnMaxValuesText);
-            #endregion
+
+            btnSwitch.MouseUpEventHandler += (sender, e) => {
+                if (btnSwitch.IsSelected)
+                {
+                    dimmerBar.Progress = 100;
+                }
+                else
+                {
+                    dimmerBar.Progress = 0;
+                }
+            };
 
         }
+        int lastBrightness = 0;
 
         /// <summary>
         /// 鍔犺浇cct灞炴�ц缃帶浠�
@@ -330,6 +380,96 @@
         /// <param name="attrView"></param>
         void LoadCctAttrView(VerticalScrolViewLayout attrView)
         {
+            attrView.AddChidren(new Button
+            {
+                Height = Application.GetRealHeight(20),
+            });
+
+            var dimmerView = new FrameLayout()
+            {
+                Height = Application.GetRealHeight(280)
+            };
+            attrView.AddChidren(dimmerView);
+
+            var dimmerBar = new WaveSeekBarOn()
+            {
+                Gravity = Gravity.CenterHorizontal,
+                Width = Application.GetRealWidth(168 - 40),
+                Height = Application.GetRealHeight(288 - 16 - 16),
+                BorderColor = 0x00000000,
+                CornerRadius = Application.GetRealWidth(30),
+                BorderWidth = 0,
+                Progress = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)),
+                IsProgressTextShow = false,
+            };
+            dimmerView.AddChidren(dimmerBar);
+
+            var btnBrightnessText = new Button()
+            {
+                Gravity = Gravity.CenterHorizontal,
+                Y = ((100 - Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(222 - 16) / 100),
+                Width = Application.GetRealWidth(56),
+                Height = Application.GetRealWidth(46),
+                UnSelectedImagePath = "FunctionIcon/Light/BrightnessBg.png",
+                TextColor = CSS_Color.FirstLevelTitleColor,
+                TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
+                Text = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)) + "%",
+            };
+            dimmerView.AddChidren(btnBrightnessText);
+
+            dimmerBar.OnProgressChangedEvent = (sender, e) =>
+            {
+                if (e == 0 && lastBrightness != 0)
+                {
+                    btnSwitch.IsSelected = false;
+                    lastBrightness = 0;
+                }
+                else
+                {
+                    if (lastBrightness == 0)
+                        lastBrightness = e;
+                    btnSwitch.IsSelected = true;
+                }
+
+                if (e == 0 || e == 100)
+                {
+                    var d = new Dictionary<string, string>();
+                    d.Add(FunctionAttributeKey.Brightness, e.ToString());
+                    function.Control(d);
+                }
+                else
+                {
+                    if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
+                    {
+                        function.refreshTime = DateTime.Now;
+                        new System.Threading.Thread(() =>
+                        {
+                            var d = new Dictionary<string, string>();
+                            d.Add(FunctionAttributeKey.Brightness, e.ToString());
+                            function.Control(d);
+                        })
+                        { IsBackground = true }.Start();
+                    }
+                }
+
+
+                btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
+                btnBrightnessText.Text = dimmerBar.Progress + "%";
+            };
+
+            btnSwitch.MouseUpEventHandler += (sender, e) => {
+                if (btnSwitch.IsSelected)
+                {
+                    dimmerBar.Progress = 100;
+                }
+                else
+                {
+                    dimmerBar.Progress = 0;
+                }
+            };
+
+            //attrView.AddChidren(new Button() { Height = Application.GetRealHeight(10) });
+
             #region 鑹叉俯
             var cctView = new FrameLayout()
             {
@@ -385,6 +525,7 @@
                 Y = Application.GetRealHeight(11),
                 Width = Application.GetRealWidth(220),
                 Height = Application.GetRealHeight(54),
+                Progress = 38,
             };
             barColorTemplatrue.MinValue = 27;
             barColorTemplatrue.MaxValue = 65;
@@ -489,6 +630,52 @@
             };
             btnWhiteRound.Visible = false;
             framePickerBack.AddChidren(btnWhiteRound);
+
+
+            //褰撳墠鐐瑰嚮鐨勩�愮偣銆戞槸鍚︽纭�
+            bool pointIsRight = false;
+            //鍦嗙殑鍗婂緞(鑰冭檻杈圭晫,闇�瑕佽缃畠鐨勫崐寰勬瘮杈冨皬涓�鐐�)
+            int circleR = colorPicker.Width / 2 - Application.GetRealWidth(12);
+            string rgbString = "255,255,255";
+            var rgbTemp = new Light();
+            colorPicker.MouseUpEventHandler = (sender2, e2) =>
+            {
+                var d = new Dictionary<string, string>();
+                d.Add(FunctionAttributeKey.RGB, rgbString);
+                function.Control(d);
+            };
+            colorPicker.ColorChaged += (sender2, e2) =>
+            {
+                rgbString = (e2[0] + "," + e2[1] + "," + e2[2]).ToString();
+                btnCurColor.BackgroundColor = (uint)(0xFF000000 + rgbTemp.GetRGBcolor(rgbString));
+                var d = new Dictionary<string, string>();
+                d.Add(FunctionAttributeKey.RGB, rgbString);
+                function.Control(d);
+            };
+            colorPicker.MouseDownEventHandler += (sender, e) =>
+            {
+                pointIsRight = this.CheckPoint(circleR, colorPicker.Width / 2, colorPicker.Height / 2, (int)e.X, (int)e.Y);
+                if (pointIsRight == false)
+                {
+                    //鐐圭殑鍖哄煙涓嶆槸鍦嗙洏鍐�
+                    return;
+                }
+                //鏄剧ず鐧界偣
+                btnWhiteRound.X = (int)e.X - btnWhiteRound.Width / 2;
+                btnWhiteRound.Y = (int)e.Y - btnWhiteRound.Height / 2;
+                if (btnWhiteRound.Visible == false)
+                {
+                    btnWhiteRound.Visible = true;
+                }
+            };
+
+            colorPicker.MouseMoveEventHandler += (sender, e) =>
+            {
+                //褰撻紶鏍囩偣涓嬩簨浠跺鐞�
+                colorPicker.MouseDownEventHandler(sender, e);
+            };
+
+
 
             #region 浜害璋冭妭
             var btnBrightnessText = new Button()
@@ -668,16 +855,17 @@
                 };
                 controlView.AddChidren(btnGradualChangeText);
 
-                var btnGradualChangeMinValuesText = new Button()
+                var btnColorfulEdit = new Button()
                 {
                     X = Application.GetRealWidth(35),
                     Y = btnGradualChangeText.Bottom + Application.GetRealHeight(10),
                     Width = Application.GetRealWidth(22),
                     Height = Application.GetRealHeight(21),
                     UnSelectedImagePath = "Public/Edit.png",
+                    Visible = false,
                 };
-                controlView.AddChidren(btnGradualChangeMinValuesText);
-                btnGradualChangeMinValuesText.MouseUpEventHandler = (sender, e) => {
+                controlView.AddChidren(btnColorfulEdit);
+                btnColorfulEdit.MouseUpEventHandler = (sender, e) => {
                     var rgbView = new ColorfulInfoPage(function);
                     MainPage.BasePageView.AddChidren(rgbView);
                     rgbView.LoadPage();
@@ -686,7 +874,7 @@
 
                 var barColorful = new FrameLayout()
                 {
-                    X = btnGradualChangeMinValuesText.Right + Application.GetRealWidth(15+5),
+                    X = btnColorfulEdit.Right + Application.GetRealWidth(15+5),
                     Y = Application.GetRealHeight(412 + heightMore - magriHeight),
                     Width = Application.GetRealWidth(170),
                     Height = Application.GetRealHeight(8),
@@ -694,21 +882,45 @@
                 };
                 controlView.AddChidren(barColorful);
 
-                var btnGradualChangeMaxValuesText = new Button()
+                var btnColorfulSwitch = new Button()
                 {
                     X = barColorful.Right + Application.GetRealWidth(8),
                     Y = btnGradualChangeText.Bottom + Application.GetRealHeight(10),
                     Width = Application.GetRealWidth(38),
                     Height = Application.GetRealHeight(24),
-                    UnSelectedImagePath = "Public/Switch.png"
+                    UnSelectedImagePath = "Public/Switch.png",
+                    SelectedImagePath = "Public/SwitchOn.png"
                 };
-                controlView.AddChidren(btnGradualChangeMaxValuesText);
+                controlView.AddChidren(btnColorfulSwitch);
+
+
+                btnColorfulSwitch.MouseUpEventHandler = (sender, e) => {
+                    btnColorfulSwitch.IsSelected = !btnColorfulSwitch.IsSelected;
+                    new System.Threading.Thread(() =>
+                    {
+                        try
+                        {
+                            var controlColorfulState = btnColorfulSwitch.IsSelected ? "on" : "off";
+                            function.SetAttrState(FunctionAttributeKey.Colorful, controlColorfulState);
+                            var d = new Dictionary<string, string>();
+                            d.Add(FunctionAttributeKey.Colorful, controlColorfulState);
+                      
+                            Control.Ins.SendWriteCommand(function, d);
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"鎺у埗鐐僵寮�鍏冲紓甯�:{ex.Message}");
+                        }
+                    })
+                    { IsBackground = true }.Start();
+                };
+
                 #endregion
 
 
             }
 
-         
+
 
         }
 
@@ -742,5 +954,9 @@
             return false;
         }
 
+
+
+
+
     }
 }

--
Gitblit v1.8.0