private void OnLevelDropdownValueChanged(int value) { int selectedLevel = OptionDataToLevelNumber(levelDropdown.options[value]); // Clear out the options in the enclosure dropdown enclosureDropdown.ClearOptions(); foreach (LevelID id in UIParent.Data.Levels) { if (id.LevelNumber == selectedLevel) { enclosureDropdown.options.Add(EnclosureNumberToOptionData(id.EnclosureNumber)); } } // Get the enclosure represented in the current scene LevelID currentLevel = LevelID.Current(); // If we selected the current level, then select the current enclosure number if (currentLevel.LevelNumber == selectedLevel) { enclosureDropdown.value = currentLevel.EnclosureNumber - 1; } else { enclosureDropdown.value = 0; } // Set the enclosure to the first one selected enclosureDropdown.RefreshShownValue(); OnEnclosureDropdownValueChanged(enclosureDropdown.value); }
public override void Setup() { base.Setup(); // Setup the bookmark target to get-set the enclosure id bookmarkTarget.Setup(() => CurrentLevelID, x => CurrentLevelID = (LevelID)x); // Clear out any existing options levelDropdown.ClearOptions(); enclosureDropdown.ClearOptions(); // Loop through all enclosure id's and add them to the list foreach (LevelID id in UIParent.Data.Levels) { TMP_Dropdown.OptionData option = LevelNumberToOptionData(id.LevelNumber); // If no option with the same text yet exists, then add it to the dropdown if (levelDropdown.options.FindIndex(x => x.text == option.text) < 0) { levelDropdown.options.Add(option); } } // Update the level dropdown to reflect the current level LevelID currentLevel = LevelID.Current(); levelDropdown.value = currentLevel.LevelNumber; levelDropdown.RefreshShownValue(); OnLevelDropdownValueChanged(levelDropdown.value); // Add listeners for the value changed events levelDropdown.onValueChanged.AddListener(OnLevelDropdownValueChanged); enclosureDropdown.onValueChanged.AddListener(OnEnclosureDropdownValueChanged); }
private void OnEnclosureSelected(LevelID id) { // Destroy all existing editors foreach (TestAndMetricsEntryEditor editor in currentEditors) { Destroy(editor.gameObject); } // Clear out the list currentEditors.Clear(); // Foreach entry in the selected list, add an editor foreach (TestAndMetricsEntryData entry in UIParent.Data.TestAndMetrics.GetEntryList(id).Entries) { TestAndMetricsEntryEditor editor = Instantiate(editorPrefab, editorParent.transform); editor.Setup(id, entry, editorScroller); currentEditors.Add(editor); } // If the enclosure selected is the current enclosure, then add a new editor // that we can use to add more entries if (id == LevelID.Current()) { CreateAddingEntry(); } }
public void Setup(NotebookTab tab, ToggleGroup parent, UnityAction <NotebookTab> callback) { // Setup the notebook child base base.Setup(); // Set the tab this.tab = tab; // Setup the toggle myToggle.group = parent; myToggle.onValueChanged.AddListener(OnToggleStateChanged); // Listen for the callback when selected event is raised selectedEvent.AddListener(callback); // Set the text on the GUI element tabName.text = tab.ToString(); if (GameManager.Instance) { // This toggle is only interactable if the tab scaffold says so LevelID current = LevelID.Current(); myToggle.interactable = UIParent.Config.TabScaffold.GetMask(current).Get(tab); } else { myToggle.interactable = true; } }
public override void Setup() { base.Setup(); // Add listener for the enclosure picked event enclosurePicker.OnLevelIDPicked.AddListener(OnEnclosureSelected); OnEnclosureSelected(LevelID.Current()); }
public override void Setup() { base.Setup(); // Add listnener to enclosure id picked event and select the enclosure for the current scene enclosurePicker.OnLevelIDPicked.AddListener(OnEnclosureSelected); OnEnclosureSelected(LevelID.Current()); }
private void CreateAddingEntry() { TestAndMetricsEntryEditor editor = Instantiate(editorPrefab, editorParent.transform); editor.Setup(LevelID.Current(), null, editorScroller); editor.OnNewEntryCreated.AddListener(OnNewEntryCreated); currentEditors.Add(editor); }
private void Start() { // Load the notebook from save, or create a new one if save data doesn't exist data = GameManager.Instance.LoadNotebook() ?? new NotebookData(config); // Set the configuration of the notebook data data.SetConfig(config); // Add the current level data.OnLevelEncountered(LevelID.Current()); // Try to get an instance of the game manager GameManager instance = GameManager.Instance; // If the instance exists then unlock all item id's that exist in the list of items if (instance) { foreach (LevelData.ItemData item in instance.LevelData.ItemQuantities) { data.UnlockItem(item.itemObject.ItemID); } } // Setup the tab picker first of all children tabPicker.Setup(); // Get the resource request editor manually resourceRequestEditor = GetComponentInChildren <ResourceRequestEditor>(true); // Setup all children, ensuring correct initialization order NotebookUIChild[] children = GetComponentsInChildren <NotebookUIChild>(true); foreach (NotebookUIChild child in children) { child.Setup(); } // Map all bookmark targets to their corresponding game object names BookmarkTarget[] allBookmarkTargets = GetComponentsInChildren <BookmarkTarget>(true); foreach (BookmarkTarget bookmarkTarget in allBookmarkTargets) { nameTargetMap.Add(bookmarkTarget.name, bookmarkTarget); } // Setup sound events after all children are set up soundManager.SetupSoundEvents(); // This line of code prevents the notebook from turning off the first time that it is turned on, // while also making sure it is turned off at the start if (!isOpen) { SetIsOpen(false); } }
private void OnSuccessConversationEnded() { // Update the save data with the id of the level we are qualified to go to LevelEndingData ending = GameManager.Instance.LevelData.Ending; SaveData.QualifyForLevel(ending.GetNextLevelID()); // Compute the rating for this level int rating = LevelRatingSystem.RateCurrentLevel(); SaveData.SetLevelRating(LevelID.Current(), rating); // Save changes to the save data SaveData.Save(); // Let the game manager handle level exiting GameManager.Instance.HandleExitLevel(); // Open the success window OpenWindow(successWindow, () => LevelDataLoader.LoadNextLevel(), () => SceneManager.LoadScene("LevelMenu")); }
public override void Setup() { base.Setup(); // Confirm button confirms the review given confirmButton.onClick.AddListener(() => { displayRoot.SetActive(false); lastReviewConfirmed = review; UIParent.Data.Concepts.ConfirmReviwedResourceRequest(LevelID.Current(), review); onReviewConfirmed.Invoke(); }); // Cancel button disables the display cancelButton.onClick.AddListener(() => { displayRoot.SetActive(false); }); // At the setup, make sure the display is inactive displayRoot.SetActive(false); }
// Setup this editor with the entry that it will edit public void Setup(ObservationsEntryData entry, LevelID id, ScrollRect scrollTarget) { base.Setup(); // Setup the text in the input with the initial values of the entry titleInput.text = entry.Title; textInput.text = entry.Text; // Cache the current enclosure LevelID current = LevelID.Current(); // If the id setting up is the same as the current then add the listeners if (id == current) { titleInput.onEndEdit.AddListener(x => entry.Title = x); textInput.onEndEdit.AddListener(x => entry.Text = x); } // Input only interactable if the id for this editor is the same as the current id titleInput.readOnly = id != current; textInput.readOnly = id != current; // Dim the elements if they are not interactable if (id == current) { group.alpha = 1f; } else { group.alpha = 0.5f; } // Add scroll interceptor to the title input OnScrollEventInterceptor interceptor = titleInput.gameObject.AddComponent <OnScrollEventInterceptor>(); interceptor.InterceptTarget = scrollTarget; // Add scroll interceptor to the text input interceptor = textInput.gameObject.AddComponent <OnScrollEventInterceptor>(); interceptor.InterceptTarget = scrollTarget; }
public void UpdateListEdited(LevelID id) { // Make sure that the list is set up if (!IsSetUp) { Setup(); } // Destroy all existing editors foreach (ResourceRequestEditor editor in currentEditors) { Destroy(editor.gameObject); } // Clear out the list currentEditors.Clear(); // Copy the requests and sort the copy //List<ResourceRequest> sortedRequests = new List<ResourceRequest>(UIParent.Notebook.Concepts.GetReviewedResourceRequestList(id).Requests); //sortedRequests.Sort(); //// Foreach entry in the selected list, add an editor //foreach (ResourceRequest request in sortedRequests) //{ // ResourceRequestEditor editor = Instantiate(editorPrefab, editorParent.transform); // editor.Setup(id, request, editorScroller, SortEditors, () => OnRequestDeleted(editor)); // currentEditors.Add(editor); //} // If the enclosure selected is the current enclosure, then add a new editor // that we can use to add more entries if (id == LevelID.Current()) { CreateAddingEntry(); } else { SortEditors(); } }
/// <summary> /// Initialize stuffs here /// </summary> public void Initialize() { startingConversation = GameManager.Instance.LevelData.StartingConversation; defaultConversation = GameManager.Instance.LevelData.DefaultConversation; ConversationManager.OnConversationEnded += ConversationEnded; if (this.startingConversation != null) { currentDialogue = this.startingConversation; } else { UpdateCurrentDialogue(); } if (ConversationManager.Instance != null && !skipOpeningConversation) { StartNewConversation(); currentDialogue.OnConversationEnded(IntroFinished); //Allow for conversation skipping if intro has already been finished if(SaveData.LatestLevelIntroFinished >= LevelID.Current()) { ConversationManager.Instance.SetSkipConversationButton(true); } } }
public NPCConversation Create(DialogueManager dialogueManager) { // Build a new quiz. This will result in regenerating new questions from any randomized pools GenerateQuizInstance(); // Create the callback that is called after any option is answered UnityAction OptionSelectedFunctor(int questionIndex, int optionIndex) { return(() => currentQuiz.AnswerQuestion(questionIndex, optionIndex)); } // Say the conversation that corresponds to the grade that the player got on the quiz void SayResponse() { // Destroy any previous response if (currentResponse) { Destroy(currentResponse); } // Instantiate a new response currentResponse = response.Get(CurrentQuiz.Grade).InstantiateAndSay(); // If we should requiz when we fail, then we must say the quiz after the response if (requizOnFail && CurrentQuiz.Grade != QuizGrade.Excellent) { SayQuizConversationNext(); } // If we will not requiz, then invoke my conversation ended event when this conversation is done else { // Set the quiz on the reports data to the quiz that we just finished GameManager.Instance.NotebookUI.Data.Reports.SetQuiz(LevelID.Current(), currentQuiz); // Invoke the quiz conversation ended event when the response is over currentResponse.OnConversationEnded(onConversationEnded.Invoke); } } // Try to get an npc conversation. If it exists, destroy it and add a new one NPCConversation conversation = gameObject.GetComponent <NPCConversation>(); if (conversation) { #if UNITY_EDITOR DestroyImmediate(conversation); #else Destroy(conversation); #endif } conversation = gameObject.AddComponent <NPCConversation>(); // Create the conversation to be edited here in the code EditableConversation editableConversation = new EditableConversation(); EditableSpeechNode previousSpeechNode = null; // A list of all nodes added to the conversation List <EditableConversationNode> nodes = new List <EditableConversationNode>(); // Loop over every question and add speech and option nodes for each for (int i = 0; i < currentQuiz.RuntimeTemplate.Questions.Length; i++) { // Cache the current question QuizQuestion question = currentQuiz.RuntimeTemplate.Questions[i]; // Create a new speech node EditableSpeechNode currentSpeechNode = CreateSpeechNode(conversation, editableConversation, question.Question, 0, i * 300, i == 0, null); nodes.Add(currentSpeechNode); // If a previous speech node exists, then make the options on the previous node // point to the speech on the current node if (previousSpeechNode != null) { foreach (EditableOptionNode option in previousSpeechNode.Options) { option.Speech.SetSpeech(currentSpeechNode); } } // Add an option node for each quiz option for (int j = 0; j < question.Options.Length; j++) { // Get the current option QuizOption option = question.Options[j]; // Create a new option node with the same label as the quiz option EditableOptionNode optionNode = CreateOptionNode(conversation, editableConversation, option.Label, j * 220, (i * 300) + 100); currentSpeechNode.AddOption(optionNode); nodes.Add(optionNode); // Create a dummy node. It is used to invoke events UnityAction optionCallback = OptionSelectedFunctor(i, j); EditableSpeechNode dummyNode = CreateSpeechNode(conversation, editableConversation, string.Empty, j * 220, (i * 300) + 200, false, optionCallback); nodes.Add(dummyNode); // Make the dummy node advance immediately dummyNode.AdvanceDialogueAutomatically = true; dummyNode.AutoAdvanceShouldDisplayOption = false; dummyNode.TimeUntilAdvance = 0f; // Make the option node point to the dummy node optionNode.SetSpeech(dummyNode); } // Update previous speech node to current before resuming previousSpeechNode = currentSpeechNode; } // Create the end of quiz node EditableSpeechNode endOfQuiz = CreateSpeechNode(conversation, editableConversation, endOfQuizText, 0, currentQuiz.RuntimeTemplate.Questions.Length * 300, false, SayResponse); nodes.Add(endOfQuiz); // If a previous speech node exists, // then make its options point to the end of quiz node if (previousSpeechNode != null) { foreach (EditableOptionNode option in previousSpeechNode.Options) { option.Speech.SetSpeech(endOfQuiz); } } // Have all the nodes register their UIDs (whatever the frick THAT means) foreach (EditableConversationNode node in nodes) { node.RegisterUIDs(); } // Serialize the editable conversation back into the NPCConversation and return the result conversation.RuntimeSave(editableConversation); return(conversation); }
private void GenerateQuizInstance() { // Get the list of reviews for the current attempt of this level ReviewedResourceRequestList reviewsList = GameManager .Instance .NotebookUI .Data .Concepts .GetEntryWithLatestAttempt(LevelID.Current()) .reviews; // If there are reviewed requests then create a quiz with additional questions if (reviewsList.Reviews.Count > 0) { // Filter only reviews that were granted, // and combine reviews that addressed and requested the same item ReviewedResourceRequest[] filteredReviews = reviewsList .Reviews .Where(ResourceRequestGeneratesQuestion) .Distinct(new ReviewedResourceRequest.ItemComparer()) .ToArray(); // Check to make sure there are some reviews to quiz on if (filteredReviews.Length > 0) { // Create an array with all the quiz questions QuizQuestion[] requestQuestions = new QuizQuestion[filteredReviews.Length]; // Fill in the info for each question for (int i = 0; i < requestQuestions.Length; i++) { ResourceRequest request = filteredReviews[i].Request; // Set the category to the item addressed by the request QuizCategory category = new QuizCategory(request.ItemAddressed, request.NeedAddressed); // Generate the quiz options QuizOption[] options = GenerateQuizOptions(request, category); // Setup the format for the question string question = $"Was the requested {request.ItemRequested.Data.Name.Get(ItemName.Type.Colloquial)} " + $"useful for improving the {request.ItemAddressed.Data.Name.Get(ItemName.Type.Colloquial)}" + $" {request.NeedAddressed} need?"; // Create the question requestQuestions[i] = new QuizQuestion(question, category, options); } // Set the current quiz with additional request questions currentQuiz = new QuizInstance(template, requestQuestions); } else { currentQuiz = new QuizInstance(template); } } // If there are no reviwed requests // then create a quiz without additional questions else { currentQuiz = new QuizInstance(template); } }
private void IntroFinished() { SaveData.TrySetLatestLevelIntro(LevelID.Current()); SaveData.Save(); }
public void Setup(LevelID enclosureID, TestAndMetricsEntryData entry, ScrollRect scrollTarget) { base.Setup(); // Setup private fields this.enclosureID = enclosureID; this.entry = entry; // Setup each dropdown itemDropdown.Setup(ItemRegistry.Category.Food, ItemRegistry.Category.Species); needDropdown.Setup(new NeedType[] { NeedType.FoodSource, NeedType.Terrain, NeedType.Liquid }); // Reset the difference options differenceDropdown.ClearOptions(); differenceDropdown.options.Add(new TMP_Dropdown.OptionData("Deteriorated")); differenceDropdown.options.Add(new TMP_Dropdown.OptionData("Improved")); // Set the initial values of the elements if (entry != null) { itemDropdown.SetSelectedItem(entry.Item); needDropdown.SetNeedTypeValue(entry.Need); differenceDropdown.value = entry.Improved ? 1 : 0; inputField.text = entry.Notes; } // If the entry is null, set the values to the first in the dropdown lists else { itemDropdown.SetDropdownValueWithoutNotify(0); needDropdown.SetDropdownValue(0); differenceDropdown.value = 0; inputField.text = UIParent.Config.TestAndMetrics.GetInitialText(enclosureID); } // Cache the current id LevelID current = LevelID.Current(); // Only add the listeners if this editor is in the current scene if (enclosureID == current) { // Add event listeners for everything itemDropdown.OnItemSelected.AddListener(x => Entry.Item = x); needDropdown.OnNeedTypeSelected.AddListener(x => Entry.Need = x); differenceDropdown.onValueChanged.AddListener(x => Entry.Improved = x == 1); inputField.onValueChanged.AddListener(x => Entry.Notes = x); } // Elements are only interactable if id is the same as the current scene group.interactable = enclosureID == current; // Make elements faded if the entry is null - meaning editing this will add a new entry if (entry != null) { group.alpha = 1f; } else { group.alpha = 0.5f; } // Make sure the scroll event is taken away from the input field OnScrollEventInterceptor interceptor = inputField.gameObject.AddComponent <OnScrollEventInterceptor>(); interceptor.InterceptTarget = scrollTarget; }