using Shared; using HDL_ON.UI.CSS; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.Stan { /// <summary> /// 控制上下左å³åœæ¢çš„å›¾åƒæŽ§ä»¶ /// </summary> public class DirectionImageControl : NormalFrameLayout { #region â– å˜é‡å£°æ˜Ž___________________________ /// <summary> /// 点击åŽè‡ªåŠ¨è¿˜åŽŸçŠ¶æ€çš„æŽ§åˆ¶äº‹ä»¶(åªæœ‰Mid,left,right,up,down) /// </summary> public Action<DirectionEnum> AutoRecoverControlEvent = null; /// <summary> /// 点击åŽä¸ä¼šè¿˜åŽŸçŠ¶æ€çš„æŽ§åˆ¶äº‹ä»¶(åªæœ‰enable,Mid,left,right,up,down。 enable:手指æ¾å¼€æ–¹å‘é”®åŽè§¦å‘) /// </summary> public Action<DirectionEnum> NotRecoverControlEvent = null; /// <summary> /// èƒ½å¦æŽ§åˆ¶æ–¹å‘ /// </summary> private bool CanDirection = false; /// <summary> /// å„图片路径 0:å¯ä»¥æŽ§åˆ¶ 1:ä¸å¯ä»¥æŽ§åˆ¶ 2:上 3:下 4:å·¦ 5:å³ /// </summary> private List<string> listIconPath = new List<string>(); #endregion #region â– åˆå§‹åŒ–_____________________________ /// <summary> /// åˆå§‹åŒ– /// </summary> /// <param name="i_enablePath">å¯ä»¥æŽ§åˆ¶çš„背景图</param> /// <param name="i_disablePath">ä¸å¯ä»¥æŽ§åˆ¶çš„背景图</param> /// <param name="i_upPath">点击å‘上的背景图</param> /// <param name="i_downPath">点击å‘下的背景图</param> /// <param name="i_leftPath">点击å‘左的背景图</param> /// <param name="i_rightPath">点击å‘å³çš„背景图</param> public void InitControl(string i_enablePath, string i_disablePath, string i_upPath, string i_downPath, string i_leftPath, string i_rightPath) { this.listIconPath.Add(i_enablePath); this.listIconPath.Add(i_disablePath); this.listIconPath.Add(i_upPath); this.listIconPath.Add(i_downPath); this.listIconPath.Add(i_leftPath); this.listIconPath.Add(i_rightPath); this.BackgroundImagePath = i_disablePath; this.CanDirection = false; //åˆå§‹åŒ–按钮 this.IntiButtion(); } /// <summary> /// åˆå§‹åŒ–按钮 /// </summary> private void IntiButtion() { //æ£ä¸é—´çš„æŒ‰é’® var btnMid = new PicViewControl(70, 70); btnMid.Gravity = Gravity.Center; this.AddChidren(btnMid); btnMid.ButtonClickEvent += (sender, e) => { //判æ–能å¦ç‚¹å‡» if (this.CanClick == false) { return; } //å¼€å¯ç‰å¾…线程(ä¸å…许狂点) this.StartWaitThread(); this.AutoRecoverControlEvent?.Invoke(DirectionEnum.Mid); this.NotRecoverControlEvent?.Invoke(DirectionEnum.Mid); }; //上按钮 var btnUp = new PicViewControl(52, 52); this.AddChidren(btnUp); btnUp.X = (this.Width - btnUp.Width) / 2; btnUp.ButtonClickEvent += (sender, e) => { //æ–¹å‘点击 this.DirectionClickEvent(DirectionEnum.Up); }; btnUp.ButtonDownClickEvent += (sender, e) => { //按键按下 this.DirectionDownClickEvent(DirectionEnum.Up); }; //下按钮 var btnDown = new PicViewControl(btnUp.Width, btnUp.Height, false); btnDown.X = btnUp.X; this.AddChidren(btnDown); btnDown.Y = this.Height - btnDown.Height; btnDown.ButtonClickEvent += (sender, e) => { //æ–¹å‘点击 this.DirectionClickEvent(DirectionEnum.Down); }; btnDown.ButtonDownClickEvent += (sender, e) => { //按键按下 this.DirectionDownClickEvent(DirectionEnum.Down); }; //左按钮 var btnLeft = new PicViewControl(btnUp.Width, btnUp.Height, false); this.AddChidren(btnLeft); btnLeft.Y = (this.Height - btnLeft.Height) / 2; btnLeft.ButtonClickEvent += (sender, e) => { //æ–¹å‘点击 this.DirectionClickEvent(DirectionEnum.Left); }; btnLeft.ButtonDownClickEvent += (sender, e) => { //按键按下 this.DirectionDownClickEvent(DirectionEnum.Left); }; //峿Œ‰é’® var btnRight = new PicViewControl(btnUp.Width, btnUp.Height, false); btnRight.Y = btnLeft.Y; this.AddChidren(btnRight); btnRight.X = this.Width - btnRight.Width; btnRight.ButtonClickEvent += (sender, e) => { //æ–¹å‘点击 this.DirectionClickEvent(DirectionEnum.Right); }; btnRight.ButtonDownClickEvent += (sender, e) => { //按键按下 this.DirectionDownClickEvent(DirectionEnum.Right); }; } #endregion #region ■外部设置图片_______________________ /// <summary> /// 设置图片显示 /// </summary> /// <param name="direction">æ–¹å‘æžšä¸¾(䏿”¯æŒMid)</param> public void SetDirectionImage(DirectionEnum direction) { if (direction == DirectionEnum.Mid) { //䏿”¯æŒMid return; } if (direction == DirectionEnum.Disable) { //ä¸èƒ½æŽ§åˆ¶æ–¹å‘ this.CanDirection = false; } else { //èƒ½å¤ŸæŽ§åˆ¶æ–¹å‘ this.CanDirection = true; } string iconPath = this.listIconPath[((int)direction) - 1]; if (this.BackgroundImagePath != iconPath) { this.BackgroundImagePath = iconPath; } } #endregion #region â– æ–¹å‘点击___________________________ /// <summary> /// æ–¹å‘点击 /// </summary> /// <param name="direction"></param> private void DirectionClickEvent(DirectionEnum direction) { //判æ–能å¦ç‚¹å‡» if (this.CanClick == false || this.CanDirection == false) { return; } //å¦‚æžœä½¿ç”¨ç‰¹æ•ˆçš„è¯ if (this.AutoRecoverControlEvent != null) { //切æ¢å›¾ç‰‡ this.SetDirectionImage(direction); //å¼€å¯ç‰å¾…线程(ä¸å…许狂点) this.StartWaitThread(); this.AutoRecoverControlEvent?.Invoke(direction); } else { //切æ¢å›¾ç‰‡ this.SetDirectionImage(DirectionEnum.Enable); this.NotRecoverControlEvent?.Invoke(DirectionEnum.Enable); } } /// <summary> /// æ–¹å‘æŒ‰é”®æŒ‰ä¸‹äº‹ä»¶ /// </summary> /// <param name="direction"></param> private void DirectionDownClickEvent(DirectionEnum direction) { //如果ä¸ä½¿ç”¨ç‰¹æ•ˆçš„è¯ if (this.CanClick == false || this.CanDirection == false || this.NotRecoverControlEvent == null) { return; } //切æ¢å›¾ç‰‡ this.SetDirectionImage(direction); this.NotRecoverControlEvent?.Invoke(direction); } #endregion #region ■一般方法___________________________ /// <summary> /// å¼€å¯ç‰å¾…线程(ä¸å…许狂点) /// </summary> private void StartWaitThread() { this.CanClick = false; HdlThreadLogic.Current.RunThread(() => { System.Threading.Thread.Sleep(300); this.CanClick = true; //如果ä¸ä½¿ç”¨ç‰¹æ•ˆçš„è¯ if (this.NotRecoverControlEvent != null) { return; } HdlThreadLogic.Current.RunMain(() => { //图片还原 if (this.BackgroundImagePath != this.listIconPath[0]) { this.BackgroundImagePath = this.listIconPath[0]; } }, ShowErrorMode.NO); }, ShowErrorMode.NO); } #endregion } }