Beispiel #1
0
        public override void StartUp()
        {
            relationshipViewModel = CollisionRelationshipViewModelController.CreateViewModel();

            collidableViewModel = new CollidableNamedObjectRelationshipViewModel();
            CollidableNamedObjectController.RegisterViewModel(collidableViewModel);

            var collisionCodeGenerator = new CollisionCodeGenerator();

            AvailableAssetTypes.Self.AddAssetType(
                AssetTypeInfoManager.Self.CollisionRelationshipAti);

            RegisterCodeGenerator(collisionCodeGenerator);

            AssignEvents();
        }
Beispiel #2
0
        public static void RefreshViewModelTo(IElement container,
                                              NamedObjectSave thisNamedObject,
                                              CollidableNamedObjectRelationshipViewModel viewModel)
        {
            viewModel.CollisionRelationshipsTitle =
                $"{thisNamedObject.InstanceName} Collision Relationships";

            var isSingleEntity        = thisNamedObject.IsList == false && thisNamedObject.SourceType == SourceType.Entity;
            var isTileShapeCollection = thisNamedObject.SourceClassType ==
                                        "FlatRedBall.TileCollisions.TileShapeCollection" ||
                                        thisNamedObject.SourceClassType == "TileShapeCollection";
            List <NamedObjectSave> collidables;

            if (isTileShapeCollection)
            {
                // only against collidables:
                collidables = container.AllNamedObjects
                              .Where(item =>
                {
                    var entity = CollisionRelationshipViewModelController.GetEntitySaveReferencedBy(item);
                    return(entity?.ImplementsICollidable == true);
                })
                              .ToList();
            }
            else
            {
                collidables = container.AllNamedObjects
                              .Where(item =>
                {
                    return(CollisionRelationshipViewModelController.GetIfCanBeReferencedByRelationship(item));
                })
                              .ToList();
            }

            if (isSingleEntity)
            {
                // don't let this be against itself
                if (collidables.Contains(thisNamedObject))
                {
                    collidables.Remove(thisNamedObject);
                }
            }

            var relationships = container.AllNamedObjects
                                .Where(item =>
            {
                return(item.GetAssetTypeInfo() == AssetTypeInfoManager.Self.CollisionRelationshipAti);
            })
                                .ToArray();



            viewModel.NamedObjectPairs.Clear();

            var name1 = thisNamedObject.InstanceName;

            foreach (var collidable in collidables)
            {
                var name2 = collidable.InstanceName;

                var pairViewModel = new NamedObjectPairRelationshipViewModel();
                pairViewModel.AddObjectClicked       += (not, used) => HandleAddCollisionRelationshipAddClicked(pairViewModel);
                pairViewModel.OtherObjectName         = collidable.InstanceName;
                pairViewModel.SelectedNamedObjectName = thisNamedObject.InstanceName;

                var relationshipsForThisPair = relationships
                                               .Where(item =>
                {
                    return((FirstCollidableIn(item) == name1 && SecondCollidableIn(item) == name2) ||
                           (FirstCollidableIn(item) == name2 && SecondCollidableIn(item) == name1));
                })
                                               .ToArray();

                foreach (var relationship in relationshipsForThisPair)
                {
                    var relationshipViewModel = new RelationshipListCellViewModel();
                    relationshipViewModel.OwnerNamedObject = thisNamedObject;
                    relationshipViewModel.OtherNamedObject = collidable;
                    relationshipViewModel.CollisionRelationshipNamedObject = relationship;

                    pairViewModel.Relationships.Add(relationshipViewModel);
                }


                viewModel.NamedObjectPairs.Add(pairViewModel);
            }
        }
Beispiel #3
0
 public static void RegisterViewModel(CollidableNamedObjectRelationshipViewModel viewModel)
 {
     ViewModel = viewModel;
 }