예제 #1
0
파일: Form1.cs 프로젝트: hnjm/VirtualRubik
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         if (oldSelection.cubePos == Cube3D.RubikPosition.None || oldSelection.facePos == Face3D.FacePosition.None)
         {
             if (currentSelection.cubePos == Cube3D.RubikPosition.None || currentSelection.facePos == Face3D.FacePosition.None)
             {
                 rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                 oldSelection = new RubikManager.PositionSpec()
                 {
                     cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
                 };
                 currentSelection = new RubikManager.PositionSpec()
                 {
                     cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
                 };
             }
             else
             {
                 if (!Cube3D.isCorner(currentSelection.cubePos))
                 {
                     oldSelection = currentSelection;
                     rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f =>
                     {
                         if (currentSelection.cubePos != c.Position && !Cube3D.isCenter(c.Position) && currentSelection.facePos == f.Position)
                         {
                             Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(currentSelection.facePos);
                             Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(currentSelection.cubePos, c.Position, assocLayer);
                             if (commonLayer != Cube3D.RubikPosition.None && c.Position.HasFlag(commonLayer))
                             {
                                 f.Selection |= Face3D.SelectionMode.Possible;
                             }
                             else
                             {
                                 f.Selection |= Face3D.SelectionMode.NotPossible;
                             }
                         }
                         else
                         {
                             f.Selection |= Face3D.SelectionMode.NotPossible;
                         }
                     }));
                     toolStripStatusLabel1.Text = "First selection: [" + currentSelection.cubePos.ToString() + "] | " + currentSelection.facePos.ToString();;
                 }
                 else
                 {
                     rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                     toolStripStatusLabel1.Text = "Error: Invalid first selection, must not be a corner";
                 }
             }
         }
         else
         {
             if (currentSelection.cubePos == Cube3D.RubikPosition.None || currentSelection.facePos == Face3D.FacePosition.None)
             {
                 toolStripStatusLabel1.Text = "Ready";
             }
             else
             {
                 if (currentSelection.cubePos != oldSelection.cubePos)
                 {
                     if (!Cube3D.isCenter(currentSelection.cubePos))
                     {
                         if (oldSelection.facePos == currentSelection.facePos)
                         {
                             Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(oldSelection.facePos);
                             Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(oldSelection.cubePos, currentSelection.cubePos, assocLayer);
                             Boolean direction = true;
                             if (commonLayer == Cube3D.RubikPosition.TopLayer || commonLayer == Cube3D.RubikPosition.MiddleLayer || commonLayer == Cube3D.RubikPosition.BottomLayer)
                             {
                                 if (((oldSelection.facePos == Face3D.FacePosition.Front) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Right) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.FrontSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Back) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Left) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BackSlice)))
                                 {
                                     direction = false;
                                 }
                             }
                             if (commonLayer == Cube3D.RubikPosition.LeftSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice_Sides || commonLayer == Cube3D.RubikPosition.RightSlice)
                             {
                                 if (((oldSelection.facePos == Face3D.FacePosition.Top) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.FrontSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Front) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BottomLayer)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Bottom) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BackSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Back) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.TopLayer)))
                                 {
                                     direction = false;
                                 }
                             }
                             if (commonLayer == Cube3D.RubikPosition.BackSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice || commonLayer == Cube3D.RubikPosition.FrontSlice)
                             {
                                 if (((oldSelection.facePos == Face3D.FacePosition.Top) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Right) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.BottomLayer)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Bottom) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                     ((oldSelection.facePos == Face3D.FacePosition.Left) && currentSelection.cubePos.HasFlag(Cube3D.RubikPosition.TopLayer)))
                                 {
                                     direction = false;
                                 }
                             }
                             if (commonLayer != Cube3D.RubikPosition.None)
                             {
                                 if (groupBox1.Enabled)
                                 {
                                     groupBox1.Enabled = false;
                                     rotationTicks     = 25;
                                     rubikManager.Rotate90(commonLayer, direction, rotationTicks);
                                     comboBox1.Text             = commonLayer.ToString();
                                     toolStripStatusLabel1.Text = "Rotating " + commonLayer.ToString() + " " + ((direction) ? "Clockwise" : "Counter-Clockwise");
                                 }
                             }
                             else
                             {
                                 toolStripStatusLabel1.Text = "Error: Invalid second selection, does not specify distinct layer";
                             }
                         }
                         else
                         {
                             toolStripStatusLabel1.Text = "Error: Invalid second selection, must match orientation of first selection";
                         }
                     }
                     else
                     {
                         toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be a center";
                     }
                 }
                 else
                 {
                     toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be first selection";
                 }
             }
             rubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
             oldSelection = new RubikManager.PositionSpec()
             {
                 cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
             };
             currentSelection = new RubikManager.PositionSpec()
             {
                 cubePos = Cube3D.RubikPosition.None, facePos = Face3D.FacePosition.None
             };
         }
     }
 }
예제 #2
0
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         if ((Control.ModifierKeys & Keys.Shift) != 0)
         {
             if (currentSelection.CubePosition != Cube3D.RubikPosition.None && currentSelection.FacePosition != Face3D.FacePosition.None)
             {
                 Color clr = rubikRenderer.RubikManager.getFaceColor(currentSelection.CubePosition, currentSelection.FacePosition);
                 int   ind = 0;
                 for (int i = 0; i < contextMenuStrip1.Items.Count; i++)
                 {
                     if (contextMenuStrip1.Items[i].Text == clr.Name)
                     {
                         ind = i;
                     }
                 }
                 ind++;
                 if (ind >= colors.Length)
                 {
                     ind = 0;
                 }
                 rubikRenderer.RubikManager.setFaceColor(currentSelection.CubePosition, currentSelection.FacePosition, colors[ind]);
             }
         }
         else
         {
             if (!contextMenuStrip1.Visible)
             {
                 if (oldSelection.CubePosition == Cube3D.RubikPosition.None || oldSelection.FacePosition == Face3D.FacePosition.None)
                 {
                     if (currentSelection.CubePosition == Cube3D.RubikPosition.None || currentSelection.FacePosition == Face3D.FacePosition.None)
                     {
                         rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                         oldSelection = new PositionSpec()
                         {
                             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                         };
                         currentSelection = new PositionSpec()
                         {
                             CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                         };
                     }
                     else
                     {
                         if (!Cube3D.isCorner(currentSelection.CubePosition))
                         {
                             oldSelection = currentSelection;
                             rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f =>
                             {
                                 if (currentSelection.CubePosition != c.Position && !Cube3D.isCenter(c.Position) && currentSelection.FacePosition == f.Position)
                                 {
                                     Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(currentSelection.FacePosition);
                                     Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(currentSelection.CubePosition, c.Position, assocLayer);
                                     if (commonLayer != Cube3D.RubikPosition.None && c.Position.HasFlag(commonLayer))
                                     {
                                         f.Selection |= Face3D.SelectionMode.Possible;
                                     }
                                     else
                                     {
                                         f.Selection |= Face3D.SelectionMode.NotPossible;
                                     }
                                 }
                                 else
                                 {
                                     f.Selection |= Face3D.SelectionMode.NotPossible;
                                 }
                             }));
                             toolStripStatusLabel1.Text = "First selection: [" + currentSelection.CubePosition.ToString() + "] | " + currentSelection.FacePosition.ToString();;
                         }
                         else
                         {
                             rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                             toolStripStatusLabel1.Text = "Error: Invalid first selection, must not be a corner";
                         }
                     }
                 }
                 else
                 {
                     if (currentSelection.CubePosition == Cube3D.RubikPosition.None || currentSelection.FacePosition == Face3D.FacePosition.None)
                     {
                         toolStripStatusLabel1.Text = "Ready";
                     }
                     else
                     {
                         if (currentSelection.CubePosition != oldSelection.CubePosition)
                         {
                             if (!Cube3D.isCenter(currentSelection.CubePosition))
                             {
                                 if (oldSelection.FacePosition == currentSelection.FacePosition)
                                 {
                                     Cube3D.RubikPosition assocLayer  = Face3D.layerAssocToFace(oldSelection.FacePosition);
                                     Cube3D.RubikPosition commonLayer = Cube3D.getCommonLayer(oldSelection.CubePosition, currentSelection.CubePosition, assocLayer);
                                     Boolean direction = true;
                                     if (commonLayer == Cube3D.RubikPosition.TopLayer || commonLayer == Cube3D.RubikPosition.MiddleLayer || commonLayer == Cube3D.RubikPosition.BottomLayer)
                                     {
                                         if (((oldSelection.FacePosition == Face3D.FacePosition.Back) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Left) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BackSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Front) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Right) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.FrontSlice)))
                                         {
                                             direction = false;
                                         }
                                     }
                                     if (commonLayer == Cube3D.RubikPosition.LeftSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice_Sides || commonLayer == Cube3D.RubikPosition.RightSlice)
                                     {
                                         if (((oldSelection.FacePosition == Face3D.FacePosition.Bottom) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BackSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Back) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.TopLayer)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Top) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.FrontSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Front) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BottomLayer)))
                                         {
                                             direction = false;
                                         }
                                     }
                                     if (commonLayer == Cube3D.RubikPosition.BackSlice || commonLayer == Cube3D.RubikPosition.MiddleSlice || commonLayer == Cube3D.RubikPosition.FrontSlice)
                                     {
                                         if (((oldSelection.FacePosition == Face3D.FacePosition.Top) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.RightSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Right) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.BottomLayer)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Bottom) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.LeftSlice)) ||
                                             ((oldSelection.FacePosition == Face3D.FacePosition.Left) && currentSelection.CubePosition.HasFlag(Cube3D.RubikPosition.TopLayer)))
                                         {
                                             direction = false;
                                         }
                                     }
                                     if (commonLayer != Cube3D.RubikPosition.None)
                                     {
                                         if (groupBox1.Enabled)
                                         {
                                             groupBox1.Enabled = false;
                                             //rotationTicks = 25;
                                             if (commonLayer == Cube3D.RubikPosition.TopLayer || commonLayer == Cube3D.RubikPosition.LeftSlice || commonLayer == Cube3D.RubikPosition.FrontSlice)
                                             {
                                                 direction = !direction;
                                             }
                                             rubikRenderer.RubikManager.Rotate90(commonLayer, direction, rotationTime);
                                             comboBox1.Text             = commonLayer.ToString();
                                             toolStripStatusLabel1.Text = "Rotating " + commonLayer.ToString() + " " + ((direction) ? "Clockwise" : "Counter-Clockwise");
                                         }
                                     }
                                     else
                                     {
                                         toolStripStatusLabel1.Text = "Error: Invalid second selection, does not specify distinct layer";
                                     }
                                 }
                                 else
                                 {
                                     toolStripStatusLabel1.Text = "Error: Invalid second selection, must match orientation of first selection";
                                 }
                             }
                             else
                             {
                                 toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be a center";
                             }
                         }
                         else
                         {
                             toolStripStatusLabel1.Text = "Error: Invalid second selection, must not be first selection";
                         }
                     }
                     rubikRenderer.RubikManager.RubikCube.cubes.ForEach(c => c.Faces.ToList().ForEach(f => f.Selection = Face3D.SelectionMode.None));
                     oldSelection = new PositionSpec()
                     {
                         CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                     };
                     currentSelection = new PositionSpec()
                     {
                         CubePosition = Cube3D.RubikPosition.None, FacePosition = Face3D.FacePosition.None
                     };
                 }
             }
         }
     }
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     {
         if ((Control.ModifierKeys & Keys.Shift) != 0)
         {
             if (currentSelection.CubePosition != Cube3D.RubikPosition.None && currentSelection.FacePosition != Face3D.FacePosition.None)
             {
                 Color clr = rubikRenderer.RubikManager.getFaceColor(currentSelection.CubePosition, currentSelection.FacePosition);
                 for (int i = 0; i < contextMenuStrip1.Items.Count; i++)
                 {
                     ((ToolStripMenuItem)contextMenuStrip1.Items[i]).Checked = (contextMenuStrip1.Items[i].Text == clr.Name);
                 }
                 contextMenuStrip1.Show(Cursor.Position);
             }
         }
     }
 }