1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using Shared.SimpleControl.Phone;
using System;
using System.Collections.Generic;
using Shared.SimpleControl.Pad;
using System.Text;
namespace Shared.SimpleControl.Pad
{
    /// <summary>
    /// 用户场景界面,用户场景界面
    /// </summary>
    public class UserGlobalScenes : Shared.Dialog
    {
 
        FrameLayout LongPressFrameLayout = new FrameLayout ();
        Button beforeClickButton = new Button ();
        FrameLayout mainFrameLayout = new FrameLayout ();//重复加载界面
 
        /// <summary>
        /// 显示当前房间的场景
        /// </summary>
        /// <param name="room">Room.</param>
        public UserGlobalScenes ()
        {
             BackgroundColor = 0xFF2f2f2f;
            AddChidren (mainFrameLayout);
            showGlobalScene ();
        }
        /// <summary>
        /// 显示当前视图
        /// </summary>
        void showGlobalScene (string s ="")
        {
            mainFrameLayout.RemoveAll ();
 
            #region 标题
            var topView = new FrameLayout () {
                Y = Application.GetRealHeight (36),
                Height = Application.GetRealHeight (90),
            };
            mainFrameLayout.AddChidren (topView);
 
            var title = new Button () {
                TextAlignment = TextAlignment.Center,
                Text = Language.StringByID (R.MyInternationalizationString.Scenes),
                TextSize = 19,
            };
            topView.AddChidren (title);
 
            var logo = new Button () {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                UnSelectedImagePath = MainPage.LogoString,
            };
            topView.AddChidren (logo);
            var back = new Button () {
                Height = Application.GetRealHeight (100),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                Close ();
                new UserDeviceToScene ().Refresh ();
            };
 
            var line = new Button () {
                Height = 1,
                BackgroundColor = 0xFF2f2f2f,
                Y = topView.Height - 1
            };
            topView.AddChidren (line);
            #endregion
 
            #region bodyView
            var bodyView = new FrameLayout () {
                Y = topView.Bottom,
            };
            mainFrameLayout.AddChidren (bodyView);
 
            var scenesBodyView = new VerticalScrolViewLayout () {
                Height = Application.GetRealHeight (1136 - 90 - 36),
            };
            bodyView.AddChidren (scenesBodyView);
 
            //所有场景
            var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
 
            List<string> sceneFilePaths = new List<string> ();//存路径
 
            sceneFilePaths = sceneFileList;
            sceneFilePaths.Add ("");
 
            FrameLayout scenesRowView = null;
 
            for (int index = 0; index < sceneFilePaths.Count; index++) {
                var sceneFilePath = sceneFilePaths [index];
                var scene = Scene.GetSceneByFilePath (sceneFilePath);
                // 当场景不存在时,可以NEW 一个场景,不然值一直是空的
                if (scene == null) {
                    scene = new Scene ();
                }
 
                if (index % 2 == 0) {
                    scenesRowView = new FrameLayout () {
                        Height = Application.GetRealHeight (250),
                    };
                    scenesBodyView.AddChidren (scenesRowView);
                }
 
                var sceneView = new FrameLayout () {
                    Width = Application.GetRealWidth (320),
                    BackgroundImagePath = scene.BackgroundImagePath,
                };
                scenesRowView.AddChidren (sceneView);
 
                if (index % 2 == 1) {
                    sceneView.X = Application.GetRealWidth (320);
                }
 
                if (index == sceneFilePaths.Count - 1) {
                    sceneView.BackgroundImagePath = "Item/SceneAdd.png";
                    sceneView.MouseUpEventHandler += (sender, e) => {
                        SceneMethod.AddOrUpdataSceneBaseMassage (Scene.GlobalSceneFilePath, null, showGlobalScene);
                    };
                } else {
                    Button btnSceneName = new Button () {
                        Height = Application.GetRealHeight (40),
                        Y = Application.GetRealHeight (210),
                            BackgroundColor = 0xFFDBDDDF,
                    };
                    sceneView.AddChidren (btnSceneName);
                    var btnBGC = new Button () {
                        UnSelectedImagePath = "Item/sss.png",
                        SelectedImagePath = "Item/SceneSettingBackground.png",
                        TextAlignment = TextAlignment.BottomCenter,
                        Text = scene.Name,
                        TextColor = SkinStyle.Current.TextColor1,
                        TextSize = 15,
                    };
                    sceneView.AddChidren (btnBGC);
 
                    btnBGC.MouseLongEventHandler += (sender, e) => {
                        if (string.IsNullOrEmpty (scene.Name))
                            return;
                        LongPressFrameLayout = new FrameLayout () {
                            BackgroundImagePath = "Item/SceneSettingBackground.png",
                        };
                        sceneView.AddChidren (LongPressFrameLayout);
                        LongPressFrameLayout.MouseUpEventHandler += (sender2, e2) => {
                            LongPressFrameLayout.RemoveFromParent ();
                        };
                        var btnEditor = new Button () {
                            Width = Application.GetRealWidth (70),
                            Height = Application.GetRealHeight (76),
                            UnSelectedImagePath = "Item/UserSceneEditIcon.png",
                            X = Application.GetRealWidth (243),
                            Y = Application.GetRealHeight (13),
                        };
                        LongPressFrameLayout.AddChidren (btnEditor);
                        btnEditor.MouseUpEventHandler += (sender1, e1) => {
                            AddChidren (new UserAddSceneDevice (Scene.GlobalSceneFilePath, sceneFilePath, (newSceneFilePath) => {
                                sceneFilePath = newSceneFilePath;
                                scene = Scene.GetSceneByFilePath (sceneFilePath);
                                sceneView.BackgroundImagePath = scene.BackgroundImagePath;
                            }));
                        };
 
                        var btnDel = new Button () {
                            Width = Application.GetRealWidth (70),
                            Height = Application.GetRealHeight (76),
                            UnSelectedImagePath = "Item/UserSceneDelIcon.png",
                            X = Application.GetRealWidth (40),
                            Y = Application.GetRealHeight (20),
                        };
                        LongPressFrameLayout.AddChidren (btnDel);
 
                        btnDel.MouseUpEventHandler += (senderDel, eDel) => {
 
                            IO.FileUtils.DeleteFile (sceneFilePath);
                            sceneFileList.Remove (sceneFilePath);
                            sceneFileList.Remove ("");
                            IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
                            showGlobalScene ();
                        };
                    };
 
                    btnBGC.MouseUpEventHandler += (sender, e) => {
                        LongPressFrameLayout.RemoveFromParent ();
                        beforeClickButton.IsSelected = false;
                        beforeClickButton = btnBGC;
                        btnBGC.IsSelected = true;
                        SceneMethod.ControlScene (scene);
                    };
                }
            }
            #endregion 
        }
    }
}