using Shared.SimpleControl.Phone;
using System;
using System.Collections.Generic;
using Shared.SimpleControl.Pad;
using System.Text;
namespace Shared.SimpleControl.Pad
{
///
/// 用户场景界面,用户场景界面
///
public class UserGlobalScenes : Shared.Dialog
{
FrameLayout LongPressFrameLayout = new FrameLayout ();
Button beforeClickButton = new Button ();
FrameLayout mainFrameLayout = new FrameLayout ();//重复加载界面
///
/// 显示当前房间的场景
///
/// Room.
public UserGlobalScenes ()
{
BackgroundColor = 0xFF2f2f2f;
AddChidren (mainFrameLayout);
showGlobalScene ();
}
///
/// 显示当前视图
///
void showGlobalScene (string s ="")
{
mainFrameLayout.RemoveAll ();
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
};
mainFrameLayout.AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = Language.StringByID (R.MyInternationalizationString.Scenes),
TextSize = 19,
};
topView.AddChidren (title);
var logo = new Button () {
Width = Application.GetRealWidth (154),
Height = Application.GetRealHeight (90),
X = Application.GetRealWidth (486),
UnSelectedImagePath = MainPage.LogoString,
};
topView.AddChidren (logo);
var back = new Button () {
Height = Application.GetRealHeight (100),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
Gravity = Gravity.CenterVertical,
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
Close ();
new UserDeviceToScene ().Refresh ();
};
var line = new Button () {
Height = 1,
BackgroundColor = 0xFF2f2f2f,
Y = topView.Height - 1
};
topView.AddChidren (line);
#endregion
#region bodyView
var bodyView = new FrameLayout () {
Y = topView.Bottom,
};
mainFrameLayout.AddChidren (bodyView);
var scenesBodyView = new VerticalScrolViewLayout () {
Height = Application.GetRealHeight (1136 - 90 - 36),
};
bodyView.AddChidren (scenesBodyView);
//所有场景
var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
List sceneFilePaths = new List ();//存路径
sceneFilePaths = sceneFileList;
sceneFilePaths.Add ("");
FrameLayout scenesRowView = null;
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 % 2 == 0) {
scenesRowView = new FrameLayout () {
Height = Application.GetRealHeight (250),
};
scenesBodyView.AddChidren (scenesRowView);
}
var sceneView = new FrameLayout () {
Width = Application.GetRealWidth (320),
BackgroundImagePath = scene.BackgroundImagePath,
};
scenesRowView.AddChidren (sceneView);
if (index % 2 == 1) {
sceneView.X = Application.GetRealWidth (320);
}
if (index == sceneFilePaths.Count - 1) {
sceneView.BackgroundImagePath = "Item/SceneAdd.png";
sceneView.MouseUpEventHandler += (sender, e) => {
SceneMethod.AddOrUpdataSceneBaseMassage (Scene.GlobalSceneFilePath, null, showGlobalScene);
};
} else {
Button btnSceneName = new Button () {
Height = Application.GetRealHeight (40),
Y = Application.GetRealHeight (210),
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);
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 (243),
Y = Application.GetRealHeight (13),
};
LongPressFrameLayout.AddChidren (btnEditor);
btnEditor.MouseUpEventHandler += (sender1, e1) => {
AddChidren (new UserAddSceneDevice (Scene.GlobalSceneFilePath, sceneFilePath, (newSceneFilePath) => {
sceneFilePath = newSceneFilePath;
scene = Scene.GetSceneByFilePath (sceneFilePath);
sceneView.BackgroundImagePath = scene.BackgroundImagePath;
}));
};
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)));
showGlobalScene ();
};
};
btnBGC.MouseUpEventHandler += (sender, e) => {
LongPressFrameLayout.RemoveFromParent ();
beforeClickButton.IsSelected = false;
beforeClickButton = btnBGC;
btnBGC.IsSelected = true;
SceneMethod.ControlScene (scene);
};
}
}
#endregion
}
}
}