using System;
using System.Collections.Generic;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
public class CatchSceneAddPage : FrameLayout
{
FrameLayout bodyView;
private ImageView addSceneImageView;
private FrameLayout sceneNameView;
private Button btnEditSceneNameIcon;
private Button btnSceneName;
private FrameLayout belongToZoneRow;
private Button btnBelongToZoneRight;
private Button btnZoneName;
private Scene scene;
private Button btnChooseZoneViewTitle;
private VerticalScrolViewLayout functionListView;
private Button btnComplete;
///
/// 捕捉的区域列表
///
private List catchRooms = new List();
///
/// 回调更新
///
Action backAction;
public CatchSceneAddPage(Scene s,Action a)
{
bodyView = this;
scene = s;
backAction =()=>{
a();
RemoveFromParent();
};
}
public void LoadPage()
{
new TopViewDiv(bodyView, Language.StringByID(StringId.CatchScene)).LoadTopView();
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
var contentView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(603 - 50),
};
bodyView.AddChidren(contentView);
contentView.AddChidren(new Button() {
Height = Application.GetRealWidth(12),
BackgroundColor = CSS_Color.MainBackgroundColor,
});
var sceneBgView = new FrameLayout()
{
Height = Application.GetRealWidth(188 + 24),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(sceneBgView);
addSceneImageView = new ImageView()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(252),
Height = Application.GetRealWidth(184),
Radius = (uint)Application.GetRealWidth(12),
};
sceneBgView.AddChidren(addSceneImageView);
//2020-12-03 修改图片加载方法
ImageUtlis.Current.LoadLocalOrNetworkImages(scene.ImagePath, addSceneImageView);
#region 场景名称row
sceneNameView = new FrameLayout()
{
Height = Application.GetRealWidth(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(sceneNameView);
Button btnSceneTitle = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(90),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
TextID = StringId.SceneName,
};
sceneNameView.AddChidren(btnSceneTitle);
btnEditSceneNameIcon = new Button()
{
X = Application.GetRealWidth(333),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(28),
Height = Application.GetMinRealAverage(28),
UnSelectedImagePath = "Public/EditIcon.png",
};
sceneNameView.AddChidren(btnEditSceneNameIcon);
btnSceneName = new Button()
{
X = Application.GetRealWidth(100),
Width = Application.GetRealWidth(230),
TextAlignment = TextAlignment.CenterRight,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.TextFontSize,
Text = scene.name
};
sceneNameView.AddChidren(btnSceneName);
Button btnSceneNameLine = new Button()
{
Y = Application.GetRealWidth(49),
Gravity = Gravity.CenterHorizontal,
Height = Application.GetRealHeight(1),
Width = Application.GetRealWidth(343),
BackgroundColor = CSS_Color.BackgroundColor,
};
sceneNameView.AddChidren(btnSceneNameLine);
#endregion
#region 所属区域row
belongToZoneRow = new FrameLayout()
{
Y = sceneNameView.Bottom,
Height = Application.GetRealWidth(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(belongToZoneRow);
Button btnBelongToTitle = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(90),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
TextID = StringId.LocationManagement,
};
belongToZoneRow.AddChidren(btnBelongToTitle);
btnBelongToZoneRight = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
belongToZoneRow.AddChidren(btnBelongToZoneRight);
btnZoneName = new Button()
{
X = Application.GetRealWidth(100),
Width = Application.GetRealWidth(230),
TextAlignment = TextAlignment.CenterRight,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.TextFontSize,
Text = scene.GetRoomListName() == "" ? Language.StringByID(StringId.WholeZone) : scene.GetRoomListName()
};
belongToZoneRow.AddChidren(btnZoneName);
contentView.AddChidren(new Button()
{
Y = belongToZoneRow.Bottom,
Height = Application.GetRealHeight(8),
BackgroundColor = CSS_Color.BackgroundColor,
});
#endregion
#region 场景延时row
/*
if (DB_ResidenceData.Instance.GatewayType == 1)
{
FrameLayout sceneDelayRow = new FrameLayout()
{
Y = sceneNameView.Bottom,
Height = Application.GetRealWidth(50),
};
contentView.AddChidren(sceneDelayRow);
Button btnSceneDelayRight = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
sceneDelayRow.AddChidren(btnSceneDelayRight);
var btnSceneDelayInfo = new Button()
{
Width = Application.GetRealWidth(327),
TextAlignment = TextAlignment.CenterRight,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
Text = scene.GetDelayText()
};
sceneDelayRow.AddChidren(btnSceneDelayInfo);
Button btnSceneDelayTitle = new Button()
{
X = Application.GetRealWidth(16),
//Width = Application.GetRealWidth(90),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
TextID = StringId.SceneDelay,
};
sceneDelayRow.AddChidren(btnSceneDelayTitle);
btnSceneDelayTitle.MouseUpEventHandler = (sender, e) =>
{
Action action = (obj) => {
scene.delay = obj;
btnSceneDelayInfo.Text = scene.GetDelayText();
};
Dictionary items = new Dictionary();
items.Add("30", "30s");
items.Add("60", "1min");
items.Add("120", "2min");
items.Add("300", "5min");
new PublicAssmebly().SetSceneDelayDialog(items, action, scene.delay);
};
contentView.AddChidren(new Button()
{
Y = sceneDelayRow.Bottom,
Height = Application.GetRealHeight(8),
BackgroundColor = CSS_Color.BackgroundColor,
});
}
*/
#endregion
#region 选择区域
FrameLayout chooseZoneView = new FrameLayout()
{
Height = Application.GetRealWidth(44),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(chooseZoneView);
btnChooseZoneViewTitle = new Button()
{
X = Application.GetRealWidth(16),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.ChooseCatchZone,
IsBold = true,
};
chooseZoneView.AddChidren(btnChooseZoneViewTitle);
functionListView = new VerticalScrolViewLayout()
{
Height = 0,
};
contentView.AddChidren(functionListView);
LoadRoomRow(functionListView);
Button btnLine1 = new Button()
{
Height = Application.GetRealHeight(8),
BackgroundColor = CSS_Color.BackgroundColor,
};
contentView.AddChidren(btnLine1);
#endregion
Button btnBottomLine = new Button()
{
Y = Application.GetRealHeight(667 - 50) - 1,
Height = 1,
BackgroundColor = CSS_Color.BackgroundColor,
};
bodyView.AddChidren(btnBottomLine);
btnComplete = new Button()
{
Y = Application.GetRealHeight(667 - 50),
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
SelectedTextColor = CSS_Color.MainColor,
TextColor = CSS_Color.BackgroundColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.NextStep,
BackgroundColor = CSS_Color.MainBackgroundColor,
SelectedBackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(btnComplete);
btnComplete.MouseUpEventHandler = (sender, e) => {
if(btnComplete.IsSelected)
{
if (string.IsNullOrEmpty(scene.name))
{
new Tip()
{
CloseTime = 1,
Text = Language.StringByID(StringId.SceneNameCannotBeEmpty),
Direction = AMPopTipDirection.None,
}.Show(bodyView);
return;
}
foreach (var tempRoom in FunctionList.List.scenes)
{
if (scene.name == tempRoom.name)
{
new PublicAssmebly().TipMsg(StringId.Tip, StringId.SceneNameAlreadyExists);
return;
}
}
var catchFunctionList = new List();
foreach(var temp in FunctionList.List.Functions)
{
foreach(var catchRoom in catchRooms)
{
if(temp.roomIds.Contains(catchRoom.roomId))
{
if (MainPage.SceneSupportFunctionList.Contains(temp.spk))
{
catchFunctionList.Add(temp);
}
}
}
}
var view = new CatchSceneCatchFunctionListPage(scene, catchFunctionList, backAction);
MainPage.BasePageView.AddChidren(view);
view.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
}
};
}
///
/// 加载功能列表
///
void LoadRoomRow(VerticalScrolViewLayout functionListView)
{
functionListView.RemoveAll();
var roomCount = SpatialInfo.CurrentSpatial.RoomList.Count;
functionListView.Height = Application.GetRealWidth(51 * roomCount);
int i = 0;
foreach(var room in SpatialInfo.CurrentSpatial.RoomList)
{
if (i < roomCount )
{
functionListView.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(343),
Height = Application.GetRealWidth(1),
BackgroundColor = CSS_Color.BackgroundColor,
});
}
i++;
var row = new FrameLayout()
{
Height = Application.GetRealWidth(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
functionListView.AddChidren(row);
Button btnChoose = new Button()
{
X = Application.GetRealWidth(331),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(28),
Height = Application.GetMinRealAverage(28),
UnSelectedImagePath = "Public/ChooseIcon.png",
SelectedImagePath = "Public/ChooseOnIcon.png",
};
row.AddChidren(btnChoose);
var btnRoomName = new TextButton()
{
X = Application.GetRealWidth(16),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
Text = room.roomName,
};
row.AddChidren(btnRoomName);
btnRoomName.Width = Utlis.GetRealWidthByTextButton(btnRoomName)+Application.GetRealWidth(12);
var btnRoomFloor = new TextButton()
{
X = btnRoomName.Right,
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
Text = room.floorName,
};
row.AddChidren(btnRoomFloor);
btnRoomFloor.Width = Utlis.GetRealWidthByTextButton(btnRoomFloor) + Application.GetRealWidth(12);
EventHandler eventHandler = (sender, e) => {
btnChoose.IsSelected = !btnChoose.IsSelected;
if (btnChoose.IsSelected)
{
catchRooms.Add(room);
}else
{
catchRooms.Remove(room);
}
if (catchRooms.Count == 1)
{
btnComplete.IsSelected = true;
}
else if (catchRooms.Count == 0)
{
btnComplete.IsSelected = false;
}
};
btnRoomFloor.MouseUpEventHandler = eventHandler;
btnRoomName.MouseUpEventHandler = eventHandler;
btnChoose.MouseUpEventHandler = eventHandler;
row.MouseUpEventHandler = eventHandler;
}
}
}
}