Exemplo n.º 1
0
 /// <summary>
 /// Draws the source section. You can override this if you want to draw more
 /// than the Source File selection field.
 /// </summary>
 protected virtual void DrawSourceSection()
 {
     EditorGUILayout.BeginHorizontal();
     prefs.sourceFilename = EditorGUILayout.TextField("Source File", prefs.sourceFilename);
     if (GUILayout.Button("...", EditorStyles.miniButton, GUILayout.Width(22)))
     {
         prefs.sourceFilename =
             EditorUtility.OpenFilePanel("Select Source File",
                                         EditorWindowTools.GetDirectoryName(prefs.sourceFilename),
                                         SourceFileExtension);
         GUIUtility.keyboardControl = 0;
     }
     EditorGUILayout.EndHorizontal();
 }
Exemplo n.º 2
0
        private void ExportSeparateLanguages()
        {
            if (table == null)
            {
                return;
            }
            string newFilename = EditorUtility.SaveFilePanel("Export Language Text", EditorWindowTools.GetDirectoryName(languageDumpBaseFilename), languageDumpBaseFilename, "txt");

            if (!string.IsNullOrEmpty(newFilename))
            {
                languageDumpBaseFilename = newFilename;
                ExportLanguage(0, languageDumpBaseFilename);
                for (int i = 1; i < table.languages.Count; i++)
                {
                    var filename = Path.GetDirectoryName(languageDumpBaseFilename) + "/" + Path.GetFileNameWithoutExtension(languageDumpBaseFilename) + "_" + table.languages[i] + ".txt";
                    ExportLanguage(i, filename);
                }
            }
        }
Exemplo n.º 3
0
        private void Export()
        {
            string newFilename = EditorUtility.SaveFilePanel("Export to CSV", EditorWindowTools.GetDirectoryName(csvFilename), csvFilename, "csv");

            if (!string.IsNullOrEmpty(newFilename))
            {
                csvFilename = newFilename;
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    csvFilename = csvFilename.Replace("/", "\\");
                }
                using (StreamWriter file = new StreamWriter(csvFilename, false, EncodingTypeTools.GetEncoding(encodingType)))
                {
                    // Write heading:
                    StringBuilder sb = new StringBuilder();
                    sb.Append("Field");
                    foreach (var language in table.languages)
                    {
                        sb.AppendFormat(",{0}", CSVExporter.CleanField(language));
                    }
                    file.WriteLine(sb);

                    // Write fields:
                    foreach (var field in table.fields)
                    {
                        sb = new StringBuilder();
                        sb.Append(CSVExporter.CleanField(field.name));
                        foreach (var value in field.values)
                        {
                            sb.AppendFormat(",{0}", CSVExporter.CleanField(value));
                        }
                        file.WriteLine(sb);
                    }
                }
                EditorUtility.DisplayDialog("Export Complete", "The localized text table was exported to CSV (comma-separated values) format. ", "OK");
            }
        }
Exemplo n.º 4
0
        private void DrawControls()
        {
            EditorGUIUtility.LookLikeControls();

            // Project Format:
            EditorGUILayout.BeginHorizontal();
            ChatMapperProjectFormat newFormat = (ChatMapperProjectFormat)EditorGUILayout.Popup(new GUIContent("Project Format", "Converting from CMP requires Chat Mapper Commercial."), (int)prefs.projectFormat, FormatOptions);

            if (newFormat != prefs.projectFormat)
            {
                for (int i = 0; i < prefs.projectFilenames.Count; i++)
                {
                    if (newFormat == ChatMapperProjectFormat.Cmp)
                    {
                        prefs.projectFilenames[i] = prefs.projectFilenames[i].Replace("xml", "cmp");
                    }
                    else
                    {
                        prefs.projectFilenames[i] = prefs.projectFilenames[i].Replace("cmp", "xml");
                    }
                }
                prefs.projectFormat        = newFormat;
                GUIUtility.keyboardControl = 0;
            }
            EditorGUILayout.EndHorizontal();

            // Path to ChatMapper.exe:
            if (prefs.projectFormat == ChatMapperProjectFormat.Cmp)
            {
                if (string.IsNullOrEmpty(prefs.pathToChatMapperExe))
                {
                    EditorGUILayout.HelpBox("To directly convert CMP files, the Dialogue System will run ChatMapper.exe in the background. Specify the location of ChatMapper.exe in the field below.", MessageType.Info);
                }
            }
            EditorGUILayout.BeginHorizontal();
            prefs.pathToChatMapperExe = EditorGUILayout.TextField(new GUIContent("Path to ChatMapper.exe", "Optional if converting XML. Also used to open CMP files in Project with double-click."), prefs.pathToChatMapperExe);
            if (GUILayout.Button("...", EditorStyles.miniButtonRight, GUILayout.Width(22)))
            {
                prefs.pathToChatMapperExe  = EditorUtility.OpenFilePanel("Path to ChatMapper.exe", "", "exe");
                GUIUtility.keyboardControl = 0;
            }
            EditorGUILayout.EndHorizontal();

            // Paths to Chat Mapper Projects:
            if (!HasValidProjectFilenames())
            {
                EditorGUILayout.HelpBox("Specify the Chat Mapper project(s) to convert. Click '+' to add a Chat Mapper project", MessageType.Info);
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Chat Mapper Projects", "Specify project to convert here."));
            if (GUILayout.Button(new GUIContent("+", "Add another Chat Mapper project to convert"), EditorStyles.miniButtonRight, GUILayout.Width(22)))
            {
                prefs.projectFilenames.Add(string.Empty);
                prefs.includeProjectFilenames.Add(true);
            }
            EditorGUILayout.EndHorizontal();
            if (prefs.includeProjectFilenames.Count < prefs.projectFilenames.Count)
            {
                for (int i = prefs.includeProjectFilenames.Count; i < prefs.projectFilenames.Count; i++)
                {
                    prefs.includeProjectFilenames.Add(true);
                }
            }
            int projectFilenameToDelete = -1;

            for (int i = 0; i < prefs.projectFilenames.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                prefs.projectFilenames[i]        = EditorGUILayout.TextField("    Filename", prefs.projectFilenames[i]);
                prefs.includeProjectFilenames[i] = EditorGUILayout.Toggle(prefs.includeProjectFilenames[i], GUILayout.Width(16));
                if (GUILayout.Button("...", EditorStyles.miniButtonMid, GUILayout.Width(22)))
                {
                    prefs.projectFilenames[i]  = EditorUtility.OpenFilePanel("Select Chat Mapper Project", EditorWindowTools.GetDirectoryName(prefs.projectFilenames[i]), GetFormatExtension(prefs.projectFormat));
                    GUIUtility.keyboardControl = 0;
                }
                if (GUILayout.Button(new GUIContent("-", "Remove this slot."), EditorStyles.miniButtonRight, GUILayout.Width(22)))
                {
                    projectFilenameToDelete = i;
                }
                EditorGUILayout.EndHorizontal();
            }
            if (projectFilenameToDelete >= 0)
            {
                prefs.projectFilenames.RemoveAt(projectFilenameToDelete);
            }

            // Portrait Folder:
            EditorGUILayout.BeginHorizontal();
            prefs.portraitFolder = EditorGUILayout.TextField(new GUIContent("Portrait Folder", "Optional folder containing actor portrait textures. The converter will search this folder for textures matching any actor pictures defined in the Chat Mapper project."), prefs.portraitFolder);
            if (GUILayout.Button("...", EditorStyles.miniButtonRight, GUILayout.Width(22)))
            {
                prefs.portraitFolder       = EditorUtility.OpenFolderPanel("Location of Portrait Textures", prefs.portraitFolder, "");
                prefs.portraitFolder       = "Assets" + prefs.portraitFolder.Replace(Application.dataPath, string.Empty);
                GUIUtility.keyboardControl = 0;
            }
            EditorGUILayout.EndHorizontal();

            // Save To:
            if (string.IsNullOrEmpty(prefs.outputFolder))
            {
                EditorGUILayout.HelpBox("In the field below, specify the folder to create the dialogue database asset(s) in.", MessageType.Info);
            }
            EditorGUILayout.BeginHorizontal();
            prefs.outputFolder = EditorGUILayout.TextField(new GUIContent("Save To", "Folder where dialogue database assets will be saved."), prefs.outputFolder);
            if (GUILayout.Button("...", EditorStyles.miniButtonRight, GUILayout.Width(22)))
            {
                prefs.outputFolder         = EditorUtility.SaveFolderPanel("Path to Save Database", prefs.outputFolder, "");
                prefs.outputFolder         = "Assets" + prefs.outputFolder.Replace(Application.dataPath, string.Empty);
                GUIUtility.keyboardControl = 0;
            }
            EditorGUILayout.EndHorizontal();

            // Project/Database Name:
            bool hasMultipleProjects = (prefs.projectFilenames.Count > 1);

            if (hasMultipleProjects)
            {
                prefs.useProjectName = true;
            }
            EditorGUI.BeginDisabledGroup(hasMultipleProjects);
            prefs.useProjectName = EditorGUILayout.Toggle(new GUIContent("Use Project Name", "Tick to use project name defined in Chat Mapper project, untick to specify a name."), prefs.useProjectName);
            EditorGUI.EndDisabledGroup();
            if (!prefs.useProjectName)
            {
                prefs.databaseName = EditorGUILayout.TextField(new GUIContent("Dialogue Database Name", "Filename to create in Save To folder."), prefs.databaseName);
            }

            // Overwrite:
            prefs.overwrite = EditorGUILayout.Toggle(new GUIContent("Overwrite", "Tick to overwrite the dialogue database if it exists, untick to create a new copy."), prefs.overwrite);

            // Buttons:
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Clear", GUILayout.Width(100)))
            {
                ClearPrefs();
            }
            bool disabled = (string.IsNullOrEmpty(prefs.pathToChatMapperExe) && (prefs.projectFormat == ChatMapperProjectFormat.Cmp)) ||
                            !HasValidProjectFilenames() ||
                            string.IsNullOrEmpty(prefs.outputFolder) ||
                            (!prefs.useProjectName && string.IsNullOrEmpty(prefs.databaseName));

            EditorGUI.BeginDisabledGroup(disabled);
            if (GUILayout.Button("Convert", GUILayout.Width(100)))
            {
                ConvertChatMapperProjects();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            if (GUI.changed)
            {
                SavePrefs();
            }
        }
        private void Import()
        {
            if (!EditorUtility.DisplayDialog("Import CSV?",
                                             "Importing from CSV will overwrite the current contents. Are you sure?",
                                             "Import", "Cancel"))
            {
                return;
            }
            string newFilename = EditorUtility.OpenFilePanel("Import from CSV", EditorWindowTools.GetDirectoryName(csvFilename), "csv");

            if (!string.IsNullOrEmpty(newFilename))
            {
                csvFilename = newFilename;
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    csvFilename = csvFilename.Replace("/", "\\");
                }
                try {
                    using (StreamReader file = new StreamReader(csvFilename, Encoding.UTF8)) {
                        // Work with a temporary, new table:
                        LocalizedTextTable newTable = ScriptableObject.CreateInstance <LocalizedTextTable>();

                        // Read heading:
                        string[] values = CSVExporter.GetValues(file.ReadLine());
                        newTable.languages = new List <string>(values);
                        newTable.languages.RemoveAt(0);

                        // Read fields:
                        newTable.fields.Clear();
                        while (!file.EndOfStream)
                        {
                            values = CSVExporter.GetValues(file.ReadLine());
                            LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                            field.name = values[0];
                            for (int i = 1; i < values.Length; i++)
                            {
                                field.values.Add(values[i]);
                            }
                            newTable.fields.Add(field);
                        }

                        // If we got to the end, use the new table:
                        table.languages.Clear();
                        foreach (var newLanguage in newTable.languages)
                        {
                            table.languages.Add(newLanguage);
                        }
                        table.fields.Clear();
                        foreach (var newField in newTable.fields)
                        {
                            LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                            field.name   = newField.name;
                            field.values = new List <string>(newField.values);
                            table.fields.Add(field);
                        }
                        DestroyImmediate(newTable);
                    }
                } catch (System.Exception e) {
                    Debug.LogError(e.Message);
                    EditorUtility.DisplayDialog("Import Failed", "There was an error importing the CSV file.", "OK");
                }
                EditorUtility.DisplayDialog("Export Complete", "The localized text table was exported to CSV (comma-separated values) format. ", "OK");
            }
        }
Exemplo n.º 6
0
        private void Import()
        {
            if (!EditorUtility.DisplayDialog("Import CSV?",
                                             "Importing from CSV will overwrite the current contents. Are you sure?",
                                             "Import", "Cancel"))
            {
                return;
            }
            string newFilename = EditorUtility.OpenFilePanel("Import from CSV", EditorWindowTools.GetDirectoryName(csvFilename), "csv");

            if (!string.IsNullOrEmpty(newFilename))
            {
                csvFilename = newFilename;
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    csvFilename = csvFilename.Replace("/", "\\");
                }
                try
                {
                    // Read the source file and combine multiline rows:
                    var    sourceLines = new List <string>();
                    var    file        = new StreamReader(csvFilename, EncodingTypeTools.GetEncoding(encodingType));
                    string line;
                    while ((line = file.ReadLine()) != null)
                    {
                        sourceLines.Add(line.TrimEnd());
                    }
                    file.Close();
                    CombineMultilineSourceLines(sourceLines);
                    if (sourceLines.Count < 1)
                    {
                        throw new System.Exception("No lines read from CSV file.");
                    }

                    // Work with a temporary, new table:
                    LocalizedTextTable newTable = ScriptableObject.CreateInstance <LocalizedTextTable>();

                    // Read heading:
                    string[] values = CSVExporter.GetValues(sourceLines[0]);
                    sourceLines.RemoveAt(0);
                    newTable.languages = new List <string>(values);
                    newTable.languages.RemoveAt(0);

                    // Read fields:
                    newTable.fields.Clear();
                    while (sourceLines.Count > 0)
                    {
                        values = CSVExporter.GetValues(sourceLines[0]);
                        sourceLines.RemoveAt(0);
                        LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                        field.name = values[0];
                        for (int i = 1; i < values.Length; i++)
                        {
                            field.values.Add(values[i]);
                        }
                        newTable.fields.Add(field);
                    }

                    // If we got to the end, use the new table:
                    table.languages.Clear();
                    foreach (var newLanguage in newTable.languages)
                    {
                        table.languages.Add(newLanguage);
                    }
                    table.fields.Clear();
                    foreach (var newField in newTable.fields)
                    {
                        LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                        field.name   = newField.name;
                        field.values = new List <string>(newField.values);
                        table.fields.Add(field);
                    }
                    DestroyImmediate(newTable);
                }
                catch (System.Exception e)
                {
                    Debug.LogError(e.Message);
                    EditorUtility.DisplayDialog("Import Failed", "There was an error importing the CSV file.", "OK");
                }
                EditorUtility.DisplayDialog("Import Complete", "The localized text table was imported from " + newFilename + ".", "OK");
            }
        }