Example #1
0
        private void Control_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (drag)
            {
                drag = false;
                Point pt = e.GetPosition(workingArea);
                //image.IsChecked = true;
                if(pt.X >= workingArea.Width
                || pt.Y >= workingArea.Height
                || ChildrenPositions[(int)pt.X / 45, (int)pt.Y / 45] == 1)//remove
                {
                    workingArea.Children.Remove(image);
                    if (image.Source == CT_Hole.Source)
                    {
                        holeCount--;
                    }
                    image = null;
                    return;
                }

                ChildrenPositions[(int)pt.X / 45, (int)pt.Y / 45] = 1;
            }
        }
Example #2
0
        private void Button_Load_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            dialog.Filter = "Reflector关卡文件|*.rf";
            dialog.FileName = "Reflector关卡.rf";
            dialog.AddExtension = true;
            dialog.AutoUpgradeEnabled = true;
            dialog.CheckFileExists = true;
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string filename = dialog.FileName;
                StreamReader reader = new StreamReader(filename);
                try
                {
                    string[] data = reader.ReadToEnd().Split(new char[]{ ';'}, StringSplitOptions.RemoveEmptyEntries);
                    string[] splits = data[0].Split(',');
                    MirrorCount.Text = splits[0];
                    PrismCount.Text = splits[1];

                    List<ImageCheckButton> imgs = new List<ImageCheckButton>();
                    for (int i = 1; i < data.Length; i++)
                    {
                        splits = data[i].Split(',');
                        ImageCheckButton icb = new ImageCheckButton();
                        icb.Width = 45;
                        icb.Height = 45;
                        icb.SetValue(Canvas.LeftProperty, (double.Parse(splits[0]) - 1) * 45);
                        icb.SetValue(Canvas.TopProperty, (double.Parse(splits[1]) - 1) * 45);
                        if (splits.Length < 5)
                        {
                            if(splits[2] == "8")
                                icb.Source = new BitmapImage(new Uri("/Images/Wall/" + "black.png", UriKind.Relative));
                            else if (splits[2] == "6")
                            {
                                icb.Source = new BitmapImage(new Uri("/Images/hole.png", UriKind.Relative));
                            }
                        }
                        else
                        {
                            string color = string.Empty;
                            switch (splits[4])
                            {
                                case "1": color = "blue.png"; break;
                                case "2": color = "yellow.png"; break;
                                case "3": color = "red.png"; break;
                                case "4": color = "green.png"; break;
                                case "5": color = "orange.png"; break;
                                case "6": color = "purple.png"; break;
                            }

                            Uri source = null;
                            switch (splits[2])
                            {
                                case "7":
                                    int angle = int.Parse(splits[3]) - 90;
                                    icb.ImageRotate(-angle);
                                    icb.CanCheck = true;
                                    source = new Uri("/Images/Emi/" + color, UriKind.Relative);
                                    break;
                                case "3":
                                    source = new Uri("/Images/Rec/" + color, UriKind.Relative);
                                    break;
                                case "4":
                                    source = new Uri("/Images/Swi/" + color, UriKind.Relative);
                                    break;
                                case "5":
                                    source = new Uri("/Images/Wall/" + color, UriKind.Relative);
                                    break;
                            }
                            icb.Source = new BitmapImage(source);
                        }
                        imgs.Add(icb);
                    }

                    this.workingArea.Children.Clear();
                    foreach (var img in imgs)
                        this.workingArea.Children.Add(img);

                }
                catch (Exception ex)
                {
                    MessageBox.Show("读取失败,原因是:" + ex.Message);
                }
                finally
                {
                    reader.Close();
                }
            }
        }
Example #3
0
        private void Control_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.Source is MyButton)
            {
                MyButton ct = e.Source as MyButton;
                drag = true;

                ControlPosition = e.GetPosition(workingArea);

                image = new ImageCheckButton();

                image.Width = 45;
                image.Height = 45;
                if (ct.Name == "CT_Emi") image.CanCheck = true;

                image.Source = ct.SelectedItem.Source;

                image.SetValue(Canvas.LeftProperty, Canvas.GetLeft(ct));
                image.SetValue(Canvas.TopProperty, Canvas.GetTop(ct));

                workingArea.Children.Add(image);

            }
            else if (e.Source is ImageCheckButton)
            {
                drag = true;
                image = e.Source as ImageCheckButton;
                Point pt = e.GetPosition(workingArea);

                ChildrenPositions[(int)pt.X / 45, (int)pt.Y / 45] = 0;
            }
            else if (e.Source == CT_Hole && holeCount < 2)
            {
                holeCount++;

                drag = true;

                ControlPosition = e.GetPosition(workingArea);

                image = new ImageCheckButton();
                image.Width = 45;
                image.Height = 45;
                image.Source = CT_Hole.Source;

                image.SetValue(Canvas.LeftProperty, Canvas.GetLeft(CT_Hole));
                image.SetValue(Canvas.TopProperty, Canvas.GetTop(CT_Hole));

                workingArea.Children.Add(image);
            }
        }