Esempio n. 1
0
        public void RecordUndoAction(string strDesc, UndoMgr undo)
        {
            if (undo == null)
            {
                return;
            }

            PaletteColorData            data   = GetUndoData();
            UndoAction_Subpalette16Edit action = new UndoAction_Subpalette16Edit(undo, this, m_snapshot, data, strDesc);
            bool fHandled = false;

            if (action.IsSelectionChange())
            {
                // Ignore selection changes
                fHandled = true;
            }
            else
            {
                // If the last undo action is also a PaletteEdit, try to merge them together
                UndoAction_Subpalette16Edit last_action = undo.GetCurrent() as UndoAction_Subpalette16Edit;
                if (last_action != null)
                {
                    // Merge 2 color changes (as long as they edit the same color)
                    int last_color, last_color_val1, last_color_val2;
                    int this_color, this_color_val1, this_color_val2;
                    if (last_action.IsColorChange(out last_color, out last_color_val1, out last_color_val2) &&
                        action.IsColorChange(out this_color, out this_color_val1, out this_color_val2)
                        )
                    {
                        if (last_color == this_color)
                        {
                            // If this color change takes it back to the original value, then
                            // delete the UndoAction.
                            if (last_color_val1 == this_color_val2)
                            {
                                undo.DeleteCurrent();
                            }
                            else
                            {
                                last_action.UpdateRedoData(data);
                            }
                            fHandled = true;
                        }
                    }
                }
            }
            if (!fHandled)
            {
                undo.Push(action);
            }

            // Update the snapshot for the next UndoAction
            RecordSnapshot();
        }
Esempio n. 2
0
        private Sprite AddSprite_2(Sprite s, List <Sprite> slist, UndoMgr undo)
        {
            slist.Add(s);

            m_nSprites++;
            m_nTiles += (s.TileWidth * s.TileHeight);

            if (undo != null)
            {
                undo.Push(new UndoAction_AddSprite(undo, this, s, true));
            }

            if (m_doc.Owner != null)
            {
                m_doc.Owner.HandleSpriteTypeChanged(this);
            }
            return(s);
        }
Esempio n. 3
0
        public void RecordUndoAction(string strDesc, UndoMgr undo)
        {
            if (undo == null)
            {
                return;
            }

            UndoData data = GetUndoData();

            // Don't record anything if there aren't any changes
            if (!data.Equals(m_snapshot))
            {
                UndoAction_MapEdit action = new UndoAction_MapEdit(undo, this, m_snapshot, data, strDesc);
                undo.Push(action);

                // Update the snapshot for the next UndoAction
                RecordSnapshot();
            }
        }
Esempio n. 4
0
        public void RemoveSprite(Sprite sToRemove, UndoMgr undo)
        {
            SpriteType stToRemove = null;
            Sprite     sPrev = null, sCurr = null, sNext = null;
            Sprite     sNewSelection = null;

            if (sToRemove == null)
            {
                return;
            }

            // Determine which sprite should be selected when this one is removed.
            foreach (SpriteType st in SpriteTypes)
            {
                if (sNewSelection != null)
                {
                    break;
                }

                foreach (Sprite s in st.Sprites)
                {
                    sPrev = sCurr;
                    sCurr = sNext;
                    sNext = s;
                    if (s == sToRemove)
                    {
                        stToRemove = st;
                    }
                    if (sCurr == sToRemove)
                    {
                        sNewSelection = sNext;
                        break;
                    }
                }
            }
            // If the last sprite is deleted, select the one before it.
            if (sNext == sToRemove)
            {
                sNewSelection = sCurr;
            }

            int nTiles = sToRemove.NumTiles;

            if (stToRemove == null)
            {
                return;
            }

            if (stToRemove.Sprites.Remove(sToRemove))
            {
                CurrentSprite = null;
                if (undo != null)
                {
                    CurrentSprite = undo.FindMostRecentSprite();
                }
                if (CurrentSprite == null)
                {
                    CurrentSprite = sNewSelection;
                }

                m_nSprites--;
                m_nTiles -= nTiles;

                if (undo != null)
                {
                    undo.Push(new UndoAction_AddSprite(undo, this, sToRemove, false));
                }

                if (m_doc.Owner != null)
                {
                    m_doc.Owner.HandleSpriteTypeChanged(this);
                }
            }

            foreach (Map m in m_Maps)
            {
                m.RemoveSpriteTilesFromMap(sToRemove);
            }
        }
Esempio n. 5
0
        public void RecordUndoAction(string strDesc, UndoMgr undo)
        {
            if (undo == null)
                return;

            PaletteColorData data = GetUndoData();
            UndoAction_Subpalette16Edit action = new UndoAction_Subpalette16Edit(undo, this, m_snapshot, data, strDesc);
            bool fHandled = false;

            if (action.IsSelectionChange())
            {
                // Ignore selection changes
                fHandled = true;
            }
            else
            {
                // If the last undo action is also a PaletteEdit, try to merge them together
                UndoAction_Subpalette16Edit last_action = undo.GetCurrent() as UndoAction_Subpalette16Edit;
                if (last_action != null)
                {
                    // Merge 2 color changes (as long as they edit the same color)
                    int last_color, last_color_val1, last_color_val2;
                    int this_color, this_color_val1, this_color_val2;
                    if (last_action.IsColorChange(out last_color, out last_color_val1, out last_color_val2)
                        && action.IsColorChange(out this_color, out this_color_val1, out this_color_val2)
                        )
                    {
                        if (last_color == this_color)
                        {
                            // If this color change takes it back to the original value, then
                            // delete the UndoAction.
                            if (last_color_val1 == this_color_val2)
                                undo.DeleteCurrent();
                            else
                                last_action.UpdateRedoData(data);
                            fHandled = true;
                        }
                    }
                }
            }
            if (!fHandled)
                undo.Push(action);

            // Update the snapshot for the next UndoAction
            RecordSnapshot();
        }
Esempio n. 6
0
        public void RecordUndoAction(string strDesc, UndoMgr undo)
        {
            if (undo == null)
                return;

            UndoData data = GetUndoData();

            // Don't record anything if there aren't any changes
            if (!data.Equals(m_snapshot))
            {
                UndoAction_SpriteEdit action = new UndoAction_SpriteEdit(undo, m_ss, this, m_snapshot, data, strDesc);
                undo.Push(action);

                // Update the snapshot for the next UndoAction
                RecordSnapshot();
            }
        }
Esempio n. 7
0
        private Sprite AddSprite_2(Sprite s, List<Sprite> slist, UndoMgr undo)
        {
            slist.Add(s);

            m_nSprites++;
            m_nTiles += (s.TileWidth * s.TileHeight);

            if (undo != null)
                undo.Push(new UndoAction_AddSprite(undo, this, s, true));

            if (m_doc.Owner != null)
                m_doc.Owner.HandleSpriteTypeChanged(this);
            return s;
        }
Esempio n. 8
0
        public void RemoveSprite(Sprite sToRemove, UndoMgr undo)
        {
            SpriteType stToRemove = null;
            Sprite sPrev = null, sCurr = null, sNext = null;
            Sprite sNewSelection = null;

            if (sToRemove == null)
                return;

            // Determine which sprite should be selected when this one is removed.
            foreach (SpriteType st in SpriteTypes)
            {
                if (sNewSelection != null)
                    break;

                foreach (Sprite s in st.Sprites)
                {
                    sPrev = sCurr;
                    sCurr = sNext;
                    sNext = s;
                    if (s == sToRemove)
                        stToRemove = st;
                    if (sCurr == sToRemove)
                    {
                        sNewSelection = sNext;
                        break;
                    }
                }
            }
            // If the last sprite is deleted, select the one before it.
            if (sNext == sToRemove)
                sNewSelection = sCurr;

            int nTiles = sToRemove.NumTiles;
            if (stToRemove == null)
                return;

            if (stToRemove.Sprites.Remove(sToRemove))
            {
                CurrentSprite = null;
                if (undo != null)
                    CurrentSprite = undo.FindMostRecentSprite();
                if (CurrentSprite == null)
                    CurrentSprite = sNewSelection;

                m_nSprites--;
                m_nTiles -= nTiles;

                if (undo != null)
                    undo.Push(new UndoAction_AddSprite(undo, this, sToRemove, false));

                if (m_doc.Owner != null)
                    m_doc.Owner.HandleSpriteTypeChanged(this);
            }

            foreach (Map m in m_Maps)
            {
                m.RemoveSpriteTilesFromMap(sToRemove);
            }
        }