Beispiel #1
0
    public void addTextBox(int dialogueIndex, CharacterData.Info.Character name)
    {
        Dialogue currDialogue = dialogueList[dialogueIndex];

        Sprite sprite = null;

        if (name.ToString() != "NONE")
        {
            sprite = characterData.GetCharacterSprites(name)[0];
        }

        currDialogue.sentenceList.Add(new Dialogue.Sentence("New text", sprite, true));
    }
    // Get the previous last index where the name is not NONE.
    int GetPreviousLastIndexNotNone(string currCharStr, int currIndex)
    {
        if (currIndex == 0)
        {
            return(-1);
        }

        CharacterData.Info.Character prevCharName = mSelf.dialogueList[currIndex - 1].character.name;

        if (prevCharName != CharacterData.Info.Character.NONE &&
            currCharStr != prevCharName.ToString())
        {
            return(currIndex - 1);
        }
        return(GetPreviousLastIndexNotNone(currCharStr, currIndex - 1));
    }
    void DeleteDialogue(int index)
    {
        CharacterData.Info.Character lastName = mSelf.dialogueList[index].character.name;
        if (lastName != CharacterData.Info.Character.NONE)
        {
            UpdateTotalWhenCharIsDeleted(lastName.ToString());
        }

        mSelf.deleteDialogue(index);
        mIsControlList.RemoveAt(index);
        mIsMessedUpList.RemoveAt(index);
        mIsAppearList.RemoveAt(index);
        mIsAddDelayList.RemoveAt(index);
        mIsReOpenList.RemoveAt(index);
        mIsDisappearList.RemoveAt(index);
        SetMessedUpMessage();
    }
    public override void OnInspectorGUI()
    {
        EditorStyles.textField.wordWrap = true;

        mSelf.characterData = (CharacterData)EditorGUILayout.ObjectField("CharacterData : ", mSelf.characterData, typeof(CharacterData), true);
//        EditorGUILayout.ObjectField("CharacterData : ",mSelf.characterData, typeof(UnityEngine.Object), true);

        EditorGUILayout.Space();

        mIsShowInfoPanel = EditorGUILayout.Foldout(mIsShowInfoPanel, "Info panel", true);
        if (mIsShowInfoPanel)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical("GroupBox");

            string allCharacters = "";
            for (int i = 0; i < mCharTotalList.Count; i++)
            {
                allCharacters += mCharTotalList[i].name + ", ";
            }
            if (allCharacters != "")
            {
                allCharacters = allCharacters.Remove(allCharacters.Length - 2, 2);
            }

            GUIStyle infoStyle = new GUIStyle(EditorStyles.label);
            infoStyle.fontStyle = FontStyle.Bold;
            EditorGUILayout.LabelField("Info Panel", infoStyle);

            GUILayout.Label("Total dialogue   : " + dialogueInfo.totalDialogue + "\t\tTotal characters : " + dialogueInfo.totalCharacter);
            GUILayout.Label("Total sentences : " + dialogueInfo.totalSentence + "\t\tSelection phase  : " + dialogueInfo.selectionPhase);
            GUILayout.Label("Total answers   : " + dialogueInfo.totalAnswer + "\t\tTotal response   : " + dialogueInfo.totalResponse);
            GUILayout.Label("\nList of characters :\n" + allCharacters);

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

        mIsShowMarker = EditorGUILayout.Foldout(mIsShowMarker, "Marker Info", true);
        if (mIsShowMarker)
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical("GroupBox");

            GUILayout.Label("+/-     : Add/Delete sentence\t+D/-D : Add/Delete dialogue");
            GUILayout.Label("+A/-A : Add/Delete answer\tApp/Dis : Appear/Disappear");
            GUILayout.Label("Dly     : Delay\t\tRe : Close and Re-open");
//            GUILayout.Label("+R : Add response\t-R : Delete response");

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

        if (mSelf.characterData == null)
        {
            return;
        }

        GUILayout.BeginVertical("HelpBox");
        EditorGUILayout.LabelField("DialogueList");
        GUILayout.EndVertical();

        for (int i = 0; i < mSelf.dialogueList.Count; i++)
        {
            // ------------------------------NEW HORIZONTAL------------------------------
            if (mIsControlList[i])
            {
                EditorGUILayout.BeginHorizontal(mDifferentColorBgStyle);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
            }

            int id = i + 1;
            if (id == 1 || id % 10 == 0)
            {
                GUIStyle s = new GUIStyle(EditorStyles.label);
                s.normal.textColor = mIDColor;
                s.fontStyle        = FontStyle.Bold;
                GUILayout.Label("ID " + id, s, GUILayout.Width(50));
            }
            else
            {
                EditorGUILayout.LabelField("ID " + id, GUILayout.Width(50));
            }
            DialogueData.Dialogue currDialogue = mSelf.dialogueList[i];

            EditorGUI.BeginChangeCheck();

            if (mSelf.characterData != null)
            {
                GUI.color = mSelf.characterData.GetCharacterColor(currDialogue.character.name.ToString());
            }
            CharacterData.Info.Character prevSelectedName = currDialogue.character.name;
            currDialogue.character.name = (CharacterData.Info.Character)EditorGUILayout.EnumPopup(currDialogue.character.name, GUILayout.Width(100));
            GUI.color = Color.white;

            CharacterData.Info.Character currCharName = currDialogue.character.name;
            if (EditorGUI.EndChangeCheck())
            {
                if (currCharName == CharacterData.Info.Character.NONE)
                {
                    mIsAppearList[i]    = false;
                    mIsDisappearList[i] = false;
                    UpdateTotalWhenCharIsDeleted(prevSelectedName.ToString());
                }
                else if (currCharName != CharacterData.Info.Character.NONE)
                {
                    UpdateTotalWhenSwappingName(currCharName.ToString(), prevSelectedName.ToString());
                    SetCharacterDirectionFromOthers(currDialogue);
                    mSelf.UpdateSpriteList(i, currCharName);
                    mSelf.UpdateCharacterInfo(ref currDialogue.character);
                }
                SetMessedUpMessage();
            }

            // Persistent messedUp message.
            if (currCharName != CharacterData.Info.Character.NONE)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUIUtility.labelWidth = 30.0f;
                currDialogue.isLeft         = EditorGUILayout.Toggle("Left", currDialogue.isLeft);

                if (EditorGUI.EndChangeCheck())
                {
                    SetSameCharacterDirection(currDialogue);
                    SetMessedUpMessage();
                }

                if (mIsMessedUpList[i])
                {
                    GUIStyle s = new GUIStyle(EditorStyles.label);
                    s.normal.textColor = mMessedUpColor;
                    GUILayout.Label("Messed-up", s);
                }
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.LabelField(new GUIContent("V", "IsVisible"), GUILayout.Width(15));

            if (GUILayout.Button("Edit", GUILayout.Width(50)))
            {
                SetIsControl(i);
            }

            EditorGUILayout.EndHorizontal();
            // ------------------------------END HORIZONTAL------------------------------

            int textCount = currDialogue.sentenceList.Count;
            for (int j = 0; j < textCount; j++)
            {
                // ------------------------------NEW HORIZONTAL------------------------------
                if (mIsControlList[i])
                {
                    EditorGUILayout.BeginHorizontal(mDifferentColorBgStyle);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                }

                DialogueData.Dialogue.Sentence currSentence = currDialogue.sentenceList[j];

                GUI.color         = mSentenceBgColor;
                currSentence.text = EditorGUILayout.TextArea(currSentence.text);
                GUI.color         = Color.white;

                if (mIsAudio)
                {
                    currSentence.audioClip = (AudioClip)EditorGUILayout.ObjectField(currSentence.audioClip, typeof(AudioClip), false, GUILayout.Width(50));
                }

                if (currDialogue.character.name == CharacterData.Info.Character.NONE)
                {
                    GUI.enabled = false;
                }
                currSentence.isCharVisible = EditorGUILayout.Toggle(currSentence.isCharVisible, GUILayout.Width(15));
                if (GUILayout.Button("Select", GUILayout.Width(50)))
                {
                    List <Sprite> charSpriteList = new List <Sprite>();
                    if (mSelf.characterData.GetCharacterSprites(currCharName) != null)
                    {
                        charSpriteList = mSelf.characterData.GetCharacterSprites(currCharName);
                    }

                    int currActiveTexture = mSelf.characterData.GetSpriteIndex(currCharName, currSentence.sprite);

                    if (currActiveTexture != -1)
                    {
                        TexturePickerEditor.ListToEditorWindow(currSentence, currActiveTexture, charSpriteList);
                    }
                    else
                    {
                        Debug.Log("Couldn't find texture");
                    }
                }
                GUI.enabled = true;

                EditorGUILayout.EndHorizontal();
                // ------------------------------END HORIZONTAL------------------------------
            }

            int answerCount = currDialogue.answerChoiceList.Count;
            for (int j = 0; j < answerCount; j++)
            {
                if (mIsControlList[i])
                {
                    EditorGUILayout.BeginHorizontal(mDifferentColorBgStyle);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                }

                EditorGUILayout.LabelField("A" + (j + 1).ToString(), GUILayout.Width(20));
                GUI.color = mAnswerBgColor;
                DialogueData.Dialogue.AnswerChoice currAnswer = currDialogue.answerChoiceList[j];
                currAnswer.answer = EditorGUILayout.TextArea(currAnswer.answer);
                GUI.color         = Color.white;

                int responseCount = currAnswer.responseList.Count;

                if (GUILayout.Button("+", GUILayout.Width(20)))
                {
                    AddResponse(i, j);
                }

                if (responseCount <= 0)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    DeleteResponse(i, j); return;
                }
                GUI.enabled = true;
//                mSelf.characterData = (CharacterData) EditorGUILayout.ObjectField("CharacterData : ",mSelf.characterData, typeof(CharacterData), true);

                EditorGUILayout.EndHorizontal();

                if (responseCount > 0)
                {
                    for (int k = 0; k < responseCount; k++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUI.color = mResponseBgColor;
                        DialogueData.Dialogue.Sentence currResponse = currAnswer.responseList[k];
                        currResponse.text = EditorGUILayout.TextArea(currResponse.text);
                        GUI.color         = Color.white;

                        currResponse.isCharVisible = EditorGUILayout.Toggle(currResponse.isCharVisible, GUILayout.Width(15));

                        if (GUILayout.Button("Select", GUILayout.Width(50)))
                        {
                            List <Sprite> charSpriteList = new List <Sprite>();
                            if (mSelf.characterData.GetCharacterSprites(currCharName) != null)
                            {
                                charSpriteList = mSelf.characterData.GetCharacterSprites(currCharName);
                            }

                            int currActiveTexture = mSelf.characterData.GetSpriteIndex(currCharName, currResponse.sprite);

                            if (currActiveTexture != -1)
                            {
                                TexturePickerEditor.ListToEditorWindow(currResponse, currActiveTexture, charSpriteList);
                            }
                            else
                            {
                                Debug.Log("Couldn't find texture");
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }

            // ------------------------------NEW HORIZONTAL------------------------------
            // --------------------------------SHOW BOXES--------------------------------
            if (mIsControlList[i])
            {
                EditorGUILayout.BeginHorizontal(mDifferentColorBgStyle);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
            }
            GUILayout.FlexibleSpace();

            if (mIsAppearList.Count != 0 && mIsAppearList[i] || currDialogue.time.moveInTime > 0)
            {
                if (currDialogue.character.name != CharacterData.Info.Character.NONE)
                {
                    EditorGUILayout.LabelField("Appear", GUILayout.Width(50));
                    currDialogue.appearMeth = (DialogueData.Dialogue.AppearMethod)EditorGUILayout.EnumPopup(currDialogue.appearMeth, GUILayout.Width(60));

                    EditorGUIUtility.labelWidth  = 35.0f;
                    currDialogue.time.moveInTime = EditorGUILayout.FloatField("Time", currDialogue.time.moveInTime, GUILayout.Width(70));
                    EditorGUIUtility.labelWidth  = 0;
                }
            }

            if (mIsDisappearList.Count != 0 && mIsDisappearList[i] || currDialogue.time.moveOutTime > 0)
            {
                if (currDialogue.character.name != CharacterData.Info.Character.NONE)
                {
                    EditorGUILayout.LabelField("Disappear", GUILayout.Width(65));
                    currDialogue.disappearMeth = (DialogueData.Dialogue.AppearMethod)EditorGUILayout.EnumPopup(currDialogue.disappearMeth, GUILayout.Width(60));

                    EditorGUIUtility.labelWidth   = 35.0f;
                    currDialogue.time.moveOutTime = EditorGUILayout.FloatField("Time", currDialogue.time.moveOutTime, GUILayout.Width(70));
                    EditorGUIUtility.labelWidth   = 0;
                }
            }
            GUILayout.EndHorizontal();
            // ------------------------------END HORIZONTAL------------------------------

            // ------------------------------NEW HORIZONTAL------------------------------
            // --------------------------------SHOW BOXES--------------------------------
            if (mIsControlList[i])
            {
                EditorGUILayout.BeginHorizontal(mDifferentColorBgStyle);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
            }
            GUILayout.FlexibleSpace();

            if (mIsAddDelayList.Count != 0 && mIsAddDelayList[i] || currDialogue.time.delayTime != 0)
            {
                EditorGUIUtility.labelWidth = 70.0f;
                currDialogue.time.delayTime = EditorGUILayout.FloatField("Next Delay", currDialogue.time.delayTime, GUILayout.Width(105));
                EditorGUIUtility.labelWidth = 0;
            }
            if (mIsReOpenList.Count != 0 && mIsReOpenList[i] || currDialogue.time.reOpenTime != 0)
            {
                EditorGUIUtility.labelWidth  = 70.0f;
                currDialogue.time.reOpenTime = EditorGUILayout.FloatField("Re-open", currDialogue.time.reOpenTime, GUILayout.Width(105));
                EditorGUIUtility.labelWidth  = 0;
            }
            if (currDialogue.character.name == CharacterData.Info.Character.NONE)
            {
                currDialogue.time.moveInTime  = 0;
                currDialogue.time.moveOutTime = 0;
            }
            GUILayout.EndHorizontal();
            // ------------------------------END HORIZONTAL------------------------------

            if (mIsControlList[i])
            {
                // ------------------------------NEW HORIZONTAL------------------------------
                DisplaySeparator();

                if (mIsControlList[i])
                {
                    EditorGUILayout.BeginHorizontal(mDifferentColorBgStyle);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                }
                GUILayout.Label("");

                EditorGUILayout.LabelField("Dialogue", GUILayout.Width(60.0f));
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("+", GUILayout.Width(20)))
                {
                    mSelf.addTextBox(i, currCharName);
                }

                if (currDialogue.sentenceList.Count == 1)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    mSelf.deleteTextBox(i);
                }
                GUI.enabled = true;

                if (GUILayout.Button("+D", GUILayout.Width(30)))
                {
                    AddDialogue(i);
                }
                else if (GUILayout.Button("-D", GUILayout.Width(30)))
                {
                    DeleteDialogue(i); return;
                }

                if (GUILayout.Button("+A", GUILayout.Width(30)))
                {
                    AddAnswer(i);
                }
                else if (GUILayout.Button("-A", GUILayout.Width(30)))
                {
                    DeleteAnswer(i); return;
                }

//                if (GUILayout.Button("+R", GUILayout.Width(30))) AddResponse(i);
//                else if (GUILayout.Button("-R", GUILayout.Width(30))) { DeleteResponse(i); return; }

                GUILayout.EndHorizontal();
                // ------------------------------END HORIZONTAL------------------------------

                // ------------------------------NEW HORIZONTAL------------------------------
                if (mIsControlList[i])
                {
                    EditorGUILayout.BeginHorizontal(mDifferentColorBgStyle);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                }
                GUILayout.Label("");

                EditorGUILayout.LabelField("Others", GUILayout.Width(60.0f));
                GUILayout.FlexibleSpace();

                // Appear button.
                if (currDialogue.character.name == CharacterData.Info.Character.NONE)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button("App", GUILayout.Width(42)))
                {
                    if (!mIsAppearList[i])
                    {
                        mIsAppearList[i] = true;
                        if (currDialogue.time.moveInTime == 0 && DialogueSlide.sSingleton.moveTime != 0)
                        {
                            currDialogue.time.moveInTime = DialogueSlide.sSingleton.moveTime;
                        }
                    }
                    else
                    {
                        currDialogue.time.moveInTime = 0.0f;
                        mIsAppearList[i]             = false;
                    }
                    SetMessedUpMessage();
                }
                GUI.enabled = true;

                // Disappear button.
                if (currDialogue.character.name == CharacterData.Info.Character.NONE)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button("Dis", GUILayout.Width(42)))
                {
                    if (!mIsDisappearList[i])
                    {
                        mIsDisappearList[i] = true;
                        if (currDialogue.time.moveOutTime == 0 && DialogueSlide.sSingleton.moveTime != 0)
                        {
                            currDialogue.time.moveOutTime = DialogueSlide.sSingleton.moveTime;
                        }
                    }
                    else
                    {
                        currDialogue.time.moveOutTime = 0.0f;
                        mIsDisappearList[i]           = false;
                    }
                    SetMessedUpMessage();
                }
                GUI.enabled = true;

                // Delay button.
                if (GUILayout.Button("Dly", GUILayout.Width(42)))
                {
                    if (!mIsAddDelayList[i])
                    {
                        mIsAddDelayList[i] = true;
                    }
                    else
                    {
                        currDialogue.time.delayTime = 0.0f;
                        mIsAddDelayList[i]          = false;
                    }
                }

                // Re-open button.
                if (GUILayout.Button("Re", GUILayout.Width(42)))
                {
                    if (!mIsReOpenList[i])
                    {
                        mIsReOpenList[i] = true;
                    }
                    else
                    {
                        currDialogue.time.reOpenTime = 0.0f;
                        mIsReOpenList[i]             = false;
                    }
                }
                GUILayout.EndHorizontal();
                // ------------------------------END HORIZONTAL------------------------------
            }

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
            EditorGUILayout.Space();
        }

        // ------------------------------NEW HORIZONTAL------------------------------
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        EditorGUIUtility.labelWidth = 70.0f;
        mIsAudio = EditorGUILayout.Toggle("Has audio", mIsAudio, GUILayout.Width(90.0f));
        EditorGUIUtility.labelWidth = 80.0f;
        mSelf.isBothAppear          = EditorGUILayout.Toggle("Both appear", mSelf.isBothAppear);
        EditorGUIUtility.labelWidth = 0.0f;
        EditorGUILayout.EndHorizontal();
        // ------------------------------END HORIZONTAL------------------------------

        // ------------------------------NEW HORIZONTAL------------------------------
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("+Dialogue", GUILayout.Width(80)))
        {
            AddDialogue();
        }
        else if (GUILayout.Button("-Dialogue", GUILayout.Width(80)))
        {
            DeleteDialogue();
        }
        else if (GUILayout.Button("Reset", GUILayout.Width(60)))
        {
            ResetInspector();
        }
        EditorGUILayout.EndHorizontal();
        // ------------------------------END HORIZONTAL------------------------------

        if (GUI.changed)
        {
            dialogueInfo = mSelf.GetDialogueInfo();
            EditorUtility.SetDirty(target);
        }
    }