public override void UpdateTechConstraints() { Fields[nameof(length)].guiActiveEditor = PPart.lengthMin != PPart.lengthMax; UI_FloatEdit lengthEdit = Fields[nameof(length)].uiControlEditor as UI_FloatEdit; lengthEdit.maxValue = PPart.lengthMax; lengthEdit.minValue = PPart.lengthMin; lengthEdit.incrementLarge = PPart.lengthLargeStep; lengthEdit.incrementSmall = PPart.lengthSmallStep; length = Mathf.Clamp(length, PPart.lengthMin, PPart.lengthMax); Fields[nameof(diameter)].guiActiveEditor = PPart.diameterMin != PPart.diameterMax; UI_FloatEdit diameterEdit = Fields[nameof(diameter)].uiControlEditor as UI_FloatEdit; diameterEdit.maxValue = PPart.diameterMax; diameterEdit.minValue = PPart.diameterMin; diameterEdit.incrementLarge = PPart.diameterLargeStep; diameterEdit.incrementSmall = PPart.diameterSmallStep; diameter = Mathf.Clamp(diameter, PPart.diameterMin, PPart.diameterMax); Fields[nameof(fillet)].guiActiveEditor = PPart.allowCurveTweaking; UI_FloatEdit filletEdit = Fields[nameof(fillet)].uiControlEditor as UI_FloatEdit; filletEdit.maxValue = Mathf.Min(length, diameter); filletEdit.minValue = 0; filletEdit.incrementLarge = PPart.diameterLargeStep; filletEdit.incrementSmall = PPart.diameterSmallStep; fillet = Mathf.Clamp(fillet, filletEdit.minValue, filletEdit.maxValue); }
private void UpdateMaxValues() { // update mass limit value slider if (proceduralMassLimitEdit == null) { proceduralMassLimitEdit = (UI_FloatEdit)Fields["proceduralMassLimit"].uiControlEditor; } if (CurrentProceduralAvionicsConfig != null && CurrentProceduralAvionicsTechNode != null) { tonnageToMassRatio = CurrentProceduralAvionicsTechNode.tonnageToMassRatio; proceduralMassLimitEdit.maxValue = CeilingToSmallIncrement(GetMaximumControllableTonnage()); proceduralMassLimitEdit.minValue = 0; var procMassDelta = proceduralMassLimitEdit.maxValue - proceduralMassLimitEdit.minValue; proceduralMassLimitEdit.incrementSmall = GetSmallIncrement(procMassDelta); proceduralMassLimitEdit.incrementLarge = proceduralMassLimitEdit.incrementSmall * 10; proceduralMassLimitEdit.incrementSlide = GetSliderIncrement(procMassDelta); proceduralMassLimitEdit.sigFigs = GetSigFigs(procMassDelta); } else { Log("Cannot update max value yet, CurrentProceduralAvionicsConfig is null"); proceduralMassLimitEdit.maxValue = float.MaxValue; proceduralMassLimitEdit.minValue = 0; } }
private void UpdateMaxValues() { //update mass limit value slider if (proceduralMassLimitEdit == null) { proceduralMassLimitEdit = (UI_FloatEdit)Fields["proceduralMassLimit"].uiControlEditor; } if (needsTechInit) { InitializeTechLimits(); UpdateConfigSliders(); } if (CurrentProceduralAvionicsConfig != null) { tonnageToMassRatio = CurrentProceduralAvionicsTechNode.tonnageToMassRatio; proceduralMassLimitEdit.maxValue = GetMaximumControllableTonnage(); proceduralMassLimitEdit.minValue = GetMinimumControllableTonnage(); } else { Log("Cannot update max value yet"); proceduralMassLimitEdit.maxValue = float.MaxValue; proceduralMassLimitEdit.minValue = 0; } if (proceduralMassLimit > proceduralMassLimitEdit.maxValue) { Log("Lowering procedural mass limit to new max value of " + proceduralMassLimitEdit.maxValue); proceduralMassLimit = proceduralMassLimitEdit.maxValue; // Don't know how to force the gui to refresh this } }
public override void UpdateTechConstraints() { Fields[nameof(innerDiameter)].guiActiveEditor = PPart.diameterMin != PPart.diameterMax; UI_FloatEdit innerDiameterEdit = Fields[nameof(innerDiameter)].uiControlEditor as UI_FloatEdit; innerDiameterEdit.incrementLarge = PPart.diameterLargeStep; innerDiameterEdit.incrementSmall = PPart.diameterSmallStep; Fields[nameof(outerDiameter)].guiActiveEditor = PPart.diameterMin != PPart.diameterMax; UI_FloatEdit outerDiameterEdit = Fields[nameof(outerDiameter)].uiControlEditor as UI_FloatEdit; outerDiameterEdit.incrementLarge = PPart.diameterLargeStep; outerDiameterEdit.incrementSmall = PPart.diameterSmallStep; Fields[nameof(length)].guiActiveEditor = PPart.lengthMin != PPart.lengthMax; UI_FloatEdit lengthEdit = Fields[nameof(length)].uiControlEditor as UI_FloatEdit; lengthEdit.incrementLarge = PPart.lengthLargeStep; lengthEdit.incrementSmall = PPart.lengthSmallStep; AdjustDimensionBounds(); innerDiameter = Mathf.Clamp(innerDiameter, innerDiameterEdit.minValue, innerDiameterEdit.maxValue); outerDiameter = Mathf.Clamp(outerDiameter, outerDiameterEdit.minValue, outerDiameterEdit.maxValue); length = Mathf.Clamp(length, lengthEdit.minValue, lengthEdit.maxValue); }
public override void OnStart(StartState state) { if (!FindDecoupler()) { Debug.LogError("Unable to find any decoupler modules"); isEnabled = enabled = false; return; } if (HighLogic.LoadedSceneIsEditor) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (mass != 0) { UpdateMass(mass); } Fields["isOmniDecoupler"].guiActiveEditor = string.IsNullOrEmpty(separatorTechRequired) || ResearchAndDevelopment.GetTechnologyState(separatorTechRequired) == RDTech.State.Available; // ReSharper disable once CompareOfFloatsByEqualityOperator if (ejectionImpulse == 0) { ejectionImpulse = (float)Math.Round(decouple.ejectionForce * ImpulsePerForceUnit, 1); } UI_FloatEdit ejectionImpulseEdit = (UI_FloatEdit)Fields["ejectionImpulse"].uiControlEditor; ejectionImpulseEdit.maxValue = maxImpulse; } else if (HighLogic.LoadedSceneIsFlight) { decouple.isOmniDecoupler = isOmniDecoupler; } }
public override void OnStart(StartState state) { if (!HighLogic.LoadedSceneIsEditor) { return; } if (pPart.lengthMin == pPart.lengthMax) { Fields["length"].guiActiveEditor = false; } else { UI_FloatEdit lengthEdit = (UI_FloatEdit)Fields["length"].uiControlEditor; lengthEdit.maxValue = pPart.lengthMax; lengthEdit.minValue = pPart.lengthMin; lengthEdit.incrementLarge = pPart.lengthLargeStep; lengthEdit.incrementSmall = pPart.lengthSmallStep; } if (pPart.diameterMin == pPart.diameterMax) { Fields["diameter"].guiActiveEditor = false; } else { UI_FloatEdit diameterEdit = (UI_FloatEdit)Fields["diameter"].uiControlEditor; diameterEdit.maxValue = pPart.diameterMax; diameterEdit.minValue = pPart.diameterMin; diameterEdit.incrementLarge = pPart.diameterLargeStep; diameterEdit.incrementSmall = pPart.diameterSmallStep; } }
public override void OnStart(StartState state) { base.OnStart(state); if (PPart is null) { Debug.LogError($"{ModTag} {part}.{this} Procedural Part not found"); return; } bottomNode = part.FindAttachNode(bottomNodeId); topNode = part.FindAttachNode(topNodeId); CopyNodeSizeAndStrength(); if (HighLogic.LoadedSceneIsEditor) { if (PPart?.CurrentShape is ProceduralShapeBezierCone cone) { cone.Fields[nameof(cone.topDiameter)].uiControlEditor.onFieldChanged += FairingThicknessChanged; cone.Fields[nameof(cone.bottomDiameter)].uiControlEditor.onFieldChanged += FairingThicknessChanged; cone.Fields[nameof(cone.length)].uiControlEditor.onFieldChanged += FairingThicknessChanged; } UI_FloatEdit fairingThicknessEdit = Fields[nameof(fairingThickness)].uiControlEditor as UI_FloatEdit; fairingThicknessEdit.maxValue = this.fairingMaxThickness; fairingThicknessEdit.minValue = this.fairingMinThickness; fairingThicknessEdit.onFieldChanged = new Callback <BaseField, object>(FairingThicknessChanged); fairingThickness = Mathf.Clamp(fairingThickness, fairingMinThickness, fairingMaxThickness); } UpdateFairing(); InitializeTexture(); }
public override void OnStart(StartState state) { // ReSharper disable CompareOfFloatsByEqualityOperator if (!HighLogic.LoadedSceneIsEditor) { return; } if (PPart.lengthMin == PPart.lengthMax) { Fields["length"].guiActiveEditor = false; } else { UI_FloatEdit lengthEdit = (UI_FloatEdit)Fields["length"].uiControlEditor; lengthEdit.maxValue = PPart.lengthMax; lengthEdit.minValue = PPart.lengthMin; lengthEdit.incrementLarge = PPart.lengthLargeStep; lengthEdit.incrementSmall = PPart.lengthSmallStep; } if (PPart.diameterMin == PPart.diameterMax) { Fields["diameter"].guiActiveEditor = false; } else { UI_FloatEdit diameterEdit = (UI_FloatEdit)Fields["diameter"].uiControlEditor; diameterEdit.maxValue = PPart.diameterMax; diameterEdit.minValue = PPart.diameterMin; diameterEdit.incrementLarge = PPart.diameterLargeStep; diameterEdit.incrementSmall = PPart.diameterSmallStep; } // ReSharper restore CompareOfFloatsByEqualityOperator }
public override void OnStart(StartState state) { if (!HighLogic.LoadedSceneIsEditor) { return; } // ReSharper disable CompareOfFloatsByEqualityOperator if (PPart.lengthMin == PPart.lengthMax || PPart.aspectMin == PPart.aspectMax) { Fields["length"].guiActiveEditor = false; } else { UI_FloatEdit lengthEdit = (UI_FloatEdit)Fields["length"].uiControlEditor; lengthEdit.maxValue = PPart.lengthMax; lengthEdit.minValue = PPart.lengthMin; lengthEdit.incrementLarge = PPart.lengthLargeStep; lengthEdit.incrementSmall = PPart.lengthSmallStep; } if (PPart.diameterMin == PPart.diameterMax || (coneTopMode == ConeEndMode.Constant && coneBottomMode == ConeEndMode.Constant)) { Fields["topDiameter"].guiActiveEditor = false; Fields["bottomDiameter"].guiActiveEditor = false; return; } // ReSharper restore CompareOfFloatsByEqualityOperator if (coneTopMode == ConeEndMode.Constant) { // Top diameter is constant Fields["topDiameter"].guiActiveEditor = false; Fields["bottomDiameter"].guiName = "Diameter"; } else { UI_FloatEdit topDiameterEdit = (UI_FloatEdit)Fields["topDiameter"].uiControlEditor; topDiameterEdit.incrementLarge = PPart.diameterLargeStep; topDiameterEdit.incrementSmall = PPart.diameterSmallStep; topDiameterEdit.maxValue = PPart.diameterMax; topDiameterEdit.minValue = (coneTopMode == ConeEndMode.CanZero && coneBottomMode != ConeEndMode.Constant) ? 0 : PPart.diameterMin; } if (coneBottomMode == ConeEndMode.Constant) { // Bottom diameter is constant Fields["bottomDiameter"].guiActiveEditor = false; Fields["topDiameter"].guiName = "Diameter"; } else { UI_FloatEdit bottomDiameterEdit = (UI_FloatEdit)Fields["bottomDiameter"].uiControlEditor; bottomDiameterEdit.incrementLarge = PPart.diameterLargeStep; bottomDiameterEdit.incrementSmall = PPart.diameterSmallStep; bottomDiameterEdit.maxValue = PPart.diameterMax; bottomDiameterEdit.minValue = (coneBottomMode == ConeEndMode.CanZero && coneTopMode != ConeEndMode.Constant) ? 0 : PPart.diameterMin; } }
public override void OnStart(StartState state) { if (HighLogic.LoadedSceneIsFlight) { if (mass <= 0) { mass = 0.000001f; } part.mass = mass; MassChanged(mass); //Debug.Log("OnStart - mass: " + part.mass); //double skinThermalMassModifier = part.thermalMassModifier; //double skinThicknessFactor = 0.1; //Debug.Log(skinThermalMassModifier); //Debug.LogWarning((double)part.mass * PhysicsGlobals.StandardSpecificHeatCapacity * skinThermalMassModifier * skinThicknessFactor); } InitializeObjects(); CopyNodeSizeAndStrength(); //if (HighLogic.LoadedSceneIsFlight) //{ // PartResource resource = part.Resources["AblativeShielding"]; // UpdateDissipationAndLoss(resource.maxAmount); //} if (PPart != null) { //PPart.AddNodeOffset(topNodeId, GetNodeOffset); loadedTextureSets = PPart.TextureSets.ToList(); loadedTextureSetNames = loadedTextureSets.Select <ProceduralPart.TextureSet, string>(x => x.name).ToArray(); BaseField field = Fields["textureSet"]; UI_ChooseOption range = (UI_ChooseOption)field.uiControlEditor; range.options = loadedTextureSetNames; if (textureSet == null || !loadedTextureSetNames.Contains(textureSet)) { textureSet = loadedTextureSetNames[0]; } UpdateTexture(); UpdateFairing(); } else { Debug.LogError("Procedural Part not found"); } UI_FloatEdit fairingThicknessEdit = (UI_FloatEdit)Fields["fairingThickness"].uiControlEditor; fairingThicknessEdit.maxValue = this.fairingMaxThickness; fairingThicknessEdit.minValue = this.fairingMinThickness; fairingThicknessEdit.incrementLarge = 0.1f; fairingThicknessEdit.incrementSmall = 0.01f; fairingThickness = Mathf.Clamp(fairingThickness, fairingMinThickness, fairingMaxThickness); }
public override void OnStart(StartState state) { if (!HighLogic.LoadedSceneIsEditor) { return; } if (pPart.lengthMin == pPart.lengthMax) { Fields["length"].guiActiveEditor = false; } else { UI_FloatEdit lengthEdit = (UI_FloatEdit)Fields["length"].uiControlEditor; lengthEdit.maxValue = pPart.lengthMax; lengthEdit.minValue = pPart.lengthMin; lengthEdit.incrementLarge = pPart.lengthLargeStep; lengthEdit.incrementSmall = pPart.lengthSmallStep; } if (pPart.diameterMin == pPart.diameterMax || (coneTopMode == ConeEndMode.Constant && coneBottomMode == ConeEndMode.Constant)) { Fields["topDiameter"].guiActiveEditor = false; Fields["bottomDiameter"].guiActiveEditor = false; return; } if (coneTopMode == ConeEndMode.Constant) { // Top diameter is constant Fields["topDiameter"].guiActiveEditor = false; Fields["bottomDiameter"].guiName = "Diameter"; } else { UI_FloatEdit topDiameterEdit = (UI_FloatEdit)Fields["topDiameter"].uiControlEditor; topDiameterEdit.incrementLarge = pPart.diameterLargeStep; topDiameterEdit.incrementSmall = pPart.diameterSmallStep; topDiameterEdit.maxValue = pPart.diameterMax; topDiameterEdit.minValue = (coneTopMode == ConeEndMode.CanZero) ? 0 : pPart.diameterMin; } if (coneBottomMode == ConeEndMode.Constant) { // Bottom diameter is constant Fields["bottomDiameter"].guiActiveEditor = false; Fields["topDiameter"].guiName = "Diameter"; } else { UI_FloatEdit bottomDiameterEdit = (UI_FloatEdit)Fields["bottomDiameter"].uiControlEditor; bottomDiameterEdit.incrementLarge = pPart.diameterLargeStep; bottomDiameterEdit.incrementSmall = pPart.diameterSmallStep; bottomDiameterEdit.maxValue = pPart.diameterMax; bottomDiameterEdit.minValue = (coneBottomMode == ConeEndMode.CanZero) ? 0 : pPart.diameterMin; } }
public override void OnStart(StartState state) { base.OnStart(state); init(); Fields[nameof(displayGravity)].guiActive = Fields[nameof(displayGravity)].guiActiveEditor = showGravityDisplay; UI_FloatEdit ufe = (UI_FloatEdit)(HighLogic.LoadedSceneIsEditor? Fields[nameof(rpm)].uiControlEditor : Fields[nameof(rpm)].uiControlFlight); ufe.minValue = minRPM; ufe.maxValue = maxRPM; }
public override void OnStart(StartState state) { base.OnStart(state); initialize(); Fields[nameof(currentModel)].guiName = uiLabel; Fields[nameof(currentModel)].uiControlEditor.onFieldChanged = delegate(BaseField a, System.Object b) { models.modelSelected(a, b); this.actionWithSymmetry(m => { m.models.setScale(currentScale); m.models.updateModelMeshes(); m.models.updateSelections(); m.updateMassAndCost(); m.updateAttachNodes(true); SSTUModInterop.updateResourceVolume(m.part); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentScale)].guiActiveEditor = canAdjustScale; UI_FloatEdit fe = (UI_FloatEdit)Fields[nameof(currentScale)].uiControlEditor; if (fe != null) { fe.minValue = minScale; fe.maxValue = maxScale; fe.incrementLarge = incScaleLarge; fe.incrementSmall = incScaleSmall; fe.incrementSlide = incScaleSlide; } Fields[nameof(currentScale)].uiControlEditor.onFieldChanged = delegate(BaseField a, System.Object b) { this.actionWithSymmetry(m => { m.models.setScale(currentScale); m.models.updateModelMeshes(); m.updateMassAndCost(); m.updateAttachNodes(true); SSTUModInterop.updateResourceVolume(m.part); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentTexture)].uiControlEditor.onFieldChanged = delegate(BaseField a, System.Object b) { models.textureSetSelected(a, b); }; Fields[nameof(currentTexture)].guiActiveEditor = models.definition.textureSets.Length > 1; SSTUStockInterop.fireEditorUpdate(); SSTUModInterop.onPartGeometryUpdate(part, true); }
public void OnShapeSelectionChanged(BaseField f, object obj) { if (CalculateVolume() > PPart.volumeMax) { UI_FloatEdit edt = Fields[nameof(length)].uiControlEditor as UI_FloatEdit; length = edt.minValue; AdjustDimensionBounds(); length = Mathf.Max(length, edt.maxValue); } OnShapeDimensionChanged(f, obj); MonoUtilities.RefreshPartContextWindow(part); }
public override void UpdateTechConstraints() { if (!HighLogic.LoadedSceneIsEditor) { return; } // ReSharper disable CompareOfFloatsByEqualityOperator if (PPart.lengthMin == PPart.lengthMax) { Fields["length"].guiActiveEditor = false; } else { UI_FloatEdit lengthEdit = (UI_FloatEdit)Fields["length"].uiControlEditor; lengthEdit.maxValue = PPart.lengthMax; lengthEdit.minValue = PPart.lengthMin; lengthEdit.incrementLarge = PPart.lengthLargeStep; lengthEdit.incrementSmall = PPart.lengthSmallStep; length = Mathf.Clamp(length, PPart.lengthMin, PPart.lengthMax); } UI_FloatEdit diameterEdit = (UI_FloatEdit)Fields["diameter"].uiControlEditor; if (PPart.diameterMin == PPart.diameterMax) { Fields["diameter"].guiActiveEditor = false; } else { diameterEdit.maxValue = PPart.diameterMax; diameterEdit.minValue = PPart.diameterMin; diameterEdit.incrementLarge = PPart.diameterLargeStep; diameterEdit.incrementSmall = PPart.diameterSmallStep; diameter = Mathf.Clamp(diameter, PPart.diameterMin, PPart.diameterMax); } if (!PPart.allowCurveTweaking) { Fields["fillet"].guiActiveEditor = false; diameterEdit.maxValue = PPart.diameterMax - fillet; } else { filletEdit = (UI_FloatEdit)Fields["fillet"].uiControlEditor; filletEdit.maxValue = Mathf.Min(length, useEndDiameter ? PPart.diameterMax : diameter); filletEdit.minValue = 0; filletEdit.incrementLarge = PPart.diameterLargeStep; filletEdit.incrementSmall = PPart.diameterSmallStep; fillet = Mathf.Clamp(fillet, filletEdit.minValue, filletEdit.maxValue); } // ReSharper restore CompareOfFloatsByEqualityOperator }
private void SetupUICallbacks() { ROLLog.debug("Setting up UICallbacks..."); if (FindModularPart() is ModuleROTank p) { ROLLog.debug("p: " + p); ROLLog.debug("p.Fields[nameof(p.currentDiameter): " + p.Fields[nameof(p.currentDiameter)]); ROLLog.debug("p.Fields: " + p.Fields); UI_FloatEdit mp = p.Fields[nameof(p.currentDiameter)].uiControlEditor as UI_FloatEdit; mp.onFieldChanged += new Callback <BaseField, object>(OnDiameterChange); } }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); _scale = this.Fields["tweakScale"]; _name = this.Fields["tweakName"]; _type = this.Fields["scaleTypeId"]; _scaleEdit = (UI_FloatEdit)_scale.uiControlEditor; _nameEdit = (UI_ChooseOption)_name.uiControlEditor; _typeEdit = (UI_ChooseOption)_type.uiControlEditor; _typeEdit.options = ScaleConfig.AllConfigs.Select(a => a.name).ToArray(); scaleInfo = ScaleDatabase.Lookup(part.partInfo.name); }
public override void UpdateTechConstraints() { Fields[nameof(length)].guiActiveEditor = PPart.lengthMin != PPart.lengthMax; UI_FloatEdit lengthEdit = Fields[nameof(length)].uiControlEditor as UI_FloatEdit; lengthEdit.maxValue = PPart.lengthMax; lengthEdit.minValue = PPart.lengthMin; lengthEdit.incrementLarge = PPart.lengthLargeStep; lengthEdit.incrementSmall = PPart.lengthSmallStep; length = Mathf.Clamp(length, PPart.lengthMin, PPart.lengthMax); if (PPart.diameterMin == PPart.diameterMax || (coneTopMode == ConeEndMode.Constant && coneBottomMode == ConeEndMode.Constant)) { Fields[nameof(topDiameter)].guiActiveEditor = false; Fields[nameof(bottomDiameter)].guiActiveEditor = false; } else { if (coneTopMode == ConeEndMode.Constant) { Fields[nameof(topDiameter)].guiActiveEditor = false; Fields[nameof(bottomDiameter)].guiName = "Diameter"; } else { UI_FloatEdit topDiameterEdit = Fields[nameof(topDiameter)].uiControlEditor as UI_FloatEdit; topDiameterEdit.incrementLarge = PPart.diameterLargeStep; topDiameterEdit.incrementSmall = PPart.diameterSmallStep; topDiameterEdit.maxValue = PPart.diameterMax; topDiameterEdit.minValue = (coneTopMode == ConeEndMode.CanZero && coneBottomMode != ConeEndMode.Constant) ? 0 : PPart.diameterMin; topDiameter = Mathf.Clamp(topDiameter, topDiameterEdit.minValue, topDiameterEdit.maxValue); } if (coneBottomMode == ConeEndMode.Constant) { Fields[nameof(bottomDiameter)].guiActiveEditor = false; Fields[nameof(topDiameter)].guiName = "Diameter"; } else { UI_FloatEdit bottomDiameterEdit = Fields[nameof(bottomDiameter)].uiControlEditor as UI_FloatEdit; bottomDiameterEdit.incrementLarge = PPart.diameterLargeStep; bottomDiameterEdit.incrementSmall = PPart.diameterSmallStep; bottomDiameterEdit.maxValue = PPart.diameterMax; bottomDiameterEdit.minValue = (coneBottomMode == ConeEndMode.CanZero && coneTopMode != ConeEndMode.Constant) ? 0 : PPart.diameterMin; bottomDiameter = Mathf.Clamp(bottomDiameter, bottomDiameterEdit.minValue, bottomDiameterEdit.maxValue); } } }
private void ChangeAttachNodeSize(string name, float minDia, float area, int size) { if (name != textureMessageName || maxImpulseDiameterRatio == 0) { return; } UI_FloatEdit ejectionImpulseEdit = (UI_FloatEdit)Fields["ejectionImpulse"].uiControlEditor; float oldRatio = ejectionImpulse / ejectionImpulseEdit.maxValue; maxImpulse = Mathf.Round(maxImpulseDiameterRatio * minDia); ejectionImpulseEdit.maxValue = maxImpulse; ejectionImpulse = Mathf.Round(maxImpulse * oldRatio / 0.1f) * 0.1f; }
public override void OnStart(StartState state) { if (!HighLogic.LoadedSceneIsEditor) { return; } if (pPart.lengthMin == pPart.lengthMax) { Fields["length"].guiActiveEditor = false; } else { UI_FloatEdit lengthEdit = (UI_FloatEdit)Fields["length"].uiControlEditor; lengthEdit.maxValue = pPart.lengthMax; lengthEdit.minValue = pPart.lengthMin; lengthEdit.incrementLarge = pPart.lengthLargeStep; lengthEdit.incrementSmall = pPart.lengthSmallStep; } UI_FloatEdit diameterEdit = (UI_FloatEdit)Fields["diameter"].uiControlEditor; if (pPart.diameterMin == pPart.diameterMax) { Fields["diameter"].guiActiveEditor = false; } else { diameterEdit.maxValue = pPart.diameterMax; diameterEdit.minValue = useEndDiameter ? 0 : pPart.diameterMin; diameterEdit.incrementLarge = pPart.diameterLargeStep; diameterEdit.incrementSmall = pPart.diameterSmallStep; } if (!pPart.allowCurveTweaking) { Fields["fillet"].guiActiveEditor = false; diameterEdit.maxValue = pPart.diameterMax - fillet; } else { filletEdit = (UI_FloatEdit)Fields["fillet"].uiControlEditor; filletEdit.maxValue = Mathf.Min(length, useEndDiameter ? pPart.diameterMax : diameter); filletEdit.minValue = 0; filletEdit.incrementLarge = pPart.diameterLargeStep; filletEdit.incrementSmall = pPart.diameterSmallStep; } }
public void ChangeAttachNodeSize(AttachNode node, float minDia, float area) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (node.id != textureMessageName || maxImpulseDiameterRatio == 0) { return; } UI_FloatEdit ejectionImpulseEdit = (UI_FloatEdit)Fields["ejectionImpulse"].uiControlEditor; float oldRatio = ejectionImpulse / ejectionImpulseEdit.maxValue; maxImpulse = Mathf.Round(maxImpulseDiameterRatio * minDia); ejectionImpulseEdit.maxValue = maxImpulse; ejectionImpulse = Mathf.Round(maxImpulse * oldRatio / 0.1f) * 0.1f; }
public void OnShapeChanged(BaseField f, object obj, bool forceRefresh = false) { float v = CalculateVolume(); if (v > PPart.volumeMax || v < PPart.volumeMin) { UI_FloatEdit edt = Fields[nameof(length)].uiControlEditor as UI_FloatEdit; length = edt.minValue; AdjustDimensionBounds(); length = Mathf.Clamp(length, edt.minValue, edt.maxValue); } OnShapeDimensionChanged(f, obj); if (forceRefresh) { MonoUtilities.RefreshPartContextWindow(part); } }
public override void UpdateTechConstraints() { // ReSharper disable CompareOfFloatsByEqualityOperator if (!HighLogic.LoadedSceneIsEditor) { return; } if (PPart.lengthMin == PPart.lengthMax) { Fields["length"].guiActiveEditor = false; } else { UI_FloatEdit lengthEdit = (UI_FloatEdit)Fields["length"].uiControlEditor; lengthEdit.maxValue = PPart.lengthMax; lengthEdit.minValue = PPart.lengthMin; lengthEdit.incrementLarge = PPart.lengthLargeStep; lengthEdit.incrementSmall = PPart.lengthSmallStep; length = Mathf.Clamp(length, PPart.lengthMin, PPart.lengthMax); } if (PPart.diameterMin == PPart.diameterMax) { Fields["diameter"].guiActiveEditor = false; } else { UI_FloatEdit diameterEdit = (UI_FloatEdit)Fields["diameter"].uiControlEditor; if (null != diameterEdit) { diameterEdit.maxValue = PPart.diameterMax; diameterEdit.minValue = PPart.diameterMin; diameterEdit.incrementLarge = PPart.diameterLargeStep; diameterEdit.incrementSmall = PPart.diameterSmallStep; diameter = Mathf.Clamp(diameter, PPart.diameterMin, PPart.diameterMax); } else { Debug.LogError("*PP* could not find field 'diameter'"); } } // ReSharper restore CompareOfFloatsByEqualityOperator }
private void UpdateMaxValues() { // update mass limit value slider if (proceduralMassLimitEdit == null) { proceduralMassLimitEdit = (UI_FloatEdit)Fields["proceduralMassLimit"].uiControlEditor; } if (CurrentProceduralAvionicsConfig != null && CurrentProceduralAvionicsTechNode != null) { tonnageToMassRatio = CurrentProceduralAvionicsTechNode.tonnageToMassRatio; proceduralMassLimitEdit.maxValue = GetMaximumControllableTonnage(); proceduralMassLimitEdit.minValue = GetMinimumControllableTonnage(); // Set slide, small, and large slider increments to be (at most) 0.025%, 1%, and 10% var procMassDelta = proceduralMassLimitEdit.maxValue - proceduralMassLimitEdit.minValue; //we'll start at a large incerement of 1, and work up from there int largeIncrement = 1; while (largeIncrement < procMassDelta) { largeIncrement *= 2; } float largeIncFloat = (float)largeIncrement; // There's some weirdness going on here that makes the slider not match up with min and max values. // Because of that, need to ensure that this difference does not get larger than FLOAT_ERROR_ALLOWANCE // which is used for ensuring the min and max values in GetInternalMassLimit(). proceduralMassLimitEdit.incrementSlide = proceduralMassLimitEdit.minValue * (FLOAT_ERROR_ALLOWANCE - 1f); proceduralMassLimitEdit.incrementSmall = largeIncFloat / 100; proceduralMassLimitEdit.incrementLarge = largeIncFloat / 10; } else { Log("Cannot update max value yet, CurrentProceduralAvionicsConfig is null"); proceduralMassLimitEdit.maxValue = float.MaxValue; proceduralMassLimitEdit.minValue = 0; } }
private void SetEditorFields() { EMRUtils.Log("Setting editor fields"); UI_FloatEdit startFloatEdit = (UI_FloatEdit)Fields["startingEMR"].uiControlEditor; UI_FloatEdit finalFloatEdit = (UI_FloatEdit)Fields["finalEMR"].uiControlEditor; startFloatEdit.minValue = CurrentNodePair.Min.ratio; startFloatEdit.maxValue = CurrentNodePair.Max.ratio; finalFloatEdit.minValue = CurrentNodePair.Min.ratio; finalFloatEdit.maxValue = CurrentNodePair.Max.ratio; if (startingEMR < CurrentNodePair.Min.ratio || startingEMR > CurrentNodePair.Max.ratio) { startingEMR = CurrentNodePair.Max.ratio; } if (finalEMR < CurrentNodePair.Min.ratio || finalEMR > CurrentNodePair.Max.ratio) { finalEMR = CurrentNodePair.Min.ratio; } }
private void UpdateMaxValues() { // update mass limit value slider if (proceduralMassLimitEdit == null) { proceduralMassLimitEdit = (UI_FloatEdit)Fields["proceduralMassLimit"].uiControlEditor; } if (CurrentProceduralAvionicsConfig != null && CurrentProceduralAvionicsTechNode != null) { tonnageToMassRatio = CurrentProceduralAvionicsTechNode.tonnageToMassRatio; proceduralMassLimitEdit.maxValue = GetMaximumControllableTonnage(); proceduralMassLimitEdit.minValue = GetMinimumControllableTonnage(); // Set slide, small, and large slider increments to be (at most) 0.025%, 1%, and 10% var procMassDelta = proceduralMassLimitEdit.maxValue - proceduralMassLimitEdit.minValue; //we'll start at a large incerement of 1, and work up from there int largeIncrement = 1; while (largeIncrement < procMassDelta) { largeIncrement *= 2; } float largeIncFloat = (float)largeIncrement; proceduralMassLimitEdit.incrementSlide = largeIncFloat / 4000; proceduralMassLimitEdit.incrementSmall = largeIncFloat / 100; proceduralMassLimitEdit.incrementLarge = largeIncFloat / 10; //There's some weirdness going on here that makes the slider not match up with min and max values, //but it's so small i don't think i need to investigate it further } else { Log("Cannot update max value yet, CurrentProceduralAvionicsConfig is null"); proceduralMassLimitEdit.maxValue = float.MaxValue; proceduralMassLimitEdit.minValue = 0; } }
private void UpdateControllableMassSlider() { Fields[nameof(controllableMass)].guiActiveEditor = !IsScienceCore; UI_FloatEdit controllableMassEdit = Fields[nameof(controllableMass)].uiControlEditor as UI_FloatEdit; if (CurrentProceduralAvionicsConfig != null && CurrentProceduralAvionicsTechNode != null) { // Formula for controllable mass given avionics mass is Mathf.Pow(1000*avionicsMass / massFactor - massConstant, 1 / massExponent) controllableMassEdit.maxValue = Mathf.Max(GetMaximumControllableMass(), 0.001f); } else { controllableMassEdit.maxValue = 0.001f; } Log($"UpdateControllableMassSlider() MaxCtrlMass: {controllableMassEdit.maxValue}"); controllableMassEdit.minValue = 0; controllableMassEdit.incrementSmall = GetSmallIncrement(controllableMassEdit.maxValue); controllableMassEdit.incrementLarge = controllableMassEdit.incrementSmall * 10; controllableMassEdit.incrementSlide = GetSliderIncrement(controllableMassEdit.maxValue); controllableMassEdit.sigFigs = GetSigFigs(controllableMassEdit.maxValue); }
private void UpdateInFlightEMRParams() { if (CurrentNodePair.Disabled) { return; } if (emrInClosedLoop) { EMRUtils.Log("Closed Loop Detected"); float bestEMR = GetOptimalRatioForRemainingFuel(); EMRUtils.Log("Best EMR computed to be ", bestEMR, ":1"); string bestEMRSuffix = ""; if (bestEMR > CurrentNodePair.Max.ratio) { EMRUtils.Log("EMR higher than ", CurrentNodePair.Max.ratio, ":1 (was ", bestEMR, ":1), capping"); bestEMR = CurrentNodePair.Max.ratio; bestEMRSuffix = " (max)"; } else if (bestEMR < CurrentNodePair.Min.ratio) { EMRUtils.Log("EMR lower than ", CurrentNodePair.Min.ratio, ":1 (was ", bestEMR, ":1), capping"); bestEMR = CurrentNodePair.Min.ratio; bestEMRSuffix = " (min)"; } currentEMR = bestEMR; closedLoopEMRText = MathUtils.RoundSigFigs(bestEMR).ToString() + ":1" + bestEMRSuffix; } //EMRUtils.Log("Updating In Flight EMR Params"); Fields["currentEMR"].guiActive = !emrInClosedLoop; Fields["closedLoopEMRText"].guiActive = emrInClosedLoop; UI_FloatEdit currentEMREditor = (UI_FloatEdit)Fields["currentEMR"].uiControlFlight; currentEMREditor.minValue = CurrentNodePair.Min.ratio; currentEMREditor.maxValue = CurrentNodePair.Max.ratio; //EMRUtils.Log("Done Updating In Flight EMR Params"); }
private void UpdateMaxValues() { // update mass limit value slider if (proceduralMassLimitEdit == null) { proceduralMassLimitEdit = (UI_FloatEdit)Fields["proceduralMassLimit"].uiControlEditor; } if (needsTechInit) { InitializeTechLimits(); UpdateConfigSliders(); } if (CurrentProceduralAvionicsConfig != null) { tonnageToMassRatio = CurrentProceduralAvionicsTechNode.tonnageToMassRatio; proceduralMassLimitEdit.maxValue = GetMaximumControllableTonnage(); proceduralMassLimitEdit.minValue = GetMinimumControllableTonnage(); // Set slide, small, and large slider increments to be 0.025%, 1%, and 10% var procMassDelta = proceduralMassLimitEdit.maxValue - proceduralMassLimitEdit.minValue; proceduralMassLimitEdit.incrementSlide = procMassDelta / 4000; proceduralMassLimitEdit.incrementSmall = procMassDelta / 100; proceduralMassLimitEdit.incrementLarge = procMassDelta / 10; } else { //Log("Cannot update max value yet"); proceduralMassLimitEdit.maxValue = float.MaxValue; proceduralMassLimitEdit.minValue = 0; } if (proceduralMassLimit > proceduralMassLimitEdit.maxValue) { Log("Lowering procedural mass limit to new max value of ", proceduralMassLimitEdit.maxValue.ToString()); proceduralMassLimit = proceduralMassLimitEdit.maxValue; // Don't know how to force the gui to refresh this } }
public static void updateUIFloatEditControl(this PartModule module, string fieldName, float min, float max, float incLarge, float incSmall, float incSlide, bool forceUpdate, float forceVal) { UI_FloatEdit widget = null; if (HighLogic.LoadedSceneIsEditor) { widget = (UI_FloatEdit)module.Fields[fieldName].uiControlEditor; } else if (HighLogic.LoadedSceneIsFlight) { widget = (UI_FloatEdit)module.Fields[fieldName].uiControlFlight; } else { return; } if (widget == null) { return; } widget.minValue = min; widget.maxValue = max; widget.incrementLarge = incLarge; widget.incrementSmall = incSmall; widget.incrementSlide = incSlide; if (forceUpdate && widget.partActionItem != null) { UIPartActionFloatEdit ctr = (UIPartActionFloatEdit)widget.partActionItem; var t = widget.onFieldChanged;//temporarily remove the callback widget.onFieldChanged = null; ctr.incSmall.onToggle.RemoveAllListeners(); ctr.incLarge.onToggle.RemoveAllListeners(); ctr.decSmall.onToggle.RemoveAllListeners(); ctr.decLarge.onToggle.RemoveAllListeners(); ctr.slider.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 } }