public override void OnAttachBill(Bill bill) { var customizedBill = bill as Bill_CustomizedProductionWithUft; var customizableRecipe = customizedBill?.OriginalRecipe as CustomizableRecipeDef; var billWorker = customizableRecipe?.billWorker as CustomizableBillWorker_MakeAutomata; if (customizedBill == null || customizableRecipe == null || billWorker == null) { Log.Error("Tried to call OnAttachBill with non-supported bill."); return; } bill.recipe.SetLabelCap(specialization.RecipeDefLabelCap); bill.recipe.workAmount = AutomataBillService.CalcWorkAmount(customizableRecipe, billWorker.baseMaterial); bill.recipe.ingredients = MakeIngredientCountList(ingredients); if (!billWorker.fixedIngredients.NullOrEmpty()) { bill.recipe.ingredients.AddRange(billWorker.fixedIngredients); } int score = AutomataBillService.CalcComponentScore(customizableRecipe, ingredients); int craftingSkillRequire = AutomataBillService.CalcCraftingSkillRequirement(customizableRecipe, score); bill.recipe.skillRequirements = new List <SkillRequirement>(); if (craftingSkillRequire > 0) { bill.recipe.skillRequirements.Add(new SkillRequirement() { skill = SkillDefOf.Crafting, minLevel = craftingSkillRequire }); } }
public override void DoWindowContents(Rect inRect) { GUI.BeginGroup(inRect); #region Appearance Tab Widgets.DrawMenuSection(UIConstants.rtAppearanceTab); GUI.BeginGroup(UIConstants.rtAppearanceTab.ContractedBy(UIConstants.groupMargin)); { Text.Font = GameFont.Medium; Widgets.Label(new Rect(0f, 0f, 200f, 40f), "PN_BILL_WINDOW_TAB_APPEARANCE_TITLE".Translate()); Text.Font = GameFont.Small; Rect innerRect = UIConstants.rtAppearanceTab.ContractedBy(UIConstants.groupMargin); TooltipHandler.TipRegion(new Rect(0f, 40f, innerRect.width, innerRect.height - 40f), "PN_BILL_WINDOW_TAB_APPEARANCE_TOOLTIP".Translate()); GUI.BeginGroup(new Rect(0f, 40f, innerRect.width, innerRect.height - 40f)); Rect[] rectPortraits = new Rect[] { new Rect(UIConstants.distanceAppearanceGap, 0f, UIConstants.pawnPortraitSize.x, UIConstants.pawnPortraitSize.y), new Rect(UIConstants.distanceAppearanceGap, UIConstants.pawnPortraitSize.y + 12f, UIConstants.pawnPortraitSize.x, UIConstants.pawnPortraitSize.y), new Rect(innerRect.width - UIConstants.pawnPortraitSize.x - UIConstants.distanceAppearanceGap, 0f, UIConstants.pawnPortraitSize.x, UIConstants.pawnPortraitSize.y), new Rect(innerRect.width - UIConstants.pawnPortraitSize.x - UIConstants.distanceAppearanceGap, UIConstants.pawnPortraitSize.y + 12f, UIConstants.pawnPortraitSize.x, UIConstants.pawnPortraitSize.y), }; for (int i = 0; i < rectPortraits.Length; ++i) { if (i < _samplePawnDrawers.Length) { _samplePawnDrawers[i].Draw(rectPortraits[i]); } } GUI.EndGroup(); Rect rect = new Rect(10f, 130f, 230f, 220f); if (Widgets.ButtonText(new Rect(150f, 324f, 100f, 36f), "Randomize".Translate())) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); for (int i = 0; i < _samplePawnDrawers.Length; ++i) { _samplePawnDrawers[i].RerollAndUpdateTexture(); } } } GUI.EndGroup(); #endregion #region Specialization Tab Widgets.DrawMenuSection(UIConstants.rtSpecializationTab); GUI.BeginGroup(UIConstants.rtSpecializationTab.ContractedBy(UIConstants.groupMargin)); { Text.Font = GameFont.Medium; Widgets.Label(new Rect(0f, 0f, 200f, 40f), "PN_BILL_WINDOW_TAB_SPECIALIZATION_TITLE".Translate()); Text.Font = GameFont.Small; // Combat float combatButtonLeft = 0f; if (Widgets.ButtonImageFitted(new Rect(combatButtonLeft, 35f, UIConstants.specializationButtonSize, UIConstants.specializationButtonSize), AutomataRaceDefOf.PN_Specialization_Combat.UIIcon)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); billWorker.selectedSpecialization = AutomataRaceDefOf.PN_Specialization_Combat; } TooltipHandler.TipRegion(new Rect(combatButtonLeft, 35f, UIConstants.specializationButtonSize, UIConstants.specializationButtonSize), AutomataRaceDefOf.PN_Specialization_Combat.tooltip); if (billWorker.selectedSpecialization == AutomataRaceDefOf.PN_Specialization_Combat) { GUI.DrawTexture(new Rect(combatButtonLeft + 26f, 81f, 32f, 32f), Widgets.CheckboxOnTex); } // Engineer float engineerButtonLeft = combatButtonLeft + UIConstants.specializationButtonSize + UIConstants.specializationButtonGap; if (Widgets.ButtonImageFitted(new Rect(engineerButtonLeft, 35f, UIConstants.specializationButtonSize, UIConstants.specializationButtonSize), AutomataRaceDefOf.PN_Specialization_Engineer.UIIcon)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); billWorker.selectedSpecialization = AutomataRaceDefOf.PN_Specialization_Engineer; } TooltipHandler.TipRegion(new Rect(engineerButtonLeft, 35f, UIConstants.specializationButtonSize, UIConstants.specializationButtonSize), AutomataRaceDefOf.PN_Specialization_Engineer.tooltip); if (billWorker.selectedSpecialization == AutomataRaceDefOf.PN_Specialization_Engineer) { GUI.DrawTexture(new Rect(engineerButtonLeft + 26f, 81f, 32f, 32f), Widgets.CheckboxOnTex); } // Domestic float domesticButtonLeft = engineerButtonLeft + UIConstants.specializationButtonSize + UIConstants.specializationButtonGap; if (Widgets.ButtonImageFitted(new Rect(domesticButtonLeft, 35f, UIConstants.specializationButtonSize, UIConstants.specializationButtonSize), AutomataRaceDefOf.PN_Specialization_Domestic.UIIcon)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); billWorker.selectedSpecialization = AutomataRaceDefOf.PN_Specialization_Domestic; } TooltipHandler.TipRegion(new Rect(domesticButtonLeft, 35f, UIConstants.specializationButtonSize, UIConstants.specializationButtonSize), AutomataRaceDefOf.PN_Specialization_Domestic.tooltip); if (billWorker.selectedSpecialization == AutomataRaceDefOf.PN_Specialization_Domestic) { GUI.DrawTexture(new Rect(domesticButtonLeft + 26f, 81f, 32f, 32f), Widgets.CheckboxOnTex); } } GUI.EndGroup(); #endregion #region Material Tab Widgets.DrawMenuSection(UIConstants.rtMaterialTab); GUI.BeginGroup(UIConstants.rtMaterialTab.ContractedBy(UIConstants.groupMargin)); { Text.Font = GameFont.Medium; Widgets.Label(new Rect(0f, 0f, 200f, 40f), "PN_BILL_WINDOW_TAB_MATERIAL_TITLE".Translate()); Text.Font = GameFont.Small; TooltipHandler.TipRegion(new Rect(0f, UIConstants.baseMaterialY, UIConstants.rtMaterialTab.width, 40f), "PN_BILL_WINDOW_TAB_MATERIAL_BASE_MATERIAL_TOOLTIP".Translate()); GUI.DrawTexture(new Rect(5f, UIConstants.baseMaterialY, 32f, 32f), billWorker.baseMaterial.uiIcon); Widgets.Label(new Rect(47f, UIConstants.baseMaterialY + 5f, 50f, 30f), $"x{billWorker.baseMaterialCount * (billWorker.baseMaterial.smallVolume ? 10 : 1)}"); if (Widgets.ButtonText(new Rect(130f, UIConstants.baseMaterialY - 3f, 125f, 35f), billWorker.baseMaterial.LabelCap)) { Find.WindowStack.Add(new FloatMenu(_baseMaterialThings.Select(x => new FloatMenuOption(x.LabelCap, () => { billWorker.baseMaterial = x; })).ToList())); } TooltipHandler.TipRegion(new Rect(0f, UIConstants.componentIndustrialY, UIConstants.rtMaterialTab.width, 40f), ThingDefOf.ComponentIndustrial.LabelCap + "\n\n" + "PN_BILL_WINDOW_TAB_MATERIAL_COMPONENT_TOOLTIP".Translate()); GUI.DrawTexture(new Rect(5f, UIConstants.componentIndustrialY, 32f, 32f), ThingDefOf.ComponentIndustrial.uiIcon); Widgets.Label(new Rect(47f, UIConstants.componentIndustrialY + 3f, 50f, 30f), $"x{billWorker.ComponentIndustrialCount}"); billWorker.ComponentIndustrialCount = (int)Widgets.HorizontalSlider(new Rect(110f, UIConstants.componentIndustrialY, 150f, 38f), billWorker.ComponentIndustrialCount, 0f, 20f, middleAlignment: true, leftAlignedLabel: "0", rightAlignedLabel: "20", roundTo: 0); TooltipHandler.TipRegion(new Rect(0f, UIConstants.componentSpacerY, UIConstants.rtMaterialTab.width, 40f), ThingDefOf.ComponentSpacer.LabelCap + "\n\n" + "PN_BILL_WINDOW_TAB_MATERIAL_COMPONENT_TOOLTIP".Translate()); GUI.DrawTexture(new Rect(5f, UIConstants.componentSpacerY, 32f, 32f), ThingDefOf.ComponentSpacer.uiIcon); Widgets.Label(new Rect(47f, UIConstants.componentSpacerY + 3f, 50f, 30f), $"x{billWorker.ComponentSpacerCount}"); billWorker.ComponentSpacerCount = (int)Widgets.HorizontalSlider(new Rect(110f, UIConstants.componentSpacerY, 150f, 38f), billWorker.ComponentSpacerCount, 0f, 20f, middleAlignment: true, leftAlignedLabel: "0", rightAlignedLabel: "20", roundTo: 0); TooltipHandler.TipRegion(new Rect(0f, UIConstants.aiPersonaCoreY, UIConstants.rtMaterialTab.width, 40f), ThingDefOf.AIPersonaCore.LabelCap + "\n\n" + "PN_BILL_WINDOW_TAB_MATERIAL_AICORE_TOOLTIP".Translate()); GUI.DrawTexture(new Rect(5f, UIConstants.aiPersonaCoreY, 32f, 32f), ThingDefOf.AIPersonaCore.uiIcon); Widgets.Label(new Rect(47f, UIConstants.aiPersonaCoreY + 3f, 50f, 30f), $"x{(billWorker.useAIPersonaCore ? 1 : 0)}"); Widgets.Checkbox(new Vector2(170f, UIConstants.aiPersonaCoreY + 2.5f), ref billWorker.useAIPersonaCore); } GUI.EndGroup(); #endregion #region Expected Tab GUI.BeginGroup(UIConstants.rtExpectedTab); { Text.Font = GameFont.Medium; Widgets.Label(new Rect(10f, 10f, 200f, 40f), "PN_BILL_WINDOW_TAB_SUMMARY_TITLE".Translate()); Text.Font = GameFont.Small; Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.MiddleRight; Widgets.Label(new Rect(UIConstants.rtExpectedTab.width - 200f, 0f, 200f, 40f), $"{"PN_BILL_WINDOW_TAB_SUMMARY_REQUIRED_SKILL".Translate()}: { AutomataBillService.CalcCraftingSkillRequirement(billWorker.recipe, billWorker.Score) }"); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; Rect innerRect = new Rect(5f, 45f, UIConstants.rtExpectedTab.width - 10f, UIConstants.rtExpectedTab.height - 45f); GUI.BeginGroup(innerRect); { float width = innerRect.width / 7f; Widgets.DrawLineHorizontal(0f, 30f, innerRect.width); Dictionary <QualityCategory, float> probability = AutomataQualityService.GetProductProbability(billWorker.Score); for (byte i = 0; i < 7; ++i) { DrawQualityProbabilitySection(probability, (QualityCategory)i, new Rect(i * width, 0f, width, innerRect.height)); } } GUI.EndGroup(); } GUI.EndGroup(); #endregion #region Buttons Tab GUI.BeginGroup(UIConstants.rtButtonTab); if (Widgets.ButtonText(new Rect(150f, 0f, 110f, 40f), "PN_BILL_WINDOW_TAB_SUMMARY_BTN_CANCEL".Translate())) { Close(true); } Color defaultColor = GUI.color; GUI.color = CheckAllRequirements() ? defaultColor : Color.grey; if (Widgets.ButtonText(new Rect(312f, 0f, 110f, 40f), "PN_BILL_WINDOW_TAB_SUMMARY_BTN_ADD_BILL".Translate())) { TryAddBill(); } GUI.color = defaultColor; GUI.EndGroup(); #endregion GUI.EndGroup(); }