public static void updateUIChooseOptionControl(this PartModule module, string fieldName, string[] options, string[] display, bool forceUpdate, string forceVal = "") { if (display.Length == 0 && options.Length > 0) { display = new string[] { "NONE" }; } if (options.Length == 0) { options = new string[] { "NONE" }; } UI_ChooseOption widget = null; if (HighLogic.LoadedSceneIsEditor) { widget = (UI_ChooseOption)module.Fields[fieldName].uiControlEditor; } else if (HighLogic.LoadedSceneIsFlight) { widget = (UI_ChooseOption)module.Fields[fieldName].uiControlFlight; } else { return; } if (widget == null) { return; } widget.display = display; widget.options = options; if (forceUpdate && widget.partActionItem != null) { UIPartActionChooseOption control = (UIPartActionChooseOption)widget.partActionItem; var t = widget.onFieldChanged; widget.onFieldChanged = null; int index = Array.IndexOf(options, forceVal); control.slider.minValue = 0; control.slider.maxValue = options.Length - 1; control.slider.value = index; control.OnValueChanged(0); widget.onFieldChanged = t; } }
public static void UpdateUIChooseOption(this PartModule module, string fieldName, string[] options, string[] display, bool forceUpdate, string forceVal = "") { if (!HighLogic.LoadedSceneIsEditor) { return; } if (display.Length == 0 || options.Length == 0 || display.Length != options.Length) { return; } UI_ChooseOption control = (UI_ChooseOption)module.Fields[fieldName].uiControlEditor; if (control == null) { return; } module.Fields[fieldName].guiActiveEditor = options.Length > 1; control.display = display; control.options = options; if (forceUpdate && control.partActionItem != null) { UIPartActionChooseOption pai = (UIPartActionChooseOption)control.partActionItem; var t = control.onFieldChanged; control.onFieldChanged = null; int index = Array.IndexOf(options, forceVal); pai.slider.minValue = 0; pai.slider.maxValue = options.Length - 1; pai.slider.value = index; pai.OnValueChanged(index); control.onFieldChanged = t; } }