public static void ROLupdateUIFloatRangeControl(this PartModule module, string fieldName, float min, float max, float inc, bool forceUpdate) { UI_FloatRange widget = null; if (HighLogic.LoadedSceneIsEditor) { widget = (UI_FloatRange)module.Fields[fieldName].uiControlEditor; } else if (HighLogic.LoadedSceneIsFlight) { widget = (UI_FloatRange)module.Fields[fieldName].uiControlFlight; } else { return; } if (widget == null) { return; } widget.minValue = min; widget.maxValue = max; widget.stepIncrement = inc; if (forceUpdate && widget.partActionItem != null) { UIPartActionFloatRange ctr = (UIPartActionFloatRange)widget.partActionItem; var t = widget.onFieldChanged; // temporarily remove the callback widget.onFieldChanged = null; ctr.slider.onValueChanged.RemoveAllListeners(); ctr.inputField.onValueChanged.RemoveAllListeners(); ctr.Setup(ctr.Window, module.part, module, HighLogic.LoadedSceneIsEditor ? UI_Scene.Editor : UI_Scene.Flight, widget, module.Fields[fieldName]); widget.onFieldChanged = t; // re-seat callback } }
public static UIPartActionScaleEdit CreateTemplate() { // Create the control GameObject editGo = new GameObject("UIPartActionScaleEdit", SystemUtils.VersionTaggedType(typeof(UIPartActionScaleEdit))); UIPartActionScaleEdit edit = editGo.GetTaggedComponent <UIPartActionScaleEdit>(); editGo.SetActive(false); // TODO: since I don'type have access to EZE GUI, I'm copying out bits from other existing GUIs // if someone does have access, they could do this better although really it works pretty well. UIPartActionButton evtp = UIPartActionController.Instance.eventItemPrefab; GameObject srcTextGo = evtp.transform.Find("Text").gameObject; GameObject srcBackgroundGo = evtp.transform.Find("Background").gameObject; GameObject srcButtonGo = evtp.transform.Find("Btn").gameObject; UIPartActionFloatRange paFlt = (UIPartActionFloatRange)UIPartActionController.Instance.fieldPrefabs.Find(cls => cls.GetType() == typeof(UIPartActionFloatRange)); GameObject srcSliderGo = paFlt.transform.Find("Slider").gameObject; // Start building our control GameObject backgroundGo = (GameObject)Instantiate(srcBackgroundGo); backgroundGo.transform.parent = editGo.transform; GameObject sliderGo = (GameObject)Instantiate(srcSliderGo); sliderGo.transform.parent = editGo.transform; sliderGo.transform.localScale = new Vector3(0.65f, 1, 1); edit.slider = sliderGo.GetComponent <UIProgressSlider>(); edit.slider.ignoreDefault = true; GameObject fieldNameGo = (GameObject)Instantiate(srcTextGo); fieldNameGo.transform.parent = editGo.transform; fieldNameGo.transform.localPosition = new Vector3(40, -8, 0); edit.fieldName = fieldNameGo.GetComponent <SpriteText>(); GameObject fieldValueGo = (GameObject)Instantiate(srcTextGo); fieldValueGo.transform.parent = editGo.transform; fieldValueGo.transform.localPosition = new Vector3(110, -8, 0); edit.fieldValue = fieldValueGo.GetComponent <SpriteText>(); GameObject incLargeDownGo = (GameObject)Instantiate(srcButtonGo); incLargeDownGo.transform.parent = edit.transform; incLargeDownGo.transform.localScale = new Vector3(0.45f, 1.1f, 1f); incLargeDownGo.transform.localPosition = new Vector3(11.5f, -9, 0); //>11 edit.incLargeDown = incLargeDownGo.GetComponent <UIButton>(); GameObject incLargeDownLabelGo = (GameObject)Instantiate(srcTextGo); incLargeDownLabelGo.transform.parent = editGo.transform; incLargeDownLabelGo.transform.localPosition = new Vector3(5.5f, -7, 0); // <6 edit.incLargeDownLabel = incLargeDownLabelGo.GetComponent <SpriteText>(); edit.incLargeDownLabel.Text = "<<"; GameObject incLargeUpGo = (GameObject)Instantiate(srcButtonGo); incLargeUpGo.transform.parent = edit.transform; incLargeUpGo.transform.localScale = new Vector3(0.45f, 1.1f, 1f); incLargeUpGo.transform.localPosition = new Vector3(187.5f, -9, 0); // >187 edit.incLargeUp = incLargeUpGo.GetComponent <UIButton>(); GameObject incLargeUpLabelGo = (GameObject)Instantiate(srcTextGo); incLargeUpLabelGo.transform.parent = editGo.transform; incLargeUpLabelGo.transform.localPosition = new Vector3(181.5f, -7, 0); //<182 edit.incLargeUpLabel = incLargeUpLabelGo.GetComponent <SpriteText>(); edit.incLargeUpLabel.Text = ">>"; return(edit); }