黄学彪
2020-04-02 9904031f5291daaf56985146bb671f25e18ebbdf
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
using Shared.Common;
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Globalization;
 
namespace Shared.Phone.Category
{
    /// <summary>
    /// 添加或者编辑场景的界面
    /// </summary>
    public class AddOrEditorSceneForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 修改的场景
        /// </summary>
        private SceneUI editorScene = null;
        /// <summary>
        /// 克隆的场景(临时编辑用)
        /// </summary>
        private SceneUI cloneScene = null;
        /// <summary>
        /// 场景当前的房间ID
        /// </summary>
        private string nowRoomId = string.Empty;
        /// <summary>
        /// 整个界面的上下滑动控件
        /// </summary>
        private VerticalFrameControl listBodyControl = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_editorScene">编辑的场景对象</param>
        public void ShowForm(SceneUI i_editorScene)
        {
            this.ScrollEnabled = false;
            this.editorScene = i_editorScene;
 
            //克隆一个临时编辑的变量
            this.cloneScene = new SceneUI();
            if (i_editorScene != null)
            {
                cloneScene.Name = i_editorScene.Name;
                cloneScene.IconPath = i_editorScene.IconPath;
                cloneScene.IconPathType = i_editorScene.IconPathType;
                var room = HdlRoomLogic.Current.GetRoomBySceneId(i_editorScene.Id);
                if (room != null)
                {
                    //当前的房间
                    this.nowRoomId = room.Id;
                }
                //设置头部信息
                base.SetTitleText(Language.StringByID(R.MyInternationalizationString.EditorScene));
            }
            else
            {
                //设置头部信息
                base.SetTitleText(Language.StringByID(R.MyInternationalizationString.AddScence));
            }
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            this.listBodyControl = new VerticalFrameControl();
            listBodyControl.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listBodyControl);
 
            //场景图片这部分的白色背景
            var framePicBack = new FrameLayout();
            framePicBack.Height = Application.GetRealHeight(559);
            framePicBack.BackgroundColor = UserCenterColor.Current.White;
            listBodyControl.frameTable.AddChidren(framePicBack);
 
            //场景图片底部阴影
            var btnShadow = new PicViewControl(916, 487);
            btnShadow.Y = Application.GetRealHeight(46);
            btnShadow.Gravity = Gravity.CenterHorizontal;
            btnShadow.UnSelectedImagePath = "Room/Room_Rectangle.png";
            framePicBack.AddChidren(btnShadow);
            //场景图片
            var btnPic = new ImageView();
            btnPic.Y = Application.GetRealHeight(46);
            btnPic.Width = Application.GetMinRealAverage(887);
            btnPic.Height = Application.GetMinRealAverage(444);
            btnPic.Radius = (uint)Application.GetRealHeight(17);
            btnPic.Gravity = Gravity.CenterHorizontal;
            if (this.editorScene == null)
            {
                btnPic.ImagePath = "SceneIcon/0.png";
            }
            else if (this.editorScene.IconPathType == 0)
            {
                btnPic.ImagePath = this.editorScene.IconPath;
            }
            else
            {
                btnPic.ImageBytes = Global.ReadFileByHomeId(this.editorScene.IconPath);
            }
            framePicBack.AddChidren(btnPic);
            //图片遮罩
            var btnZhezhao = new FrameLayout();
            btnZhezhao.Width = btnPic.Width;
            btnZhezhao.Height = btnPic.Height;
            btnZhezhao.Y = btnPic.Y;
            btnZhezhao.Gravity = Gravity.CenterHorizontal;
            btnZhezhao.Radius = btnPic.Radius;
            framePicBack.AddChidren(btnZhezhao);
            btnZhezhao.MouseUpEventHandler += (sender, e) =>
            {
                //房间图片选择
                this.ScenePictrueSelect(btnPic);
            };
 
            //初始化信息编辑控件
            this.InitInfoEditorControl();
        }
 
        #endregion
 
        #region ■ 初始化信息编辑_____________________
 
        /// <summary>
        /// 初始化信息编辑控件
        /// </summary>
        private void InitInfoEditorControl()
        {
            //白色背景框
            var frameBack = new FrameLayout();
            frameBack.Y = Application.GetRealHeight(582);
            frameBack.Height = Application.GetRealHeight(429);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            this.listBodyControl.frameTable.AddChidren(frameBack);
 
            //信息编辑
            var btnTitle = new NormalViewControl(300, 60, true);
            btnTitle.X = ControlCommonResourse.XXLeft;
            btnTitle.Y = Application.GetRealHeight(46);
            btnTitle.TextSize = 15;
            btnTitle.TextID = R.MyInternationalizationString.uInfoEditor;
            btnTitle.TextColor = UserCenterColor.Current.TextColor2;
            frameBack.AddChidren(btnTitle);
 
            //场景名称
            var rowScene = new FrameCaptionInputControl(Language.StringByID(R.MyInternationalizationString.SceneName), this.cloneScene.Name);
            rowScene.txtInput.PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputSceneName);
            rowScene.Y = btnTitle.Bottom + Application.GetRealHeight(23);
            frameBack.AddChidren(rowScene);
            //底线
            rowScene.AddBottomLine();
 
            //所属区域
            var rowBelong = new BelongAreaControl();
            //rowBelong.Y= rowScene.Bottom+
        }
 
        #endregion
 
        #region ■ 场景图片选择_______________________
 
        /// <summary>
        /// 场景图片选择
        /// </summary>
        /// <param name="imageContr"></param>
        private void ScenePictrueSelect(ImageView imageContr)
        {
            var menuContr = new BottomMenuSelectForm();
            menuContr.AddForm(3);
            //默认图库
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.LocalPicture), () =>
            {
                var localPic = new Device.Room.AddRoomSelectPicByLocal();
                UserView.HomePage.Instance.AddChidren(localPic);
                UserView.HomePage.Instance.PageIndex += 1;
                localPic.Show();
                localPic.action = (imgPath) =>
                {
                    if (string.IsNullOrEmpty(imgPath) == true)
                    {
                        return;
                    }
                    this.cloneScene.IconPathType = 0;
                    this.cloneScene.IconPath = imgPath;
                    imgPath = IO.FileUtils.GetImageFilePath(imgPath);
                    imageContr.ImageBytes = IO.FileUtils.ReadFile(imgPath);
                };
            });
            //拍照
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.Photograph), () =>
            {
                //通过相机拍照裁剪
                CropImage.TakePicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == true)
                    {
                        return;
                    }
                    this.cloneScene.IconPathType = 1;
                    imageContr.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    System.IO.File.Delete(imagePath);
                }, "HdlPic", 2, 1);
            });
            //我的相册
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.MyAblums), () =>
            {
                //从相册选择图片裁剪
                CropImage.SelectPicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == true)
                    {
                        return;
                    }
                    this.cloneScene.IconPathType = 2;
                    imageContr.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    System.IO.File.Delete(imagePath);
 
                }, "HdlPic", 2, 1);
            });
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        #endregion
    }
}