private void initializeAutoScale() { BaseField field = Fields["AutoScale"]; UI_Toggle tog = (UI_Toggle)field.uiControlEditor; tog.onFieldChanged = autoScaleChanged; }
private void initializeDiameter() { BaseField field = Fields["DiameterMatching"]; UI_Toggle tog = (UI_Toggle)field.uiControlEditor; tog.onFieldChanged = diameterChanged; // Note whether ProceduralParts found enough shapes to enable the setting shapeNameActiveDefault = shapeNameActive; }
public void Start() { heatModule1 = this.GetComponents <ModuleSystemHeat>().ToList().Find(x => x.moduleID == systemHeatModuleID1); heatModule2 = this.GetComponents <ModuleSystemHeat>().ToList().Find(x => x.moduleID == systemHeatModuleID2); UI_Toggle toggle = (HighLogic.LoadedSceneIsEditor) ? (UI_Toggle)Fields[nameof(ToggleSource)].uiControlEditor: (UI_Toggle)Fields[nameof(ToggleSource)].uiControlFlight; if (ToggleSource) { sourceModule = heatModule1; destModule = heatModule2; } else { sourceModule = heatModule2; destModule = heatModule1; } toggle.onFieldChanged = ToggleDirection; toggle.disabledText = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatExchanger_Field_Direction_String", sourceModule.LoopID, destModule.LoopID); toggle.enabledText = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatExchanger_Field_Direction_String", sourceModule.LoopID, destModule.LoopID); if (DirectionLightTransformName != "") { dirLight = part.FindModelTransform(DirectionLightTransformName).GetComponent <Renderer>(); if (ToggleSource) { dirLight.material.SetColor("_TintColor", XKCDColors.BlueGrey); } else { dirLight.material.SetColor("_TintColor", XKCDColors.Orange); } } if (OnLightTransformName != "") { onLight = part.FindModelTransform(OnLightTransformName).GetComponent <Renderer>(); } if (SystemHeatSettings.DebugModules) { Utils.Log("[ModuleSystemHeatSink] Setup completed"); } }
private void ToggleDirection(BaseField field, object oldFieldValueObj) { Utils.Log($"[ModuleSystemHeatExchanger] Toggled direction of flow"); ModuleSystemHeat saved = sourceModule; sourceModule = destModule; destModule = saved; UI_Toggle toggle = (HighLogic.LoadedSceneIsEditor) ? (UI_Toggle)Fields[nameof(ToggleSource)].uiControlEditor : (UI_Toggle)Fields[nameof(ToggleSource)].uiControlFlight; toggle.disabledText = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatExchanger_Field_Direction_String", sourceModule.LoopID, destModule.LoopID); toggle.enabledText = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatExchanger_Field_Direction_String", sourceModule.LoopID, destModule.LoopID); if (ToggleSource) { dirLight.material.SetColor("_TintColor", XKCDColors.BlueGrey); } else { dirLight.material.SetColor("_TintColor", XKCDColors.Orange); } }
public void Start() { if (hasRotatingPivot && savedRotation != Quaternion.identity) { rotationPivot.localRotation = savedRotation; } if (deployState == DeployState.RETRACTED) { Fields["isActive"].guiActive = false; } if (!showWindDirection) { Fields["toggleLines"].guiActive = false; } if (!ConfigSettings.Instance.debug) { Events["ForceWindUpdate"].guiActive = false; } UI_Toggle turbineToggle = (UI_Toggle)Fields["isActive"].uiControlFlight; turbineToggle.requireFullControl = DifficultyGeneral.Instance.requireFullControl; if (HighLogic.LoadedSceneIsFlight) { if (showWindDirection) { windDirectionLine = new Vector3Renderer(part, "windDirection", "Current Wind Direction", ConfigSettings.Instance.windColor); currentOrientationLine = new Vector3Renderer(part, "currentOrientation", "Current Orientation", ConfigSettings.Instance.orientationColor); } onAnimationStart.Add(AnimationStart); onAnimationStop.Add(AnimationStop); } }
public override void OnStart(StartState state) { base.OnStart(state); StatusField.guiActive = guiActive; StatusField.guiActiveEditor = guiActiveEditor; StatusField.guiName = statusLabel; UI_Toggle toggle = StatusField.uiControlEditor as UI_Toggle; if (toggle != null) { toggle.enabledText = statusOn; toggle.disabledText = statusOff; } toggle = StatusField.uiControlFlight as UI_Toggle; if (toggle != null) { toggle.enabledText = statusOn; toggle.disabledText = statusOff; } ToggleAction.guiName = toggleAction; ActivateAction.guiName = activateAction; DeactivateAction.guiName = deactivateAction; }
private void DoToggleDirection() { Utils.Log($"[ModuleSystemHeatExchanger] Toggled direction of flow", LogType.Modules); ModuleSystemHeat saved = sourceModule; sourceModule = destModule; destModule = saved; sourceModule.ignoreTemperature = true; destModule.ignoreTemperature = false; UI_Toggle toggle = (HighLogic.LoadedSceneIsEditor) ? (UI_Toggle)Fields[nameof(ToggleSource)].uiControlEditor : (UI_Toggle)Fields[nameof(ToggleSource)].uiControlFlight; toggle.disabledText = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatExchanger_Field_Direction_String", sourceModule.LoopID, destModule.LoopID); toggle.enabledText = Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatExchanger_Field_Direction_String", sourceModule.LoopID, destModule.LoopID); if (ToggleSource) { dirLight.material.SetColor("_TintColor", XKCDColors.BlueGrey); } else { dirLight.material.SetColor("_TintColor", XKCDColors.Orange); } }
/// <summary> /// For the editor, load the color presets so the player can adjust colors in the VAB. /// </summary> private void SetupChooser() { if (Tweakable) { ConfigNode[] colorPresetNodes = GameDatabase.Instance.GetConfigNodes("AVIATION_LIGHTS_PRESET_COLORS"); List <string> colorNames = new List <string>(); presetColorValues = new List <Vector3>(); for (int presetNode = 0; presetNode < colorPresetNodes.Length; ++presetNode) { ConfigNode[] colors = colorPresetNodes[presetNode].GetNodes("Color"); for (int colorIndex = 0; colorIndex < colors.Length; ++colorIndex) { string guiName = string.Empty; Vector3 value = new Vector3(0.0f, 0.0f, 0.0f); if (colors[colorIndex].TryGetValue("guiName", ref guiName) && colors[colorIndex].TryGetValue("value", ref value)) { if (colorNames.Contains(guiName) == false) { colorNames.Add(guiName); value.x = Mathf.Clamp01(value.x); value.y = Mathf.Clamp01(value.y); value.z = Mathf.Clamp01(value.z); presetColorValues.Add(value); } } } } BaseField chooseField = Fields["colorPreset"]; if (colorNames.Count > 0) { UI_ChooseOption chooseOption = (UI_ChooseOption)chooseField.uiControlEditor; chooseOption.options = colorNames.ToArray(); chooseOption.onFieldChanged = ColorPresetChanged; } else { // No colors? No preset slider. chooseField.guiActiveEditor = false; } ConfigNode[] typePresetNodes = GameDatabase.Instance.GetConfigNodes("AVIATION_LIGHTS_PRESET_TYPES"); List <string> presetNames = new List <string>(); presetTypes = new List <TypePreset>(); for (int presetNode = 0; presetNode < typePresetNodes.Length; ++presetNode) { ConfigNode[] types = typePresetNodes[presetNode].GetNodes("Type"); for (int typeIndex = 0; typeIndex < types.Length; ++typeIndex) { string guiName = string.Empty; float flashOn = 0.0f, flashOff = 0.0f, interval = 0.0f, intensity = 0.0f, range = 0.0f; if (types[typeIndex].TryGetValue("guiName", ref guiName) && types[typeIndex].TryGetValue("flashOn", ref flashOn) && types[typeIndex].TryGetValue("flashOff", ref flashOff) && types[typeIndex].TryGetValue("interval", ref interval) && types[typeIndex].TryGetValue("intensity", ref intensity) && types[typeIndex].TryGetValue("range", ref range)) { if (presetNames.Contains(guiName) == false) { presetNames.Add(guiName); TypePreset type = new TypePreset(); type.flashOn = Mathf.Max(flashOn, 0.0f); type.flashOff = Mathf.Max(flashOff, 0.0f); type.interval = Mathf.Max(interval, 0.0f); type.intensity = Mathf.Clamp(intensity, 0.0f, 8.0f); type.range = Mathf.Max(range, 0.0f); presetTypes.Add(type); } } } } chooseField = Fields["typePreset"]; if (presetNames.Count > 0) { UI_ChooseOption chooseOption = (UI_ChooseOption)chooseField.uiControlEditor; chooseOption.options = presetNames.ToArray(); chooseOption.onFieldChanged = TypePresetChanged; } else { // No types? No preset slider. chooseField.guiActiveEditor = false; } chooseField = Fields["Intensity"]; UI_FloatRange floatRange = (UI_FloatRange)chooseField.uiControlEditor; floatRange.onFieldChanged = ValueChanged; chooseField = Fields["Range"]; floatRange = (UI_FloatRange)chooseField.uiControlEditor; floatRange.onFieldChanged = ValueChanged; chooseField = Fields["lightR"]; floatRange = (UI_FloatRange)chooseField.uiControlEditor; floatRange.onFieldChanged = ValueChanged; chooseField = Fields["lightG"]; floatRange = (UI_FloatRange)chooseField.uiControlEditor; floatRange.onFieldChanged = ValueChanged; chooseField = Fields["lightB"]; floatRange = (UI_FloatRange)chooseField.uiControlEditor; floatRange.onFieldChanged = ValueChanged; chooseField = Fields["spotLight"]; chooseField.guiActiveEditor = (SpotAngle > 0.0f); UI_Toggle toggle = (UI_Toggle)chooseField.uiControlEditor; toggle.onFieldChanged = ValueChanged; } else { // The module is configured as non-Tweakable. Remove the config options from the editor. Fields["colorPreset"].guiActiveEditor = false; Fields["typePreset"].guiActiveEditor = false; Fields["Intensity"].guiActiveEditor = false; Fields["Range"].guiActiveEditor = false; Fields["lightR"].guiActiveEditor = false; Fields["lightG"].guiActiveEditor = false; Fields["lightB"].guiActiveEditor = false; } }
public override void OnStart(StartState state) { base.OnStart(state); UI_FloatRange motorLimitField = (UI_FloatRange)(HighLogic.LoadedSceneIsEditor ? Fields[nameof(motorOutput)].uiControlEditor : Fields[nameof(motorOutput)].uiControlFlight); motorLimitField.onFieldChanged = (a, b) => { this.symmetryUpdate(m => { m.motorOutput = motorOutput; int len = m.motorModules.Length; for (int i = 0; i < len; i++) { m.motorModules[i].motorOutput = motorOutput; } }); }; UI_Toggle invertMotorField = (UI_Toggle)(HighLogic.LoadedSceneIsEditor ? Fields[nameof(invertMotor)].uiControlEditor : Fields[nameof(invertMotor)].uiControlFlight); invertMotorField.onFieldChanged = (a, b) => { this.symmetryUpdate(m => { m.invertMotor = invertMotor; int len = m.motorModules.Length; for (int i = 0; i < len; i++) { m.motorModules[i].invertMotor = !m.motorModules[i].invertMotor; } }); }; UI_Toggle motorLockedField = (UI_Toggle)(HighLogic.LoadedSceneIsEditor ? Fields[nameof(motorLocked)].uiControlEditor : Fields[nameof(motorLocked)].uiControlFlight); motorLockedField.onFieldChanged = (a, b) => { this.symmetryUpdate(m => { m.motorLocked = motorLocked; int len = m.motorModules.Length; for (int i = 0; i < len; i++) { m.motorModules[i].motorLocked = !m.motorModules[i].motorLocked; } m.updatePowerStats(); }); }; UI_Toggle invertSteeringField = (UI_Toggle)(HighLogic.LoadedSceneIsEditor ? Fields[nameof(invertSteering)].uiControlEditor : Fields[nameof(invertSteering)].uiControlFlight); invertSteeringField.onFieldChanged = (a, b) => { this.symmetryUpdate(m => { m.invertSteering = invertSteering; int len = m.motorModules.Length; for (int i = 0; i < len; i++) { m.motorModules[i].invertSteering = !m.motorModules[i].invertSteering; } }); }; UI_Toggle steeringLockedField = (UI_Toggle)(HighLogic.LoadedSceneIsEditor ? Fields[nameof(steeringLocked)].uiControlEditor : Fields[nameof(steeringLocked)].uiControlFlight); steeringLockedField.onFieldChanged = (a, b) => { this.symmetryUpdate(m => { m.steeringLocked = steeringLocked; int len = m.motorModules.Length; for (int i = 0; i < len; i++) { m.motorModules[i].steeringLocked = !m.motorModules[i].steeringLocked; } }); }; UI_Toggle halfTrackSteeringField = (UI_Toggle)(HighLogic.LoadedSceneIsEditor ? Fields[nameof(halfTrackSteering)].uiControlEditor : Fields[nameof(halfTrackSteering)].uiControlFlight); halfTrackSteeringField.onFieldChanged = (a, b) => { this.symmetryUpdate(m => { m.halfTrackSteering = halfTrackSteering; int len = m.motorModules.Length; for (int i = 0; i < len; i++) { m.motorModules[i].halfTrackSteering = !m.motorModules[i].halfTrackSteering; } }); }; UI_FloatEdit gearRatioField = (UI_FloatEdit)(HighLogic.LoadedSceneIsEditor ? Fields[nameof(gearRatio)].uiControlEditor : Fields[nameof(gearRatio)].uiControlFlight); gearRatioField.minValue = minGearRatio; gearRatioField.maxValue = maxGearRatio; gearRatioField.onFieldChanged = (a, b) => { this.symmetryUpdate(m => { m.gearRatio = gearRatio; int len = m.motorModules.Length; for (int i = 0; i < len; i++) { m.motorModules[i].gearRatio = m.gearRatio; m.motorModules[i].calcPowerStats(); } m.updatePowerStats(); }); }; }