protected void ShowBackstoryDialog(CustomPawn customPawn, BackstorySlot slot) { Backstory originalBackstory = (slot == BackstorySlot.Childhood) ? customPawn.Childhood : customPawn.Adulthood; Backstory selectedBackstory = originalBackstory; Dialog_Options <Backstory> dialog = new Dialog_Options <Backstory>(slot == BackstorySlot.Childhood ? this.providerBackstories.ChildhoodBackstories : this.providerBackstories.AdulthoodBackstories) { NameFunc = (Backstory backstory) => { return(backstory.Title); }, DescriptionFunc = (Backstory backstory) => { return(backstory.FullDescriptionFor(customPawn.Pawn)); }, SelectedFunc = (Backstory backstory) => { return(selectedBackstory == backstory); }, SelectAction = (Backstory backstory) => { selectedBackstory = backstory; }, CloseAction = () => { if (slot == BackstorySlot.Childhood) { BackstoryUpdated(BackstorySlot.Childhood, selectedBackstory); } else { BackstoryUpdated(BackstorySlot.Adulthood, selectedBackstory); } } }; Find.WindowStack.Add(dialog); }
protected void ShowHeadDialog(CustomPawn customPawn) { IEnumerable <CustomHeadType> headTypes = PrepareCarefully.Instance.Providers.HeadTypes.GetHeadTypes(customPawn.Pawn.def, customPawn.Gender); Dialog_Options <CustomHeadType> dialog = new Dialog_Options <CustomHeadType>(headTypes) { NameFunc = (CustomHeadType headType) => { return(headType.Label); }, SelectedFunc = (CustomHeadType headType) => { return(customPawn.HeadType.GraphicPath == headType.GraphicPath); }, SelectAction = (CustomHeadType headType) => { customPawn.HeadType = headType; this.pawnLayerLabel = headType.Label; }, CloseAction = () => { } }; Find.WindowStack.Add(dialog); }
protected void ShowHairDialog(CustomPawn customPawn) { List <HairDef> hairDefs = PrepareCarefully.Instance.Providers.Hair.GetHairs(customPawn); Dialog_Options <HairDef> dialog = new Dialog_Options <HairDef>(hairDefs) { NameFunc = (HairDef hairDef) => { return(hairDef.LabelCap); }, SelectedFunc = (HairDef hairDef) => { return(customPawn.HairDef == hairDef); }, SelectAction = (HairDef hairDef) => { customPawn.HairDef = hairDef; this.pawnLayerLabel = hairDef.LabelCap; }, CloseAction = () => { } }; Find.WindowStack.Add(dialog); }
protected void ShowPawnLayerOptionsDialog(CustomPawn customPawn) { List <PawnLayerOption> options = selectedPawnLayer.Options; Dialog_Options <PawnLayerOption> dialog = new Dialog_Options <PawnLayerOption>(options) { NameFunc = (PawnLayerOption option) => { return(option.Label); }, SelectedFunc = (PawnLayerOption option) => { return(selectedPawnLayer.IsOptionSelected(customPawn, option)); }, SelectAction = (PawnLayerOption option) => { selectedPawnLayer.SelectOption(customPawn, option); this.pawnLayerLabel = option.Label; }, CloseAction = () => { } }; Find.WindowStack.Add(dialog); }
protected void ShowBodyTypeDialog(CustomPawn customPawn) { ProviderBodyTypes provider = PrepareCarefully.Instance.Providers.BodyTypes; List <BodyType> bodyTypes = provider.GetBodyTypesForPawn(customPawn); Dialog_Options <BodyType> dialog = new Dialog_Options <BodyType>(bodyTypes) { NameFunc = (BodyType bodyType) => { return(provider.GetBodyTypeLabel(bodyType)); }, SelectedFunc = (BodyType bodyType) => { return(customPawn.BodyType == bodyType); }, SelectAction = (BodyType bodyType) => { customPawn.BodyType = bodyType; this.pawnLayerLabel = provider.GetBodyTypeLabel(bodyType); }, CloseAction = () => { } }; Find.WindowStack.Add(dialog); }
protected void OpenAddPawnDialog() { ProviderFactions factionProvider = PrepareCarefully.Instance.Providers.Factions; FactionDef selectedFaction = previousFaction != null ? previousFaction : factionProvider.NonPlayerHumanlikeFactionDefs.First(); var dialog = new Dialog_Options <FactionDef>(factionProvider.NonPlayerHumanlikeFactionDefs) { ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(), CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(), HeaderLabel = "EdB.PC.Panel.PawnList.SelectFaction".Translate(), NameFunc = (FactionDef def) => { return(def.LabelCap); }, SelectedFunc = (FactionDef def) => { return(def.defName == selectedFaction.defName); }, SelectAction = (FactionDef def) => { selectedFaction = def; }, EnabledFunc = (FactionDef def) => { return(true); }, ConfirmValidation = () => { if (selectedFaction == null) { return("EdB.PC.Panel.PawnList.Error.MustSelectFaction"); } else { return(null); } }, CloseAction = () => { SoundDefOf.SelectDesignator.PlayOneShotOnCamera(); previousFaction = selectedFaction; AddingFactionPawn(selectedFaction); } }; Find.WindowStack.Add(dialog); }
protected void ShowApparelDialog(CustomPawn customPawn, int layer) { List <ThingDef> apparelList = PrepareCarefully.Instance.Providers.Apparel.GetApparel(customPawn, layer); Dialog_Options <ThingDef> dialog = new Dialog_Options <ThingDef>(apparelList) { IncludeNone = true, NameFunc = (ThingDef apparel) => { return(apparel.LabelCap); }, SelectedFunc = (ThingDef apparel) => { return(customPawn.GetSelectedApparel(layer) == apparel); }, SelectAction = (ThingDef apparel) => { this.pawnLayerLabel = apparel.LabelCap; if (apparel.MadeFromStuff) { if (customPawn.GetSelectedStuff(layer) == null) { customPawn.SetSelectedStuff(layer, apparelStuffLookup[apparel][0]); } } else { customPawn.SetSelectedStuff(layer, null); } customPawn.SetSelectedApparel(layer, apparel); }, NoneSelectedFunc = () => { return(customPawn.GetSelectedApparel(layer) == null); }, SelectNoneAction = () => { customPawn.SetSelectedApparel(layer, null); customPawn.SetSelectedStuff(layer, null); this.pawnLayerLabel = "EdB.PC.Panel.Appearance.NoneSelected".Translate(); } }; Find.WindowStack.Add(dialog); }
protected void ShowApparelStuffDialog(CustomPawn customPawn, int layer) { ThingDef apparel = customPawn.GetSelectedApparel(layer); if (apparel == null) { return; } List <ThingDef> stuffList = this.apparelStuffLookup[apparel]; Dialog_Options <ThingDef> dialog = new Dialog_Options <ThingDef>(stuffList) { NameFunc = (ThingDef stuff) => { return(stuff.LabelCap); }, SelectedFunc = (ThingDef stuff) => { return(customPawn.GetSelectedStuff(layer) == stuff); }, SelectAction = (ThingDef stuff) => { customPawn.SetSelectedStuff(layer, stuff); } }; Find.WindowStack.Add(dialog); }
protected void ShowBackstoryDialog(CustomPawn customPawn, BackstorySlot slot) { Backstory originalBackstory = (slot == BackstorySlot.Childhood) ? customPawn.Childhood : customPawn.Adulthood; Backstory selectedBackstory = originalBackstory; Filter <Backstory> filterToRemove = null; bool filterListDirtyFlag = true; List <Backstory> fullOptionsList = slot == BackstorySlot.Childhood ? this.providerBackstories.GetChildhoodBackstoriesForPawn(customPawn) : this.providerBackstories.GetAdulthoodBackstoriesForPawn(customPawn); List <Backstory> filteredBackstories = new List <Backstory>(fullOptionsList.Count); Dialog_Options <Backstory> dialog = new Dialog_Options <Backstory>(filteredBackstories) { NameFunc = (Backstory backstory) => { return(backstory.TitleCapFor(customPawn.Gender)); }, DescriptionFunc = (Backstory backstory) => { return(backstory.FullDescriptionFor(customPawn.Pawn)); }, SelectedFunc = (Backstory backstory) => { return(selectedBackstory == backstory); }, SelectAction = (Backstory backstory) => { selectedBackstory = backstory; }, CloseAction = () => { if (slot == BackstorySlot.Childhood) { BackstoryUpdated(BackstorySlot.Childhood, selectedBackstory); } else { BackstoryUpdated(BackstorySlot.Adulthood, selectedBackstory); } } }; dialog.DrawHeader = (Rect rect) => { if (filterToRemove != null) { activeFilters.Remove(filterToRemove); filterToRemove = null; filterListDirtyFlag = true; } if (filterListDirtyFlag) { filteredBackstories.Clear(); filteredBackstories.AddRange(fullOptionsList.Where(p => { foreach (var f in activeFilters) { if (f.FilterFunction(p) == false) { return(false); } } return(true); })); filterListDirtyFlag = false; dialog.ScrollToTop(); } float filterHeight = 18; float filterPadding = 4; float maxWidth = rect.width - 32; Vector2 cursor = new Vector2(0, 0); string addFilterLabel = "EdB.PC.Dialog.Backstory.Filter.Add".Translate(); float width = Text.CalcSize(addFilterLabel).x; Rect addFilterRect = new Rect(rect.x, rect.y, width + 30, filterHeight); Widgets.DrawAtlas(addFilterRect, Textures.TextureFilterAtlas1); Text.Font = GameFont.Tiny; if (addFilterRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorText; } Widgets.Label(addFilterRect.InsetBy(10, 0, 20, 0).OffsetBy(0, 1), addFilterLabel); GUI.DrawTexture(new Rect(addFilterRect.xMax - 20, addFilterRect.y + 6, 11, 8), Textures.TextureDropdownIndicator); if (Widgets.ButtonInvisible(addFilterRect, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (var filter in availableFilters) { if (activeFilters.FirstOrDefault((f) => { if (f == filter || f.ConflictsWith(filter)) { return(true); } return(false); }) == null) { list.Add(new FloatMenuOption(filter.LabelFull, () => { activeFilters.Add(filter); filterListDirtyFlag = true; }, MenuOptionPriority.Default, null, null, 0, null, null)); } } Find.WindowStack.Add(new FloatMenu(list, null, false)); } cursor.x += addFilterRect.width + filterPadding; Text.Font = GameFont.Tiny; foreach (var filter in activeFilters) { GUI.color = Style.ColorText; float labelWidth = Text.CalcSize(filter.LabelShort).x; if (cursor.x + labelWidth > maxWidth) { cursor.x = 0; cursor.y += filterHeight + filterPadding; } Rect filterRect = new Rect(cursor.x, cursor.y, labelWidth + 30, filterHeight); Widgets.DrawAtlas(filterRect, Textures.TextureFilterAtlas2); Rect closeButtonRect = new Rect(filterRect.xMax - 15, filterRect.y + 5, 9, 9); if (filterRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorText; } Widgets.Label(filterRect.InsetBy(10, 0, 20, 0).OffsetBy(0, 1), filter.LabelShort); GUI.DrawTexture(closeButtonRect, Textures.TextureButtonCloseSmall); if (Widgets.ButtonInvisible(filterRect)) { filterToRemove = filter; filterListDirtyFlag = true; SoundDefOf.Tick_High.PlayOneShotOnCamera(); } cursor.x += filterRect.width + filterPadding; } Text.Font = GameFont.Small; GUI.color = Color.white; return(cursor.y + filterHeight + 4); }; Find.WindowStack.Add(dialog); }
protected void ShowAddRelationshipDialogs() { CustomPawn sourcePawn = null; PawnRelationDef selectedRelationship = null; CustomPawn targetPawn = null; Dialog_Options <PawnRelationDef> relationshipDialog = new Dialog_Options <PawnRelationDef>(null) { ConfirmButtonLabel = "EdB.PC.Common.Next".Translate(), CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(), HeaderLabel = "EdB.PC.AddRelationship.Header.Relationship".Translate(), NameFunc = (PawnRelationDef def) => { return(def.GetGenderSpecificLabelCap(sourcePawn.Pawn)); }, SelectedFunc = (PawnRelationDef def) => { return(def == selectedRelationship); }, SelectAction = (PawnRelationDef def) => { selectedRelationship = def; }, EnabledFunc = (PawnRelationDef d) => { return(!disabledRelationships.Contains(d)); }, ConfirmValidation = () => { if (selectedRelationship == null) { return("EdB.PC.AddRelationship.Error.RelationshipRequired"); } else { return(null); } } }; DialogSelectPawn sourcePawnDialog = new DialogSelectPawn() { HeaderLabel = "EdB.PC.AddRelationship.Header.Source".Translate(), SelectAction = (CustomPawn pawn) => { sourcePawn = pawn; }, Pawns = PrepareCarefully.Instance.Pawns, ConfirmValidation = () => { if (sourcePawn == null) { return("EdB.PC.AddRelationship.Error.SourceRequired"); } else { return(null); } } }; DialogSelectPawn targetPawnDialog = new DialogSelectPawn() { HeaderLabel = "EdB.PC.AddRelationship.Header.Target".Translate(), SelectAction = (CustomPawn pawn) => { targetPawn = pawn; }, ConfirmValidation = () => { if (targetPawn == null) { return("EdB.PC.AddRelationship.Error.TargetRequired"); } else { return(null); } } }; sourcePawnDialog.CloseAction = () => { List <PawnRelationDef> relationDefs = PrepareCarefully.Instance.RelationshipManager.AllowedRelationships.Select((PawnRelationDef def) => { return(def); }).ToList(); relationDefs.Sort((PawnRelationDef a, PawnRelationDef b) => { return(a.GetGenderSpecificLabelCap(sourcePawn.Pawn).CompareTo(b.GetGenderSpecificLabelCap(sourcePawn.Pawn))); }); relationshipDialog.Options = relationDefs; Find.WindowStack.Add(relationshipDialog); }; relationshipDialog.CloseAction = () => { SetDisabledTargets(sourcePawn, selectedRelationship); targetPawnDialog.DisabledPawns = disabledTargets; List <CustomPawn> otherPawns = PrepareCarefully.Instance.Pawns.FindAll((CustomPawn p) => { return(p != sourcePawn); }); targetPawnDialog.Pawns = otherPawns; Find.WindowStack.Add(targetPawnDialog); }; targetPawnDialog.CloseAction = () => { this.RelationshipAdded(PrepareCarefully.Instance.RelationshipManager.FindInverseRelationship(selectedRelationship), sourcePawn, targetPawn); }; Find.WindowStack.Add(sourcePawnDialog); }
protected override void DrawPanelContent(State state) { CustomPawn currentPawn = state.CurrentPawn; tipCache.CheckPawn(currentPawn); if (currentPawn.TraitCount > Constraints.MaxVanillaTraits) { Warning = "EdB.PC.Panel.Traits.Warning.TooManyTraits".Translate(); } else { Warning = null; } base.DrawPanelContent(state); Action clickAction = null; float cursor = 0; GUI.color = Color.white; GUI.BeginGroup(RectScrollFrame); try { if (currentPawn.Traits.Count() == 0) { GUI.color = Style.ColorText; Widgets.Label(RectScrollView.InsetBy(6, 0, 0, 0), "EdB.PC.Panel.Traits.None".Translate()); } GUI.color = Color.white; scrollView.Begin(RectScrollView); int index = 0; foreach (Trait trait in currentPawn.Traits) { if (index >= fields.Count) { fields.Add(new Field()); } Field field = fields[index]; GUI.color = Style.ColorPanelBackgroundItem; Rect traitRect = new Rect(0, cursor, SizeTrait.x - (scrollView.ScrollbarsVisible ? 16 : 0), SizeTrait.y); GUI.DrawTexture(traitRect, BaseContent.WhiteTex); GUI.color = Color.white; Rect fieldRect = new Rect(SizeFieldPadding.x, cursor + SizeFieldPadding.y, SizeField.x, SizeField.y); if (scrollView.ScrollbarsVisible) { fieldRect.width = fieldRect.width - 16; } field.Rect = fieldRect; Rect fieldClickRect = fieldRect; fieldClickRect.width = fieldClickRect.width - 36; field.ClickRect = fieldClickRect; if (trait != null) { field.Label = trait.LabelCap; field.Tip = GetTraitTip(trait, currentPawn); } else { field.Label = null; field.Tip = null; } Trait localTrait = trait; int localIndex = index; field.ClickAction = () => { Trait originalTrait = localTrait; Trait selectedTrait = originalTrait; ComputeDisallowedTraits(currentPawn, originalTrait); Dialog_Options <Trait> dialog = new Dialog_Options <Trait>(providerTraits.Traits) { NameFunc = (Trait t) => { return(t.LabelCap); }, DescriptionFunc = (Trait t) => { return(GetTraitTip(t, currentPawn)); }, SelectedFunc = (Trait t) => { if ((selectedTrait == null || t == null) && selectedTrait != t) { return(false); } return(selectedTrait.def == t.def && selectedTrait.Label == t.Label); }, SelectAction = (Trait t) => { selectedTrait = t; }, EnabledFunc = (Trait t) => { return(!disallowedTraitDefs.Contains(t.def)); }, CloseAction = () => { TraitUpdated(localIndex, selectedTrait); }, NoneSelectedFunc = () => { return(selectedTrait == null); }, SelectNoneAction = () => { selectedTrait = null; } }; Find.WindowStack.Add(dialog); }; field.PreviousAction = () => { var capturedIndex = index; clickAction = () => { SelectPreviousTrait(currentPawn, capturedIndex); }; }; field.NextAction = () => { var capturedIndex = index; clickAction = () => { SelectNextTrait(currentPawn, capturedIndex); }; }; field.Draw(); // Remove trait button. Rect deleteRect = new Rect(field.Rect.xMax - 32, field.Rect.y + field.Rect.HalfHeight() - 6, 12, 12); if (deleteRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(deleteRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(deleteRect, false)) { SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(); traitsToRemove.Add(trait); } index++; cursor += SizeTrait.y + SizeTraitMargin.y; } cursor -= SizeTraitMargin.y; } finally { scrollView.End(cursor); GUI.EndGroup(); } tipCache.MakeReady(); GUI.color = Color.white; if (clickAction != null) { clickAction(); clickAction = null; } // Randomize traits button. Rect randomizeRect = new Rect(PanelRect.width - 32, 9, 22, 22); if (randomizeRect.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(randomizeRect, Textures.TextureButtonRandom); if (Widgets.ButtonInvisible(randomizeRect, false)) { SoundDefOf.Tick_Low.PlayOneShotOnCamera(); tipCache.Invalidate(); TraitsRandomized(); } // Add trait button. Rect addRect = new Rect(randomizeRect.x - 24, 12, 16, 16); Style.SetGUIColorForButton(addRect); int traitCount = state.CurrentPawn.Traits.Count(); bool addButtonEnabled = (state.CurrentPawn != null && traitCount < Constraints.MaxTraits); if (!addButtonEnabled) { GUI.color = Style.ColorButtonDisabled; } GUI.DrawTexture(addRect, Textures.TextureButtonAdd); if (addButtonEnabled && Widgets.ButtonInvisible(addRect, false)) { ComputeDisallowedTraits(currentPawn, null); SoundDefOf.Tick_Low.PlayOneShotOnCamera(); Trait selectedTrait = null; Dialog_Options <Trait> dialog = new Dialog_Options <Trait>(providerTraits.Traits) { ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(), NameFunc = (Trait t) => { return(t.LabelCap); }, DescriptionFunc = (Trait t) => { return(GetTraitTip(t, state.CurrentPawn)); }, SelectedFunc = (Trait t) => { return(selectedTrait == t); }, SelectAction = (Trait t) => { selectedTrait = t; }, EnabledFunc = (Trait t) => { return(!disallowedTraitDefs.Contains(t.def)); }, CloseAction = () => { if (selectedTrait != null) { TraitAdded(selectedTrait); tipCache.Invalidate(); } } }; Find.WindowStack.Add(dialog); } if (traitsToRemove.Count > 0) { foreach (var trait in traitsToRemove) { TraitRemoved(trait); } traitsToRemove.Clear(); tipCache.Invalidate(); } }
protected void ShowAddRelationshipDialogs() { CustomPawn sourceParentChildPawn = null; PawnRelationDef selectedRelationship = null; CustomPawn targetParentChildPawn = null; Dialog_Options <PawnRelationDef> relationshipDialog = new Dialog_Options <PawnRelationDef>(null) { ConfirmButtonLabel = "EdB.PC.Common.Next".Translate(), CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(), HeaderLabel = "EdB.PC.AddRelationship.Header.Relationship".Translate(), NameFunc = (PawnRelationDef def) => { return(def.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn)); }, SelectedFunc = (PawnRelationDef def) => { return(def == selectedRelationship); }, SelectAction = (PawnRelationDef def) => { selectedRelationship = def; }, EnabledFunc = (PawnRelationDef d) => { return(!disabledRelationships.Contains(d)); }, ConfirmValidation = () => { if (selectedRelationship == null) { return("EdB.PC.AddRelationship.Error.RelationshipRequired"); } else { return(null); } } }; List <WidgetTable <CustomPawn> .RowGroup> sourceRowGroups = new List <WidgetTable <CustomPawn> .RowGroup>(); sourceRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.SelectColonist".Translate(), PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => { return(pawn.Type == CustomPawnType.Colonist); }))); List <CustomPawn> hiddenPawnsForSource = PrepareCarefully.Instance.RelationshipManager.HiddenPawns.ToList(); hiddenPawnsForSource.Sort((a, b) => { if (a.Type != b.Type) { return(a.Type == CustomPawnType.Hidden ? -1 : 1); } else { int aInt = a.Index == null ? 0 : a.Index.Value; int bInt = b.Index == null ? 0 : b.Index.Value; return(aInt.CompareTo(bInt)); } }); sourceRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("<b>" + "EdB.PC.AddParentChild.Header.SelectWorldPawn".Translate() + "</b>", PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => { return(pawn.Type != CustomPawnType.Colonist); }).Concat(hiddenPawnsForSource))); WidgetTable <CustomPawn> .RowGroup sourceNewPawnGroup = new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.CreateTemporaryPawn".Translate(), PrepareCarefully.Instance.RelationshipManager.TemporaryPawns); sourceRowGroups.Add(sourceNewPawnGroup); DialogSelectParentChildPawn sourcePawnDialog = new DialogSelectParentChildPawn() { HeaderLabel = "EdB.PC.AddRelationship.Header.Source".Translate(), SelectAction = (CustomPawn pawn) => { sourceParentChildPawn = pawn; }, RowGroups = sourceRowGroups, DisabledPawns = null, ConfirmValidation = () => { if (sourceParentChildPawn == null) { return("EdB.PC.AddRelationship.Error.SourceRequired"); } else { return(null); } }, CloseAction = () => { // If the user selected a new pawn, replace the pawn in the new pawn list with another one. int index = sourceNewPawnGroup.Rows.FirstIndexOf((CustomPawn p) => { return(p == targetParentChildPawn); }); if (index > -1 && index < PrepareCarefully.Instance.RelationshipManager.TemporaryPawns.Count) { targetParentChildPawn = PrepareCarefully.Instance.RelationshipManager.ReplaceNewTemporaryCharacter(index); } } }; DialogSelectParentChildPawn targetPawnDialog = new DialogSelectParentChildPawn() { HeaderLabel = "EdB.PC.AddRelationship.Header.Target".Translate(), SelectAction = (CustomPawn pawn) => { targetParentChildPawn = pawn; }, RowGroups = null, // To be filled out later DisabledPawns = null, // To be filled out later ConfirmValidation = () => { if (sourceParentChildPawn == null) { return("EdB.PC.AddRelationship.Error.TargetRequired"); } else { return(null); } } }; WidgetTable <CustomPawn> .RowGroup targetNewPawnGroup = null; sourcePawnDialog.CloseAction = () => { List <PawnRelationDef> relationDefs = PrepareCarefully.Instance.RelationshipManager.AllowedRelationships.Select((PawnRelationDef def) => { return(def); }).ToList(); relationDefs.Sort((PawnRelationDef a, PawnRelationDef b) => { return(a.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn).CompareTo(b.GetGenderSpecificLabelCap(sourceParentChildPawn.Pawn))); }); relationshipDialog.Options = relationDefs; Find.WindowStack.Add(relationshipDialog); }; relationshipDialog.CloseAction = () => { SetDisabledTargets(sourceParentChildPawn, selectedRelationship); targetPawnDialog.DisabledPawns = disabledTargets; List <WidgetTable <CustomPawn> .RowGroup> targetRowGroups = new List <WidgetTable <CustomPawn> .RowGroup>(); targetRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.SelectColonist".Translate(), PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => { return(pawn.Type == CustomPawnType.Colonist && pawn != sourceParentChildPawn); }))); List <CustomPawn> hiddenPawnsForTarget = PrepareCarefully.Instance.RelationshipManager.HiddenPawns.ToList(); hiddenPawnsForTarget.Sort((a, b) => { if (a.Type != b.Type) { return(a.Type == CustomPawnType.Hidden ? -1 : 1); } else { int aInt = a.Index == null ? 0 : a.Index.Value; int bInt = b.Index == null ? 0 : b.Index.Value; return(aInt.CompareTo(bInt)); } }); targetRowGroups.Add(new WidgetTable <CustomPawn> .RowGroup("<b>" + "EdB.PC.AddParentChild.Header.SelectWorldPawn".Translate() + "</b>", PrepareCarefully.Instance.RelationshipManager.ColonyAndWorldPawns.Where((CustomPawn pawn) => { return(pawn.Type != CustomPawnType.Colonist && pawn != sourceParentChildPawn); }).Concat(hiddenPawnsForTarget))); targetNewPawnGroup = new WidgetTable <CustomPawn> .RowGroup("EdB.PC.AddParentChild.Header.CreateTemporaryPawn".Translate(), PrepareCarefully.Instance.RelationshipManager.TemporaryPawns); targetRowGroups.Add(targetNewPawnGroup); targetPawnDialog.RowGroups = targetRowGroups; Find.WindowStack.Add(targetPawnDialog); }; targetPawnDialog.CloseAction = () => { // If the user selected a new pawn, replace the pawn in the new pawn list with another one. int index = targetNewPawnGroup.Rows.FirstIndexOf((CustomPawn p) => { return(p == targetParentChildPawn); }); if (index > -1 && index < PrepareCarefully.Instance.RelationshipManager.TemporaryPawns.Count) { targetParentChildPawn = PrepareCarefully.Instance.RelationshipManager.ReplaceNewTemporaryCharacter(index); } this.RelationshipAdded(PrepareCarefully.Instance.RelationshipManager.FindInverseRelationship(selectedRelationship), sourceParentChildPawn, targetParentChildPawn); }; Find.WindowStack.Add(sourcePawnDialog); }
public void DrawHeader() { GUI.BeginGroup(RectHeader); GUI.color = Color.white; // Injury button. if (Widgets.ButtonText(new Rect(0, 0, 120, 28), "EdB.PrepareCarefully.AddInjury".Translate(), true, true, true)) { CustomPawn customPawn = PrepareCarefully.Instance.State.CurrentPawn; InjuryOption selectedInjury = null; BodyPartRecord selectedBodyPart = null; bool bodyPartSelectionRequired = true; InjurySeverity selectedSeverity = null; Dialog_Options <InjurySeverity> severityDialog; Dialog_Options <BodyPartRecord> bodyPartDialog; ResetInjuryOptionEnabledState(customPawn); Action addInjuryAction = () => { if (bodyPartSelectionRequired) { AddInjuryToPawn(customPawn, selectedInjury, selectedSeverity, selectedBodyPart); } else { if (selectedInjury.ValidParts.Count > 0) { foreach (var p in selectedInjury.ValidParts) { BodyPartRecord record = PrepareCarefully.Instance.HealthManager.FirstBodyPartRecord(customPawn, p); if (record != null) { AddInjuryToPawn(customPawn, selectedInjury, selectedSeverity, record); } else { Log.Warning("Could not find body part record for definition: " + p.defName); } } } else { AddInjuryToPawn(customPawn, selectedInjury, selectedSeverity, null); } } }; severityDialog = new Dialog_Options <InjurySeverity>(severityOptions) { ConfirmButtonLabel = "EdB.PrepareCarefully.Add", CancelButtonLabel = "EdB.PrepareCarefully.Cancel", HeaderLabel = "EdB.PrepareCarefully.SelectSeverity", NameFunc = (InjurySeverity option) => { if (!string.IsNullOrEmpty(option.Label)) { return(option.Label); } else { return(selectedInjury.HediffDef.LabelCap); } }, SelectedFunc = (InjurySeverity option) => { return(option == selectedSeverity); }, SelectAction = (InjurySeverity option) => { selectedSeverity = option; }, ConfirmValidation = () => { if (selectedSeverity == null) { return("EdB.PrepareCarefully.ErrorMustSelectSeverity"); } else { return(null); } }, CloseAction = () => { addInjuryAction(); } }; bodyPartDialog = new Dialog_Options <BodyPartRecord>(null) { ConfirmButtonLabel = "EdB.PrepareCarefully.Add", CancelButtonLabel = "EdB.PrepareCarefully.Cancel", HeaderLabel = "EdB.PrepareCarefully.SelectBodyPart", NameFunc = (BodyPartRecord option) => { return(option.def.LabelCap); }, SelectedFunc = (BodyPartRecord option) => { return(option == selectedBodyPart); }, SelectAction = (BodyPartRecord option) => { selectedBodyPart = option; }, EnabledFunc = (BodyPartRecord option) => { return(!disabledBodyParts.Contains(option)); }, ConfirmValidation = () => { if (selectedBodyPart == null) { return("EdB.PrepareCarefully.ErrorMustSelectBodyPart"); } else { return(null); } }, CloseAction = () => { if (this.severityOptions.Count > 1) { Find.WindowStack.Add(severityDialog); } else { if (severityOptions.Count > 0) { selectedSeverity = this.severityOptions[0]; } addInjuryAction(); } } }; Dialog_Options <InjuryOption> injuryOptionDialog = new Dialog_Options <InjuryOption>(PrepareCarefully.Instance.HealthManager.InjuryManager.Options) { ConfirmButtonLabel = "EdB.PrepareCarefully.Next", CancelButtonLabel = "EdB.PrepareCarefully.Cancel", HeaderLabel = "EdB.PrepareCarefully.SelectInjury", NameFunc = (InjuryOption option) => { return(option.Label); }, SelectedFunc = (InjuryOption option) => { return(selectedInjury == option); }, SelectAction = (InjuryOption option) => { selectedInjury = option; if (option.ValidParts == null) { bodyPartSelectionRequired = true; } else { bodyPartSelectionRequired = false; } }, EnabledFunc = (InjuryOption option) => { return(!disabledInjuryOptions.Contains(option)); }, ConfirmValidation = () => { if (selectedInjury == null) { return("EdB.PrepareCarefully.ErrorMustSelectInjury"); } else { return(null); } }, CloseAction = () => { ResetSeverityOptions(selectedInjury); if (bodyPartSelectionRequired) { bodyPartDialog.Options = PrepareCarefully.Instance.HealthManager.AllSkinCoveredBodyParts(customPawn); ResetBodyPartEnabledState(bodyPartDialog.Options, customPawn); Find.WindowStack.Add(bodyPartDialog); } else if (severityOptions.Count > 1) { Find.WindowStack.Add(severityDialog); } else { if (severityOptions.Count > 0) { selectedSeverity = this.severityOptions[0]; } addInjuryAction(); } } }; Find.WindowStack.Add(injuryOptionDialog); } // Implant button. if (Widgets.ButtonText(new Rect(RectHeader.width - 120, 0, 120, 28), "EdB.PrepareCarefully.AddImplant".Translate(), true, true, true)) { CustomPawn customPawn = PrepareCarefully.Instance.State.CurrentPawn; RecipeDef selectedRecipe = null; BodyPartRecord selectedBodyPart = null; bool bodyPartSelectionRequired = true; Dialog_Options <BodyPartRecord> bodyPartDialog = new Dialog_Options <BodyPartRecord>(null) { ConfirmButtonLabel = "EdB.PrepareCarefully.Add", CancelButtonLabel = "EdB.PrepareCarefully.Cancel", HeaderLabel = "EdB.PrepareCarefully.SelectBodyPart", NameFunc = (BodyPartRecord record) => { return(record.def.LabelCap); }, SelectedFunc = (BodyPartRecord record) => { return(record == selectedBodyPart); }, SelectAction = (BodyPartRecord record) => { selectedBodyPart = record; }, EnabledFunc = (BodyPartRecord record) => { return(!disabledBodyParts.Contains(record)); }, ConfirmValidation = () => { if (selectedBodyPart == null) { return("EdB.PrepareCarefully.ErrorMustSelectBodyPart"); } else { return(null); } }, CloseAction = () => { customPawn.AddImplant(new Implant(selectedBodyPart, selectedRecipe)); } }; Dialog_Options <RecipeDef> implantRecipeDialog = new Dialog_Options <RecipeDef>(PrepareCarefully.Instance.HealthManager.ImplantManager.RecipesForPawn(customPawn)) { ConfirmButtonLabel = "EdB.PrepareCarefully.Next", CancelButtonLabel = "EdB.PrepareCarefully.Cancel", HeaderLabel = "EdB.PrepareCarefully.SelectImplant", NameFunc = (RecipeDef recipe) => { return(recipe.LabelCap); }, SelectedFunc = (RecipeDef recipe) => { return(selectedRecipe == recipe); }, SelectAction = (RecipeDef recipe) => { selectedRecipe = recipe; IEnumerable <BodyPartRecord> bodyParts = PrepareCarefully.Instance.HealthManager.ImplantManager.PartsForRecipe(customPawn.Pawn, recipe); int bodyPartCount = bodyParts.Count(); if (bodyParts != null && bodyPartCount > 0) { if (bodyPartCount > 1) { selectedBodyPart = null; bodyPartDialog.Options = bodyParts; bodyPartSelectionRequired = true; ResetBodyPartEnabledState(bodyParts, customPawn); } else { selectedBodyPart = bodyParts.First(); bodyPartSelectionRequired = false; } } else { selectedBodyPart = null; bodyPartSelectionRequired = false; } }, ConfirmValidation = () => { if (selectedRecipe == null) { return("EdB.PrepareCarefully.ErrorMustSelectImplant"); } else { return(null); } }, CloseAction = () => { if (bodyPartSelectionRequired) { Find.WindowStack.Add(bodyPartDialog); } else { customPawn.AddImplant(new Implant(selectedBodyPart, selectedRecipe)); } } }; Find.WindowStack.Add(implantRecipeDialog); } GUI.EndGroup(); }
public void DrawHeader() { GUI.BeginGroup(RectHeader); GUI.color = Color.white; // TODO: Disable button if there's only one pawn? What about other pawns, i.e. faction leaders, etc. if (Widgets.ButtonText(RectAddButton, "EdB.PrepareCarefully.AddRelationship".Translate(), true, true, true)) { CustomPawn customPawn = PrepareCarefully.Instance.State.CurrentPawn; PawnRelationDef selectedRelationship = null; CustomPawn selectedPawn = null; List <CustomPawn> otherPawns = PrepareCarefully.Instance.Pawns.FindAll((CustomPawn p) => { return(p != customPawn); }); Dialog_Options <PawnRelationDef> relationshipDialog = new Dialog_Options <PawnRelationDef>(null) { ConfirmButtonLabel = "EdB.PrepareCarefully.Add", CancelButtonLabel = "EdB.PrepareCarefully.Cancel", HeaderLabel = "EdB.PrepareCarefully.SelectRelationship", NameFunc = (PawnRelationDef def) => { return(def.GetGenderSpecificLabelCap(selectedPawn.Pawn)); }, SelectedFunc = (PawnRelationDef def) => { return(def == selectedRelationship); }, SelectAction = (PawnRelationDef def) => { selectedRelationship = def; }, EnabledFunc = (PawnRelationDef d) => { return(!disabledRelationships.Contains(d)); }, ConfirmValidation = () => { if (selectedRelationship == null) { return("EdB.PrepareCarefully.ErrorMustSelectRelationship"); } else { return(null); } }, CloseAction = () => { PrepareCarefully.Instance.RelationshipManager.AddRelationship(selectedRelationship, customPawn, selectedPawn); } }; Dialog_Options <CustomPawn> colonistDialog = new Dialog_Options <CustomPawn>(otherPawns) { ConfirmButtonLabel = "EdB.PrepareCarefully.Next", CancelButtonLabel = "EdB.PrepareCarefully.Cancel", HeaderLabel = "EdB.PrepareCarefully.SelectColonist", NameFunc = (CustomPawn pawn) => { return(pawn.Name.ToStringFull); }, SelectedFunc = (CustomPawn pawn) => { return(pawn == selectedPawn); }, SelectAction = (CustomPawn pawn) => { selectedPawn = pawn; }, ConfirmValidation = () => { if (selectedPawn == null) { return("EdB.PrepareCarefully.ErrorMustSelectColonist"); } else { return(null); } }, CloseAction = () => { SetDisabledRelationships(selectedPawn); List <PawnRelationDef> relationDefs = new List <PawnRelationDef>(PrepareCarefully.Instance.RelationshipManager.AllowedRelationships); relationDefs.Sort((PawnRelationDef a, PawnRelationDef b) => { return(a.GetGenderSpecificLabelCap(selectedPawn.Pawn).CompareTo(b.GetGenderSpecificLabelCap(selectedPawn.Pawn))); }); relationshipDialog.Options = relationDefs; Find.WindowStack.Add(relationshipDialog); } }; Find.WindowStack.Add(colonistDialog); } GUI.EndGroup(); }
public void DrawAddButton() { if (RectButtonAdd.Contains(Event.current.mousePosition)) { GUI.color = Style.ColorButtonHighlight; } else { GUI.color = Style.ColorButton; } GUI.DrawTexture(RectButtonAdd, Textures.TextureButtonAdd); // Add button. if (Widgets.ButtonInvisible(RectButtonAdd, false)) { CustomPawn customPawn = PrepareCarefully.Instance.State.CurrentPawn; Action addEntryAction = () => { }; OptionsHealth healthOptions = PrepareCarefully.Instance.Providers.Health.GetOptions(customPawn); string selectedHediffType = this.selectedHediffType; RecipeDef selectedRecipe = null; InjuryOption selectedInjury = null; BodyPartRecord selectedBodyPart = null; bool bodyPartSelectionRequired = true; InjurySeverity selectedSeverity = null; Dialog_Options <InjurySeverity> severityDialog; Dialog_Options <BodyPartRecord> bodyPartDialog; Dialog_Options <InjuryOption> injuryOptionDialog; //Dialog_Options<RecipeDef> implantRecipeDialog; DialogManageImplants manageImplantsDialog; Dialog_Options <string> hediffTypeDialog; ResetDisabledInjuryOptions(customPawn); Action addInjuryAction = () => { if (bodyPartSelectionRequired) { AddInjuryToPawn(selectedInjury, selectedSeverity, selectedBodyPart); } else { if (selectedInjury.ValidParts != null && selectedInjury.ValidParts.Count > 0) { foreach (var p in selectedInjury.ValidParts) { var part = healthOptions.FindBodyPartsForDef(p).FirstOrDefault(); if (part != null) { AddInjuryToPawn(selectedInjury, selectedSeverity, part.Record); } else { Log.Warning("Could not find body part record for definition: " + p.defName); } } } else { AddInjuryToPawn(selectedInjury, selectedSeverity, null); } } }; severityDialog = new Dialog_Options <InjurySeverity>(severityOptions) { ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(), CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(), HeaderLabel = "EdB.PC.Panel.Health.SelectSeverity".Translate(), NameFunc = (InjurySeverity option) => { if (!string.IsNullOrEmpty(option.Label)) { return(option.Label); } else { return(selectedInjury.HediffDef.LabelCap); } }, SelectedFunc = (InjurySeverity option) => { return(option == selectedSeverity); }, SelectAction = (InjurySeverity option) => { selectedSeverity = option; }, ConfirmValidation = () => { if (selectedSeverity == null) { return("EdB.PC.Panel.Health.Error.MustSelectSeverity"); } else { return(null); } }, CloseAction = () => { addInjuryAction(); } }; bodyPartDialog = new Dialog_Options <BodyPartRecord>(null) { ConfirmButtonLabel = "EdB.PC.Common.Add".Translate(), CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(), HeaderLabel = "EdB.PC.Dialog.BodyPart.Header".Translate(), NameFunc = (BodyPartRecord option) => { return(option.LabelCap); }, SelectedFunc = (BodyPartRecord option) => { return(option == selectedBodyPart); }, SelectAction = (BodyPartRecord option) => { selectedBodyPart = option; }, EnabledFunc = (BodyPartRecord option) => { return(!disabledBodyParts.Contains(option)); }, ConfirmValidation = () => { if (selectedBodyPart == null) { return("EdB.PC.Dialog.BodyPart.Error.Required"); } else { return(null); } }, CloseAction = () => { if (selectedHediffType == HediffTypeInjury) { if (this.severityOptions.Count > 1) { Find.WindowStack.Add(severityDialog); } else { if (severityOptions.Count > 0) { selectedSeverity = this.severityOptions[0]; } addInjuryAction(); } } else if (selectedHediffType == HediffTypeImplant) { ImplantAdded(new Implant(selectedBodyPart, selectedRecipe)); } } }; injuryOptionDialog = new Dialog_Options <InjuryOption>(healthOptions.InjuryOptions) { ConfirmButtonLabel = "EdB.PC.Common.Next".Translate(), CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(), HeaderLabel = "EdB.PC.Dialog.Injury.Header".Translate(), NameFunc = (InjuryOption option) => { return(option.Label); }, SelectedFunc = (InjuryOption option) => { return(selectedInjury == option); }, SelectAction = (InjuryOption option) => { selectedInjury = option; if (option.ValidParts == null && !option.WholeBody) { bodyPartSelectionRequired = true; } else if (option.ValidParts != null && option.ValidParts.Count > 0) { bodyPartSelectionRequired = true; } else { bodyPartSelectionRequired = false; } }, EnabledFunc = (InjuryOption option) => { return(!disabledInjuryOptions.Contains(option)); }, ConfirmValidation = () => { if (selectedInjury == null) { return("EdB.PC.Dialog.Injury.Error.Required"); } else { return(null); } }, CloseAction = () => { ResetSeverityOptions(selectedInjury); if (bodyPartSelectionRequired) { bodyPartDialog.Options = healthOptions.BodyPartsForInjury(selectedInjury); int count = bodyPartDialog.Options.Count(); if (count > 1) { ResetDisabledBodyParts(bodyPartDialog.Options, customPawn); Find.WindowStack.Add(bodyPartDialog); return; } else if (count == 1) { selectedBodyPart = bodyPartDialog.Options.First(); } } if (severityOptions.Count > 1) { Find.WindowStack.Add(severityDialog); } else { if (severityOptions.Count > 0) { selectedSeverity = this.severityOptions[0]; } addInjuryAction(); } } }; hediffTypeDialog = new Dialog_Options <string>(new string[] { HediffTypeInjury, HediffTypeImplant }) { ConfirmButtonLabel = "EdB.PC.Common.Next".Translate(), CancelButtonLabel = "EdB.PC.Common.Cancel".Translate(), NameFunc = (string type) => { return(("EdB.PC.Panel.Health." + type).Translate()); }, SelectedFunc = (string type) => { return(selectedHediffType == type); }, SelectAction = (string type) => { selectedHediffType = type; }, ConfirmValidation = () => { if (selectedHediffType == null) { return("EdB.PC.Panel.Health.Error.MustSelectOption"); } else { return(null); } }, CloseAction = () => { this.selectedHediffType = selectedHediffType; if (selectedHediffType == HediffTypeInjury) { Find.WindowStack.Add(injuryOptionDialog); } else { ResetDisabledImplantRecipes(customPawn); manageImplantsDialog = new DialogManageImplants(customPawn) { HeaderLabel = "EdB.PC.Dialog.Implant.Header".Translate(), CloseAction = (List <Implant> implants) => { ApplyImplantsToPawn(customPawn, implants); } }; Find.WindowStack.Add(manageImplantsDialog); } } }; Find.WindowStack.Add(hediffTypeDialog); } }