using Shared.Common;
|
using Shared.Phone.UserCenter;
|
using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.Category
|
{
|
/// <summary>
|
/// 添加或者编辑场景的界面
|
/// </summary>
|
public class AddOrEditorSceneForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 场景变更事件(场景,房间ID)
|
/// </summary>
|
public Action<SceneUI, string> SceneChangedEvent = null;
|
/// <summary>
|
/// 修改的场景
|
/// </summary>
|
private SceneUI editorScene = null;
|
/// <summary>
|
/// 克隆的场景(临时编辑用)
|
/// </summary>
|
private SceneUI cloneScene = null;
|
/// <summary>
|
/// 场景当前的房间ID
|
/// </summary>
|
private string nowRoomId = string.Empty;
|
/// <summary>
|
/// 当前界面上显示的执行目标
|
/// </summary>
|
private List<Scene.DeviceListData> listAdjustTarget = null;
|
/// <summary>
|
/// 整个界面的上下滑动控件
|
/// </summary>
|
private VerticalFrameControl listBodyControl = null;
|
/// <summary>
|
/// 添加目标的的容器控件
|
/// </summary>
|
private FrameListControl frameTargetTableControl = null;
|
/// <summary>
|
/// 这个是加到【整个界面的上下滑动控件】中,促使界面能够滑动刚好超过【完成按钮】
|
/// </summary>
|
private FrameLayout frameBottomTemp = null;
|
/// <summary>
|
/// 场景图片显示控件(生成图片文件使用)
|
/// </summary>
|
private ImageView btnScenePic = null;
|
/// <summary>
|
/// 场景图片是否变更(针对编辑模式)
|
/// </summary>
|
private bool isScenePictrueChanged = false;
|
/// <summary>
|
/// 执行目标是否改变(针对编辑模式)
|
/// </summary>
|
private bool isAdjustTargetChanged = false;
|
|
#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.Id = i_editorScene.Id;
|
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
|
{
|
cloneScene.IconPath = "SceneIcon/0.png";
|
listAdjustTarget = new List<Scene.DeviceListData>();
|
//设置头部信息
|
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);
|
|
//初始化场景图片
|
this.InitScenePictureControl();
|
|
//初始化信息编辑控件
|
this.InitInfoEditorControl();
|
|
//初始化添加目标
|
this.InitAddTargetControl();
|
|
//完成
|
var btnSave = new BottomClickButton();
|
btnSave.TextID = R.MyInternationalizationString.uFinish;
|
bodyFrameLayout.AddChidren(btnSave);
|
btnSave.ButtonClickEvent += (sender, e) =>
|
{
|
//保存场景数据
|
this.SaveSceneData();
|
};
|
|
//分享的场景不能保存
|
if (this.editorScene != null && this.editorScene.IsSharedScene == true)
|
{
|
btnSave.CanClick = false;
|
}
|
else if (Config.Instance.Home.IsShowTemplate == true)
|
{
|
//模板场景不能保存
|
btnSave.CanClick = false;
|
}
|
//如果是有模板,有设备的时候,在没有发送成功之前
|
else if (Common.Config.Instance.Home.TemplateMode == 2
|
&& Common.Config.Instance.Home.SendTemplateSuccess == false)
|
{
|
btnSave.CanClick = false;
|
}
|
}
|
|
#endregion
|
|
#region ■ 初始化场景图片_____________________
|
|
/// <summary>
|
/// 初始化场景图片
|
/// </summary>
|
private void InitScenePictureControl()
|
{
|
//场景图片这部分的白色背景
|
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);
|
//场景图片
|
this.btnScenePic = new ImageView();
|
btnScenePic.Y = Application.GetRealHeight(46);
|
btnScenePic.Width = this.GetPictrueRealSize(887);
|
btnScenePic.Height = this.GetPictrueRealSize(444);
|
btnScenePic.Radius = (uint)Application.GetRealHeight(17);
|
btnScenePic.Gravity = Gravity.CenterHorizontal;
|
if (this.editorScene == null)
|
{
|
btnScenePic.ImagePath = "SceneIcon/0.png";
|
}
|
else if (this.editorScene.IconPathType == 0)
|
{
|
btnScenePic.ImagePath = this.editorScene.IconPath;
|
}
|
else
|
{
|
btnScenePic.ImageBytes = Global.ReadFileByHomeId(this.editorScene.IconPath);
|
}
|
framePicBack.AddChidren(btnScenePic);
|
//图片遮罩
|
var btnZhezhao = new FrameLayout();
|
btnZhezhao.Width = btnScenePic.Width;
|
btnZhezhao.Height = btnScenePic.Height;
|
btnZhezhao.Y = btnScenePic.Y;
|
btnZhezhao.Gravity = Gravity.CenterHorizontal;
|
btnZhezhao.Radius = (uint)Application.GetRealHeight(17);
|
btnZhezhao.BackgroundColor = UserCenterColor.Current.PictrueZhezhaoColor;
|
framePicBack.AddChidren(btnZhezhao);
|
|
//分享的场景不能编辑
|
if (this.editorScene == null || this.editorScene.IsSharedScene == false)
|
{
|
if (Config.Instance.Home.IsShowTemplate == true)
|
{
|
//模板场景不允许编辑
|
return;
|
}
|
btnZhezhao.MouseUpEventHandler += (sender, e) =>
|
{
|
//房间图片选择
|
this.ScenePictrueSelect(btnScenePic);
|
};
|
}
|
}
|
|
#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 = HdlControlResourse.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.txtInput.MaxByte = 32;//限制只能输入32个字节
|
rowScene.Y = btnTitle.Bottom + Application.GetRealHeight(23);
|
frameBack.AddChidren(rowScene);
|
rowScene.InitControl();
|
//底线
|
rowScene.AddBottomLine();
|
rowScene.txtInput.TextChangeEventHandler += (sender, value) =>
|
{
|
this.cloneScene.Name = value;
|
};
|
|
//所属区域
|
var rowBelong = new BelongAreaControl();
|
rowBelong.Y = rowScene.Bottom + Application.GetRealHeight(14);
|
frameBack.AddChidren(rowBelong);
|
rowBelong.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), this.nowRoomId);
|
//分享的场景不能编辑
|
if (this.editorScene == null || this.editorScene.IsSharedScene == false)
|
{
|
rowBelong.SelectRoomEvent += (selectId) =>
|
{
|
this.nowRoomId = selectId;
|
};
|
}
|
if (Config.Instance.Home.IsShowTemplate == true)
|
{
|
//模板场景不允许编辑
|
rowBelong.CanClick = false;
|
}
|
}
|
|
#endregion
|
|
#region ■ 初始化添加目标_____________________
|
|
/// <summary>
|
/// 初始化添加目标
|
/// </summary>
|
private void InitAddTargetControl()
|
{
|
if (this.frameTargetTableControl == null || this.frameTargetTableControl.Parent == null)
|
{
|
//添加目标的的容器控件
|
this.frameTargetTableControl = new FrameListControl();
|
frameTargetTableControl.Y = Application.GetRealHeight(1034);
|
frameTargetTableControl.BackgroundColor = UserCenterColor.Current.White;
|
frameTargetTableControl.Height = Application.GetRealHeight(346);
|
this.listBodyControl.frameTable.AddChidren(frameTargetTableControl);
|
}
|
else
|
{
|
this.frameTargetTableControl?.RemoveAll();
|
frameTargetTableControl.Height = Application.GetRealHeight(346);
|
}
|
|
//添加目标
|
var rowAddTarget = new FrameRowControl(frameTargetTableControl.rowSpace / 2);
|
rowAddTarget.UseClickStatu = false;
|
rowAddTarget.Y = Application.GetRealHeight(46 - 12);
|
frameTargetTableControl.AddChidren(rowAddTarget);
|
rowAddTarget.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.AddScentTargetAction), 600);
|
//+号
|
var btnAddIcon = rowAddTarget.AddMostRightEmptyIcon(61, 58);
|
btnAddIcon.UnSelectedImagePath = "Item/Add.png";
|
//底线
|
rowAddTarget.AddBottomLine();
|
rowAddTarget.ButtonClickEvent += (sender, e) =>
|
{
|
//显示添加目标菜单
|
this.ShowAddTargetMenu();
|
};
|
if (Config.Instance.Home.IsShowTemplate == true)
|
{
|
//模板场景不允许编辑
|
rowAddTarget.CanClick = false;
|
}
|
//如果是有模板,有设备的时候,在没有发送成功之前
|
if (Common.Config.Instance.Home.TemplateMode == 2
|
&& Common.Config.Instance.Home.SendTemplateSuccess == false)
|
{
|
rowAddTarget.CanClick = false;
|
}
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//从网关获取场景的执行目标
|
var result = this.GetSceneTargetList();
|
if (result == true)
|
{
|
//添加【执行目标行】
|
this.AddTargetRow();
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 获取及添加【目标行】_______________
|
|
/// <summary>
|
/// 添加【执行目标行】
|
/// </summary>
|
private void AddTargetRow()
|
{
|
//检测网关上的数据是否和本地一致
|
for (int i = 0; i < this.listAdjustTarget.Count; i++)
|
{
|
if (listAdjustTarget[i].Type == 0)
|
{
|
//设备
|
var device = HdlDeviceCommonLogic.Current.GetDevice(listAdjustTarget[i].DeviceAddr, listAdjustTarget[i].Epoint);
|
if (device == null)
|
{
|
//不显示这个不存在本地的设备
|
listAdjustTarget.RemoveAt(i);
|
i--;
|
}
|
continue;
|
}
|
else if (listAdjustTarget[i].Type == 1)
|
{
|
//场景
|
var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(listAdjustTarget[i].ElseScenesId);
|
if (scene == null)
|
{
|
//不显示这个不存在本地的设备
|
listAdjustTarget.RemoveAt(i);
|
i--;
|
}
|
continue;
|
}
|
}
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
for (int i = 0; i < listAdjustTarget.Count; i++)
|
{
|
if (listAdjustTarget[i].Type == 0)
|
{
|
//设备
|
this.AddDeviceTargetRow(listAdjustTarget[i], i, i != listAdjustTarget.Count - 1);
|
}
|
else if (listAdjustTarget[i].Type == 1)
|
{
|
//场景
|
this.AddSceneTargetRow(listAdjustTarget[i], i, i != listAdjustTarget.Count - 1);
|
}
|
else if (listAdjustTarget[i].Type == 2)
|
{
|
//延时
|
this.AddDelayTimeTargetRow(listAdjustTarget[i], i, i != listAdjustTarget.Count - 1);
|
}
|
}
|
//初始化促使界面能够刚好滑动超过保存按钮的控件
|
this.InitFrameBottomTempControl();
|
|
//调整执行目标的桌布高度
|
this.AdjustTargetTableHeight();
|
});
|
}
|
|
#endregion
|
|
#region ■ 添加设备执行目标行_________________
|
|
/// <summary>
|
/// 添加设备执行目标行
|
/// </summary>
|
private void AddDeviceTargetRow(Scene.DeviceListData data, int index, bool addLine)
|
{
|
//设备
|
var device = HdlDeviceCommonLogic.Current.GetDevice(data.DeviceAddr, data.Epoint);
|
var rowDevice = new DeviceRoomControl(device, frameTargetTableControl.rowSpace / 2);
|
rowDevice.MainKeys = index.ToString();
|
this.frameTargetTableControl.AddChidren(rowDevice);
|
//控件向右偏移
|
rowDevice.frameTable.LeftOffset = Application.GetRealWidth(104) - HdlControlResourse.XXLeft;
|
rowDevice.InitControl();
|
rowDevice.frameTable.UseClickStatu = false;
|
|
//状态文本
|
string statuText2 = HdlSafeguardLogic.Current.GetAdjustTargetStatuText(data.TaskList);
|
var btnStatu = rowDevice.frameTable.AddMostRightView(statuText2, 400);
|
if (addLine == true)
|
{
|
//底线
|
rowDevice.frameTable.AddBottomLine();
|
}
|
//分享的场景不能编辑
|
if (this.editorScene == null || this.editorScene.IsSharedScene == false)
|
{
|
if (Config.Instance.Home.IsShowTemplate == true)
|
{
|
//模板场景不允许编辑
|
return;
|
}
|
//编辑
|
var btnEditor = rowDevice.AddEditorControl();
|
btnEditor.ButtonClickEvent += (sender, e) =>
|
{
|
if (device.Type == DeviceType.DimmableLight//调光器
|
|| device.Type == DeviceType.ColorDimmableLight)//彩灯
|
{
|
var form = new UserCenter.Safety.AlarmTargetStatuSelectLightForm();
|
form.AddForm(device, data.TaskList);
|
form.FinishSelectEvent += (statuText, listInfo) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
|
if (listInfo.Count == 0) { statuText = string.Empty; }
|
btnStatu.Text = statuText;
|
//将新的执行目标添加入缓存
|
data.TaskList.Clear();
|
data.TaskList.AddRange(listInfo);
|
};
|
}
|
else if (device.Type == DeviceType.Thermostat)//空调
|
{
|
var form = new UserCenter.Safety.AlarmTargetStatuSelectAcForm();
|
form.AddForm(device, data.TaskList);
|
form.FinishSelectEvent += (statuText, listInfo) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
|
if (listInfo.Count == 0) { statuText = string.Empty; }
|
btnStatu.Text = statuText;
|
//将新的执行目标添加入缓存
|
data.TaskList.Clear();
|
data.TaskList.AddRange(listInfo);
|
};
|
}
|
else if (device.Type == DeviceType.WindowCoveringDevice)//窗帘
|
{
|
var form = new UserCenter.Safety.AlarmTargetStatuSelectCurtainForm();
|
form.AddForm(device, data.TaskList);
|
form.FinishSelectEvent += (statuText, listInfo) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
|
if (listInfo.Count == 0) { statuText = string.Empty; }
|
btnStatu.Text = statuText;
|
//将新的执行目标添加入缓存
|
data.TaskList.Clear();
|
data.TaskList.AddRange(listInfo);
|
};
|
}
|
else
|
{
|
//其他直接归为开关类
|
var form = new UserCenter.Safety.AlarmTargetStatuSelectSwitchForm();
|
form.AddForm(device, data.TaskList);
|
form.FinishSelectEvent += (statuText, listInfo) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
|
if (listInfo.Count == 0) { statuText = string.Empty; }
|
btnStatu.Text = statuText;
|
//将新的执行目标添加入缓存
|
data.TaskList.Clear();
|
data.TaskList.AddRange(listInfo);
|
};
|
}
|
};
|
|
//删除
|
var btnDelete = rowDevice.AddDeleteControl();
|
btnDelete.ButtonClickEvent += (sender, e) =>
|
{
|
//隐藏右滑菜单
|
rowDevice.HideMenu();
|
//确认是否要删除?
|
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
//调整执行目标里面的全部坐标(删除的时候使用)
|
this.AdjustTargetLocation(rowDevice.MainKeys);
|
//移除
|
rowDevice.RemoveFromParent();
|
this.listAdjustTarget.Remove(data);
|
//调整执行目标的桌布高度
|
this.AdjustTargetTableHeight();
|
});
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 添加场景执行目标行_________________
|
|
/// <summary>
|
/// 添加场景执行目标行
|
/// </summary>
|
private void AddSceneTargetRow(Scene.DeviceListData data, int index, bool addLine)
|
{
|
//场景
|
var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(data.ElseScenesId);
|
var rowScene = new SceneRoomControl(scene.Id, scene.Name, frameTargetTableControl.rowSpace / 2);
|
rowScene.MainKeys = index.ToString();
|
frameTargetTableControl.AddChidren(rowScene);
|
//控件向右偏移
|
rowScene.frameTable.LeftOffset = Application.GetRealWidth(104) - HdlControlResourse.XXLeft;
|
rowScene.InitControl();
|
if (addLine == true)
|
{
|
//底线
|
rowScene.frameTable.AddBottomLine();
|
}
|
rowScene.frameTable.UseClickStatu = false;
|
|
//分享的场景不能编辑
|
if (this.editorScene == null || this.editorScene.IsSharedScene == false)
|
{
|
if (Config.Instance.Home.IsShowTemplate == true)
|
{
|
//模板场景不允许编辑
|
return;
|
}
|
//删除
|
var btnDelete = rowScene.AddDeleteControl();
|
btnDelete.ButtonClickEvent += (sender, e) =>
|
{
|
//隐藏右滑菜单
|
rowScene.HideMenu();
|
|
//确认是否要删除?
|
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
//调整执行目标里面的全部坐标(删除的时候使用)
|
this.AdjustTargetLocation(rowScene.MainKeys);
|
//移除
|
rowScene.RemoveFromParent();
|
this.listAdjustTarget.Remove(data);
|
//调整执行目标的桌布高度
|
this.AdjustTargetTableHeight();
|
});
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 添加延时行_________________________
|
|
/// <summary>
|
/// 添加延时行
|
/// </summary>
|
private void AddDelayTimeTargetRow(Scene.DeviceListData data, int index, bool addLine)
|
{
|
string hourText = Language.StringByID(R.MyInternationalizationString.Hour);
|
string minuText = Language.StringByID(R.MyInternationalizationString.Minute);
|
string secondText = Language.StringByID(R.MyInternationalizationString.Second);
|
|
//行控件
|
var rowDelay = new RowLayoutControl(frameTargetTableControl.rowSpace / 2);
|
rowDelay.MainKeys = index.ToString();
|
frameTargetTableControl.AddChidren(rowDelay);
|
//控件向右偏移
|
rowDelay.frameTable.LeftOffset = Application.GetRealWidth(104) - HdlControlResourse.XXLeft;
|
rowDelay.frameTable.UseClickStatu = false;
|
//图标
|
var btnIcon = rowDelay.frameTable.AddLeftIcon();
|
btnIcon.UnSelectedImagePath = "Item/Timer.png";
|
//延时
|
var btnDelay = rowDelay.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.Delay), 400);
|
btnDelay.TextColor = UserCenterColor.Current.TextGrayColor3;
|
|
//x小时x分钟x秒后
|
string timeStr = this.GetTimeString(data.DelayTime, hourText, minuText, secondText);
|
timeStr += Language.StringByID(R.MyInternationalizationString.Later);
|
var btnStatu = rowDelay.frameTable.AddMostRightView(timeStr, 300);
|
|
if (addLine == true)
|
{
|
//底线
|
rowDelay.frameTable.AddBottomLine();
|
}
|
|
//分享的场景不能编辑
|
if (this.editorScene == null || this.editorScene.IsSharedScene == false)
|
{
|
if (Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
//模板场景不允许编辑
|
return;
|
}
|
//编辑
|
var btnEditor = rowDelay.AddEditorControl();
|
btnEditor.ButtonClickEvent += (sender, e) =>
|
{
|
//延时时间选择
|
var form = new AdjustTargetAddDelayTimeForm();
|
form.AddForm(data.DelayTime);
|
form.FinishSelectEvent += (delayTime) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
data.DelayTime = delayTime;
|
//x小时x分钟x秒后
|
timeStr = this.GetTimeString(data.DelayTime, hourText, minuText, secondText);
|
btnStatu.Text = timeStr;
|
};
|
};
|
//删除
|
var btnDelete = rowDelay.AddDeleteControl();
|
btnDelete.ButtonClickEvent += (sender, e) =>
|
{
|
//隐藏右滑菜单
|
rowDelay.HideMenu();
|
//确认是否要删除?
|
string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
//调整执行目标里面的全部坐标(删除的时候使用)
|
this.AdjustTargetLocation(rowDelay.MainKeys);
|
//移除
|
rowDelay.RemoveFromParent();
|
this.listAdjustTarget.Remove(data);
|
//调整执行目标的桌布高度
|
this.AdjustTargetTableHeight();
|
});
|
};
|
}
|
}
|
|
/// <summary>
|
/// 从网关获取场景的执行目标
|
/// </summary>
|
/// <returns></returns>
|
private bool GetSceneTargetList()
|
{
|
if (this.editorScene == null || this.listAdjustTarget != null)
|
{
|
return true;
|
}
|
|
//打开进度条
|
this.ShowProgressBar();
|
//获取执行目标列表
|
var listData = HdlSceneLogic.Current.GetAdjustTargetList(this.editorScene);
|
if (listData == null)
|
{
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return false;
|
}
|
this.listAdjustTarget = new List<Scene.DeviceListData>();
|
listAdjustTarget.AddRange(listData);
|
|
this.CloseProgressBar();
|
return true;
|
}
|
|
|
#endregion
|
|
#region ■ 初始化促使界面滑动控件_____________
|
|
/// <summary>
|
/// 初始化促使界面能够刚好滑动超过保存按钮的控件
|
/// </summary>
|
private void InitFrameBottomTempControl()
|
{
|
if (this.frameBottomTemp != null)
|
{
|
return;
|
}
|
//借用一下控件的Y轴
|
var btnTemp = new BottomClickButton();
|
|
//那个特殊的控件
|
this.frameBottomTemp = new FrameLayout();
|
frameBottomTemp.Height = bodyFrameLayout.Height - btnTemp.Yaxis + Application.GetRealHeight(23);
|
this.listBodyControl.AddChidren(frameBottomTemp);
|
}
|
|
#endregion
|
|
#region ■ 显示添加目标菜单___________________
|
|
/// <summary>
|
/// 显示添加目标菜单
|
/// </summary>
|
private void ShowAddTargetMenu()
|
{
|
var menuContr = new BottomMenuSelectForm();
|
menuContr.AddForm(3);
|
//功能
|
menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uFunction), () =>
|
{
|
var form = new AdjustTargetAddDeviceForm();
|
form.AddForm(listAdjustTarget);
|
form.FinishSelectEvent += (dicData) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
foreach (var mainKey in dicData.Keys)
|
{
|
var device = HdlDeviceCommonLogic.Current.GetDevice(mainKey);
|
var data = new Scene.DeviceListData();
|
data.Type = 0;
|
data.DeviceAddr = device.DeviceAddr;
|
data.Epoint = device.DeviceEpoint;
|
data.TaskList = dicData[mainKey];
|
this.listAdjustTarget.Add(data);
|
}
|
//刷新列表控件
|
this.InitAddTargetControl();
|
};
|
});
|
//场景
|
menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uScence), () =>
|
{
|
var form = new AdjustTargetAddSceneForm();
|
form.AddForm(listAdjustTarget);
|
form.FinishSelectEvent += (listSceneId) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
foreach (int sceneId in listSceneId)
|
{
|
var data = new Scene.DeviceListData();
|
data.Type = 1;
|
data.ElseScenesId = sceneId;
|
this.listAdjustTarget.Add(data);
|
}
|
//刷新列表控件
|
this.InitAddTargetControl();
|
};
|
});
|
//延时
|
menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.Delay), () =>
|
{
|
//延时时间选择
|
var form = new AdjustTargetAddDelayTimeForm();
|
form.AddForm(0);
|
form.FinishSelectEvent += (delayTime) =>
|
{
|
//执行目标已经改变
|
this.isAdjustTargetChanged = true;
|
var data = new Scene.DeviceListData();
|
data.Type = 2;
|
data.DelayTime = delayTime;
|
this.listAdjustTarget.Add(data);
|
//刷新列表控件
|
this.InitAddTargetControl();
|
};
|
});
|
}
|
|
#endregion
|
|
#region ■ 保存场景数据_______________________
|
|
/// <summary>
|
/// 保存场景数据
|
/// </summary>
|
private void SaveSceneData()
|
{
|
//检测能否保存场景
|
if (this.CheckCanSaveScene() == false)
|
{
|
return;
|
}
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//打开进度条
|
this.ShowProgressBar();
|
//新建场景
|
if (this.editorScene == null)
|
{
|
//保存新建的场景
|
this.SaveSceneDataByNewMode();
|
}
|
//编辑场景
|
else
|
{
|
//保存编辑的场景
|
this.SaveSceneDataByEditorMode();
|
}
|
});
|
}
|
|
/// <summary>
|
/// 保存新建的场景
|
/// </summary>
|
private void SaveSceneDataByNewMode()
|
{
|
//添加场景
|
this.editorScene = HdlSceneLogic.Current.AddNewSceneToGateway(this.cloneScene.Name, this.listAdjustTarget);
|
//关闭进度条
|
this.CloseProgressBar();
|
|
if (editorScene == null)
|
{
|
return;
|
}
|
if (this.nowRoomId != string.Empty)
|
{
|
//添加房间
|
var newRoom = HdlRoomLogic.Current.GetRoomById(this.nowRoomId);
|
HdlSceneLogic.Current.AddSceneToRoom(newRoom, this.editorScene);
|
}
|
if (this.cloneScene.IconPathType != 0)
|
{
|
//自定义图片
|
var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss");
|
var fileName = $"SceneIcon_{tradeTime}.png";
|
//生成文件图片
|
IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), this.btnScenePic.ImageBytes);
|
HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(fileName);
|
this.cloneScene.IconPath = fileName;
|
}
|
//转移属性
|
this.editorScene.Name = this.cloneScene.Name;
|
this.editorScene.IconPathType = this.cloneScene.IconPathType;
|
this.editorScene.IconPath = this.cloneScene.IconPath;
|
this.editorScene.Save();
|
|
//新建场景,主页需要重新刷新
|
UserView.UserPage.Instance.RefreshAllForm = true;
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//调用回调函数
|
this.SceneChangedEvent?.Invoke(this.editorScene, this.nowRoomId);
|
this.CloseForm();
|
});
|
}
|
|
/// <summary>
|
/// 保存编辑的场景
|
/// </summary>
|
private async void SaveSceneDataByEditorMode()
|
{
|
if (this.editorScene.Name != this.cloneScene.Name)
|
{
|
//修改名称
|
var result = await HdlSceneLogic.Current.EditorSceneNameFromGateway(this.editorScene, this.cloneScene.Name);
|
if (result == false)
|
{
|
//关闭进度条
|
this.CloseProgressBar();
|
return;
|
}
|
}
|
if (isAdjustTargetChanged == true)
|
{
|
//修改场景
|
var result = await HdlSceneLogic.Current.EditorSceneFromGateway(this.editorScene, this.listAdjustTarget);
|
if (result == false)
|
{
|
//关闭进度条
|
this.CloseProgressBar();
|
return;
|
}
|
}
|
|
if (this.nowRoomId != string.Empty)
|
{
|
//变更房间
|
HdlSceneLogic.Current.ChangedSceneRoom(this.editorScene, this.nowRoomId);
|
}
|
else
|
{
|
//移除出房间
|
var room = HdlRoomLogic.Current.GetRoomBySceneId(this.editorScene.Id);
|
if (room != null)
|
{
|
HdlSceneLogic.Current.DeleteSceneFromRoom(room, this.editorScene);
|
}
|
}
|
|
//图片改变了
|
if (isScenePictrueChanged == true)
|
{
|
if (this.editorScene.IconPathType != 0)
|
{
|
//删除自定义图片
|
HdlFileLogic.Current.DeleteFile(System.IO.Path.Combine(Config.Instance.FullPath, this.editorScene.IconPath));
|
HdlBackupLogic.Current.DeleteAutoBackFileStatu(this.editorScene.IconPath);
|
}
|
if (this.cloneScene.IconPathType != 0)
|
{
|
//自定义图片
|
var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss");
|
var fileName = $"SceneIcon_{tradeTime}.png";
|
//生成文件图片
|
IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), this.btnScenePic.ImageBytes);
|
HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(fileName);
|
this.cloneScene.IconPath = fileName;
|
}
|
}
|
|
//转移属性
|
this.editorScene.Name = this.cloneScene.Name;
|
this.editorScene.IconPathType = this.cloneScene.IconPathType;
|
this.editorScene.IconPath = this.cloneScene.IconPath;
|
this.editorScene.Save();
|
|
//编辑场景,主页需要重新刷新
|
UserView.UserPage.Instance.RefreshAllForm = true;
|
|
//关闭进度条
|
this.CloseProgressBar();
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//调用回调函数
|
this.SceneChangedEvent?.Invoke(this.editorScene, this.nowRoomId);
|
this.CloseForm();
|
});
|
}
|
|
/// <summary>
|
/// 检测能否保存场景
|
/// </summary>
|
/// <returns></returns>
|
private bool CheckCanSaveScene()
|
{
|
if (this.cloneScene.Name == string.Empty)
|
{
|
//场景名不能为空
|
this.ShowMassage(ShowMsgType.Remind, Language.StringByID(R.MyInternationalizationString.SceneNameCannotBeNull));
|
return false;
|
}
|
bool hadTarget = false;
|
foreach (var data in this.listAdjustTarget)
|
{
|
if (data.Type == 0 || data.Type == 1)
|
{
|
//拥有执行目标
|
hadTarget = true;
|
break;
|
}
|
}
|
if (hadTarget == false)
|
{
|
//请添加执行目标
|
this.ShowMassage(ShowMsgType.Remind, Language.StringByID(R.MyInternationalizationString.uPleaseAddAdjustTarget));
|
return false;
|
}
|
return true;
|
}
|
|
#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 form = new SelectLocalSceneImageForm();
|
form.AddForm();
|
form.FinishSelectEvent = (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);
|
//场景图片已经改变
|
this.isScenePictrueChanged = true;
|
};
|
});
|
//拍照
|
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);
|
//场景图片已经改变
|
this.isScenePictrueChanged = true;
|
|
}, "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);
|
//场景图片已经改变
|
this.isScenePictrueChanged = true;
|
|
}, "HdlPic", 2, 1);
|
});
|
}
|
|
#endregion
|
|
#region ■ 界面关闭___________________________
|
|
/// <summary>
|
/// 界面关闭
|
/// </summary>
|
public override void CloseFormBefore()
|
{
|
this.SceneChangedEvent = null;
|
|
base.CloseFormBefore();
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 获取时间的翻译文本
|
/// </summary>
|
/// <param name="second"></param>
|
/// <param name="hourText">小时的文本</param>
|
/// <param name="minuText">分的文本</param>
|
/// <param name="secondText">秒的文本</param>
|
/// <returns></returns>
|
private string GetTimeString(int second, string hourText, string minuText, string secondText)
|
{
|
string timeStr = string.Empty;
|
int hour = second / 3600;
|
int minu = second % 3600 / 60;
|
int sec = second % 60;
|
if (hour > 0)
|
{
|
timeStr += hour + hourText;
|
}
|
if (minu > 0)
|
{
|
timeStr += minu + minuText;
|
}
|
if (sec > 0)
|
{
|
timeStr += sec + secondText;
|
}
|
return timeStr;
|
}
|
|
/// <summary>
|
/// 调整执行目标的桌布高度
|
/// </summary>
|
private void AdjustTargetTableHeight()
|
{
|
//调整桌布高度
|
int minHeight = Application.GetRealHeight(346);
|
int realHeight = frameTargetTableControl.GetChildren(frameTargetTableControl.ChildrenCount - 1).Bottom;
|
realHeight += Application.GetRealHeight(23);
|
if (realHeight > minHeight)
|
{
|
frameTargetTableControl.Height = realHeight;
|
}
|
else if (frameTargetTableControl.Height != minHeight)
|
{
|
frameTargetTableControl.Height = minHeight;
|
}
|
//这个特殊的东西必须放在执行目标容器的底部
|
this.frameBottomTemp.Y = frameTargetTableControl.Bottom;
|
//调整全局上下滑动控件的桌布高度
|
this.listBodyControl.AdjustTableHeight();
|
}
|
|
/// <summary>
|
/// 调整执行目标里面的全部坐标(删除的时候使用)
|
/// </summary>
|
/// <param name="mainKey">删除的主键</param>
|
private void AdjustTargetLocation(string mainKey)
|
{
|
bool canChanged = false;
|
int YY = 0;
|
for (int i = 0; i < frameTargetTableControl.ChildrenCount; i++)
|
{
|
var myRow = frameTargetTableControl.GetChildren(i);
|
if (canChanged == false && (myRow is RowLayoutControl))
|
{
|
if (((RowLayoutControl)myRow).MainKeys == mainKey)
|
{
|
//已经到达要删除的索引
|
canChanged = true;
|
YY = frameTargetTableControl.GetChildren(i).Y;
|
}
|
continue;
|
}
|
if (canChanged == true)
|
{
|
//它下面的行全部往上移
|
myRow.Y = YY;
|
YY = myRow.Bottom;
|
}
|
}
|
}
|
|
#endregion
|
}
|
}
|