예제 #1
0
파일: Console.cs 프로젝트: mill1/dynamic-ui
        private static void HandleUserInteraction(IUI ui, Dictionary <string, UiOption> uiOptions)
        {
            UiOption uiOption = null;

            ui.Output(new string('-', 40));

            foreach (KeyValuePair <string, UiOption> option in uiOptions)
            {
                ui.Output($"({option.Key}) - {option.Value.Text}");
            }

            string input = ui.Input("Select an option:", null);

            if (!string.IsNullOrEmpty(input) && uiOptions.TryGetValue(input, out uiOption))
            {
                uiOption.Action();
            }
            else
            {
                ui.Output("Option does not exist");
            }
        }
예제 #2
0
    void activateDecisions(Prompt prompt, int currentOptionInt)
    {
        optionsActive = true;
        if (currentPrompt.noPointer == false)
        {
            pointer.SetActive(true);
        }
        currentOptionIndex = currentOptionInt;
        //assign new prompt
        if (prompt == null)
        {
            Debug.Log("NoPrompt");
        }
        else
        {
            currentPrompt        = prompt;
            scenePromptText.text = currentPrompt.promptString;

            foreach (PromptOption option in prompt.promptOptions)
            {
                bool valid = true;

                foreach (string requiredKey in option.requiredKeys)
                {
                    if (!ownedKeys.Contains(requiredKey))
                    {
                        valid = false;
                        break;
                    }
                    else if (PlayerPrefs.HasKey(requiredKey))
                    {
                        if (PlayerPrefs.GetInt(requiredKey) != 1)
                        {
                            valid = false;
                            break;
                        }
                    }
                }

                foreach (string forbiddenKey in option.forbiddenKeys)
                {
                    if (ownedKeys.Contains(forbiddenKey))
                    {
                        valid = false;
                        break;
                    }
                    else if (PlayerPrefs.HasKey(forbiddenKey))
                    {
                        if (PlayerPrefs.GetInt(forbiddenKey) == 1)
                        {
                            valid = false;
                            break;
                        }
                    }
                }

                //at this point, we now know whether the option is valid to display. so we create the option in the UI accordingly.

                if (valid == true)
                {
                    UiOption uiOption = Instantiate(uiPromptOptionPrefab) as UiOption;
                    uiOption.transform.SetParent(scenePromptOptions.transform, false);
                    uiOption.text.text = option.optionString;
                    if (option.fontFace != null)
                    {
                        uiOption.text.font = option.fontFace;
                    }
                    uiOption.text.alignment = option.alignment;
                    //the UI option needs a reference to the actual option in order for Update (above) to know which option that the current UI option refers to

                    uiOption.option = option;
                }
            }
        }
        if (timetbox != null)
        {
            if (currentPrompt.useTimer && PlayerPrefs.GetInt("Debugging") != 1)
            {
                if (scenePromptOptions.transform.childCount == 1)
                {
                    activateTimer = false;
                    Debug.Log("activateTimerFalse");
                }
                else
                {
                    time          = currentPrompt.time;
                    activateTimer = true;
                    if (isTimerActive == false)
                    {
                        timeLeft      = time;
                        isTimerActive = true;
                    }
                    Debug.Log("activateTimerTrue");
                }
            }
            if (currentPrompt.hideTimer)
            {
                timetbox.color = new Color(0, 0, 0, 0);
            }
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (pausedPrefab != null)
            {
                if (!isPaused)
                {
                    isPaused            = true;
                    pausedScreen        = Instantiate(pausedPrefab, new Vector3(0, 0, 100f), gameObject.transform.rotation);
                    Time.timeScale      = 0;
                    Time.fixedDeltaTime = 0;
                }
                else
                {
                    unpauseGame();
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.R) && isPaused)
        {
            SceneManager.LoadScene("MainMenu");
        }

        if (!isPaused)
        {
            if (activateTimer && scenePromptOptions.transform.childCount != 1)
            {
                timeLeft     -= Time.deltaTime;
                timetbox.text = Mathf.Round(timeLeft).ToString();
                if (timeLeft < 0)
                {
                    if (currentPrompt.TimerForceChoice)
                    {
                        currentOptionIndex = currentPrompt.TimerForceOptionInt;
                        for (int i = 0; i < 10; i++)
                        {
                            ownedKeys.Remove("disappearChoice" + i.ToString());
                        }
                        activateTimer = false;
                        if (timetbox != null)
                        {
                            timetbox.text = "";
                        }
                        deactivateDecisions(currentPrompt);
                        insecurityActivatedOnce = false;
                        isTimerActive           = false;
                        PromptOption option = currentUiOption.option;
                        arrStoryInt       = option.nextLinesInt;
                        currentStoryIndex = option.startingInt;
                        promptTimer       = option.startingInt;
                        currentPrompt     = option.optionPrompt;
                        if (option.picture != null)
                        {
                            background.GetComponent <Image> ().sprite = option.picture;
                        }
                        if (option.sound != null)
                        {
                            AudioSource.PlayClipAtPoint(option.sound, new Vector3(0, 0, 0));
                        }
                        foreach (string grantedKey in option.grantedKeys)
                        {
                            ownedKeys.Add(grantedKey);
                        }
                        nextStoryLine(currentStoryIndex);
                    }
                    else
                    {
                        timetbox.text = "";
                        deleteChoice();
                    }
                }
            }

            if (DinerRound1NextPlayerCheck.timeDelay == true || ElectronicsCheckers.timeDelay == true || GiftShopCheckers.timeDelay == true || MechanicCheckers.timeDelay == true)
            {
                nextStoryLine(currentStoryIndex);
                DinerRound1NextPlayerCheck.timeDelay = false;
                ElectronicsCheckers.timeDelay        = false;
                GiftShopCheckers.timeDelay           = false;
                MechanicCheckers.timeDelay           = false;
            }


            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                //select previous option (if possible)
                if (optionsActive)
                {
                    insecurityActivatedOnce = false;
                    deactivateDecisions(currentPrompt);
                    if (currentOptionIndex == 0)
                    {
                        currentOptionIndex = scenePromptOptions.transform.childCount - 1;
                    }
                    else
                    {
                        currentOptionIndex = Mathf.Max(currentOptionIndex - 1, 0);
                    }
                    activateDecisions(currentPrompt, currentOptionIndex);
                }
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                //select next option (if possible)
                if (optionsActive)
                {
                    insecurityActivatedOnce = false;
                    deactivateDecisions(currentPrompt);
                    if (currentOptionIndex == scenePromptOptions.transform.childCount - 1)
                    {
                        currentOptionIndex = 0;
                    }
                    else
                    {
                        currentOptionIndex = Mathf.Min(currentOptionIndex + 1, scenePromptOptions.transform.childCount - 1);
                    }
                    activateDecisions(currentPrompt, currentOptionIndex);
                }
            }
            else if (Input.GetKeyDown(KeyCode.Return) && PlayerPrefs.GetInt("PreventReturn") != 1)
            {
                if (promptTimer == StoryStrings.StoryLines [arrStoryInt].StoryText.Length + 1)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        ownedKeys.Remove("disappearChoice" + i.ToString());
                    }
                    activateTimer = false;
                    if (timetbox != null)
                    {
                        timetbox.text = "";
                    }
                    deactivateDecisions(currentPrompt);
                    insecurityActivatedOnce = false;
                    isTimerActive           = false;
                    PromptOption option = currentUiOption.option;
                    arrStoryInt       = option.nextLinesInt;
                    currentStoryIndex = option.startingInt;
                    promptTimer       = option.startingInt;
                    currentPrompt     = option.optionPrompt;
                    if (option.picture != null)
                    {
                        background.GetComponent <Image> ().sprite = option.picture;
                    }
                    if (option.sound != null)
                    {
                        AudioSource.PlayClipAtPoint(option.sound, new Vector3(0, 0, -10));
                    }
                    foreach (string grantedKey in option.grantedKeys)
                    {
                        ownedKeys.Add(grantedKey);
                    }
                }
                nextStoryLine(currentStoryIndex);
            }
            else if (Input.GetKeyDown(KeyCode.Backspace))
            {
                if (optionsActive == false && PlayerPrefs.GetInt("Debugging") == 1)
                {
                    if (currentStoryIndex != 1)
                    {
                        previousStoryLine(currentStoryIndex);
                    }
                }
            }
            else if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (PlayerPrefs.GetInt("Debugging") == 1)
                {
                    SceneManager.LoadScene("DebuggerSelection");
                }
            }
            if (promptTimer == StoryStrings.StoryLines [arrStoryInt].StoryText.Length + 1)
            {
                movePointer();
                Transform t = scenePromptOptions.transform.GetChild(currentOptionIndex); //get the child of the the "UiOptions" object corresponding to the current option index
                currentUiOption = t.GetComponent <UiOption> ();                          //store a reference to the UiOption component of this child
            }
            if (Input.GetKeyDown(KeyCode.C))
            {
                print("currentStoryIndex: " + currentStoryIndex);
                print("arrStoryInt: " + arrStoryInt);
                print("currentTurn " + PlayerPrefs.GetInt("currentTurn").ToString());
            }
            if (promptTimer == StoryStrings.StoryLines [arrStoryInt].StoryText.Length)
            {
                activateDecisions(currentPrompt, 0);
                currentStoryIndex = 0;
                promptTimer      += 1;
            }
            for (int i = 0; i < scenePromptOptions.transform.childCount; i++)
            {
                Transform child     = scenePromptOptions.transform.GetChild(i);
                Text      childText = child.GetComponent <Text> ();
                childText.fontSize = 15;

                if (i == currentOptionIndex)
                {
                    if (playernum == 1)
                    {
                        childText.color = newBluePointer;
                    }
                    else if (playernum == 2)
                    {
                        childText.color = newGreenPointer;
                    }
                    else if (playernum == 3)
                    {
                        childText.color = newRedPointer;
                    }
                    else if (playernum == 4)
                    {
                        childText.color = newYellowPointer;
                    }
                }
                else
                {
                    childText.color = Color.white;
                }
            }
        }
    }