public static void DuplicateGenerators(this Graph graph, ref HashSet <Generator> gens) /// Changes the selected hashset { GraphWindow.RecordCompleteUndo(); if (gens.Count == 0) { return; } Generator[] duplicatedGens = graph.Duplicate(gens); //placing under source generators Rect selectionRect = new Rect(duplicatedGens[0].guiPosition, Vector2.zero); foreach (Generator gen in duplicatedGens) { selectionRect = selectionRect.Encapsulate(new Rect(gen.guiPosition, gen.guiSize)); } foreach (Generator gen in duplicatedGens) { gen.guiPosition.y += selectionRect.size.y + 20; } gens.Clear(); gens.AddRange(duplicatedGens); GraphWindow.current.Focus(); //to return focus from right-click menu GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
public static Group CreateGroup(Vector2 mousePos, Graph graph) { GraphWindow.RecordCompleteUndo(); Group grp = new Group(); grp.guiPos = mousePos; graph.Add(grp); return(grp); }
public static void RemoveGroupContents(Group group, Graph graph) /// Called from editor. Removes the enlisted generators on group remove { GraphWindow.RecordCompleteUndo(); Generator[] containedGens = GetContainedGenerators(group, graph.generators); for (int i = 0; i < containedGens.Length; i++) { graph.Remove(containedGens[i]); } }
public static void CreateGenerator(this Graph graph, Type type, Vector2 mousePos) { GraphWindow.RecordCompleteUndo(); Generator gen = Generator.Create(type, graph); gen.guiPosition = new Vector2(mousePos.x - GeneratorDraw.nodeWidth / 2, mousePos.y - GeneratorDraw.headerHeight / 2); graph.Add(gen); GraphWindow.current.Focus(); //to return focus from right-click menu GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
public static Group CreateGroup(Vector2 mousePos, Graph graph) { GraphWindow.RecordCompleteUndo(); Group grp = new Group(); grp.guiPos = mousePos; graph.Add(grp); GraphWindow.current.Focus(); GraphWindow.current.Repaint(); //GraphWindow.RefreshMapMagic(); //not necessary return(grp); }
public static void RemoveGroup(Group grp, Graph graph, bool withContent = false) { GraphWindow.RecordCompleteUndo(); if (withContent) { GroupDraw.RemoveGroupContents(grp, graph); } graph.Remove(grp); GraphWindow.current.Focus(); GraphWindow.current.Repaint(); if (withContent) { GraphWindow.RefreshMapMagic(); } }
public static void RemoveGenerators(this Graph graph, HashSet <Generator> selected) { bool isOutput = false; foreach (Generator gen in selected) { if (gen is IOutputGenerator) { isOutput = true; break; } } if (isOutput && GraphWindow.current.mapMagic != null && EditorUtility.DisplayDialog("Purge Output", "Would you like to clear generated results on the terrain as well?", "Clear", "Keep")) { foreach (Generator gen in selected) { if (gen is IOutputGenerator outGen) { GraphWindow.current.mapMagic.Purge(outGen); } } } GraphWindow.RecordCompleteUndo(); foreach (Generator sgen in selected) { if (graph.ContainsGenerator(sgen)) { graph.Remove(sgen); } } GraphWindow.current.Focus(); GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
public static void RemoveGenerator(this Graph graph, Generator gen) { if (gen is IOutputGenerator && GraphWindow.current.mapMagic != null) { if (EditorUtility.DisplayDialog("Purge Output", "Would you like to clear generated results on the terrain as well?", "Clear", "Keep")) { GraphWindow.current.mapMagic.Purge((IOutputGenerator)gen); } } GraphWindow.RecordCompleteUndo(); if (graph.ContainsGenerator(gen)) { graph.ThroughLink(gen); //trying to maintain connections between generators graph.Remove(gen); } GraphWindow.current.Focus(); GraphWindow.current.Repaint(); GraphWindow.RefreshMapMagic(); }
private void DrawToolbar () { //using (Timer.Start("DrawToolbar")) using (Cell.LinePx(toolbarSize)) { //Graph graph = CurrentGraph; //Graph rootGraph = mapMagic.graph; //if (mapMagic != null && mapMagic.graph!=graph && mapMagic.graph!=rootGraph) mapMagic = null; UI.current.styles.Resize(0.9f); //shrinking all font sizes Draw.Element(UI.current.styles.toolbar); //undefined graph if (graph==null) { using (Cell.RowPx(200)) Draw.Label("No graph selected to display. Select:"); using (Cell.RowPx(100)) Draw.ObjectField(ref graph); return; } //if graph loaded corrupted if (graph.generators==null) { using (Cell.RowPx(300)) Draw.Label("Graph is null. Check the console for the error on load."); using (Cell.RowPx(100)) if (Draw.Button("Reload", style:UI.current.styles.toolbarButton)) graph.OnAfterDeserialize(); using (Cell.RowPx(100)) { if (Draw.Button("Reset", style:UI.current.styles.toolbarButton)) graph.generators = new Generator[0]; } Cell.EmptyRowRel(1); return; } //root graph Graph rootGraph = null; if (parentGraphs != null && parentGraphs.Count != 0) rootGraph = parentGraphs[0]; //this has nothing to do with currently assigned mm graph - we can view subGraphs with no mm in scene at all if (rootGraph != null) { Vector2 rootBtnSize = UnityEngine.GUI.skin.label.CalcSize( new GUIContent(rootGraph.name) ); using (Cell.RowPx(rootBtnSize.x)) { //Draw.Button(graph.name, style:UI.current.styles.toolbarButton, cell:rootBtnCell); Draw.Label(rootGraph.name); if (Draw.Button("", visible:false)) EditorGUIUtility.PingObject(rootGraph); } using (Cell.RowPx(20)) Draw.Label(">>"); } //this graph Vector2 graphBtnSize = UnityEngine.GUI.skin.label.CalcSize( new GUIContent(graph.name) ); using (Cell.RowPx(graphBtnSize.x)) { Draw.Label(graph.name); if (Draw.Button("", visible:false)) EditorGUIUtility.PingObject(graph); } //up-level and tree using (Cell.RowPx(20)) { if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/FolderTree"), iconScale:0.5f, visible:false)) GraphTreePopup.DrawGraphTree(rootGraph!=null ? rootGraph : graph); } using (Cell.RowPx(20)) { if (parentGraphs != null && parentGraphs.Count != 0 && Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/FolderUp"), iconScale:0.5f, visible:false)) { graph = parentGraphs[parentGraphs.Count-1]; parentGraphs.RemoveAt(parentGraphs.Count-1); ScrollZoomOnOpen(); Repaint(); } } Cell.EmptyRowRel(1); //switching to right corner //seed Cell.EmptyRowPx(5); using (Cell.RowPx(1)) Draw.ToolbarSeparator(); using (Cell.RowPx(90)) // using (Cell.LinePx(toolbarSize-1)) //-1 just to place it nicely { #if UNITY_2019_1_OR_NEWER int newSeed; using (Cell.RowRel(0.4f)) Draw.Label("Seed:"); using (Cell.RowRel(0.6f)) using (Cell.Padded(1)) newSeed = (int)Draw.Field(graph.random.Seed, style:UI.current.styles.toolbarField); #else Cell.current.fieldWidth = 0.6f; int newSeed = Draw.Field(graph.random.Seed, "Seed:"); #endif if (newSeed != graph.random.Seed) { GraphWindow.RecordCompleteUndo(); graph.random.Seed = newSeed; GraphWindow.RefreshMapMagic(); } } Cell.EmptyRowPx(2); //gauge using (Cell.RowPx(1)) Draw.ToolbarSeparator(); using (Cell.RowPx(200)) using (Cell.LinePx(toolbarSize-1)) //-1 to leave underscore under gauge { if (mapMagic != null) { float progress = mapMagic.GetProgress(); if (progress < 1 && progress != 0) { Texture2D backgroundTex = UI.current.textures.GetTexture("DPUI/ProgressBar/BackgroundBorderless"); mapMagic.GetProgress(); Draw.Texture(backgroundTex); Texture2D fillTex = UI.current.textures.GetBlankTexture(StylesCache.isPro ? Color.grey : Color.white); Color color = StylesCache.isPro ? new Color(0.24f, 0.37f, 0.58f) : new Color(0.44f, 0.574f, 0.773f); Draw.ProgressBarGauge(progress, fillTex, color); } using (Cell.RowPx(20)) if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/RefreshAll"), iconScale:0.5f, visible:false)) { //graphUI.undo.Record(completeUndo:true); //won't record changed terrain data foreach (Terrain terrain in mapMagic.tiles.AllActiveTerrains()) UnityEditor.Undo.RegisterFullObjectHierarchyUndo(terrain.terrainData, "RefreshAll"); EditorUtility.SetDirty(mapMagic); GraphWindow.current.mapMagic.ClearAll(); GraphWindow.current.mapMagic.StartGenerate(); } using (Cell.RowPx(20)) if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/Refresh"), iconScale:0.5f, visible:false)) { GraphWindow.current.mapMagic.StartGenerate(); } if (progress > 0.9999f) { Cell.EmptyRow(); using (Cell.RowPx(40)) Draw.Label("Ready"); } //else Repaint(); //doing it in OnInspectorUpdate } else Draw.Label("Not Assigned to MapMagic Object"); } using (Cell.RowPx(1)) Draw.ToolbarSeparator(); //focus using (Cell.RowPx(20)) if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/FocusSmall"), iconScale:0.5f, visible:false)) { graphUI.scrollZoom.FocusWindowOn(GetNodesCenter(graph), position.size); } using (Cell.RowPx(20)) { if (graphUI.scrollZoom.zoom < 0.999f) { if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/ZoomSmallPlus"), iconScale:0.5f, visible:false)) graphUI.scrollZoom.Zoom(1f, position.size/2); } else { if (Draw.Button(null, icon:UI.current.textures.GetTexture("DPUI/Icons/ZoomSmallMinus"), iconScale:0.5f, visible:false)) graphUI.scrollZoom.Zoom(0.5f, position.size/2); } } } }