Beispiel #1
0
        public IEnumerator Running()
        {
            // Wait a frame so we can evaluate if objects we check for requirements have been destroyed
            yield return(0);

            // Display the choices on the UI
            UIManager.ui_manager.choice_panel.SetActive(true);

            if (Localize_Choice_Text)
            {
                UIManager.ui_manager.choice_text_banner.text = VNSceneManager.scene_manager.Get_Localized_Dialogue_Entry(Name_Of_Choice);  // Localize the name of the choice;
            }
            else
            {
                UIManager.ui_manager.choice_text_banner.text = Name_Of_Choice;
            }

            if (Hide_Dialogue_UI)
            {
                VNSceneManager.scene_manager.Show_UI(!Hide_Dialogue_UI);
            }

            // Loop through each button
            // Make buttons that have events visible, set their text,
            // add call to Finish_Node() on the OnClick() listener and hook up the choices buttons to the events on this node
            for (int x = 0; x < Number_Of_Choices; x++)
            {
                if (Button_Events[x].GetPersistentEventCount() > 0)
                {
                    // Set a button image for this button if we have one
                    if (x < choice_button_images.Length && choice_button_images[x] != null)
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().sprite = choice_button_images[x];

                        if (use_image_native_size_for_buttons)
                        {
                            UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().preserveAspect = true;
                            UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().type           = Image.Type.Simple;
                            UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().SetNativeSize();
                            UIManager.ui_manager.choice_buttons[x].GetComponent <LayoutElement>().preferredHeight = -1;
                        }
                    }
                    // No image to set, use reset it to the default one
                    else
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().sprite = default_button_sprite;
                        UIManager.ui_manager.choice_buttons[x].GetComponent <LayoutElement>().preferredHeight = default_button_flexible_height;
                        UIManager.ui_manager.choice_buttons[x].GetComponent <Image>().preserveAspect          = false;
                        //UIManager.ui_manager.choice_buttons[x].GetComponent<Image>().SetNativeSize();
                    }

                    UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(true);    // Make visible
                    UIManager.ui_manager.choice_buttons[x].interactable = true;
                    bool requirement_met = true;

                    if (Localize_Choice_Text)
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentInChildren <Text>().text = VNSceneManager.scene_manager.Get_Localized_Dialogue_Entry(Button_Text[x]);   // Set button text, get localized version
                    }
                    else
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentInChildren <Text>().text = Button_Text[x];   // Set button text
                    }
                    //(Choice_Been_Clicked_Before[x] ||
                    if (Show_Choice_Was_Selected_Before[x] && StatsManager.Compare_Bool_Stat_To(Name_Of_Choice + ": " + Button_Text[x], true))
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentsInChildren <Image>(true)[1].enabled = true;
                    }
                    else
                    {
                        UIManager.ui_manager.choice_buttons[x].GetComponentsInChildren <Image>(true)[1].enabled = false;
                    }


                    if (Has_Requirements[x] != Choice_Stat_Requirement.No_Requirement)
                    {
                        // Loop through each requirement
                        for (int req = 0; req < max_number_of_buttons; req++)
                        {
                            bool this_requirement_met = true;

                            // No more requirements
                            if (req > 0 && Logic[x * max_number_of_buttons + (req - 1)] == Choice_Boolean_Logic.Done)
                            {
                                break;
                            }

                            // Check stat requirements
                            switch (Requirement_Type[x * max_number_of_buttons + req])
                            {
                            case Choice_Condition.Float_Stat_Requirement:
                                this_requirement_met = StatsManager.Compare_Float_Stat(Stat_Name[x * max_number_of_buttons + req], Float_Stat_Is[x * max_number_of_buttons + req], Float_Compare_Value[x * max_number_of_buttons + req]);
                                break;


                            case Choice_Condition.Bool_Stat_Requirement:
                                this_requirement_met = StatsManager.Compare_Bool_Stat_To(Stat_Name[x * max_number_of_buttons + req], Bool_Compare_Value[x * max_number_of_buttons + req]);
                                break;


                            case Choice_Condition.String_Stat_Requirement:
                                bool the_same = true;
                                switch (String_Is[x * max_number_of_buttons + req])
                                {
                                case Result.Is:
                                    the_same = true;
                                    break;

                                case Result.Is_Not:
                                    the_same = false;
                                    break;
                                }
                                this_requirement_met = StatsManager.Compare_String_Stat_To(Stat_Name[x * max_number_of_buttons + req], String_Compare_Value[x * max_number_of_buttons + req], the_same);
                                break;


                            case Choice_Condition.Object_Is_Null:
                                // Check if object exists
                                // If the object doesn't exist, and the box is checked
                                // OR  the object exists and the box is not checked
                                this_requirement_met = Check_Null_Object[x * max_number_of_buttons + req] && !Bool_Compare_Value[x * max_number_of_buttons + req];
                                break;
                            }

                            // Compare this requirement with previous requirement
                            if (req > 0)
                            {
                                switch (Logic[x * max_number_of_buttons + (req - 1)])
                                {
                                case Choice_Boolean_Logic.And:
                                    requirement_met = requirement_met && this_requirement_met;
                                    break;

                                case Choice_Boolean_Logic.Or:
                                    requirement_met = requirement_met || this_requirement_met;
                                    break;
                                }
                            }
                            else
                            {
                                requirement_met = this_requirement_met; // First requirement uses this requirement
                            }
                        }
                    }

                    // Stat requirements have been met. Display the choice
                    if (requirement_met)
                    {
                        AddListeners(x);
                    }
                    else
                    {
                        switch (Requirement_Not_Met_Actions[x])
                        {
                        case Requirement_Not_Met_Action.Disable_Button:
                            UIManager.ui_manager.choice_buttons[x].interactable = false;
                            UIManager.ui_manager.choice_buttons[x].GetComponentInChildren <Text>().text = Disabled_Text[x];      // Set button text
                            break;

                        case Requirement_Not_Met_Action.Hide_Choice:
                            UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(false);        // Make inivisible
                            break;
                        }
                    }
                }
                else
                {
                    UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(false);
                }
            }

            // Disable all other buttons
            for (int x = Number_Of_Choices; x < max_number_of_buttons; x++)
            {
                UIManager.ui_manager.choice_buttons[x].gameObject.SetActive(false);
            }

            if (randomize_choices_order)
            {
                RandomizeButtonOrder();
            }
        }
Beispiel #2
0
        public IEnumerator Running()
        {
            // Wait a frame so we can evaluate if objects we check for requirements have been destroyed
            yield return(0);

            bool conditions_met = true;

            for (int x = 0; x < Number_Of_Conditions; x++)
            {
                bool cur_condition = false;

                // Evaluate each condition sequentially
                switch (Conditions[x])
                {
                case Condition.Bool_Stat_Requirement:
                    cur_condition = StatsManager.Compare_Bool_Stat_To(Stat_Name[x], Bool_Compare_Value[x]);
                    break;


                case Condition.Float_Stat_Requirement:
                    cur_condition = StatsManager.Compare_Float_Stat(Stat_Name[x], Float_Stat_Is[x], Float_Compare_Value[x]);
                    break;

                case Condition.String_Stat_Requirement:
                    bool the_same = true;
                    switch (String_Is[x])
                    {
                    case Result.Is:
                        the_same = true;
                        break;

                    case Result.Is_Not:
                        the_same = false;
                        break;
                    }
                    cur_condition = StatsManager.Compare_String_Stat_To(Stat_Name[x], String_Compare_Value[x], the_same);
                    break;

                case Condition.Object_Is_Null:
                    // Check if object exists
                    // If the object doesn't exist, and the box is checked
                    // OR  the object exists and the box is not checked
                    cur_condition = Check_Null_Object[x] && !Bool_Compare_Value[x];
                    break;

                case Condition.Object_Is_Active:
                    // Check if the gameobject is enabled
                    cur_condition = Check_Active_Object[x].activeSelf && Bool_Compare_Value[x];
                    break;
                }

                // Check if need to keep going with AND's or OR's
                if (x == 0)
                {
                    // First condition, nothing to AND or OR with
                    conditions_met = cur_condition;
                }
                else if (x < Number_Of_Conditions)
                {
                    // Must AND or OR the previous condition
                    switch (Logic[x - 1])
                    {
                    case Boolean_Logic.And:
                        conditions_met = conditions_met && cur_condition;
                        break;

                    case Boolean_Logic.Or:
                        conditions_met = conditions_met || cur_condition;
                        break;
                    }
                }
            }

            if ((Is_Condition_Met == Condition_Is.Met && conditions_met) ||
                (Is_Condition_Met == Condition_Is.Not_Met && !conditions_met))
            {
                switch (Action)
                {
                case Requirement_Met_Action.Change_Conversation:
                    if (Conversation_To_Switch_To != null)
                    {
                        Conversation_To_Switch_To.Start_Conversation();
                    }
                    else
                    {
                        Debug.LogError("No conversation to switch to", this.gameObject);
                    }
                    break;

                case Requirement_Met_Action.Jump_to_Middle_of_Conversation:
                    if (!Node_To_Switch_To)
                    {
                        Debug.LogError("Node to switch to not set in IfNode", gameObject);
                        break;
                    }

                    ConversationManager cm = Node_To_Switch_To.GetComponentInParent <ConversationManager>();
                    if (cm)
                    {
                        cm.Start_At_Node(Node_To_Switch_To);
                    }
                    else
                    {
                        Debug.LogError("Couldn't find Conversation associated with Node: " + Node_To_Switch_To.name, gameObject);
                    }
                    break;

                case Requirement_Met_Action.Custom_Events:
                    Custom_Actions.Invoke();

                    if (Continue_Conversation)
                    {
                        Finish_Node();
                    }
                    break;
                }
            }
            else
            {
                // Just continue conversation
                Finish_Node();
            }
        }