private void AssignSpritesToView(List<int> spriteNumbers, AssignToView dialog) { int loop = dialog.LoopNumber; if (dialog.ReverseFrames) { spriteNumbers.Reverse(); } AGS.Types.View view = Factory.AGSEditor.CurrentGame.FindViewByID(dialog.ViewNumber); if (view == null) { Factory.GUIController.ShowMessage("The view number you selected (" + dialog.ViewNumber + ") does not exist.", MessageBoxIcon.Warning); return; } while (loop >= view.Loops.Count) { view.AddNewLoop(); } if (!dialog.AddFramesToExistingLoop) { view.Loops[loop].Frames.Clear(); } foreach (int spriteNum in spriteNumbers) { if (view.Loops[loop].Full) { if (!dialog.ContinueIntoNextLoop) { Factory.GUIController.ShowMessage("The selected loop is now full. Not all the selected sprites were assigned.", MessageBoxIcon.Information); view.NotifyClientsOfUpdate(); return; } loop++; if (loop >= view.Loops.Count) { view.AddNewLoop(); } view.Loops[loop - 1].RunNextLoop = true; } ViewFrame newFrame = new ViewFrame(); newFrame.ID = view.Loops[loop].Frames.Count; newFrame.Image = spriteNum; if (dialog.FlipFrames) { newFrame.Flipped = true; } view.Loops[loop].Frames.Add(newFrame); } Factory.GUIController.ShowMessage("The selected sprites were assigned successfully.", MessageBoxIcon.Information); view.NotifyClientsOfUpdate(); }
private void SpriteContextMenuEventHandler(object sender, EventArgs e) { ToolStripMenuItem item = (ToolStripMenuItem)sender; if (item.Name == MENU_ITEM_PASTE_NEW) { if ((Clipboard.ContainsImage()) && (Clipboard.GetImage() is Bitmap)) { Bitmap bmp = (Bitmap)Clipboard.GetImage(); if ((bmp.PixelFormat == PixelFormat.Format32bppRgb) || (bmp.PixelFormat == PixelFormat.Format16bppRgb565)) { ImportNewSprite(bmp, null); SetAsLastImportedSprite(bmp, null); } else { Factory.GUIController.ShowMessage("The image on the clipboard is in an unrecognised format: " + bmp.PixelFormat, MessageBoxIcon.Warning); bmp.Dispose(); } } else { Factory.GUIController.ShowMessage("The clipboard does not currently contain a supported image format.", MessageBoxIcon.Warning); } } else if (item.Name == MENU_ITEM_IMPORT_NEW) { string fileName = Factory.GUIController.ShowOpenFileDialog("Import new sprite...", GUIController.IMAGE_FILE_FILTER); if (fileName != null) { ImportNewSpriteUsingImportWindow(fileName); } } else if (item.Name == MENU_ITEM_NEW_FROM_PREVIOUS) { ImportNewSprite(_lastImportedSprite, _lastImportedFileName); } else if (item.Name == MENU_ITEM_REPLACE_FROM_FILE) { string fileName = Factory.GUIController.ShowOpenFileDialog("Replace sprite...", GUIController.IMAGE_FILE_FILTER); if (fileName != null) { Sprite sprite = FindSpriteByNumber(_spriteNumberOnMenuActivation); ReplaceSpriteUsingImportWindow(fileName, sprite); } } else if (item.Name == MENU_ITEM_REPLACE_FROM_CLIPBOARD) { if ((Clipboard.ContainsImage()) && (Clipboard.GetImage() is Bitmap)) { Bitmap bmp = (Bitmap)Clipboard.GetImage(); if ((bmp.PixelFormat == PixelFormat.Format32bppRgb) || (bmp.PixelFormat == PixelFormat.Format16bppRgb565)) { Sprite sprite = FindSpriteByNumber(_spriteNumberOnMenuActivation); ReplaceSprite(bmp, sprite, null); SetAsLastImportedSprite(bmp, null); } else { Factory.GUIController.ShowMessage("The image on the clipboard is in an unrecognised format: " + bmp.PixelFormat, MessageBoxIcon.Warning); bmp.Dispose(); } } else { Factory.GUIController.ShowMessage("The clipboard does not currently contain a supported image format.", MessageBoxIcon.Warning); } } else if (item.Name == MENU_ITEM_REPLACE_FROM_PREVIOUS) { Sprite sprite = FindSpriteByNumber(_spriteNumberOnMenuActivation); ReplaceSprite(_lastImportedSprite, sprite, _lastImportedFileName); } else if (item.Name == MENU_ITEM_DELETE_SPRITE) { DeleteSelectedSprites(); } else if (item.Name == MENU_ITEM_QUICK_IMPORT_GIF_FLC) { string fileName = Factory.GUIController.ShowOpenFileDialog("Import GIF frames...", GIF_FILTER); if (fileName != null) { ImportMultipleGIFFrames(fileName); } } else if (item.Name == MENU_ITEM_QUICK_IMPORT_SPRITES) { string[] fileNames = Factory.GUIController.ShowOpenFileDialogMultipleFiles("Import multiple sprites...", GUIController.IMAGE_FILE_FILTER); if ((fileNames != null) && (fileNames.Length > 0)) { this.Cursor = Cursors.WaitCursor; Application.DoEvents(); foreach (string fileName in fileNames) { QuickImportSpriteFromFile(fileName); } this.Cursor = Cursors.Default; RefreshSpriteDisplay(); } } else if (item.Name == MENU_ITEM_EXPORT_FOLDER) { string exportFolder = Factory.GUIController.ShowSelectFolderOrNoneDialog("Export sprites to folder...", System.IO.Directory.GetCurrentDirectory()); if (exportFolder != null) { ExportAllSpritesInFolder(exportFolder); } } else if (item.Name == MENU_ITEM_SORT_BY_NUMBER) { SortAllSpritesInCurrentFolderByNumber(); } else if (item.Name == MENU_ITEM_FIND_BY_NUMBER) { PromptUserForSpriteNumberAndFindSprite(); } else if (item.Name == MENU_ITEM_EXPORT_SPRITE) { string fileName = Factory.GUIController.ShowSaveFileDialog("Export sprite...", GUIController.IMAGE_FILE_FILTER); if (fileName != null) { Sprite sprite = FindSpriteByNumber(_spriteNumberOnMenuActivation); ExportSprite(fileName, sprite); } } else if (item.Name == MENU_ITEM_USE_THIS_SPRITE) { if (OnSpriteActivated != null) { OnSpriteActivated(this.SelectedSprite); } } else if (item.Name == MENU_ITEM_EDIT_THIS_SPRITE) { LaunchImageEditorForSprite(this.SelectedSprite); } else if (item.Name == MENU_ITEM_COPY_TO_CLIPBOARD) { Sprite sprite = FindSpriteByNumber(_spriteNumberOnMenuActivation); Bitmap bmp = Factory.NativeProxy.GetBitmapForSprite(sprite.Number, sprite.Width, sprite.Height); bool doCopy = true; if ((GetDesktopColourDepth() < 32) && ((bmp.PixelFormat == PixelFormat.Format32bppArgb) || (bmp.PixelFormat == PixelFormat.Format32bppRgb))) { if (Factory.GUIController.ShowQuestion("Your desktop colour depth is lower than this image. You may lose image detail if you copy this to the clipboard. Do you want to go ahead?") == DialogResult.No) { doCopy = false; } } if (doCopy) { Clipboard.SetImage(bmp); } bmp.Dispose(); } else if (item.Name == MENU_ITEM_CHANGE_SPRITE_NUMBER) { if (Factory.GUIController.ShowQuestion("Changing the sprite slot number is a specialized operation, for advanced users only.\n\nOnly re-number this sprite if you are ABSOLUTELY SURE it is not used AT ALL in your game. Any parts of your game that do use this sprite will cause the editor and engine to crash if you go ahead. Are you sure?") == DialogResult.Yes) { string usage = _spriteUsageChecker.GetSpriteUsageReport(_spriteNumberOnMenuActivation, Factory.AGSEditor.CurrentGame); if (usage != null) { Factory.GUIController.ShowMessage("Cannot change the sprite number because it is in use:" + Environment.NewLine + usage, MessageBoxIcon.Warning); return; } Sprite sprite = FindSpriteByNumber(_spriteNumberOnMenuActivation); int newNumber = NumberEntryDialog.Show("Change Sprite Number", "Enter the new sprite number in the box below:", sprite.Number); if (newNumber == -1) { // Dialog cancelled } else if (Factory.NativeProxy.DoesSpriteExist(newNumber)) { Factory.GUIController.ShowMessage("The destination sprite number " + newNumber + " already exists.", MessageBoxIcon.Stop); } else { try { Factory.NativeProxy.ChangeSpriteNumber(sprite, newNumber); RefreshSpriteDisplay(); SelectSprite(sprite); } catch (AGSEditorException ex) { Factory.GUIController.ShowMessage("Unable to change the sprite number: " + ex.Message, MessageBoxIcon.Warning); } } } } else if (item.Name == MENU_ITEM_SHOW_USAGE) { string usage = _spriteUsageChecker.GetSpriteUsageReport(_spriteNumberOnMenuActivation, Factory.AGSEditor.CurrentGame); if (usage == null) { Factory.GUIController.ShowMessage("No uses of this sprite could be found automatically. HOWEVER, it may be used in scripts or as a room object image; these uses cannot be detected automatically.", MessageBoxIcon.Information); } else { Factory.GUIController.ShowMessage(usage, MessageBoxIcon.Information); } } else if (item.Name == MENU_ITEM_ASSIGN_TO_VIEW) { AssignToView dialog = new AssignToView(); if (dialog.ShowDialog(this) == DialogResult.OK) { List<int> spriteNumbers = new List<int>(); foreach (ListViewItem selectedItem in spriteList.SelectedItems) { spriteNumbers.Add(Convert.ToInt32(selectedItem.Name.ToString())); } AssignSpritesToView(spriteNumbers, dialog); } dialog.Dispose(); } else if (item.Name == MENU_ITEM_CROP_ASYMMETRIC) { if (Factory.GUIController.ShowQuestion("Cropping the selected sprites will trim off the edges to reduce all the selected sprites to the size required by the largest. Are you sure you want to proceed?") == DialogResult.Yes) { CropSelectedSprites(false); } } else if (item.Name == MENU_ITEM_CROP_SYMMETRIC) { if (Factory.GUIController.ShowQuestion("Cropping the selected sprites will trim off the edges to reduce all the selected sprites to the size required by the largest, but ensuring that the central pivot point of the sprites remains unchanged. Are you sure you want to proceed?") == DialogResult.Yes) { CropSelectedSprites(true); } } else if (item.Name == MENU_ITEM_REPLACE_FROM_SOURCE) { ReplaceSpritesFromSource(); } }