Пример #1
0
        private void loadAsset(LevelObjectAsset asset)
        {
            ClearMainArea();

            objectFrameworkArea.Data.MainPanel.AddControl(new TextArea(25, 25, "Name: ") {Color = "black"});
            TextBox tb = null;
            objectFrameworkArea.Data.MainPanel.AddControl(tb = new TextBox(100, 5, 290, 25, asset.Name) {Color = "rgb(50,150,50)", Click = (p) => { asset.Name = tb.Text; }});

            objectFrameworkArea.Data.MainPanel.AddControl(new Button(400, 5, 100, 25, "Add Frame") {
                                                                                                           Color = "rgb(50,150,50)",
                                                                                                           Click = (p) => {
                                                                                                                       LevelObjectAssetFrame vs;
                                                                                                                       asset.Frames.Add(vs = new LevelObjectAssetFrame("Frame " + ( asset.Frames.Count + 1 )));
                                                                                                                       vs.Palette = new string[] {"000", "111", "222", "333", "444", "555", "666", "777", "888", "999", "AAA", "BBB", "CCC", "DDD", "EEE", "FFF"};
                                                                                                                       vs.Width = (int) ( Math.Floor(Math.Random() * 40) + 20 );
                                                                                                                       vs.Height = (int) ( Math.Floor(Math.Random() * 40) + 20 );
                                                                                                                       vs.ColorMap = new int[vs.Width][];
                                                                                                                       for (var i = 0; i < vs.Width; i++) {
                                                                                                                           vs.ColorMap[i] = new int[vs.Height];
                                                                                                                           for (var j = 0; j < vs.Height; j++) {
                                                                                                                               vs.ColorMap[i][j] = (int) Math.Floor(Math.Random() * vs.Palette.Length);
                                                                                                                           }
                                                                                                                       }

                                                                                                                       objectFrameworkArea.Data.MainPanel.Data.AssetPopulate(asset);
                                                                                                                   }
                                                                                                   });

            HScrollBox jd;
            objectFrameworkArea.Data.MainPanel.AddControl(jd = new HScrollBox(20, 35, 70, 4, 112) {BackColor = "rgb(50,60,127)"});
            objectFrameworkArea.Data.MainPanel.Data.AssetPopulate = (ast) => {
                                                                        jd.Controls = new List<Element>();
                                                                        foreach (LevelObjectAssetFrame t in ast.Frames) {
                                                                            ImageButton<LevelObjectAssetFrame> bd = null;
                                                                            bd = new ImageButton<LevelObjectAssetFrame>(null, 0, 0, 0, 0);

                                                                            bd.Text = ( (Func<string>) ( () => { return bd.Data.Name; } ) );
                                                                            bd.OnDraw = (canvas, x, y) =>
                                                                                        bd.Data.DrawSimple(canvas, new Point(x, y), bd.Width, bd.Height - 15, false, false);

                                                                            bd.Click = (p) => objectFrameworkArea.Data.MainPanel.Data.LoadFrame(bd.Data);

                                                                            jd.AddControl(bd);
                                                                            bd.Data = t;
                                                                        }
                                                                    };

            objectFrameworkArea.Data.MainPanel.Data.AssetPopulate(asset);

            objectFrameworkArea.Data.MainPanel.AddControl(objectFrameworkArea.Data.MainPanel.Data.FrameArea = new Panel<FrameAreaData>(new FrameAreaData(), 7, 155, 480, 350));
            objectFrameworkArea.Data.MainPanel.Data.FrameArea.Outline = false;

            objectFrameworkArea.Data.MainPanel.Data.LoadFrame = (frame) => {
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.Controls = new List<Element>();
                                                                    //Data.MainPanel.Data.FrameArea.currentFrame = frame;
                                                                    //var ce;
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new TextArea(15, 21, "Name: ") {Color = "black"});
                                                                    TextBox textBox = null;
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(textBox=new TextBox(90, 0, 395, 25, frame.Name??"") {
                                                                                                                                                                                 Color = "rgb(50,150,50)",
                                                                                                                                                                                 Click = (p) => { frame.Name = textBox.Text; }
                                                                                                                                                                         });


                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new TextArea(15, 100, "Transparent Color: ") { Color = "black" });
                                                                    TextBox tb2=null;
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(tb2 = new TextBox(15, 120, 395, 25, frame.TransparentColor ?? "")
                                                                    {
                                                                        Color = "rgb(50,150,50)",
                                                                        TextChanged = () => { frame.TransparentColor = tb2.Text;
                                                                        
                                                                        frame.ClearCache();
                                                                        }
                                                                    });

                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new TextArea(0, 275, (Func<string>) ( () => { return "Width:  " + frame.Width; } )) {Color = "Black"});

                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new Button(75, 275 - 25, 14, 17, "^") {
                                                                                                                                                                               Color = "rgb(50,150,50)",
                                                                                                                                                                               Click = (p) => { frame.SetWidth(frame.Width + 1); }
                                                                                                                                                                       });
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new Button(75, 275 - 5, 14, 20, "v") {
                                                                                                                                                                              Color = "rgb(50,150,50)",
                                                                                                                                                                              Click = (p) => { frame.SetWidth(frame.Width - 1); }
                                                                                                                                                                      });

                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new TextArea(0, 320, ( (Func<string>) ( () => { return "Height: " + frame.Height; } ) )) {Color = "Black"});

                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new Button(75, 320 - 25, 14, 17, "^") {
                                                                                                                                                                               Color = "rgb(50,150,50)",
                                                                                                                                                                               Click = (p) => { frame.SetHeight(frame.Height + 1); }
                                                                                                                                                                       });
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new Button(75, 320 - 5, 14, 20, "v") {
                                                                                                                                                                              Color = "rgb(50,150,50)",
                                                                                                                                                                              Click = (p) => { frame.SetHeight(frame.Height - 1); }
                                                                                                                                                                      });

                                                                    Button bt;
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(bt = new Button(230 - 55, 35, 150, 25, "Collide Map") {
                                                                                                                                                                                               Color = "rgb(50,150,50)",
                                                                                                                                                                                               Click = (p) => {
                                                                                                                                                                                                           //    ce.showCollideMap = this.toggled;
                                                                                                                                                                                                       }
                                                                                                                                                                                       });
                                                                    bt.Toggle = true;
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(bt = new Button(390 - 55, 35, 150, 25, "Hurt Map") {
                                                                                                                                                                                            Color = "rgb(50,150,50)",
                                                                                                                                                                                            Click = (p) => {
                                                                                                                                                                                                        //    ce.showHurtMap = this.toggled;
                                                                                                                                                                                                    }
                                                                                                                                                                                    });
                                                                    bt.Toggle = true;

                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(objectFrameworkArea.Data.MainPanel.Data.FrameArea.Data.ColorEditor = new ColorEditingArea(230 - 55, 65, 310, 225) {ShowOffset = true});
                                                                    var ce = objectFrameworkArea.Data.MainPanel.Data.FrameArea.Data.ColorEditor;
                                                                    ce.Init(frame);
                                                                    ce.Editor.ShowOutline = false;
                                                                    ce.Editable = false;
                                                                    ce.Click = (p) => { frame.SetOffset(p.X, p.Y); };
                                                                    /*
                                Data.MainPanel.Data.FrameArea.AddControl(new HtmlBox(19, 64, 120, 31, () =>
                                {
                                    var sc = document.getElementById("picFieldUploader");

                                    sc.style.left = (objectFrameworkArea.x + 320 + 7 + 19) + "px";
                                    sc.style.top = (objectFrameworkArea.y + 150 + 155 + 64) + "px";
                                    sc.style.position = "absolute";
                                    sc.style.visibility = "visible";
                                }, (x, y) =>
                                {
                                    var sc = document.getElementById("picFieldUploader");
                                    if (sc)
                                    {
                                        if (sc.style.left == x + "px" && sc.style.top == y + "px")
                                            return;
                                        sc.style.left = x + "px";
                                        sc.style.top = y + "px";
                                    }
                                }, () =>
                                {
                                    var sc = document.getElementById("picFieldUploader");
                                    if (sc)
                                    {
                                        sc.style.visibility = "visible";
                                    }
                                }, () =>
                                {
                                    var sc = document.getElementById("picFieldUploader");
                                    if (sc)
                                    {
                                        sc.style.left = "-100px";
                                        sc.style.top = "-100px";
                                        sc.style.visibility = "hidden";
                                    }
                                }));
                */

                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(objectFrameworkArea.Data.MainPanel.Data.FrameArea.Data.PalatteArea = new PaletteArea(230 - 55, 300) {Scale = new Point(39, 11), ShowCurrent = false});
                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.Data.PalatteArea.Init(frame.Palette, true);

                                                                    objectFrameworkArea.Data.MainPanel.Data.FrameArea.AddControl(new Button(230 - 55, 305 + 11 * 2, 310, 25, "Edit Map") {
                                                                                                                                                                                                 Color = "rgb(50,150,50)",
                                                                                                                                                                                                 Click = (p) => {
                                                                                                                                                                                                             SonicManager.Instance.UIManager.UIManagerAreas.ColorEditorArea.Data.Init(frame);
                                                                                                                                                                                                             SonicManager.Instance.UIManager.UIManagerAreas.ColorEditorArea.Visible = true;
                                                                                                                                                                                                             SonicManager.Instance.UIManager.UIManagerAreas.ColorEditorArea.Depth = /*this.Depth + 1*/ 10;
                                                                                                                                                                                                             objectFrameworkArea.LoseFocus();
                                                                                                                                                                                                         }
                                                                                                                                                                                         });
                                                                };
        }
Пример #2
0
        public static LevelObject ExtendObject(LevelObjectData d)
        {
            LevelObject obj = new LevelObject(d.Key)
            {
                CollideScript = d.CollideScript,
                HurtScript = d.HurtScript,
                InitScript = d.InitScript,
                TickScript = d.TickScript
            };
            obj.Description = d.Description;
            //d.oldKey = name;
            obj.Assets = new List<LevelObjectAsset>();

            for (int i = 0; i < d.Assets.Count; i++)
            {
                var asset = d.Assets[i];
                var levelObjectAsset = new LevelObjectAsset(asset.Name)
                {
                    Name = asset.Name,
                };
                levelObjectAsset.Frames = new List<LevelObjectAssetFrame>();
                for (int index = 0; index < asset.Frames.Count; index++)
                {
                    var fr = asset.Frames[index];

                    levelObjectAsset.Frames[index] = new LevelObjectAssetFrame(fr.Name)
                    {
                        OffsetX = fr.OffsetX,
                        Width = fr.Width,
                        TransparentColor = fr.TransparentColor,
                        Height = fr.Height,
                        OffsetY = fr.OffsetY,
                        HurtSonicMap = fr.HurtSonicMap,
                        CollisionMap = fr.CollisionMap,
                        ColorMap = fr.ColorMap,
                        Palette = fr.Palette,
                    };
                }
                obj.Assets[i] = levelObjectAsset;
            }
            obj.Pieces = new List<LevelObjectPiece>();

            for (int index = 0; index < d.Pieces.Count; index++)
            {
                var piece = d.Pieces[index];
                obj.Pieces[index] = piece;
            }
            obj.PieceLayouts = new List<LevelObjectPieceLayout>();
            for (int index = 0; index < d.PieceLayouts.Count; index++)
            {
                var pl = d.PieceLayouts[index];
                obj.PieceLayouts[index] = new LevelObjectPieceLayout(pl.Name)
                {
                    Height = pl.Height,
                    Width = pl.Width
                };

                obj.PieceLayouts[index].Pieces = new List<LevelObjectPieceLayoutPiece>();
                for (int i = 0; i < d.PieceLayouts[index].Pieces.Count; i++)
                {
                    obj.PieceLayouts[index].Pieces[i] = d.PieceLayouts[index].Pieces[i];
                }
            }
            obj.Projectiles = new List<LevelObjectProjectile>();
            for (int index = 0; index < d.Projectiles.Count; index++)
            {
                var proj = d.Projectiles[index];
                proj = new LevelObjectProjectile(proj.Name)
                {
                    X = proj.X,
                    Y = proj.Y,
                    Xsp = proj.Xsp,
                    Ysp = proj.Ysp,
                    Xflip = proj.Xflip,
                    Yflip = proj.Yflip,
                    AssetIndex = proj.AssetIndex,
                    FrameIndex = proj.FrameIndex,
                };
                obj.Projectiles[index] = proj;
            }
            return obj;
        }