// This is probably the weirdest one, so some comments here. private void MakeClanFilter(float xOffset, float yOffset) { // As usual, start with initalizing the filters if they aren't yet. // (Probably should use two if-statements as a fail-safe, but there should be no way only one of them // is ever set and not the other) if (clanFilter1 == null || clanFilter2 == null) { clanFilter1 = new RunDataFilterClan(saveManager, RunDataFilterClan.CLAN_ANY, RunDataFilterClan.AS_PRIMARY); filterManager.AddFilter(clanFilter1); clanFilter2 = new RunDataFilterClan(saveManager, RunDataFilterClan.CLAN_ANY, RunDataFilterClan.AS_SECONDARY); filterManager.AddFilter(clanFilter2); } // First clan: Choose the clan as well as the role it should play. clanRoleDropdown = CustomUIManager.AddDropdownToComponent(content, "ClanRoleDropdown", RunDataFilterClan.roleOptions, xOffset - 10, yOffset); CustomUIManager.AddLabelToComponent(content, "Clan:", xOffset + 260, yOffset, 100, 50); clanDropdown1 = CustomUIManager.AddDropdownToComponent(content, "ClanDropdown1", clanFilter1.clanOptions, xOffset + columnWidth, yOffset); // For the second clan, the role directly results from the first clan's role, so we can use a simple label. // However, we need to update that label accordingly if the first clan's role is changed, see below. secondClanLabel = CustomUIManager.AddLabelToComponent(content, "Secondary Clan:", xOffset, yOffset + 70, 350, 50); clanDropdown2 = CustomUIManager.AddDropdownToComponent(content, "ClanDropdown1", clanFilter2.clanOptions, xOffset + columnWidth, yOffset + lineHeight); // Add listeners. clanRoleDropdown.optionChosenSignal.AddListener(HandleClanRole); clanDropdown1.optionChosenSignal.AddListener(HandleClan1); clanDropdown2.optionChosenSignal.AddListener(HandleClan2); // If the current filter settings are not the default ones, we need to update the UI elements. As we also // need to do this whenever the first clan's role is changed, put it in a seperate method. UpdateClanFilter(); // "Register" the UI elements. dropdowns.Add(clanRoleDropdown); dropdowns.Add(clanDropdown1); dropdowns.Add(clanDropdown2); }
/// <summary> /// Create a dropdown menu at the specified position, assign it to a parent <c>Component</c> and return it. /// </summary> /// <remarks> /// Uses <c>STANDARD_UI_ELEMENT_WIDTH</c> and <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 dropdown menu's supposed parent.</param> /// <param name="name">The Unity name of the dropdown menu.</param> /// <param name="options">A list of availalbe options, as a string. The first one is automatically /// set as default when invoking this method.</param> /// <param name="x">The x-position of the dropdown menu, relative to the container's upper left corner.</param> /// <param name="y">The y-position of the dropdown menu, relative to the container's upper left corner.</param> /// <returns>The created dropdown menu.</returns> public static GameUISelectableDropdown AddDropdownToComponent(Component parent, string name, List <string> options, float x, float y) { GameUISelectableDropdown dropdown = GameObject.Instantiate(dropdownTemplate, parent.transform); dropdown.name = name; (dropdown.transform as RectTransform).anchorMin = new Vector2(0, 1); (dropdown.transform as RectTransform).anchorMax = new Vector2(0, 1); (dropdown.transform as RectTransform).offsetMin = new Vector2(x, -y - 50); (dropdown.transform as RectTransform).offsetMax = new Vector2(x + 250, -y); dropdown.SetOptions(options); dropdown.SetValue(options[0]); return(dropdown); }
private void MakeRunTypeFilter(float xOffset, float yOffset) { if (runTypeFilter == null) { runTypeFilter = new RunDataFilterRunType(); filterManager.AddFilter(runTypeFilter); } CustomUIManager.AddLabelToComponent(content, "Run Type:", xOffset, yOffset, 240, 50); runTypeFilterDropdown = CustomUIManager.AddDropdownToComponent(content, "RunTypeDropdown", runTypeFilter.options, xOffset + columnWidth, yOffset); runTypeFilterDropdown.optionChosenSignal.AddListener(HandleRunType); runTypeFilterDropdown.SetValue(runTypeFilter.options[runTypeFilter.SelectedRunType]); dropdowns.Add(runTypeFilterDropdown); }
/// <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); } } }
// A lot of methods to initalize filters and UI elements, some very similar code, not gonna comment them all. private void MakeOutcomeFilter(float xOffset, float yOffset) { // If the filter has not yet been created, do so and add it to the filter manager if (outcomeFilter == null) { outcomeFilter = new RunDataFilterOutcome(); filterManager.AddFilter(outcomeFilter); } // UI stuff CustomUIManager.AddLabelToComponent(content, "Run Outcome:", xOffset, yOffset, 240, 50); outcomeFilterDropdown = CustomUIManager.AddDropdownToComponent(content, "OutcomeDropdown", outcomeFilter.options, xOffset + columnWidth, yOffset); outcomeFilterDropdown.optionChosenSignal.AddListener(HandleOutcome); // Manually set the dropdown menu to the current option chosen. There might be a less ugly way to do this. outcomeFilterDropdown.SetValue(outcomeFilter.options[outcomeFilter.Outcome]); dropdowns.Add(outcomeFilterDropdown); }