JLChen
2021-06-23 8b317182c94145de9b7e8ca5a22c14b2d99bb66b
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
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class AddTarget : FrameLayout
    {
        public AddTarget()
        {
            Tag = "Logic";
        }
        public void Show()
        {
 
            LogicView.TopView topView = new LogicView.TopView();
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
            };
            topView.topNameBtn.TextID = StringId.addtarget;
 
            FrameLayout viewLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64),
                Width = Application.GetRealWidth(LogicView.TextSize.view375),
                Height = Application.GetRealHeight(LogicView.TextSize.view667 - 64),
                BackgroundColor = CSS.CSS_Color.viewMiddle,
            };
            this.AddChidren(viewLayout);
            #region 功能
            //功能
            LogicView.SelectTypeView functionView = new LogicView.SelectTypeView();
            functionView.btnText.TextID = StringId.funLogic;
            functionView.btnIcon.UnSelectedImagePath = "LogicIcon/functionicon.png";
            viewLayout.AddChidren(functionView.FLayoutView());
 
            //场景
            LogicView.SelectTypeView sceneView = new LogicView.SelectTypeView();
            sceneView.frameLayout.Y = functionView.frameLayout.Bottom;
            sceneView.btnText.TextID = StringId.Scenes;
            sceneView.btnIcon.UnSelectedImagePath = "LogicIcon/scene.png";
            viewLayout.AddChidren(sceneView.FLayoutView());
 
            //延时
            LogicView.SelectTypeView delayView = new LogicView.SelectTypeView();
            delayView.frameLayout.Y = sceneView.frameLayout.Bottom;
            delayView.btnText.TextID = StringId.delayLogic;
            delayView.btnIcon.UnSelectedImagePath = "LogicIcon/time.png";
            viewLayout.AddChidren(delayView.FLayoutView());
            #endregion
 
            #region  所有点击事件
            //功能点击事件
            functionView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                FunTpye funTpye = new FunTpye();
                MainPage.BasePageView.AddChidren(funTpye);
                funTpye.Show(LogicMethod.target_if);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
            };
            //场景点击事件
            sceneView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                SceneMethod();
            };
            //延时点击事件
            delayView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
 
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                this.AddChidren(fLayout);
                Delayed(fLayout,false,1000);
            };
            #endregion
 
        }
 
        /// <summary>
        /// 添加场景
        /// </summary>
        public void SceneMethod()
        {
            var sceneList = LogicMethod.GetSceneList();
            List<string> nameList = new List<string>();
            for (int i = 0; i < sceneList.Count; i++) {
                var scene = sceneList[i];
                nameList.Add(scene.name);
            }
            PublicInterface publicInterface = new PublicInterface();
            publicInterface.FrameOrVv(this, nameList, StringId.addSceneLogic, (index) =>
            {
                var sceneSelecetd = sceneList[index];
                Output outputDevice = new Output();
                outputDevice.target_type = "2";
                outputDevice.sid = sceneSelecetd.sid;
                //没啥作用,为了发送数据格式统一;
                outputDevice.status = new List<Dictionary<string, string>> { new Dictionary<string, string> { { "key", "scene" }, { "value", "0" } } };
                AddOutput(outputDevice);
                LogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            });
        }
 
        /// <summary>
        /// 延时时间方法
        /// </summary>
        /// <param name="fLayout">在哪个界面显示</param>
        /// <param name="edit">(true=编辑;false=新建)</param>
        /// <param name="index">编辑条件的索引</param>
        public void Delayed(FrameLayout fLayout, bool edit, int index)
        {
            LogicView.TimeView timePointView = new LogicView.TimeView();
            timePointView.FLayoutView(fLayout);
            EventHandler<MouseEventArgs> RemovefLayout = (sender, e1) =>
            {
                //移除fLayout界面
                fLayout.RemoveFromParent();
            };
            //取消点击事件
            timePointView.btnCancel.MouseUpEventHandler += RemovefLayout;
 
            //加载数据界面的设置方法(列表互不联动)
            timePointView.mUIPickerView.setNPicker(timePointView.GethStringList0(), timePointView.GetmStringList(), null);
            //默认初始选中状态
            timePointView.mUIPickerView.setCurrentItems(0, 5, 0);
            //定义一个局部变量记录选中时间
            string timepoint = "00:05";
 
            if (edit)
            {
                Output output = Logic.currlogic.output[index];
                if (output.target_type == "3")
                {
                    List<Dictionary<string, string>> dicList = output.status as List<Dictionary<string, string>>;
                    foreach (var dic in dicList)
                    {
                        string timeValue = dic["value"];
                        int hIndex = timePointView.GetValueIndex(timeValue, 0, 1, timePointView.GethIntList());
                        int mIndex = timePointView.GetValueIndex(timeValue, 1, 0, timePointView.GetmIntList());
                        //更新初始状态
                        timePointView.mUIPickerView.setCurrentItems(hIndex, mIndex, 0);
                        timepoint = timeValue;
                    }
                }
            }
 
 
            //选中时间回调方法,时间变化一次回调一次
            timePointView.mUIPickerView.OnSelectChangeEvent += (index1, index2, index3) =>
            {
                string hour = timePointView.GethStringList0()[index1].Split(' ')[0];
                string minuet = timePointView.GetmStringList()[index2].Split(' ')[0];
                timepoint = hour + ":" + minuet;
            };
            //确定点击事件
            timePointView.btnConfirm.MouseUpEventHandler += (sender, e3) =>
            {
                if (timepoint=="00:00") {
                    //提示
                    return;
                }
                Output outputTime= new Output();
                outputTime.sid = LogicMethod.NewSid();
                outputTime.target_type = "3";
                Dictionary<string, string> dic = new Dictionary<string, string>();
                LogicMethod.dictionary(dic, "key", "delay");
                LogicMethod.dictionary(dic, "value", timepoint);
                outputTime.status.Add(dic);
                if (edit)
                {
                    //移除旧数据
                    Logic.currlogic.output.RemoveAt(index);
                    //新数据插入旧数据的位置;
                    Logic.currlogic.output.Insert(index, outputTime);
                }
                else
                {
                    //添加一个新的时间点条件
                    AddOutput(outputTime);
                }
                fLayout.RemoveFromParent();
                LogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
            };
        }
 
        /// <summary>
        /// 添加目标
        /// </summary>
        /// <param name="target"></param>
        private void AddOutput(Output target)
        {
            int indexValue = -1;
            for (int i = 0; i < Logic.currlogic.output.Count; i++)
            {
                if (Logic.currlogic.output[i].sid == target.sid)
                {
                    indexValue = i;
                    break;
                }
            }
 
            if (indexValue != -1)
            {
                Logic.currlogic.output.RemoveAt(indexValue);
                Logic.currlogic.output.Insert(indexValue, target);
            }
            else
            {
                Logic.currlogic.output.Add(target);
            }
 
        }
    }
}