using System;
using Shared;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using System.Collections.Generic;
namespace HDL_ON.UI
{
public partial class SceneFunctionListChoosePage : FrameLayout
{
FrameLayout bodyView;
FrameLayout showdFunctionTypeRow;
///
/// 楼层选择下拉图标
///
Button btnFloorDownIcon;
///
/// 楼层显示
///
Button btnFloor;
/////
///// 筛选选择下拉图标
/////
//Button btnScreenIcon;
///
/// 筛选文本显示
///
Button btnScreenText;
VerticalScrolViewLayout functionListView;
List allocatedList;
List unallocatedList;
Scene scene;
Action refreshAction;
public SceneFunctionListChoosePage(Scene function,Action action)
{
bodyView = this;
scene = function;
allocatedList = new List();
unallocatedList = new List();
refreshAction = () =>
{
this.RemoveFromParent();
action();
};
}
///
/// 加载界面
///
public void LoadPage()
{
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
new TopViewDiv(bodyView, Language.StringByID(StringId.AddFunction)).LoadTopView();
//new PublicAssmebly().LoadTopView(bodyView, Language.StringByID(StringId.AddFunction));
#region 显示的功能类型切换区域
showdFunctionTypeRow = new FrameLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(62),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
bodyView.AddChidren(showdFunctionTypeRow);
btnFloorDownIcon = new Button()
{
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
X = Application.GetRealWidth(16),
Y = Application.GetRealHeight(18),
UnSelectedImagePath = "Public/DownIcon.png",
};
showdFunctionTypeRow.AddChidren(btnFloorDownIcon);
btnFloor = new Button()
{
X = btnFloorDownIcon.Right,
Y = Application.GetRealHeight(18),
Width = Application.GetRealWidth(200),
Height = Application.GetMinRealAverage(16),
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
TextAlignment = TextAlignment.CenterLeft,
Text = DB_ResidenceData.Instance.CurFloor.roomName,
};
showdFunctionTypeRow.AddChidren(btnFloor);
//btnScreenIcon = new Button()
//{
// Width = Application.GetMinRealAverage(16),
// Height = Application.GetMinRealAverage(16),
// X = Application.GetRealWidth(122),
// Y = Application.GetRealHeight(18),
// UnSelectedImagePath = "Public/DownIcon.png",
//};
//showdFunctionTypeRow.AddChidren(btnScreenIcon);
//btnScreenText = new Button()
//{
// X = btnScreenIcon.Right,
// Y = Application.GetRealHeight(18),
// Width = Application.GetRealWidth(200),
// Height = Application.GetMinRealAverage(16),
// TextColor = CSS_Color.FirstLevelTitleColor,
// TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
// TextAlignment = TextAlignment.CenterLeft,
// TextID = StringId.Screen
//};
//showdFunctionTypeRow.AddChidren(btnScreenText);
#endregion
functionListView = new VerticalScrolViewLayout()
{
Y = showdFunctionTypeRow.Bottom,
Height = Application.GetRealHeight(530),
BackgroundColor = CSS_Color.BackgroundColor,
};
bodyView.AddChidren(functionListView);
foreach (var function in FunctionList.List.GetDeviceFunctionList())
{
if (function == null)
{
continue;
}
function.roomIds.Remove(null);
if (scene.functions.Find((obj) => obj.sid == function.sid) != null)
{
allocatedList.Add(function);
}
else
{
unallocatedList.Add(function);
}
}
LoadFunctionListRow(null);
LoadEventList();
}
///
/// 显示功能Row
///
/// 是否是显示未分配
void LoadFunctionListRow(List functions)
{
functionListView.RemoveAll();
if (functions == null)
{
//初始值
functions = new List();
functions.AddRange(unallocatedList);
functions.AddRange(allocatedList);
}
foreach (var function in functions)
{
if (function.functionCategory != FunctionCategory.Light &&
function.functionCategory != FunctionCategory.Thermostat &&
function.functionCategory != FunctionCategory.Curtain
)
{
continue;
}
functionListView.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(343),
Height = Application.GetRealWidth(1),
BackgroundColor = CSS_Color.DividingLineColor,
});
FrameLayout functionRow = new FrameLayout()
{
Height = Application.GetRealHeight(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
functionListView.AddChidren(functionRow);
if (allocatedList.Contains(function))
{
var btnTipAdded = new Button()
{
Width = Application.GetRealWidth(327),
TextAlignment = TextAlignment.CenterRight,
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.TextFontSize,
TextID = StringId.Added
};
functionRow.AddChidren(btnTipAdded);
}
var btnFunctionIcon = new Button()
{
X = Application.GetRealWidth(12),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(28),
Height = Application.GetMinRealAverage(28),
};
functionRow.AddChidren(btnFunctionIcon);
switch (function.functionCategory)
{
case FunctionCategory.Thermostat:
switch (function.functionType)
{
case FunctionType.AC:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/AC/AcThinIcon1.png";
break;
case FunctionType.FloorHeating:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/FloorHeating/FloorHeatingThinIcon.png";
break;
}
break;
case FunctionCategory.Curtain:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Curtain/CurtainThinIcon.png";
break;
case FunctionCategory.Light:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Light/LightThinIcon.png";
break;
case FunctionCategory.SwitchDevice:
switch (function.functionType)
{
case FunctionType.Socket:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Socket/SocketThinIcon.png";
break;
}
break;
case FunctionCategory.Electrical:
switch (function.functionType)
{
case FunctionType.Fan:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Electrical/FanThinIcon.png";
break;
case FunctionType.TV:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Electrical/TVThinIcon.png";
break;
}
break;
case FunctionCategory.Scene:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Scene/SceneIcon.png";
break;
case FunctionCategory.Music:
btnFunctionIcon.UnSelectedImagePath = "FunctionIcon/Music/MusicThinIcon.png";
break;
}
var btnFunctionName = new Button()
{
X = btnFunctionIcon.Right + Application.GetRealWidth(12),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(40),
Text = function.name,
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
};
functionRow.AddChidren(btnFunctionName);
var btnFunctionFloorName = new Button()
{
X = btnFunctionIcon.Right + Application.GetRealWidth(12),
Y = Application.GetRealHeight(30),
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(20),
Text = function.GetRoomListName(),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
};
functionRow.AddChidren(btnFunctionFloorName);
Button btnChooseIcon = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
functionRow.AddChidren(btnChooseIcon);
LoadEvent_SkipEditFunctionInfo(functionRow, btnFunctionFloorName, btnChooseIcon, btnFunctionName, function);
}
}
///
/// 住宅列表点击事件
///
void LoadDialog_ChangeFloor()
{
string nowSelectId = null;
btnFloor.MouseUpEventHandler += (sender, e) =>
{
var listAllFun = new List();
listAllFun.AddRange(unallocatedList);
listAllFun.AddRange(allocatedList);
//显示下拉界面
var form = new FloorRoomSelectPopupView();
form.ShowDeviceFunctionView(btnFloor, listAllFun, (selectId, listFun) =>
{
nowSelectId = selectId;
//重新刷新设备列表
this.LoadFunctionListRow(listFun);
}, nowSelectId);
};
}
}
//---------------------------------------
public partial class SceneFunctionListChoosePage
{
void LoadEventList()
{
LoadDialog_ChangeFloor();
}
///
/// 新增场景功能
///
///
///
///
///
///
void LoadEvent_SkipEditFunctionInfo(FrameLayout view, Button btn1, Button btn2, Button btn3, Function function)
{
EventHandler eventHandler = (sender, e) =>
{
var ssf = new SceneFunctionInfoEditPage(scene, function.ConvertSceneFunction(), refreshAction);
MainPage.BasePageView.AddChidren(ssf);
ssf.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
view.MouseUpEventHandler = eventHandler;
btn1.MouseUpEventHandler = eventHandler;
btn2.MouseUpEventHandler = eventHandler;
btn3.MouseUpEventHandler = eventHandler;
}
}
}