private static void HandleViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var viewModel   = sender as CollisionRelationshipViewModel;
            var namedObject = GlueState.Self.CurrentNamedObjectSave;

            var element = GlueState.Self.CurrentElement;

            switch (e.PropertyName)
            {
            case nameof(viewModel.FirstCollisionName):
            case nameof(viewModel.SecondCollisionName):
                var nos = viewModel.GlueObject as NamedObjectSave;
                CollisionRelationshipViewModelController.TryFixSourceClassType(nos);

                RefreshSubcollisionObjects(element, viewModel);

                TryApplyAutoName(element, namedObject);
                break;

            case nameof(viewModel.FirstSubCollisionSelectedItem):
                TryApplyAutoName(element, namedObject);

                break;

            case nameof(viewModel.SecondSubCollisionSelectedItem):
                TryApplyAutoName(element, namedObject);

                break;

            case nameof(viewModel.IsAutoNameEnabled):
                TryApplyAutoName(element, namedObject);
                break;
            }
        }
Ejemplo n.º 2
0
        private static void HandleViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var viewModel = sender as CollisionRelationshipViewModel;

            ////////////////Early Out///////////////////
            if (viewModel.IsUpdatingFromGlueObject)
            {
                return;
            }

            //////////////End Early Out/////////////////

            var namedObject = GlueState.Self.CurrentNamedObjectSave;

            var element = GlueState.Self.CurrentElement;
            var nos     = viewModel.GlueObject as NamedObjectSave;

            switch (e.PropertyName)
            {
            case nameof(viewModel.FirstCollisionName):
            case nameof(viewModel.SecondCollisionName):
                CollisionRelationshipViewModelController.TryFixSourceClassType(nos);

                RefreshSubcollisionObjects(element, viewModel);

                TryApplyAutoName(element, namedObject);

                if (TryFixMassesForTileShapeCollisionRelationship(element, nos))
                {
                    viewModel.UpdateFromGlueObject();
                }

                break;

            case nameof(viewModel.FirstSubCollisionSelectedItem):
                TryApplyAutoName(element, namedObject);

                break;

            case nameof(viewModel.SecondSubCollisionSelectedItem):
                TryApplyAutoName(element, namedObject);

                break;

            case nameof(viewModel.IsAutoNameEnabled):
                TryApplyAutoName(element, namedObject);
                break;

            case nameof(viewModel.CollisionType):
                if (TryFixMassesForTileShapeCollisionRelationship(element, nos))
                {
                    viewModel.UpdateFromGlueObject();
                }
                break;
            }
        }
Ejemplo n.º 3
0
        private static void HandleAddCollisionRelationshipAddClicked(NamedObjectPairRelationshipViewModel pairViewModel)
        {
            var addObjectModel = new AddObjectViewModel();

            addObjectModel.SourceType      = FlatRedBall.Glue.SaveClasses.SourceType.FlatRedBallType;
            addObjectModel.SourceClassType = "FlatRedBall.Math.Collision.CollisionRelationship";
            addObjectModel.ObjectName      = "ToBeRenamed";

            IElement selectedElement     = GlueState.Self.CurrentElement;
            var      selectedNamedObject = GlueState.Self.CurrentNamedObjectSave;

            var newNos =
                GlueCommands.Self.GluxCommands.AddNewNamedObjectTo(addObjectModel,
                                                                   selectedElement, namedObject: null);

            newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.IsAutoNameEnabled), true);

            bool needToInvert = selectedNamedObject.SourceType != SourceType.Entity &&
                                selectedNamedObject.IsList == false;

            if (needToInvert)
            {
                newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.FirstCollisionName),
                                           pairViewModel.OtherObjectName);
                newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.SecondCollisionName),
                                           pairViewModel.SelectedNamedObjectName);
            }
            else
            {
                newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.FirstCollisionName),
                                           pairViewModel.SelectedNamedObjectName);
                newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.SecondCollisionName),
                                           pairViewModel.OtherObjectName);
            }


            CollisionRelationshipViewModelController.TryFixSourceClassType(newNos);

            // this will regenerate and save everything too:
            CollisionRelationshipViewModelController.TryApplyAutoName(
                selectedElement, newNos);


            RefreshViewModelTo(selectedElement, selectedNamedObject, ViewModel);

            CollisionRelationshipViewModelController.TryFixMassesForTileShapeCollisionRelationship(selectedElement, newNos);
        }