Example #1
0
 public void OnSetupSelected(PartSetupDialog dialog)
 {
     this.tier = (int)dialog.Tier;
     this.body = dialog.Body ?? NotSet;
     PksTieredResourceConverter.RiskTolerance     = dialog.RiskLevel;
     PksTieredResourceConverter.DefaultPartSetFor = this.part;
     PksTieredResourceConverter.LastTierSelected  = dialog.Tier;
     if (dialog.Applicability == PartSetupDialog.DecisionImpact.AllParts)
     {
         this.SetupAllParts();
     }
 }
        private void CalculateTierLabels(bool setTier)
        {
            for (TechTier tier = TechTier.Tier0; tier <= TechTier.Tier4; ++tier)
            {
                var  suitability = StaticAnalysis.GetTierSuitability(ColonizationResearchScenario.Instance, this.Product, tier, this.MaxTierForPart, this.Body);
                bool isEnabled;
                Func <string, string> transform;
                string toolTipTag;
                switch (suitability)
                {
                default:
                case TierSuitability.Ideal:
                    transform  = TextEffects.Green;
                    toolTipTag = "#LOC_KPBS_IDEAL_TIER";
                    isEnabled  = true;
                    if (setTier)
                    {
                        this.RiskLevel = TierSuitability.Ideal;
                        this.Tier      = tier;
                    }
                    break;

                case TierSuitability.LacksScanner:
                    transform  = TextEffects.Yellow;
                    toolTipTag = "#LOC_KPBS_SCANNING_SKILL_LAGS";
                    isEnabled  = true;
                    break;

                case TierSuitability.LacksSubordinateResearch:
                    transform  = TextEffects.Red;
                    toolTipTag = "#LOC_KPBS_SUBORDINATE_SKILL_LAGS";
                    isEnabled  = true;
                    break;

                case TierSuitability.UnderTier:
                    transform  = TextEffects.Yellow;
                    toolTipTag = "#LOC_KPBS_UNDER_TIER";
                    isEnabled  = true;
                    break;

                case TierSuitability.NotResearched:
                    transform  = s => s;
                    toolTipTag = "#LOC_KPBS_NOT_RESEARCHED";
                    isEnabled  = false;
                    break;

                case TierSuitability.BodyNotSelected:
                    transform  = s => s;
                    toolTipTag = "#LOC_KPBS_CHOOSE_A_BODY_FIRST";
                    isEnabled  = false;
                    break;

                case TierSuitability.PartDoesntSupportTier:
                    transform  = s => s;
                    toolTipTag = "#LOC_KPBS_PART_DOES_NOT_SUPPORT_TIER";
                    isEnabled  = false;
                    break;
                }

                TechTier techTierCopy = tier;
                string labelGetter() => transform(techTierCopy.DisplayName());

                void onToggled(bool isSelected)
                {
                    if (isSelected && isEnabled)
                    {
                        this.Tier      = techTierCopy;
                        this.RiskLevel = suitability;
                    }
                }

                if (this.tierToggles[(int)tier] == null)
                {
                    this.tierToggles[(int)tier] = new DialogGUIToggle(() => techTierCopy == this.Tier, labelGetter, onToggled);
                }
                else
                {
                    this.tierToggles[(int)tier].setLabel  = labelGetter;
                    this.tierToggles[(int)tier].onToggled = onToggled;
                }

                this.tierToggles[(int)tier].OptionInteractableCondition = () => isEnabled;
                this.tierToggles[(int)tier].tooltipText = Localizer.GetStringByTag(toolTipTag);
            }
        }