Example #1
0
        public static void SetAfterUpdateDelegate(Type type, string member, AfterUpdateDelegate afterUpdateDelegate)
        {
            PropertyComparer propertyComparer =
                mPropertyComparers[type];

            propertyComparer.SetAfterUpdateDelegateForMember(member, afterUpdateDelegate);
        }
Example #2
0
        public static void RecordUndos <T>(bool createNewList) where T : new()
        {
            PropertyComparer <T> propertyComparer =
                mPropertyComparers[typeof(T)] as PropertyComparer <T>;

            propertyComparer.GetAllChangedMemberInstructions(mInstructions, createNewList);
        }
Example #3
0
        public static void ClearObjectsWatching <T>() where T : new()
        {
            PropertyComparer <T> propertyComparer =
                mPropertyComparers[typeof(T)] as PropertyComparer <T>;

            propertyComparer.ClearObjects();
        }
Example #4
0
        public static void SetPropertyComparer(Type type, PropertyComparer propertyComparer)
        {
            if (mPropertyComparers.ContainsKey(type))
            {
                mPropertyComparers.Remove(type);
            }

            mPropertyComparers.Add(type, propertyComparer);
        }
Example #5
0
        public static void AddAxisAlignedCubePropertyComparer()
        {
            PropertyComparer <AxisAlignedCube> axisAlignedCubePropertyComparer =
                new PropertyComparer <AxisAlignedCube>();

            mPropertyComparers.Add(typeof(AxisAlignedCube), axisAlignedCubePropertyComparer);

            axisAlignedCubePropertyComparer.AddMemberWatching <float>("X");
            axisAlignedCubePropertyComparer.AddMemberWatching <float>("Y");
            axisAlignedCubePropertyComparer.AddMemberWatching <float>("Z");

            axisAlignedCubePropertyComparer.AddMemberWatching <float>("ScaleX");
            axisAlignedCubePropertyComparer.AddMemberWatching <float>("ScaleY");
            axisAlignedCubePropertyComparer.AddMemberWatching <float>("ScaleZ");
        }
Example #6
0
        public static void AddToWatch <T>(T objectToWatch) where T : new()
        {
            PropertyComparer <T> propertyComparer =
                mPropertyComparers[typeof(T)] as PropertyComparer <T>;

            if (objectToWatch == null)
            {
                throw new NullReferenceException("Can't add a null object to the UndoManager's watch");
            }

            if (propertyComparer.Contains(objectToWatch) == false)
            {
                propertyComparer.AddObject(objectToWatch, new T());
            }
        }
Example #7
0
        static UndoManager()
        {
            // These should be moved into their own constructors that the user can call depending on what undos they need

            #region Set the members to watch for Sprites
            PropertyComparer <Sprite> spritePropertyComparer =
                new PropertyComparer <Sprite>();
            mPropertyComparers.Add(typeof(Sprite), spritePropertyComparer);

            spritePropertyComparer.AddMemberWatching <float>("X");
            spritePropertyComparer.AddMemberWatching <float>("Y");
            spritePropertyComparer.AddMemberWatching <float>("Z");

            spritePropertyComparer.AddMemberWatching <float>("ScaleX");
            spritePropertyComparer.AddMemberWatching <float>("ScaleY");

            spritePropertyComparer.AddMemberWatching <float>("RotationX");
            spritePropertyComparer.AddMemberWatching <float>("RotationY");
            spritePropertyComparer.AddMemberWatching <float>("RotationZ");

            spritePropertyComparer.AddMemberWatching <float>("RelativeX");
            spritePropertyComparer.AddMemberWatching <float>("RelativeY");
            spritePropertyComparer.AddMemberWatching <float>("RelativeZ");

            spritePropertyComparer.AddMemberWatching <float>("RelativeRotationX");
            spritePropertyComparer.AddMemberWatching <float>("RelativeRotationY");
            spritePropertyComparer.AddMemberWatching <float>("RelativeRotationZ");

            #endregion

            #region Set the members to watch for SpriteFrames
            PropertyComparer <SpriteFrame> spriteFramePropertyComparer =
                new PropertyComparer <SpriteFrame>();
            mPropertyComparers.Add(typeof(SpriteFrame), spriteFramePropertyComparer);

            spriteFramePropertyComparer.AddMemberWatching <float>("X");
            spriteFramePropertyComparer.AddMemberWatching <float>("Y");
            spriteFramePropertyComparer.AddMemberWatching <float>("Z");

            spriteFramePropertyComparer.AddMemberWatching <float>("ScaleX");
            spriteFramePropertyComparer.AddMemberWatching <float>("ScaleY");

            spriteFramePropertyComparer.AddMemberWatching <float>("RotationX");
            spriteFramePropertyComparer.AddMemberWatching <float>("RotationY");
            spriteFramePropertyComparer.AddMemberWatching <float>("RotationZ");

            spriteFramePropertyComparer.AddMemberWatching <float>("RelativeX");
            spriteFramePropertyComparer.AddMemberWatching <float>("RelativeY");
            spriteFramePropertyComparer.AddMemberWatching <float>("RelativeZ");

            spriteFramePropertyComparer.AddMemberWatching <float>("RelativeRotationX");
            spriteFramePropertyComparer.AddMemberWatching <float>("RelativeRotationY");
            spriteFramePropertyComparer.AddMemberWatching <float>("RelativeRotationZ");

            #endregion

            #region Set the members to watch for Polygons

            PolygonPropertyComparer polygonPropertyComparer = new PolygonPropertyComparer();
            mPropertyComparers.Add(typeof(Polygon), polygonPropertyComparer);

            polygonPropertyComparer.AddMemberWatching <float>("X");
            polygonPropertyComparer.AddMemberWatching <float>("Y");
            polygonPropertyComparer.AddMemberWatching <float>("Z");

            polygonPropertyComparer.AddMemberWatching <float>("RotationZ");

            #endregion

            #region Set the members to watch for AxisAlignedRectangles

            PropertyComparer <AxisAlignedRectangle> axisAlignedRectanglePropertyComparer =
                new PropertyComparer <AxisAlignedRectangle>();
            mPropertyComparers.Add(typeof(AxisAlignedRectangle), axisAlignedRectanglePropertyComparer);

            axisAlignedRectanglePropertyComparer.AddMemberWatching <float>("X");
            axisAlignedRectanglePropertyComparer.AddMemberWatching <float>("Y");
            axisAlignedRectanglePropertyComparer.AddMemberWatching <float>("Z");

            axisAlignedRectanglePropertyComparer.AddMemberWatching <float>("ScaleX");
            axisAlignedRectanglePropertyComparer.AddMemberWatching <float>("ScaleY");

            #endregion

            #region Set the members to watch for Circles

            PropertyComparer <Circle> circlePropertyComparer = new PropertyComparer <Circle>();
            mPropertyComparers.Add(typeof(Circle), circlePropertyComparer);

            circlePropertyComparer.AddMemberWatching <float>("X");
            circlePropertyComparer.AddMemberWatching <float>("Y");
            circlePropertyComparer.AddMemberWatching <float>("Z");

            circlePropertyComparer.AddMemberWatching <float>("Radius");

            #endregion

            #region Set the members to watch for Spheres

            PropertyComparer <Sphere> spherePropertyComparer =
                new PropertyComparer <Sphere>();
            mPropertyComparers.Add(typeof(Sphere), spherePropertyComparer);

            spherePropertyComparer.AddMemberWatching <float>("X");
            spherePropertyComparer.AddMemberWatching <float>("Y");
            spherePropertyComparer.AddMemberWatching <float>("Z");

            spherePropertyComparer.AddMemberWatching <float>("Radius");

            #endregion

            #region Set the members to watch for Texts
            PropertyComparer <Text> textPropertyComparer =
                new PropertyComparer <Text>();
            mPropertyComparers.Add(typeof(Text), textPropertyComparer);

            textPropertyComparer.AddMemberWatching <float>("X");
            textPropertyComparer.AddMemberWatching <float>("Y");
            textPropertyComparer.AddMemberWatching <float>("Z");

            textPropertyComparer.AddMemberWatching <float>("RotationZ");
            #endregion

            #region Set the members to watch for PositionedModels
            PropertyComparer <PositionedModel> positionedModelPropertyComparer =
                new PropertyComparer <PositionedModel>();
            mPropertyComparers.Add(typeof(PositionedModel), positionedModelPropertyComparer);

            positionedModelPropertyComparer.AddMemberWatching <float>("X");
            positionedModelPropertyComparer.AddMemberWatching <float>("Y");
            positionedModelPropertyComparer.AddMemberWatching <float>("Z");

            positionedModelPropertyComparer.AddMemberWatching <float>("RotationZ");

            #endregion

            #region Set the members to watch for SpriteGrids

            mPropertyComparers.Add(typeof(SpriteGrid),
                                   new SpriteGridPropertyComparer());

            #endregion
        }
Example #8
0
        public static void EndOfFrameActivity()
        {
            UpdateListDisplayWindow();

            #region Perform Undos if pushed Control+Z

            if (InputManager.Keyboard.ControlZPushed() &&
                mInstructions.Count != 0)
            {
                InstructionList instructionList = mInstructions[mInstructions.Count - 1];

                for (int i = 0; i < instructionList.Count; i++)
                {
                    Instruction instruction = instructionList[i];

                    // See if the instruction is one that has an associated delegate
                    if (instruction is GenericInstruction)
                    {
                        GenericInstruction asGenericInstruction = instruction as GenericInstruction;

                        Type targetType = asGenericInstruction.Target.GetType();

                        PropertyComparer propertyComparerForType = null;

                        if (mPropertyComparers.ContainsKey(targetType))
                        {
                            // There is a PropertyComparer for this exact type
                            propertyComparerForType = mPropertyComparers[targetType];
                        }
                        else
                        {
                            // There isn't a PropertyComparer for this exact type, so climb up the inheritance tree
                            foreach (PropertyComparer pc in mPropertyComparers.Values)
                            {
                                if (pc.GenericType.IsAssignableFrom(targetType))
                                {
                                    propertyComparerForType = pc;
                                    break;
                                }
                            }
                        }

                        // If there's no PropertyComparer, then the app might be a UI-only app.  If that's
                        // the case, we don't want to run afterUpdateDelegates
                        if (propertyComparerForType != null)
                        {
                            AfterUpdateDelegate afterUpdateDelegate =
                                propertyComparerForType.GetAfterUpdateDelegateForMember(asGenericInstruction.Member);

                            if (afterUpdateDelegate != null)
                            {
                                afterUpdateDelegate(asGenericInstruction.Target);
                            }
                        }
                    }

                    instruction.Execute();
                }
                mInstructions.RemoveAt(mInstructions.Count - 1);
            }

            #endregion

            // Vic says that this will break if undos are added through this and through
            // the property comparers in the same frame.
            if (mUndosAddedThisFrame.Count != 0)
            {
                mInstructions.Add(mUndosAddedThisFrame);

                mUndosAddedThisFrame = new InstructionList();
            }
        }