Exemplo n.º 1
0
    //Gets the next line, based on the prerequisites of the possible lines.
    //This means that there may be multiple possible outcomes,
    //depending on the states of the prerequisite flags.
    //If multiple prerequisites are valid, the one with the highest
    //priority value gets selected (or the first, in the case of a tie).
    //Returns null if there is no line that fit.
    public Line FindLine(List <string> lines)
    {
        Line result = null;
        bool found;

        foreach (string id in lines)
        {
            Line l = activeDialogue.GetLine(id);
            if (l == null)
            {
                continue;
            }
            //Best prio so far?
            if (result == null || result.priority < l.priority)
            {
                found = true;
                //If any prereqs fail, skip this line
                foreach (Condition p in l.conditions)
                {
                    var v = flagManager.GetValue(p.flag);
                    if ((p.hasMin && v < p.minValue) || (p.hasMax && v > p.maxValue))
                    {
                        found = false;
                        break;
                    }
                }
                if (found)
                {
                    result = l;
                }
            }
        }
        return(result);
    }
Exemplo n.º 2
0
    //Goes through the prerequisites, checking if
    //this reply is available based on the flags.
    public bool IsAvailable()
    {
        FlagManager fm = GameObject.Find("FlagManager").GetComponent <FlagManager>();

        foreach (Condition p in conditions)
        {
            var v = fm.GetValue(p.flag);
            if ((p.hasMin && v < p.minValue) || (p.hasMax && v > p.maxValue))
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 3
0
    void OnGUI_Selection_ConditionValues(Condition c, FlagManager fm)
    {
        var s = EditorGUILayout.TextField(c.flag, GUILayout.Width(50));

        if (s != c.flag)
        {
            c.flag = s;
        }

        if (c.hasMin)
        {
            c.minValue = EditorGUILayout.IntField(c.minValue, GUILayout.Width(50));
        }
        else
        {
            if (GUILayout.Button("Add", GUILayout.Width(50)))
            {
                c.hasMin = true;
            }
        }

        if (c.hasMax)
        {
            c.maxValue = EditorGUILayout.IntField(c.maxValue, GUILayout.Width(50));
        }
        else
        {
            if (GUILayout.Button("Add", GUILayout.Width(50)))
            {
                c.hasMax = true;
            }
        }

        EditorGUILayout.LabelField(fm.GetValue(c.flag).ToString(), GUILayout.Width(50));
        //float max = c.maxValue, min = c.minValue;
        //EditorGUILayout.MinMaxSlider(ref min, ref max, 0, 100);
        //c.maxValue = (int)max; c.minValue = (int)min;
    }
Exemplo n.º 4
0
 //フラグ操作
 public bool GetFlag(string flagName)
 {
     return(FlagManager.GetValue(flagName));
 }
Exemplo n.º 5
0
    void OnGUI_Selection(Line line)
    {
        FlagManager fm         = GameObject.Find("#Player").GetComponent <FlagManager>();
        Line        parentLine = activeDialogue.GetLine(activeParent);

        Vector2 scroll = EditorGUILayout.BeginScrollView(new Vector2(
                                                             EditorPrefs.GetFloat("DialogueWindow_Selection_ScrollX"), 0),
                                                         new GUIStyle(GUI.skin.horizontalScrollbar), GUIStyle.none,
                                                         GUILayout.ExpandHeight(false), GUILayout.Height(120));

        EditorPrefs.SetFloat("DialogueWindow_Selection_ScrollX", scroll.x);
        EditorGUILayout.BeginHorizontal();

        //Conditions
        if (prefs.conditionUsage != DialogueWindowPreferences.ConditionUsage.None)
        {
            EditorGUILayout.BeginVertical(GUILayout.Width(270));
            EditorGUILayout.LabelField("Conditions", prefs.styleSelectionLabel);
            OnGUI_Selection_ConditionLabels();
            foreach (Condition c in line.conditions)
            {
                EditorGUILayout.BeginHorizontal();
                OnGUI_Selection_ConditionValues(c, fm);
                OnGUI_CheckDelete(c, line);
                EditorGUILayout.EndHorizontal();
            }
            //Add condition
            EditorGUILayout.BeginHorizontal();
            if (prefs.conditionUsage == DialogueWindowPreferences.ConditionUsage.FlagManager)
            {
                newFlagCondition = EditorGUILayout.TextField(newFlagCondition, GUILayout.Width(50));
            }
            else if (prefs.conditionUsage == DialogueWindowPreferences.ConditionUsage.Components)
            {
                EditorPrefs.SetInt("DialogueWindow_AddConditionIndex",
                                   EditorGUILayout.Popup(EditorPrefs.GetInt("DialogueWindow_AddConditionIndex"),
                                                         condNames.ToArray(), GUILayout.Width(50)));
            }
            if (GUILayout.Button("Add", GUILayout.Width(50)))
            {
                Condition c = AddCondition(line);
                c.hasMin = true;
            }
            if (GUILayout.Button("Add", GUILayout.Width(50)))
            {
                Condition c = AddCondition(line);
                c.hasMax = true;
            }
            EditorGUILayout.LabelField(fm.GetValue(newFlagCondition).ToString(), GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }

        //Actions
        GUILayout.Space(20);
        EditorGUILayout.BeginVertical(GUILayout.Width(200));
        EditorGUILayout.LabelField("Actions", prefs.styleSelectionLabel);
        //Set flag
        if (prefs.conditionUsage == DialogueWindowPreferences.ConditionUsage.FlagManager)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Set flag", GUILayout.Width(70));
            line.flagActionName = EditorGUILayout.TextField(line.flagActionName, GUILayout.Width(58));
            EditorGUILayout.LabelField("to", GUILayout.Width(14));
            line.flagActionParam = EditorGUILayout.TextField(line.flagActionParam, GUILayout.Width(58));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();
        }
        //Action function calls
        OnGUI_Selection_Action(line);

        //UI function calls. May cause side effects on player replies, so just disallow.
        if (!line.isPlayer)
        {
            EditorGUILayout.Separator();
            OnGUI_Selection_UI(line);
        }

        EditorGUILayout.EndVertical();

        //Various stuff
        GUILayout.Space(20);
        EditorGUILayout.BeginVertical(GUILayout.Width(150));
        EditorGUILayout.LabelField("Additional data", prefs.styleSelectionLabel);
        if (parentLine != null && !parentLine.isPlayer)
        {
            ToggleIsPlayer(line, EditorGUILayout.Toggle("Player's line", line.isPlayer));
            EditorGUILayout.Separator();
        }
//		else
//			if(EditorGUILayout.Toggle("Player's line", line.isPlayer))
//				EditorUtility.DisplayDialog("Cannot become player's", parentLine == null
//					? "First line cannot be the player's."
//					: "Player cannot have consecutive lines.", "OK");

        if (line.isPlayer)
        {
            var i = EditorGUILayout.IntField("Countdown", line.countdown);
            if (i != line.countdown)
            {
//				EditorUtility.SetDirty(line); //temp
//				Undo.RegisterUndo(line, "countdown editing");
                line.countdown = i;
            }
        }
        else
        {
            int prevIndex = activeDialogue.speakers.IndexOf(line.speaker);
            if (prevIndex == -1)
            {
                prevIndex = (int)Dialogue.SpeakerIndex.TARGET;
            }
            int spIndex = EditorGUILayout.Popup("Speaker", prevIndex,
                                                activeDialogue.speakers.ToArray()); //todo: Don't use ToArray()
            if (spIndex != prevIndex)
            {
//				EditorUtility.SetDirty(line);
//				Undo.RegisterUndo(line, "set speaker");
                if (spIndex == (int)Dialogue.SpeakerIndex.ADD_SPEAKER)
                {
                    //todo: dialog for adding speaker. save new speaker for future lines, at least in this dialogue
                }
                else
                {
                    line.speaker = activeDialogue.speakers[spIndex];
                }
            }

            var i = EditorGUILayout.IntField("Priority", line.priority);
            if (i != line.priority)
            {
//				EditorUtility.SetDirty(line); //temp
//				Undo.RegisterUndo(line, "priority editing");
                line.priority = i;
                //todo
                //parentLine.replies.Sort(Line.LineComparison);
            }
        }
        EditorGUILayout.EndVertical();

        //Comment
        GUILayout.Space(20);
        EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField("Comments", prefs.styleSelectionLabel);
        var s = EditorGUILayout.TextArea(line.comment, GUILayout.MinHeight(87));

        if (s != line.comment)
        {
//			EditorUtility.SetDirty(line); //temp
//			Undo.RegisterUndo(line, "comment text editing");
            line.comment = s;
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndScrollView();
    }