Beispiel #1
0
        /// <summary>
        /// Overridden save function
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public override bool Save(string filename)
        {
            PrefabDesc      prefab = new PrefabDesc(filename);
            ShapeCollection all    = new ShapeCollection();

            // the following shapes go into the prefab: lightgrid boxes, lights
            foreach (ShapeBase shape in this.FilteredSupplier)
            {
                all.Add(shape);
            }

            foreach (ShapeBase shape in this.FilteredLights)
            {
                if (!all.Contains(shape))
                {
                    all.Add(shape);
                }
            }

            if (!prefab.CreateFromInstances(all, Vector3F.Zero, false, false))
            {
                return(false);
            }
            return(prefab.SaveToFile(null));
        }
        /// <summary>
        /// Overridden save function
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public override bool Save(string filename)
        {
            PrefabDesc prefab = new PrefabDesc(filename);
              ShapeCollection all = new ShapeCollection();

              // the following shapes go into the prefab: lightgrid boxes, lights
              foreach (ShapeBase shape in this.FilteredSupplier)
            all.Add(shape);

              foreach (ShapeBase shape in this.FilteredLights)
            if (!all.Contains(shape))
              all.Add(shape);

              if (!prefab.CreateFromInstances(all, Vector3F.Zero, false, false))
            return false;
              return prefab.SaveToFile(null);
        }
        private void treeView_Creators_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            PrefabDesc prefab = SelectedCreatorObject as PrefabDesc;

            if (prefab != null)
            {
                using (PropertyGridDlg dlg = new PropertyGridDlg("Change prefab properties", "Change the properties of this prefab and click OK to apply and save the new settings"))
                {
                    dlg.DataObject = prefab;
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    // get back results
                    prefab = (PrefabDesc)dlg.DataObject;
                    if (!prefab.PropertiesChanged) // seems untouched by property grid
                    {
                        return;
                    }

                    // fire the static event
                    prefab.TriggerPropertiesChangedEvent();
                    if (!prefab.SaveToFile(null))
                    {
                        EditorManager.ShowMessageBox("Changes could not be applied because the prefab shape could not be saved.\n\nDetailed message:" + prefab.LastError, "Failed to save prefab", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }


                    //_selectedCreatorNode.CreatorObject = prefab;
                    // brute force rebuild tree:
                    ProjectUpdate();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// helper function to save layers as prefabs
        /// </summary>
        /// <param name="folderName">absolute path to the folder where the prefabs should be saved in. Set string to null if you want to use the default folder</param>
        private void ExportLayersAsPrefabs(string folderName)
        {
            if (EditorManager.Scene == null)
            return;
              int iCount = 0;

              bool bAsBinary = true;

              try
              {
            foreach (Layer layer in EditorManager.Scene.Layers)
            {
              string prefabName;
              if (folderName == null) //if no foldername is used
              {
            prefabName = Path.ChangeExtension(layer.AbsoluteLayerFilename, ".prefab");
              }
              else
              {
            prefabName = Path.Combine(folderName, layer.LayerName + ".prefab");
              }
              PrefabDesc prefab = new PrefabDesc(prefabName);
              prefab.AutoSaveBinary = true; //activate autosave per default [#2112]
              prefab.Description = layer.Description;
              prefab.CreateFromInstances(layer.Root.ChildCollection, Vector3F.Zero, true, true);
              if (prefab.SaveToFile(null))
            iCount++;

              if (bAsBinary)
              {
            SceneExportInfo info = new SceneExportInfo();
            info.ExportType = SceneExportInfo.ExportType_e.VPrefab;
            info.AbsoluteFilename = EditorManager.Project.MakeAbsolute(prefab.BinaryFilename);
            info.RelevantShapes = SceneExportInfo.GetRelevantExportShapes(layer.Root);

            ExportHelper.StartPrefabExport(info);
            layer.Root.OnExportRecursive(info);
            ExportHelper.EndPrefabExport(info);
              }
            }
              }
              catch (Exception ex)
              {
            EditorManager.DumpException(ex);
            EditorManager.ShowMessageBox(this, "Failed to export layers. Detailed message:\n\n" + ex.Message, "Export Layers as Prefabs", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
              }
              if (iCount == 0)
            EditorManager.ShowMessageBox(this, "No layer valid for export", "Export Layers as Prefabs", MessageBoxButtons.OK, MessageBoxIcon.Information);
              else
            EditorManager.ShowMessageBox(this, iCount.ToString() + " Layer(s) exported successfully", "Export Layers as Prefabs", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void createPrefabToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShapeCollection shapes = shapeTreeView.SelectedShapes;
              PrefabDesc prefab = new PrefabDesc(null);

              // try to use/create the prefabs directory of the project
              string proj = EditorManager.Project.ProjectDir;
              string prefabDir = Path.Combine(proj, EditorManager.Settings.PrefabDirectory);
              if (!Directory.Exists(prefabDir))
              {
            try
            {
              Directory.CreateDirectory(prefabDir);
            }
            catch (Exception ex)
            {
              EditorManager.DumpException(ex);
              prefabDir = proj; // OK, fallback to project directory
            }
              }

              // first select the prefab file to save
              CreateFileDlg fileDlg = new CreateFileDlg();
              fileDlg.Caption = "Save a prefab";
              fileDlg.Description = "Enter the name of the prefab file and select the directory to save it in. Then click OK to proceed.";
              fileDlg.InitialDirectory = prefabDir;
              fileDlg.Ext = ".prefab";
              fileDlg.Filter = new string[] { ".prefab" };
              fileDlg.AllowOverwrite = true;

              if (fileDlg.ShowDialog() != DialogResult.OK)
            return;

              prefab.Filename = fileDlg.FileName;

              // if the file exists, load it to get the properties
              if (File.Exists(prefab.Filename))
              {
            prefab.Load();
              }

              // set this before the dialog opens
              prefab.SourceShapesForExposedParameters = shapes;

              // edit the prefab properties
              using (PropertyGridDlg propDlg = new PropertyGridDlg("Edit prefab properties", "Edit additional prefab properties. Click OK to proceed with saving the prefab file."))
              {
            propDlg.DataObjectNoClone = prefab;
            if (propDlg.ShowDialog() != DialogResult.OK)
              return;

            // fill with the shapes
            if (!prefab.CreateFromInstances(shapes, shapes.Center, true, true))
            {
              EditorManager.ShowMessageBox("Failed to create prefab. Detailed message:\n\n" + prefab.LastError, "Creation Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
              return;
            }

            if (!prefab.SaveToFile(fileDlg.FileName))
            {
              EditorManager.ShowMessageBox("Failed to save prefab. Detailed message:\n\n" + prefab.LastError, "Saving Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
              return;
            }
              }
        }