// 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 Setup(ItemID id, string label, ScrollRect scrollTarget) { // Setup the UI child base base.Setup(); // Read the initial note value string initialNote = UIParent.Data.Research.GetEntry(id).ReadNote(label); // Setup the initial note and label labelText.text = label + ":"; myInputField.text = initialNote; // When input finishes editing then write the note to the notebook model myInputField.onEndEdit.AddListener(s => { UIParent.Data.Research.GetEntry(id).WriteNote(label, s); }); // Make the scroll event of the input field target the scroll rect OnScrollEventInterceptor interceptor = myInputField.gameObject.AddComponent <OnScrollEventInterceptor>(); interceptor.InterceptTarget = scrollTarget; }
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; }