public void AttachTo(SpriteGrid parentSpriteGrid) { mParentSpriteGrid = parentSpriteGrid; if (mParentSpriteGrid != null) { SetLinePolygonPositions(); /* * for (int i = 0; i < 4; i++) * { * mCornerHandles[i].ScaleBy( * (mCornerHandles[i].Z - camera.Z) / * (200*(mCornerHandles[i].X - mCornerHandles[i].Points[0].X)) * ); * * mSideHandles[i].ScaleBy( * (mSideHandles[i].Z - camera.Z) / * (200 * (mSideHandles[i].X - mSideHandles[i].Points[0].X)) * ); * }*/ Visible = true; } else { Visible = false; } }
public FlatRedBall.ManagedSpriteGroups.SpriteGrid ToSpriteGrid(Camera camera, string contentManagerName) // where SpriteGridType : FlatRedBall.ManagedSpriteGroups.SpriteGrid, new() { FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane plane = GetPlaneFromAxis(); // Since the TextureGrid is passed as an argument in the constructor of the SpriteGrid, it // needs to be created before the SpriteGrid is initialized TextureGrid <Texture2D> textureGrid = CreateTextureGrid(contentManagerName); FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid = new FlatRedBall.ManagedSpriteGroups.SpriteGrid( camera, plane, this.Blueprint.ToSprite(contentManagerName), textureGrid); CreateAnimationChainGrid(contentManagerName, spriteGrid); CreateDisplayRegionGrid(spriteGrid); spriteGrid.Name = this.Name; SetBoundsValues(spriteGrid); spriteGrid.GridSpacing = GridSpacing; SetOrderingMode(spriteGrid); spriteGrid.CreatesAutomaticallyUpdatedSprites = CreatesAutomaticallyUpdatedSprites; spriteGrid.CreatesParticleSprites = CreatesParticleSprites; //spriteGrid.DrawDefaultTileNoPopulate = DrawDefaultTile; return(spriteGrid); // do we need this line? // lastBlueprintPosition = Blueprint.ToVector3(); }
private void SetBoundsValues(FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid) { spriteGrid.XLeftBound = XLeftBound; spriteGrid.XRightBound = XRightBound; spriteGrid.YTopBound = YTopBound; spriteGrid.YBottomBound = YBottomBound; spriteGrid.ZCloseBound = ZCloseBound; spriteGrid.ZFarBound = ZFarBound; }
private static bool DoBoundsOverlapSprites(SpriteGrid spriteGrid) { return(spriteGrid.FurthestTopY > spriteGrid.YTopBound || spriteGrid.FurthestBottomY < spriteGrid.YBottomBound || spriteGrid.FurthestLeftX < spriteGrid.XLeftBound || spriteGrid.FurthestRightX > spriteGrid.XRightBound || spriteGrid.FurthestTopY < spriteGrid.FurthestBottomY || spriteGrid.FurthestRightX < spriteGrid.FurthestLeftX); }
private void CreateAnimationChainGrid(string contentManagerName, FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid) { #region Create the AnimationChainGrid if (AnimationChainGridSave != null) { TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> animationChainGrid = AnimationChainGridSave.ToAnimationChainGrid(contentManagerName, GridSpacing); spriteGrid.AnimationChainGrid = animationChainGrid; } #endregion }
private void AddSpriteGridsToScene(string contentManagerName, FlatRedBall.Scene scene, SceneSettingOptions options) { foreach (SpriteGridSave spriteGridSave in SpriteGridList) { // for now just use the default camera and create a new Random - not sure if user ever needs // to specify the Random to use - perhaps for multiplayer games and SpriteGrids which are using AnimationChains FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid = spriteGridSave.ToSpriteGrid( SpriteManager.Camera, contentManagerName); scene.SpriteGrids.Add(spriteGrid); } bool hasFlag = (options & SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids) == SceneSettingOptions.ConvertZSeparatedSpritesIntoSpriteGrids; if (hasFlag) { Dictionary <int, FlatRedBall.ManagedSpriteGroups.SpriteGrid> spriteGrids = new Dictionary <int, FlatRedBall.ManagedSpriteGroups.SpriteGrid>(); foreach (SpriteSave spriteSave in this.SpriteList) { FloatRectangle floatRectangle = new FloatRectangle(); int zAsInt = MathFunctions.RoundToInt(spriteSave.Z); if (spriteGrids.ContainsKey(zAsInt) == false) { var newGrid = new ManagedSpriteGroups.SpriteGrid(SpriteManager.Camera, ManagedSpriteGroups.SpriteGrid.Plane.XY, spriteSave.ToSprite(contentManagerName)); spriteGrids.Add(zAsInt, newGrid); scene.SpriteGrids.Add(newGrid); } var spriteGrid = spriteGrids[zAsInt]; spriteGrid.XLeftBound = System.Math.Min(spriteGrid.XLeftBound, spriteSave.X - spriteSave.ScaleX * 2); spriteGrid.YBottomBound = System.Math.Min(spriteGrid.YBottomBound, spriteSave.Y - spriteSave.ScaleY * 2); spriteGrid.XRightBound = System.Math.Max(spriteGrid.XRightBound, spriteSave.X + spriteSave.ScaleX * 2); spriteGrid.YTopBound = System.Math.Max(spriteGrid.YTopBound, spriteSave.Y + spriteSave.ScaleY * 2); spriteGrid.PaintSprite(spriteSave.X, spriteSave.Y, spriteSave.Z, FlatRedBallServices.Load <Texture2D>(spriteSave.Texture)); floatRectangle.Left = spriteSave.LeftTextureCoordinate; floatRectangle.Right = spriteSave.RightTextureCoordinate; floatRectangle.Top = spriteSave.TopTextureCoordinate; floatRectangle.Bottom = spriteSave.BottomTextureCoordinate; spriteGrid.PaintSpriteDisplayRegion(spriteSave.X, spriteSave.Y, spriteSave.Z, ref floatRectangle); } } }
private void SetOrderingMode(FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid) { #if FRB_MDX spriteGrid.Blueprint.mOrdered = this.Blueprint.Ordered; #endif if (this.Blueprint.Ordered) { spriteGrid.OrderingMode = FlatRedBall.Graphics.OrderingMode.DistanceFromCamera; } else { spriteGrid.OrderingMode = FlatRedBall.Graphics.OrderingMode.ZBuffered; } }
public void spriteGridArrayLogic() { if (GameData.EditorProperties.CullSpriteGrids == true) { for (int i = 0; i < GameData.Scene.SpriteGrids.Count; i++) { SpriteGrid sg = GameData.Scene.SpriteGrids[i]; sg.Manage(); if (!sg.CreatesAutomaticallyUpdatedSprites) { sg.ManualAnimationUpdate(); } } } }
void MakeAllSpriteGridsCreateParticleSpriteClick(Window callingWindow) { int numberConverted = 0; for (int i = 0; i < GameData.Scene.SpriteGrids.Count; i++) { SpriteGrid spriteGrid = GameData.Scene.SpriteGrids[i]; if (!spriteGrid.CreatesParticleSprites) { spriteGrid.CreatesParticleSprites = true; numberConverted++; } } GuiManager.ShowMessageBox("Converted " + numberConverted + " SpriteGrids", "Conversion Complete"); }
public void DeleteGrid(SpriteGrid gridToDelete) { if (gridToDelete == null) { int m = 3; } gridToDelete.Destroy(); GameData.Scene.SpriteGrids.Remove(gridToDelete); if (gridToDelete == CurrentSpriteGrid) { GameData.DeselectCurrentSprites(); mSpriteGridBorder.AttachTo(null); CurrentSpriteGrid = null; } }
private void CreateDisplayRegionGrid(FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid) { #region Create the DisplayRegionGrid if (DisplayRegionGridSave != null) { TextureGrid <FloatRectangle> displayRegionGrid = DisplayRegionGridSave.ToDisplayRegionGrid(GridSpacing); if (displayRegionGrid.BaseTexture == null) { displayRegionGrid.BaseTexture = new FloatRectangle( spriteGrid.Blueprint.TopTextureCoordinate, spriteGrid.Blueprint.BottomTextureCoordinate, spriteGrid.Blueprint.LeftTextureCoordinate, spriteGrid.Blueprint.RightTextureCoordinate); } spriteGrid.DisplayRegionGrid = displayRegionGrid; } #endregion }
/// <summary> /// Deselects the grid on the list window and returns whether to ask to keep changes /// </summary> /// <remarks> /// When either a new SpriteGrid or a different Sprite in the same SpriteGrid is selected, /// the ShouldAskUserIfChangesShouldBeApplied() method must be called. This /// method does not deselect the currentSpriteGrid, but returns whether changes /// have been made so that the /// code calling this method can store the newly-selected Sprite and SpriteGrid /// in the newlySelectedCurrentSprite and newlySelectedCurrentSpriteGrid variables. /// /// For this, this method is private and only called from within this class. To deselect /// a grid from outside of this class, call clickGrid(null, null). /// </remarks> /// <param name="tempSpriteGridGrabbed"></param> /// <param name="tempSpriteGrabbed"></param> /// <returns>Whether the currentSpriteGrid has been changed</returns> #endregion private bool ShouldAskUserIfChangesShouldBeApplied(SpriteGrid tempSpriteGridGrabbed, Sprite tempSpriteGrabbed) { GuiData.ToolsWindow.convertToSpriteGridButton.Enabled = false; if (tempSpriteGridGrabbed == null) { GuiData.ListWindow.SpriteGridListBox.HighlightItem(null, false); } #region we clicked, but already have a different Sprite selected on a grid if (CurrentSpriteGrid != null && (GameData.EditorLogic.CurrentSprites.Count == 0 || tempSpriteGrabbed != GameData.EditorLogic.CurrentSprites[0])) { if (GameData.EditorLogic.CurrentSprites.Count != 0 && HasBlueprintChanged()) { /* There SpriteGrid that has the Sprite being deselected has been changed. * Need to store the new Sprite in newlySelectedCurrentSprite and * SpriteGrid in newlySelectedCurrentSpriteGrid and hold on to the current Sprite/ * SpriteGrid so that the changes can be applied if the user chooses to do so * through the OKCancelWindow that is being created */ return(true); } else { return(false); } } #endregion #region if we clicked on a sprite and didn't have a grid selected before else if (tempSpriteGridGrabbed != null && oldPosition == Vector3.Empty) { return(false); } #endregion return(false); }
public void PopulateAndAddGridToEngine(SpriteGrid gridToAdd, Sprite spriteToUseAsPopulationSource) { #region select the base point for population and populate the grid if (gridToAdd.GridPlane == SpriteGrid.Plane.XY) { gridToAdd.PopulateGrid(camera.X, camera.Y, spriteToUseAsPopulationSource.Z); } else { gridToAdd.PopulateGrid(camera.X, spriteToUseAsPopulationSource.Y, spriteToUseAsPopulationSource.Z); } #endregion GameData.Scene.SpriteGrids.Add(gridToAdd); /* When converting a Sprite to a SpriteGrid, the editGrids is not pressed * (yet) when this method is called. Therefore, if the editGrids button * is not pressed, then the grid was created from the currentSprite, so * the currentSprite should be deleted. * * If it is pressed, the Grid has been created from a CTRL+C command * (copying a SpriteGrid). In that case, no deleting of currentSprites * should be executed. */ if (!SpriteEditorSettings.EditingSpriteGrids && spriteToUseAsPopulationSource != null) { SpriteManager.RemoveSprite(spriteToUseAsPopulationSource); } this.ClickGrid(gridToAdd, null); }
public void ClickGrid(SpriteGrid gridClicked, Sprite spriteClicked) { #region if eyedropper is pressed, don't select the grid, just grab the texture if (GuiData.ToolsWindow.eyedropper.IsPressed) { GameData.Cursor.ClickSprite(spriteClicked); } #endregion #region Select the grid - eyedropper is not down else { newlySelectedCurrentSprite = null; newlySelectedCurrentSpriteGrid = null; #region if selecting a new grid, not painting, and changes have been made if ((gridClicked != CurrentSpriteGrid || currentSprites.Contains(spriteClicked) == false || spriteClicked == null) && GuiData.ToolsWindow.paintButton.IsPressed == false && ShouldAskUserIfChangesShouldBeApplied(gridClicked, spriteClicked)) { // The user may have changed the texture coordinates on the // selected Sprite. This should result in the new texture coordinates // being "painted" on the SpriteGrid at the given location. PaintTextureCoordinatesOnCurrentSpriteInGrid(); newlySelectedCurrentSprite = spriteClicked; newlySelectedCurrentSpriteGrid = gridClicked; AskIfChangesShouldBeApplied(null); } #endregion #region else, do not need to ask if changes should be applied else { if (GuiData.ToolsWindow.paintButton.IsPressed == false && GameData.EditorLogic.CurrentSprites.Contains(spriteClicked) == false) { if (spriteClicked != null) oldPosition = spriteClicked.Position; else oldPosition = Vector3.Empty; PaintTextureCoordinatesOnCurrentSpriteInGrid(); } if (CurrentSpriteGrid != gridClicked) GameData.DeselectCurrentSprites(); CurrentSpriteGrid = gridClicked; // attach the grid border mSpriteGridBorder.AttachTo(CurrentSpriteGrid); GameData.Cursor.ClickSprite(spriteClicked); SpriteGridGrabbed = gridClicked; mSpriteGrabbed = spriteClicked; if (gridClicked != null) { UndoManager.AddToWatch<Sprite>(gridClicked.Blueprint); UndoManager.AddToWatch<SpriteGrid>(gridClicked); } GuiData.ListWindow.SpriteGridListBox.HighlightObject(gridClicked, false); } #endregion cursor.ObjectGrabbed = spriteClicked; if (gridClicked == null) return; #region Change the convert to sprite grid button to "Modify Sprite Grid" GuiData.ToolsWindow.convertToSpriteGridButton.Enabled = true; GuiData.ToolsWindow.convertToSpriteGridButton.Text = "Modify Sprite Grid"; #endregion } #endregion }
public void grabGridSprite() { if (GameData.EditorLogic.EditAxes.CursorPushedOnAxis == true || GuiManager.DominantWindowActive) { return; } #region checking to see which sprite we are over, considering double clicking and current sprite selected // this is a temporary Sprite that we will use Sprite tempSpriteGrabbed = null; SpriteGrid tempSpriteGridGrabbed = null; // first see if we are over the current Sprite. It has prescedence over the other sprites if (GameData.EditorLogic.CurrentSprites.Count != 0 && GameData.Cursor.IsOn3D(GameData.EditorLogic.CurrentSprites[0]) == true) { tempSpriteGrabbed = GameData.EditorLogic.CurrentSprites[0]; } // if not over the current Sprite, or there is no currentSprite, see if over any Sprites in the current grid if (tempSpriteGrabbed == null && CurrentSpriteGrid != null) { tempSpriteGrabbed = cursor.GetSpriteOver(CurrentSpriteGrid.VisibleSprites); } // if we are not over our current Sprite, we need to see if we are over any other sprites if (tempSpriteGrabbed == null) { tempSpriteGrabbed = GameData.Cursor.GetSpriteOver(GameData.Scene.SpriteGrids); if (tempSpriteGrabbed != null) { tempSpriteGridGrabbed = null; foreach (SpriteGrid spriteGrid in GameData.Scene.SpriteGrids) { foreach (var list in spriteGrid.VisibleSprites) { if (list.Contains(tempSpriteGrabbed)) { tempSpriteGridGrabbed = spriteGrid; break; } } if (tempSpriteGridGrabbed != null) { break; } } } } else { tempSpriteGridGrabbed = CurrentSpriteGrid; } #endregion #region Push either mouse button or double clicked, call click sprite, grab or attach, and update stored variables for old sprite if (cursor.PrimaryPush || cursor.SecondaryPush || cursor.PrimaryDoubleClick) { // we already know if we are over a Sprite. If we have clicked with either mouse button or double clicked with the primary // then we can call click sprite // store the last currentSprite, because we need to update stored variables of the old Sprite if we select a new one Sprite lastCurrentSprite; SpriteGrid lastCurrentGrid; if (currentSprites.Count != 0) { lastCurrentSprite = currentSprites[0]; } else { lastCurrentSprite = null; } lastCurrentGrid = CurrentSpriteGrid; if (newlySelectedCurrentSpriteGrid == null) { ClickGrid(tempSpriteGridGrabbed, tempSpriteGrabbed); } } #endregion #region if the mouse button is held down - Painting if (CurrentSpriteGrid != null && GuiData.ToolsWindow.paintButton.IsPressed && (GuiData.ListWindow.HighlightedAnimationChain != null || GuiData.ListWindow.HighlightedTexture != null)) { PaintSpriteGrid(tempSpriteGrabbed); } #endregion #region we released the mouse the mouse, so release any sprite grabbed if (cursor.PrimaryClick) { if (mSpriteGrabbed != null) { UndoManager.RecordUndos <Sprite>(); // Vic says - Because of the way the UndoManager works // I can only attach the recreation of the grid to the undos // for the SpriteGrid and not the Blueprint Sprite...however, // the reason we need to recreate the SpriteGrid is because the // Blueprint values might change from an undo. // That means that the blueprint undos should come first, then the // SpriteGrid undos so that they use the proper values. To do this // we simply need to record the undos of the blueprint first. bool createNewList = false; // Makes it so one undo will record everything UndoManager.RecordUndos <SpriteGrid>(createNewList); UndoManager.ClearObjectsWatching <SpriteGrid>(); UndoManager.ClearObjectsWatching <Sprite>(); } SpriteGridGrabbed = null; mSpriteGrabbed = null; } #endregion }
public void AttachTo(SpriteGrid parentSpriteGrid) { mParentSpriteGrid = parentSpriteGrid; if (mParentSpriteGrid != null) { SetLinePolygonPositions(); /* for (int i = 0; i < 4; i++) { mCornerHandles[i].ScaleBy( (mCornerHandles[i].Z - camera.Z) / (200*(mCornerHandles[i].X - mCornerHandles[i].Points[0].X)) ); mSideHandles[i].ScaleBy( (mSideHandles[i].Z - camera.Z) / (200 * (mSideHandles[i].X - mSideHandles[i].Points[0].X)) ); }*/ Visible = true; } else { Visible = false; } }
private static bool DoBoundsOverlapSprites(SpriteGrid spriteGrid) { return spriteGrid.FurthestTopY > spriteGrid.YTopBound || spriteGrid.FurthestBottomY < spriteGrid.YBottomBound || spriteGrid.FurthestLeftX < spriteGrid.XLeftBound || spriteGrid.FurthestRightX > spriteGrid.XRightBound || spriteGrid.FurthestTopY < spriteGrid.FurthestBottomY || spriteGrid.FurthestRightX < spriteGrid.FurthestLeftX; }
/// <summary> /// Deselects the grid on the list window and returns whether to ask to keep changes /// </summary> /// <remarks> /// When either a new SpriteGrid or a different Sprite in the same SpriteGrid is selected, /// the ShouldAskUserIfChangesShouldBeApplied() method must be called. This /// method does not deselect the currentSpriteGrid, but returns whether changes /// have been made so that the /// code calling this method can store the newly-selected Sprite and SpriteGrid /// in the newlySelectedCurrentSprite and newlySelectedCurrentSpriteGrid variables. /// /// For this, this method is private and only called from within this class. To deselect /// a grid from outside of this class, call clickGrid(null, null). /// </remarks> /// <param name="tempSpriteGridGrabbed"></param> /// <param name="tempSpriteGrabbed"></param> /// <returns>Whether the currentSpriteGrid has been changed</returns> #endregion private bool ShouldAskUserIfChangesShouldBeApplied(SpriteGrid tempSpriteGridGrabbed, Sprite tempSpriteGrabbed) { GuiData.ToolsWindow.convertToSpriteGridButton.Enabled = false; if(tempSpriteGridGrabbed == null) { GuiData.ListWindow.SpriteGridListBox.HighlightItem(null, false); } #region we clicked, but already have a different Sprite selected on a grid if(CurrentSpriteGrid != null && (GameData.EditorLogic.CurrentSprites.Count == 0 || tempSpriteGrabbed != GameData.EditorLogic.CurrentSprites[0])) { if(GameData.EditorLogic.CurrentSprites.Count != 0 && HasBlueprintChanged()) { /* There SpriteGrid that has the Sprite being deselected has been changed. * Need to store the new Sprite in newlySelectedCurrentSprite and * SpriteGrid in newlySelectedCurrentSpriteGrid and hold on to the current Sprite/ * SpriteGrid so that the changes can be applied if the user chooses to do so * through the OKCancelWindow that is being created */ return true; } else { return false; } } #endregion #region if we clicked on a sprite and didn't have a grid selected before else if(tempSpriteGridGrabbed != null && oldPosition == Vector3.Empty) { return false; } #endregion return false; }
public void PopulateAndAddGridToEngine(SpriteGrid gridToAdd, Sprite spriteToUseAsPopulationSource) { #region select the base point for population and populate the grid if (gridToAdd.GridPlane == SpriteGrid.Plane.XY) { gridToAdd.PopulateGrid(camera.X, camera.Y, spriteToUseAsPopulationSource.Z); } else { gridToAdd.PopulateGrid(camera.X, spriteToUseAsPopulationSource.Y, spriteToUseAsPopulationSource.Z); } #endregion GameData.Scene.SpriteGrids.Add(gridToAdd); /* When converting a Sprite to a SpriteGrid, the editGrids is not pressed * (yet) when this method is called. Therefore, if the editGrids button * is not pressed, then the grid was created from the currentSprite, so * the currentSprite should be deleted. * * If it is pressed, the Grid has been created from a CTRL+C command * (copying a SpriteGrid). In that case, no deleting of currentSprites * should be executed. */ if ( !SpriteEditorSettings.EditingSpriteGrids && spriteToUseAsPopulationSource != null) { SpriteManager.RemoveSprite(spriteToUseAsPopulationSource); } this.ClickGrid(gridToAdd, null); }
private void RepopulateSpriteGrid(object spriteGrid) { SpriteGrid asSpriteGrid = spriteGrid as SpriteGrid; asSpriteGrid.PopulateGrid(); }
public void PerformLoadScn(string fileName, bool replace) { // This method is public because this method is called if the user drags a // .scnx onto the SpriteEditor #region Mark how many objects before loading in case there is an insertion. // If there is an insertion, only the newly-added objects should have post load // logic performed on them int numSpritesBefore = GameData.Scene.Sprites.Count; int numOfSGsBefore = GameData.Scene.SpriteGrids.Count; int numOfSpriteFramesBefore = GameData.Scene.SpriteFrames.Count; int numberOfPositionedModels = GameData.Scene.PositionedModels.Count; #endregion SpriteEditorScene tempSES = SpriteEditorScene.FromFile(fileName); #region See if there are any Models that reference files that aren't on disk string sceneDirectory = FileManager.GetDirectory(fileName); for (int i = 0; i < tempSES.PositionedModelSaveList.Count; i++) { PositionedModelSave modelSave = tempSES.PositionedModelSaveList[i]; if (!FileManager.FileExists(modelSave.ModelFileName)) { // See if there's a .x with that name if (FileManager.FileExists(sceneDirectory + modelSave.ModelFileName + ".x")) { modelSave.ModelFileName = modelSave.ModelFileName + ".x"; } } } #endregion #region Now, see if there are any other files that haven't been found and create the error window List <string> texturesNotFound = tempSES.GetMissingFiles(); if (texturesNotFound.Count != 0) { OkListWindow okListWindow = new OkListWindow( "There are files that the .scnx references which cannot be located.", "Error loading .scnx"); foreach (string file in texturesNotFound) { okListWindow.AddItem(file); } return; } #endregion #region if replacing, clear the old scene out if (replace) { SpriteManager.RemoveScene(GameData.Scene, true); FlatRedBallServices.Unload(GameData.SceneContentManager); tempSES.SetCamera(GameData.Camera); #if FRB_MDX if (tempSES.CoordinateSystem == FlatRedBall.Math.CoordinateSystem.RightHanded) { GameData.Camera.Z *= -1; } #endif GameData.EditorProperties.PixelSize = tempSES.PixelSize; GuiData.EditorPropertiesGrid.Refresh(); // 4/16/2011: The following line of code // was causing errors when saving the .scnx // file through CTRL+S. Taking it out because // I don't see why we need this anyway. // GameData.FileName = FileManager.RemoveExtension(fileName); GameData.FileName = fileName; FlatRedBallServices.Owner.Text = "SpriteEditor - Currently editing " + GameData.FileName; GuiData.MenuStrip.LastFileTypeLoaded = FileManager.GetExtension(fileName); } #endregion Scene newlyLoadedScene = tempSES.ToScene <EditorSprite>(GameData.SceneContentManager); GameData.Scene.AddToThis(newlyLoadedScene); // This caused // a double-add. // Not sure why we're // adding GameData.Scene. //GameData.Scene.AddToManagers(); newlyLoadedScene.AddToManagers(); GuiData.ListWindow.RefreshListsShown(); #region Add the used Textures to the texture ListBox for (int i = numSpritesBefore; i < GameData.Scene.Sprites.Count; i++) { GuiData.ListWindow.Add(GameData.Scene.Sprites[i].Texture); GuiData.ListWindow.Add(GameData.Scene.Sprites[i].AnimationChains); } for (int i = numOfSpriteFramesBefore; i < GameData.Scene.SpriteFrames.Count; i++) { GuiData.ListWindow.Add(GameData.Scene.SpriteFrames[i].Texture); GuiData.ListWindow.Add(GameData.Scene.SpriteFrames[i].AnimationChains); } for (int i = numOfSGsBefore; i < GameData.Scene.SpriteGrids.Count; i++) { SpriteGrid sg = GameData.Scene.SpriteGrids[i]; sg.PopulateGrid(GameData.Camera.X, GameData.Camera.Y, 0f); sg.RefreshPaint(); List <Texture2D> texturesToAdd = sg.GetUsedTextures(); foreach (Texture2D tex in texturesToAdd) { GuiData.ListWindow.Add(tex); } } #endregion CheckForExtraFiles(FileManager.RemoveExtension(fileName)); GameData.Scene.Sprites.SortZInsertionDescending(); if (tempSES.AssetsRelativeToSceneFile) { FileManager.ResetRelativeToCurrentDirectory(); } }
public void grabGridSprite() { if (GameData.EditorLogic.EditAxes.CursorPushedOnAxis == true || GuiManager.DominantWindowActive) return; #region checking to see which sprite we are over, considering double clicking and current sprite selected // this is a temporary Sprite that we will use Sprite tempSpriteGrabbed = null; SpriteGrid tempSpriteGridGrabbed = null; // first see if we are over the current Sprite. It has prescedence over the other sprites if (GameData.EditorLogic.CurrentSprites.Count != 0 && GameData.Cursor.IsOn3D(GameData.EditorLogic.CurrentSprites[0]) == true) tempSpriteGrabbed = GameData.EditorLogic.CurrentSprites[0]; // if not over the current Sprite, or there is no currentSprite, see if over any Sprites in the current grid if (tempSpriteGrabbed == null && CurrentSpriteGrid != null) { tempSpriteGrabbed = cursor.GetSpriteOver(CurrentSpriteGrid.VisibleSprites); } // if we are not over our current Sprite, we need to see if we are over any other sprites if (tempSpriteGrabbed == null) { tempSpriteGrabbed = GameData.Cursor.GetSpriteOver(GameData.Scene.SpriteGrids); if (tempSpriteGrabbed != null) { tempSpriteGridGrabbed = null; foreach (SpriteGrid spriteGrid in GameData.Scene.SpriteGrids) { foreach (var list in spriteGrid.VisibleSprites) { if (list.Contains(tempSpriteGrabbed)) { tempSpriteGridGrabbed = spriteGrid; break; } } if (tempSpriteGridGrabbed != null) { break; } } } } else tempSpriteGridGrabbed = CurrentSpriteGrid; #endregion #region Push either mouse button or double clicked, call click sprite, grab or attach, and update stored variables for old sprite if (cursor.PrimaryPush || cursor.SecondaryPush || cursor.PrimaryDoubleClick) { // we already know if we are over a Sprite. If we have clicked with either mouse button or double clicked with the primary // then we can call click sprite // store the last currentSprite, because we need to update stored variables of the old Sprite if we select a new one Sprite lastCurrentSprite; SpriteGrid lastCurrentGrid; if (currentSprites.Count != 0) lastCurrentSprite = currentSprites[0]; else lastCurrentSprite = null; lastCurrentGrid = CurrentSpriteGrid; if (newlySelectedCurrentSpriteGrid == null) ClickGrid(tempSpriteGridGrabbed, tempSpriteGrabbed); } #endregion #region if the mouse button is held down - Painting if (CurrentSpriteGrid != null && GuiData.ToolsWindow.paintButton.IsPressed && (GuiData.ListWindow.HighlightedAnimationChain != null || GuiData.ListWindow.HighlightedTexture != null)) { PaintSpriteGrid(tempSpriteGrabbed); } #endregion #region we released the mouse the mouse, so release any sprite grabbed if (cursor.PrimaryClick) { if (mSpriteGrabbed != null) { UndoManager.RecordUndos<Sprite>(); // Vic says - Because of the way the UndoManager works // I can only attach the recreation of the grid to the undos // for the SpriteGrid and not the Blueprint Sprite...however, // the reason we need to recreate the SpriteGrid is because the // Blueprint values might change from an undo. // That means that the blueprint undos should come first, then the // SpriteGrid undos so that they use the proper values. To do this // we simply need to record the undos of the blueprint first. bool createNewList = false; // Makes it so one undo will record everything UndoManager.RecordUndos<SpriteGrid>(createNewList); UndoManager.ClearObjectsWatching<SpriteGrid>(); UndoManager.ClearObjectsWatching<Sprite>(); } SpriteGridGrabbed = null; mSpriteGrabbed = null; } #endregion }
public static SpriteGridSave FromSpriteGrid(FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid) { SpriteGridSave spriteGridSave = new SpriteGridSave(); if (spriteGrid.Name != null) { spriteGridSave.Name = spriteGrid.Name; } spriteGridSave.Blueprint = SpriteSave.FromSprite(spriteGrid.Blueprint); #region Set the GridPlane (Axis in SpriteSave) if (spriteGrid.GridPlane == FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane.XY) { spriteGridSave.Axis = 'y'; } else { spriteGridSave.Axis = 'z'; } #endregion // Create new lists here instead of just assigning them (like we used to do) because // the SpriteGridSave will make modifications to these to make file sizes smaller. If // we don't make new lists, then the SpriteGridSave will make modifications to the original // SpriteGrid which causes problems. spriteGridSave.FirstPaintedX = new List <float>(spriteGrid.TextureGrid.FirstPaintedX); spriteGridSave.FirstPaintedY = spriteGrid.TextureGrid.FirstPaintedY; spriteGridSave.GridSpacing = spriteGrid.GridSpacing; // Right now there's no sprite type. Should there be Ordered/Unordered? #region set the bounds spriteGridSave.XRightBound = spriteGrid.XRightBound; spriteGridSave.XLeftBound = spriteGrid.XLeftBound; spriteGridSave.YTopBound = spriteGrid.YTopBound; spriteGridSave.YBottomBound = spriteGrid.YBottomBound; spriteGridSave.ZCloseBound = spriteGrid.ZCloseBound; spriteGridSave.ZFarBound = spriteGrid.ZFarBound; #endregion #region fill up the strings for the FRBTextures if (spriteGrid.TextureGrid.BaseTexture != null) { spriteGridSave.BaseTexture = spriteGrid.TextureGrid.BaseTexture.SourceFile(); } else { spriteGridSave.BaseTexture = ""; } #region Chop off the bottom (or near in XZ) int numberToChopOffBottom = 0; float yValue = spriteGrid.TextureGrid.FirstPaintedY; float bottomBound = spriteGrid.YBottomBound; if (spriteGrid.GridPlane == FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane.XZ) { bottomBound = spriteGrid.ZCloseBound; } // This will usually include one extra row beyond the bounds, but that's ok because // it's possible that someone creates a really weird grid with overlapping Sprites. while (yValue + spriteGrid.GridSpacing / 2.0f < bottomBound) { numberToChopOffBottom++; yValue += spriteGrid.GridSpacing; spriteGridSave.FirstPaintedY += spriteGrid.GridSpacing; if (spriteGridSave.FirstPaintedX.Count == 0) { // we're done here, so exit out break; } else { spriteGridSave.FirstPaintedX.RemoveAt(0); } } #endregion #region Chop off the top (or far in XZ) int numberToChopOffTop = 0; yValue = spriteGrid.TextureGrid.FirstPaintedY + spriteGrid.TextureGrid.FirstPaintedX.Count * spriteGrid.GridSpacing; float topBound = spriteGrid.YTopBound; if (spriteGrid.GridPlane == FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane.XZ) { topBound = spriteGrid.ZFarBound; } while (yValue - spriteGrid.GridSpacing / 2.0f > topBound) { numberToChopOffTop++; yValue -= spriteGrid.GridSpacing; if (spriteGridSave.FirstPaintedX.Count == 0) { break; } else { spriteGridSave.FirstPaintedX.RemoveAt(spriteGridSave.FirstPaintedX.Count - 1); } } #endregion int numberOfGridTextures = spriteGrid.TextureGrid.Textures.Count - numberToChopOffBottom - numberToChopOffTop; numberOfGridTextures = System.Math.Max(numberOfGridTextures, 0); // don't let it be negative spriteGridSave.GridTexturesArray = new string[numberOfGridTextures][]; //GridTextures = new StringArrayArray(); //GridTexturesArray = new string[spriteGrid.textureGrid.textures.Count][]; TextureGrid <Texture2D> textureGrid = spriteGrid.TextureGrid; for (int i = numberToChopOffBottom; i < textureGrid.Textures.Count - numberToChopOffTop; i++) { int numberToChopOffLeft = 0; int numberToChopOffRight = 0; float xValue = textureGrid.FirstPaintedX[i]; while (xValue + spriteGrid.GridSpacingX / 2.0f < spriteGrid.XLeftBound) { xValue += spriteGrid.GridSpacingX; numberToChopOffLeft++; spriteGridSave.FirstPaintedX[i - numberToChopOffBottom] += spriteGrid.GridSpacingX; } xValue = textureGrid.LastPaintedX[i]; while (xValue - spriteGrid.GridSpacingX / 2.0f > spriteGrid.XRightBound) { xValue -= spriteGrid.GridSpacingX; numberToChopOffRight++; } int numberOfTexturesInRow = textureGrid.Textures[i].Count - numberToChopOffLeft - numberToChopOffRight; numberOfTexturesInRow = System.Math.Max(0, numberOfTexturesInRow); spriteGridSave.GridTexturesArray[i - numberToChopOffBottom] = new string[numberOfTexturesInRow]; for (int j = numberToChopOffLeft; j < textureGrid.Textures[i].Count - numberToChopOffRight; j++) { if (textureGrid.Textures[i][j] != null) { spriteGridSave.GridTexturesArray[i - numberToChopOffBottom][j - numberToChopOffLeft] = textureGrid.Textures[i][j].SourceFile(); } else { spriteGridSave.GridTexturesArray[i - numberToChopOffBottom][j - numberToChopOffLeft] = null; } } } #endregion spriteGridSave.AnimationChainGridSave = AnimationChainGridSave.FromAnimationChainGrid( spriteGrid.AnimationChainGrid); spriteGridSave.DisplayRegionGridSave = DisplayRegionGridSave.FromDisplayRegionGrid( spriteGrid.DisplayRegionGrid); #if FRB_XNA spriteGridSave.Blueprint.Ordered = spriteGrid.OrderingMode == FlatRedBall.Graphics.OrderingMode.DistanceFromCamera; #else spriteGridSave.Blueprint.Ordered = spriteGrid.Blueprint.mOrdered; #endif spriteGridSave.CreatesAutomaticallyUpdatedSprites = spriteGrid.CreatesAutomaticallyUpdatedSprites; spriteGridSave.CreatesParticleSprites = spriteGrid.CreatesParticleSprites; //spriteGridSave.DrawDefaultTile = spriteGrid.DrawDefaultTile; //spriteGridSave.DrawableBatch = spriteGrid.DrawableBatch; spriteGridSave.CropOutOfBoundsPaintedSprites(); return(spriteGridSave); }
public void ClickGrid(SpriteGrid gridClicked, Sprite spriteClicked) { #region if eyedropper is pressed, don't select the grid, just grab the texture if (GuiData.ToolsWindow.eyedropper.IsPressed) { GameData.Cursor.ClickSprite(spriteClicked); } #endregion #region Select the grid - eyedropper is not down else { newlySelectedCurrentSprite = null; newlySelectedCurrentSpriteGrid = null; #region if selecting a new grid, not painting, and changes have been made if ((gridClicked != CurrentSpriteGrid || currentSprites.Contains(spriteClicked) == false || spriteClicked == null) && GuiData.ToolsWindow.paintButton.IsPressed == false && ShouldAskUserIfChangesShouldBeApplied(gridClicked, spriteClicked)) { // The user may have changed the texture coordinates on the // selected Sprite. This should result in the new texture coordinates // being "painted" on the SpriteGrid at the given location. PaintTextureCoordinatesOnCurrentSpriteInGrid(); newlySelectedCurrentSprite = spriteClicked; newlySelectedCurrentSpriteGrid = gridClicked; AskIfChangesShouldBeApplied(null); } #endregion #region else, do not need to ask if changes should be applied else { if (GuiData.ToolsWindow.paintButton.IsPressed == false && GameData.EditorLogic.CurrentSprites.Contains(spriteClicked) == false) { if (spriteClicked != null) { oldPosition = spriteClicked.Position; } else { oldPosition = Vector3.Empty; } PaintTextureCoordinatesOnCurrentSpriteInGrid(); } if (CurrentSpriteGrid != gridClicked) { GameData.DeselectCurrentSprites(); } CurrentSpriteGrid = gridClicked; // attach the grid border mSpriteGridBorder.AttachTo(CurrentSpriteGrid); GameData.Cursor.ClickSprite(spriteClicked); SpriteGridGrabbed = gridClicked; mSpriteGrabbed = spriteClicked; if (gridClicked != null) { UndoManager.AddToWatch <Sprite>(gridClicked.Blueprint); UndoManager.AddToWatch <SpriteGrid>(gridClicked); } GuiData.ListWindow.SpriteGridListBox.HighlightObject(gridClicked, false); } #endregion cursor.ObjectGrabbed = spriteClicked; if (gridClicked == null) { return; } #region Change the convert to sprite grid button to "Modify Sprite Grid" GuiData.ToolsWindow.convertToSpriteGridButton.Enabled = true; GuiData.ToolsWindow.convertToSpriteGridButton.Text = "Modify Sprite Grid"; #endregion } #endregion }