using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
namespace HDL_ON.Stan
{
///
/// 设备功能卡片的底层界面
///
public class DeviceFunctionCardCommonForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 当前回路对象
///
public Function device = null;
///
/// 右上角配置结束的事件
///
public Action SettionFinishEvent = null;
///
/// 左右整个翻页的控件
///
private PageLayout pageLayout = null;
///
/// 设备名字控件(刷新用到)
///
public NormalViewControl btnDeviceName = null;
///
/// 房间名字控件(刷新用到)
///
public NormalViewControl btnRoomName = null;
///
/// 底部快捷按钮1
///
private NormalViewControl btnBottomOne = null;
///
/// 底部快捷按钮2
///
private NormalViewControl btnBottomTwo = null;
///
/// 第一索引的白色区域的桌布控件
///
public NormalFrameLayout FrameWhiteCentet1 = null;
///
/// 第二索引的白色区域的桌布控件(请先调用AddSecondPage函数完成添加)
///
public NormalFrameLayout FrameWhiteCentet2 = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 设备对象
/// 上一级界面的收藏控件(原来on的框架太坑)
/// 上一级界面的设备名字控件(原来on的框架太坑)
/// 上一级界面的房间名字控件(原来on的框架太坑)
public void ShowForm(Function i_device, Button btnHigherCollection, Button btnHigherDeviceName, Button btnHigherRoom)
{
this.device = i_device;
//添加头部【设置】图标
this.AddTopSettingIcon(btnHigherDeviceName, btnHigherRoom);
//初始化中部信息
this.InitMiddleFrame(btnHigherCollection);
}
///
/// 初始化中部信息
///
/// 上一级界面的收藏控件
private void InitMiddleFrame(Button btnHigherCollection)
{
//清空bodyFrame
this.ClearBodyFrame();
//左右整个翻页的控件
this.pageLayout = new PageLayout();
pageLayout.IsShowPoint = false;
pageLayout.ScrollEnabled = false;
bodyFrameLayout.AddChidren(pageLayout);
pageLayout.PageChange += (sender, index) =>
{
//设置底部两个按钮的状态
this.SetBottomTwoButtonStatu();
};
//初始化第一个索引的桌布
this.InitFrameWhiteContent1(btnHigherCollection);
//初始化白色内容(需要自主实现)
this.InitFrameWhiteContent();
}
///
/// 初始化第一个索引的桌布
///
/// 上一级界面的收藏控件
private void InitFrameWhiteContent1(Button btnHigherCollection)
{
//第一个索引桌布是必定存在的
var frameTable1 = new FrameLayout();
frameTable1.Width = pageLayout.Width;
frameTable1.Height = pageLayout.Height;
pageLayout.AddChidren(frameTable1);
//第一个索引的白色桌布
this.FrameWhiteCentet1 = new NormalFrameLayout();
FrameWhiteCentet1.Gravity = Gravity.CenterHorizontal;
FrameWhiteCentet1.Y = Application.GetRealHeight(22);
FrameWhiteCentet1.Width = Application.GetRealWidth(327);
FrameWhiteCentet1.Height = Application.GetRealHeight(526);
FrameWhiteCentet1.BackgroundImagePath = "Public/Fragmentbg.png";
frameTable1.AddChidren(FrameWhiteCentet1);
//设备名字
this.btnDeviceName = new NormalViewControl(270, 37, true);
btnDeviceName.X = Application.GetRealWidth(16);
btnDeviceName.Y = Application.GetRealHeight(18);
btnDeviceName.TextColor = CSS_Color.FirstLevelTitleColor;
btnDeviceName.TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel;
btnDeviceName.Text = device.name;
btnDeviceName.Width = btnDeviceName.GetRealWidthByText();
FrameWhiteCentet1.AddChidren(btnDeviceName);
//房间名字
this.btnRoomName = new NormalViewControl(270, 21, true);
btnRoomName.X = Application.GetRealWidth(16);
btnRoomName.Y = btnDeviceName.Bottom;
btnRoomName.TextColor = CSS_Color.PromptingColor1;
btnRoomName.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
btnRoomName.Text = device.GetRoomListName();
btnRoomName.Width = btnRoomName.GetRealWidthByText();
FrameWhiteCentet1.AddChidren(btnRoomName);
//成员没有收藏功能
if (DB_ResidenceData.Instance.CurrentRegion.IsOthreShare == false)
{
var btnCollection = new IconViewControl(40);
btnCollection.X = Application.GetRealWidth(273);
btnCollection.Y = Application.GetRealHeight(16);
btnCollection.SelectedImagePath = "Collection/CollectionIcon.png";
btnCollection.UnSelectedImagePath = "Collection/CollectionGrayIcon.png";
btnCollection.IsSelected = device.collect;
FrameWhiteCentet1.AddChidren(btnCollection);
btnCollection.ButtonClickEvent += (sender, e) =>
{
btnCollection.IsSelected = !btnCollection.IsSelected;
device.collect = btnCollection.IsSelected;
btnHigherCollection.IsSelected = device.collect;
device.CollectFunction();
};
}
}
///
/// 初始化第二个索引的桌布
///
private void InitFrameWhiteContent2()
{
this.pageLayout.ScrollEnabled = true;
//第一个索引桌布是必定存在的
var frameTable2 = new FrameLayout();
frameTable2.Width = pageLayout.Width;
frameTable2.Height = pageLayout.Height;
pageLayout.AddChidren(frameTable2);
//第一个索引的白色桌布
this.FrameWhiteCentet2 = new NormalFrameLayout();
FrameWhiteCentet2.Gravity = Gravity.CenterHorizontal;
FrameWhiteCentet2.Y = Application.GetRealHeight(22);
FrameWhiteCentet2.Width = Application.GetRealWidth(327);
FrameWhiteCentet2.Height = Application.GetRealHeight(526);
FrameWhiteCentet2.BackgroundImagePath = "Public/Fragmentbg.png";
frameTable2.AddChidren(FrameWhiteCentet2);
}
///
/// 初始化白色内容(需要自主实现)
///
public virtual void InitFrameWhiteContent()
{
}
#endregion
#region ■ 添加第二索引页_____________________
///
/// 添加第二索引页
///
public void AddSecondPage()
{
//初始化第二个索引的桌布
this.InitFrameWhiteContent2();
//底部添加两个按钮
this.btnBottomOne = new NormalViewControl(14, 6, true);
btnBottomOne.X = Application.GetRealWidth(170);
btnBottomOne.Y = FrameWhiteCentet1.Bottom + Application.GetRealHeight(30);
btnBottomOne.BackgroundColor = CSS_Color.MainColor;
btnBottomOne.Radius = (uint)Application.GetRealHeight(6) / 2;
bodyFrameLayout.AddChidren(btnBottomOne);
btnBottomOne.ButtonClickEvent += (sender, e) =>
{
this.pageLayout.PageIndex = 0;
//设置底部两个按钮的状态
this.SetBottomTwoButtonStatu();
};
this.btnBottomTwo = new NormalViewControl(14, 6, true);
btnBottomTwo.X = btnBottomOne.Right + Application.GetRealWidth(8);
btnBottomTwo.Y = btnBottomOne.Y;
btnBottomTwo.BackgroundColor = 0xffadc7f7;
btnBottomTwo.Radius = (uint)Application.GetRealHeight(6) / 2;
bodyFrameLayout.AddChidren(btnBottomTwo);
btnBottomTwo.ButtonClickEvent += (sender, e) =>
{
this.pageLayout.PageIndex = 1;
//设置底部两个按钮的状态
this.SetBottomTwoButtonStatu();
};
}
///
/// 设置底部两个按钮的状态
///
private void SetBottomTwoButtonStatu()
{
if (this.btnBottomTwo == null) { return; }
if (this.pageLayout.PageIndex == 1)
{
this.btnBottomOne.BackgroundColor = 0xffadc7f7;
this.btnBottomTwo.BackgroundColor = CSS_Color.MainColor;
}
else
{
this.btnBottomOne.BackgroundColor = CSS_Color.MainColor;
this.btnBottomTwo.BackgroundColor = 0xffadc7f7;
}
}
#endregion
#region ■ 一般方法___________________________
///
/// 添加头部【设置】的图标
///
/// 上一级界面的收藏控件(原来on的框架太坑)
/// 上一级界面的设备名字控件(原来on的框架太坑)
private void AddTopSettingIcon(Button btnHigherDeviceName, Button btnHigherRoom)
{
//如果是成员没有功能
if (DB_ResidenceData.Instance.CurrentRegion.IsOthreShare == true)
{
return;
}
//设置图标
var btnSetting = new PicViewControl(28, 28);
btnSetting.X = Application.GetRealWidth(337);
btnSetting.Y = Application.GetRealHeight(9);
btnSetting.UnSelectedImagePath = "Public/FuncInfoSetIcon.png";
topFrameLayout.AddChidren(btnSetting);
btnSetting.ButtonClickEvent += (sender, e) =>
{
var infoView = new UI.FunctionBaseInfoSetPage(this.device, () =>
{
//刷新显示
btnHigherDeviceName.Text = this.device.name;
btnHigherRoom.Text = this.device.GetRoomListName();
//从新计算宽度
this.btnDeviceName.Text = btnHigherDeviceName.Text;
this.btnDeviceName.Width = this.btnDeviceName.GetRealWidthByText();
this.btnRoomName.Text = btnHigherRoom.Text;
this.btnRoomName.Width = this.btnRoomName.GetRealWidthByText();
//回调事件
this.SettionFinishEvent?.Invoke();
});
MainPage.BasePageView.AddChidren(infoView);
infoView.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
}
#endregion
}
}