Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Editor: Menu voice for replacing multiple sprites

When selecting more than one sprite and right clicking a "Replace selected sprites from file..." voice will appear, at the moment it's only useful for tiled imports.
  • Loading branch information...
commit aa610214631d390553797d5bb7aaa9028f4177b1 1 parent 79f03ee
@AlanDrake AlanDrake authored
Showing with 54 additions and 0 deletions.
  1. +54 −0 Editor/AGS.Editor/Panes/SpriteSelector.cs
View
54 Editor/AGS.Editor/Panes/SpriteSelector.cs
@@ -43,6 +43,7 @@ public partial class SpriteSelector : UserControl
private const string MENU_ITEM_COPY_TO_CLIPBOARD = "CopyToClipboard";
private const string MENU_ITEM_EXPORT_SPRITE = "ExportSprite";
private const string MENU_ITEM_REPLACE_FROM_FILE = "ReplaceFromFile";
+ private const string MENU_ITEM_REPLACE_FROM_FILE_MULTI = "ReplaceFromFileMulti";
private const string MENU_ITEM_REPLACE_FROM_CLIPBOARD = "ReplaceFromClipboard";
private const string MENU_ITEM_REPLACE_FROM_PREVIOUS = "ReplaceFromPrevious";
private const string MENU_ITEM_DELETE_SPRITE = "DeleteSprite";
@@ -467,6 +468,24 @@ private void ReplaceSprite(Bitmap bmp, Sprite sprite, string sourceFileName)
impWin.Dispose();
}
+ private void ReplaceMultiSprite(Bitmap bmp, Sprite[] sprites, string sourceFileName)
+ {
+ bool useAlphaChannel = AskAboutAlphaChannel(bmp);
+ SpriteImportWindow impWin = new SpriteImportWindow(bmp);
+ if (impWin.ShowDialog() == DialogResult.OK)
+ {
+ for (int i = 0; (i < sprites.Length) && (i < impWin.SelectedBitmaps.Count); i++)
+ {
+ Bitmap bmpToImport = impWin.SelectedBitmaps[i];
+ Factory.NativeProxy.ReplaceSpriteWithBitmap(sprites[i], bmpToImport, (SpriteImportMethod)SpriteImportWindow.SpriteImportMethod, impWin.RemapToGamePalette, impWin.UseBackgroundSlots, useAlphaChannel);
+ sprites[i].SourceFile = string.Empty;
+ }
+
+ RefreshSpriteDisplay();
+ }
+ impWin.Dispose();
+ }
+
public void DeleteKeyPressed()
{
if ((folderList.Focused) && (folderList.SelectedNode != null))
@@ -567,6 +586,26 @@ private void SpriteContextMenuEventHandler(object sender, EventArgs e)
ReplaceSpriteUsingImportWindow(fileName, sprite);
}
}
+
+ else if (item.Name == MENU_ITEM_REPLACE_FROM_FILE_MULTI)
+ {
+ string fileName = Factory.GUIController.ShowOpenFileDialog("Replace sprites...", GUIController.IMAGE_FILE_FILTER);
+ if (fileName != null)
+ {
+ Sprite[] selectedSprites = new Sprite[spriteList.SelectedItems.Count];
+ for (int i = 0; i < selectedSprites.Length; i++)
+ {
+ selectedSprites[i] = FindSpriteByNumber(Convert.ToInt32(spriteList.SelectedItems[i].Name));
+ if (selectedSprites[i] == null)
+ {
+ throw new AGSEditorException("Internal error: selected sprite not in folder");
+ }
+ }
+ //Sprite sprite = FindSpriteByNumber(_spriteNumberOnMenuActivation);
+ ReplaceMultiSpriteUsingImportWindow(fileName, selectedSprites);
+ }
+ }
+
else if (item.Name == MENU_ITEM_REPLACE_FROM_CLIPBOARD)
{
if ((Clipboard.ContainsImage()) && (Clipboard.GetImage() is Bitmap))
@@ -1132,6 +1171,20 @@ private void ReplaceSpriteUsingImportWindow(string fileName, Sprite sprite)
Factory.GUIController.ShowMessage("There was an error importing the file. The error message was: '" + ex.Message + "'. Please try again", MessageBoxIcon.Warning);
}
}
+
+ private void ReplaceMultiSpriteUsingImportWindow(string fileName, Sprite[] sprites)
+ {
+ try
+ {
+ Bitmap bmp = LoadSpriteFileFromDisk(fileName);
+ ReplaceMultiSprite(bmp, sprites, fileName);
+ SetAsLastImportedSprite(bmp, fileName);
+ }
+ catch (Exception ex)
+ {
+ Factory.GUIController.ShowMessage("There was an error importing the file. The error message was: '" + ex.Message + "'. Please try again", MessageBoxIcon.Warning);
+ }
+ }
private void ImportMultipleGIFFrames(string fileName)
{
@@ -1208,6 +1261,7 @@ private void ShowSpriteContextMenu(Point menuPosition)
{
menuItem.Enabled = false;
}
+ menu.Items.Add(new ToolStripMenuItem("Replace selected sprites from file...", null, onClick, MENU_ITEM_REPLACE_FROM_FILE_MULTI));
}
menu.Items.Add(new ToolStripMenuItem("Assign to view...", null, onClick, MENU_ITEM_ASSIGN_TO_VIEW));
menu.Items.Add(new ToolStripSeparator());
Please sign in to comment.
Something went wrong with that request. Please try again.