using Shared;
|
using HDL_ON.UI.CSS;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace HDL_ON.Stan
|
{
|
/// <summary>
|
/// 底部项目选择控件(不需要加入父控件,AddRowMenu添加菜单)
|
/// </summary>
|
public class BottomItemSelectControl: BottomDialogCommon
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 结束事件,可以多选(0:点击了取消,第二参数为null 1:点击了确定,第二参数为选择的索引,从0开始)
|
/// </summary>
|
public Action<int, List<int>> FinishEvent = null;
|
/// <summary>
|
/// 结束事件,只能选择一个(0:点击了取消,第二参数为null 1:点击了确定,第二参数为选择的索引,从0开始)
|
/// </summary>
|
public Action<int, int> FinishOnlyEvent = null;
|
/// <summary>
|
/// 选择的索引
|
/// </summary>
|
private List<int> ListSelect = new List<int>();
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
/// <summary>
|
/// 当前选择的图标控件
|
/// </summary>
|
private MostRightIconControl btnNowSelectIcon = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 有标题的弹窗型菜单选择控件(不需要加入父控件,AddRowMenu添加菜单)
|
/// </summary>
|
/// <param name="i_RowCount">菜单行数(不含标题)</param>
|
/// <param name="i_title">标题</param>
|
/// <param name="clickBackClose">点击背景时,是否关闭弹窗</param>
|
public BottomItemSelectControl(int i_RowCount, string i_title, bool clickBackClose = true)
|
{
|
//最大显示7个
|
base.RowCount = i_RowCount > 7 ? 7 : i_RowCount;
|
base.ClickBackClose = clickBackClose;
|
base.StrTitle = i_title;
|
}
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
private void InitControl()
|
{
|
//已经初始化
|
if (base.btnCancel != null) { return; }
|
|
//初始化底层控件
|
var frameWhiteBack = base.InitBaseControl();
|
//取消
|
base.btnCancel.ButtonClickEvent += (sender, e) =>
|
{
|
base.Close();
|
this.FinishEvent?.Invoke(0, null);
|
this.FinishOnlyEvent?.Invoke(0, 0);
|
this.FinishEvent = null;
|
this.FinishOnlyEvent = null;
|
};
|
|
base.btnConfirm.ButtonClickEvent += (sender, e) =>
|
{
|
//有选择才能点确认
|
if (this.ListSelect.Count > 0)
|
{
|
base.Close();
|
this.FinishEvent?.Invoke(1, this.ListSelect);
|
this.FinishOnlyEvent?.Invoke(1, this.ListSelect[0]);
|
this.FinishEvent = null;
|
this.FinishOnlyEvent = null;
|
}
|
};
|
|
//列表控件
|
this.listView = new VerticalListControl();
|
listView.Y = btnConfirm.Bottom;
|
listView.Height = this.RowCount * this.RowHeight;
|
frameWhiteBack.AddChidren(listView);
|
}
|
|
#endregion
|
|
#region ■ 添加菜单___________________________
|
|
/// <summary>
|
/// 添加菜单行
|
/// </summary>
|
/// <param name="i_listText">显示的列表文字</param>
|
/// <param name="i_listSelect">默认选择(请勿设置为null)</param>
|
public void AddRowMenu(List<string> i_listText, List<int> i_listSelect)
|
{
|
foreach (var index in i_listSelect)
|
{
|
if (index >= 0)
|
{
|
//舍弃掉一些非法的数据
|
this.ListSelect.Add(index);
|
}
|
}
|
|
//先初始化控件
|
this.InitControl();
|
|
for (int index = 0; index < i_listText.Count; index++)
|
{
|
//生成行控件
|
this.CreatRowControl(i_listText[index], index);
|
}
|
}
|
|
/// <summary>
|
/// 生成行控件
|
/// </summary>
|
/// <param name="i_text">显示文本</param>
|
/// <param name="i_index">索引</param>
|
private void CreatRowControl(string i_text, int i_index)
|
{
|
//它的上一行
|
var rowBefor = this.listView.GetChildren(this.listView.ChildrenCount - 1) as FrameRowControl;
|
if (rowBefor != null)
|
{
|
//画底线
|
var btnLine = rowBefor.AddBottomLine();
|
btnLine.Width = rowBefor.Width - Application.GetRealWidth(20) * 2;
|
btnLine.Gravity = Gravity.CenterHorizontal;
|
}
|
|
//行
|
var rowContr = new FrameRowControl();
|
rowContr.LeftOffset = Application.GetRealWidth(20) - HdlControlResourse.XXLeft;
|
rowContr.RightOffset = HdlControlResourse.XXLeft - Application.GetRealWidth(12);
|
rowContr.Width = this.listView.Width;
|
rowContr.Height = this.RowHeight;
|
this.listView.AddChidren(rowContr);
|
//显示文本
|
var btnView = rowContr.AddLeftCaption(i_text, 300);
|
btnView.TextColor = CSS_Color.FirstLevelTitleColor;
|
//选择图标
|
var btnIcon = rowContr.AddMostRightEmptyIcon(28, 28);
|
btnIcon.MainKey = i_index.ToString();
|
btnIcon.UnSelectedImagePath = "Public/ChooseIcon.png";
|
btnIcon.SelectedImagePath = "Public/ChooseOnIcon.png";
|
if (this.ListSelect.Contains(i_index) == true)
|
{
|
btnIcon.IsSelected = true;
|
this.btnNowSelectIcon = btnIcon;
|
}
|
rowContr.ButtonClickEvent += (sender, e) =>
|
{
|
btnIcon.IsSelected = !btnIcon.IsSelected;
|
if (btnIcon.IsSelected == true)
|
{
|
this.ListSelect.Add(i_index);
|
if (this.FinishOnlyEvent != null)
|
{
|
//如果选择了只能选择一个的模式,则取消掉上一次的选择
|
if (this.btnNowSelectIcon != null)
|
{
|
this.btnNowSelectIcon.IsSelected = false;
|
this.ListSelect.Remove(Convert.ToInt32(this.btnNowSelectIcon.MainKey));
|
}
|
this.btnNowSelectIcon = btnIcon;
|
}
|
}
|
else
|
{
|
this.ListSelect.Remove(i_index);
|
this.btnNowSelectIcon = null;
|
}
|
};
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 关闭界面
|
/// </summary>
|
public override void Close()
|
{
|
base.Close();
|
this.FinishEvent = null;
|
this.FinishOnlyEvent = null;
|
}
|
|
#endregion
|
}
|
}
|