using Shared.Common;
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.Category
{
///
/// 场景执行目标添加设备的界面
///
public class AdjustTargetAddSceneForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 完成选择的事件(场景ID)
///
public Action> FinishSelectEvent = null;
///
/// 当前已经添加的执行目标
///
private List listAdjustTarget = null;
///
/// 当前已经添加的场景ID(存在检测用)
///
private List listOldSceneId = null;
///
/// 当前界面上选择的场景(存在检测用)
///
private List listNewScene = null;
///
/// 完成按钮
///
private BottomClickButton btnFinishControl = null;
///
/// 场景列表控件
///
private VerticalListControl listSceneView = null;
///
/// 当前选择的楼层
///
private string nowSelectFloorId = string.Empty;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 当前执行目标列表
public void ShowForm(List i_listAdjustTarget)
{
this.listAdjustTarget = i_listAdjustTarget;
//设置头部信息
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.AddScence));
//初始化右上角的控件
this.InitTopRightMenuControl();
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//清空body
this.ClearBodyFrame();
//获取能够显示的房间列表
var listRoom = this.GetCanShowRoomList();
if (listRoom.Count == 0)
{
//没有可以添加的场景
this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddScene));
return;
}
//房间菜单控件
var roomSwitchContr = new RoomDeviceGroupMenuControl(listRoom);
this.bodyFrameLayout.AddChidren(roomSwitchContr);
//选择事件
roomSwitchContr.SelectRoomEvent += (selectRoom) =>
{
//在外面清空(特效的问题)
this.listSceneView?.RemoveAll();
HdlThreadLogic.Current.RunMainInThread(() =>
{
//刷新设备分支控件
this.RefreshFunctionView(selectRoom);
});
};
this.listSceneView = new VerticalListControl(35);
listSceneView.BackgroundColor = UserCenterColor.Current.White;
listSceneView.Y = roomSwitchContr.Bottom;
listSceneView.Height = bodyFrameLayout.Height - roomSwitchContr.Bottom;
bodyFrameLayout.AddChidren(listSceneView);
//完成按钮
this.btnFinishControl = new BottomClickButton();
btnFinishControl.TextID = R.MyInternationalizationString.uFinish;
bodyFrameLayout.AddChidren(btnFinishControl);
if (this.listNewScene == null || this.listNewScene.Count == 0)
{
btnFinishControl.Visible = false;
}
btnFinishControl.ButtonClickEvent += (sender, e) =>
{
//回调函数
this.FinishSelectEvent?.Invoke(listNewScene);
this.CloseForm();
};
//执行初始化(会自动触发SelectRoomEvent事件)
roomSwitchContr.InitControl();
}
///
/// 初始化右上角的控件
///
private void InitTopRightMenuControl()
{
//获取楼层
var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
if (dicFloor.Count == 0)
{
return;
}
var btnIconContr = new MostRightIconControl(69, 69);
btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
topFrameLayout.AddChidren(btnIconContr);
btnIconContr.InitControl();
var btnFloor = new NormalViewControl(300, 69, true);
btnFloor.Gravity = Gravity.CenterVertical;
btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
btnFloor.TextAlignment = TextAlignment.CenterRight;
topFrameLayout.AddChidren(btnFloor);
foreach (var floorId in dicFloor.Keys)
{
//第一个楼层
this.nowSelectFloorId = floorId;
btnFloor.Text = dicFloor[floorId];
break;
}
btnIconContr.ButtonClickEvent += (sender, e) =>
{
//楼层菜单
var contr = new TopRightFloorMenuControl(dicFloor.Count, 2, this.nowSelectFloorId, Language.StringByID(R.MyInternationalizationString.SelectFloor));
foreach (var floorId in dicFloor.Keys)
{
contr.AddRowMenu(floorId, () =>
{
//记录起选择的ID
this.nowSelectFloorId = floorId;
btnFloor.Text = dicFloor[this.nowSelectFloorId];
//初始化中部信息
this.InitMiddleFrame();
});
}
};
}
#endregion
#region ■ 刷新场景列表_______________________
///
/// 刷新功能分支控件
///
///
private void RefreshFunctionView(Room room)
{
//获取房间场景列表
var listScene = this.GetListSceneFromRoom(room);
for (int i = 0; i < listScene.Count; i++)
{
var scene = listScene[i];
//场景行控件
var rowContr = new FrameRowControl(listSceneView.rowSpace / 2);
listSceneView.AddChidren(rowContr);
//图标
var btnIcon = rowContr.AddLeftIcon(81);
btnIcon.UnSelectedImagePath = "Scene/SceneIcon.png";
//场景名
var btnName = rowContr.AddLeftCaption(scene.Name, 700);
btnName.TextSize = 15;
//选择
var btnSelect = rowContr.AddMostRightEmptyIcon(58, 58);
btnSelect.Visible = false;
btnSelect.UnSelectedImagePath = "Item/ItemSelected.png";
if (i != listScene.Count - 1)
{
//底线
rowContr.AddBottomLine();
}
if (listNewScene.Contains(scene.Id) == true)
{
btnSelect.Visible = true;
}
//点击事件
rowContr.ButtonClickEvent += (sender, e) =>
{
btnSelect.Visible = !btnSelect.Visible;
if (btnSelect.Visible == true)
{
//添加缓存
listNewScene.Add(scene.Id);
if (btnFinishControl.Visible == false)
{
btnFinishControl.Visible = true;
}
}
else
{
//移除缓存
listNewScene.Remove(scene.Id);
if (listNewScene.Count == 0)
{
btnFinishControl.Visible = false;
}
}
};
}
//调整控件桌布高度
this.listSceneView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
}
#endregion
#region ■ 获取房间场景列表___________________
///
/// 获取房间场景列表
///
///
private List GetListSceneFromRoom(Common.Room room)
{
//获取全部的场景
var listAllScene = HdlSceneLogic.Current.GetRoomSceneList(room);
var listShowScene = new List();
foreach (var scene in listAllScene)
{
//判断该场景能否显示
if (this.CheckSceneCanShow(scene) == true)
{
listShowScene.Add(scene);
}
}
return listShowScene;
}
#endregion
#region ■ 获取房间列表_______________________
///
/// 获取能够显示的房间列表
///
///
///
private List GetCanShowRoomList()
{
if (this.listNewScene == null)
{
//先列表化
this.listOldSceneId = new List();
this.listNewScene = new List();
foreach (var data in this.listAdjustTarget)
{
if (data.Type == 1)
{
//只要场景
listOldSceneId.Add(data.ElseScenesId);
}
}
}
//当前楼层的全部房间
var lisrRoom = HdlRoomLogic.Current.GetRoomsByFloorIdAppendLoveRoom(this.nowSelectFloorId);
var listShowRoom = new List();
foreach (var room in lisrRoom)
{
foreach (var sceneId in room.ListSceneId)
{
var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId);
if (this.CheckSceneCanShow(scene) == true)
{
//这个场景本地存在,并且它还没有加入到执行目标列表,则这个房间可以显示
listShowRoom.Add(room);
break;
}
}
}
return listShowRoom;
}
#endregion
#region ■ 界面关闭___________________________
///
/// 界面关闭
///
public override void CloseFormBefore()
{
this.FinishSelectEvent = null;
base.CloseFormBefore();
}
#endregion
#region ■ 一般方法___________________________
///
/// 检测场景能否显示
///
///
private bool CheckSceneCanShow(SceneUI i_scene)
{
//本地不存在
if (i_scene == null) { return false; }
if (this.listOldSceneId.Contains(i_scene.Id) == true)
{
return false;
}
return true;
}
#endregion
#region ■ 结构体_____________________________
///
/// 设备行信息
///
private class DeviceRowInfo
{
///
/// 文本ID,目前用来做主键
///
public int TextId = 0;
///
/// 图标
///
public string IconPath = string.Empty;
///
/// 图标
///
public string IconPathSelected = string.Empty;
///
/// 设备回路主键
///
public List listDeviceKeys = new List();
}
#endregion
}
}