예제 #1
0
        /// <summary>
        /// Change the type of the dialog part and modify the GUI according to the new type
        /// </summary>
        /// <param name="_type"></param>
        private void ChangeType(DialogSetType _type)
        {
            m_type = _type;
            switch (m_type)
            {
            case DialogSetType.BasicType:
                m_currentIcon = m_basicSetIcon;
                for (int i = 0; i < m_dialogLines.Count - 1; i++)
                {
                    m_dialogLines[i].LinkedToken = -1;
                }
                break;

            case DialogSetType.PlayerAnswer:
                m_currentIcon = m_answerIcon;
                break;

            default:
                break;
            }
        }
예제 #2
0
        /// <summary>
        /// Draw the Dialog Line
        /// </summary>
        /// <param name="_startPos">Starting position of the rect within the line will be drawn</param>
        /// <param name="_lineDescriptor">Line Descriptor</param>
        /// <param name="_removeAction">Action called when the Dialog Line is removed</param>
        /// <param name="_isLastPoint">Does this Dialog Line has to draw an out point</param>
        /// <param name="_pointIcon">Icon of the out point</param>
        /// <param name="_pointStyle"> Style of the point
        /// <param name="_onOutLineSelected">Action called when the out point of this line is selected</param>
        /// <param name="_otherSets">The other sets in the current Dialog</param>
        /// <returns>Height used to draw the dialog Line</returns>
        public float Draw(Vector2 _startPos, string _lineDescriptor, Action <DialogueLine> _removeAction, DialogSetType _dialogSetType, bool _isLastPoint, GUIContent _pointIcon, GUIStyle _pointStyle, Action <DialogueLine> _onOutLineSelected, List <DialogueSet> _otherSets, List <DialogueCondition> _otherConditions, List <CharacterColorSettings> _colorSettings)
        {
            if (m_ids == null)
            {
                InitEditor(_lineDescriptor);
            }
            if (m_content == string.Empty && m_key != string.Empty)
            {
                Script _luaScript = new Script();
                _luaScript.DoString(_lineDescriptor);
                DynValue _content = _luaScript.Globals.Get(m_key).Table.Get("Text_En_en");

                m_content = _content.String;
            }
            Rect _r = new Rect(_startPos.x, _startPos.y, DialogueNode.POPUP_HEIGHT, DialogueNode.POPUP_HEIGHT);

            if (GUI.Button(_r, "-"))
            {
                _removeAction.Invoke(this);
                return(_r.y);
            }
            _r = new Rect(_r.position.x + DialogueNode.POPUP_HEIGHT, _r.position.y, DialogueNode.CONTENT_WIDTH - DialogueNode.POPUP_HEIGHT, DialogueNode.POPUP_HEIGHT);

            Color _originalColor = GUI.backgroundColor;

            if (_colorSettings != null && m_key != string.Empty && _colorSettings.Any(s => s.CharacterIdentifier == m_key.Substring(0, 2)))
            {
                GUI.backgroundColor = _colorSettings.Where(s => s.CharacterIdentifier == m_key.Substring(0, 2)).First().CharacterColor;
            }
            m_nextIndex         = EditorGUI.Popup(_r, "Line ID", m_index, m_ids);
            GUI.backgroundColor = _originalColor;
            if (m_nextIndex != m_index)
            {
                m_index = m_nextIndex;
                m_key   = m_ids[m_index];

                Script _luaScript = new Script();
                _luaScript.DoString(_lineDescriptor);
                DynValue _content = _luaScript.Globals.Get(m_key).Table.Get("Text_En_en");

                m_content = _content.String;
            }
            _r.y += DialogueNode.POPUP_HEIGHT;

            // -- Draw the dialog line content -- //
            _r = new Rect(_startPos.x, _r.position.y, DialogueNode.CONTENT_WIDTH, DialogueNode.BASIC_CONTENT_HEIGHT);
            GUI.TextArea(_r, m_content);
            _r.y += DialogueNode.BASIC_CONTENT_HEIGHT;

            _r = new Rect(_startPos.x, _r.position.y, DialogueNode.CONTENT_WIDTH, DialogueNode.POPUP_HEIGHT);
            m_initalWaitingTime = EditorGUI.Slider(_r, new GUIContent("Inital Waiting Time (s): ", "Used if there is no audioclip linked to this line"), m_initalWaitingTime, 0, 10);
            _r.y += DialogueNode.POPUP_HEIGHT;

            EditorGUI.BeginDisabledGroup(_dialogSetType == DialogSetType.PlayerAnswer);
            // -- Draw the Dialog Line Waiting Type -- //
            _r            = new Rect(_startPos.x, _r.position.y, DialogueNode.CONTENT_WIDTH, DialogueNode.POPUP_HEIGHT);
            m_waitingType = (WaitingType)EditorGUI.EnumPopup(_r, "Extra Waiting Type: ", m_waitingType);
            _r.y         += DialogueNode.POPUP_HEIGHT;

            EditorGUI.BeginDisabledGroup(m_waitingType != WaitingType.WaitForTime);
            // -- Draw the Dialog Waiting Time Value -- //
            _r = new Rect(_startPos.x, _r.position.y, DialogueNode.CONTENT_WIDTH, DialogueNode.POPUP_HEIGHT);
            m_extraWaitingTime = EditorGUI.Slider(_r, new GUIContent("Extra Waiting Time (s): ", "Duration to wait after the end of the inital waiting time"), m_extraWaitingTime, 0, 10);
            EditorGUI.EndDisabledGroup();
            EditorGUI.EndDisabledGroup();
            _r.y += DialogueNode.POPUP_HEIGHT;

            _r.y += DialogueNode.SPACE_HEIGHT / 2;
            Color _c = GUI.color;

            GUI.color = Color.black;
            _r        = new Rect(_startPos.x, _r.position.y, DialogueNode.CONTENT_WIDTH, .5f);
            GUI.Box(_r, "");
            GUI.color = _c;

            _r.y += DialogueNode.SPACE_HEIGHT / 2;


            m_pointRect = new Rect(_startPos.x + DialogueNode.CONTENT_WIDTH - 2, (_startPos.y + _r.y) / 2, 38, 38);
            if (_isLastPoint || _dialogSetType == DialogSetType.PlayerAnswer)
            {
                if (m_linkedToken != -1)
                {
                    Rect _linkedRect = Rect.zero;
                    if (_otherSets.Any(s => s.NodeToken == m_linkedToken))
                    {
                        _linkedRect = _otherSets.Where(p => p.NodeToken == m_linkedToken).First().InPointRect;
                    }
                    else if (_otherConditions.Any(c => c.NodeToken == m_linkedToken))
                    {
                        _linkedRect = _otherConditions.Where(p => p.NodeToken == m_linkedToken).First().InPointRect;
                    }
                    else
                    {
                        m_linkedToken = -1;
                    }
                    if (_linkedRect != Rect.zero)
                    {
                        Handles.DrawBezier(m_pointRect.center, _linkedRect.center, m_pointRect.center + Vector2.right * 100.0f, _linkedRect.center + Vector2.left * 100.0f, Color.white, null, 2.0f);
                        Handles.color = Color.white;
                        if (Handles.Button((m_pointRect.center + _linkedRect.center) * 0.5f, Quaternion.identity, 4, 8, Handles.RectangleHandleCap))
                        {
                            m_linkedToken = -1;
                        }
                    }
                }
                if (GUI.Button(m_pointRect, _pointIcon, _pointStyle))
                {
                    _onOutLineSelected?.Invoke(this);
                }
            }
            return(_r.y);
        }