コード例 #1
0
    public void Init(DialogueFile file, string entry)
    {
        this.file = file;
        //this.currentEntryId = entry;

        // get all the speakers in the file
        speakers.Clear();
        entrySpeakers.Clear();
        foreach (DialogueFile.DialogueEntry e in file.entries)
        {
            if (e.id == entry)
            {
                currentEntry = e;
            }
            foreach (string s in e.speakers)
            {
                speakers.Add(s);
                if (e.id == entry)
                {
                    entrySpeakers.Add(s);
                }
            }
        }

        speakers.ExceptWith(entrySpeakers);
        if (currentEntry.speakers == null)
        {
            currentEntry.speakers = new List <string>();
        }
    }
コード例 #2
0
	void serializeToXML(string filename, DialogueFile dialogue)
	{
		XmlSerializer serializer = new XmlSerializer(typeof(DialogueFile));
		TextWriter textWriter = new StreamWriter(filename);
		serializer.Serialize(textWriter, dialogue);
		textWriter.Close();
	}
コード例 #3
0
ファイル: EditSpeakers.cs プロジェクト: pyrosousa/sean_VM364
    public void Init(DialogueFile file, string entry)
    {
        this.file = file;
        //this.currentEntryId = entry;

        // get all the speakers in the file
        speakers.Clear();
        entrySpeakers.Clear();
        foreach (DialogueFile.DialogueEntry e in file.entries)
        {
            if (e.id == entry)
                currentEntry = e;
            foreach (string s in e.speakers)
            {
                speakers.Add(s);
                if (e.id == entry)
                {
                    entrySpeakers.Add(s);
                }
            }
        }

        speakers.ExceptWith(entrySpeakers);
        if (currentEntry.speakers == null)
            currentEntry.speakers = new List<string>();
    }
コード例 #4
0
    private void CreateNewFile()
    {
        DialogueFile asset = ScriptableObject.CreateInstance <DialogueFile>();

        asset.Names    = new List <string>();
        asset.Dialogue = new List <string>();

        for (int i = 0; i < NumberOfLines; i++)
        {
            asset.Names.Add(NewNames[i]);
            asset.Dialogue.Add(NewDialogue[i]);
        }

        if (!System.IO.Directory.Exists(Application.dataPath + "/Dialogue"))
        {
            AssetDatabase.CreateFolder("Assets", "Dialogue");
        }

        AssetDatabase.CreateAsset(asset, "Assets/Dialogue/" + FileName + ".asset");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();

        ClearLists();
    }
コード例 #5
0
    void SaveConversation(DialogueFile dialogueFile, Conversation conversation)
    {
        string conversationAsJson = JsonUtility.ToJson(conversation);

        Directory.CreateDirectory(dialogueFile.directory);
        File.WriteAllText(dialogueFile.file, conversationAsJson);
    }
コード例 #6
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();

        EditorGUILayout.PropertyField(fromLanguage, true);
        EditorGUILayout.PropertyField(conversation, true);

        DialogueFile dialogueFileFrom =
            new DialogueFile(dialogue.name, dialogue.fromLanguage.ToString());

        BuildButtons(dialogueFileFrom, dialogue.conversation, true);

        GUILayout.EndVertical();

        GUILayout.BeginVertical();

        EditorGUILayout.PropertyField(toLanguage, true);
        EditorGUILayout.PropertyField(conversationToTranslate, true);

        DialogueFile dialogueFileTo =
            new DialogueFile(dialogue.name, dialogue.toLanguage.ToString());

        BuildButtons(dialogueFileTo, dialogue.conversationToTranslate, false);

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        serializedObject.ApplyModifiedProperties();
    }
コード例 #7
0
 public void ChangeFile(DialogueFile I)
 {
     if (I)
     {
         File = I;
     }
     R();
 }
コード例 #8
0
	DialogueFile deserializeFromXML(string filename)
	{
		XmlSerializer serializer = new XmlSerializer(typeof(DialogueFile));
		TextReader textReader = new StreamReader(filename);
		DialogueFile result = serializer.Deserialize(textReader) as DialogueFile;
		textReader.Close();
		return result;
	}
コード例 #9
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            this.SetMain(entity, main);
            entity.CannotSuspend = true;

            DialogueFile file = entity.GetOrCreate <DialogueFile>("DialogueFile");

            file.EditorProperties();
        }
コード例 #10
0
        public override string Run(DialogueFile file, DialogueLine line)
        {
            if (target == null) {
                DialogueCompiler.Instance.Error(line, "No chapter specified");
                return null;
            }

            line.Options.SetSet(DialogueCompiler.ChapterVariable, target);
            return "";
        }
コード例 #11
0
        public override bool Run(DialogueFile file)
        {
            if (DialogueCompiler.Instance.DialogueName == null) {
                DialogueCompiler.Instance.DialogueName = name.Content;
            } else {
                if (DialogueCompiler.Instance.DialogueName != name.Content) {
                    DialogueCompiler.Instance.PrintWarning(name, "Dialogue name is already defined. Only the first dialogue name is used");
                }
            }

            return false;
        }
コード例 #12
0
        public override bool Run(DialogueFile file)
        {
            if (file.ChapterName != null) {
                DialogueCompiler.Instance.Error(line, "File already has a chapter name");
            } else if (DialogueCompiler.Instance.HasChapter(line.Content)) {
                DialogueCompiler.Instance.Error(line, "Chapter name '{0}' is used for another file", line.Content);
            } else {
                file.ChapterName = line.Content;
                DialogueCompiler.Instance.ProvideChapter(line.Content);
            }

            return false;
        }
コード例 #13
0
    void Start()
    {
        fromLanguage = DialogueManager.dialogueManager.fromLanguage;
        toLanguage   = DialogueManager.dialogueManager.toLanguage;

        dialogueFileFrom = new DialogueFile(name, fromLanguage.ToString());
        dialogueFileTo   = new DialogueFile(name, toLanguage.ToString());

        conversation            = dialogueFileFrom.LoadConversation();
        conversationToTranslate = dialogueFileTo.LoadConversation();

        VerifyDialogueData();
    }
コード例 #14
0
    public void DNL()
    {
        if (File == null)
        {
            FileHasEnded = true;
        }
        if (DS < File.Names.Count)
        {
            switch (File.Names[DS])
            {
            case "###":
                DialName.text = "";
                DialText.text = "";
                if (PCo == null)
                {
                    PCo = SC(CL(File.Dialogue[DS]));
                }
                break;

            case "@@@":
                if (PCo == null)
                {
                    PCo = SC(PD(3));
                }
                break;

            case "^^^":
                AnimToPlay.Play(File.Dialogue[DS], -1);
                break;

            case "***":
                DS           = 0;
                FileHasEnded = true;
                break;

            default:
                DialName.text = File.Names[DS];
                DialText.text = File.Dialogue[DS];
                DS++;
                InputPressed = false;
                break;
            }
        }
        else
        {
            DialName.text = "";
            DialText.text = "";
            FileHasEnded  = true;
            File          = null;
        }
    }
コード例 #15
0
    DialogueFile DeserializeFromJson(string filename)
    {
        TextReader textReader = new StreamReader(filename);
        //Debug.Log (textReader.ReadToEnd ());
        //DialogueFile result = JsonUtility.FromJson<DialogueFile> (textReader.ReadToEnd ());
        //textReader.Close ();
        string json = File.ReadAllText(filename);

        Debug.Log(json);
        DialogueFile file = new DialogueFile();

        JsonUtility.FromJsonOverwrite(json, file);
        return(file);
    }
コード例 #16
0
    /// <summary>
    /// Load a dialogue file by the given DialogueFile reference
    /// </summary>
    /// <param name="file">A reference to a DialogueFile</param>
    /// <returns>A DialogueManager holding the file reference</returns>
    public static DialogueManager LoadDialogueFile(DialogueFile file)
    {
        if (managers.ContainsKey(file))
        {
            return(managers[file]);
        }

        // load file, optimize for searching dialogues
        DialogueManager manager = new DialogueManager();

        managers.Add(file, manager);

        manager.file = file;

        return(manager);
    }
コード例 #17
0
    public static DialogueManager GetFileFromJSON(string json)
    {
        Debug.Log(json);
        DialogueFile dialogueFile = DialogueFile.CreateInstance("DialogueFile") as DialogueFile;

        JsonUtility.FromJsonOverwrite(json, dialogueFile);
        Debug.Log(dialogueFile.ToString());
        if (managers.ContainsKey(dialogueFile))
        {
            return(managers[dialogueFile]);
        }
        DialogueManager manager = new DialogueManager();

        managers.Add(dialogueFile, manager);
        manager.file = dialogueFile;
        return(manager);
    }
コード例 #18
0
 void BuildButtons(DialogueFile dialogueFile, Conversation conversation, bool isTo)
 {
     if (GUILayout.Button(string.Format("Load from {0}", dialogueFile.fileRelative)))
     {
         if (isTo)
         {
             dialogue.conversation = dialogueFile.LoadConversation();
         }
         else
         {
             dialogue.conversationToTranslate = dialogueFile.LoadConversation();
         }
     }
     if (GUILayout.Button(string.Format("Save to {0}", dialogueFile.fileRelative)))
     {
         SaveConversation(dialogueFile, conversation);
     }
 }
コード例 #19
0
    private void CreateNewFile()
    {
        DialogueFile asset = ScriptableObject.CreateInstance <DialogueFile>();

        asset.Names    = new List <string>();
        asset.Dialogue = new List <string>();

        for (int i = 0; i < NumberOfLines; i++)
        {
            asset.Names.Add(NewNames[i]);
            asset.Dialogue.Add(NewDialogue[i]);
        }

        AssetDatabase.CreateAsset(asset, "Assets/Dialogue/" + FileName + ".asset");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();

        ClearLists();
    }
コード例 #20
0
	string createUniqueDialogueName()
	{
		DialogueFile file = files[filePopupSelectedIndex];
		int index = 0;
		string baseName = "newDialogue";
		string currentCheck = baseName;
		bool found = true;
		while (found)
		{
			found = false;
			foreach (DialogueFile.DialogueEntry entry in file.entries)
			{
				if (entry.id.IndexOf(currentCheck) == 0)
				{
					index++;
					currentCheck = baseName + index;
					found = true;
					break;
				}
			}
		}
		return currentCheck;
	}
コード例 #21
0
        public static string ExecuteCommands(DialogueFile file, DialogueLine line)
        {
            int startAt = 0;
            bool keep = true;
            var newLine = new StringBuilder(line.Content.Length);
            var match = commandPattern.Match(line.Content, startAt);
            while (match.Success) {
                newLine.Append(line.Content.Substring(startAt, match.Index - startAt));

                var commandName = match.Groups[1].Value;
                if (commands.ContainsKey(commandName)) {
                    var args = new string[match.Groups[2].Captures.Count];
                    for (int i = 0; i < match.Groups[2].Captures.Count; ++i) {
                        args[i] = match.Groups[2].Captures[i].Value;
                    }

                    var command = commands[commandName](commandName, args);

                    var replacement = command.Run(file, line);
                    if (replacement == null) {
                        keep = false;
                    } else {
                        newLine.Append(replacement);
                    }

                } else {
                    (new NoSuchCommand(commandName, null)).Run(file, line);
                }

                startAt = match.Index + match.Length;
                match = commandPattern.Match(line.Content, startAt);
            }

            newLine.Append(line.Content.Substring(startAt));

            return keep ? newLine.ToString() : null;
        }
コード例 #22
0
    // The stuff that shows up in the window
    public void OnGUI()
    {
        DeselectWindow = new Rect(0, 0, position.width, position.height);

        GUILayout.Space(15f);

        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        Tab = GUILayout.Toolbar(Tab, new string[] { "Create New File", "Edit Existing File" }, GUILayout.MaxWidth(250f), GUILayout.MaxHeight(25f));
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(5f);

        NewNames.Add("");
        NewDialogue.Add("");

        switch (Tab)
        {
        // If Creating a new file
        case 0:

            GUILayout.Space(20);

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("File Name:", GUILayout.MaxWidth(65f));
            FileName = EditorGUILayout.TextField(FileName);
            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10f);

            // Displays the table headers
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("No:", GUILayout.MaxWidth(30f));
            EditorGUILayout.LabelField("Character:", GUILayout.MaxWidth(200f));
            EditorGUILayout.LabelField("Dialogue:", GUILayout.MinWidth(100f));
            EventChoice = (EventOptions)EditorGUILayout.EnumPopup(EventChoice, GUILayout.MaxWidth(75f));

            EditorGUILayout.EndHorizontal();

            ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos, GUILayout.Width(position.width), GUILayout.ExpandHeight(true));

            // Displays the table for the number of lines added to the file
            for (int i = 0; i < NumberOfLines; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(i.ToString(), GUILayout.MaxWidth(30f));
                NewNames[i]    = EditorGUILayout.TextField(NewNames[i], GUILayout.MaxWidth(200f));
                NewDialogue[i] = EditorGUILayout.TextField(NewDialogue[i]);

                GUILayout.Space(10f);

                GUI.backgroundColor = Color.yellow;

                if (GUILayout.Button("~", GUILayout.Width(25)))
                {
                    string Choice;

                    switch (EventChoice)
                    {
                    case EventOptions.None:
                        Choice = "";
                        break;

                    case EventOptions.Cinematic:
                        Choice = "###";
                        break;

                    case EventOptions.Pause:
                        Choice = "@@@";
                        break;

                    case EventOptions.ExitDial:
                        Choice = "***";
                        break;

                    case EventOptions.Animation:
                        Choice = "^^^";
                        break;

                    default:
                        Choice = "";
                        break;
                    }

                    // this is where the event would be set, might make a enum to select a tye of event in the future...
                    NewNames.Insert(i, Choice);
                    NewDialogue.Insert(i, Choice);
                }

                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("+", GUILayout.Width(25)))
                {
                    NumberOfLines++;
                    NewNames.Insert(i + 1, "");
                    NewDialogue.Insert(i + 1, "");
                }

                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("-", GUILayout.Width(25)))
                {
                    if (i != 0)
                    {
                        NumberOfLines--;
                        NewNames.RemoveAt(i);
                        NewDialogue.RemoveAt(i);
                    }
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }

            // Creates a new Dialogue File with the name and text inputted
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("Create File", GUILayout.MaxWidth(100f)))
            {
                CreateFile = true;
            }
            GUI.backgroundColor = Color.white;
            if (GUILayout.Button("Reset File", GUILayout.MaxWidth(100f)))
            {
                ClearLists();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();

            break;

        // If editing an exsisting file
        case 1:



            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Here you can edit already exsisting files as if you were creating them.");
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);

            // Label & Box for the user to select the Dialogue FIle they wish to edit
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUILayout.LabelField("Dialogue File: ", GUILayout.MaxWidth(80f));
            CurrentFile = (DialogueFile)EditorGUILayout.ObjectField(CurrentFile, typeof(DialogueFile), false);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (CurrentFile != null)
            {
                GUILayout.Space(20);

                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("Edit File Name:", GUILayout.MaxWidth(100f));
                CurrentFile.name = EditorGUILayout.TextField(CurrentFile.name);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(10);
                EditorGUILayout.LabelField("Contents of File:", GUILayout.MaxWidth(100f));
                GUILayout.Space(5);

                // Table Headers
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("No:", GUILayout.MaxWidth(30f));
                EditorGUILayout.LabelField("Character:", GUILayout.MaxWidth(200f));
                EditorGUILayout.LabelField("Dialogue:", GUILayout.MinWidth(100f));
                EventChoice = (EventOptions)EditorGUILayout.EnumPopup(EventChoice, GUILayout.MaxWidth(75f));
                EditorGUILayout.EndHorizontal();

                ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos, GUILayout.Width(position.width), GUILayout.ExpandHeight(true));

                // Displays the current file's dialogue in the correct boxes and allow it to be edited
                for (int i = 0; i < CurrentFile.Names.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(i.ToString(), GUILayout.MaxWidth(30f));
                    CurrentFile.Names[i]    = EditorGUILayout.TextField(CurrentFile.Names[i], GUILayout.MaxWidth(200f));
                    CurrentFile.Dialogue[i] = EditorGUILayout.TextField(CurrentFile.Dialogue[i], GUILayout.MaxWidth(400f));
                    GUILayout.Space(10);

                    GUI.backgroundColor = Color.yellow;

                    if (GUILayout.Button("~", GUILayout.Width(25)))
                    {
                        string Choice;

                        switch (EventChoice)
                        {
                        case EventOptions.None:
                            Choice = "";
                            break;

                        case EventOptions.Cinematic:
                            Choice = "###";
                            break;

                        case EventOptions.Pause:
                            Choice = "@@@";
                            break;

                        case EventOptions.ExitDial:
                            Choice = "***";
                            break;

                        case EventOptions.Animation:
                            Choice = "^^^";
                            break;

                        default:
                            Choice = "";
                            break;
                        }

                        // this is where the event would be set, might make a enum to select a tye of event in the future...
                        NewNames.Insert(i, Choice);
                        NewDialogue.Insert(i, Choice);
                    }

                    GUI.backgroundColor = Color.green;
                    if (GUILayout.Button("+", GUILayout.Width(25)))
                    {
                        NumberOfLines++;
                        CurrentFile.Names.Insert(i + 1, "");
                        CurrentFile.Dialogue.Insert(i + 1, "");

                        Debug.Log("Adding new line");
                    }
                    GUI.backgroundColor = Color.red;
                    if (GUILayout.Button("-", GUILayout.Width(25)))
                    {
                        if (i != 0)
                        {
                            NumberOfLines--;
                            CurrentFile.Names.RemoveAt(i);
                            CurrentFile.Dialogue.RemoveAt(i);
                        }
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndScrollView();
            }
            else
            {
                EditorGUILayout.LabelField("No Dialogue File Selected!");
            }
            break;

        default:
            break;
        }

        // Makes it so you can deselect elements in the window by adding a button the size of the window that you can't see under everything
        //make sure the following code is at the very end of OnGUI Function
        if (GUI.Button(DeselectWindow, "", GUIStyle.none))
        {
            GUI.FocusControl(null);
        }
    }
コード例 #23
0
	void OnGUI()
	{
		TextAnchor oldAlignment = GUI.skin.window.alignment;
		GUI.skin.window.alignment = TextAnchor.UpperLeft;

		// check if windows need to be recreated
		if (Event.current.type == EventType.Repaint && filePopupSelectedIndex >= 0 && selectedEntry != null)
			createWindows();

		GUILayout.BeginHorizontal();

		GUILayout.BeginVertical(GUILayout.Width(200));
		GUILayout.Space(5);

		GUILayout.BeginHorizontal();
		int t = filePopupSelectedIndex;
		filePopupSelectedIndex = EditorGUILayout.Popup(filePopupSelectedIndex, filePopupList);
		if (t != filePopupSelectedIndex) { } // the selected index has changed, load the correct dialogue file

		// create new dialogue file
		if (GUILayout.Button("+"))
		{
			saveUndo("creating dialogue file");
			// create new dialogueFile
			DialogueFile file = ScriptableObject.CreateInstance<DialogueFile>();
			AssetDatabase.CreateAsset(file, AssetDatabase.GenerateUniqueAssetPath("Assets/Script.asset"));
			AssetDatabase.SaveAssets();
			files.Add(file);
			buildFilePopupArray();
		}
		GUILayout.EndHorizontal();

		// import export buttons
		GUILayout.BeginHorizontal();
		if (filePopupSelectedIndex < 0)
			GUI.enabled = false;
		if (GUILayout.Button("Import"))
		{
			string filename = EditorUtility.OpenFilePanel("Import dialogue", ".", "xml");
			DialogueFile importedFile = deserializeFromXML(filename);
			// import the various entries and lines
			// check if the existing file already has the same entries
			bool foundSameEntryName = false;
			string sameEntryName = "";
			foreach (DialogueFile.DialogueEntry entry in importedFile.entries)
			{
				foreach (DialogueFile.DialogueEntry oldEntry in files[filePopupSelectedIndex].entries)
				{
					if (entry.id == oldEntry.id)
					{
						// found same entry
						foundSameEntryName = true;
						sameEntryName = entry.id;
						break;
					}
				}
			}
			bool continueImport = true;
			if (foundSameEntryName)
			{
				continueImport = EditorUtility.DisplayDialog("Same dialogue entry found", "The existing dialogue already has an entry named " + sameEntryName + ". If you continue, existing dialogues will be overwritten. Do you want to continue?", "Continue", "Cancel");
			}

			if (continueImport)
			{
				saveUndo("Importing dialogue");
				// add the entries and lines
				foreach (DialogueFile.DialogueEntry entry in importedFile.entries)
				{
					// check if it already exists
					bool dialogueExists = false;
					foreach (DialogueFile.DialogueEntry oldEntry in files[filePopupSelectedIndex].entries)
					{
						if (entry.id == oldEntry.id)
						{
							dialogueExists = true;
							// clear out existing lines
							files[filePopupSelectedIndex].lines.RemoveAll((item) => item.dialogueEntry == entry.id);
						}
					}
					if (!dialogueExists)
						files[filePopupSelectedIndex].entries.Add(entry); // add entry if it does not exists
				}

				// add the lines in one go
				files[filePopupSelectedIndex].lines.AddRange(importedFile.lines);
				EditorUtility.SetDirty(files[filePopupSelectedIndex]);
			}
		}
		if (GUILayout.Button("Export"))
		{
			// test serialization
			string filename = EditorUtility.SaveFilePanelInProject("Export dialogue", "dialogue", "xml", "");
			serializeToXML(filename, files[filePopupSelectedIndex]);
			AssetDatabase.Refresh();
		}
		if (filePopupSelectedIndex < 0)
			GUI.enabled = true;
		GUILayout.EndHorizontal();
		// draw the dialogues
		dialogueListScroll = GUILayout.BeginScrollView(dialogueListScroll, (GUIStyle)"box");

		if (filePopupSelectedIndex >= 0)
		{
			foreach (DialogueFile.DialogueEntry entry in files[filePopupSelectedIndex].entries)
			{
				if (entry == selectedEntry)
				{
					GUILayout.Label(entry.id, (GUIStyle)"boldLabel");
				}
				else
				{
					if (GUILayout.Button(entry.id, (GUIStyle)"label"))
					{
						selectedEntry = entry;
						// build windows
						createWindows();
					}
				}
			}
		}

		GUILayout.EndScrollView();

		GUILayout.BeginHorizontal();
		if (filePopupSelectedIndex < 0) GUI.enabled = false;
		if (GUILayout.Button("+"))
		{
			saveUndo("creating dialogue");
			// create new dialogue entry
			DialogueFile.DialogueEntry newEntry = new DialogueFile.DialogueEntry(createUniqueDialogueName());
			DialogueFile.DialogueLine beginLine = new DialogueFile.DialogueLine();
			beginLine.dialogueEntry = newEntry.id;
			beginLine.id = 0;
			beginLine.position = new Vector2(10, 10);
			files[filePopupSelectedIndex].entries.Add(newEntry);
			files[filePopupSelectedIndex].lines.Add(beginLine);
			EditorUtility.SetDirty(files[filePopupSelectedIndex]);
		}
		if (GUILayout.Button("-"))
		{
			saveUndo("deleting dialogue");
			// delete all the lines corresponding to this entry
			files[filePopupSelectedIndex].lines.RemoveAll((item) => item.dialogueEntry == selectedEntry.id);
			// delete the entry
			files[filePopupSelectedIndex].entries.Remove(selectedEntry);
			selectedEntry = null;
			windows.Clear();
			EditorUtility.SetDirty(files[filePopupSelectedIndex]);

		}
		if (filePopupSelectedIndex < 0) GUI.enabled = true;
		GUILayout.EndHorizontal();

		GUILayout.Space(5);
		GUILayout.EndVertical();

		GUILayout.BeginVertical();

		// show selected dialogueinfo
		GUILayout.BeginHorizontal();
		// display name
		if (selectedEntry != null) GUILayout.Label("Name: " + selectedEntry.id);
		else GUILayout.Label("Name: ");
		GUILayout.FlexibleSpace();

		if (selectedEntry == null) GUI.enabled = false;
		// rename button
		if (GUILayout.Button("Rename"))
		{
			// open rename dialog
			RenameDialogue dialog = GetWindow<RenameDialogue>(true);
			dialog.oldName = dialog.newName = selectedEntry.id;
			dialog.file = files[filePopupSelectedIndex];
		}
		if (GUILayout.Button("Edit Speakers"))
		{
			// open rename dialog
			EditSpeakers dialog = GetWindow<EditSpeakers>(true);
			dialog.Init(files[filePopupSelectedIndex], selectedEntry.id);
		}
		if (selectedEntry == null) GUI.enabled = true;
		GUILayout.EndHorizontal();

		// get rect for scrollview
		GUIStyle style = new GUIStyle();
		style.stretchHeight = true;
		style.stretchWidth = true;
		style.margin = new RectOffset(4, 4, 4, 4);
		Rect rc = GUILayoutUtility.GetRect(new GUIContent(), style);
		GUI.Box(rc, "");
		Rect bounds = getBoundingRect(new Rect(25, 25, rc.width - 50, rc.height - 50));
		bounds.x -= 25; bounds.y -= 25; bounds.width += 50; bounds.height += 50;
		dialogueTreeScroll = GUI.BeginScrollView(rc, dialogueTreeScroll, bounds);

		BeginWindows();
		int index = 0;
		bool createWindow = false;
		bool createLink = false;
		bool breakLink = false;
		bool deleteWindow = false;
		foreach (DialogueWindow window in windows)
		{
			string title = "";
			if (window.line.id == 0)
			{
				title = "BEGIN";
			}
			else
			{
				if (window.line != null) title = window.line.dialogue;
			}

			// draw output lines
			if (window.line != null)
			{
				foreach (int outputId in window.line.output)
				{
					// find connecting line
					foreach (DialogueFile.DialogueLine outputLine in files[filePopupSelectedIndex].lines)
					{
						if (outputLine.dialogueEntry == selectedEntry.id && outputLine.id == outputId)
						{
							Color color = Color.black;
							if (lastFocusWindow >= 0 && windows.Count > lastFocusWindow && windows[lastFocusWindow].line.id == outputId)
								color = Color.green;
							else if (lastFocusWindow >= 0 && windows.Count > lastFocusWindow && windows[lastFocusWindow].line == window.line)
								color = Color.red;

							Vector2 startPos = window.line.position + new Vector2(100, 25);
							Vector2 endPos = outputLine.position + new Vector2(0, 25);
							Vector2 midPos = (endPos - startPos).normalized;

							// found correct line
							float diffY = Mathf.Abs(startPos.y - endPos.y) / 4;
							float diffX = Mathf.Abs(startPos.x - endPos.x) / 4;
							Vector2 tPos = new Vector2(startPos.x + Mathf.Min(25, diffX), (startPos.y < endPos.y) ? startPos.y + Mathf.Min(25, diffY) : startPos.y - Mathf.Min(25, diffY));
							Vector2 tPos2 = new Vector2(endPos.x - Mathf.Min(25, diffX), (startPos.y < endPos.y) ? endPos.y - Mathf.Min(25, diffY) : endPos.y + Mathf.Min(25, diffY));
							Handles.DrawBezier(startPos, tPos, startPos + new Vector2(10, 0), tPos + midPos * -20, color, linetexture, 2);

							Handles.DrawBezier(tPos, tPos2, tPos + midPos * 20, tPos2 + midPos * -20, color, linetexture, 2);

							Handles.DrawBezier(tPos2, endPos, tPos2 + midPos * 20, endPos + new Vector2(-10, 0), color, linetexture, 2);
							break;
						}
					}
				}
			}

			window.rect = GUI.Window(index, window.rect, doWindow, title);

			if (window.line != null)
				window.line.position = new Vector2(window.rect.x, window.rect.y);
			//if (FocusedWindow < 0) GUI.FocusWindow(lastFocusWindow);
			GUI.FocusWindow(FocusedWindow);
			if (index == FocusedWindow)
			{
				// show extra buttons
				if (GUI.Button(new Rect(window.rect.xMax, window.rect.y + 10, 20, 20), "+", windowButtonStyle))
				{
					createWindow = true;
				}
				if (GUI.Button(new Rect(window.rect.xMax, window.rect.y + 30, 20, 20), "->", windowButtonStyle))
				{
					createLink = true;
				}
				if (GUI.Button(new Rect(window.rect.x - 20, window.rect.y + 10, 20, 20), "X", windowButtonStyle))
				{
					breakLink = true;
				}
				if (index != 0)
				{
					if (GUI.Button(new Rect(window.rect.x + 80, window.rect.y - 15, 15, 15), "x", windowButtonStyle))
					{
						deleteWindow = true;
					}
				}
			}
			lastFocusWindow = FocusedWindow;
			index++;
		}

		if (createdWindow >= 0)
		{
			GUI.BringWindowToFront(createdWindow);
			createdWindow = -1;
		}

		if (createWindow)
		{
			saveUndo("creating node");
			// create new line and window
			DialogueFile.DialogueLine line = new DialogueFile.DialogueLine();
			line.dialogue = "";
			line.dialogueEntry = selectedEntry.id;
			line.id = selectedEntry.maxLineId++;

			// set line's position
			Rect windowRc = windows[lastFocusWindow].rect;
			line.position = new Vector2(windowRc.xMax + 50, windowRc.y);

			files[filePopupSelectedIndex].lines.Add(line);

			if (windows[lastFocusWindow].line != null) windows[lastFocusWindow].line.output.Add(line.id);
			int w = addWindow(line);
			GUI.FocusWindow(w);
			createdWindow = w;

			EditorUtility.SetDirty(files[filePopupSelectedIndex]);
		}

		if (createLink)
		{
			linkDragging = true;
			linkDragStartWindow = windows[lastFocusWindow];
			wantsMouseMove = true;
		}
		if (breakLink)
		{
			linkDragging = true;
			this.breakLink = true;
			linkDragStartWindow = windows[lastFocusWindow];
			wantsMouseMove = true;
		}

		if (linkDragging)
		{
			if (Event.current.type == EventType.MouseMove)
			{
				mousePos = Event.current.mousePosition;
				Repaint();
			}

			if (this.breakLink)
			{
				// draw bezier curve from start window to cursor
				Vector2 pos1 = linkDragStartWindow.line.position + new Vector2(0, 25);
				Vector2 pos2 = mousePos;
				Handles.DrawBezier(pos1, pos2, pos1, pos2, Color.red, linetexture, 2);
			}
			else
			{
				// draw bezier curve from start window to cursor
				Vector2 pos1 = linkDragStartWindow.line.position + new Vector2(100, 25);
				Vector2 pos2 = mousePos;
				Handles.DrawBezier(pos1, pos2, pos1, pos2, Color.green, linetexture, 2);
			}
		}

		if (deleteWindow)
		{
			saveUndo("deleting node");
			// find lines that link to this one
			foreach (DialogueFile.DialogueLine line in files[filePopupSelectedIndex].lines)
			{
				if (line.dialogueEntry == windows[lastFocusWindow].line.dialogueEntry)
				{
					if (line.output.Contains(windows[lastFocusWindow].line.id))
						line.output.Remove(windows[lastFocusWindow].line.id);
				}
			}
			// remove currently selected window
			files[filePopupSelectedIndex].lines.Remove(windows[lastFocusWindow].line);
			windows.RemoveAt(lastFocusWindow);
			GUI.FocusWindow(0);
			lastFocusWindow = 0;
			EditorUtility.SetDirty(files[filePopupSelectedIndex]);
		}

		EndWindows();

		// dialogue line text area
		GUI.EndScrollView();
		if (lastFocusWindow > 0 && windows.Count > lastFocusWindow)
			windows[lastFocusWindow].line.dialogue = GUILayout.TextArea(windows[lastFocusWindow].line.dialogue, GUILayout.Height(GUI.skin.textArea.lineHeight * 3.1f));
		else
			GUILayout.TextArea("", GUILayout.Height(GUI.skin.textArea.lineHeight * 3.1f));

		GUILayout.EndVertical();

		GUILayout.EndHorizontal();
		GUI.skin.window.alignment = oldAlignment;
	}
コード例 #24
0
ファイル: AtLoad.cs プロジェクト: Terrapin/dialogue-compiler
 public override bool Run(DialogueFile file)
 {
     DialogueCompiler.Instance.ImportFile(File);
     return false;
 }
コード例 #25
0
ファイル: AtQuote.cs プロジェクト: Terrapin/dialogue-compiler
 public override string Run(DialogueFile file, DialogueLine line)
 {
     return "%22";
 }
コード例 #26
0
 public abstract string Run(DialogueFile file, DialogueLine line);
コード例 #27
0
	int addWindow(DialogueFile.DialogueLine line)
	{
		windows.Add(new DialogueWindow(new Rect(line.position.x, line.position.y, 100, 65), line, false));
		return windows.Count - 1;
	}
コード例 #28
0
		public DialogueWindow(Rect rc, DialogueFile.DialogueLine line = null, bool startConversation = false)
		{
			rect = rc;
			this.line = line;
			this.startConversation = startConversation;
		}
コード例 #29
0
	void serializeToXML(string filename, DialogueFile dialogue)
	{
		XmlSerializer serializer = new XmlSerializer(typeof(DialogueFile));
		TextWriter textWriter = new StreamWriter(filename);
		serializer.Serialize(textWriter, dialogue);
		textWriter.Close();
	}
コード例 #30
0
 void SerializeToJson(string filename, DialogueFile dialogue)
 {
     File.WriteAllText(filename, JsonUtility.ToJson(dialogue));
 }
コード例 #31
0
 public override string Run(DialogueFile file, DialogueLine line)
 {
     return String.Format("*{0}*", DialogueCompiler.ChapterVariable);
 }
コード例 #32
0
 /// <summary>
 /// Used internally. Adds a line to the dialogue.
 /// </summary>
 /// <param name="line">The line to be added</param>
 public void AddLine(DialogueFile.DialogueLine line)
 {
     lines.Add(line.id, line);
 }
コード例 #33
0
    /// <summary>
    /// Load a dialogue file by the given DialogueFile reference
    /// </summary>
    /// <param name="file">A reference to a DialogueFile</param>
    /// <returns>A DialogueManager holding the file reference</returns>
    public static DialogueManager LoadDialogueFile(DialogueFile file)
    {
        
        if (managers.ContainsKey(file))
            return managers[file];

        // load file, optimize for searching dialogues
        DialogueManager manager = new DialogueManager();
        managers.Add(file, manager);

        manager.file = file;

        return manager;
    }
コード例 #34
0
ファイル: AtLoad.cs プロジェクト: Terrapin/dialogue-compiler
 public AtLoad(DialogueLine param)
 {
     File = DialogueFile.Open(param.Content);
 }
コード例 #35
0
 public override string Run(DialogueFile file, DialogueLine line)
 {
     DialogueCompiler.Instance.Error(line, "No such command ({0})", command);
     return null;
 }
コード例 #36
0
 /// <summary>
 /// Call this to change the active Dialogue File
 /// </summary>
 /// <param name="Input">The Dialogue File you want to input into the system</param>
 public void ChangeFile(DialogueFile Input)
 {
     File = Input;
     Reset();
     ResetDisplayText();
 }