using Shared.SimpleControl.Phone;
using System;
using System.Collections.Generic;
namespace Shared.SimpleControl.Pad
{
///
/// 用户场景界面
///
public class UserScenePage : FrameLayout
{
public static readonly VerticalScrolViewLayout VerticalScrolView_InUserMiddleView = new VerticalScrolViewLayout ();
Button beforeClickButton = new Button ();
FrameLayout LongPressFrameLayout = new FrameLayout ();
///
///构造函数
///
public UserScenePage (Room room)
{
BackgroundColor = 0xFF2f2f2f;
ShowUserScene (room);
}
///
/// 刷新界面
///
/// Room file path.
public void ShowUserSceneForFileName (string roomFilePath)
{
Room.InitAllRoom ();
if (roomFilePath == Scene.GlobalSceneFilePath)
ShowUserScene (null);
else {
Room room = Room.GetRoomByFilePath (roomFilePath);
ShowUserScene (room);
}
}
public void ShowUserScene (Room room)
{
#region bodyView
this.RemoveAll ();
FrameLayout bodyView = new FrameLayout ();
AddChidren (bodyView);
VerticalScrolViewLayout scenesBodyView = new VerticalScrolViewLayout ();
bodyView.AddChidren (scenesBodyView);
FrameLayout scenesRowView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (254),
};
//显示每个房间有多少个场景
List sceneFileList = null;
if (room != null) {
sceneFileList = room.SceneFilePathList;
} else
sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
List sceneFilePaths = new List ();//存路径
sceneFilePaths = sceneFileList;
sceneFilePaths.Add ("");
for (int index = 0; index < sceneFilePaths.Count; index++) {
var sceneFilePath = sceneFilePaths [index];
var scene = Scene.GetSceneByFilePath (sceneFilePath);
// 当场景不存在时,可以NEW 一个场景,不然值一直是空的
if (scene == null) {
scene = new Scene ();
}
if (index % 4 == 0) {
Button btnR = new Button () {
Height = Application.GetRealHeight (20),
};
scenesBodyView.AddChidren (btnR);
scenesRowView = new FrameLayout () {
X = Application.GetRealWidth (20),
//Width = Application.GetRealWidth(320),
Height = Application.GetRealHeight (280),
};
scenesBodyView.AddChidren (scenesRowView);
}
var sceneView = new FrameLayout () {
Width = Application.GetRealWidth (365),
BackgroundImagePath = scene.BackgroundImagePath,
};
scenesRowView.AddChidren (sceneView);
if (index % 4 == 1) {
sceneView.X = Application.GetRealWidth (385 * 1);
} else if (index % 4 == 2) {
sceneView.X = Application.GetRealWidth (385 * 2);
} else if (index % 4 == 3) {
sceneView.X = Application.GetRealWidth (385 * 3);
}
if (index == sceneFilePaths.Count - 1) {
sceneView.BackgroundImagePath = "Item/SceneAdd.png";
sceneView.MouseUpEventHandler += (sender, e) => {
if (room == null)
SceneMethod.AddOrUpdataSceneBaseMassage (Scene.GlobalSceneFilePath, null, ShowUserSceneForFileName);
else
SceneMethod.AddOrUpdataSceneBaseMassage (typeof (Room).Name + "_" + room.Name, null, ShowUserSceneForFileName);
};
} else {
Button btnSceneName = new Button () {
Height = Application.GetRealHeight (40),
Y = Application.GetRealHeight (240),
BackgroundColor = 0xFFDBDDDF,
};
sceneView.AddChidren (btnSceneName);
var btnBGC = new Button () {
UnSelectedImagePath = "Item/sss.png",
SelectedImagePath = "Item/SceneSettingBackground.png",
TextAlignment = TextAlignment.BottomCenter,
Text = scene.Name,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 15,
};
sceneView.AddChidren (btnBGC);
if (room != null) {
btnBGC.MouseLongEventHandler += (sender, e) => {
if (string.IsNullOrEmpty (scene.Name))
return;
LongPressFrameLayout = new FrameLayout () {
BackgroundImagePath = "Item/SceneSettingBackground.png",
};
LongPressFrameLayout.MouseUpEventHandler += (sender2, e2) => {
LongPressFrameLayout.RemoveFromParent ();
};
sceneView.AddChidren (LongPressFrameLayout);
var btnEditor = new Button () {
Width = Application.GetRealWidth (70),
Height = Application.GetRealHeight (76),
UnSelectedImagePath = "Item/UserSceneEditIcon.png",
X = Application.GetRealWidth (250),
Y = Application.GetRealHeight (20),
};
LongPressFrameLayout.AddChidren (btnEditor);
btnEditor.MouseUpEventHandler += (sender1, e1) => {
var addSceneDevcie = new UserAddSceneDevice (typeof (Room).Name + "_" + room.Name, sceneFilePath, (newSceneFilePath) => {
sceneFilePath = newSceneFilePath;
scene = Scene.GetSceneByFilePath (sceneFilePath);
sceneView.BackgroundImagePath = scene.BackgroundImagePath;
ShowUserSceneForFileName (typeof (Room).Name + "_" + room.Name);
});
this.AddChidren (addSceneDevcie);
addSceneDevcie.ShowAddSceneDeviceView ();
};
var btnDel = new Button () {
Width = Application.GetRealWidth (70),
Height = Application.GetRealHeight (76),
UnSelectedImagePath = "Item/UserSceneDelIcon.png",
X = Application.GetRealWidth (40),
Y = Application.GetRealHeight (20),
};
LongPressFrameLayout.AddChidren (btnDel);
btnDel.MouseUpEventHandler += (senderDel, eDel) => {
IO.FileUtils.DeleteFile (sceneFilePath);
room.SceneFilePathList.Remove (sceneFilePath);
room.SceneFilePathList.Remove ("");
room.Save (typeof (Room).Name + "_" + room.Name);
ShowUserSceneForFileName (typeof (Room).Name + "_" + room.Name);
};
};
} else {
btnBGC.MouseLongEventHandler += (sender, e) => {
if (string.IsNullOrEmpty (scene.Name))
return;
LongPressFrameLayout = new FrameLayout () {
BackgroundImagePath = "Item/SceneSettingBackground.png",
};
sceneView.AddChidren (LongPressFrameLayout);
LongPressFrameLayout.MouseUpEventHandler += (sender2, e2) => {
LongPressFrameLayout.RemoveFromParent ();
};
var btnEditor = new Button () {
Width = Application.GetRealWidth (70),
Height = Application.GetRealHeight (76),
UnSelectedImagePath = "Item/UserSceneEditIcon.png",
X = Application.GetRealWidth (240),
Y = Application.GetRealHeight (20),
};
LongPressFrameLayout.AddChidren (btnEditor);
btnEditor.MouseUpEventHandler += (sender1, e1) => {
var addSceneDevice = new UserAddSceneDevice (Scene.GlobalSceneFilePath, sceneFilePath, (newSceneFilePath) => {
sceneFilePath = newSceneFilePath;
scene = Scene.GetSceneByFilePath (sceneFilePath);
sceneView.BackgroundImagePath = scene.BackgroundImagePath;
});
this.AddChidren (addSceneDevice);
addSceneDevice.ShowAddSceneDeviceView ();
};
var btnDel = new Button () {
Width = Application.GetRealWidth (70),
Height = Application.GetRealHeight (76),
UnSelectedImagePath = "Item/UserSceneDelIcon.png",
X = Application.GetRealWidth (40),
Y = Application.GetRealHeight (20),
};
LongPressFrameLayout.AddChidren (btnDel);
btnDel.MouseUpEventHandler += (senderDel, eDel) => {
IO.FileUtils.DeleteFile (sceneFilePath);
sceneFileList.Remove (sceneFilePath);
sceneFileList.Remove ("");
IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
ShowUserSceneForFileName (Scene.GlobalSceneFilePath);
};
};
}
btnBGC.MouseUpEventHandler += (sender, e) => {
LongPressFrameLayout.RemoveFromParent ();
beforeClickButton.IsSelected = false;
beforeClickButton = btnBGC;
btnBGC.IsSelected = true;
SceneMethod.ControlScene (scene);
};
}
}
sceneFileList.Remove ("");
#endregion
}
}
}