示例#1
0
        private void Selection_SelectionChanged(EditorItemSelection sender)
        {
            if (suppressSelectionEvents)
            {
                return;
            }

            // match our tree to our editor selection
            List <TreeNode> selectedNodes = new List <TreeNode>();

            foreach (Item item in sender.Items)
            {
                if (item is LevelItem)
                {
                    LevelItem levelItem = (LevelItem)item;

                    // find the index of the level item
                    int index = LevelData.GetIndexOfItem(levelItem);

                    selectedNodes.Add(levelItemNode.Nodes[index]);
                }
                else if (item is LevelAnim)
                {
                    LevelAnim levelAnim = (LevelAnim)item;

                    // find the index of the level animation
                    int index = LevelData.GetIndexOfItem(levelAnim);

                    selectedNodes.Add(levelAnimNode.Nodes[index]);
                }
                else if (item is DeathZoneItem)
                {
                    DeathZoneItem deathZoneItem = (DeathZoneItem)item;

                    int index = LevelData.DeathZones.IndexOf(deathZoneItem);

                    selectedNodes.Add(deathZoneNode.Nodes[index]);
                }
                else if (item is MissionSETItem)
                {
                    MissionSETItem miSetItem = (MissionSETItem)item;

                    int index = LevelData.MissionSETItems[LevelData.Character].IndexOf(miSetItem);

                    selectedNodes.Add(missionSETNode.Nodes[index]);
                }
                else if (item is SETItem)
                {
                    SETItem setItem = (SETItem)item;

                    int index = LevelData.GetIndexOfSETItem(LevelData.Character, setItem);                    //LevelData.SETItems[LevelData.Character].IndexOf(setItem);

                    selectedNodes.Add(setNode.Nodes[index]);
                }
                else if (item is CAMItem)
                {
                    CAMItem camItem = (CAMItem)item;

                    int index = LevelData.CAMItems[LevelData.Character].IndexOf(camItem);

                    selectedNodes.Add(camNode.Nodes[index]);
                }
                else if (item is SplineData)
                {
                    SplineData spline = (SplineData)item;

                    int index = LevelData.LevelSplines.IndexOf(spline);

                    selectedNodes.Add(splineNode.Nodes[index]);
                }
            }

            sceneTreeView.SelectedNodes = selectedNodes;
        }
示例#2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            List <Item> selection = items.GetSelection();

            foreach (Item item in selection)
            {
                if (item is SETItem)
                {
                    SETItem itemConv = (SETItem)item;

                    if (sonicCheckBox.Checked)
                    {
                        LevelData.AddSETItem(0, new SETItem(itemConv.GetBytes(), 0, items));
                    }

                    if (tailsCheckBox.Checked)
                    {
                        LevelData.AddSETItem(1, new SETItem(itemConv.GetBytes(), 0, items));
                    }

                    if (knucklesCheckBox.Checked)
                    {
                        LevelData.AddSETItem(2, new SETItem(itemConv.GetBytes(), 0, items));
                    }

                    if (amyCheckBox.Checked)
                    {
                        LevelData.AddSETItem(3, new SETItem(itemConv.GetBytes(), 0, items));
                    }

                    if (gammaCheckBox.Checked)
                    {
                        LevelData.AddSETItem(4, new SETItem(itemConv.GetBytes(), 0, items));
                    }

                    if (bigCheckBox.Checked)
                    {
                        LevelData.AddSETItem(5, new SETItem(itemConv.GetBytes(), 0, items));
                    }
                }
                else if (item is CAMItem)
                {
                    CAMItem itemConv = (CAMItem)item;

                    if ((sonicCheckBox.Checked) && (LevelData.CAMItems[0] != null))
                    {
                        LevelData.CAMItems[0].Add(new CAMItem(itemConv.GetBytes(), 0, items));
                    }

                    if (tailsCheckBox.Checked)
                    {
                        LevelData.CAMItems[1].Add(new CAMItem(itemConv.GetBytes(), 0, items));
                    }

                    if (knucklesCheckBox.Checked)
                    {
                        LevelData.CAMItems[2].Add(new CAMItem(itemConv.GetBytes(), 0, items));
                    }

                    if (amyCheckBox.Checked)
                    {
                        LevelData.CAMItems[3].Add(new CAMItem(itemConv.GetBytes(), 0, items));
                    }

                    if (gammaCheckBox.Checked)
                    {
                        LevelData.CAMItems[4].Add(new CAMItem(itemConv.GetBytes(), 0, items));
                    }

                    if (bigCheckBox.Checked)
                    {
                        LevelData.CAMItems[5].Add(new CAMItem(itemConv.GetBytes(), 0, items));
                    }
                }
            }

            Close();
        }
示例#3
0
        /// <summary>
        /// Transforms the Items that belong to this Gizmo.
        /// </summary>
        /// <param name="xChange">Input for x axis.</param>
        /// <param name="yChange">Input for y axis.</param>
        public void TransformAffected(float xChange, float yChange, EditorCamera cam)
        {
            // don't operate with an invalid axis seleciton, or invalid mode
            if (!enabled)
            {
                return;
            }
            if ((selectedAxes == GizmoSelectedAxes.NONE) || (mode == TransformMode.NONE))
            {
                return;
            }

            float yFlip   = -1;           // I don't think we'll ever need to mess with this
            float xFlip   = 1;
            float axisDot = 0;

            for (int i = 0; i < affectedItems.Count; i++)             // loop through operands
            {
                Item currentItem = affectedItems[i];
                switch (mode)
                {
                case TransformMode.TRANFORM_MOVE:
                    if (isTransformLocal)                             // then check operant space.
                    {
                        Vector3 Up = new Vector3(), Look = new Vector3(), Right = new Vector3();
                        affectedItems[i].GetLocalAxes(out Up, out Right, out Look);

                        Vector3 currentPosition = currentItem.Position.ToVector3();
                        Vector3 destination     = new Vector3();

                        switch (selectedAxes)
                        {
                        case GizmoSelectedAxes.X_AXIS:
                            axisDot     = Vector3.Dot(cam.Look, Right);
                            xFlip       = (axisDot > 0) ? 1 : -1;
                            destination = (currentPosition + Right * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange * xFlip : yChange));
                            break;

                        case GizmoSelectedAxes.Y_AXIS:
                            destination = (currentPosition + Up * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange : yChange * yFlip));
                            break;

                        case GizmoSelectedAxes.Z_AXIS:
                            axisDot     = Vector3.Dot(cam.Look, Right);
                            xFlip       = (axisDot > 0) ? -1 : 1;
                            destination = (currentPosition + Look * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange * xFlip : yChange));
                            break;
                        }

                        currentItem.Position = destination.ToVertex();
                    }
                    else
                    {
                        float   xOff = 0.0f, yOff = 0.0f, zOff = 0.0f;
                        Vector3 axisDirection = new Vector3();

                        switch (selectedAxes)
                        {
                        case GizmoSelectedAxes.X_AXIS:
                            axisDirection = new Vector3(1, 0, 0);
                            axisDot       = Vector3.Dot(cam.Look, axisDirection);
                            xFlip         = (axisDot > 0) ? 1 : -1;
                            xOff          = xChange * xFlip;
                            break;

                        case GizmoSelectedAxes.Y_AXIS:
                            axisDirection = new Vector3(0, 1, 0);
                            axisDot       = Vector3.Dot(cam.Look, axisDirection);
                            yOff          = yChange * yFlip;
                            break;

                        case GizmoSelectedAxes.Z_AXIS:
                            axisDirection = new Vector3(0, 0, 1);
                            axisDot       = Vector3.Dot(cam.Look, axisDirection);
                            xFlip         = (axisDot > 0) ? -1 : 1;
                            zOff          = xChange * xFlip;
                            break;

                        case GizmoSelectedAxes.XY_AXIS:
                            xOff = xChange; yOff = yChange * yFlip;
                            break;

                        case GizmoSelectedAxes.XZ_AXIS:
                            xOff = xChange; zOff = yChange;
                            break;

                        case GizmoSelectedAxes.ZY_AXIS:
                            zOff = xChange; yOff = yChange * yFlip;
                            break;
                        }

                        currentItem.Position = new Vertex(currentItem.Position.X + xOff, currentItem.Position.Y + yOff, currentItem.Position.Z + zOff);
                    }

                    if (currentItem is LevelItem)
                    {
                        LevelItem levelItem = (LevelItem)currentItem;
                        levelItem.Save();
                    }
                    break;

                case TransformMode.TRANSFORM_ROTATE:
                    if (currentItem is StartPosItem)
                    {
                        currentItem.Rotation.Y += (int)xChange;
                        continue;
                    }
                    if (currentItem is CAMItem)
                    {
                        currentItem.Rotation.Y += (int)xChange * 2;
                        continue;
                    }

                    if (isTransformLocal)                             // then check operant space.
                    {
                        try
                        {
                            switch (selectedAxes)
                            {
                            case GizmoSelectedAxes.X_AXIS:
                                currentItem.Rotation.XDeg += (int)xChange;
                                break;

                            case GizmoSelectedAxes.Y_AXIS:
                                currentItem.Rotation.ZDeg += (int)xChange;
                                break;

                            case GizmoSelectedAxes.Z_AXIS:
                                currentItem.Rotation.YDeg += (int)xChange;
                                break;
                            }
                        }
                        catch (NotSupportedException)
                        {
                            Console.WriteLine("Certain Item types don't support rotations. This can be ignored.");
                        }
                    }
                    else
                    {
                        // This code doesn't work - we need to find another way to do global rotations
                        //int xOff = 0, yOff = 0, zOff = 0;
                        MatrixStack objTransform = new MatrixStack();

                        /*
                         * switch (selectedAxes)
                         * {
                         *      case GizmoSelectedAxes.X_AXIS:
                         *              xOff = (int)xChange;
                         *              break;
                         *
                         *      case GizmoSelectedAxes.Y_AXIS:
                         *              yOff = (int)xChange;
                         *              break;
                         *
                         *      case GizmoSelectedAxes.Z_AXIS:
                         *              zOff = (int)xChange;
                         *              break;
                         * }
                         */

                        objTransform.Push();
                        //objTransform.RotateXYZLocal(xOff, yOff, zOff);
                        objTransform.RotateXYZLocal(currentItem.Rotation.X, currentItem.Rotation.Y, currentItem.Rotation.Z);

                        //Rotation oldRotation = currentItem.Rotation;
                        //Rotation newRotation = SAModel.Direct3D.Extensions.FromMatrix(objTransform.Top);

                        // todo: Fix Matrix->Euler conversion, then uncomment the line with the rotatexyz call. Then uncomment the call below and the gizmo should work.
                        //currentItem.Rotation = newRotation;
                    }
                    break;

                case TransformMode.TRANSFORM_SCALE:
                    if (currentItem is LevelItem)
                    {
                        LevelItem levelItem = (LevelItem)currentItem;
                        switch (selectedAxes)
                        {
                        case GizmoSelectedAxes.X_AXIS:
                            levelItem.CollisionData.Model.Scale = new Vertex(levelItem.CollisionData.Model.Scale.X + xChange, levelItem.CollisionData.Model.Scale.Y, levelItem.CollisionData.Model.Scale.Z);
                            break;

                        case GizmoSelectedAxes.Y_AXIS:
                            levelItem.CollisionData.Model.Scale = new Vertex(levelItem.CollisionData.Model.Scale.X, levelItem.CollisionData.Model.Scale.Y + yChange, levelItem.CollisionData.Model.Scale.Z);
                            break;

                        case GizmoSelectedAxes.Z_AXIS:
                            levelItem.CollisionData.Model.Scale = new Vertex(levelItem.CollisionData.Model.Scale.X, levelItem.CollisionData.Model.Scale.Y, levelItem.CollisionData.Model.Scale.Z + xChange);
                            break;
                        }
                    }
                    else if (currentItem is CAMItem)
                    {
                        CAMItem camItem = (CAMItem)currentItem;
                        switch (selectedAxes)
                        {
                        case GizmoSelectedAxes.X_AXIS:
                            camItem.Scale = new Vertex(MathHelper.Clamp(camItem.Scale.X + xChange, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Y, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Z, 1, float.MaxValue));                                             // Clamping is to prevent invalid scale valeus (0 or less)
                            break;

                        case GizmoSelectedAxes.Y_AXIS:
                            camItem.Scale = new Vertex(MathHelper.Clamp(camItem.Scale.X, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Y + yChange, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Z, 1, float.MaxValue));
                            break;

                        case GizmoSelectedAxes.Z_AXIS:
                            camItem.Scale = new Vertex(MathHelper.Clamp(camItem.Scale.X, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Y, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Z + xChange, 1, float.MaxValue));                                             // I just realized that Math.Min would work for these. Oh well, gave me an excuse to write a clamp function
                            break;
                        }
                    }
                    break;
                }
            }

            SetGizmo();
        } // end of TransformAffected()