Example #1
0
        private void DefaultPalette_Color2()
        {
            int i = 0;

            UpdateColor(i++, 0x7fff);                           // transparent (white)
            UpdateColor(i++, 0x0000);                           // black
            UpdateColor(i++, 0x7fff);                           // white
            UpdateColor(i++, 0x0c59);                           // red
            UpdateColor(i++, 0x0e04);                           // green
            UpdateColor(i++, 0x6d08);                           // blue
            UpdateColor(i++, 0x0fdf);                           // yellow
            UpdateColor(i++, 0x6b64);                           // cyan
            UpdateColor(i++, 0x56b5);                           // lt gray
            UpdateColor(i++, 0x318c);                           // dk gray
            UpdateColor(i++, 0x0d11);                           // brown
            UpdateColor(i++, 0x5a9f);                           // lt red (pink)
            UpdateColor(i++, 0x4351);                           // lt green
            UpdateColor(i++, 0x7e93);                           // lt blue
            UpdateColor(i++, 0x1e7f);                           // orange
            UpdateColor(i++, 0x5cd1);                           // purple
            if (i != k_nColors)
            {
                //System.Windows.Forms.MessageBox.Show("Wrong number of colors in palette");
                System.Windows.Forms.MessageBox.Show(ResourceMgr.GetString("ErrorNumColorsInPalette0"));
            }
        }
Example #2
0
        public Toolbox_Sprite() : base()
        {
            Tools.Add(new Tool("Select", ToolType.Select, 0, 0, true, false,
                               ResourceMgr.GetBitmap("tool_select")));
            Tools.Add(new Tool("Pencil", ToolType.Pencil, 1, 0, true, true,
                               ResourceMgr.GetBitmap("tool_pencil")));
            Tools.Add(new Tool("Eyedropper", ToolType.Eyedropper, 0, 1, true, true,
                               ResourceMgr.GetBitmap("tool_eyedropper")));
            Tools.Add(new Tool("FloodFill", ToolType.FloodFill, 1, 1, true, true,
                               ResourceMgr.GetBitmap("tool_floodfill")));
            Tools.Add(new Tool("Eraser", ToolType.Eraser, 0, 2, true, true,
                               ResourceMgr.GetBitmap("tool_eraser")));
            Tools.Add(new Tool("Line", ToolType.Line, 1, 2, false, false,
                               ResourceMgr.GetBitmap("tool_line")));
            Tools.Add(new Tool("Rect", ToolType.Rect, 0, 3, false, false,
                               ResourceMgr.GetBitmap("tool_rect")));
            Tools.Add(new Tool("RectFilled", ToolType.RectFilled, 1, 3, false, false,
                               ResourceMgr.GetBitmap("tool_rectfilled")));
            Tools.Add(new Tool("Ellipse", ToolType.Ellipse, 0, 4, false, false,
                               ResourceMgr.GetBitmap("tool_ellipse")));
            Tools.Add(new Tool("EllipseFilled", ToolType.EllipseFilled, 1, 4, false, false,
                               ResourceMgr.GetBitmap("tool_ellipsefilled")));

            ToolboxRows     = 3;                // 3 visible rows.
            CurrentToolType = ToolType.Pencil;
        }
Example #3
0
        private void DefaultPalette_Color1()
        {
            int i = 0;

            UpdateColor(i++, 0x1f, 0x1f, 0x1f);                         // transparent (white)
            UpdateColor(i++, 0x00, 0x00, 0x00);                         // black
            UpdateColor(i++, 0x10, 0x00, 0x00);                         // dk red
            UpdateColor(i++, 0x00, 0x10, 0x00);                         // green

            UpdateColor(i++, 0x1f, 0x1f, 0x1f);                         // white
            UpdateColor(i++, 0x10, 0x10, 0x10);                         // gray
            UpdateColor(i++, 0x1f, 0x00, 0x00);                         // red
            UpdateColor(i++, 0x00, 0x1f, 0x00);                         // lt green

            UpdateColor(i++, 0x10, 0x10, 0x00);                         // greenish yellow
            UpdateColor(i++, 0x00, 0x00, 0x10);                         // blue
            UpdateColor(i++, 0x10, 0x00, 0x10);                         // purple
            UpdateColor(i++, 0x00, 0x10, 0x10);                         // aqua

            UpdateColor(i++, 0x1f, 0x1f, 0x00);                         // yellow
            UpdateColor(i++, 0x00, 0x00, 0x1f);                         // blue
            UpdateColor(i++, 0x1f, 0x00, 0x1f);                         // magenta
            UpdateColor(i++, 0x00, 0x1f, 0x1f);                         // cyan
            if (i != k_nColors)
            {
                //System.Windows.Forms.MessageBox.Show("Wrong number of colors in palette");
                System.Windows.Forms.MessageBox.Show(ResourceMgr.GetString("ErrorNumColorsInPalette0"));
            }
        }
Example #4
0
        public Toolbox_BgImage() : base()
        {
            Tools.Add(new Tool("Select", ToolType.Select, 0, 0, true, false,
                               ResourceMgr.GetBitmap("tool_select")));

            ToolboxRows     = 1;
            CurrentToolType = ToolType.Blank;
        }
Example #5
0
        public Toolbox_Map() : base()
        {
            Tools.Add(new Tool("RubberStamp", ToolType.RubberStamp, 0, 0,
                               ResourceMgr.GetBitmap("tool_rubberstamp")));
            Tools.Add(new Tool("FloodFill", ToolType.FloodFill, 1, 0,
                               ResourceMgr.GetBitmap("tool_floodfill")));

            ToolboxRows     = 1;
            CurrentToolType = ToolType.RubberStamp;
        }
Example #6
0
        private void UpdateSpriteInfo()
        {
            tbName.Text        = m_bgimage.Name;
            tbDescription.Text = m_bgimage.Description;

            // "{2}x{3} pixels"
            string strFormat = ResourceMgr.GetString("BgImageSizeFormat");

            lSizeData.Text = String.Format(strFormat, m_bgimage.Bitmap.Width, m_bgimage.Bitmap.Height);
        }
Example #7
0
 /// <summary>
 /// Update the screen bounds button to match the current platform.
 /// </summary>
 public void UpdateScreenButton()
 {
     if (Options.Platform == Options.PlatformType.GBA)
     {
         m_toolScreen.ChangeToolBitmap(ResourceMgr.GetBitmap("tool_gba"));
     }
     else
     {
         m_toolScreen.ChangeToolBitmap(ResourceMgr.GetBitmap("tool_nds"));
     }
 }
Example #8
0
        public Optionbox_Map() : base()
        {
            m_toolScreen = new Tool("ShowScreen", ToolType.ShowScreen, 0, 0,
                                    ResourceMgr.GetBitmap("tool_gba"),
                                    Options.BoolOptionName.BackgroundMap_ShowScreen);
            Tools.Add(m_toolScreen);

            Tools.Add(new Tool("ShowTileGrid", ToolType.ShowTileGrid, 1, 0,
                               ResourceMgr.GetBitmap("tool_smallgrid"),
                               Options.BoolOptionName.BackgroundMap_ShowGrid));

            ToolboxRows = 1;
        }
Example #9
0
        public Export(string strDocName)
        {
            InitializeComponent();

            this.DialogResult = DialogResult.Cancel;

            // Add Tooltips.
            ToolTip ttSprites = new ToolTip();

            ttSprites.SetToolTip(rbSprites, ResourceMgr.GetString("ExportTooltipSprites"));
            ToolTip ttUpdateProject = new ToolTip();

            ttUpdateProject.SetToolTip(rbUpdateProject, ResourceMgr.GetString("ExportTooltipUpdateProject"));
            ToolTip ttCompleteProject = new ToolTip();

            ttCompleteProject.SetToolTip(rbProject, ResourceMgr.GetString("ExportTooltipCompleteProject"));

            // Reset the export directory if we've opened a new file.
            if (m_strLastDocument != strDocName)
            {
                m_strLastExportDirectory = "";
            }
            m_strLastDocument = strDocName;

            // Reset any invalid directories.
            if (m_strLastExportDirectory != "" && !System.IO.Directory.Exists(m_strLastExportDirectory))
            {
                m_strLastExportDirectory = "";
            }

            // Default to save in document's directory.
            if (m_strLastExportDirectory == "" && strDocName != "")
            {
                m_strLastExportDirectory = System.IO.Path.GetDirectoryName(strDocName);
                if (!System.IO.Directory.Exists(m_strLastExportDirectory))
                {
                    m_strLastExportDirectory = "";
                }
            }

            // Set the default directory to be the same as the application's directory.
            if (m_strLastExportDirectory == "")
            {
                m_strLastExportDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            }

            tbLocation.Text   = m_strLastExportDirectory;
            rbSprites.Checked = true;

            this.Text += " - " + (Options.Platform == Options.PlatformType.NDS ? "NDS" : "GBA");
        }
Example #10
0
        /// <summary>
        /// Display a warning message using a hard-coded string.
        /// All calls to this routine should be converted to use WarningId()
        /// so that they can be localized.
        /// </summary>
        /// <param name="strFormat">Hard-coded warning message string</param>
        /// <param name="args">Arguments to be folded into the warning string</param>
        public void WarningString(string strFormat, params object[] args)
        {
            string strMessage = String.Format(strFormat, args);

            if (m_form == null)
            {
                System.Console.WriteLine(ResourceMgr.GetString("WARNING") + strMessage);
            }
            else
            {
                ShowMessageCheck = true;
                m_form.Warning(strMessage);
                ShowMessageCheck = false;
            }
        }
Example #11
0
        public Optionbox_Sprite() : base()
        {
            Tools.Add(new Tool("ShowTileScreen", ToolType.ShowTileGrid, 0, 0,
                               ResourceMgr.GetBitmap("tool_largegrid"),
                               Options.BoolOptionName.Sprite_ShowTileGrid));

            Tools.Add(new Tool("ShowPixelGrid", ToolType.ShowPixelGrid, 1, 0,
                               ResourceMgr.GetBitmap("tool_smallgrid"),
                               Options.BoolOptionName.Sprite_ShowPixelGrid));

            Tools.Add(new Tool("ShowPaletteIndex", ToolType.ShowPaletteIndex, 0, 1,
                               ResourceMgr.GetBitmap("tool_number"),
                               Options.BoolOptionName.Sprite_ShowPaletteIndex));

            ToolboxRows = 2;
        }
Example #12
0
        /// <summary>
        /// Display an error string using the given message-id.
        /// </summary>
        /// <param name="strMessageId">The name (message-id) of the string so display</param>
        /// <param name="args">Arguments to be folded into the error string</param>
        public void ErrorId(string strMessageId, params object[] args)
        {
            string strFormat  = ResourceMgr.GetString(strMessageId);
            string strMessage = String.Format(strFormat, args);

            if (m_form == null)
            {
                System.Console.WriteLine(ResourceMgr.GetString("ERROR") + strMessage);
            }
            else
            {
                ShowMessageCheck = true;
                m_form.Error(strMessage);
                ShowMessageCheck = false;
            }
        }
Example #13
0
        private void UpdateSpriteInfo()
        {
            tbName.Text        = m_sprite.Name;
            tbDescription.Text = m_sprite.Description;

            // "{0}x{1} tiles ({2}x{3} pixels)"
            string strFormat = ResourceMgr.GetString("SpriteSizeFormat");

            lSizeData.Text = String.Format(strFormat, m_sprite.TileWidth, m_sprite.TileHeight,
                                           m_sprite.PixelWidth, m_sprite.PixelHeight);

            pbSprite.Invalidate();

            // Enable/disable the next/prev buttons.
            bNext.Enabled = !m_ss.IsLastSprite(m_sprite);
            bPrev.Enabled = !m_ss.IsFirstSprite(m_sprite);
        }
Example #14
0
        private void bBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog SaveFolderDialog = new FolderBrowserDialog();

            //SaveFolderDialog.Description = "Select the directory where you want to store the exported files:";
            SaveFolderDialog.Description  = ResourceMgr.GetString("SelectExportDir");
            SaveFolderDialog.SelectedPath = m_strLastExportDirectory;
            if (SaveFolderDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            tbLocation.Text = SaveFolderDialog.SelectedPath;

            // TODO: verify that the path doesn't contain spaces or punctuation
            if (tbLocation.Text.IndexOfAny(new char[] { ' ' }) != -1)
            {
                //MessageBox.Show("The directory path that you've chosen contains at least one space (' ').\r\nWhile this is a valid Windows path, the spaces will cause problems for the Gameboy/Nintendo DS development tools.\r\nPlease select a path that does not contain these characters.", "Invalid Path", MessageBoxButtons.OK, MessageBoxIcon.Error);
                MessageBox.Show(ResourceMgr.GetString("InvalidPath"), ResourceMgr.GetString("InvalidPathTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #15
0
        public Sprite DuplicateSprite(Sprite sToCopy, UndoMgr undo)
        {
            if (sToCopy == null)
            {
                return(null);
            }

            // Calulate an appropriate name for the copy
            string strNewBaseName;
            int    nCopy = 1;
            string strNewName;
            string strCopySuffix = ResourceMgr.GetString("CopySuffix");
            Match  m             = Regex.Match(sToCopy.Name, String.Format("^(.*){0}([0-9]*)$", strCopySuffix));

            if (m.Success)
            {
                strNewBaseName = String.Format("{0}{1}", m.Groups[1].Value, strCopySuffix);
                if (m.Groups[2].Value != "")
                {
                    nCopy = Int32.Parse(m.Groups[2].Value);
                }
                strNewName = String.Format("{0}{1}", strNewBaseName, ++nCopy);
            }
            else
            {
                strNewBaseName = String.Format("{0}{1}", sToCopy.Name, strCopySuffix);
                strNewName     = strNewBaseName;
            }

            while (HasNamedSprite(strNewName))
            {
                strNewName = String.Format("{0}{1}", strNewBaseName, ++nCopy);
            }

            Sprite sNew = AddSprite(sToCopy.TileWidth, sToCopy.TileHeight, strNewName, NextTileId++, sToCopy.Description, undo);

            sNew.Duplicate(sToCopy);
            return(sNew);
        }
Example #16
0
        private void menuSprite_Delete_Click(object sender, EventArgs e)
        {
            Spriteset ss = ActiveSpriteset();
            Sprite    s  = ActiveSprite();

            if (s == null)
            {
                return;
            }

            if (!s.IsEmpty())
            {
                // "Are you sure you want to delete the currently selected sprite?"
                if (!m_doc.AskYesNo(ResourceMgr.GetString("DeleteCurrentSprite")))
                {
                    return;
                }
            }

            ss.RemoveSelectedSprite(ActiveUndo());
            HandleSpriteDataChanged(ss);
        }
Example #17
0
        private void menuSprite_Clear_Click(object sender, EventArgs e)
        {
            Spriteset ss = ActiveSpriteset();
            Sprite    s  = ActiveSprite();

            if (s == null)
            {
                return;
            }

            if (!s.IsEmpty())
            {
                //if (!AskYesNo("Are you sure you want to erase the data in the currently selected sprite?"))
                if (!AskYesNo(ResourceMgr.GetString("EraseCurrentSprite")))
                {
                    return;
                }
                s.Clear();
                s.RecordUndoAction("clear", ActiveUndo());
                HandleSpriteDataChanged(ss);
            }
        }
Example #18
0
        /// <summary>
        /// Export this document/project as source code.
        /// </summary>
        public void Export()
        {
            string strProjectDir;
            bool   fProject;

            FileHandler.ExportResult result = m_data.Filer.ExportDialog(Name, out strProjectDir, out fProject);

            if (result == FileHandler.ExportResult.Cancel)
            {
                return;
            }

            if (result == FileHandler.ExportResult.OK)
            {
                string        strTarget = (Options.Platform == Options.PlatformType.NDS ? "NDS" : "GBA");
                StringBuilder sb        = new StringBuilder("");
                if (fProject)
                {
                    // "Successfully exported {0} project to "{1}"."
                    sb.Append(String.Format(ResourceMgr.GetString("ExportProjectSuccess"), strTarget, strProjectDir));
                    sb.Append("\r\n");
                    // "Go to this directory and run "make" to build your project."
                    sb.Append(ResourceMgr.GetString("InstrHowToMake"));
                }
                else
                {
                    // "Successfully exported {0} sprite data to "{1}"."
                    sb.Append(String.Format(ResourceMgr.GetString("ExportSpritesSuccess"), strTarget, strProjectDir));
                }
                m_form.Info(sb.ToString());
            }
            else
            {
                // "Unable to export!"
                ErrorId("ExportFail");
            }
        }
Example #19
0
        public bool Close()
        {
            if (m_fHasUnsavedChanges)
            {
                bool fCancel;
                bool fSave = m_doc.AskYesNoCancel(ResourceMgr.GetString("SaveChanges"), out fCancel);
                if (fCancel)
                {
                    return(false);
                }
                if (fSave)
                {
                    if (!SaveFile())
                    {
                        // Implicitly cancel if we were unable to save.
                        return(false);
                    }
                }
            }

            m_strFilename        = "";
            m_fHasUnsavedChanges = false;
            return(true);
        }
Example #20
0
        private bool ExportFromTemplate(string strProjName, string strTemplateFilename, string strOutputFilename, bool fNDS)
        {
            try
            {
                string strExeDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                string strTemplateDir = String.Format("{0}{1}{2}{3}", strExeDir,
                                                      Path.DirectorySeparatorChar,
                                                      "templates",
                                                      Path.DirectorySeparatorChar);

                using (TextReader tr = new StreamReader(strTemplateDir + strTemplateFilename, Encoding.UTF8))
                {
                    using (TextWriter tw = new StreamWriter(strOutputFilename))
                    {
                        Spritesets sprites    = m_doc.Spritesets;
                        Spritesets bgsprites  = m_doc.BackgroundSpritesets;
                        Palettes   palettes   = m_doc.Palettes;
                        Palettes   bgpalettes = m_doc.BackgroundPalettes;
                        Maps       maps       = m_doc.BackgroundMaps;
                        BgImages   bgimages   = m_doc.BackgroundImages;

                        sprites.Export_AssignIDs();
                        bgsprites.Export_AssignIDs();
                        palettes.Export_AssignIDs();
                        bgpalettes.Export_AssignIDs();
                        maps.Export_AssignIDs();
                        bgimages.Export_AssignIDs();

                        string strLine;
                        while ((strLine = tr.ReadLine()) != null)
                        {
                            if (strLine.StartsWith("%%NDS:%%"))
                            {
                                if (fNDS)
                                {
                                    tw.WriteLine(strLine.Substring(8));
                                }
                                continue;
                            }
                            if (strLine.StartsWith("%%GBA:%%"))
                            {
                                if (!fNDS)
                                {
                                    tw.WriteLine(strLine.Substring(8));
                                }
                                continue;
                            }

                            if (strLine == "%%_SPRITE_PALETTE_INFO_%%")
                            {
                                palettes.Export_PaletteInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_PALETTES_%%")
                            {
                                palettes.Export_Palettes(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_PALETTE_INFO_%%")
                            {
                                bgpalettes.Export_PaletteInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_PALETTES_%%")
                            {
                                bgpalettes.Export_Palettes(tw);
                                continue;
                            }

                            if (strLine == "%%_SPRITESET_INFO_%%")
                            {
                                sprites.Export_SpritesetInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITESET_IDS_%%")
                            {
                                sprites.Export_SpritesetIDs(tw);
                                continue;
                            }

                            if (strLine == "%%_SPRITE_INFO_%%")
                            {
                                sprites.Export_SpriteInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_TILES_%%")
                            {
                                sprites.Export_TileData(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_MASKS_%%")
                            {
                                sprites.Export_SpriteMaskData(tw);
                                continue;
                            }
                            if (strLine == "%%_SPRITE_IDS_%%")
                            {
                                sprites.Export_SpriteIDs(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_TILESET_INFO_%%")
                            {
                                bgsprites.Export_BgTilesetInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_TILESET_IDS_%%")
                            {
                                bgsprites.Export_BgTilesetIDs(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_TILES_%%")
                            {
                                bgsprites.Export_TileData(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_TILE_IDS_%%")
                            {
                                bgsprites.Export_TileIDs(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_MAP_INFO_%%")
                            {
                                maps.Export_MapInfo(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_MAP_IDS_%%")
                            {
                                maps.Export_MapIDs(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_MAP_DATA_%%")
                            {
                                maps.Export_MapData(tw);
                                continue;
                            }

                            if (strLine == "%%_BACKGROUND_IMAGE_INFO_%%")
                            {
                                bgimages.Export_BgImageInfo(tw, fNDS);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_IDS_%%")
                            {
                                bgimages.Export_BgImageIDs(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_HEADERS_%%")
                            {
                                bgimages.Export_BgImageHeaders(tw, fNDS);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_PALETTEDATA_%%")
                            {
                                bgimages.Export_BgImagePaletteData(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_DATA_PALETTED_%%")
                            {
                                bgimages.Export_BgImageData_Paletted(tw);
                                continue;
                            }
                            if (strLine == "%%_BACKGROUND_IMAGE_DATA_DIRECT_%%")
                            {
                                bgimages.Export_BgImageData_Direct(tw);
                                continue;
                            }

                            strLine = strLine.Replace("%%_NAME_%%", strProjName);
                            strLine = strLine.Replace("%%_VERSION_%%", ResourceMgr.GetString("Version"));
                            strLine = strLine.Replace("%%_PLATFORM_%%", fNDS ? "NDS" : "GBA");

                            strLine = strLine.Replace("%%_NUM_PALETTES_%%", palettes.NumPalettes.ToString());
                            strLine = strLine.Replace("%%_NUM_SPRITESETS_%%", sprites.NumSpritesets.ToString());
                            strLine = strLine.Replace("%%_NUM_SPRITES_%%", sprites.NumSprites.ToString());
                            strLine = strLine.Replace("%%_NUM_TILES_%%", sprites.NumTiles.ToString());

                            strLine = strLine.Replace("%%_NUM_BACKGROUND_PALETTES_%%", bgpalettes.NumPalettes.ToString());
                            strLine = strLine.Replace("%%_NUM_BACKGROUND_TILESETS_%%", bgsprites.NumSpritesets.ToString());
                            strLine = strLine.Replace("%%_NUM_BACKGROUND_TILES_%%", bgsprites.NumTiles.ToString());

                            strLine = strLine.Replace("%%_NUM_BACKGROUND_MAPS_%%", maps.NumMaps.ToString());

                            strLine = strLine.Replace("%%_NUM_BACKGROUND_IMAGES_%%", bgimages.NumImages.ToString());

                            tw.WriteLine(strLine);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // "An exception was thrown while load the project template files: {0}"
                m_doc.ErrorId("ExceptionLoadTemplate", ex.Message);
                // "An exception was thrown while opening the project file for writing: {0}"
                //m_doc.ErrorId("ExceptionOpenProjectWrite", ex.Message);
                return(false);
            }

            return(true);
        }
Example #21
0
 public void NYI()
 {
     // "Sorry - Not Yet Implemented"
     MessageBox.Show(ResourceMgr.GetString("NYI"), AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Example #22
0
        public bool Resize(int tileWidth, int tileHeight)
        {
            // If the new size == the old size
            if (tileWidth == m_tileWidth && tileHeight == m_tileHeight)
            {
                return(false);
            }

            int oldX      = m_tileWidth;                // AKA: TileWidth
            int oldY      = m_tileHeight;               // AKA: TileHeight
            int old_tiles = m_tileWidth * m_tileHeight; // AKA: NumTiles
            int newX      = tileWidth;
            int newY      = tileHeight;
            int new_tiles = tileWidth * tileHeight;

            // If we are clipping any tiles with the new size
            if (oldX > newX || oldY > newY)
            {
                // Check to see if any of the clipped tiles contain data
                bool fHasData = false;

                // Handle case where the old sprite is wider than the new sprite:
                // e.g. old=4,2  xxOO     old=4,2  xxOO    old=4,4  xxOO
                //      new=2,4  xxOO     new=2,2  xxOO    new=2,2  xxOO
                //               nn                                 ooOO
                //               nn                                 ooOO
                // (O = tile only in old sprite - checked by this loop,
                //  o = tile only in old sprite - NOT checked by this loop,
                //  n = tile only in new sprite - not checked,
                //  x = tile shared in both sprites - not checked)
                for (int ix = newX; ix < oldX; ix++)
                {
                    for (int iy = 0; iy < oldY; iy++)
                    {
                        if (!m_Tiles[(iy * oldX) + ix].IsEmpty())
                        {
                            fHasData = true;
                        }
                    }
                }

                // Handle the case where the old sprite is taller than the new sprite:
                // e.g. old=2,4  xxnn     old=2,4  xx      old=4,4  xxoo
                //      new=4,2  xxnn     new=2,2  xx      new=2,2  xxoo
                //               OO                OO               OOoo
                //               OO                OO               OOoo
                // Note that we can cut the x-loop short when oldX > newX since we've covered that case
                // in the above loop.
                int minX = (oldX < newX ? oldX : newX);
                for (int iy = newY; iy < oldY; iy++)
                {
                    for (int ix = 0; ix < minX; ix++)
                    {
                        if (!m_Tiles[(iy * oldX) + ix].IsEmpty())
                        {
                            fHasData = true;
                        }
                    }
                }

                // Make sure it's OK with the user before discarding clipped data
                //if (fHasData && !m_doc.AskYesNo("Resizing the sprite will cause some tiles to be clipped and the associated data will be lost.\nAre you sure you want to resize the sprite?"))
                if (fHasData && !m_doc.AskYesNo(ResourceMgr.GetString("WarnSpriteResizeClip")))
                {
                    return(false);
                }
            }

            // Allocate the new tiles (copying over from the current tiles as needed)
            Tile[] newTiles = new Tile[new_tiles];
            for (int ix = 0; ix < newX; ix++)
            {
                for (int iy = 0; iy < newY; iy++)
                {
                    newTiles[(iy * newX) + ix] = new Tile(this, m_ss.NextTileId++);
                    if (ix < oldX && iy < oldY)
                    {
                        newTiles[(iy * newX) + ix].CopyData(m_Tiles[(iy * oldX) + ix]);
                    }
                }
            }

            // Switch over to the newly resized tile data
            m_tileWidth  = newX;
            m_tileHeight = newY;
            m_Tiles      = newTiles;

            return(true);
        }