public void RefreshDialogue(string newNodeID, bool showResponse)
    {
        //if loading a new node, first create a dialogue entry for it and push into
        //the stack.



        if (newNodeID != "")
        {
            //create dialogue entry
            //Debug.Log("new node ID " + newNodeID);
            DialogueNode node = GameManager.Inst.DBManager.DBHandlerDialogue.GetDialogueNode(newNodeID);

            if (showResponse)
            {
                DialogueResponse response = EvaluateResponse(node.Responses);
                if (response != null)
                {
                    DialogueEntry entry = CreateDialogueEntry(GetSpeakerName(), ParseDialogueText(response.Text), false);

                    _entries.Push(entry);

                    //check if response has an event
                    if (response.Events != null && response.Events.Count > 0)
                    {
                        foreach (string e in response.Events)
                        {
                            if (GameManager.Inst.QuestManager.Scripts.ContainsKey(e))
                            {
                                StoryEventScript script = GameManager.Inst.QuestManager.Scripts[e];
                                script.Trigger(new object[] {});
                            }
                        }
                    }
                }
            }

            //create dialogue options relevant to this node
            foreach (Topic option in node.Options)
            {
                if (EvaluateTopicConditions(option.Conditions))
                {
                    DialogueOptionEntry optionEntry = new DialogueOptionEntry();

                    GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject;
                    optionEntry.Text      = o.GetComponent <UILabel>();
                    optionEntry.Text.text = option.Title;
                    TopicReference reference = o.GetComponent <TopicReference>();
                    reference.Topic = option;
                    UIButton button = o.GetComponent <UIButton>();
                    button.onClick.Add(new EventDelegate(this, "OnSelectTopic"));

                    _options.Add(optionEntry);
                }
            }
        }

        //create topics entry
        Character    target = GameManager.Inst.PlayerControl.SelectedPC.MyAI.BlackBoard.InteractTarget;
        List <Topic> topics = GameManager.Inst.DBManager.DBHandlerDialogue.GetNPCTopics(target, null);

        foreach (Topic topic in topics)
        {
            //if we are not at root node then don't show info topics
            if (topic.Type == TopicType.Info && _currentNodeID != _rootNode)
            {
                continue;
            }

            //if topic is not known to player, don't show it

            if (topic.Type == TopicType.Info && !GameManager.Inst.PlayerProgress.IsTopicDiscovered(topic.ID))
            {
                continue;
            }


            TopicEntry entry = new TopicEntry();

            GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject;
            entry.Text      = o.GetComponent <UILabel>();
            entry.Text.text = topic.Title;
            TopicReference reference = o.GetComponent <TopicReference>();
            reference.Topic = topic;
            UIButton button = o.GetComponent <UIButton>();
            button.onClick.Add(new EventDelegate(this, "OnSelectTopic"));
            BoxCollider2D collider = o.GetComponent <BoxCollider2D>();
            collider.size = new Vector2(collider.size.x, 27);
            entry.Type    = topic.Type;

            _topics.Add(entry);
        }

        //now make a copy of the stack, and start popping entries out of it, and arrange them under the dialog panel
        Stack <DialogueEntry> copy = new Stack <DialogueEntry>(_entries.Reverse());
        float currentY             = -260;

        _totalHeight = 0;
        int i = 0;

        while (copy.Count > 0)
        {
            DialogueEntry entry = copy.Pop();
            entry.SpeakerName.transform.parent = DialogueEntryAnchor.transform;
            entry.SpeakerName.MakePixelPerfect();
            entry.Text.transform.parent = DialogueEntryAnchor.transform;
            entry.Text.MakePixelPerfect();

            float height = Mathf.Max(entry.SpeakerName.height * 1f, entry.Text.height * 1f);


            entry.SpeakerName.transform.localPosition = new Vector3(-150, currentY + height, 0);
            entry.Text.transform.localPosition        = new Vector3(22, currentY + height, 0);



            currentY      = currentY + height + 15;
            _totalHeight += (height + 15);


            if (_totalHeight < 400)
            {
                DialogueEntryAnchor.localPosition = new Vector3(-210, 0 - _totalHeight, 0);
                _dialogueAnchorTarget             = new Vector3(-210, 175 - _totalHeight, 0);
            }
            else
            {
                DialogueEntryAnchor.localPosition = new Vector3(-210, -220, 0);
                _dialogueAnchorTarget             = new Vector3(-210, -175, 0);
            }


            i++;
        }
        //now re-add collider to fix collider size

        NGUITools.AddWidgetCollider(DialogueScroll.gameObject);

        /*
         * if(_intro != null)
         * {
         *      _intro.transform.parent = DialogueEntryAnchor.transform;
         *      _intro.MakePixelPerfect();
         *      _intro.transform.localPosition = new Vector3(-150, currentY + _intro.height, 0);
         * }
         */

        //arrange topic entries
        currentY = 200;
        TopicScroll.ResetPosition();
        foreach (TopicEntry entry in _topics)
        {
            entry.Text.transform.parent = TopicAnchor.transform;
            entry.Text.MakePixelPerfect();


            entry.Text.transform.localPosition = new Vector3(0, currentY, 0);

            currentY = currentY - entry.Text.height;



            if (entry.Text.text == "Goodbye")
            {
                currentY = currentY - 15;
            }

            if (entry.Type != TopicType.Info)
            {
                entry.Text.color = new Color(0.5f, 0.5f, 0.8f);
            }
        }

        //now re-add collider to fix collider size
        //NGUITools.AddWidgetCollider(TopicScroll.gameObject, false);

        float currentX = -128;

        foreach (DialogueOptionEntry entry in _options)
        {
            entry.Text.transform.parent = DialogueOptionScroll.transform;
            entry.Text.MakePixelPerfect();
            entry.Text.width = entry.Text.text.Length * 15;
            entry.Text.transform.localPosition = new Vector3(currentX, 78, 0);

            BoxCollider2D collider = entry.Text.GetComponent <BoxCollider2D>();
            collider.size = new Vector2(collider.size.x, 27);

            currentX = currentX + entry.Text.width + 20;
        }
    }
Exemple #2
0
	public void RefreshDialogue(string newNodeID, bool showResponse)
	{
		//if loading a new node, first create a dialogue entry for it and push into 
		//the stack. 
		if(newNodeID != "")
		{
			//create dialogue entry

			DialogueNode node = GameManager.Inst.DBManager.DBHandlerDialogue.GetDialogueNode(newNodeID);

			if(showResponse)
			{
				DialogueResponse response = EvaluateResponse(node.Responses);
				if(response != null)
				{
					DialogueEntry entry = CreateDialogueEntry("Jonathan Perpy", ParseDialogueText(response.Text), false);

					_entries.Push(entry);
				}
			}

			//create dialogue options relevant to this node
			foreach(Topic option in node.Options)
			{
				if(EvaluateTopicConditions(option.Conditions))
				{
					DialogueOptionEntry optionEntry = new DialogueOptionEntry();

					GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject;
					optionEntry.Text = o.GetComponent<UILabel>();
					optionEntry.Text.text = option.Title;
					TopicReference reference = o.GetComponent<TopicReference>();
					reference.Topic = option;
					UIButton button = o.GetComponent<UIButton>();
					button.onClick.Add(new EventDelegate(this, "OnSelectTopic"));
					_options.Add(optionEntry);
				}
			}

		}

		//create topics entry
		List<Topic> topics = GameManager.Inst.DBManager.DBHandlerDialogue.GetNPCTopics(null, null);
		foreach(Topic topic in topics)
		{
			//if we are not at root node then don't show info topics
			if(topic.Type == TopicType.Info && _currentNodeID != _rootNode)
			{
				continue;
			}

			TopicEntry entry = new TopicEntry();

			GameObject o = GameObject.Instantiate(Resources.Load("TopicEntry")) as GameObject;
			entry.Text = o.GetComponent<UILabel>();
			entry.Text.text = topic.Title;
			TopicReference reference = o.GetComponent<TopicReference>();
			reference.Topic = topic;
			UIButton button = o.GetComponent<UIButton>();
			button.onClick.Add(new EventDelegate(this, "OnSelectTopic"));

			_topics.Add(entry);
		}

		//now make a copy of the stack, and start popping entries out of it, and arrange them under the dialog panel
		Stack<DialogueEntry> copy = new Stack<DialogueEntry>(_entries.Reverse());

		float currentY = -260;
		while(copy.Count > 0)
		{
			DialogueEntry entry = copy.Pop();
			entry.SpeakerName.transform.parent = DialogueScroll.transform;
			entry.SpeakerName.MakePixelPerfect();
			entry.Text.transform.parent = DialogueScroll.transform;
			entry.Text.MakePixelPerfect();

			float height = Mathf.Max(entry.SpeakerName.height * 1f, entry.Text.height * 1f);

			entry.SpeakerName.transform.localPosition = new Vector3(-150, currentY + height, 0);
			entry.Text.transform.localPosition = new Vector3(22, currentY + height, 0);

			currentY = currentY + height + 15;
		}
		//now re-add collider to fix collider size
		NGUITools.AddWidgetCollider(DialogueScroll.gameObject);


		if(_intro != null)
		{
			_intro.transform.parent = DialogueScroll.transform;
			_intro.MakePixelPerfect();
			_intro.transform.localPosition = new Vector3(-150, currentY + _intro.height, 0);
		}

		//arrange topic entries
		currentY = 85;
		foreach(TopicEntry entry in _topics)
		{
			entry.Text.transform.parent = TopicScroll.transform;
			entry.Text.MakePixelPerfect();
			entry.Text.transform.localPosition = new Vector3(-122, currentY, 0);

			currentY = currentY - entry.Text.height;

			if(entry.Text.text == "Goodbye")
			{
				currentY = currentY - 4;
				TopicDivider.transform.localPosition = new Vector3(8, currentY, 0);
				currentY = currentY - 8;
			}


		}

		float currentX = -128;
		foreach(DialogueOptionEntry entry in _options)
		{
			entry.Text.transform.parent = DialogueOptionScroll.transform;
			entry.Text.MakePixelPerfect();
			entry.Text.width = entry.Text.text.Length * 15;
			entry.Text.transform.localPosition = new Vector3(currentX, 78, 0);

			currentX = currentX + entry.Text.width;
		}

		//now re-add collider to fix collider size
		NGUITools.AddWidgetCollider(TopicScroll.gameObject);

	}