using System;
using System.Collections.Generic;
namespace Shared.SimpleControl.Phone
{
public class UserDeviceToScene : FrameLayout
{
VerticalScrolViewLayout bodyScrolView;
FrameLayout LongPressFrameLayout = new FrameLayout ();
static UserDeviceToScene curView;
Button beforeClickButton = null;
///
/// 构造函数
///
public UserDeviceToScene ()
{
BackgroundColor = SkinStyle.Current.MainColor;
curView = this;
}
public static bool hasModify = false;
public static void Refresh ()
{
if (curView == null)
return;
if (hasModify) {
curView.ShowAllScene ();
hasModify = false;
}
}
///
/// 显示房间的所有场景
///
public void ShowAllScene ()
{
this.RemoveAll ();
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = Language.StringByID (R.MyInternationalizationString.Scenes),
TextSize = 19,
TextColor = SkinStyle.Current.TextColor1,
};
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 (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
curView = null;
};
#endregion
#region titelView
var roomTitleView = new FrameLayout () {
Height = Application.GetRealHeight (110),
BackgroundColor = SkinStyle.Current.TitileView,
Y = topView.Bottom,
};
AddChidren (roomTitleView);
var btnRoomArea = new Button () {
Width = Application.GetRealWidth (320),
TextSize = 16,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.RoomArea,
IsSelected = !UserConfig.Instance.SceneOfGloba
};
roomTitleView.AddChidren (btnRoomArea);
var btnGloba = new Button () {
Width = Application.GetRealWidth (320),
X = btnRoomArea.Right,
TextSize = 16,
SelectedTextColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.GlobaScene,
IsSelected = UserConfig.Instance.SceneOfGloba
};
roomTitleView.AddChidren (btnGloba);
var btnLine = new Button () {
Width = 1,
Height = Application.GetRealHeight (110) - 1,
BackgroundColor = SkinStyle.Current.White20Transparent,
X = btnRoomArea.Right,
Y = 1,
};
roomTitleView.AddChidren (btnLine);
btnRoomArea.MouseUpEventHandler += (sender, e) => {
btnRoomArea.IsSelected = true;
btnGloba.IsSelected = false;
UserConfig.Instance.SceneOfGloba = false;
UserConfig.Instance.SaveUserConfig ();
InitView (UserConfig.Instance.SceneOfGloba);
};
btnGloba.MouseUpEventHandler += (sender, e) => {
btnGloba.IsSelected = true;
btnRoomArea.IsSelected = false;
UserConfig.Instance.SceneOfGloba = true;
UserConfig.Instance.SaveUserConfig ();
InitView (UserConfig.Instance.SceneOfGloba);
};
#endregion
var bodyView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (Application.DesignHeight) - roomTitleView.Bottom,
Y = roomTitleView.Bottom,
BackgroundColor = SkinStyle.Current.ViewColor
};
AddChidren (bodyView);
bodyScrolView = new VerticalScrolViewLayout ();
bodyView.AddChidren (bodyScrolView);
InitView (UserConfig.Instance.SceneOfGloba);
}
Button lastSceneButton = null;
void InitView (bool isGolba)
{
bodyScrolView.RemoveAll ();
if (isGolba) {
var sceneFilePaths = Newtonsoft.Json.JsonConvert.DeserializeObject> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
if (sceneFilePaths == null) {
sceneFilePaths = new List ();//存路径
IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFilePaths)));
}
sceneFilePaths.Add ("");
FrameLayout scenesRowView = null;
for (int index = 0; index < sceneFilePaths.Count; index++) {
var sceneFilePath = sceneFilePaths [index];
var scene = Scene.GetSceneByFilePath (sceneFilePath);
if (scene == null) {
scene = new Scene ();
}
if (index % 2 == 0) {
scenesRowView = new FrameLayout () {
Height = Application.GetRealWidth (250),
};
bodyScrolView.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) => {
new ScenePhoneMethod ().AddOrUpdataSceneBaseMassage (Scene.GlobalSceneFilePath, null, (newGlobaFile) => {
InitView (isGolba);
});
};
} else {
Button btnSceneName = new Button () {
Height = Application.GetRealWidth (40),
Y = Application.GetRealWidth (210),
BackgroundColor = SkinStyle.Current.Black50Transparent,
};
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,
IsSelected = UserConfig.Instance.CurScene == sceneFilePath ? true : false
};
sceneView.AddChidren (btnBGC);
if(UserConfig.Instance.CurScene == sceneFilePath) {
beforeClickButton = btnBGC;
}
btnBGC.MouseLongEventHandler += (sender, e) => {
//if (string.IsNullOrEmpty (scene.Name))
// return;
LongPressFrameLayout = new FrameLayout () {
BackgroundColor = SkinStyle.Current.SceneTransparentBackColor,
};
sceneView.AddChidren (LongPressFrameLayout);
LongPressFrameLayout.MouseUpEventHandler += (sender2, e2) => {
LongPressFrameLayout.RemoveFromParent ();
};
var btnEditor = new Button () {
Width = Application.GetRealWidth (70),
Height = Application.GetMinRealAverage (76),
UnSelectedImagePath = "Item/UserSceneEditIcon.png",
X = Application.GetRealWidth (220),
Y = Application.GetRealHeight (13),
};
//if (!scene.busScene) {
LongPressFrameLayout.AddChidren (btnEditor);
//}
btnEditor.MouseUpEventHandler += (sender1, e1) => {
var userAddSceneDeviceView = new UserAddSceneDevice (Scene.GlobalSceneFilePath, sceneFilePath);
UserMiddle.DevicePageView.AddChidren (userAddSceneDeviceView);
userAddSceneDeviceView.ShowScene ((newSceneFilePath) => {
sceneFilePath = newSceneFilePath;
scene = Scene.GetSceneByFilePath (sceneFilePath);
sceneView.BackgroundImagePath = scene.BackgroundImagePath;
UserDeviceToScene.hasModify = true;
Refresh ();
});
UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
LongPressFrameLayout.RemoveFromParent ();
};
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);
sceneFilePaths.Remove (sceneFilePath);
sceneFilePaths.Remove ("");
IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFilePaths)));
InitView (isGolba);
};
};
btnBGC.MouseUpEventHandler += (sender, e) => {
if (beforeClickButton != null) {
beforeClickButton.IsSelected = false;
}
beforeClickButton = btnBGC;
btnBGC.IsSelected = true;
new ScenePhoneMethod ().ControlScene (sceneFilePath);
UserConfig.Instance.CurScene = sceneFilePath;
UserConfig.Instance.SaveUserConfig ();
};
}
}
} else {
VerticalScrolViewLayout roomListView = new VerticalScrolViewLayout () {
Height = bodyScrolView.Height - Application.GetRealHeight (90),
};
bodyScrolView.AddChidren (roomListView);
FrameLayout bottomView = new FrameLayout () {
Height = Application.GetRealHeight (90),
};
bodyScrolView.AddChidren (bottomView);
Button btnHideNullRoom = new Button () {
Width = LayoutParams.MatchParent,
Height = LayoutParams.MatchParent,
TextID = UserConfig.Instance.HideInvalidRoomScene == true ? R.MyInternationalizationString.ShowAllRoomList : R.MyInternationalizationString.HideNullRoomScene,
TextAlignment = TextAlignment.Center,
IsSelected = UserConfig.Instance.HideInvalidRoomScene,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.MainColor,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
};
bottomView.AddChidren (btnHideNullRoom);
btnHideNullRoom.MouseUpEventHandler += (sender, e) => {
btnHideNullRoom.IsSelected = !btnHideNullRoom.IsSelected;
UserConfig.Instance.HideInvalidRoomScene = btnHideNullRoom.IsSelected;
UserConfig.Instance.SaveUserConfig ();
InitRoomScene (btnHideNullRoom.IsSelected, roomListView);
btnHideNullRoom.TextID = UserConfig.Instance.HideInvalidRoomScene == true ? R.MyInternationalizationString.ShowAllRoomList : R.MyInternationalizationString.HideNullRoomScene;
};
InitRoomScene (btnHideNullRoom.IsSelected, roomListView);
}
}
void InitRoomScene (bool hideNull, VerticalScrolViewLayout roomListView)
{
roomListView.RemoveAll ();
foreach (var room in Room.Lists) {
if (string.IsNullOrEmpty(room.Name )) {
continue;
}
if (hideNull && room.SceneFilePathList.Count == 0)
continue;
var roomView = new FrameLayout () {
Height = Application.GetRealHeight (110),
BackgroundColor = SkinStyle.Current.ViewColor,
Tag = room.Name
};
roomListView.AddChidren (roomView);
var btnPoint = new Button () {
Width = Application.GetRealWidth (10),
Height = Application.GetRealHeight (10),
X = Application.GetRealWidth (30),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Point.png",
SelectedImagePath = "Item/Point.png",
};
roomView.AddChidren (btnPoint);
var btnRoomName = new Button () {
Text = room.Name,
X = btnPoint.Right + Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1,
};
roomView.AddChidren (btnRoomName);
var btnNumber = new EditText () {
Width = Application.GetRealWidth (50),
Height = Application.GetRealHeight (35),
X = Application.GetRealWidth (570),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/LightingCount.png",
SelectedImagePath = "Item/LightingCount.png",
Enable = false,
Text = room.SceneFilePathList.Count.ToString (),
TextAlignment = TextAlignment.Center,
Tag = room.Name
};
roomView.AddChidren (btnNumber);
btnRoomName.MouseUpEventHandler += (sender, e) => {
var userScenePage = new UserScenePage ();
UserMiddle.DevicePageView.AddChidren (userScenePage);
userScenePage.ShowUserScene (room);
UserMiddle.DevicePageView.PageIndex = 2;
};
Button btnRoomViewNull = new Button () {
Y = roomView.Height - Application.GetRealHeight (3),
Height = Application.GetRealHeight (3),
BackgroundColor = SkinStyle.Current.TitileView
};
roomView.AddChidren (btnRoomViewNull);
}
}
}
}