Ejemplo n.º 1
0
        private void ButtonUpload_Click(ProcedureUI.Button sender)
        {
            if (EditorMessageBox.ShowQuestion("Upload selected products to the store?", EMessageBoxButtons.OKCancel) == EDialogResult.Cancel)
            {
                return;
            }

            var item = ScreenNotifications.ShowSticky("Processing...");

            try
            {
                foreach (var product in GetObjects <Component_StoreProduct>())
                {
                    if (!product.BuildArchive())
                    {
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Warning(e.Message);
                return;
            }
            finally
            {
                item.Close();
            }

            ScreenNotifications.Show("The product was prepared successfully.");
        }
        private void ButtonGenerate_Click(ProcedureUI.Button sender)
        {
            //!!!!support undo
            var text = "Generate world?\n\nUnable to undo the action.";

            if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.Cancel)
            {
                return;
            }

            var notification = ScreenNotifications.ShowSticky("Processing...");

            try
            {
                foreach (var generator in GetObjects <Component_WorldGenerator>())
                {
                    generator.Generate(Provider.DocumentWindow.Document);
                }

                //!!!!
                //clear undo history
                Provider.DocumentWindow.Document?.UndoSystem.Clear();
            }
            finally
            {
                notification.Close();
            }
        }
Ejemplo n.º 3
0
        private void ButtonImport_Click(ProcedureUI.Button sender)
        {
            var sky = GetFirstObject <Component_Skybox>();

            if (sky == null)
            {
                return;
            }
            var scene = sky.FindParent <Component_Scene>();

            if (scene == null)
            {
                return;
            }

            var link = editLink.Text;

            var notification = ScreenNotifications.ShowSticky("Importing...");

            try
            {
                string destVirtualFileName;
                {
                    string name = sky.GetPathFromRoot();
                    foreach (char c in new string( Path.GetInvalidFileNameChars()) + new string( Path.GetInvalidPathChars()))
                    {
                        name = name.Replace(c.ToString(), "_");
                    }
                    name = name.Replace(" ", "_");
                    destVirtualFileName = Path.Combine(ComponentUtility.GetOwnedFileNameOfComponent(scene) + "_Files", name);

                    destVirtualFileName += Path.GetExtension(link);
                }

                var destRealFileName = VirtualPathUtility.GetRealPathByVirtual(destVirtualFileName);


                if (File.Exists(destRealFileName))
                {
                    if (EditorMessageBox.ShowQuestion($"Overwrite \'{destRealFileName}\'?", EMessageBoxButtons.OKCancel) == EDialogResult.Cancel)
                    {
                        return;
                    }
                }

                Directory.CreateDirectory(Path.GetDirectoryName(destRealFileName));

                if (File.Exists(link))
                {
                    File.Copy(link, destRealFileName, true);
                }
                else
                {
                    //if( Uri.IsWellFormedUriString( link, UriKind.Absolute ) )
                    //{
                    using (var client = new WebClient())
                        client.DownloadFile(link, destRealFileName);
                    //}
                }

                var oldValue = sky.Cubemap;

                sky.Cubemap = ReferenceUtility.MakeReference(destVirtualFileName);

                //undo
                var property   = (Metadata.Property)sky.MetadataGetMemberBySignature("property:Cubemap");
                var undoItem   = new UndoActionPropertiesChange.Item(sky, property, oldValue);
                var undoAction = new UndoActionPropertiesChange(undoItem);
                Provider.DocumentWindow.Document.CommitUndoAction(undoAction);
            }
            catch (Exception e)
            {
                EditorMessageBox.ShowWarning(e.Message);
            }
            finally
            {
                notification.Close();
            }
        }
Ejemplo n.º 4
0
        private void kryptonButtonInstall_Click(object sender, EventArgs e)
        {
            var info = PackageManager.ReadPackageArchiveInfo(selectedPackage.FullFilePath, out var error);

            if (info == null)
            {
                return;
            }

            var filesToCopy = new List <string>();

            foreach (var file in info.Files)
            {
                var fullName = Path.Combine(VirtualFileSystem.Directories.Project, file);
                filesToCopy.Add(fullName);
            }

            var text = string.Format(Translate("Install {0}?\n\n{1} files will created."), selectedPackage.GetDisplayName(), filesToCopy.Count);

            //var text = string.Format( Translate( "Install {0}?\r\n\r\n{1} files will created." ), selectedPackage.Name, filesToCopy.Count );
            //var text = $"Install {selectedPackage.Name}?\r\n\r\n{filesToCopy.Count} files will created.";

            if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.YesNo) != EDialogResult.Yes)
            {
                return;
            }

            var notification = ScreenNotifications.ShowSticky("Installing the package...");

            try
            {
                using (var archive = ZipFile.OpenRead(selectedPackage.FullFilePath))
                {
                    foreach (var entry in archive.Entries)
                    {
                        var  fileName  = entry.FullName;
                        bool directory = fileName[fileName.Length - 1] == '/';
                        if (fileName != "Package.info" && !directory)
                        {
                            var fullPath = Path.Combine(VirtualFileSystem.Directories.Project, fileName);

                            var directoryName = Path.GetDirectoryName(fullPath);
                            if (!Directory.Exists(directoryName))
                            {
                                Directory.CreateDirectory(directoryName);
                            }

                            entry.ExtractToFile(fullPath, true);
                        }
                    }
                }

                PackageManager.ChangeInstalledState(selectedPackage.Name, true);
            }
            catch (Exception e2)
            {
                EditorMessageBox.ShowWarning(e2.Message);
                return;
            }
            finally
            {
                notification.Close();
            }

            if (!string.IsNullOrEmpty(info.AddCSharpFilesToProject))
            {
                var toAdd = new ESet <string>();

                var path = Path.Combine(VirtualFileSystem.Directories.Assets, info.AddCSharpFilesToProject);
                if (Directory.Exists(path))
                {
                    var fullPaths = CSharpProjectFileUtility.GetProjectFileCSFiles(false, true);
                    var files     = Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories);
                    foreach (var file in files)
                    {
                        if (!fullPaths.Contains(file))
                        {
                            toAdd.AddWithCheckAlreadyContained(file);
                        }
                    }
                }

                //	if( !fileItem.IsDirectory && Path.GetExtension( fileItem.FullPath ).ToLower() == ".cs" )
                //	{
                //		bool added = CSharpProjectFileUtility.GetProjectFileCSFiles( false, true ).Contains( fileItem.FullPath );
                //		if( !added )
                //			toAdd.Add( fileItem.FullPath );
                //	}

                if (toAdd.Count != 0)
                {
                    if (CSharpProjectFileUtility.UpdateProjectFile(toAdd, null, out var error2))
                    {
                        if (toAdd.Count > 1)
                        {
                            Log.Info(EditorLocalization.Translate("General", "Items have been added to the Project.csproj."));
                        }
                        else
                        {
                            Log.Info(EditorLocalization.Translate("General", "The item has been added to the Project.csproj."));
                        }
                    }
                    else
                    {
                        Log.Warning(error2);
                    }
                }
            }

            needUpdateList = true;

            if (info.MustRestart)
            {
                ShowRestartLabel();
            }

            if (!string.IsNullOrEmpty(info.OpenAfterInstall))
            {
                var realFileName = VirtualPathUtility.GetRealPathByVirtual(info.OpenAfterInstall);

                if (info.MustRestart)
                {
                    EditorSettingsSerialization.OpenFileAtStartup = realFileName;
                }
                else
                {
                    EditorAPI.SelectFilesOrDirectoriesInMainResourcesWindow(new string[] { realFileName }, Directory.Exists(realFileName));
                    EditorAPI.OpenFileAsDocument(realFileName, true, true);
                }
            }

            ScreenNotifications.Show(EditorLocalization.Translate("General", "The package has been successfully installed."));

            //restart application
            if (info.MustRestart)
            {
                var text2 = EditorLocalization.Translate("General", "To apply changes need restart the editor. Restart?");
                if (EditorMessageBox.ShowQuestion(text2, EMessageBoxButtons.YesNo) == EDialogResult.Yes)
                {
                    EditorAPI.BeginRestartApplication();
                }
            }
        }
Ejemplo n.º 5
0
        void RenderByEngineRender()
        {
            var renderToFile = RenderToFile;
            var scene        = renderToFile.ParentRoot as Component_Scene;

            //get camera
            var camera = renderToFile.Camera.Value;

            if (camera == null)
            {
                camera = scene.Mode.Value == Component_Scene.ModeEnum._2D ? scene.CameraEditor2D : scene.CameraEditor;
            }
            if (camera == null)
            {
                EditorMessageBox.ShowWarning("Camera is not specified.");
                return;
            }

            var destRealFileName = renderToFile.OutputFileName.Value.Trim();

            if (!Path.IsPathRooted(destRealFileName) && !string.IsNullOrEmpty(destRealFileName))
            {
                destRealFileName = VirtualPathUtility.GetRealPathByVirtual(destRealFileName);
            }

            if (string.IsNullOrEmpty(destRealFileName))
            {
                var dialog = new SaveFileDialog();
                //dialog.InitialDirectory = Path.GetDirectoryName( RealFileName );
                if (renderToFile.Mode.Value == Component_RenderToFile.ModeEnum.Material)
                {
                    dialog.FileName = "Output.material";
                    dialog.Filter   = "Material files (*.material)|*.material";
                }
                else
                {
                    dialog.FileName = "Output.png";
                    dialog.Filter   = "PNG files (*.png)|*.png";
                }
                dialog.RestoreDirectory = true;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                destRealFileName = dialog.FileName;
            }
            else
            {
                //!!!!material mode

                //file already exists
                if (File.Exists(destRealFileName))
                {
                    var text = $"The file with name \'{destRealFileName}\' is already exists. Overwrite?";
                    if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.Cancel)
                    {
                        return;
                    }
                }
            }

            var item = ScreenNotifications.ShowSticky("Processing...");

            try
            {
                if (renderToFile.Mode.Value == Component_RenderToFile.ModeEnum.Material)
                {
                    RenderMaterial(camera, destRealFileName);
                }
                else
                {
                    RenderScreenshot(camera, destRealFileName);
                }
            }
            finally
            {
                item.Close();
            }
        }