Esempio n. 1
0
        public TileChunkArea(UIManager.UIManager uiManager)
        {
            var tileChunkArea = uiManager.UIManagerAreas.TileChunkArea = new UIArea<TileChunk>(null, 700, 500, 390, 390) {Closable = true};
            tileChunkArea.Visible = false;

            uiManager.AddArea(tileChunkArea);
            tileChunkArea.AddControl(new TextArea(30, 25, "Tile Chunks") {Color = "blue"});

            tileChunkArea.AddControl(chunkPieceList = new ScrollBox(30, 70, 96 - 16, 3, 64) {BackColor = "rgb(50,60,127)"});

            TileChunk[] tileChunks = SonicManager.Instance.SonicLevel.TileChunks.Array();
            for (int index = 0; index < tileChunks.Length; index++) {
                var tileChunk = tileChunks[index];
                ImageButton<TileChunk> chunkButton = new ImageButton<TileChunk>(tileChunk, 0, 0, 0, 0);
                chunkButton.OnDraw = (cnv, x, y) => {
//                                         chunkButton.Data.DrawUI(cnv, new Point(x, y), new DoublePoint(0.5d, 0.5d), 0);
//                                         chunkButton.Data.DrawUI(cnv, new Point(x, y), new DoublePoint(0.5d, 0.5d), 1);
                                     };
                chunkButton.Font = UIManager.UIManager.SmallTextFont;
                chunkButton.Text = "Chunk #" + index;
                chunkButton.Click = (e) => { tileChunkArea.Data = tileChunk; };
                chunkPieceList.AddControl(chunkButton);
            }

            Image image = new Image(125, 70, 256, 256);
            int areaDrawScale = 2;
            image.OnDraw += (context, x, y) => {
                                if (tileChunkArea.Data == null) return;
//                                tileChunkArea.Data.DrawUI(context, new Point(x, y), new Point(areaDrawScale, areaDrawScale), 0);
//                                tileChunkArea.Data.DrawUI(context, new Point(x, y), new Point(areaDrawScale, areaDrawScale), 1);
                            };
            image.Click += (e) => {
                               if (tileChunkArea.Data == null) return;
//                               var tilePiece = tileChunkArea.Data.GetBlockAt(e.X / areaDrawScale, e.Y / areaDrawScale);

//                               uiManager.UIManagerAreas.TilePieceArea.Visible = false;
//                               uiManager.UIManagerAreas.TilePieceArea.Data = tilePiece;
//                               tilePieceList.ScrollIndex = Math.Max(uiManager.sonicManager.SonicLevel.TilePieces.IndexOf(tilePiece) - 1, 0);
                           };
            tileChunkArea.AddControl(image);

            buildTilePiece(uiManager);

            /*
                        var table=tileChunkArea.AddControl(new Table(10, 40, 350, 280));
                        var row = table.AddRow(new TableRow(50.Percent()));
                        var cell = row.AddCell(new TableCell(50.Percent(), 50.Percent()));
                        cell.AddControl(new Button(0, 0, 0, 0, "Text"));
                        cell = row.AddCell(new TableCell(50.Percent(), 50.Percent()));
                        cell.AddControl(new Button(0, 0, 0, 0, "Text1")); 



                        row = table.AddRow(new TableRow(100));
                        cell = row.AddCell(new TableCell(100, 100));
                        cell.AddControl(new Button(0, 0, 100, 100, "Text"));
                        cell = row.AddCell(new TableCell(100, 100){FullSize=false});
                        cell.AddControl(new Button(0, 0, 100, 50, "Text1"));
                        cell.AddControl(new Button(0, 50, 100, 50, "Text2"));*/
        }
Esempio n. 2
0
        private void buildTilePiece(UIManager.UIManager uiManager)
        {
            var tilePieceArea = uiManager.UIManagerAreas.TilePieceArea = new UIArea<TilePiece>(null, 1100, 400, 390, 390) {Closable = true};
            tilePieceArea.Visible = false;

            uiManager.AddArea(tilePieceArea);
            tilePieceArea.AddControl(new TextArea(30, 25, "Tile Pieces") {Color = "blue"});

            bool showHeightMap = false;
            tilePieceArea.AddControl(new Button(100, 50, 125, 25, (Func<string>) ( () => showHeightMap ? "Hide Height Map" : "Show Height Map" )) {
                                                                                                                                                          Click = (e) => {
                                                                                                                                                                      if (tilePieceArea.Data == null) return;
                                                                                                                                                                      showHeightMap = !showHeightMap;
                                                                                                                                                                  }
                                                                                                                                                  });

            tilePieceList = new ScrollBox(10, 35, 96 - 16, 4, 64) {BackColor = "rgb(50,60,127)"};
            tilePieceArea.AddControl(tilePieceList);

            var tilePieces = SonicManager.Instance.SonicLevel.TilePieces.Array();
            for (int index = 0; index < tilePieces.Length; index++) {
                var tilePiece = tilePieces[index];
                ImageButton<TilePiece> tilePieceButton = new ImageButton<TilePiece>(tilePiece, 0, 0, 0, 0);
                tilePieceButton.OnDraw = (cnv, x, y) => {
                                             cnv.Save();
                                             cnv.Translate(x, y);
                                             cnv.Scale(4, 4);
//                                             tilePieceButton.Data.Draw(cnv, new Point(0, 0), ChunkLayer.Low, false, false, 0);
//                                             tilePieceButton.Data.Draw(cnv, new Point(0, 0), ChunkLayer.High, false, false, 0);

                                             if (showHeightMap) {
                                                 HeightMap hmap;
                                                 if (SonicManager.Instance.SonicLevel.CurHeightMap)
                                                     hmap = tilePiece.GetLayer1HeightMaps();
                                                 else
                                                     hmap = tilePiece.GetLayer2HeightMaps();

                                                 hmap.Draw(cnv, new Point(0, 0), false, false, 1, 0);
                                             }

                                             cnv.Restore();
                                         };
                tilePieceButton.Font = UIManager.UIManager.SmallTextFont;
                tilePieceButton.Text = "Tile Piece #" + index;
                tilePieceButton.Click = (e) => { tilePieceArea.Data = tilePiece; };
                tilePieceList.AddControl(tilePieceButton);
            }

            Image image = new Image(105, 120, 256, 256);
            image.OnDraw += (context, x, y) => {
                                if (tilePieceArea.Data == null) return;
                                context.Save();
                                context.Translate(x, y);
                                context.Scale(16, 16);
//                                tilePieceArea.Data.Draw(context, new Point(0, 0), ChunkLayer.Low, false, false, 0);
//                                tilePieceArea.Data.Draw(context, new Point(0, 0), ChunkLayer.High, false, false, 0);
                                context.Restore();
                            };

            tilePieceArea.AddControl(image);
        }
        public ObjectFrameworkListArea(UIManager.UIManager uiManager)
        {
            Action<string> loadObject = null;

            var objectFrameworkListArea = uiManager.UIManagerAreas.ObjectFrameworkListArea = new UIArea(90, 500, 390, 300) {Closable = true};
            objectFrameworkListArea.Visible = true;

            uiManager.AddArea(objectFrameworkListArea);
            objectFrameworkListArea.AddControl(new TextArea(30, 25, "Object Frameworks") {Color = "blue"});
            ScrollBox fList;
            objectFrameworkListArea.AddControl(fList = new ScrollBox(30, 90, 25, 6, 315) {BackColor = "rgb(50,60,127)"});
            objectFrameworkListArea.AddControl(new Button(35, 50, 160, 25, "Create Framework") {
                                                                                                       Color = "rgb(50,150,50)",
                                                                                                       Click = (p) => {
                                                                                                                   uiManager.UIManagerAreas.ObjectFrameworkArea.Populate(new LevelObject("SomeKey"));
                                                                                                                   uiManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Visible = true;
                                                                                                               }
                                                                                               });
            Action getObjects = () => {
                                    SonicEngine.Instance.client.Emit("GetAllObjects", "");
                                    SonicEngine.Instance.client.On<DataObject<string[]>>("GetAllObjects.Response",
                                                                                         (data) => {
                                                                                             var obj = data.Data;

                                                                                             fList.Controls = new List<Element>();
                                                                                             foreach (var itm in obj.OrderBy(a => a)) {
                                                                                                 Button d;
                                                                                                 string name = itm;
                                                                                                 fList.AddControl(d = new Button(0, 0, 0, 0, itm) {
                                                                                                                                                          Color = "rgb(50,190,90)",
                                                                                                                                                          Click = (p) => { loadObject(name); }
                                                                                                                                                  });
                                                                                             }
                                                                                         });
                                };

            objectFrameworkListArea.AddControl(new Button(200, 50, 160, 25, "Save Framework") {
                                                                                                      Color = "rgb(50,150,50)",
                                                                                                      Click = (p) => {
                                                                                                                  var oldTitle = UIManager.UIManager.CurLevelName;
                                                                                                                  UIManager.UIManager.UpdateTitle("Saving Object");

                                                                                                                  var k = uiManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Data.ObjectFramework.Key;
                                                                                                                  var o = uiManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Data.ObjectFramework.oldKey ??
                                                                                                                          uiManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Data.ObjectFramework.Key;
                                                                                                                  var v = Help.Stringify(uiManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Data.ObjectFramework);

                                                                                                                  SonicEngine.Instance.client.Emit("SaveObject", new SaveObjectModel {Key = k, OldKey = o, Data = v});
                                                                                                                  SonicEngine.Instance.client.On<bool>("SaveObject.Response", (data) => { UIManager.UIManager.UpdateTitle(oldTitle); });

                                                                                                                  getObjects();
                                                                                                              }
                                                                                              });

            getObjects();
            loadObject = (name) => {
                             var objects = SonicManager.Instance.cachedObjects;
                             if (objects != null) {
                                 if (objects[name] != null) {
                                     uiManager.UIManagerAreas.ObjectFrameworkArea.Populate(objects[name]);
                                     uiManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Visible = true;
                                     return;
                                 }
                             }

                             var oldTitle = UIManager.UIManager.CurLevelName;

                             UIManager.UIManager.UpdateTitle("Downloading Object:" + name);

                             SonicEngine.Instance.client.Emit("GetObject", new DataObject<string>(name));
                             SonicEngine.Instance.client.On<DataObject<string>>("GetObject.Response",
                                                                                (lvl) => {
                                                                                    UIManager.UIManager.UpdateTitle(oldTitle);
                                                                                    var d = ObjectManager.ExtendObject(jQuery.ParseJsonData<LevelObjectData>(lvl.Data));
                                                                                    uiManager.UIManagerAreas.ObjectFrameworkArea.Populate(d);
                                                                                    uiManager.UIManagerAreas.ObjectFrameworkArea.objectFrameworkArea.Visible = true;
                                                                                });
                         };
        }