private void ImportBackground(int bgIndex)
{
string selectedFile = Factory.GUIController.ShowOpenFileDialog("Select background to import...", GUIController.IMAGE_FILE_FILTER);
if (selectedFile != null)
{
Bitmap bmp = null;
try
{
bmp = new Bitmap(selectedFile);
bmp = ExtendBitmapIfSmallerThanScreen(bmp);
bool doImport = true;
bool deleteExtraFrames = false;
RoomResolution newResolution;
if (bgIndex > 0)
{
newResolution = _room.Resolution;
}
// CHECKME: WTF is this??? How to deal with it?
else if (//(bmp.Width > 640) && (bmp.Height > 400) &&
(!Factory.AGSEditor.CurrentGame.Settings.LowResolution))
{
newResolution = RoomResolution.HighRes;
}
else
{
newResolution = RoomResolution.LowRes;
}
if ((bmp.Width != _room.Width) || (bmp.Height != _room.Height) ||
(newResolution != _room.Resolution))
{
if (bgIndex > 0)
{
Factory.GUIController.ShowMessage("This image is a different size to the main background image. All backgrounds for the room must be of the same size." + Environment.NewLine + Environment.NewLine + "Main background: " + _room.Width + " x " + _room.Height + "; this image: " + bmp.Width + " x " + bmp.Height, MessageBoxIcon.Warning);
doImport = false;
}
else if (_room.BackgroundCount > 1)
{
if (Factory.GUIController.ShowQuestion("Changing the size of the main background will mean that all extra backgrounds are deleted. Are you sure you want to do this?") != DialogResult.Yes)
{
doImport = false;
}
else
{
deleteExtraFrames = true;
}
}
if (doImport)
{
if (Factory.GUIController.ShowQuestion("The new background is a different size to the old one. If you import it, all your regions, hotspots and walkable areas will be cleared. Do you want to proceed?") != DialogResult.Yes)
{
doImport = false;
}
}
}
if (doImport)
{
_room.Resolution = newResolution;
_room.Width = bmp.Width;
_room.Height = bmp.Height;
Factory.NativeProxy.ImportBackground(_room, bgIndex, bmp, !Factory.AGSEditor.Preferences.RemapPalettizedBackgrounds, false);
_room.Modified = true;
if (deleteExtraFrames)
{
while (_room.BackgroundCount > 1)
{
Factory.NativeProxy.DeleteBackground(_room, 1);
}
}
sldZoomLevel.Value = 3 - (int)_room.Resolution;
sldZoomLevel_Scroll(null, null);
UpdateScrollableWindowSize();
}
}
catch (Exception ex)
{
Factory.GUIController.ShowMessage("The background could not be imported. The error was:" + Environment.NewLine + Environment.NewLine + ex.Message, MessageBoxIcon.Warning);
}
if (bmp != null)
{
bmp.Dispose();
}
}
}