using System;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
public class SceneControlZone :FrameLayout
{
Scene scene;
Button btnIcon;
Button btnName;
Button btnFromFloor;
Button btnCollectionIcon;
public SceneControlZone(Scene inParScene)
{
scene = inParScene;
Gravity = Gravity.CenterHorizontal;
Width = Application.GetRealWidth(343);
Height = Application.GetRealHeight(65);
Radius = (uint)Application.GetMinRealAverage(12);
BorderColor = 0x00FFFFFF;
BorderWidth = 1;
BackgroundColor = CSS_Color.MainBackgroundColor;
Tag = "Scene-" + scene.sid;
}
///
/// 加载功能类型控制卡片
///
public void LoadView()
{
btnIcon = new Button()
{
X = Application.GetRealWidth(10),
Y = Application.GetRealHeight(15),
Width = Application.GetRealWidth(32),
Height = Application.GetRealWidth(32),
};
this.AddChidren(btnIcon);
btnName = new Button()
{
X = Application.GetRealWidth(8 + 10 + 32),
Y = Application.GetRealHeight(10),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(24),
Text = scene.name,
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
};
this.AddChidren(btnName);
btnFromFloor = new Button()
{
X = Application.GetRealWidth(8 + 10 + 32),
Y = Application.GetRealHeight(10 + 24),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(18),
Text = scene.GetRoomListName(),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
};
this.AddChidren(btnFromFloor);
btnCollectionIcon = new Button()
{
X = Application.GetRealWidth(299),
Y = Application.GetRealHeight(10),
Width = Application.GetMinRealAverage(40),
Height = Application.GetMinRealAverage(40),
SelectedImagePath = "Collection/CollectionIcon.png",
UnSelectedImagePath = "Collection/CollectionGrayIcon.png",
IsSelected = scene.collect
};
if (scene.sceneType != SceneType.LightScene)
{
this.AddChidren(btnCollectionIcon);
}
btnIcon.UnSelectedImagePath = "FunctionIcon/Scene/SceneIcon.png";
if (scene.sceneType == SceneType.MovieScene)
{
Button movieIcon = new Button()
{
X = Application.GetRealWidth(52),
Y = Application.GetRealHeight(14),
Width = Application.GetRealWidth(16),
Height = Application.GetRealWidth(16),
UnSelectedImagePath = "FunctionIcon/Scene/MovieMark.png",
};
this.AddChidren(movieIcon);
btnName.X = Application.GetRealWidth(52 + 16);
}
//加载场景控制事件
LoadEvent_ControlScene(btnName, btnFromFloor, scene);
LoadEvent_FunctionCollection(btnCollectionIcon, scene);
}
///
/// 加载功能收藏按钮事件
///
void LoadEvent_FunctionCollection(Button btnCollectionIcon, Scene scene)
{
btnCollectionIcon.MouseUpEventHandler += (sender, e) =>
{
btnCollectionIcon.IsSelected = scene.collect = !btnCollectionIcon.IsSelected;
scene.CollectScene();
};
}
///
/// 加载场景控制事件
///
void LoadEvent_ControlScene(Button btnName, Button btnFromFloor, Scene scene)
{
if (scene.sceneType == SceneType.LightScene)
{
EventHandler upEvent = (sender, e) =>
{
if (scene.functions.Count == 0)
{
var waitPage = new Loading();
new Thread(() =>
{
try
{
Application.RunOnMainThread(() =>
{
MainPage.BaseView.AddChidren(waitPage);
waitPage.Start(Language.StringByID(StringId.PleaseWait));
});
var pm = new HttpServerRequest();
var pack = pm.GetSceneInfo(scene.userSceneId);
if (pack.Code == StateCode.SUCCESS)
{
var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject>(pack.Data.ToString());
var tempScene = sceneList.Find((obj) => obj.userSceneId == scene.userSceneId);
if (tempScene != null)
{
scene.name = tempScene.name;
scene.delay = tempScene.delay;
scene.roomIds = tempScene.roomIds;
scene.functions = tempScene.functions;
}
Application.RunOnMainThread(() =>
{
var sceneLishtList = new List();
foreach (var light in FunctionList.List.GetLightList())
{
var temp = scene.functions.Find((obj) => obj.sid == light.sid);
if (temp != null)
{
sceneLishtList.Add(light);
}
}
Action action = (Scene) => { };
var lightSceneDialog = new LightSceneEditDialog(sceneLishtList, scene, action);
lightSceneDialog.ShowDialog();
waitPage.Hide();
waitPage.RemoveFromParent();
});
}
else
{
IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
}
}
catch { }
finally
{
Application.RunOnMainThread(() =>
{
waitPage.Hide();
waitPage.RemoveFromParent();
});
}
}).Start();
}
else
{
var sceneLishtList = new List();
foreach (var light in FunctionList.List.GetLightList())
{
var temp = scene.functions.Find((obj) => obj.sid == light.sid);
if (temp != null)
{
sceneLishtList.Add(light);
}
}
Action action = (Scene) => { };
var lightSceneDialog = new LightSceneEditDialog(sceneLishtList, scene, action);
lightSceneDialog.ShowDialog();
}
};
btnName.MouseUpEventHandler = upEvent;
btnFromFloor.MouseUpEventHandler = upEvent;
this.MouseUpEventHandler = upEvent;
}
else
{
EventHandler upEvent = (sender, e) =>
{
DriverLayer.Control.Ins.ControlScene(scene);
string msg = scene.name + Language.StringByID(StringId.AlreadyOpened);
new PublicAssmebly().TipMsgAutoClose(msg, false);
};
btnName.MouseUpEventHandler = upEvent;
btnFromFloor.MouseUpEventHandler = upEvent;
this.MouseUpEventHandler = upEvent;
}
}
}
}