public void AddSpritesToLayers(Layer darknessLayer, Layer hudLayer) { if (LayerProvidedByContainer != null) { if (HasLightSource) { LayerProvidedByContainer.Remove(LightOrShadowSprite); } LayerProvidedByContainer.Remove(CircleInstance); } if (_AddedToLayers) { darknessLayer.Remove(LightOrShadowSprite); hudLayer.Remove(CircleInstance); if (HasLightSource) { darknessLayer.Remove(SpriteInstance); } } if (HasLightSource) { SpriteManager.AddToLayer(SpriteInstance, darknessLayer); } if (HasLightSource) { SpriteManager.AddToLayer(LightOrShadowSprite, darknessLayer); } ShapeManager.AddToLayer(CircleInstance, hudLayer); _AddedToLayers = true; }
public new void AddSpritesToLayers(Layer darknessLayer, Layer hudLayer) { base.AddSpritesToLayers(darknessLayer, hudLayer); LayerProvidedByContainer.Remove(RangeCircleInstance); ShapeManager.AddToLayer(RangeCircleInstance, hudLayer); }
protected void AddSpritesToLayers(Layer darknessLayer, Layer hudLayer) { _hudLayer = hudLayer; _lightLayer = darknessLayer; #if DEBUG if (DebugVariables.ShowDebugShapes) { LayerProvidedByContainer.Remove(AxisAlignedRectangleInstance); ShapeManager.AddToLayer(AxisAlignedRectangleInstance, hudLayer); } #endif LayerProvidedByContainer.Remove(RangePreviewSprite); SpriteManager.AddToLayer(RangePreviewSprite, hudLayer); LayerProvidedByContainer.Remove(LightSpriteInstance); SpriteManager.AddToLayer(LightSpriteInstance, darknessLayer); LayerProvidedByContainer.Remove(WarpSpriteInstance); SpriteManager.AddToLayer(WarpSpriteInstance, darknessLayer); LayerProvidedByContainer.Remove(LightAimSpriteInstance); SpriteManager.AddToLayer(LightAimSpriteInstance, darknessLayer); var gumLayer = RenderingLibrary.SystemManagers.Default.Renderer.Layers.FirstOrDefault(l => l.Name == "InfoLayerGum"); StructureUpgradeStatusInstance.MoveToFrbLayer(hudLayer, gumLayer); LayerProvidedByContainer.Remove(RangeCircleInstance); ShapeManager.AddToLayer(RangeCircleInstance, hudLayer); }
// Generated AddToManagers public virtual void ReAddToManagers(Layer layerToAddTo) { LayerProvidedByContainer = layerToAddTo; SpriteManager.AddPositionedObject(this); ShapeManager.AddToLayer(mCollision, LayerProvidedByContainer); SpriteManager.AddToLayer(Sprite, LayerProvidedByContainer); }
protected void AddSpritesToLayers(FlatRedBall.Graphics.Layer worldLayer, FlatRedBall.Graphics.Layer darknessLayer, FlatRedBall.Graphics.Layer hudLayer) { if (_AddedToLayers) { darknessLayer.Remove(LightSprite); if (CircleInstance != null) { hudLayer.Remove(CircleInstance); } if (AxisAlignedRectangleInstance != null) { hudLayer.Remove(AxisAlignedRectangleInstance); } } StunParticles.LayerToEmitOn = worldLayer; PoisonedParticles.LayerToEmitOn = worldLayer; FrozenParticles.LayerToEmitOn = worldLayer; SmokeParticles.LayerToEmitOn = worldLayer; HealthBar.MoveToLayer(hudLayer); SpriteManager.AddToLayer(SpriteInstance, worldLayer); SpriteManager.AddToLayer(LightSprite, darknessLayer); SpriteManager.AddToLayer(ShadowSprite, worldLayer); if (CircleInstance != null) { ShapeManager.AddToLayer(CircleInstance, hudLayer); } if (AxisAlignedRectangleInstance != null) { ShapeManager.AddToLayer(AxisAlignedRectangleInstance, hudLayer); } _AddedToLayers = true; }
public void AddToLayer(Layer layer) { mLayer = layer; if (layer != null) { if (layer.CameraBelongingTo == null) { mText.CameraToAdjustPixelPerfectTo = SpriteManager.Camera; } else { mText.CameraToAdjustPixelPerfectTo = layer.CameraBelongingTo; } } if (mCircleVisibleRepresentation != null) { ShapeManager.AddToLayer(mCircleVisibleRepresentation, layer); } else { SpriteManager.AddToLayer(mSpriteVisibleRepresentation, layer); } ShapeManager.AddToLayer(mParentLine, layer); ShapeManager.AddToLayer(mParentAttachmentPoint, layer); TextManager.AddToLayer(mText, layer); mText.SetPixelPerfectScale(mLayer); }
private void CreateLines() { //Create vertical lines for (int i = 0; i < BoardColumn + 1; ++i) { //Assign variable double X = i * (Global.GAMETILE_WIDTH + (2 * Global.GAMEGAP_WIDTH)); Line L = ShapeManager.AddLine(); //Draw line L.RelativePoint1 = new Point3D(X, Global.EDITORLINE_LIMIT, 0); L.RelativePoint2 = new Point3D(X, Global.EDITORLINE_LIMIT, BoardRow * (Global.GAMETILE_HEIGHT + (2 * Global.GAMEGAP_HEIGHT))); L.Color = Color.Black; ShapeManager.AddToLayer(L, m_Layer); } //Create horizontal lines for (int i = 0; i < BoardRow + 1; ++i) { //Assign variable double Z = i * (Global.GAMETILE_HEIGHT + (2 * Global.GAMEGAP_HEIGHT)); Line L = ShapeManager.AddLine(); //Draw line L.RelativePoint1 = new Point3D(0, Global.EDITORLINE_LIMIT, Z); L.RelativePoint2 = new Point3D(BoardColumn * (Global.GAMETILE_WIDTH + (2 * Global.GAMEGAP_WIDTH)), Global.EDITORLINE_LIMIT, Z); L.Color = Color.Black; ShapeManager.AddToLayer(L, m_Layer); } }
// Generated AddToManagers public override void ReAddToManagers(Layer layerToAddTo) { base.ReAddToManagers(layerToAddTo); SpriteManager.AddToLayer(SpriteInstance, LayerProvidedByContainer); SpriteManager.AddToLayer(HandSprite, LayerProvidedByContainer); ShapeManager.AddToLayer(mGunRectangle, LayerProvidedByContainer); SpriteManager.AddToLayer(mFedoraSprite, LayerProvidedByContainer); }
protected void InitializeNewPoly(Polygon polygon) { ShapeManager.AddPolygon(polygon); ShapeManager.AddToLayer(polygon, Layer); polygon.Color = Color; }
public virtual void AddToManagers(Layer layerToAddTo) { LayerProvidedByContainer = layerToAddTo; SpriteManager.AddPositionedObject(this); ShapeManager.AddToLayer(mCollision, LayerProvidedByContainer); AddToManagersBottomUp(layerToAddTo); CustomInitialize(); }
public override void AddToManagers(Layer layerToAddTo) { LayerProvidedByContainer = layerToAddTo; SpriteManager.AddToLayer(SpriteInstance, LayerProvidedByContainer); SpriteManager.AddToLayer(HandSprite, LayerProvidedByContainer); ShapeManager.AddToLayer(mGunRectangle, LayerProvidedByContainer); SpriteManager.AddToLayer(mFedoraSprite, LayerProvidedByContainer); base.AddToManagers(layerToAddTo); CustomInitialize(); }
public Handle(Layer layer, Circle circle) { mLayer = layer; mCircle = circle; ScaleXCoefficient = 0; ScaleYCoefficient = 0; ShapeManager.AddCircle(mCircle); ShapeManager.AddToLayer(mCircle, mLayer); }
// Generated AddToManagers public virtual void ReAddToManagers(Layer layerToAddTo) { LayerProvidedByContainer = layerToAddTo; SpriteManager.AddPositionedObject(this); TextManager.AddToLayer(TextInstance, LayerProvidedByContainer); if (TextInstance.Font != null) { TextInstance.SetPixelPerfectScale(LayerProvidedByContainer); } SpriteManager.AddToLayer(SpriteInstance, LayerProvidedByContainer); ShapeManager.AddToLayer(mCollision, LayerProvidedByContainer); }
public override void UpdateShapes() { base.UpdateShapes(); if (Visible == false) { while (mOccupiedTileCircles.Count != 0) { ShapeManager.Remove(mOccupiedTileCircles[mOccupiedTileCircles.Count - 1]); } } else { // Remove circles if necessary while (mOccupiedTileCircles.Count > mOccupiedTiles.Count) { ShapeManager.Remove(mOccupiedTileCircles.Last); } while (mOccupiedTileCircles.Count < mOccupiedTiles.Count) { Circle circle = new Circle(); circle.Color = Color.Orange; ShapeManager.AddToLayer(circle, LayerToDrawOn); mOccupiedTileCircles.Add(circle); } for (int i = 0; i < mOccupiedTiles.Count; i++) { IndexToWorld(mOccupiedTiles[i].X, mOccupiedTiles[i].Y, out mOccupiedTileCircles[i].Position.X, out mOccupiedTileCircles[i].Position.Y); mOccupiedTileCircles[i].Radius = OccupiedCircleRadius; } } }
/// <summary> /// Creates a runtime object and adds the LoadedFile to the element. /// </summary> /// <param name="objectToLoad"></param> /// <param name="container"></param> /// <param name="elementRuntime"></param> /// <param name="objectType"></param> /// <param name="objectJustLoaded"></param> /// <param name="newElementRuntime"></param> /// <param name="toAddTo"></param> /// <param name="layerToAddTo"></param> /// <param name="rfs"></param> /// <param name="pullsFromEntireNamedObject"></param> /// <returns></returns> private static LoadedFile CreateRuntimeObjectForNamedObject(NamedObjectSave objectToLoad, IElement container, ElementRuntime elementRuntime, string objectType, LoadedFile objectJustLoaded, ElementRuntime newElementRuntime, object toAddTo, Layer layerToAddTo, ReferencedFileSave rfs, bool pullsFromEntireNamedObject) { var fileName = ElementRuntime.ContentDirectory + objectToLoad.SourceFile; bool shouldClone = rfs != null && (rfs.IsSharedStatic && !(container is ScreenSave)) && !pullsFromEntireNamedObject; LoadedFile toReturn = null; // This could have a ( in the name in a file like .scnx, so use the last ( //int indexOfType = objectToLoad.SourceName.IndexOf("("); int indexOfType = objectToLoad.SourceName.LastIndexOf("("); string objectName = objectToLoad.SourceName.Substring(0, indexOfType - 1); switch (objectType) { case "Scene": { Scene scene = objectJustLoaded.RuntimeObject as Scene; foreach (Text text in scene.Texts) { text.AdjustPositionForPixelPerfectDrawing = true; if (ObjectFinder.Self.GlueProject.UsesTranslation) { text.DisplayText = LocalizationManager.Translate(text.DisplayText); } } if (shouldClone) { scene = scene.Clone(); elementRuntime.EntireScenes.Add(objectToLoad.SourceFile, scene); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = scene; loadedFile.FilePath = objectToLoad.SourceFile; loadedFile.ReferencedFileSave = rfs; toReturn = loadedFile; newElementRuntime.ReferencedFileRuntimeList.Add(loadedFile); scene.AddToManagers(layerToAddTo); } } break; case "Sprite": { Sprite loadedSprite = null; Scene scene = objectJustLoaded.RuntimeObject as Scene; if (scene != null) { loadedSprite = scene.Sprites.FindByName(objectName); } if (loadedSprite == null) { System.Windows.Forms.MessageBox.Show("There is a missing Sprite called\n\n" + objectName + "\n\n" + "in the object\n\n" + elementRuntime.Name + "\n\n" + "This probably happened if someone changed the name of a Sprite in a .scnx file but didn't update " + "the associated object in Glue", "Missing Sprite"); } else { if (shouldClone) { loadedSprite = loadedSprite.Clone(); (toAddTo as Scene).Sprites.Add(loadedSprite); SpriteManager.AddToLayer(loadedSprite, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedSprite; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } } break; case "SpriteFrame": { Scene scene = objectJustLoaded.RuntimeObject as Scene; SpriteFrame loadedSpriteFrame = scene.SpriteFrames.FindByName(objectName); if (loadedSpriteFrame != null) { if (shouldClone) { loadedSpriteFrame = loadedSpriteFrame.Clone(); (toAddTo as Scene).SpriteFrames.Add(loadedSpriteFrame); SpriteManager.AddToLayer(loadedSpriteFrame, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedSpriteFrame; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } } break; case "SpriteGrid": { Scene scene = objectJustLoaded.RuntimeObject as Scene; SpriteGrid spriteGrid = null; for (int i = 0; i < scene.SpriteGrids.Count; i++) { if (scene.SpriteGrids[i].Name == objectName) { spriteGrid = scene.SpriteGrids[i]; break; } } if (spriteGrid != null) { if (shouldClone) { spriteGrid = spriteGrid.Clone(); (toAddTo as Scene).SpriteGrids.Add(spriteGrid); spriteGrid.Layer = layerToAddTo; spriteGrid.PopulateGrid(); spriteGrid.RefreshPaint(); spriteGrid.Manage(); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = spriteGrid; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } } break; case "Text": { Scene scene = objectJustLoaded.RuntimeObject as Scene; Text loadedText = scene.Texts.FindByName(objectName); if (loadedText != null) { if (shouldClone) { loadedText = loadedText.Clone(); (toAddTo as Scene).Texts.Add(loadedText); TextManager.AddToLayer(loadedText, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedText; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } loadedText.AdjustPositionForPixelPerfectDrawing = true; if (LocalizationManager.HasDatabase) { loadedText.DisplayText = LocalizationManager.Translate(loadedText.DisplayText); } } } break; case "ShapeCollection": { ShapeCollection shapeCollection = objectJustLoaded.RuntimeObject as ShapeCollection; if (shouldClone) { shapeCollection = shapeCollection.Clone(); elementRuntime.EntireShapeCollections.Add(objectToLoad.SourceFile, shapeCollection); newElementRuntime.ReferencedFileRuntimeList.LoadedShapeCollections.Add(shapeCollection); shapeCollection.AddToManagers(layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = shapeCollection; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } // Most cases are handled below in an AttachTo method, but // ShapeCollection isn't a PositionedObject so we have to do it manually here if (objectToLoad.AttachToContainer) { shapeCollection.AttachTo(elementRuntime, true); } } break; case "AxisAlignedCube": { ShapeCollection shapeCollection = objectJustLoaded.RuntimeObject as ShapeCollection; AxisAlignedCube loadedAxisAlignedCube = shapeCollection.AxisAlignedCubes.FindByName(objectName); if (shouldClone) { loadedAxisAlignedCube = loadedAxisAlignedCube.Clone(); (toAddTo as ShapeCollection).AxisAlignedCubes.Add(loadedAxisAlignedCube); ShapeManager.AddToLayer(loadedAxisAlignedCube, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedAxisAlignedCube; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "AxisAlignedRectangle": { ShapeCollection shapeCollection = objectJustLoaded.RuntimeObject as ShapeCollection; AxisAlignedRectangle loadedAxisAlignedRectangle = shapeCollection.AxisAlignedRectangles.FindByName(objectName); if (shouldClone) { loadedAxisAlignedRectangle = loadedAxisAlignedRectangle.Clone(); (toAddTo as ShapeCollection).AxisAlignedRectangles.Add(loadedAxisAlignedRectangle); ShapeManager.AddToLayer(loadedAxisAlignedRectangle, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedAxisAlignedRectangle; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "Circle": { ShapeCollection shapeCollection = objectJustLoaded.RuntimeObject as ShapeCollection; Circle loadedCircle = shapeCollection.Circles.FindByName(objectName); if (shouldClone) { loadedCircle = loadedCircle.Clone(); (toAddTo as ShapeCollection).Circles.Add(loadedCircle); ShapeManager.AddToLayer(loadedCircle, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedCircle; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "Polygon": { ShapeCollection shapeCollection = objectJustLoaded.RuntimeObject as ShapeCollection; Polygon loadedPolygon = shapeCollection.Polygons.FindByName(objectName); if (shouldClone) { loadedPolygon = loadedPolygon.Clone(); (toAddTo as ShapeCollection).Polygons.Add(loadedPolygon); ShapeManager.AddToLayer(loadedPolygon, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedPolygon; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "Sphere": { ShapeCollection shapeCollection = objectJustLoaded.RuntimeObject as ShapeCollection; Sphere loadedSphere = shapeCollection.Spheres.FindByName(objectName); if (shouldClone) { loadedSphere = loadedSphere.Clone(); (toAddTo as ShapeCollection).Spheres.Add(loadedSphere); ShapeManager.AddToLayer(loadedSphere, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedSphere; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "Capsule2D": { ShapeCollection shapeCollection = objectJustLoaded.RuntimeObject as ShapeCollection; Capsule2D loadedCapsule2D = shapeCollection.Capsule2Ds.FindByName(objectName); if (shouldClone) { loadedCapsule2D = loadedCapsule2D.Clone(); (toAddTo as ShapeCollection).Capsule2Ds.Add(loadedCapsule2D); ShapeManager.AddToLayer(loadedCapsule2D, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedCapsule2D; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "Emitter": { EmitterList emitterList = objectJustLoaded.RuntimeObject as EmitterList; Emitter loadedEmitter = emitterList.FindByName(objectName); if (shouldClone && loadedEmitter != null) { loadedEmitter = loadedEmitter.Clone(); (toAddTo as EmitterList).Add(loadedEmitter); SpriteManager.AddEmitter(loadedEmitter, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = loadedEmitter; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "EmitterList": { EmitterList emitterList = objectJustLoaded.RuntimeObject as EmitterList; if (shouldClone && emitterList != null) { emitterList = emitterList.Clone(); foreach (var item in emitterList) { SpriteManager.AddEmitter(item); } var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = emitterList; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "NodeNetwork": { NodeNetwork nodeNetwork = objectJustLoaded.RuntimeObject as NodeNetwork; if (shouldClone) { nodeNetwork = nodeNetwork.Clone(); elementRuntime.EntireNodeNetworks.Add(objectToLoad.SourceFile, nodeNetwork); newElementRuntime.ReferencedFileRuntimeList.LoadedNodeNetworks.Add(nodeNetwork); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = nodeNetwork; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "SplineList": { SplineList splineList = objectJustLoaded.RuntimeObject as SplineList; if (shouldClone) { splineList = splineList.Clone(); elementRuntime.EntireSplineLists.Add(splineList.Name, splineList); foreach (var spline in splineList) { spline.CalculateVelocities(); spline.CalculateAccelerations(); } splineList.AddToManagers(); splineList[0].UpdateShapes(); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = splineList; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } } break; case "Spline": { SplineList splineList = objectJustLoaded.RuntimeObject as SplineList; Spline spline = splineList.FirstOrDefault(item => item.Name == objectName); if (shouldClone && spline != null) { spline = spline.Clone(); (toAddTo as SplineList).Add(spline); // Eventually support layers? //ShapeManager.AddToLayer(spline, layerToAddTo); var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = spline; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; } spline.CalculateVelocities(); spline.CalculateAccelerations(); } break; } if (toReturn == null) { foreach (var manager in ReferencedFileRuntimeList.FileManagers) { var objectFromFile = manager.TryGetObjectFromFile(elementRuntime.ReferencedFileRuntimeList.LoadedRfses, rfs, objectType, objectName); if (objectFromFile != null) { var runtimeObject = objectFromFile; var loadedFile = new LoadedFile(); loadedFile.RuntimeObject = runtimeObject; loadedFile.FilePath = objectJustLoaded.FilePath; loadedFile.DataModel = objectJustLoaded.DataModel; loadedFile.ReferencedFileSave = objectJustLoaded.ReferencedFileSave; toReturn = loadedFile; break; } } } if (toReturn != null && objectToLoad.AttachToContainer) { if (toReturn.RuntimeObject is PositionedObject) { // If the object is already attached to something, that means it // came from a file, so we don't want to re-attach it. PositionedObject asPositionedObject = toReturn.RuntimeObject as PositionedObject; if (asPositionedObject.Parent == null) { asPositionedObject.AttachTo(elementRuntime, true); } } else if (toReturn.RuntimeObject is Scene) { ((Scene)toReturn.RuntimeObject).AttachAllDetachedTo(elementRuntime, true); } else if (toReturn.RuntimeObject is ShapeCollection) { ((ShapeCollection)toReturn.RuntimeObject).AttachAllDetachedTo(elementRuntime, true); } } return(toReturn); }
/// <summary> /// Updates the visible representation of the NodeNetwork. This is only needed to be called if the NodeNetwork /// is visible and if any contained PositionedNodes or Links have changed. /// </summary> public virtual void UpdateShapes() { Vector3 zeroVector = new Vector3(); if (mVisible == false) { while (mNodeVisibleRepresentation.Count != 0) { ShapeManager.Remove(mNodeVisibleRepresentation[mNodeVisibleRepresentation.Count - 1]); } while (mLinkVisibleRepresentation.Count != 0) { ShapeManager.Remove(mLinkVisibleRepresentation[mLinkVisibleRepresentation.Count - 1]); } } else { #region Create nodes to match how many nodes are in the network while (mNodes.Count > mNodeVisibleRepresentation.Count) { Polygon newPolygon = Polygon.CreateEquilateral(4, 1, MathHelper.PiOver4); newPolygon.Name = "NodeNetwork Polygon"; const bool makeAutomaticallyUpdated = false; ShapeManager.AddToLayer(newPolygon, LayerToDrawOn, makeAutomaticallyUpdated); // This was commented out and I'm not sure why. With this // uncommented, it makes it so the NodeNetwork is never drawn. // I discovered this while working on the AIEditor on Sept 22, 2010. newPolygon.Visible = true; newPolygon.Color = mNodeColor; mNodeVisibleRepresentation.Add(newPolygon); } #endregion #region Remove nodes if there are too many while (mNodes.Count < mNodeVisibleRepresentation.Count) { ShapeManager.Remove(mNodeVisibleRepresentation[mNodeVisibleRepresentation.Count - 1]); } #endregion #region Create/update links and update node positions int nextLine = 0; //List<PositionedNode> nodesAlreadyLinkedTo = new List<PositionedNode>(); for (int i = 0; i < mNodes.Count; i++) { mNodeVisibleRepresentation[i].Position = mNodes[i].Position; mNodeVisibleRepresentation[i].ScaleBy( GetVisibleNodeRadius(SpriteManager.Camera, i) / mNodeVisibleRepresentation[i].BoundingRadius); mNodeVisibleRepresentation[i].UpdateDependencies(-1, true); foreach (Link link in mNodes[i].mLinks) { #region If this line hasn't been created or updated during this method yet, update it //if (nodesAlreadyLinkedTo.Contains(link.NodeLinkingTo) == false) { // haven't drawn links to this node yet so draw it #region Create a line for this link if there isn't one already if (nextLine >= mLinkVisibleRepresentation.Count) { Line line = new Line(); line.Name = "NodeNetwork Link Line"; mLinkVisibleRepresentation.Add(line); const bool makeAutomaticallyUpdated = false; ShapeManager.AddToLayer(line, LayerToDrawOn, makeAutomaticallyUpdated); //line.Visible = true; } #endregion #region Adjust the line if necessary Line lineModifying = mLinkVisibleRepresentation[nextLine]; nextLine++; lineModifying.SetFromAbsoluteEndpoints( mNodes[i].Position, link.NodeLinkingTo.Position); Vector3 offsetVector = link.NodeLinkingTo.Position - mNodes[i].Position; offsetVector.Normalize(); offsetVector *= mLinkPerpendicularOffset; // A negative 90 degree rotation will result in forward being "on the right side" MathFunctions.RotatePointAroundPoint(zeroVector, ref offsetVector, -(float)System.Math.PI / 2.0f); lineModifying.Position += offsetVector; //lineModifying.Position.X = (mNodes[i].X + link.NodeLinkingTo.X) / 2.0f; //lineModifying.Position.Y = (mNodes[i].Y + link.NodeLinkingTo.Y) / 2.0f; //lineModifying.RelativePoint1.X = mNodes[i].X - lineModifying.X; //lineModifying.RelativePoint1.Y = mNodes[i].Y - lineModifying.Y; //lineModifying.RelativePoint2.X = link.NodeLinkingTo.X - lineModifying.X; //lineModifying.RelativePoint2.Y = link.NodeLinkingTo.Y - lineModifying.Y; UpdateLinkColor(lineModifying, link.Cost); #endregion } #endregion } //nodesAlreadyLinkedTo.Add(mNodes[i]); } #endregion while (nextLine < mLinkVisibleRepresentation.Count) { ShapeManager.Remove(mLinkVisibleRepresentation[mLinkVisibleRepresentation.Count - 1]); } } }
private void UpdateGrid() { #region Make sure there are enough horizontal lines while (mHorizontalLines.Count < mNumberOfHorizontalLines) { Line newLine = new Line(); if (mLayer != null) { ShapeManager.AddToLayer(newLine, mLayer, false); } mHorizontalLines.Add(newLine); } while (mHorizontalLines.Count > mNumberOfHorizontalLines) { ShapeManager.Remove(mHorizontalLines.Last); } #endregion #region Make sure there are enough vertical lines while (mVerticalLines.Count < mNumberOfVerticalLines) { Line newLine = new Line(); if (mLayer != null) { ShapeManager.AddToLayer(newLine, mLayer, false); } mVerticalLines.Add(newLine); } while (mVerticalLines.Count > mNumberOfVerticalLines) { ShapeManager.Remove(mVerticalLines.Last); } #endregion #region Get top, bottom, left, right of LineGrid float bottom = mY - mDistanceBetweenLines * (mNumberOfHorizontalLines - 1) / 2.0f; float top = mY + mDistanceBetweenLines * (mNumberOfHorizontalLines - 1) / 2.0f; float left = mX - mDistanceBetweenLines * (mNumberOfVerticalLines - 1) / 2.0f; float right = mX + mDistanceBetweenLines * (mNumberOfVerticalLines - 1) / 2.0f; #endregion #region Position, color, and scale the horizontal lines for (int i = 0; i < mNumberOfHorizontalLines; i++) { mHorizontalLines[i].X = mX; mHorizontalLines[i].Y = bottom + i * mDistanceBetweenLines; mHorizontalLines[i].Z = mZ; mHorizontalLines[i].RelativePoint1.X = left - mX; mHorizontalLines[i].RelativePoint1.Y = 0; mHorizontalLines[i].RelativePoint2.X = right - mX; mHorizontalLines[i].RelativePoint2.Y = 0; if (i == mNumberOfHorizontalLines / 2) { mHorizontalLines[i].Color = CenterLineColor; } else { mHorizontalLines[i].Color = GridColor; } } #endregion #region Position, color, and scale the vertical lines for (int i = 0; i < mNumberOfVerticalLines; i++) { mVerticalLines[i].X = left + i * mDistanceBetweenLines;; mVerticalLines[i].Y = mY; mVerticalLines[i].Z = mZ; mVerticalLines[i].RelativePoint1.X = 0; mVerticalLines[i].RelativePoint1.Y = bottom - mY; mVerticalLines[i].RelativePoint2.X = 0; mVerticalLines[i].RelativePoint2.Y = top - mY; if (i == mNumberOfVerticalLines / 2) { mVerticalLines[i].Color = CenterLineColor; } else { mVerticalLines[i].Color = GridColor; } } #endregion UpdateVisibility(); }
private object CreateFlatRedBallTypeNos(NamedObjectSave namedObjectSave, PositionedObjectList <ElementRuntime> listToPopulate, Layer layerToPutOn) { object returnObject = null; ElementRuntime newElementRuntime = null; switch (namedObjectSave.SourceClassType) { case "Layer": case "FlatRedBall.Graphics.Layer": returnObject = CreateLayerObject(namedObjectSave, returnObject); break; case "AxisAlignedRectangle": case "FlatRedBall.Math.Geometry.AxisAlignedRectangle": AxisAlignedRectangle aaRectangle = ShapeManager.AddAxisAlignedRectangle(); if (layerToPutOn != null) { ShapeManager.AddToLayer(aaRectangle, layerToPutOn); } aaRectangle.Name = namedObjectSave.InstanceName; returnObject = aaRectangle; break; case "Camera": case "FlatRedBall.Camera": if (namedObjectSave.IsNewCamera) { returnObject = null; } else { returnObject = SpriteManager.Camera; } break; case "Circle": case "FlatRedBall.Math.Geometry.Circle": Circle circle = ShapeManager.AddCircle(); circle.Name = namedObjectSave.InstanceName; if (layerToPutOn != null) { ShapeManager.AddToLayer(circle, layerToPutOn); } returnObject = circle; break; case "Polygon": case "FlatRedBall.Math.Geometry.Polygon": Polygon polygon = ShapeManager.AddPolygon(); polygon.Name = namedObjectSave.InstanceName; if (layerToPutOn != null) { ShapeManager.AddToLayer(polygon, layerToPutOn); } returnObject = polygon; break; case "Sprite": case "FlatRedBall.Sprite": Sprite sprite = SpriteManager.AddSprite((Texture2D)null); if (layerToPutOn != null) { SpriteManager.AddToLayer(sprite, layerToPutOn); } sprite.Name = namedObjectSave.InstanceName; returnObject = sprite; break; case "SpriteFrame": case "FlatRedBall.ManagedSpriteGroups.SpriteFrame": SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All); if (layerToPutOn != null) { SpriteManager.AddToLayer(spriteFrame, layerToPutOn); } spriteFrame.Name = namedObjectSave.InstanceName; returnObject = spriteFrame; break; case "Text": case "FlatRedBall.Graphics.Text": Text text = TextManager.AddText(""); if (layerToPutOn != null) { TextManager.AddToLayer(text, layerToPutOn); text.SetPixelPerfectScale(layerToPutOn); } text.Name = namedObjectSave.InstanceName; returnObject = text; break; case "Scene": case "FlatRedBall.Scene": Scene scene = new Scene(); scene.Name = namedObjectSave.InstanceName; returnObject = scene; break; default: // do nothing - need to add more types? break; } if (returnObject != null) { if (returnObject is IScalable) { newElementRuntime = new ScalableElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet); } else { newElementRuntime = new ElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet); } newElementRuntime.mDirectObjectReference = returnObject; if (returnObject is Camera && !namedObjectSave.IsNewCamera) { SpriteManager.Camera.AttachTo(newElementRuntime, false); SpriteManager.Camera.RelativePosition = Vector3.Zero; newElementRuntime.Z = 40; newElementRuntime.Name = namedObjectSave.InstanceName; } else if (returnObject is FlatRedBall.Utilities.INameable) { newElementRuntime.Name = ((FlatRedBall.Utilities.INameable)returnObject).Name; } else { object nameValueAsObject; if (LateBinder.TryGetValueStatic(returnObject, "Name", out nameValueAsObject)) { newElementRuntime.Name = (string)nameValueAsObject; } } listToPopulate.Add(newElementRuntime); } return(returnObject); }