public WindowForm CrTileSetEditor() { setX = 0; setY = 0; CurSetMap = new Map(); var setLight = new Vivid.Scene.GraphLight(); setLight.SetPos(120, 120); setLight.SetZ(40); setLight.Diffuse = new OpenTK.Vector3(1, 1, 1); setLight.Specular = new OpenTK.Vector3(1, 1, 1); setLight.Range = 1200; CurSetMap.AddLight(setLight); WindowForm set_Editor = new WindowForm().Set(200, 200, 700, 600, "TileSet") as WindowForm; ToolBarForm tools = new ToolBarForm().Set(0, 0, 700, 25) as ToolBarForm; set_Editor.body.Add(tools); MapViewForm tileSet_View = new MapViewForm(CurSetMap).Set(0, 25, set_Editor.body.W, set_Editor.body.H - 25) as MapViewForm; tView = tileSet_View; //CurSetMap = new Map(1); tView.MouseLeave = () => { ClearHL(tileSet_View); }; tView.MouseMove = (x, y, dx, dy) => { if (tView.Graph != null) { var node = tView.Graph.Pick(x, y); if (node != null) { tView.Map.HL.Clear(); tView.Map.HighlightTile(node.TileX, node.TileY); tileSet_View.UpdateGraph(); // tileSet_View.Graph.X = -32 + tileSet_View.W / 2; //tileSet_View.Graph.Y = -32 + tileSet_View.H / 2; // Console.WriteLine("MX:" + x + " MY:" + y); } else { ClearHL(tileSet_View); } } }; CurSetLayer = CurSetMap.AddLayer(new SpaceEngine.Map.Layer.MapLayer(setWidth, setHeight)); set_Editor.body.Add(tileSet_View); void click_AddFolder() { var req = new RequestFileForm("Select a folder to scan..", ContentPath, true); SUI.Top = req; req.Selected = (path) => { Console.WriteLine("Folder:" + path + ":"); SUI.Top = null; var di = new DirectoryInfo(path); foreach (var file in di.GetFiles()) { switch (file.Extension) { case ".png": case ".bmp": case ".jpg": case ".tga": FAddTile(file.FullName); break; } } ResetMap(tView); }; // var file } tools.AddItem("Clear"); var tile_Add = tools.AddItem("Add Tile"); var tile_AddFolder = tools.AddItem("Add Folder"); tile_AddFolder.Click = click_AddFolder; void click_AddTile() { var addReq = new RequestFileForm("Add Tile to set...", ContentPath); SUI.Top = addReq; addReq.Selected = (path) => { Console.WriteLine("Loading Tile:" + path); FAddTile(path); //CurSetMap.HighlightTile(setX - 1, setY); ResetMap(tileSet_View); //tileSet_View.Graph.X = (CurSetMap.Layers[0].Width * 64)/2; // tileSet_View.Graph.Y = (CurSetMap.Layers[0].Height * 64) / 2; // tileSet_View.Graph.X -= 64; SUI.Top = null; }; } tile_Add.Click = click_AddTile; return(set_Editor); }
public MapEditForm() { var layDown = new ButtonForm().Set(140, -20, 30, 20, "\\/"); var layUp = new ButtonForm().Set(240, -20, 30, 20, "/\\"); var lay = new TextBoxForm().Set(175, -20, 70, 20, "0"); body.Add(layDown); body.Add(layUp); body.Add(lay); layDown.Click = (b) => { EditZ--; if (EditZ < 0) { EditZ = 0; } lay.Text = EditZ.ToString(); }; layUp.Click = (b) => { EditZ++; if (EditZ >= View.Map.Layers.Count) { EditZ = View.Map.Layers.Count - 1; } ; lay.Text = EditZ.ToString(); }; Tab = new TabForm(); CurMap = new Map(); for (int i = 0; i < 4; i++) { Layers.Add(new MapLayer(24, 24, CurMap)); CurMap.AddLayer(Layers[i]); } //CurMap.AddLayer(layer[0]); CurLayer = Layers[0]; CurTile = null; View = new MapViewForm(CurMap); var l1 = new Vivid.Scene.GraphLight(); var l2 = new Vivid.Scene.GraphLight(); var l3 = new Vivid.Scene.GraphLight(); // View.Map.AddLight(l1); // View.Map.AddLight(l2); // View.Map.AddLight(l3); LabelForm cLab = null; ; var TView = View; float r = 0; Update = () => { if (lMode != Mode) { updateModeLabel(); lMode = Mode; } /* * TView.Map.Lights[0].SetPos(300,300); * TView.Map.Lights[0].Range = 450; * TView.Map.Lights[0].Diffuse = new OpenTK.Vector3(0, 1, 1); * TView.Map.Lights[1].SetPos(650, 400); * TView.Map.Lights[1].Range = 400; * TView.Map.Lights[1].Diffuse = new OpenTK.Vector3(1, 1, 0); * TView.Map.Lights[0].Z = 0.1f; * TView.Map.Lights[1].Z = 0.1f; * TView.Map.Lights[2].Z = 0.1f; * TView.Map.Lights[2].Diffuse = new OpenTK.Vector3(1, 0, 1); * TView.Map.Lights[2].Range = 600; * TView.Map.Lights[2].SetPos(150, 150); */ }; void updateModeLabel() { if (cLab != null) { View.Forms.Remove(cLab); } cLab = new LabelForm().Set(2, -23, 30, 20, "Mode:Paste") as LabelForm; View.Add(cLab); } updateModeLabel(); body.Add(View); MoveNodeForm moveForm = new MoveNodeForm().Set(0, 0, 0, 0) as MoveNodeForm; moveForm.View = TView; TView.Add(moveForm); TView.MouseDown = (b) => { if (b == 2) { rotCam = true; return; } if (b == 1) { MoveCam = true; return; } Console.WriteLine("MX:" + mX + " MY:" + mY); AppInfo.RW = W; AppInfo.RH = H; var pn = TView.PickObj(mX, mY); if (pn != null) { if (pn is Vivid.Scene.GraphLight) { ActiveNode = pn; TView.ActiveNode = pn; TView.SetActiveSprite(); moveForm.SetNode(TView.ActiveNode); moveForm.Set((int)TView.ActiveNodeSprite.DrawP[0].X, (int)TView.ActiveNodeSprite.DrawP[0].Y, 64, 64); Console.WriteLine("Set PN"); } else { Console.WriteLine("nope"); } } else { Console.WriteLine("No obj"); } MouseIn = true; var hz = ONode; // TView.Graph.Pick(lx, ly); if (hz != null) { } }; TView.MouseWheelMoved = (z) => { TView.Graph.Z += ((z * 0.1f) * TView.Graph.Z); }; TView.MouseUp = (b) => { if (b == 2) { rotCam = false; return; } if (b == 1) { MoveCam = false; return; } MouseIn = false; }; TView.MouseMove = (x, y, dx, dy) => { mX = x; mY = y; if (rotCam) { TView.Graph.Rot += dx; } if (MoveCam) { TView.Graph.Move(-dx, -dy); //TView.Graph.X -= dx; // TView.Graph.Y -= dy; } lx = x; ly = y; if (TView.Graph != null) { AppInfo.RW = TView.MapFrame.IW; AppInfo.RH = TView.MapFrame.IH; var node = TView.Graph.Pick(x, y); AppInfo.RW = AppInfo.W; AppInfo.RH = AppInfo.H; if (node != null) { ONode = node; if (MouseIn) { switch (Mode) { case EditMode.Paste: TView.Map.Layers[EditZ].SetTile(node.TileX, node.TileY, TileBrowser.ActiveTile); //TView.UpdateGraph(); break; case EditMode.Fill: TView.Map.Layers[EditZ].Fill(TileBrowser.ActiveTile); break; } } var tView = TView; TView.Map.HL.Clear(); TView.Map.HighlightTile(node.TileX, node.TileY); TView.UpdateGraph(); if (TView.ActiveNodeSprite != null) { // TView.ActiveNodeSprite.SyncCoords(); if (TView.ActiveNodeSprite.DrawP != null) { moveForm.Set((int)TView.ActiveNodeSprite.DrawP[0].X, (int)TView.ActiveNodeSprite.DrawP[0].Y, 64, 64); // TView.Graph.X = -32 + TView.W / 2; } } // TView.Graph.Y = -32 + TView.H / 2; // Console.WriteLine("MX:" + x + " MY:" + y); } else { ClearHL(TView); } } }; AfterSet = () => { Tab.W = W; Tab.H = body.H; View.Set(0, 0, body.W, body.H); View.UpdateGraph(); }; }