コード例 #1
0
ファイル: FileHandler_Load.cs プロジェクト: nnn1590/spritely
            public void Test_LoadXML_OLD_palettes_valid()
            {
                // Valid old palette.
                XmlElement xnPalettes = m_xd.CreateElement("palettes");

                for (int id = 0; id < 16; id++)
                {
                    Test_LoadXML_OLD_palettes_AddSubpalette(xnPalettes, id, 16);
                }
                Assert.IsTrue(m_filer.LoadXML_OLD_palettes(xnPalettes.ChildNodes, m_doc.Palettes, Options.DefaultPaletteName));

                Assert.AreEqual(1, m_doc.Palettes.NumPalettes);
                Palette16 p = m_doc.Palettes.GetPalette(0) as Palette16;

                Assert.IsNotNull(p);

                // Verify the colors are the same ones from the XML:
                // Color 0 is the same as the subpalette id
                Assert.AreEqual(0, p.GetSubpalette(0).Encoding(0));
                Assert.AreEqual(4, p.GetSubpalette(4).Encoding(0));
                // Other colors are the same as the color index
                Assert.AreEqual(3, p.GetSubpalette(0).Encoding(3));
                Assert.AreEqual(7, p.GetSubpalette(6).Encoding(7));
                Assert.AreEqual(12, p.GetSubpalette(8).Encoding(12));
            }
コード例 #2
0
ファイル: Document.cs プロジェクト: nnn1590/spritely
        /// <summary>
        /// Add a default sprite to the new document when Spritely is first launched.
        /// This is so that first-time users don't see an empty window - they can
        /// start editing their first sprite immediately.
        /// </summary>
        public void InitializeEmptyDocument()
        {
            // Palettes
            Palette16 pal = m_data.Palettes.AddPalette16(Options.DefaultPaletteName, 0, "");

            pal.SetDefaultPalette();

            // Spritesets
            Spriteset ss = m_data.Spritesets.AddSpriteset(Options.DefaultSpritesetName, Options.DefaultPaletteId, "", pal);

            // Add a single 2x2 sprite.
            ss.AddSprite(2, 2, "", -1, "", 0, null);
            ss.SelectFirstSprite();

            // Background palettes
            Palette16 bgpal = m_data.BackgroundPalettes.AddPalette16(Options.DefaultBgPaletteName, 0, "");

            bgpal.SetDefaultPalette();

            // Background tiles (bgsprites and bgtilegroups)
            Spriteset bss = m_data.BackgroundSpritesets.AddSpriteset(Options.DefaultBgTilesetName, Options.DefaultBgPaletteId, "", bgpal);

            // Add a single blank background tile.
            bss.AddSprite(1, 1, "", -1, "", 0, null);
            bss.SelectFirstSprite();

            // Background tile map
            m_data.BackgroundMaps.AddMap("map", 0, "", m_data.BackgroundSpritesets.Current);

            // The sprites we just added above don't count as document changes.
            HasUnsavedChanges = false;
        }
コード例 #3
0
            public void Test_LoadXML_palette16_valid()
            {
                Palette16 p = m_doc.Palettes.AddPalette16("pal16", 0, "");

                Assert.IsNotNull(p);

                // Valid palette16.
                XmlElement xnPalette16 = m_xd.CreateElement("palette16");

                // Attributes on palette are not needed for test:
                //xnPalette16.SetAttribute("name", "pal16");
                //xnPalette16.SetAttribute("id", "0");
                //xnPalette16.SetAttribute("desc", "");
                for (int id = 0; id < 16; id++)
                {
                    Test_LoadXML_palette16_AddSubpalette(xnPalette16, id, 16);
                }

                Assert.IsTrue(p.LoadXML_palette16(xnPalette16));

                // Verify the colors are the same ones from the XML:
                // Each component of Color 0 is the same as the subpalette id
                Assert.AreEqual(0, p.GetSubpalette(0).Red(0));
                Assert.AreEqual(4, p.GetSubpalette(4).Green(0));
                // Components of other colors are the same as the color index
                Assert.AreEqual(3, p.GetSubpalette(0).Red(3));
                Assert.AreEqual(7, p.GetSubpalette(6).Green(7));
                Assert.AreEqual(12, p.GetSubpalette(8).Blue(12));
            }
コード例 #4
0
        public Palette16Form(ProjectMainForm parent, Palette16 p)
        {
            m_parent = parent;
            m_palette = p;

            InitializeComponent();

            MdiParent = parent;
            FormBorderStyle = FormBorderStyle.FixedToolWindow;
            StartPosition = FormStartPosition.Manual;
            Visible = false;
            ControlBox = false;

            if (m_palette.IsBackground)
                Text = "BgPalette '" + p.Name + "'";
            else
                Text = "Palette '" + p.Name + "'";

            if (m_brushTransparent == null)
            {
                m_brushTransparent = new System.Drawing.Drawing2D.HatchBrush(
                        Options.TransparentPattern,
                        Color.LightGray, Color.Transparent);
            }
        }
コード例 #5
0
ファイル: Palettes.cs プロジェクト: nnn1590/spritely
        public bool LoadXML_palettes(XmlNode xnode)
        {
            foreach (XmlNode xn in xnode.ChildNodes)
            {
                switch (xn.Name)
                {
                case "palette16":
                    string strName = XMLUtils.GetXMLAttribute(xn, "name");
                    int    id      = XMLUtils.GetXMLIntegerAttribute(xn, "id");
                    string strDesc = XMLUtils.GetXMLAttribute(xn, "desc");

                    Palette16 p = AddPalette16(strName, id, strDesc);
                    if (!p.LoadXML_palette16(xn))
                    {
                        return(false);
                    }
                    break;

                case "palette256":
                    // NYI - ignore
                    break;
                }
            }
            return(true);
        }
コード例 #6
0
        public Palette16Form(ProjectMainForm parent, Palette16 p)
        {
            m_parent  = parent;
            m_palette = p;

            InitializeComponent();

            MdiParent       = parent;
            FormBorderStyle = FormBorderStyle.FixedToolWindow;
            StartPosition   = FormStartPosition.Manual;
            Visible         = false;
            ControlBox      = false;

            if (m_palette.IsBackground)
            {
                Text = "BgPalette '" + p.Name + "'";
            }
            else
            {
                Text = "Palette '" + p.Name + "'";
            }

            if (m_brushTransparent == null)
            {
                m_brushTransparent = new System.Drawing.Drawing2D.HatchBrush(
                    Options.TransparentPattern,
                    Color.LightGray, Color.Transparent);
            }
        }
コード例 #7
0
ファイル: Palettes.cs プロジェクト: jduranmaster/spritely
        public Palette16 AddPalette16(string strName, int id, string strDesc)
        {
            // Don't allow a second palette with the same name.
            if (m_palettes.ContainsKey(id))
                return null;

            Palette16 pal16 = new Palette16(m_doc, this, strName, id, strDesc);
            m_palettes.Add(id, pal16);
            m_paletteCurrent = pal16;
            return pal16;
        }
コード例 #8
0
            public void Test_LoadXML_palette16_invalidid()
            {
                Palette16 p16 = m_doc.Palettes.AddPalette16("pal16", 0, "");

                Assert.IsNotNull(p16);

                // Invalid palette id (145)
                XmlElement xnPalette16 = m_xd.CreateElement("palette16");

                Test_LoadXML_palette16_AddSubpalette(xnPalette16, 145, 16);

                Assert.IsFalse(p16.LoadXML_palette16(xnPalette16));
            }
コード例 #9
0
ファイル: Palettes.cs プロジェクト: nnn1590/spritely
        public Palette16 AddPalette16(string strName, int id, string strDesc)
        {
            // Don't allow a second palette with the same name.
            if (m_palettes.ContainsKey(id))
            {
                return(null);
            }

            Palette16 pal16 = new Palette16(m_doc, this, strName, id, strDesc);

            m_palettes.Add(id, pal16);
            m_paletteCurrent = pal16;
            return(pal16);
        }
コード例 #10
0
            public void Test_LoadXML_palette16_17colors()
            {
                Palette16 p = m_doc.Palettes.AddPalette16("pal16", 0, "");

                Assert.IsNotNull(p);

                // 17 colors in each subpalette
                XmlElement xnPalette16 = m_xd.CreateElement("palette16");

                for (int id = 0; id < 16; id++)
                {
                    Test_LoadXML_palette16_AddSubpalette(xnPalette16, id, 17);
                }

                Assert.IsFalse(p.LoadXML_palette16(xnPalette16));
            }
コード例 #11
0
ファイル: FileHandler_Load.cs プロジェクト: nnn1590/spritely
        private bool LoadXML(XmlNodeList xnl)
        {
            m_fFoundSpritePalettes     = false;
            m_fFoundSprites            = false;
            m_fFoundBackgroundPalettes = false;
            m_fFoundBackgroundSprites  = false;
            m_fFoundBackgroundMap      = false;

            foreach (XmlNode xn in xnl)
            {
                // Old version 1 file format.
                if (xn.Name == "gba_tileset"
                    // Obsolete name for gba_tileset.
                    // No longer used - included for backwards compatibility.
                    || xn.Name == "gba_sprite_collection"
                    )
                {
                    if (!LoadXML_OLD_gba_tileset(xn.ChildNodes))
                    {
                        return(false);
                    }
                }

                // Version 2 files.
                if (xn.Name == "spritely")
                {
                    if (!LoadXML_spritely(xn))
                    {
                        return(false);
                    }
                }
            }

            if (!m_fFoundSpritePalettes)
            {
                Palette16 pal = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, "");
                pal.SetDefaultPalette();
            }
            if (!m_fFoundSprites)
            {
                Palette pal = m_doc.Palettes.GetPalette(0);
                m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, Options.DefaultPaletteId, "", pal);
            }
            if (!m_fFoundBackgroundPalettes)
            {
                Palette16 bgpal = m_doc.BackgroundPalettes.AddPalette16(Options.DefaultBgPaletteName, 0, "");
                bgpal.SetDefaultPalette();
            }
            if (!m_fFoundBackgroundSprites)
            {
                Palette bgpal = m_doc.BackgroundPalettes.GetPalette(0);
                m_doc.BackgroundSpritesets.AddSpriteset(Options.DefaultBgPaletteName, Options.DefaultBgPaletteId, "", bgpal);
                m_doc.BackgroundSpritesets.Current.AddSprite(1, 1, "", -1, "", 0, null);
            }
            if (!m_fFoundBackgroundMap)
            {
                m_doc.BackgroundMaps.AddMap("map", 0, "", m_doc.BackgroundSpritesets.Current);
            }

            // Remove any UndoActions since we just loaded from a file.
            m_doc.Owner.ClearUndo();
            m_doc.RecordSnapshot();
            return(true);
        }
コード例 #12
0
ファイル: FileHandler_Load.cs プロジェクト: nnn1590/spritely
        private bool LoadXML_OLD_palettes(XmlNodeList xnl, Palettes palettes, string strName)
        {
            Palette16 palette     = palettes.AddPalette16(strName, 0, "");
            int       nSubpalette = 0;

            foreach (XmlNode xn in xnl)
            {
                if (xn.Name == "palette")
                {
                    int nSubpaletteId = XMLUtils.GetXMLIntegerAttribute(xn, "id");
                    if (nSubpalette > 16)
                    {
                        // Incorrect number of subpalettes - too many.
                        m_doc.ErrorString("Too many subpalettes specified for palette (expected 16)");
                        return(false);
                    }
                    if (nSubpaletteId != nSubpalette)
                    {
                        // Subpalettes out of order.
                        m_doc.ErrorString("Subpalette ids are out of order");
                        return(false);
                    }

                    int[] anPalette  = new int[16];
                    int   nCurrEntry = 0;

                    Regex rxPalette = new Regex(@"\s*0x([0-9A-Fa-f]{4})\s*,");
                    Match mxPalette = rxPalette.Match(xn.InnerText);
                    if (mxPalette.Success)
                    {
                        while (mxPalette.Success)
                        {
                            GroupCollection matchGroups = mxPalette.Groups;

                            if (nCurrEntry >= 16)
                            {
                                // Wrong number of colors in palette - too many.
                                m_doc.ErrorString("Too many colors specified for subpalette {0} (expected 16)", nSubpaletteId);
                                return(false);
                            }

                            anPalette[nCurrEntry] = Convert.ToInt32(matchGroups[1].Value, 16);
                            nCurrEntry++;
                            if (nCurrEntry == 16)
                            {
                                // After we've read 16 colors, update the subpalette.
                                if (!palette.ImportSubpalette(nSubpaletteId, anPalette))
                                {
                                    // Warning/Error message already displayed.
                                    return(false);
                                }

                                // Since we just loaded from a file, update the snapshot without creating an UndoAction
                                palette.GetSubpalette(nSubpaletteId).RecordSnapshot();
                            }

                            // Get the next match.
                            mxPalette = mxPalette.NextMatch();
                        }

                        if (nCurrEntry != 16)
                        {
                            // "Wrong number of colors in palette with ID='{0}'. Found {1}, expected 16."
                            m_doc.ErrorId("ErrorNumColorsInPalette", nSubpaletteId, nCurrEntry);
                            return(false);
                        }
                    }
                    nSubpalette++;
                }
            }

            if (nSubpalette != 16)
            {
                // Incorrect number of subpalettes - too few.
                m_doc.ErrorString("Too few subpalettes (expected 16)");
                return(false);
            }

            return(true);
        }
コード例 #13
0
        /// <summary>
        /// Enable/disable menu items as appropriate
        /// </summary>
        private void ActivateMenuItems()
        {
            bool fHasDoc        = m_doc != null;
            bool fSpriteEditing = m_tabCurrent.Id == TabMgr.TabId.Sprites || m_tabCurrent.Id == TabMgr.TabId.BackgroundMaps;

            // Enable/disable File menu items
            menuFile.Enabled             = true;
            menuFile_New.Enabled         = true;
            menuFile_Open.Enabled        = true;
            menuFile_Close.Enabled       = fHasDoc;
            menuFile_Save.Enabled        = fHasDoc;
            menuFile_SaveAs.Enabled      = fHasDoc;
            menuFile_Export.Enabled      = fHasDoc;
            menuFile_RecentFiles.Enabled = (m_recent.Count != 0);
            menuFile_Exit.Enabled        = true;

            menuEdit.Enabled = true;
            UndoMgr undo     = ActiveUndo();
            bool    fCanUndo = fHasDoc && undo != null && undo.CanUndo();
            bool    fCanRedo = fHasDoc && undo != null && undo.CanRedo();

            menuEdit_Undo.Enabled  = fCanUndo;
            menuEdit_Redo.Enabled  = fCanRedo;
            menuEdit_Cut.Enabled   = false;
            menuEdit_Copy.Enabled  = false;
            menuEdit_Paste.Enabled = false;

            menuProject.Enabled                        = true;
            menuProject_Platform.Enabled               = true;
            menuProject_Platform_GBA.Enabled           = true;
            menuProject_Platform_GBA.Checked           = Options.Platform == Options.PlatformType.GBA;
            menuProject_Platform_NDS.Enabled           = true;
            menuProject_Platform_NDS.Checked           = Options.Platform == Options.PlatformType.NDS;
            menuProject_Palettes.Enabled               = true;
            menuProject_Palettes_New.Enabled           = false;
            menuProject_Spritesets.Enabled             = true;
            menuProject_Spritesets_New.Enabled         = false;
            menuProject_BackgroundPalettes.Enabled     = true;
            menuProject_BackgroundPalettes_New.Enabled = false;
            menuProject_BackgroundTilesets.Enabled     = true;
            menuProject_BackgroundTilesets_New.Enabled = false;
            menuProject_BackgroundMaps.Enabled         = true;
            menuProject_BackgroundMaps_New.Enabled     = false;

            // Enable/disable Sprite menu items
            menuSprite.Enabled = true;
            Sprite s = ActiveSprite();

            if (s != null)
            {
                menuSprite_New.Enabled       = true;
                menuSprite_Duplicate.Enabled = true;
                menuSprite_Clear.Enabled     = !s.IsEmpty();
                menuSprite_Resize.Enabled    = true;
                menuSprite_Delete.Enabled    = true;

                menuSprite_Resize_1x1.Enabled = !s.IsSize(1, 1);
                menuSprite_Resize_1x2.Enabled = !s.IsSize(1, 2);
                menuSprite_Resize_1x4.Enabled = !s.IsSize(1, 4);
                menuSprite_Resize_2x1.Enabled = !s.IsSize(2, 1);
                menuSprite_Resize_2x2.Enabled = !s.IsSize(2, 2);
                menuSprite_Resize_2x4.Enabled = !s.IsSize(2, 4);
                menuSprite_Resize_4x1.Enabled = !s.IsSize(4, 1);
                menuSprite_Resize_4x2.Enabled = !s.IsSize(4, 2);
                menuSprite_Resize_4x4.Enabled = !s.IsSize(4, 4);

                //bool fFirst, fLast;
                //tab.SpriteList.IsFirstLastSpriteOfType(s, out fFirst, out fLast);
                menuSprite_Properties.Enabled              = true;
                menuSprite_Rotate.Enabled                  = true;
                menuSprite_Rotate_Clockwise.Enabled        = true;
                menuSprite_Rotate_Counterclockwise.Enabled = true;
                menuSprite_Flip.Enabled             = true;
                menuSprite_Flip_Horizontal.Enabled  = true;
                menuSprite_Flip_Vertical.Enabled    = true;
                menuSprite_Arrange.Enabled          = false;
                menuSprite_Arrange_MoveUp.Enabled   = false;              // !fFirst;
                menuSprite_Arrange_MoveDown.Enabled = false;              // !fLast;
            }
            else
            {
                // The 'new sprite' option is always enabled when were in sprite editing mode.
                menuSprite_New.Enabled = fHasDoc && fSpriteEditing;

                // Disable all sprite editing options if there is no sprite selection or
                // if we're not editing sprites.
                menuSprite_Duplicate.Enabled               = false;
                menuSprite_Clear.Enabled                   = false;
                menuSprite_Resize.Enabled                  = false;
                menuSprite_Delete.Enabled                  = false;
                menuSprite_Properties.Enabled              = false;
                menuSprite_Rotate.Enabled                  = false;
                menuSprite_Rotate_Clockwise.Enabled        = false;
                menuSprite_Rotate_Counterclockwise.Enabled = false;
                menuSprite_Flip.Enabled             = false;
                menuSprite_Flip_Horizontal.Enabled  = false;
                menuSprite_Flip_Vertical.Enabled    = false;
                menuSprite_Arrange.Enabled          = false;
                menuSprite_Arrange_MoveUp.Enabled   = false;
                menuSprite_Arrange_MoveDown.Enabled = false;
            }

            // Enable/disable Palette menu items
            menuPalette.Enabled = true;
            Palette p             = ActivePalette();
            bool    fValidPalette = false;

            if (p.PaletteType == Palette.Type.Color16)
            {
                Palette16 p16 = p as Palette16;
                if (p16.GetCurrentSubpalette() != null)
                {
                    fValidPalette = true;
                }
            }
            else
            {
                fValidPalette = true;
            }
            if (fValidPalette)
            {
                menuPalette_Copy.Enabled         = false;
                menuPalette_Paste.Enabled        = false;
                menuPalette_Clear.Enabled        = false;
                menuPalette_ViewEncoding.Enabled = fSpriteEditing;
                menuPalette_Color.Enabled        = false;
                menuPalette_Color_Copy.Enabled   = false;
                menuPalette_Color_Paste.Enabled  = false;
                menuPalette_Color_Clear.Enabled  = false;
            }
            else
            {
                menuPalette_Copy.Enabled         = false;
                menuPalette_Paste.Enabled        = false;
                menuPalette_Clear.Enabled        = false;
                menuPalette_ViewEncoding.Enabled = false;
                menuPalette_Color.Enabled        = false;
                menuPalette_Color_Copy.Enabled   = false;
                menuPalette_Color_Paste.Enabled  = false;
                menuPalette_Color_Clear.Enabled  = false;
            }

            menuWindow.Enabled         = true;
            menuWindow_Arrange.Enabled = fHasDoc;

            menuHelp.Enabled       = true;
            menuHelp_About.Enabled = true;

            // Used for debugging only - set to false for release builds.
            menuTest.Visible = Options.DEBUG;
            menuTest_RunUnittests.Visible    = true;
            menuTest_ShowUndoHistory.Visible = true;
            menuTest_ShowUndoHistory.Checked = UndoHistoryVisible;
            menuTest_CollisionTest.Visible   = true;
        }