public SpriteImportWindow(string[] filenames, SpriteFolder folder) { InitializeComponent(); // take some defaults from Editor preferences SpriteImportMethod = (SpriteImportTransparency)Factory.AGSEditor.Settings.SpriteImportMethod; // import, not replace this.folder = folder; replace = null; btnImportAll.Enabled = cmbFilenames.Enabled = filenames.Length > 1; cmbFilenames.Items.Clear(); imageLookup = new List <string>(); foreach (string filename in filenames) { imageLookup.Add(filename); cmbFilenames.Items.Add(Path.GetFileName(filename)); } cmbFilenames.SelectedIndex = 0; OneTimeControlSetup(); PostImageLoad(); }
public static void ExportSprites(SpriteFolder folder, string path, bool recurse, bool skipValidSourcePath, bool updateSourcePath) { foreach (Sprite sprite in folder.Sprites) { if (skipValidSourcePath) { string checkPath; if (Path.IsPathRooted(sprite.SourceFile)) { checkPath = sprite.SourceFile; } else { checkPath = Path.Combine(Factory.AGSEditor.CurrentGame.DirectoryPath, sprite.SourceFile); } if (File.Exists(checkPath)) { continue; } } ExportSprite(sprite, path, updateSourcePath); } if (recurse) { foreach (SpriteFolder subFolder in folder.SubFolders) { ExportSprites(subFolder, path, recurse, skipValidSourcePath, updateSourcePath); } } }
private void onQuickImportFromFolderClicked(object sender, EventArgs e) { Sprite chosen = SpriteChooser.ShowSpriteChooser(_LastSelectedSprite, "Select the first sprite to be imported from the folder"); if (chosen != null) { SpriteFolder parent = Factory.AGSEditor.CurrentGame.RootSpriteFolder.FindFolderThatContainsSprite(chosen.Number); if (parent != null) { for (int i = 0; i < parent.Sprites.Count; i++) { if (parent.Sprites[i].Number >= chosen.Number) { _loop.Frames.Add(new ViewFrame { ID = _loop.Frames.Count, Image = parent.Sprites[i].Number, }); } } UpdateControlWidth(); this.Invalidate(); } } }
public static void ImportNewSprite(SpriteFolder folder, Bitmap bmp, bool alpha, bool remapColours, bool useRoomBackground, SpriteImportTransparency transparency, string filename, int frame, Rectangle selection, bool tile) { // ignore alpha channel if not 32 bit ARGB bool useAlphaChannel = bmp.PixelFormat != PixelFormat.Format32bppArgb || Factory.AGSEditor.CurrentGame.Settings.ColorDepth != GameColorDepth.TrueColor ? false : alpha; // ignore palette remap options if not using an indexed palette if (bmp.PixelFormat != PixelFormat.Format8bppIndexed) { remapColours = false; useRoomBackground = false; } // do import Sprite sprite = Factory.NativeProxy.CreateSpriteFromBitmap(bmp, transparency, remapColours, useRoomBackground, useAlphaChannel); sprite.TransparentColour = transparency; sprite.RemapToGamePalette = remapColours; sprite.RemapToRoomPalette = useRoomBackground; sprite.SourceFile = Utilities.GetRelativeToProjectPath(filename); sprite.Frame = frame; sprite.OffsetX = selection.Left; sprite.OffsetY = selection.Top; sprite.ImportWidth = selection.Width; sprite.ImportHeight = selection.Height; sprite.ImportAlphaChannel = alpha; sprite.ImportAsTile = tile; folder.Sprites.Add(sprite); }
public SpriteImportWindow(string[] filenames, Sprite replace) { InitializeComponent(); // set defaults from the old sprite SpriteImportMethod = replace.TransparentColour; SelectionOffset = new Point(replace.OffsetX, replace.OffsetY); SelectionSize = new Size(replace.Width, replace.Height); UseAlphaChannel = replace.ImportAlphaChannel; RemapToGamePalette = replace.RemapToGamePalette; UseBackgroundSlots = replace.RemapToRoomPalette; // replace, not import folder = null; this.replace = replace; // replacement can only use one image, but you can pick // any one and make a selection from it btnImportAll.Enabled = false; cmbFilenames.Enabled = filenames.Length > 1; cmbFilenames.Items.Clear(); imageLookup = new List <string>(); foreach (string filename in filenames) { imageLookup.Add(filename); cmbFilenames.Items.Add(Path.GetFileName(filename)); } cmbFilenames.SelectedIndex = 0; OneTimeControlSetup(); PostImageLoad(); }
public static void ImportNewSprite(SpriteFolder folder, Bitmap bmp, bool alpha, bool remapColours, bool useRoomBackground, SpriteImportTransparency transparency, string filename = "", int frame = 0, int offsetX = 0, int offsetY = 0) { // ignore alpha channel if not 32 bit ARGB bool useAlphaChannel = bmp.PixelFormat != PixelFormat.Format32bppArgb ? false : alpha; // ignore palette remap options if not using an indexed palette if (bmp.PixelFormat != PixelFormat.Format8bppIndexed) { remapColours = false; useRoomBackground = false; } // do import Sprite sprite = Factory.NativeProxy.CreateSpriteFromBitmap(bmp, transparency, remapColours, useRoomBackground, useAlphaChannel); sprite.TransparentColour = transparency; sprite.RemapToGamePalette = remapColours; sprite.RemapToRoomPalette = useRoomBackground; sprite.SourceFile = Utilities.GetRelativeToProjectPath(filename); sprite.Frame = frame; sprite.OffsetX = offsetX; sprite.OffsetY = offsetY; folder.Sprites.Add(sprite); }
public static void ExportSprites(string path, bool recurse, SkipIf skipIf, bool updateSourcePath) { SpriteFolder folder = Factory.AGSEditor.CurrentGame.RootSpriteFolder; ExportSprites(folder, path, recurse, skipIf, updateSourcePath); }
public static void ExportSprites(SpriteFolder folder, string path, bool recurse, SkipIf skipIf, bool updateSourcePath) { foreach (Sprite sprite in folder.Sprites) { if (skipIf > 0) { string checkPath = Path.IsPathRooted(sprite.SourceFile) ? sprite.SourceFile : Path.Combine(Factory.AGSEditor.CurrentGame.DirectoryPath, sprite.SourceFile); if (skipIf.HasFlag(SkipIf.SourceValid) && File.Exists(checkPath)) { continue; // skip if source is valid } else if (skipIf.HasFlag(SkipIf.SourceLocal) && File.Exists(checkPath) && Utilities.PathsAreSameOrNested(sprite.SourceFile, Factory.AGSEditor.CurrentGame.DirectoryPath)) { continue; // skip if source is valid and local (inside the project folder) } } ExportSprite(sprite, path, updateSourcePath); } if (recurse) { foreach (SpriteFolder subFolder in folder.SubFolders) { ExportSprites(subFolder, path, recurse, skipIf, updateSourcePath); } } }
public SpriteManager() { _spriteUpdateHandler = new SpriteFolder.SpritesUpdatedHandler(RootSpriteFolder_SpritesUpdated); InitializeComponent(); spriteSelector.OnSelectionChanged += new SpriteSelector.SelectionChangedHandler(spriteSelector_OnSelectionChanged); _attachedToFolder = Factory.AGSEditor.CurrentGame.RootSpriteFolder; _attachedToFolder.SpritesUpdated += _spriteUpdateHandler; }
/// <summary> /// Writes the sprite file, importing all the existing sprites either from the /// their sources, or sprite cache, - whatever is present (in that order). /// </summary> public static void WriteSpriteFileFromSources(string filename, IWorkProgress progress) { int storeFlags = 0; if (Factory.AGSEditor.CurrentGame.Settings.OptimizeSpriteStorage) { storeFlags |= (int)Native.SpriteFileWriter.StorageFlags.OptimizeForSize; } var compressSprites = Factory.AGSEditor.CurrentGame.Settings.CompressSpritesType; SpriteFolder folder = Factory.AGSEditor.CurrentGame.RootSpriteFolder; var sprites = folder.GetAllSpritesFromAllSubFolders(); var orderedSprites = sprites.OrderBy(sprite => sprite.Number); progress.Total = orderedSprites.Count(); progress.Current = 0; var writer = new Native.SpriteFileWriter(filename); writer.Begin(storeFlags, compressSprites); int spriteIndex = 0; int realSprites = 0; foreach (Sprite sprite in orderedSprites) { // NOTE: we must add empty slots to fill all the gaps in sprite IDs! for (; spriteIndex < sprite.Number; ++spriteIndex) { writer.WriteEmptySlot(); } // Try get the image, first from source, then from editor's cache var bmp = LoadBitmapFromSource(sprite); // TODO: this is quite suboptimal, find a way to retrieve a native handle instead? if (bmp == null) { bmp = Factory.NativeProxy.GetBitmapForSprite(sprite.Number, sprite.Width, sprite.Height); } if (bmp != null) { writer.WriteBitmap(bmp, sprite.TransparentColour, sprite.RemapToGamePalette, sprite.RemapToRoomPalette, sprite.AlphaChannel); bmp.Dispose(); } else { bmp = new Bitmap(sprite.Width, sprite.Height); writer.WriteBitmap(bmp); bmp.Dispose(); } progress.Current = ++realSprites; spriteIndex++; } writer.End(); }
public void GameChanged() { if (_attachedToFolder != null) { _attachedToFolder.SpritesUpdated -= _spriteUpdateHandler; } _attachedToFolder = Factory.AGSEditor.CurrentGame.RootSpriteFolder; _attachedToFolder.SpritesUpdated += _spriteUpdateHandler; spriteSelector.SetDataSource(_attachedToFolder); }
private int CountSpriteFolders(SpriteFolder folder) { int total = folder.SubFolders.Count; foreach (SpriteFolder subFolder in folder.SubFolders) { total += CountSpriteFolders(subFolder); } return(total); }
public static void ImportNewSprites(SpriteFolder folder, string[] filenames, bool alpha, bool remapColours, bool useRoomBackground, SpriteImportTransparency transparency, SpriteSheet spritesheet = null) { Progress progress = new Progress(filenames.Length, String.Format("Importing sprites from {0} files", filenames.Length)); progress.Show(); for (int index = 0; index < filenames.Length; index++) { progress.SetProgressValue(index); ImportNewSprites(folder, filenames[index], alpha, remapColours, useRoomBackground, transparency, spritesheet); } progress.Hide(); progress.Dispose(); }
public SpriteImportWindow(Bitmap bmp, SpriteFolder folder) { InitializeComponent(); // take some defaults from Editor preferences SpriteImportMethod = (SpriteImportTransparency)Factory.AGSEditor.Settings.SpriteImportMethod; // import, not replace this.folder = folder; replace = null; image = bmp; btnImportAll.Enabled = false; cmbFilenames.Enabled = false; OneTimeControlSetup(); PostImageLoad(); }
public static void ImportNewSprites(SpriteFolder folder, Bitmap bmp, bool alpha, bool remapColours, bool useRoomBackground, SpriteImportTransparency transparency, SpriteSheet spritesheet = null, int frame = 0, string filename = "") { if (spritesheet != null) { foreach (Rectangle selection in spritesheet.GetSpriteSelections(new Size(bmp.Width, bmp.Height))) { Bitmap import = bmp.Clone(selection, bmp.PixelFormat); ImportNewSprite(folder, import, alpha, remapColours, useRoomBackground, transparency, filename, frame, selection.Left, selection.Top); import.Dispose(); } } else { ImportNewSprite(folder, bmp, alpha, remapColours, useRoomBackground, transparency, filename, frame); } }
public static void ImportNewSprites(SpriteFolder folder, string filename, bool alpha, bool remapColours, bool useRoomBackground, SpriteImportTransparency transparency, SpriteSheet spritesheet = null) { Progress progress = new Progress(GetFrameCountEstimateFromFile(filename), String.Format("Importing frames from {0}", filename)); progress.Show(); int frame = 0; foreach (Bitmap bmp in LoadSpritesFromFile(filename)) { progress.SetProgressValue(frame); ImportNewSprites(folder, bmp, alpha, remapColours, useRoomBackground, transparency, spritesheet, frame, filename); bmp.Dispose(); frame++; } progress.Hide(); progress.Dispose(); }
public SpriteExportDialog(SpriteFolder folder) { InitializeComponent(); radThisFolder.Text = String.Format("This sprite folder ({0})", folder.Name); if (folder == Factory.AGSEditor.CurrentGame.RootSpriteFolder) { radRootFolder.Checked = true; radThisFolder.Enabled = false; } List <ToolStripMenuItem> tokens = new List <ToolStripMenuItem>(); foreach (PropertyInfo property in typeof(Sprite).GetProperties()) { tokens.Add(new ToolStripMenuItem(String.Format("%{0}%", property.Name))); } menuItemToken.DropDownItems.AddRange(tokens.ToArray()); }
private void loopPane_NewFrameAdded(ViewLoop loop, int newSelectedFrame) { if (newSelectedFrame > 0) { // Attempt to initialize the new frame to the sprite that // comes after the previous frame in the sprite manager int previousFrameImage = loop.Frames[newSelectedFrame - 1].Image; SpriteFolder parent = Factory.AGSEditor.CurrentGame.RootSpriteFolder.FindFolderThatContainsSprite(previousFrameImage); if ((parent != null) && (previousFrameImage > 0)) { for (int i = 0; i < parent.Sprites.Count; i++) { if ((parent.Sprites[i].Number == previousFrameImage) && (i < parent.Sprites.Count - 1)) { loop.Frames[newSelectedFrame].Image = parent.Sprites[i + 1].Number; break; } } } } }
public SpriteImportWindow(Bitmap bmp, Sprite replace) { InitializeComponent(); // set defaults from the old sprite SpriteImportMethod = replace.TransparentColour; SelectionOffset = new Point(replace.OffsetX, replace.OffsetY); SelectionSize = new Size(replace.Width, replace.Height); UseAlphaChannel = replace.ImportAlphaChannel; RemapToGamePalette = replace.RemapToGamePalette; UseBackgroundSlots = replace.RemapToRoomPalette; // replace, not import folder = null; this.replace = replace; image = bmp; btnImportAll.Enabled = false; cmbFilenames.Enabled = false; OneTimeControlSetup(); PostImageLoad(); }