tzy
2021-05-14 0fa1534827bd21d763216550d11006fc1441c6cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
    }
}