Example #1
0
 private void UpdateResourceAmounts()
 {
     foreach (TankResource tr in SelectedTankType.resources)
     {
         if (part.Resources.Get(tr.name) is PartResource pr)
         {
             double maxAmount = CalculateMaxResourceAmount(tr);
             pr.amount    = Math.Round(pr.amount * maxAmount / pr.maxAmount, 4);
             pr.maxAmount = maxAmount;
             pr.amount    = Math.Min(pr.amount, maxAmount);
             if (part.PartActionWindow?.ListItems.FirstOrDefault(x => (x as UIPartActionResourceEditor)?.Resource == pr) is UIPartActionResourceEditor pare)
             {
                 pare.resourceMax.text = KSPUtil.LocalizeNumber(pr.maxAmount, "F1");
                 pare.UpdateItem();
                 pare.slider.onValueChanged.Invoke(pare.slider.value);
             }
         }
         else
         {
             Debug.LogError($"{ModTag} UpdateResourceAmounts for {tr.name} found no matching PartResource!");
         }
     }
 }
Example #2
0
        public void ClobberEngineersReport()
        {
            if (!HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            EnsureLocalizationsCached();

            ShipConstruct ship = EditorLogic.fetch.ship;

            SpaceCenterFacility launchFacility;

            switch (EditorDriver.editorFacility)
            {
            default:
            case EditorFacility.VAB:
                launchFacility = SpaceCenterFacility.LaunchPad;
                break;

            case EditorFacility.SPH:
                launchFacility = SpaceCenterFacility.Runway;
                break;
            }

            bool isLP = launchFacility == SpaceCenterFacility.LaunchPad;
            //partCount = ship.parts.Count;
            //partLimit = GameVariables.Instance.GetPartCountLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(editorFacility), editorFacility == SpaceCenterFacility.VehicleAssemblyBuilding);

            float   totalMass = Utilities.GetShipMass(ship, true, out _, out _);
            Vector3 craftSize = Utilities.GetShipSize(ship, true);

            float   massLimit;
            Vector3 maxSize;

            if (PresetManager.Instance.ActivePreset.GeneralSettings.Enabled && PresetManager.Instance.ActivePreset.GeneralSettings.BuildTimes)
            {
                massLimit = isLP ? KCTGameStates.ActiveKSC.ActiveLPInstance.SupportedMass : GameVariables.Instance.GetCraftMassLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(launchFacility), false);
                maxSize   = isLP ? KCTGameStates.ActiveKSC.ActiveLPInstance.SupportedSize : GameVariables.Instance.GetCraftSizeLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(launchFacility), false);
            }
            else
            {
                massLimit = GameVariables.Instance.GetCraftMassLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(launchFacility), isLP);
                maxSize   = GameVariables.Instance.GetCraftSizeLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(launchFacility), isLP);
            }

            string neutralColorHex = XKCDColors.HexFormat.KSPNeutralUIGrey;

            //string partCountColorHex = partCount <= partLimit ? XKCDColors.HexFormat.KSPBadassGreen : XKCDColors.HexFormat.KSPNotSoGoodOrange;
            //partCountLH.text = partCountLH.text = KSP.Localization.Localizer.Format("#autoLOC_443389", neutralColorHex);

            //if (partLimit < int.MaxValue)
            //{
            //    partCountRH.text = "<color=" + partCountColorHex + ">" + partCount.ToString("0") + " / " + partLimit.ToString("0") + "</color>";
            //}
            //else
            //{
            //    partCountRH.text = "<color=" + partCountColorHex + ">" + partCount.ToString("0") + "</color>";
            //}

            string partMassColorHex = totalMass <= massLimit ? XKCDColors.HexFormat.KSPBadassGreen : XKCDColors.HexFormat.KSPNotSoGoodOrange;

            _refERpartMassLH.text = KSP.Localization.Localizer.Format("#autoLOC_443401", neutralColorHex);

            if (massLimit < float.MaxValue)
            {
                _refERpartMassRH.text = KSP.Localization.Localizer.Format("#autoLOC_443405", partMassColorHex, totalMass.ToString("N3"), massLimit.ToString("N1"));
            }
            else
            {
                _refERpartMassRH.text = KSP.Localization.Localizer.Format("#autoLOC_443409", partMassColorHex, totalMass.ToString("N3"));
            }

            string sizeForeAftHex = craftSize.y <= maxSize.y ? XKCDColors.HexFormat.KSPBadassGreen : XKCDColors.HexFormat.KSPNotSoGoodOrange;
            string sizeSpanHex    = craftSize.x <= maxSize.x ? XKCDColors.HexFormat.KSPBadassGreen : XKCDColors.HexFormat.KSPNotSoGoodOrange;
            string sizeTHgtHex    = craftSize.z <= maxSize.z ? XKCDColors.HexFormat.KSPBadassGreen : XKCDColors.HexFormat.KSPNotSoGoodOrange;


            _refERsizeLH.text = "<line-height=110%><color=" + neutralColorHex + ">" + _cacheAutoLOC_443417 + "</color>\n<color=" +
                                neutralColorHex + ">" + _cacheAutoLOC_443418 + "</color>\n<color=" +
                                neutralColorHex + ">" + _cacheAutoLOC_443419 + "</color>\n<color=" +
                                neutralColorHex + ">" + _cacheAutoLOC_443420 + "</color></line-height>";

            if (maxSize.x < float.MaxValue && maxSize.y < float.MaxValue && maxSize.z < float.MaxValue)
            {
                _refERsizeRH.text =
                    "<line-height=110%>  \n<color=" + sizeForeAftHex + ">" + KSPUtil.LocalizeNumber(craftSize.y, "0.0") + _cacheAutoLOC_7001411 +
                    " / " + KSPUtil.LocalizeNumber(maxSize.y, "0.0") + _cacheAutoLOC_7001411 + "</color>\n<color=" +
                    sizeSpanHex + ">" + KSPUtil.LocalizeNumber(craftSize.x, "0.0") + _cacheAutoLOC_7001411 + " / " +
                    KSPUtil.LocalizeNumber(maxSize.x, "0.0") +
                    _cacheAutoLOC_7001411 + "</color>\n<color=" + sizeTHgtHex + ">" + KSPUtil.LocalizeNumber(craftSize.z, "0.0") + _cacheAutoLOC_7001411 + " / " +
                    KSPUtil.LocalizeNumber(maxSize.z, "0.0") + _cacheAutoLOC_7001411 + "</color></line-height>";
            }
            else
            {
                _refERsizeRH.text = "<line-height=110%> \n<color=" + sizeForeAftHex + ">" + KSPUtil.LocalizeNumber(craftSize.y, "0.0") + _cacheAutoLOC_7001411 +
                                    "</color>\n<color=" + sizeSpanHex + ">" + KSPUtil.LocalizeNumber(craftSize.x, "0.0") + _cacheAutoLOC_7001411 +
                                    "</color>\n<color=" + sizeTHgtHex + ">" + KSPUtil.LocalizeNumber(craftSize.z, "0.0") + _cacheAutoLOC_7001411 + "</color></line-height>";
            }

            bool allGood = //partCount <= partLimit &&
                           totalMass <= massLimit &&
                           craftSize.x <= maxSize.x &&
                           craftSize.y <= maxSize.y &&
                           craftSize.z <= maxSize.z;

            _refERappFrame.header.color = allGood ? XKCDColors.ElectricLime : XKCDColors.Orange;

            if (!allGood)
            {
                EngineersReport.Instance.appLauncherButton.sprite.color = XKCDColors.Orange;
            }
            if (allGood)
            {
                EngineersReport.Instance.appLauncherButton.sprite.color = Color.white;
            }
        }
Example #3
0
        private List <UIListItem> CreateAtmosphericCharacteristics(CelestialBody currentBody, GenericCascadingList cascadingList)
        {
            GenericCascadingList genericCascadingList = cascadingList;
            Boolean atmosphere = currentBody.atmosphere && currentBody.atmospherePressureSeaLevel > 0;

            String     key      = Localizer.Format("#autoLOC_462448");
            String     template = atmosphere ? "#autoLOC_439855" : "#autoLOC_439856";
            UIListItem item     = genericCascadingList.CreateBody(key, "<color=#b8f4d1>" + Localizer.Format((string)template) + "</color>");

            List <UIListItem> list = new List <UIListItem>();

            list.Add(item);

            if (atmosphere)
            {
                item = cascadingList.CreateBody(Localizer.Format("#autoLOC_462453"), "<color=#b8f4d1>" + KSPUtil.LocalizeNumber(currentBody.atmosphereDepth, "N0") + " " + Localizer.Format("#autoLOC_7001411") + "</color>");
                list.Add(item);
                item = cascadingList.CreateBody(Localizer.Format("#autoLOC_462456"), "<color=#b8f4d1>" + KSPUtil.LocalizeNumber(currentBody.atmospherePressureSeaLevel / 101.324996948242, "0.#####") + " " + Localizer.Format("#autoLOC_7001419") + "</color>");
                list.Add(item);
                item = cascadingList.CreateBody(Localizer.Format("#autoLOC_462459"), "<color=#b8f4d1>" + KSPUtil.LocalizeNumber(currentBody.atmosphereTemperatureSeaLevel, "0.##") + " " + Localizer.Format("#autoLOC_7001406") + "</color>");
                list.Add(item);
            }

            return(list);
        }
        // See CompilePartInfo
        public static AvailablePart.ResourceInfo GetResourceInfo(PartResource pr)
        {
            AvailablePart.ResourceInfo resourceInfo = new AvailablePart.ResourceInfo();
            resourceInfo.resourceName = pr.resourceName;
            resourceInfo.displayName  = pr.info.displayName.LocalizeRemoveGender();
            StringBuilder infoString = new StringBuilder();

            infoString.Append(Localizer.Format("#autoLOC_166269", pr.amount.ToString("F1")));
            infoString.Append((pr.amount == pr.maxAmount) ? string.Empty : (" " + Localizer.Format("#autoLOC_6004042", pr.maxAmount.ToString("F1"))));
            infoString.Append(Localizer.Format("#autoLOC_166270", (pr.amount * pr.info.density).ToString("F2")));
            infoString.Append((pr.info.unitCost <= 0f) ? string.Empty : Localizer.Format("#autoLOC_166271", (pr.amount * (double)pr.info.unitCost).ToString("F2")));
            resourceInfo.info = infoString.ToStringAndRelease();
            if (pr.maxAmount > 0.0)
            {
                resourceInfo.primaryInfo = "<b>" + resourceInfo.displayName + ": </b>" + KSPUtil.LocalizeNumber(pr.maxAmount, "F1");
            }
            return(resourceInfo);
        }