Example #1
0
        private void WldView_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.Modifiers == Keys.Control)
            {
                switch (e.KeyCode)
                {

                    case Keys.S:
                        Save();
                        break;

                    case Keys.G:
                        TsbGrid.Checked = !TsbGrid.Checked;
                        break;

                    case Keys.X:
                        Cut();
                        break;

                    case Keys.C:
                        Copy();
                        break;

                    case Keys.V:
                        Paste(useTransparentTile);
                        break;

                    case Keys.D:
                        ToggleRightClickMode();
                        break;

                    case Keys.Z:
                        Undo();
                        break;
                }
            }
            else
            {
                switch (e.KeyCode)
                {
                    case Keys.Delete:

                        if (CurrentSprite != null && EditMode == EditMode.Sprites)
                        {
                            CurrentWorld.SpriteData.Remove(CurrentSprite);
                            WldView.DelayDrawing = true;
                            WldView.ClearSelection();
                            WldView.DelayDrawing = false;
                            WldView.UpdateSprites();
                            CurrentSprite = null;
                        }
                        else if (EditMode == EditMode.Tiles && TileDrawMode == TileDrawMode.Selection)
                        {
                            DeleteTiles();
                        }
                        else if (EditMode == EditMode.Pointers)
                        {
                            DeleteCurrentPointer();
                        }
                        break;

                    case Keys.Escape:
                        ContinueDrawing = false;
                        WldView.ClearSelection();
                        WldView.ClearLine();
                        if (TileDrawMode == TileDrawMode.Selection)
                            TileDrawMode = PreviousMode;
                        break;
                }
            }
        }
Example #2
0
        private void LoadSpriteSelector()
        {
            SpriteViewer spViewer = new SpriteViewer(8);
            spViewer.IsViewingMapSprites = true;
            spViewer.SpecialPalette = ProjectController.SpecialManager.SpecialPalette;

            int x = 0;
            List<Sprite> CurrentList = new List<Sprite>();
            foreach (var ks in ProjectController.SpriteManager.MapSpriteDefinitions.Values)
            {
                Sprite next = new Sprite();
                next.IsMapSprite = true;
                next.X = x;
                next.Y = 0;
                next.InGameID = ks.InGameId;
                CurrentList.Add(next);
                x += next.Width + 1;
            }

            spViewer.SpriteList = CurrentList;
            spViewer.Location = new Point(0, 0);
            SpriteViewers.Add(spViewer);
            spViewer.CurrentPalette = CurrentPalette;
            spViewer.UpdateSprites();
            spViewer.SelectionChanged += new EventHandler<TEventArgs<Sprite>>(spViewer_SelectionChanged);

            TabPage tPage = new TabPage();
            tPage.Text = "Map";
            tPage.AutoScroll = true;
            tPage.Controls.Add(spViewer);

            TabClass1.TabPages.Add(tPage);
        }
Example #3
0
 private void spViewer_SelectionChanged(object sender, TEventArgs<Sprite> e)
 {
     CurrentSelectorSprite = e.Data;
     if (CurrentSelectorSprite != null)
     {
         foreach (var sp in SpriteViewers)
         {
             if (sp.SelectedSprite != CurrentSelectorSprite)
             {
                 sp.SelectedSprite = null;
             }
         }
         LblSpriteSelected.Text = "Sprite: " + CurrentSelectorSprite.InGameID.ToHexString() + " - " + CurrentSelectorSprite.Name;
     }
     else
     {
         LblSpriteSelected.Text = "None";
     }
 }
Example #4
0
        private void LvlView_MouseDown(object sender, MouseEventArgs e)
        {
            int x = (e.X / 16) / LvlView.Zoom;
            int y = (e.Y / 16) / LvlView.Zoom;
            PnlView.Focus();

            vMirrorButton.Enabled = hMirrorButton.Enabled = false;
            if (x < 0 || x >= CurrentLevel.Width || y < 0 || y >= CurrentLevel.Height)
                return;

            if (_SelectingStartPositionMode)
            {
                int oldX = CurrentLevel.XStart;
                int oldY = CurrentLevel.YStart;
                CurrentLevel.XStart = x;
                CurrentLevel.YStart = y;
                if (TsbStartPoint.Checked)
                {
                    LvlView.UpdatePoint(x, y);
                    LvlView.UpdatePoint(oldX, oldY);
                }
                _SelectingStartPositionMode = false;
                TlsTileCommands.Enabled = TlsDrawing.Enabled = TabLevelInfo.Enabled = true;
                SetHelpText(PreviousHelperText);
                LblStartPoint.Text = string.Format("X: {0} Y: {1}", CurrentLevel.XStart.ToHexString(), CurrentLevel.YStart.ToHexString());
            }
            else if (_PlacingPointer)
            {
                _PlacingPointer = false;
                CurrentLevel.AddPointer();
                CurrentPointer = PntEditor.CurrentPointer = CurrentLevel.Pointers[CurrentLevel.Pointers.Count - 1];
                CurrentPointer.XEnter = x;
                CurrentPointer.YEnter = y;
                LvlView.DelayDrawing = true;
                LvlView.UpdatePoint(x, y);
                LvlView.UpdatePoint(x + 1, y);
                LvlView.UpdatePoint(x, y + 1);
                LvlView.UpdatePoint(x + 1, y + 1);
                LvlView.DelayDrawing = false;
                LvlView.SelectionRectangle = new Rectangle(x, y, 2, 2);
                BtnAddPointer.Enabled = CurrentLevel.Pointers.Count <= 10;
                TabEditSelector.Enabled = PnlInfo.Enabled = true;
                SetHelpText(Reuben.Properties.Resources.PointerHelper);
            }

            else if (EditMode == EditMode.Tiles)
            {
                if (ModifierKeys == Keys.Shift)
                {
                    BlsSelector.SelectedTileIndex = CurrentLevel.LevelData[x, y];
                    BlsSelector_SelectionChanged(this, new TEventArgs<MouseButtons>(e.Button));
                }
                else
                {
                    LvlView.ClearSelection();
                    if (TileDrawMode == TileDrawMode.Selection)
                    {
                        TileDrawMode = PreviousMode;
                    }

                    if (e.Button == MouseButtons.Right && MouseMode == MouseMode.RightClickSelection)
                    {
                        PreviousMode = TileDrawMode;
                        TileDrawMode = TileDrawMode.Selection;
                    }

                    switch (TileDrawMode)
                    {
                        case TileDrawMode.Pencil:
                            CurrentMultiTile = new MultiTileAction();
                            CurrentMultiTile.AddTileChange(x, y, CurrentLevel.LevelData[x, y]);
                            CurrentLevel.SetTile(x, y, (byte)(DrawingTile));
                            ContinueDrawing = true;
                            break;

                        case TileDrawMode.Outline:
                        case TileDrawMode.Rectangle:
                        case TileDrawMode.Scatter:
                        case TileDrawMode.Selection:
                            StartX = x;
                            StartY = y;
                            ContinueDrawing = true;
                            LvlView.SelectionRectangle = new Rectangle(StartX, StartY, 1, 1);
                            break;

                        case TileDrawMode.Line:
                            StartX = x;
                            StartY = y;
                            ContinueDrawing = true;
                            LvlView.SelectionLine = new Line(StartX, StartY, StartX, StartY);
                            break;

                        case TileDrawMode.Fill:
                            Point start = new Point(x, y);
                            Stack<Point> stack = new Stack<Point>();
                            stack.Push(start);
                            int checkValue = CurrentLevel.LevelData[x, y];
                            if (checkValue == DrawingTile)
                                return;

                            CurrentMultiTile = new MultiTileAction();
                            while (stack.Count > 0)
                            {
                                Point p = stack.Pop();
                                int lowestX, highestX;
                                ;
                                int lowestY, highestY;
                                lowestX = highestX = x;
                                lowestY = highestY = y;
                                int i = p.X;
                                int j = p.Y;
                                if (CurrentLevel.LevelLayout == LevelLayout.Horizontal)
                                {
                                    if (j < 0 || j >= CurrentLevel.Height || i < 0 || i >= CurrentLevel.Length * 16)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    if (j < 0 || j >= (CurrentLevel.Length * 15) - 4 || i < 0 || i >= CurrentLevel.Width)
                                    {
                                        continue;
                                    }
                                }

                                LvlView.DelayDrawing = true;
                                if (checkValue == CurrentLevel.LevelData[i, j])
                                {
                                    CurrentMultiTile.AddTileChange(i, j, CurrentLevel.LevelData[i, j]);
                                    CurrentLevel.SetTile(i, j, (byte)DrawingTile);
                                    if (i < lowestX)
                                        lowestX = i;
                                    if (i > highestX)
                                        highestX = i;
                                    if (j < lowestY)
                                        lowestY = j;
                                    if (j > highestY)
                                        highestY = j;

                                    stack.Push(new Point(i + 1, j));
                                    stack.Push(new Point(i - 1, j));
                                    stack.Push(new Point(i, j + 1));
                                    stack.Push(new Point(i, j - 1));
                                }
                                UndoBuffer.Add(CurrentMultiTile);
                                LvlView.DelayDrawing = false;
                                LvlView.UpdateArea(new Rectangle(lowestX, lowestY, highestX - lowestX + 1, highestY - lowestY + 1));
                            }

                            break;

                        case TileDrawMode.Replace:
                            LvlView.DelayDrawing = true;
                            int findTile = CurrentLevel.LevelData[x, y];
                            MultiTileAction mta = new MultiTileAction();
                            for (int i = 0; i < (15 * 16); i++)
                            {
                                for (int j = 0; j < 0x1B; j++)
                                {
                                    if (CurrentLevel.LevelData[i, j] == findTile)
                                    {
                                        mta.AddTileChange(i, j, CurrentLevel.LevelData[i, j]);
                                        CurrentLevel.LevelData[i, j] = (byte)DrawingTile;
                                    }
                                }
                            }

                            LvlView.DelayDrawing = false;
                            ;
                            LvlView.FullUpdate();
                            break;
                    }
                }
            }
            else if (EditMode == EditMode.Sprites)
            {
                previousSprite = CurrentSprite;
                CurrentSprite = SelectSprite(x, y);

                modifySpriteVisiblity = false;

                if (CurrentSprite == null)
                {
                    CmbSpriteProperty.Enabled = false;
                    CmbSpriteProperty.SelectedIndex = -1;
                    CmbSpriteProperty.DataSource = null;
                }

                if (CurrentSprite != null)
                {
                    SpriteDefinition def = ProjectController.SpriteManager.GetDefinition(CurrentSprite.InGameID);
                    if (def != null)
                    {
                        CmbSpriteProperty.DataSource = def.PropertyDescriptions;
                    }
                    else
                    {
                        CmbSpriteProperty.DataSource = null;
                    }
                }

                if (CurrentSprite != null && MouseButtons == MouseButtons.Left)
                {
                    if (CmbSpriteProperty.Items.Count > 0)
                    {
                        CmbSpriteProperty.SelectedIndex = CurrentSprite.Property;
                    }
                    CmbSpriteProperty.Enabled = true;

                    LvlView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                    ContinueDragging = true;
                    LblSprite.Text = "Current Sprite: " + CurrentSprite.InGameID.ToHexString() + " - " + CurrentSprite.Name;
                    if (ModifierKeys == Keys.Shift)
                    {
                        ((SpriteViewer)TabClass1.SelectedTab.Controls[0]).SelectedSprite = null;
                        ((SpriteViewer)TabClass2.SelectedTab.Controls[0]).SelectedSprite = null;
                        ((SpriteViewer)TabClass3.SelectedTab.Controls[0]).SelectedSprite = null;

                        SpriteDefinition sDef = ProjectController.SpriteManager.GetDefinition(CurrentSprite.InGameID);
                        switch (sDef.Class)
                        {
                            case 1:
                                foreach (TabPage t in TabClass1.TabPages)
                                {
                                    if (t.Text == sDef.Group)
                                    {
                                        TabClass1.SelectedTab = t;
                                    }
                                }
                                break;

                            case 2:
                                foreach (TabPage t in TabClass2.TabPages)
                                {
                                    if (t.Text == sDef.Group)
                                    {
                                        TabClass2.SelectedTab = t;
                                    }
                                }
                                break;

                            case 3:
                                foreach (TabPage t in TabClass3.TabPages)
                                {
                                    if (t.Text == sDef.Group)
                                    {
                                        TabClass3.SelectedTab = t;
                                    }
                                }
                                break;
                        }

                        SpriteViewer sv = SpriteViewers.Find(s => s.SpriteList.Find(c => c.InGameID == CurrentSprite.InGameID) != null);
                        sv.SetSelectedSprite(CurrentSprite);
                        CurrentSelectorSprite = sv.SelectedSprite;
                    }
                }
                else if (CurrentSprite != null && MouseButtons == MouseButtons.Right && CurrentSelectorSprite != null)
                {
                    CurrentSprite.InGameID = CurrentSelectorSprite.InGameID;
                    CurrentSprite.Property = 0;
                    CurrentSprite.Property = CurrentSelectorSprite.Property;
                    SpriteDefinition sp = ProjectController.SpriteManager.GetDefinition(CurrentSprite.InGameID);
                    int xDiff = x - CurrentSprite.X;
                    int yDiff = y - CurrentSprite.Y;
                    int rectX = xDiff >= 0 ? (CurrentSprite.X * 16) + sp.MaxLeftX : (x * 16) + sp.MaxLeftX;
                    int rectY = yDiff >= 0 ? (CurrentSprite.Y * 16) + sp.MaxTopY : (y * 16) + sp.MaxTopY;
                    int width = xDiff >= 0 ? ((x * 16) + sp.MaxRightX) - ((CurrentSprite.X * 16) + sp.MaxLeftX) : ((CurrentSprite.X * 16) + sp.MaxRightX) - ((x * 16) + sp.MaxLeftX);
                    int height = yDiff >= 0 ? ((y * 16) + sp.MaxBottomY) - ((CurrentSprite.Y * 16) + sp.MaxTopY) : ((CurrentSprite.Y * 16) + sp.MaxBottomY) - ((y * 16) + sp.MaxTopY);
                    Rectangle r = new Rectangle(rectX, rectY, width, height);
                    CurrentSprite.X = x;
                    CurrentSprite.Y = y;
                    LvlView.DelayDrawing = true;
                    LvlView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                    LvlView.DelayDrawing = false;
                    LvlView.UpdateSprites(r);
                }
                else if (CurrentSelectorSprite != null && MouseButtons == MouseButtons.Right)
                {
                    Sprite newSprite = new Sprite() { X = x, Y = y, InGameID = CurrentSelectorSprite.InGameID };
                    if (previousSprite != null && newSprite.InGameID == previousSprite.InGameID)
                    {
                        newSprite.Property = previousSprite.Property;
                    }
                    
                    CurrentLevel.AddSprite(newSprite);
                    CurrentSprite = newSprite;
                    LvlView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                    ContinueDragging = true;
                    LblSprite.Text = "Current Sprite: " + CurrentSprite.InGameID.ToHexString() + " - " + CurrentSprite.Name;
                    CmbSpriteProperty.DataSource = ProjectController.SpriteManager.GetDefinition(CurrentSprite.InGameID).PropertyDescriptions;
                    CmbSpriteProperty.Enabled = CmbSpriteProperty.DataSource != null && CmbSpriteProperty.Items.Count > 1;

                    if (CmbSpriteProperty.Enabled)
                    {
                        CmbSpriteProperty.SelectedIndex = CurrentSprite.Property;
                    }
                }
                else
                {
                    LvlView.ClearSelection();
                    ContinueDragging = false;
                    LblSprite.Text = "None";
                }

                modifySpriteVisiblity = true;
            }
            else if (EditMode == EditMode.Pointers)
            {
                LevelPointer p = CurrentLevel.Pointers.Find(pt => (pt.XEnter == x || pt.XEnter + 1 == x) && (pt.YEnter == y || pt.YEnter + 1 == y));
                PntEditor.CurrentPointer = p;
                CurrentPointer = p;
                if (p != null)
                {
                    LvlView.SelectionRectangle = new Rectangle(p.XEnter, p.YEnter, 2, 2);
                    ContinueDragging = true;
                    BtnDeletePointer.Enabled = true;
                }
                else
                {
                    BtnDeletePointer.Enabled = false;
                    LvlView.ClearSelection();
                }
            }
        }
Example #5
0
        private void WldView_MouseDown(object sender, MouseEventArgs e)
        {
            int x = (e.X / 16) / WldView.Zoom;
            int y = (e.Y / 16) / WldView.Zoom;
            PnlView.Focus();

            if (x < 0 || x >= CurrentWorld.Width || y < 0 || y >= CurrentWorld.Height) return;

            if (_PlacingPointer)
            {
                _PlacingPointer = false;
                CurrentWorld.AddPointer();
                PntEditor.CurrentPointer = CurrentWorld.Pointers[CurrentWorld.Pointers.Count - 1];
                CurrentPointer = PntEditor.CurrentPointer;
                CurrentPointer.X = x;
                CurrentPointer.Y = y;
                PnlDrawing.Enabled = TabLevelInfo.Enabled = true;
                WldView.SelectionRectangle = new Rectangle(x, y, 1, 1);
                WldView.UpdatePoint(x, y);
                PntEditor.UpdatePosition();
            }

            else if (EditMode == EditMode.Tiles)
            {
                if (ModifierKeys == Keys.Shift)
                {
                    BlsSelector.SelectedTileIndex = CurrentWorld.LevelData[x, y];
                    BlsSelector_SelectionChanged(this, new TEventArgs<MouseButtons>(e.Button));
                }
                else
                {
                    WldView.ClearSelection();
                    if (TileDrawMode == TileDrawMode.Selection)
                    {
                        TileDrawMode = PreviousMode;
                    }

                    if (e.Button == MouseButtons.Right && MouseMode == MouseMode.RightClickSelection)
                    {
                        PreviousMode = TileDrawMode;
                        TileDrawMode = TileDrawMode.Selection;
                    }

                    switch (TileDrawMode)
                    {
                        case TileDrawMode.Pencil:
                            CurrentMultiTile = new MultiTileAction();
                            CurrentMultiTile.AddTileChange(x, y, CurrentWorld.LevelData[x, y]);
                            CurrentWorld.SetTile(x, y, (byte)(DrawingTile));
                            ContinueDrawing = true;
                            break;

                        case TileDrawMode.Outline:
                        case TileDrawMode.Rectangle:
                        case TileDrawMode.Selection:
                            StartX = x;
                            StartY = y;
                            ContinueDrawing = true;
                            WldView.SelectionRectangle = new Rectangle(StartX, StartY, 1, 1);
                            break;

                        case TileDrawMode.Line:
                            StartX = x;
                            StartY = y;
                            ContinueDrawing = true;
                            WldView.SelectionLine = new Line(StartX, StartY, StartX, StartY);
                            break;

                        case TileDrawMode.Fill:
                            Point start = new Point(x, y);
                            Stack<Point> stack = new Stack<Point>();
                            stack.Push(start);
                            int checkValue = CurrentWorld.LevelData[x, y];
                            if (checkValue == DrawingTile) return;

                            CurrentMultiTile = new MultiTileAction();
                            while (stack.Count > 0)
                            {
                                Point p = stack.Pop();
                                int lowestX, highestX; ;
                                int lowestY, highestY;
                                lowestX = highestX = x;
                                lowestY = highestY = y;
                                int i = p.X;
                                int j = p.Y;

                                if (j < 0 || j >= CurrentWorld.Height || i < 0 || i >= CurrentWorld.Length * 16)
                                {
                                    continue;
                                }

                                WldView.DelayDrawing = true;
                                if (checkValue == CurrentWorld.LevelData[i, j])
                                {
                                    CurrentMultiTile.AddTileChange(i, j, CurrentWorld.LevelData[i, j]);
                                    CurrentWorld.SetTile(i, j, (byte)DrawingTile);
                                    if (i < lowestX) lowestX = i;
                                    if (i > highestX) highestX = i;
                                    if (j < lowestY) lowestY = j;
                                    if (j > highestY) highestY = j;

                                    stack.Push(new Point(i + 1, j));
                                    stack.Push(new Point(i - 1, j));
                                    stack.Push(new Point(i, j + 1));
                                    stack.Push(new Point(i, j - 1));
                                }
                                UndoBuffer.Add(CurrentMultiTile);
                                WldView.DelayDrawing = false;
                                WldView.UpdateArea(new Rectangle(lowestX, lowestY, highestX - lowestX + 1, highestY - lowestY + 1));
                            }

                            break;
                    }
                }
            }
            else if (EditMode == EditMode.Sprites)
            {
                CurrentSprite = SelectSprite(x, y);
                if (CurrentSprite != null && MouseButtons == MouseButtons.Left)
                {
                    WldView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                    ContinueDragging = true;
                    LblSprite.Text = "Current Sprite: " + CurrentSprite.InGameID.ToHexString() + " - " + CurrentSprite.Name + " - Item: " + CurrentSprite.Item;
                }
                else if (CurrentSprite != null && MouseButtons == MouseButtons.Right && CurrentSelectorSprite != null)
                {
                    CurrentSprite.InGameID = CurrentSelectorSprite.InGameID;
                    SpriteDefinition sp = ProjectController.SpriteManager.GetDefinition(CurrentSprite.InGameID);
                    int xDiff = x - CurrentSprite.X;
                    int yDiff = y - CurrentSprite.Y;
                    int rectX = xDiff >= 0 ? (CurrentSprite.X * 16) + sp.MaxLeftX : (x * 16) + sp.MaxLeftX;
                    int rectY = yDiff >= 0 ? (CurrentSprite.Y * 16) + sp.MaxTopY : (y * 16) + sp.MaxTopY;
                    int width = xDiff >= 0 ? ((x * 16) + sp.MaxRightX) - ((CurrentSprite.X * 16) + sp.MaxLeftX) : ((CurrentSprite.X * 16) + sp.MaxRightX) - ((x * 16) + sp.MaxLeftX);
                    int height = yDiff >= 0 ? ((y * 16) + sp.MaxBottomY) - ((CurrentSprite.Y * 16) + sp.MaxTopY) : ((CurrentSprite.Y * 16) + sp.MaxBottomY) - ((y * 16) + sp.MaxTopY);
                    Rectangle r = new Rectangle(rectX, rectY, width, height);
                    CurrentSprite.X = x;
                    CurrentSprite.Y = y;
                    WldView.DelayDrawing = true;
                    WldView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                    WldView.DelayDrawing = false;
                    WldView.UpdateSprites(r);
                }
                else if (CurrentSelectorSprite != null && MouseButtons == MouseButtons.Right)
                {
                    Sprite newSprite = new Sprite() { IsMapSprite = true, X = x, Y = y, InGameID = CurrentSelectorSprite.InGameID };
                    CurrentWorld.AddSprite(newSprite);
                    CurrentSprite = newSprite;
                    WldView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                    ContinueDragging = true;
                    LblSprite.Text = "Current Sprite: " + CurrentSprite.InGameID.ToHexString() + " - " + CurrentSprite.Name;
                }

                else
                {
                    WldView.ClearSelection();
                    ContinueDragging = false;
                    LblSprite.Text = "None";
                }
            }
            else if (EditMode == EditMode.Pointers)
            {
                WorldPointer p = CurrentWorld.Pointers.Find(pt => pt.X == x && pt.Y == y);
                PntEditor.CurrentPointer = p;
                CurrentPointer = p;
                if (p != null)
                {
                    WldView.SelectionRectangle = new Rectangle(p.X, p.Y, 1, 1);
                    ContinueDragging = true;
                    BtnDeletePointer.Enabled = true;
                }
                else
                {
                    BtnDeletePointer.Enabled = false;
                    WldView.ClearSelection();
                }
            }
        }
Example #6
0
        private void LoadSpriteSelector()
        {
            List<Sprite> CurrentList;
            foreach (var s in ProjectController.SpriteManager.SpriteGroups.Keys)
            {
                foreach (var k in from l in ProjectController.SpriteManager.SpriteGroups[s].Keys orderby l select l)
                {
                    if (k == "Map")
                        continue;
                    SpriteViewer spViewer = new SpriteViewer(ProjectController.SpriteManager.SpriteGroups[s][k].Count);
                    spViewer.SpecialPalette = ProjectController.SpecialManager.SpecialPalette;
                    CurrentList = new List<Sprite>();

                    int x = 0;
                    foreach (var ks in ProjectController.SpriteManager.SpriteGroups[s][k])
                    {
                        Sprite next = new Sprite();
                        next.Property = 0;
                        next.X = x;
                        next.Y = 0;
                        next.InGameID = ks.InGameId;
                        CurrentList.Add(next);
                        x += next.Width + 1;
                    }

                    spViewer.SpriteList = CurrentList;
                    spViewer.Location = new Point(0, 0);
                    SpriteViewers.Add(spViewer);
                    spViewer.CurrentPalette = CurrentPalette;
                    spViewer.UpdateSprites();
                    spViewer.SelectionChanged += new EventHandler<TEventArgs<Sprite>>(spViewer_SelectionChanged);

                    TabPage tPage = new TabPage();
                    tPage.Text = k;
                    tPage.AutoScroll = true;
                    tPage.Controls.Add(spViewer);


                    switch (s)
                    {
                        case 1:
                            TabClass1.TabPages.Add(tPage);
                            break;

                        case 2:
                            TabClass2.TabPages.Add(tPage);
                            break;

                        case 3:
                            TabClass3.TabPages.Add(tPage);
                            break;
                    }
                }
            }
        }
Example #7
0
        private void LevelEditor_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.Modifiers & Keys.Control) > Keys.None)
            {
                switch (e.KeyCode)
                {
                    case Keys.A:
                        LvlView.SelectionRectangle = new Rectangle(0, 0, CurrentLevel.Length * 16, 0x1B);
                        break;

                    case Keys.Add:
                        if (!TsbZoom.Checked)
                            TsbZoom.Checked = true;
                        break;

                    case Keys.Subtract:
                        if (TsbZoom.Checked)
                            TsbZoom.Checked = false;
                        break;

                    case Keys.S:
                        Save();
                        MessageBox.Show("Level succesfully saved.");
                        break;


                    case Keys.X:
                        Cut();
                        break;

                    case Keys.C:
                        Copy();
                        break;

                    case Keys.V:
                        Paste();
                        break;

                    case Keys.Z:
                        Undo();
                        break;
                }
            }
            else
            {
                switch (e.KeyCode)
                {
                    case Keys.Delete:

                        if (CurrentSprite != null && EditMode == EditMode.Sprites)
                        {
                            CurrentLevel.SpriteData.Remove(CurrentSprite);
                            LvlView.DelayDrawing = true;
                            LvlView.ClearSelection();
                            LvlView.DelayDrawing = false;
                            LvlView.UpdateSprites();
                            CurrentSprite = null;
                        }
                        else if (EditMode == EditMode.Tiles && TileDrawMode == TileDrawMode.Selection)
                        {
                            DeleteTiles();
                        }
                        else if (EditMode == EditMode.Pointers)
                        {
                            DeleteCurrentPointer();
                        }
                        break;

                    case Keys.F11:
                        if (EditMode == EditMode.Sprites)
                        {
                            var ordered = CurrentLevel.SpriteData.OrderBy(p => p.X * 32 + p.Y).ToList();
                            var index = ordered.IndexOf(CurrentSprite);
                            if (index > 0)
                            {
                                CurrentSprite = ordered[index - 1];
                                LvlView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                                ContinueDragging = true;
                                LblSprite.Text = "Current Sprite: " + CurrentSprite.InGameID.ToHexString() + " - " + CurrentSprite.Name;
                            }


                            if (CurrentSprite != null)
                            {
                                if (CurrentSprite.X * 16 < PnlView.HorizontalScroll.Value)
                                {
                                    PnlView.HorizontalScroll.Value = CurrentSprite.X * 16 + CurrentSprite.Width - 100;
                                }
                                else if (CurrentSprite.X * 16 >= PnlView.HorizontalScroll.Value + PnlView.Width)
                                {
                                    PnlView.HorizontalScroll.Value = (CurrentSprite.X * 16 - (PnlView.Width)) + 100;
                                }
                            }
                        }
                        break;

                    case Keys.F12:
                        if (EditMode == EditMode.Sprites)
                        {
                            var ordered = CurrentLevel.SpriteData.OrderBy(p => p.X * 32 + p.Y).ToList();
                            var index = ordered.IndexOf(CurrentSprite);
                            if (index < ordered.Count - 1)
                            {
                                CurrentSprite = ordered[index + 1];
                                LvlView.SelectionRectangle = new Rectangle(CurrentSprite.X, CurrentSprite.Y, CurrentSprite.Width, CurrentSprite.Height);
                                ContinueDragging = true;
                                LblSprite.Text = "Current Sprite: " + CurrentSprite.InGameID.ToHexString() + " - " + CurrentSprite.Name;
                            }

                            if (CurrentSprite != null)
                            {
                                if (CurrentSprite.X * 16 < PnlView.HorizontalScroll.Value)
                                {
                                    PnlView.HorizontalScroll.Value = CurrentSprite.X * 16 + CurrentSprite.Width - 100;
                                }
                                else if (CurrentSprite.X * 16 >= PnlView.HorizontalScroll.Value + PnlView.Width)
                                {
                                    PnlView.HorizontalScroll.Value = (CurrentSprite.X * 16 - (PnlView.Width)) + 100;
                                }
                            }
                        }
                        break;

                    case Keys.Escape:
                        ContinueDrawing = false;
                        LvlView.ClearSelection();
                        LvlView.ClearLine();
                        if (TileDrawMode == TileDrawMode.Selection)
                            TileDrawMode = PreviousMode;
                        break;

                    case Keys.F2:
                        TsbStartPoint.Checked = !TsbStartPoint.Checked;
                        break;

                    case Keys.F3:
                        TsbGrid.Checked = !TsbGrid.Checked;
                        break;

                    case Keys.F4:
                        TsbItems.Checked = !TsbItems.Checked;
                        break;

                    case Keys.F5:
                        TsbSolidity.Checked = !TsbSolidity.Checked;
                        break;

                    case Keys.F6:
                        TsbInteractions.Checked = !TsbInteractions.Checked;
                        break;

                    case Keys.F7:
                        TsbSriteSpecials.Checked = !TsbSriteSpecials.Checked;
                        break;

                    case Keys.F8:
                        TsbPointers.Checked = !TsbPointers.Checked;
                        break;
                    case Keys.D1:
                        TsbPencil_Click(null, null);
                        break;

                    case Keys.D2:
                        TsbLine_Click(null, null);
                        break;

                    case Keys.D3:
                        TsbRectangle_Click(null, null);
                        break;

                    case Keys.D4:
                        TsbOutline_Click(null, null);
                        break;

                    case Keys.D5:
                        TsbBucket_Click(null, null);
                        break;

                    case Keys.D6:
                        TsbReplace_Click(null, null);
                        break;

                    case Keys.Q:
                        TabEditSelector.SelectedIndex = 0;
                        break;

                    case Keys.W:
                        TabEditSelector.SelectedIndex = 1;
                        break;

                    case Keys.E:
                        TabEditSelector.SelectedIndex = 2;
                        break;
                }
            }
        }
Example #8
0
 public void RemoveSprite(Sprite sprite)
 {
     SpriteData.Remove(sprite);
     if (SpriteRemoved != null) SpriteRemoved(this, new TEventArgs<Sprite>(sprite));
 }
Example #9
0
 public void AddSprite(Sprite sprite)
 {
     SpriteData.Add(sprite);
     if (SpriteAdded != null) SpriteAdded(this, new TEventArgs<Sprite>(sprite));
 }
Example #10
0
        public bool Load(string filename)
        {
            XDocument xDoc;
            string[] levelData = null;
            string[] compressData = null;
            SpriteData.Clear();
            Pointers.Clear();

            try
            {
                xDoc = XDocument.Load(filename);
            }
            catch
            {
                return false;
            }

            XElement level = xDoc.Element("level");

            foreach (var a in level.Attributes())
            {
                switch (a.Name.LocalName)
                {
                    case "layout":
                        LevelLayout = (LevelLayout)Enum.Parse(typeof(LevelLayout), a.Value, true);
                        break;

                    case "guid":
                        Guid = a.Value.ToGuid();
                        break;

                    case "type":
                        Type = a.Value.ToInt();
                        break;

                    case "clearvalue":
                        ClearValue = a.Value.ToInt();
                        break;

                    case "graphicsbank":
                        GraphicsBank = a.Value.ToInt();
                        break;

                    case "music":
                        Music = a.Value.ToInt();
                        break;

                    case "length":
                        Length = a.Value.ToInt();
                        break;

                    case "time":
                        Time = a.Value.ToInt();
                        break;

                    case "xstart":
                        XStart = a.Value.ToInt();
                        break;

                    case "ystart":
                        YStart = a.Value.ToInt();
                        break;

                    case "invincibleenemies":
                        InvincibleEnemies = a.Value.ToBoolean();
                        break;

                    case "vineblocked":
                        VineBlocked = a.Value.ToBoolean();
                        break;

                    case "paletteeffect":
                        PaletteEffect = a.Value.ToInt();
                        break;

                    case "palette":
                        Palette = a.Value.ToInt();
                        break;

                    case "scrolltype":
                        ScrollType = a.Value.ToInt();
                        break;

                    case "animationtype":
                        AnimationType = a.Value.ToInt();
                        break;

                    case "startaction":
                        StartAction = a.Value.ToInt();
                        break;

                    case "leveldata":
                        levelData = a.Value.Split(',');
                        break;

                    case "compresseddata":
                        compressData = a.Value.Split(',');
                        break;

                    case "challengeleveltype":
                        ChallengeType = a.Value.ToInt();
                        break;

                    case "specialleveltype":
                        SpecialLevelType = a.Value.ToInt();
                        break;

                    case "misc1":
                        MiscByte1 = a.Value.ToInt();
                        break;

                    case "misc2":
                        MiscByte2 = a.Value.ToInt();
                        break;

                    case "misc3":
                        MiscByte3 = a.Value.ToInt();
                        break;

                    case "tempprojeffects":
                        ProjectileBlocksTemporary = a.Value.ToBoolean();
                        break;

                    case "rhythm":
                        RhythmPlatforms = a.Value.ToBoolean();
                        break;

                    case "dpadtiles":
                        DpadTiles = a.Value.ToBoolean();
                        break;
                }
            }

            int xPointer = 0, yPointer = 0;
            int[] tileCount = new int[256];
            foreach (var c in levelData)
            {
                LevelData[xPointer, yPointer] = (byte)c.ToInt();
                tileCount[c.ToInt()]++;
                xPointer++;

                if (xPointer >= Width)
                {
                    xPointer = 0;
                    yPointer++;
                    if (yPointer > Height) break;
                }
            }

            int highestTileCount = -1;
            for (int i = 0; i < 256; i++)
            {
                if (tileCount[i] > highestTileCount)
                {
                    highestTileCount = MostCommonTile = i;

                }
            }

            foreach (var x in level.Elements())
            {
                switch (x.Name.LocalName)
                {

                    case "spritedata":
                        foreach (var spr in x.Elements("sprite"))
                        {
                            Sprite s = new Sprite();
                            s.LoadFromElement(spr);
                            SpriteData.Add(s);
                        }
                        break;

                    case "pointers":
                        foreach (var ptr in x.Elements("pointer"))
                        {
                            LevelPointer p = new LevelPointer();
                            p.LoadFromElement(ptr);
                            Pointers.Add(p);
                        }
                        break;

                    case "settings":
                        Settings.LoadFromElement(x);
                        break;
                }
            }

            return true;
        }
Example #11
0
        public bool Load(string filename)
        {
            string[] compressData = null;
            string[] levelData = null;

            XDocument xDoc;
            try
            {
                xDoc = XDocument.Load(filename);
            }
            catch
            {
                return false;
            }

            XElement world = xDoc.Element("world");

            foreach (var a in world.Attributes())
            {
                switch (a.Name.LocalName)
                {
                    case "guid":
                        Guid = a.Value.ToGuid();
                        break;

                    case "graphicsbank":
                        GraphicsBank = a.Value.ToInt();
                        break;

                    case "music":
                        Music = a.Value.ToInt();
                        break;

                    case "length":
                        Length = a.Value.ToInt();
                        break;

                    case "palette":
                        Palette = a.Value.ToInt();
                        break;

                    case "compresseddata":
                        compressData = a.Value.Split(',');
                        break;

                    case "worlddata":
                        levelData = a.Value.Split(',');
                        break;
                }
            }

            int xPointer = 0, yPointer = 0;
            foreach (var c in levelData)
            {
                LevelData[xPointer, yPointer] = (byte)c.ToInt();
                xPointer++;

                if (xPointer >= Width)
                {
                    xPointer = 0;
                    yPointer++;
                    if (yPointer > Height) break;
                }
            }

            SpriteData.Clear();
            Pointers.Clear();
            foreach (var x in world.Elements())
            {
                switch (x.Name.LocalName)
                {
                    case "spritedata":
                        foreach (var spr in x.Elements("sprite"))
                        {
                            Sprite s = new Sprite();
                            s.LoadFromElement(spr);
                            SpriteData.Add(s);
                        }
                        break;

                    case "pointers":

                        foreach (var ptr in x.Elements("pointer"))
                        {
                            WorldPointer p = new WorldPointer();
                            p.LoadFromElement(ptr);
                            Pointers.Add(p);
                        }
                        break;

                    case "settings":
                        Settings.LoadFromElement(x);
                        break;
                }
            }

            return true;
        }
Example #12
0
        public void SetSelectedSprite(Sprite sprite)
        {
            _SelectedSprite = SpriteList.Find(s => s.InGameID == sprite.InGameID);
            if (_SelectedSprite != null)
            {
                SelectionionRectangle = new Rectangle(SelectedSprite.X, SelectedSprite.Y, SelectedSprite.Width, SelectedSprite.Height);
            }
            else
            {
                ClearSelection();
            }

            FullSpriteRender();
            Invalidate();
        }