asmrobot
2019-11-25 2aeab450471cb80b59002da7da80faf251a0c4f4
src/RichCreator/MainWindow.xaml.cs
@@ -22,6 +22,7 @@
using RichCreator.Maps.Kalete;
using ZTImage.Collections;
using System.Collections.Generic;
using System.Windows.Media.Imaging;
namespace RichCreator
{
@@ -34,7 +35,7 @@
        public MainWindow()
        {
            InitializeComponent();
            G.Instance.EnableWriter(this.writeDebug, this.writeInfo, this.writeRemainTime, this.CancelConfirm,this.stopTaskUI);
            G.Instance.EnableWriter(this.writeDebug, this.writeInfo, this.writeRemainTime, this.CancelConfirm,this.stopTaskUI,this.updateState);
            viewModel = new ConfigViewModel();
            this.DataContext = viewModel;
        }
@@ -123,6 +124,36 @@
            this.LogTB.Text = string.Empty;
        }
        /// <summary>
        /// 折叠日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LogTBExpand_Click(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            Image img = btn.Content as Image;
            BitmapImage bitmap = null;
            if (this.LogTB.Visibility == Visibility.Collapsed)
            {
                //当前是隐藏状态
                this.LogTB.Visibility = Visibility.Visible;
                this.LogTBClearBtn.Visibility = Visibility.Visible;
                //todo:让日志图像设为up.png
                bitmap = new BitmapImage(new Uri("pack://application:,,,/Images/up.png"));
            }
            else
            {
                this.LogTB.Visibility = Visibility.Collapsed;
                this.LogTBClearBtn.Visibility = Visibility.Collapsed;
                //todo:让日志图像设为down.png
                bitmap = new BitmapImage(new Uri("pack://application:,,,/Images/down.png"));
            }
            img.Source = bitmap;
        }
        /// <summary>
        /// 点击检测按钮
        /// </summary>
@@ -191,23 +222,7 @@
            MessageBox.Show("配置更新成功");
        }
        #endregion
        private ZTPoint GetRolePosition()
        {
            System.Drawing.Bitmap bitmap = ScreenCapture.Instance.CaptureScreen();
            //原图
            Image<Rgb, byte> image = new Image<Rgb, byte>(bitmap);
            //色彩hsv
            Image<Hsv, byte> hsvImage = new Image<Hsv, byte>(image.Width, image.Height);
            CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv);
            hsvImage = hsvImage.GetSubRect(new System.Drawing.Rectangle(0, 0, 1280, 720));
            return DnfCVHelper.FindRole(hsvImage, new ZTRectangle(0, 0, 1280, 720));
        }
        /// <summary>
        /// 测速
@@ -285,13 +300,9 @@
                    }
                    Thread.Sleep(500);
                }
                G.Instance.InfoWriter($"测试技能发放完成");
            });
        }
        
        private ZTPoint rolePosition = ZTPoint.Empty;
        /// <summary>
        /// 读取角色位置
        /// </summary>
@@ -305,10 +316,10 @@
                Thread.Sleep(1000);
                Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
                CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv);
                rolePosition = DnfCVHelper.FindRole(hsvImage, gameRect);
                ZTPoint rolePosition = DnfCVHelper.FindRole(hsvImage, gameRect);
                G.Instance.InfoWriter($"角色位置读取成功:{rolePosition}");
                G.Instance.InfoWriter($"角色位置读取成功,CBPosition:{rolePosition},Half Position:{DnfRole.CBToHalfPosition(rolePosition)},Foot Position:{DnfRole.CBToFootPosition(rolePosition)}");
            });
        }
@@ -317,51 +328,40 @@
        /// </summary>
        private void TestToNextDoor()
        {
            HouseInfo house = new HouseInfo(0, MapType.Kalete, false, null);
            //ZTRectangle gameRect = ZTRectangle.Empty;
            //WindowUtils.GetDnfRect(out gameRect);
            ZTRectangle gameRect = ZTRectangle.Empty;
            WindowUtils.GetDnfRect(out gameRect);
            Image<Hsv, byte> hsvImage = new Image<Hsv, byte>(gameRect.End.X - gameRect.Start.X, gameRect.End.Y - gameRect.Start.Y );
            Task.Run(() => {
                WindowUtils.SetDnfToTop();
                Thread.Sleep(10);
            //HouseInfo house = new HouseInfo(1, MapType.Kalete, false, null,null);
            //DnfRole role = new DnfRole(gameRect);
            //role.SetHouse(house);
                Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
                image.ROI = new System.Drawing.Rectangle(gameRect.Start.X, gameRect.Start.Y, gameRect.End.X - gameRect.Start.X, gameRect.End.Y - gameRect.Start.Y);
                CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv);
                image.ROI = System.Drawing.Rectangle.Empty;
            //Image<Hsv, byte> hsvImage = new Image<Hsv, byte>(gameRect.End.X - gameRect.Start.X, gameRect.End.Y - gameRect.Start.Y );
            //Task.Run(() => {
            //    WindowUtils.SetDnfToTop();
            //    Thread.Sleep(10);
            //    Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
            //    image.ROI = new System.Drawing.Rectangle(gameRect.Start.X, gameRect.Start.Y, gameRect.End.X - gameRect.Start.X, gameRect.End.Y - gameRect.Start.Y);
            //    CvInvoke.CvtColor(image, hsvImage, Emgu.CV.CvEnum.ColorConversion.Rgb2Hsv);
            //    image.ROI = System.Drawing.Rectangle.Empty;
                
                //定位点
                ParametersPoint locationCoor = DnfCVHelper.GetLocationPoint(image, gameRect);
                if (locationCoor.Equals(ParametersPoint.Empty))
                {
                    //找不到定位点
                    G.Instance.InfoWriter("找不到定位点");
                    return;
                }
                ZTPoint rolePosition = DnfCVHelper.FindRole(hsvImage, gameRect);
                ZTPoint start=house.ScreenToMapCoordinate(rolePosition, locationCoor);
                DnfRole role = new DnfRole(gameRect);
                Int32 doorIndex = 0;
                List<ZTPoint> paths=house.FindDoorPath(out doorIndex,start);
                ZTPoint last = start;
                for (int i = 0; i < paths.Count; i++)
                {
                    //移动
                    ZTPoint distance = paths[i].Sub(last);
                    last = paths[i];
                    role.SyncMove(distance);
                }
            //    //定位点
            //    ParametersPoint locationCoor = DnfCVHelper.GetLocationPoint(image, gameRect);
            //    if (locationCoor.Equals(ParametersPoint.Empty))
            //    {
            //        //找不到定位点
            //        G.Instance.InfoWriter("找不到定位点");
            //        return;
            //    }
                
            //    ZTPoint rolePosition = DnfCVHelper.FindRole(hsvImage, gameRect);
            //    role.UpdatePosition(rolePosition);
                G.Instance.InfoWriter($"测试进入下一关的门完成");
            });
            //    role.ToNextGateMove(locationCoor, house.HousePathInfo.NextGates[0].Point);
            //    G.Instance.InfoWriter($"测试进入下一关的门完成");
            //});
        }
@@ -546,6 +546,19 @@
        }
        /// <summary>
        /// 更新指定状态
        /// </summary>
        /// <param name="index"></param>
        /// <param name="text"></param>
        private void updateState(Int32 index, string text)
        {
            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                this.StateList.Items[index] = text;
            }));
        }
        /// <summary>
        /// 开始任务UI设置
        /// </summary>
        private void startTaskUI()
@@ -609,6 +622,12 @@
            }
            //初始状态
            for (Int32 i = 0; i < StateProvider.States.Length; i++)
            {
                this.StateList.Items.Add(StateProvider.States[i].HeaderText+":"+ StateProvider.States[i].Value);
            }
        }
@@ -619,5 +638,6 @@
            IntPtr intPtr = (new WindowInteropHelper(this)).Handle;
            SystemHotKey.UnRegHotKey(intPtr, hotKeyID);
        }
    }
}