wei
2021-04-14 1498a62d1d44d715e310b42e3133aa8cdc6eec92
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using System;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    public class CatchSceneCatchFunctionListPage :FrameLayout
    {
        /// <summary>
        /// 主控件
        /// </summary>
        FrameLayout bodyView;
        /// <summary>
        /// 内容区域
        /// </summary>
        VerticalScrolViewLayout contentView;
        /// <summary>
        /// 生成场景按钮
        /// </summary>
        Button btnGenerateScene;
 
 
        Scene scene;
        /// <summary>
        /// 捕捉到到功能数据
        /// </summary>
        List<Function> catchFunctionList;
        /// <summary>
        /// 回掉更新事件
        /// </summary>
        Action backAction;
 
        public CatchSceneCatchFunctionListPage(Scene s, List<Function> list,Action action)
        {
            bodyView = this;
            scene = s;
            catchFunctionList = list;
            backAction = action;
        }
 
        public void LoadPage()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.CatchScene)).LoadTopView();
 
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
 
            contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(667 - 64 - 60),
            };
            bodyView.AddChidren(contentView);
 
 
            LoadFunctionRow();
 
            btnGenerateScene = new Button()
            {
                Y = Application.GetRealHeight(667 - 50),
                Height = Application.GetRealHeight(50),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.GenerateScene,
                BackgroundColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(btnGenerateScene);
            LoadEvent_CompleteEvent();
        }
 
        /// <summary>
        /// 加载功能信息行
        /// </summary>
        private void LoadFunctionRow()
        {
            contentView.RemoveAll();
            scene.functions.Clear();
            bool isFrist = true;
 
            foreach (var function in catchFunctionList)
            {
                var scenefunction = function.ConvertSceneFunction();
 
                scene.functions.Add(scenefunction);
 
                RowLayout functionRow = new RowLayout()
                {
                    Height = Application.GetRealHeight(50),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                    LineColor = 0x00000000,
                };
                contentView.AddChidren(functionRow);
 
                if (isFrist)
                {
                    isFrist = false;
                }
                else
                {
                    functionRow.AddChidren(new Button()
                    {
                        Gravity = Gravity.CenterHorizontal,
                        Width = Application.GetRealWidth(343),
                        Height = Application.GetRealWidth(1),
                        BackgroundColor = CSS_Color.DividingLineColor,
                    });
                }
 
                var btnFunctionIcon = new Button()
                {
                    X = Application.GetRealWidth(12),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetMinRealAverage(28),
                    Height = Application.GetMinRealAverage(28),
                };
                functionRow.AddChidren(btnFunctionIcon);
 
                btnFunctionIcon.UnSelectedImagePath = $"FunctionIcon/Icon/{function.IconName}.png";
 
                var btnName = new Button()
                {
                    X = Application.GetRealWidth(8 + 10 + 32),
                    Width = Application.GetRealWidth(200),
                    Height = Application.GetRealHeight(32),
                    Text = function.name,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.TextFontSize,
                };
                functionRow.AddChidren(btnName);
 
                var btnFromFloor = new Button()
                {
                    X = Application.GetRealWidth(8 + 10 + 32),
                    Y = Application.GetRealHeight(24),
                    Width = Application.GetRealWidth(200),
                    Height = Application.GetRealHeight(26),
                    Text = function.GetRoomListName(),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.PromptingColor1,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                };
                functionRow.AddChidren(btnFromFloor);
 
                Button btnRight = new Button()
                {
                    X = Application.GetRealWidth(339),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetMinRealAverage(16),
                    Height = Application.GetMinRealAverage(16),
                    UnSelectedImagePath = "Public/Right.png",
                };
                functionRow.AddChidren(btnRight);
 
                var btnFunctionInfo = new Button()
                {
                    Width = Application.GetRealWidth(327),
                    TextAlignment = TextAlignment.CenterRight,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    Text = scenefunction.GetFunctionScnenInfo(),
                };
                functionRow.AddChidren(btnFunctionInfo);
                EventHandler<MouseEventArgs> eventHandler = (sender, e) => {
                    Action refreshFunctionRowAction = () => {
                        btnFunctionInfo.Text = scenefunction.GetFunctionScnenInfo();
                    };
                    var ssf = new SceneFunctionInfoEditPage(scene, scenefunction, refreshFunctionRowAction);
                    MainPage.BasePageView.AddChidren(ssf);
                    ssf.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                btnFunctionInfo.MouseUpEventHandler = eventHandler;
                btnRight.MouseUpEventHandler = eventHandler;
 
                Button btnDelSceneFunction = new Button()
                {
                    BackgroundColor = CSS_Color.WarningColor,
                    TextColor = CSS_Color.MainBackgroundColor,
                    TextID = StringId.Del,
                };
                functionRow.AddRightView(btnDelSceneFunction);
                btnDelSceneFunction.MouseUpEventHandler = (sender, e) => {
                    catchFunctionList.Remove(function);
                    LoadFunctionRow();
                };
            }
 
        }
 
        /// <summary>
        /// 完成按钮点击事件
        /// </summary>
        void LoadEvent_CompleteEvent()
        {
            btnGenerateScene.MouseUpEventHandler += (sender, e) =>
            {
                var waitPage = new Loading();
                MainPage.BaseView.AddChidren(waitPage);
                waitPage.Start(Language.StringByID(StringId.PleaseWait));
                new Thread(() =>
                {
                    try
                    {
                        var serverScene = new Scene();
                        var result = FunctionList.List.AddScene(scene, out serverScene);
                        Application.RunOnMainThread(() =>
                        {
                            if (result == StateCode.SUCCESS)
                            {
                                scene = serverScene;
                                FunctionList.List.scenes.Add(scene);
                                backAction();
                                RemoveFromParent();
                            }
                            else
                            {
                                IMessageCommon.Current.ShowErrorInfoAlter(result);
                            }
                        });
                    }
                    catch { }
                    finally
                    {
                        Application.RunOnMainThread(() => {
                            waitPage.Hide();
                            waitPage.RemoveFromParent();
                        });
                    }
                })
                { IsBackground = true, Priority = ThreadPriority.AboveNormal }.Start();
            };
        }
 
 
    }
}