public IModConfigMenu GetModMenu(IModBehaviour modBehaviour) { OwmlConsole.WriteLine("Registering " + modBehaviour.ModHelper.Manifest.UniqueName); var modConfigMenu = _modConfigMenus.FirstOrDefault(x => x.Mod == modBehaviour); if (modConfigMenu == null) { OwmlConsole.WriteLine($"Error: {modBehaviour.ModHelper.Manifest.UniqueName} isn't added."); return(null); } return(modConfigMenu); }
protected void AddConfigInput(string key, object value, int index) { if (value is bool) { AddToggleInput(key, index); return; } if (value is string) { AddTextInput(key, index); return; } if (new[] { typeof(long), typeof(int), typeof(float), typeof(double) }.Contains(value.GetType())) { AddNumberInput(key, index); return; } if (value is JObject obj) { var type = (string)obj["type"]; if (type == "slider") { AddSliderInput(key, obj, index); return; } if (type == "toggle") { AddToggleInput(key, obj, index); return; } if (type == "input") { AddComboInput(key, index); return; } OwmlConsole.WriteLine("Error: unrecognized complex setting: " + value); return; } OwmlConsole.WriteLine("Error: unrecognized setting type: " + value.GetType()); }
public void Initialize(PopupInputMenu menu) { if (Menu != null) { return; } var parentCopy = Object.Instantiate(menu.transform.parent.gameObject); parentCopy.AddComponent <DontDestroyOnLoad>(); _twoButtonPopup = parentCopy.transform.Find("TwoButton-Popup")?.GetComponent <PopupMenu>(); if (_twoButtonPopup == null) { Console.WriteLine("Error: Failed to setup warning popup"); } var originalMenu = parentCopy.transform.GetComponentInChildren <PopupInputMenu>(true); // InputField-Popup var menuTransform = originalMenu.GetComponentInChildren <VerticalLayoutGroup>(true).transform; // InputFieldElements var buttonsTransform = menuTransform.GetComponentInChildren <HorizontalLayoutGroup>(true).transform; var buttons = buttonsTransform.GetComponentsInChildren <Button>(true).ToList(); buttons.ForEach(button => button.navigation = new Navigation { mode = Navigation.Mode.None }); var tabbedNavigations = menuTransform.GetComponentsInChildren <TabbedNavigation>(true).ToList(); tabbedNavigations.ForEach(Object.Destroy); var resetButtonObject = CreateResetButton(buttonsTransform); ModLayoutManager layout = null; var inputObject = menuTransform.GetComponentInChildren <InputField>(true).gameObject; // InputField Object.Destroy(inputObject.GetComponent <InputField>()); foreach (Transform child in inputObject.transform) { if (child.name == "BorderImage") { layout = CreateLayoutManager(child.gameObject, resetButtonObject.transform); } else { Object.Destroy(child.gameObject); } } if (layout == null) { OwmlConsole.WriteLine("Error: failed to create combination visualizer in combination editor"); return; } var inputSelectable = inputObject.AddComponent <Selectable>(); _inputMenu = originalMenu.gameObject.AddComponent <ModInputCombinationPopup>(); var submitAction = resetButtonObject.GetComponent <SubmitAction>(); var imageElement = resetButtonObject.GetComponent <ButtonWithHotkeyImageElement>(); _inputMenu.Initialize(originalMenu, inputSelectable, submitAction, imageElement, layout, _inputHandler); Object.Destroy(originalMenu); Object.Destroy(_inputMenu.GetValue <Text>("_labelText").GetComponent <LocalizedText>()); Initialize(_inputMenu); }