public static BaseMatrixWindow GetCreateWindow(IPreview preview) /// Tries to find opened window by preview and updates it, and opens new window if non is found { IOutlet <object> outlet = PreviewManager.GetOutlet(preview); Guid previewGuid = outlet.Gen.Guid; BaseMatrixWindow[] windows = Resources.FindObjectsOfTypeAll <BaseMatrixWindow>(); BaseMatrixWindow window = null; for (int i = 0; i < windows.Length; i++) { if (windows[i] is IPreviewWindow serGuid && serGuid.SerializedGenGuid == previewGuid) { window = windows[i]; break; } } if (window == null) { window = preview.CreateWindow(); if (window is IPreviewWindow serGuid) { serGuid.SerializedGenGuid = previewGuid; } window.ShowTab(); } window.Show(); return(window); }
private static void TerrainWindowButtons(IPreview preview) { using (Cell.LineStd) { using (Cell.RowPx(20)) { if (preview.Terrain != null) { if (Draw.Button(UI.current.textures.GetTexture("MapMagic/Icons/PreviewToTerrainActive"), visible: false)) { PreviewManager.RemoveAllFromTerrain(); } } else { if (Draw.Button(UI.current.textures.GetTexture("MapMagic/Icons/PreviewToTerrain"), visible: false)) { PreviewManager.RemoveAllFromTerrain(); TerrainTile previewTile = GraphWindow.current.mapMagic?.PreviewTile; preview.ToTerrain(previewTile?.main?.terrain, previewTile?.draft?.terrain); } } } using (Cell.RowPx(20)) if (Draw.Button(UI.current.textures.GetTexture("MapMagic/Icons/PreviewToWindow"), visible: false)) { PreviewManager.GetCreateWindow(preview); } //Cell.EmptyRow(); } }
public static void DrawPreview(IOutlet <object> outlet) { IPreview preview = PreviewManager.GetPreview(outlet); if (preview == null) { preview = PreviewManager.CreatePreview(outlet); if (preview == null) { return; //for unknown types } preview.SetObject(outlet, GraphWindow.current.mapMagic?.PreviewData); } //preview itself using (Cell.Full) { Color backColor = StylesCache.isPro ? new Color(0.33f, 0.33f, 0.33f, 1) : new Color(0.4f, 0.4f, 0.4f, 1); Draw.Rect(BackgroundColor); //background in case no preview, or preview object was not assigned if (preview != null) { preview.DrawInGraph(); } } //clock/na if (GraphWindow.current.mapMagic == null) { using (Cell.Full) Draw.Icon(UI.current.textures.GetTexture("MapMagic/PreviewNA")); } else if (preview.Stage == PreviewStage.Generating || (preview.Stage == PreviewStage.Blank && GraphWindow.current.mapMagic.IsGenerating())) { using (Cell.Full) Draw.Icon(UI.current.textures.GetTexture("MapMagic/PreviewSandClock")); } else if (preview.Stage == PreviewStage.Blank) { using (Cell.Full) Draw.Icon(UI.current.textures.GetTexture("MapMagic/PreviewNA")); } //terrain buttons if (preview != null) { using (Cell.Full) TerrainWindowButtons(preview); } }