Esempio n. 1
0
 public static int[] Show(byte layer, int x, int y)
 {
     newLayerAlign               = new LayerAlign();
     newLayerAlign.xchange       = x;
     newLayerAlign.ychange       = y;
     newLayerAlign.TopBox.Value  = 0;
     newLayerAlign.LeftBox.Value = 0;
     newLayerAlign.label1.Text   = String.Format(newLayerAlign.label1.Text, layer + 1, Math.Abs(y), (y >= 0) ? "tall" : "short", Math.Abs(x), (x >= 0) ? "wid" : "narrow");
     newLayerAlign.ShowDialog();
     return(results);
 }
Esempio n. 2
0
        private bool ApplyChanges()
        {
            newrectangle = null;
            lock (DataSource)
            {
                if (DataSource.Width != WidthBox.Value || DataSource.Height != HeightBox.Value)
                {
                    newrectangle = LayerAlign.Show(CurrentLayer, (int)WidthBox.Value - (int)DataSource.Width, (int)HeightBox.Value - (int)DataSource.Height);
                    if (newrectangle == null)
                    {
                        return(false);
                    }
                    SourceForm.Undoable = new Stack <MLLE.Mainframe.LayerAndSpecificTiles>(SourceForm.Undoable.Where(action => action.Layer != DataSource));
                    SourceForm.Redoable = new Stack <MLLE.Mainframe.LayerAndSpecificTiles>(SourceForm.Redoable.Where(action => action.Layer != DataSource));
                }

                DataSource.Width  = (uint)WidthBox.Value;
                DataSource.Height = (uint)HeightBox.Value;
                if (TileWidth.Checked)
                {
                    switch (DataSource.Width % 4)
                    {
                    case 0: DataSource.RealWidth = DataSource.Width; break;

                    case 2: DataSource.RealWidth = DataSource.Width * 2; break;

                    default: DataSource.RealWidth = DataSource.Width * 4; break;
                    }
                }
                else
                {
                    DataSource.RealWidth = DataSource.Width;
                }

                if (newrectangle != null)
                {
                    ArrayMap <ushort> newTileMap = new ArrayMap <ushort>(DataSource.Width, DataSource.Height);
                    for (ushort x = 0; x < DataSource.Width; x++)
                    {
                        for (ushort y = 0; y < DataSource.Height; y++)
                        {
                            newTileMap[x, y] = (
                                x >= -newrectangle[2] &&
                                newrectangle[2] + x < DataSource.TileMap.GetLength(0) &&
                                y >= -newrectangle[0] &&
                                newrectangle[0] + y < DataSource.TileMap.GetLength(1)
                                )
                                ? DataSource.TileMap[newrectangle[2] + x, newrectangle[0] + y]
                                : (ushort)0;
                        }
                    }

                    if (DataSource.id == J2LFile.SpriteLayerID) //sprite layer, i.e. events are associated with this one
                    {
                        if (SourceForm.J2L.VersionType == Version.AGA)
                        {
                            AGAEvent[,] newAGAMap = new AGAEvent[DataSource.Width, DataSource.Height];
                            for (ushort x = 0; x < DataSource.Width; x++)
                            {
                                for (ushort y = 0; y < DataSource.Height; y++)
                                {
                                    newAGAMap[x, y] = (
                                        x >= -newrectangle[2] &&
                                        newrectangle[2] + x < DataSource.TileMap.GetLength(0) &&
                                        y >= -newrectangle[0] &&
                                        newrectangle[0] + y < DataSource.TileMap.GetLength(1)
                                        )
                                        ? SourceForm.J2L.AGA_EventMap[newrectangle[2] + x, newrectangle[0] + y]
                                        : new AGAEvent();
                                }
                            }
                            SourceForm.J2L.AGA_EventMap = newAGAMap;
                        }
                        else
                        {
                            var oldEventMap = SourceForm.J2L.EventMap;
                            uint[,] newEventMap = new uint[DataSource.Width, DataSource.Height];

                            PlusPropertyList rememberPlusEventBasedSettings = new PlusPropertyList(null);
                            rememberPlusEventBasedSettings.ReadFromEventMap(oldEventMap);
                            rememberPlusEventBasedSettings.WriteToEventMap(newEventMap);

                            int oldEventMapRightColumn = oldEventMap.GetLength(0) - 1;
                            int oldEventMapBottomRow   = oldEventMap.GetLength(1) - 1;

                            for (ushort x = 0; x < DataSource.Width; x++)
                            {
                                for (ushort y = 0; y < DataSource.Height - 1; y++)                                           //-1 because events in the bottom row don't work, except for a few events parsed by JJ2+ that were handled above
                                {
                                    newEventMap[x, y] = (
                                        x >= -newrectangle[2] &&
                                        newrectangle[2] + x <= oldEventMapRightColumn &&
                                        y >= -newrectangle[0] &&
                                        newrectangle[0] + y < oldEventMapBottomRow
                                        )
                                        ? oldEventMap[newrectangle[2] + x, newrectangle[0] + y]
                                        : (ushort)0;
                                }
                            }
                            SourceForm.J2L.EventMap = newEventMap;
                        }
                    }
                    DataSource.TileMap = newTileMap;
                }

                DataSource.TileWidth  = TileWidth.Checked;
                DataSource.TileHeight = TileHeight.Checked;
                Single.TryParse(XSpeed.Text, out DataSource.XSpeed);
                Single.TryParse(YSpeed.Text, out DataSource.YSpeed);
                Single.TryParse(AutoXSpeed.Text, out DataSource.AutoXSpeed);
                Single.TryParse(AutoYSpeed.Text, out DataSource.AutoYSpeed);
                Single.TryParse(XOffset.Text, out DataSource.WaveX);
                Single.TryParse(YOffset.Text, out DataSource.WaveY);
                DataSource.LimitVisibleRegion = LimitVisibleRegion.Checked;
                DataSource.IsTextured         = TextureMode.Checked;
                DataSource.HasStars           = Stars.Checked;
                DataSource.TexturParam1       = (byte)Param1.Value;
                DataSource.TexturParam2       = (byte)Param2.Value;
                DataSource.TexturParam3       = (byte)Param3.Value;
                DataSource.TextureMode        = (byte)TextureModeSelect.SelectedIndex;
                DataSource.Name                     = NameBox.Text;
                DataSource.Hidden                   = Hidden.Checked;
                DataSource.SpriteMode               = (byte)SpriteMode.SelectedIndex;
                DataSource.SpriteParam              = (byte)SpriteParam.Value;
                DataSource.RotationAngle            = (int)RotationAngle.Value;
                DataSource.RotationRadiusMultiplier = (int)RotationRadiusMultiplier.Value;
                SourceForm.LevelHasBeenModified     = true;
            }

            return(true);
        }