/// <summary> /// Create a slider at the specified position, assign it to a parent <c>Component</c> and return it. /// </summary> /// <remarks> /// Uses <c>STANDARD_UI_ELEMENT_HEIGHT</c> to determine the /// width and height of this object. Using other values might lead to weird results. /// </remarks> /// <param name="parent">The sliders's supposed parent.</param> /// <param name="name">The Unity name of the slider.</param> /// <param name="value">The default value of the slider.</param> /// <param name="min">The minimum value the slider can be set to.</param> /// <param name="min">The maximum value the slider can be set to.</param> /// <param name="x">The x-position of the slider, relative to the container's upper left corner.</param> /// <param name="y">The y-position of the slider, relative to the container's upper left corner.</param> /// <param name="width">The width of the slider. Note that this includes the label at the side.</param> /// <returns>The created slider.</returns> public static SelectableSliderHelper AddSliderToComponent(Component parent, string name, int value, int min, int max, float x, float y, float width) { SelectableSliderHelper slider = GameObject.Instantiate(sliderTemplate, parent.transform); slider.Set(value, min, max); (slider.transform as RectTransform).anchorMin = new Vector2(0, 1); (slider.transform as RectTransform).anchorMax = new Vector2(0, 1); (slider.transform as RectTransform).offsetMin = new Vector2(x, -y - 50); (slider.transform as RectTransform).offsetMax = new Vector2(x + width, -y); return(slider); }
/// <summary> /// Initalize a bunch of UI element templates: a dialog, a button, a dropdown menu, a slider, a toggle button and /// a label. /// </summary> /// <remarks> /// This method needs to be called before trying to instantiate any UI elements with <c>CreateCustomXXX</c> /// methods, otherwise those will throw unchecked NullPointerExceptions (I should probably handle those better). /// Currently, this is achieved by the <see cref="InitCustomUIElementsPatch"/>. Also, once it has been called, /// another call to this method has no effect. /// </remarks> /// <param name="settingsScreen">The settings screen. Using this to store the dialog template so that it doesn't /// get unloaded. There's probably a less hacky way to do this.</param> /// <param name="dialog">The dialog to be used as a template.</param> /// <param name="settingsDialog">The Settings Dialog, used to get a variety of UI elements.</param> public static void InitalizeTemplates(SettingsScreen settingsScreen, ScreenDialog dialog, SettingsDialog settingsDialog) { // This only needs to run once. if (!AreTemplatesInitalized()) { initalized = true; // Just store a bunch of UI elements from the settings screen as templates. They will always be loaded, // so we don't have to care about manipulating them in any way yet. buttonTemplate = Traverse.Create(settingsDialog).Field("keyMappingButton").GetValue <GameUISelectableButton>(); dropdownTemplate = Traverse.Create(settingsDialog).Field("gameSpeedDropdown").GetValue <GameUISelectableDropdown>();; toggleTemplate = Traverse.Create(settingsDialog).Field("googlyEyesToggle").GetValue <GameUISelectableToggle>(); sliderTemplate = Traverse.Create(Traverse.Create(settingsDialog).Field("scrollSensitivityControl").GetValue <ScrollSensitivityControl>()).Field("slider").GetValue <SelectableSliderHelper>(); // There don't seem to be any labels that are assigned to explicit fields, which kinda makes sense, so we'll have to search for one. // This unfortunately breaks pretty easily as shown by the latest update of the game, so I guess we need a long term solution. labelTemplate = settingsDialog.transform.Find("Content/Content/Audio Section/Global volume control").GetComponentInChildren <TextMeshProUGUI>(); // Print warnings if any initalization has been unsuccessful. if (buttonTemplate == null) { AdvancedRunHistory.Log("Button template is null.", LogLevel.Warning); } if (dropdownTemplate == null) { AdvancedRunHistory.Log("Dropdown template is null.", LogLevel.Warning); } if (toggleTemplate == null) { AdvancedRunHistory.Log("Toggle template is null.", LogLevel.Warning); } if (sliderTemplate == null) { AdvancedRunHistory.Log("Slider template is null.", LogLevel.Warning); } if (labelTemplate == null) { AdvancedRunHistory.Log("Label template is null.", LogLevel.Warning); } // We actually neeed to instantiate a copy of the dialog template right now, as the Patch Notes dialog will // unload as soon as you leave the Main Menu screen. Also, we can remove its contents while we're at it. dialogTemplate = GameObject.Instantiate(dialog, settingsScreen.transform); foreach (Transform child in dialogTemplate.transform.Find("Content")) { GameObject.Destroy(child.gameObject); } if (dialogTemplate == null) { AdvancedRunHistory.Log("Dialog template is null.", LogLevel.Warning); } } }
private void MakeProgressFilter(float xOffset, float yOffset) { if (progressFilter == null) { progressFilter = new RunDataFilterProgress(); filterManager.AddFilter(progressFilter); } CustomUIManager.AddLabelToComponent(content, "Min Ring:", xOffset, yOffset, 240, 50); CustomUIManager.AddLabelToComponent(content, "Max Ring:", xOffset, yOffset + 70, 240, 50); progressMinSlider = CustomUIManager.AddSliderToComponent(content, "MinProgressSlider", 0, 0, 25, xOffset + columnWidth, yOffset, 240); progressMaxSlider = CustomUIManager.AddSliderToComponent(content, "MaxProgressSlider", 25, 0, 25, xOffset + columnWidth, yOffset + lineHeight, 240); progressMinSlider.ValueChangedSignal.AddListener(HandleMinProgress); progressMaxSlider.ValueChangedSignal.AddListener(HandleMaxProgress); UpdateProgressFilter(); sliders.Add(progressMinSlider); sliders.Add(progressMaxSlider); }
private void MakeCovenantFilter(float xOffset, float yOffset) { if (covenantFilter == null) { covenantFilter = new RunDataFilterCovenant(); filterManager.AddFilter(covenantFilter); } CustomUIManager.AddLabelToComponent(content, "Min Covenant:", xOffset, yOffset, 240, 50); CustomUIManager.AddLabelToComponent(content, "Max Covenant:", xOffset, yOffset + 70, 240, 50); covenantMinSlider = CustomUIManager.AddSliderToComponent(content, "MinCovenantSlider", 0, 0, 25, xOffset + columnWidth, yOffset, 240); covenantMaxSlider = CustomUIManager.AddSliderToComponent(content, "MaxCovenantSlider", 25, 0, 25, xOffset + columnWidth, yOffset + lineHeight, 240); covenantMinSlider.ValueChangedSignal.AddListener(HandleMinCovenant); covenantMaxSlider.ValueChangedSignal.AddListener(HandleMaxCovenant); UpdateCovenantFilter(); sliders.Add(covenantMinSlider); sliders.Add(covenantMaxSlider); }