public static void RemoveText <T>(AttachableList <T> listToRemove) where T : Text { // backwards loop so we don't miss any Text objects for (int i = listToRemove.Count - 1; i > -1; i--) { RemoveText(listToRemove[i]); } }
public static void DeselectCurrentObjects <T>(AttachableList <T> currentObjects) where T : PositionedObject, ICursorSelectable { for (int i = currentObjects.Count - 1; i > -1; i--) { DeselectCurrentObject(currentObjects[i], currentObjects); } currentObjects.Clear(); }
public static void DeselectCurrentObject <T>(T currentObject, AttachableList <T> currentList) where T : PositionedObject { ClearAttachedMarkers(); if (currentObject as EditorSprite != null) { mEditorLogic.SetIndividualVariablesFromStoredVariables(currentObject as EditorSprite); } currentList.Remove(currentObject); }
public void GetObjectsOver <T>(AttachableList <T> allObjects, AttachableList <T> objectsOver) where T : PositionedObject, IAttachable, ICursorSelectable { if (mRectangle.Visible) { mRectangleStarted = false; float x = 0; float y = 0; GuiManager.Cursor.GetCursorPosition(out x, out y, 0); mRectangle.X = (x + mOriginalPoint.X) / 2.0f; mRectangle.Y = (y + mOriginalPoint.Y) / 2.0f; mRectangle.ScaleX = Math.Abs(x - mOriginalPoint.X) / 2.0f; mRectangle.ScaleY = Math.Abs(y - mOriginalPoint.Y) / 2.0f; if (System.Math.Abs(x - mOriginalPoint.X) > .1f && System.Math.Abs(y - mOriginalPoint.Y) > .1f) { Polygon spritePolygon = new Polygon(); Point[] spritePoints = new Point[5]; foreach (T t in allObjects) { if (t.CursorSelectable) { spritePoints[0] = new Point(-t.ScaleX, t.ScaleY); spritePoints[1] = new Point(t.ScaleX, t.ScaleY); spritePoints[2] = new Point(t.ScaleX, -t.ScaleY); spritePoints[3] = new Point(-t.ScaleX, -t.ScaleY); spritePoints[4] = spritePoints[0]; spritePolygon.Points = spritePoints; spritePolygon.Position = t.Position; spritePolygon.RotationMatrix = t.RotationMatrix; if (spritePolygon.CollideAgainst(mRectangle)) { objectsOver.Add(t); } } } } } }
public static void KeepSpriteNameUnique <T>(T spriteToKeepNameUnique, string nameToUse, AttachableList <T> list) where T : class, IAttachable, ITexturable { string spriteTexture = "Untextured"; if (spriteToKeepNameUnique.Texture != null) { spriteTexture = FileManager.RemoveExtension( spriteToKeepNameUnique.Texture.Name); } spriteTexture = FileManager.RemovePath(spriteTexture); if (nameToUse == "") { string spriteName = spriteTexture + "1"; string adjustedSpriteName = GetUniqueNameForObject(spriteName, spriteToKeepNameUnique); spriteToKeepNameUnique.Name = adjustedSpriteName; mNextSpriteNumber++; if (adjustedSpriteName != spriteName) { mNextSpriteNumber++; // if we need to move ahead, then we might as well move the spriteNum to save some calculations } } else { spriteToKeepNameUnique.Name = nameToUse; } }
public void CopyCurrentObjects(Window callingWindow) { if ((GameData.EditorLogic.CurrentSprites.Count != 0) || (GameData.EditorLogic.CurrentSpriteFrames.Count != 0) || (GameData.EditorLogic.CurrentPositionedModels.Count != 0) || (GameData.EditorLogic.CurrentTexts.Count != 0)) { int instructionNum = 0; #region Copy Sprites if (SpriteEditorSettings.EditingSprites) { // remove the in-screen markers and axes so they don't get touched by the copying GameData.EditorLogic.EditAxes.CurrentObject = null; Sprite topSpriteAdded = null; AttachableList <Sprite> oldestParents = AttachableList <Sprite> .GetTopParents <Sprite, Sprite>(GameData.EditorLogic.CurrentSprites); SpriteList addedSprites = new SpriteList(); // The appendedNumbers variable is used for improving performance when copying large groups. When a Sprite // is copied, it is given a number at the end of its name or if there is already a number present, // it is incremented. However, copying large groups can result in a lot of string checking which // can hurt performance. // Consider copying 100 Sprites with the same texture. Their names will likely be redball1, redball2, // redball3, ... redball100. Let's say redball1 gets copied first. The SpriteEditor increments the // number at the end to redball2, then checks to see if there is already a Sprite with that name. If // there is, it increments to redball3 and so on. This must be conducted on average 10,000 times and each // iteration requires string copying, concatenation, and parsing for integers. To cut this down, the // appendedNumbers variable associates a given name (in this case redball) with the last integer appended // to that particular name. Therefore, when the first Sprite is created, it will loop through 1 - 100 and // eventually end up at redball101. It will then associate the number 101 with the name redball. The next // Sprite (named redball2) will know to begin at redball101. This increases the performance of // copying large groups from O(n^2) to O(n). Dictionary <string, int> appendedNumbers = new Dictionary <string, int>(); foreach (Sprite s in oldestParents) { if (s is ISpriteEditorObject) { if (GuiData.ToolsWindow.groupHierarchyControlButton.IsPressed) { topSpriteAdded = GameData.copySpriteHierarchy( s, s.Parent as Sprite, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers); } else { topSpriteAdded = GameData.copySpriteHierarchy( s.TopParent as Sprite, null, GameData.EditorProperties.PixelSize, addedSprites, appendedNumbers); } } SpriteList tempSpriteArray = new SpriteList(); topSpriteAdded.GetAllDescendantsOneWay(tempSpriteArray); tempSpriteArray.Add(topSpriteAdded); } GameData.EditorLogic.EditAxes.CurrentObject = GameData.EditorLogic.CurrentSprites[0]; GameData.Cursor.ClickSprite(null); foreach (Sprite s in AttachableList <Sprite> .GetTopParents <Sprite, Sprite>(addedSprites)) { // the 2nd true forces selection of all Sprites GameData.Cursor.ClickObject <Sprite>(s, GameData.EditorLogic.CurrentSprites, true, true); } GameData.Cursor.VerifyAndUpdateGrabbedAgainstCurrent(); } #endregion #region Copy SpriteGrids else if (SpriteEditorSettings.EditingSpriteGrids) { SpriteGrid sg = SESpriteGridManager.CurrentSpriteGrid.Clone(); FlatRedBall.Utilities.StringFunctions.MakeNameUnique <SpriteGrid>(sg, GameData.Scene.SpriteGrids); this.sesgMan.PopulateAndAddGridToEngine(sg, GameData.EditorLogic.CurrentSprites[0]); sg.RefreshPaint(); } #endregion #region Copy SpriteFrames else if (SpriteEditorSettings.EditingSpriteFrames) { GameData.EditorLogic.EditAxes.CurrentObject = null; AttachableList <SpriteFrame> oldestParents = AttachableList <SpriteFrame> .GetTopParents <SpriteFrame, SpriteFrame>(GameData.EditorLogic.CurrentSpriteFrames); foreach (SpriteFrame sf in oldestParents) { SpriteFrame topSpriteFrameAdded = GameData.CopySpriteFrameHierarchy(sf, null, GameData.EditorProperties.PixelSize); GameData.Cursor.ClickSpriteFrame(topSpriteFrameAdded); } } #endregion #region Copy Models else if (SpriteEditorSettings.EditingModels) { GameData.EditorLogic.EditAxes.CurrentObject = null; AttachableList <PositionedModel> oldestParents = AttachableList <PositionedModel> .GetTopParents <PositionedModel, PositionedModel>(GameData.EditorLogic.CurrentPositionedModels); foreach (PositionedModel model in oldestParents) { PositionedModel topSpriteFrameAdded = GameData.CopyModelHierarchy(model, null, GameData.EditorProperties.PixelSize); // GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded); } } #endregion #region Copy Texts else if (SpriteEditorSettings.EditingTexts) { GameData.EditorLogic.EditAxes.CurrentObject = null; AttachableList <Text> oldestParents = AttachableList <Text> .GetTopParents <Text, Text>(GameData.EditorLogic.CurrentTexts); foreach (Text text in oldestParents) { Text topText = GameData.CopyTextHierarchy(text, null, GameData.EditorProperties.PixelSize); // GameData.cursor.ClickSpriteFrame(topSpriteFrameAdded); } } #endregion } }