private bool UpdateResources() { // Hopefully we can just fiddle with the existing part resources. // This saves having to make the window dirty, which breaks dragging on sliders. if (part.Resources.Count != selectedTankType.resources.Count) { Debug.LogWarning("*TCS* Selected and existing resource counts differ"); return(false); } for (int i = 0; i < part.Resources.Count; ++i) { PartResource partRes = part.Resources[i]; TankResource tankRes = selectedTankType.resources[i]; if (partRes.resourceName != tankRes.name) { Debug.LogWarning("*TCS* Selected and existing resource names differ"); return(false); } //double maxAmount = (float)Math.Round(tankRes.unitsConst + tankVolume * tankRes.unitsPerKL + mass * tankRes.unitsPerT, 2); double maxAmount = CalculateMaxResourceAmount(tankRes); // ReSharper disable CompareOfFloatsByEqualityOperator if (partRes.maxAmount == maxAmount) { continue; } if (tankRes.forceEmpty) { partRes.amount = 0; } else if (partRes.maxAmount == 0) { partRes.amount = maxAmount; } else { SIPrefix pfx = maxAmount.GetSIPrefix(); partRes.amount = pfx.Round(partRes.amount * maxAmount / partRes.maxAmount, 4); } partRes.maxAmount = maxAmount; // ReSharper restore CompareOfFloatsByEqualityOperator MaxAmountChanged(part, partRes, partRes.maxAmount); InitialAmountChanged(part, partRes, partRes.amount); } return(true); }
private void OnSliderChanged(IUIObject obj) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (oldSliderValue == slider.Value) { return; } oldSliderValue = slider.Value; SIPrefix prefix = resource.maxAmount.GetSIPrefix(); resource.amount = prefix.Round(slider.Value * resource.maxAmount, digits: 4); PartMessageService.Send <PartResourceInitialAmountChanged>(this, part, resource, resource.amount); if (scene == UI_Scene.Editor) { SetSymCounterpartsAmount(resource.amount); } resourceAmnt.Text = resource.amount.ToString("F1"); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); }