Beispiel #1
0
    public void SetFlowchart(DTreeNode currq, List <Fungus.Command> qCommands)
    {
        Fungus.Say question = (Fungus.Say)qCommands[0];
        question.SetStandardText(currq.GetQuestion());

        Fungus.Menu goodopt = (Fungus.Menu)qCommands [2];
        goodopt.SetStandardText(currq.GetGoodOption());

        Fungus.Menu badopt = (Fungus.Menu)qCommands [3];
        badopt.SetStandardText(currq.GetBadOption());
    }
Beispiel #2
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            bool showPortraits         = false;
            bool showNarratorPortraits = false;

            CommandEditor.ObjectField <Character>(characterProp,
                                                  new GUIContent("Character", "Character that is speaking"),
                                                  new GUIContent("<None>"),
                                                  Character.activeCharacters);

            Say t = target as Say;

            // Only show portrait selection if...
            if (t.character != null &&                          // Character is selected
                t.character.portraits != null &&                // Character has a portraits field
                t.character.portraits.Count > 0)                // Selected Character has at least 1 portrait
            {
                showPortraits = true;
            }
            else
            {
                //MIKE SHIT: ADDED SHOWING PORTRAIT DURING NARRATOR
                EditorGUILayout.PropertyField(showNarratorPortraitProp);
                if (showNarratorPortraitProp.boolValue)
                {
                    CommandEditor.ObjectField <Character>(narratorCharacterProp,
                                                          new GUIContent("Narrator Character", "Character shown while narrator speaks"),
                                                          new GUIContent("<None>"),
                                                          Character.activeCharacters);

                    // Only show portrait selection if...
                    if (t.narratorCharacter != null &&             // Character is selected
                        t.narratorCharacter.portraits != null &&   // Character has a portraits field
                        t.narratorCharacter.portraits.Count > 0)   // Selected Character has at least 1 portrait
                    {
                        showNarratorPortraits = true;
                    }

                    if (showNarratorPortraits)
                    {
                        CommandEditor.ObjectField <Sprite>(narratorPortraitProp,
                                                           new GUIContent("Narrator Portrait", "Portrait shown while narrator speaks"),
                                                           new GUIContent("<None>"),
                                                           t.narratorCharacter.portraits);
                    }
                    else
                    {
                        if (!t.extendPrevious)
                        {
                            t.portrait = null;
                        }
                    }
                }
            }

            if (showPortraits)
            {
                CommandEditor.ObjectField <Sprite>(portraitProp,
                                                   new GUIContent("Portrait", "Portrait representing speaking character"),
                                                   new GUIContent("<None>"),
                                                   t.character.portraits);
            }
            else
            {
                if (!t.extendPrevious)
                {
                    t.portrait = null;
                }
            }

            EditorGUILayout.PropertyField(storyTextProp);

            EditorGUILayout.PropertyField(descriptionProp);

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PropertyField(extendPreviousProp);

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(new GUIContent("Tag Help", "View available tags"), new GUIStyle(EditorStyles.miniButton)))
            {
                showTagHelp = !showTagHelp;
            }
            EditorGUILayout.EndHorizontal();

            if (showTagHelp)
            {
                DrawTagHelpLabel();
            }

            EditorGUILayout.Separator();

            EditorGUILayout.PropertyField(voiceOverClipProp,
                                          new GUIContent("Voice Over Clip", "Voice over audio to play when the text is displayed"));

            EditorGUILayout.PropertyField(showAlwaysProp);

            if (showAlwaysProp.boolValue == false)
            {
                EditorGUILayout.PropertyField(showCountProp);
            }

            GUIStyle centeredLabel = new GUIStyle(EditorStyles.label);

            centeredLabel.alignment = TextAnchor.MiddleCenter;
            GUIStyle leftButton = new GUIStyle(EditorStyles.miniButtonLeft);

            leftButton.fontSize = 10;
            leftButton.font     = EditorStyles.toolbarButton.font;
            GUIStyle rightButton = new GUIStyle(EditorStyles.miniButtonRight);

            rightButton.fontSize = 10;
            rightButton.font     = EditorStyles.toolbarButton.font;

            EditorGUILayout.PropertyField(fadeWhenDoneProp);
            EditorGUILayout.PropertyField(waitForClickProp);
            EditorGUILayout.PropertyField(setSayDialogProp);

            if (showPortraits && t.portrait != null)
            {
                Texture2D characterTexture = t.portrait.texture;
                float     aspect           = (float)characterTexture.width / (float)characterTexture.height;
                Rect      previewRect      = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));
                if (characterTexture != null)
                {
                    GUI.DrawTexture(previewRect, characterTexture, ScaleMode.ScaleToFit, true, aspect);
                }
            }
            else
            {
                if (showNarratorPortraits && t.narratorPortrait != null)
                {
                    Texture2D characterTexture = t.narratorPortrait.texture;
                    float     aspect           = (float)characterTexture.width / (float)characterTexture.height;
                    Rect      previewRect      = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));
                    if (characterTexture != null)
                    {
                        GUI.DrawTexture(previewRect, characterTexture, ScaleMode.ScaleToFit, true, aspect);
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #3
0
        /**
         * Builds a dictionary of localizable text items in the scene.
         */
        protected Dictionary <string, TextItem> FindTextItems()
        {
            Dictionary <string, TextItem> textItems = new Dictionary <string, TextItem>();

            // Export all character names
            foreach (Character character in GameObject.FindObjectsOfType <Character>())
            {
                // String id for character names is CHARACTER.<Character Name>
                TextItem textItem = new TextItem();
                textItem.standardText = character.nameText;
                textItem.description  = character.description;
                string stringId = "CHARACTER." + character.nameText;
                textItems[stringId] = textItem;
            }

            // Export all Say and Menu commands in the scene
            // To make it easier to localize, we preserve the command order in each exported block.
            Flowchart[] flowcharts = GameObject.FindObjectsOfType <Flowchart>();
            foreach (Flowchart flowchart in flowcharts)
            {
                // If no localization id has been set then use the Flowchart name
                string localizationId = flowchart.localizationId;
                if (localizationId.Length == 0)
                {
                    localizationId = flowchart.name;
                }

                Block[] blocks = flowchart.GetComponentsInChildren <Block>();
                foreach (Block block in blocks)
                {
                    foreach (Command command in block.commandList)
                    {
                        string stringId     = "";
                        string standardText = "";
                        string description  = "";

                        System.Type type = command.GetType();
                        if (type == typeof(Say))
                        {
                            // String id for Say commands is SAY.<Flowchart id>.<Command id>.<Character Name>
                            Say sayCommand = command as Say;
                            standardText = sayCommand.storyText;
                            description  = sayCommand.description;
                            stringId     = "SAY." + localizationId + "." + sayCommand.itemId + ".";
                            if (sayCommand.character != null)
                            {
                                stringId += sayCommand.character.nameText;
                            }
                        }
                        else if (type == typeof(Menu))
                        {
                            // String id for Menu commands is MENU.<Flowchart id>.<Command id>
                            Menu menuCommand = command as Menu;
                            standardText = menuCommand.text;
                            description  = menuCommand.description;
                            stringId     = "MENU." + localizationId + "." + menuCommand.itemId;
                        }
                        else
                        {
                            continue;
                        }

                        TextItem textItem = null;
                        if (textItems.ContainsKey(stringId))
                        {
                            textItem = textItems[stringId];
                        }
                        else
                        {
                            textItem            = new TextItem();
                            textItems[stringId] = textItem;
                        }

                        // Update basic properties,leaving localised strings intact
                        textItem.standardText = standardText;
                        textItem.description  = description;
                    }
                }
            }

            return(textItems);
        }
Beispiel #4
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            Say t = target as Say;

            CommandEditor.ObjectField <Character>(characterProp,
                                                  new GUIContent("Character", "Character to display in dialog"),
                                                  new GUIContent("<None>"),
                                                  Character.activeCharacters);

            CommandEditor.ObjectField <SayDialog>(sayDialogProp,
                                                  new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"),
                                                  new GUIContent("<Default>"),
                                                  SayDialog.activeDialogs);
            bool showPortraits = false;

            // Only show portrait selection if...
            if (t.character != null &&                          // Character is selected
                t.character.portraits != null &&                // Character has a portraits field
                t.character.portraits.Count > 0)                // Selected Character has at least 1 portrait
            {
                showPortraits = true;
            }

            if (showPortraits)
            {
                CommandEditor.ObjectField <Sprite>(portraitProp,
                                                   new GUIContent("Portrait", "Portrait representing speaking character"),
                                                   new GUIContent("<None>"),
                                                   t.character.portraits);
            }
            else
            {
                t.portrait = null;
            }

            EditorGUILayout.PropertyField(storyTextProp);

            EditorGUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton)))
            {
                showTagHelp = !showTagHelp;
            }
            EditorGUILayout.EndHorizontal();

            if (showTagHelp)
            {
                DrawTagHelpLabel();
            }

            EditorGUILayout.Separator();

            EditorGUILayout.PropertyField(voiceOverClipProp,
                                          new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed"));

            EditorGUILayout.PropertyField(showAlwaysProp);

            if (showAlwaysProp.boolValue == false)
            {
                EditorGUILayout.PropertyField(showCountProp);
            }

            EditorGUILayout.PropertyField(waitForInputProp);

            if (showPortraits && t.portrait != null)
            {
                Texture2D characterTexture = t.portrait.texture;

                float aspect = (float)characterTexture.width / (float)characterTexture.height;

                Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));

                CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor;
                characterEditor.DrawPreview(previewRect, characterTexture);
                DestroyImmediate(characterEditor);
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #5
0
        //MIKEHACK
        public virtual void CreateNewBlock()
        {
            //TODO: fix block position;
            Flowchart flow = FindObjectOfType <Flowchart>();

            //Create block
            Vector2 blockPos = new Vector2(-500, -500);
            Block   b        = flow.CreateBlock(blockPos);

            //load in data
            string textData = FindObjectOfType <Localization>().rtfDocument.text;

            b.blockName = FindObjectOfType <Localization>().rtfDocument.name;
            string[] lines = textData.Split('\n');

            Character lastSpeaker    = flow.gameObject.AddComponent(typeof(Character)) as Character; //used to keep track of who spoke last, outside of loop to remember.
            Character currentSpeaker = flow.gameObject.AddComponent(typeof(Character)) as Character; //used to keep track of who's speaking, outside of loop to remember.
            Sprite    speakerSprite  = null;
            bool      portraitStart  = false;

            //process line by line
            foreach (string line in lines)
            {
                string buffer = line.Trim();

                if (buffer == "")
                {
                    continue;
                }

                //title of the block and create a new one
                if (buffer.StartsWith("TITLE:"))
                {
                    blockPos = new Vector2(blockPos.x + 250, -500);
                    b        = flow.CreateBlock(blockPos);

                    buffer      = buffer.Substring(7, buffer.Length - 7); //cuts "TITLE: " from the front
                    b.blockName = buffer;

                    continue;
                }

                //fade the scene with default params
                if (buffer.StartsWith("<<fade>>"))
                {
                    FadeScreen newCommand = flow.gameObject.AddComponent(typeof(FadeScreen)) as FadeScreen;
                    newCommand.parentBlock = b;
                    newCommand.itemId      = flow.NextItemId();
                    b.commandList.Add(newCommand);

                    continue;
                }

                //if it's a bg change then write the lineID and the buffer
                if (buffer.StartsWith("<<bg>>"))
                {
                    //Add Say command
                    Say newCommand = flow.gameObject.AddComponent(typeof(Say)) as Say;
                    newCommand.parentBlock = b;
                    newCommand.itemId      = flow.NextItemId();
                    b.commandList.Add(newCommand);
                    //assign text
                    newCommand.storyText = "ADD BACKGROUND TO OBJECT #" + flow.NextItemId() + " :" + buffer;

                    continue;
                }

                //description of the block for reference of bgs
                if (buffer.StartsWith("BG:"))
                {
                    buffer        = buffer.Substring(4, buffer.Length - 4); //cuts "BG: " from the front
                    b.description = buffer;

                    continue;
                }
                else
                {
                    //if it starts with some portrait, we try and find that portrait and set it
                    if (buffer.StartsWith("<mei") || buffer.StartsWith("<bastion") || buffer.StartsWith("<soldier") || buffer.StartsWith("<mercy") || buffer.StartsWith("<genji"))
                    {
                        portraitStart = true; //using this to track whether or not to remember portrait

                        int    lasti      = buffer.LastIndexOf(">");
                        string spriteName = buffer.Substring(1, lasti - 1);
                        speakerSprite = FindSprite(spriteName);

                        buffer = buffer.Substring(lasti + 1, buffer.Length - lasti - 1).Trim();
                    }
                    else
                    {
                        portraitStart = false;
                    }

                    //Check second character is a colon, which would indicate that someone must have been speaking.
                    //we're assuming the id's won't ever be longer than 1
                    //if that's the case we look for the speaker based on the first letter and save that for later
                    if (buffer.Substring(1, 1) == ":")
                    {
                        currentSpeaker = WhoIsSpeaking(buffer.Substring(0, 1)); // will return null if it's the narrator

                        //if there is no portrait and the sentence starts with an ID we reset the speakerSprite
                        if (!portraitStart)
                        {
                            speakerSprite = null;
                        }

                        //cuts the identifier + the space from the front
                        buffer = buffer.Substring(3, buffer.Length - 3);
                    }
                    else
                    {
                        currentSpeaker = lastSpeaker;
                    }

                    //Add Say command
                    Say newCommand = flow.gameObject.AddComponent(typeof(Say)) as Say;
                    newCommand.parentBlock = b;
                    newCommand.itemId      = flow.NextItemId();
                    b.commandList.Add(newCommand);
                    //assign text
                    newCommand.storyText = buffer;
                    //assign speaker
                    newCommand.character = currentSpeaker;

                    if (speakerSprite != null)
                    {
                        //if a portrait should be shown while narrator speaks
                        if (currentSpeaker == null)
                        {
                            newCommand.showNarratorPortrait = true;                        //show narrator portrait
                            newCommand.narratorCharacter    = WhoHasSprite(speakerSprite); //replace narrator character with whoever owns the sprite.
                            newCommand.narratorPortrait     = speakerSprite;               //replace narrator portrait
                        }
                        else
                        {
                            newCommand.portrait = speakerSprite;
                        }
                    }
                    else
                    {
                        if (currentSpeaker != null && currentSpeaker.portraits.Count > 0)
                        {
                            newCommand.portrait = currentSpeaker.portraits[0]; //default
                        }
                    }


                    lastSpeaker = currentSpeaker;

                    //remove speaker objects again
                    //TODO: fix this garbage, it's a workaround for the lack of "new" keyword
                    DestroyImmediate(flow.gameObject.GetComponent <Character>());
                }
            }
        }
Beispiel #6
0
        public override void DrawCommandGUI()
        {
            serializedObject.Update();

            Say       t  = target as Say;
            SayDialog sd = t.sayDialog;

            if (t.sayDialog == null)                   // If default box selected
            {
                sd = t.GetFungusScript().defaultSay;   // Try to get character's default say dialog box
                if (sd == null)                        // If no default specified, try to get any SayDialog in the scene
                {
                    sd = GameObject.FindObjectOfType <SayDialog>();
                }
            }

            bool showPortraits = false;

            CommandEditor.ObjectField <SayDialog>(sayDialogProp,
                                                  new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"),
                                                  new GUIContent("<Default>"),
                                                  SayDialog.activeDialogs);
            if (sd != null && sd.nameText != null)
            {
                CommandEditor.ObjectField <Character>(characterProp,
                                                      new GUIContent("Character", "Character to display in dialog"),
                                                      new GUIContent("<None>"),
                                                      Character.activeCharacters);
            }
            else
            {
                t.character = null;
            }
            // Only show portrait selection if...
            if (t.character != null &&                          // Character is selected
                t.character.portraits != null &&                // Character has a portraits field
                t.character.portraits.Count > 0)                // Selected Character has at least 1 portrait
            {
                if (sd != null && sd.characterImage != null)    // Check that selected say dialog has a character image
                {
                    showPortraits = true;
                }
            }

            if (showPortraits)
            {
                CommandEditor.ObjectField <Sprite>(portraitProp,
                                                   new GUIContent("Portrait", "Portrait representing speaking character"),
                                                   new GUIContent("<None>"),
                                                   t.character.portraits);
            }
            else
            {
                if (!t.extendPrevious)
                {
                    t.portrait = null;
                }
            }

            EditorGUILayout.PropertyField(storyTextProp);

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PropertyField(extendPreviousProp);

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton)))
            {
                showTagHelp = !showTagHelp;
            }
            EditorGUILayout.EndHorizontal();

            if (showTagHelp)
            {
                DrawTagHelpLabel();
            }

            EditorGUILayout.Separator();

            EditorGUILayout.PropertyField(voiceOverClipProp,
                                          new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed"));
            EditorGUILayout.PropertyField(fadeInProp);
            EditorGUILayout.PropertyField(fadeOutProp);
            EditorGUILayout.PropertyField(showAlwaysProp);

            if (showAlwaysProp.boolValue == false)
            {
                EditorGUILayout.PropertyField(showCountProp);
            }

            if (showPortraits && t.portrait != null)
            {
                Texture2D characterTexture = t.portrait.texture;

                float aspect = (float)characterTexture.width / (float)characterTexture.height;

                Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));
                if (characterTexture != null)
                {
                    EditorGUI.DrawPreviewTexture(previewRect,
                                                 characterTexture,
                                                 spriteMaterial);
                }
            }

            serializedObject.ApplyModifiedProperties();
        }