protected override void DrawPanelContent()
        {
            base.DrawPanelContent();

            float cursor = 0;

            GUI.color = Color.white;
            GUI.BeginGroup(RectScrollFrame);
            try
            {
                if (pawnFilter.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 pawnFilter.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;
                        Dialog_Options <Trait> dialog = new Dialog_Options <Trait>(providerTraits.Traits)
                        {
                            NameFunc = (Trait t) => {
                                return(t.LabelCap);
                            },
                            DescriptionFunc = (Trait t) => {
                                return(null);
                                //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 = () => {
                        SelectPreviousTrait(index);
                    };
                    field.NextAction = () => {
                        SelectNextTrait(index);
                    };
                    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))
                    {
                        // TODO SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
                        traitsToRemove.Add(trait);
                    }

                    index++;

                    cursor += SizeTrait.y + SizeTraitMargin.y;
                }
                cursor -= SizeTraitMargin.y;
            }
            finally
            {
                scrollView.End(cursor);
                GUI.EndGroup();
            }

            GUI.color = Color.white;

            // 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();
            //    TraitsRandomized();
            //}

            // Add trait button.
            Rect addRect = new Rect(PanelRect.width - 24, 12, 16, 16);

            Style.SetGUIColorForButton(addRect);
            int  traitCount       = pawnFilter.Traits.Count();
            bool addButtonEnabled = (traitCount < 3);

            if (!addButtonEnabled)
            {
                GUI.color = Style.ColorButtonDisabled;
            }
            GUI.DrawTexture(addRect, Textures.TextureButtonAdd);
            if (addButtonEnabled && Widgets.ButtonInvisible(addRect, false))
            {
                ComputeDisallowedTraits(null);
                // TODO 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);
                    },
                    // TODO
//                    DescriptionFunc = (Trait t) => {
//                        return null;
////                        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);
                        }
                    }
                };

                Find.WindowStack.Add(dialog);
            }

            if (traitsToRemove.Count > 0)
            {
                foreach (var trait in traitsToRemove)
                {
                    TraitRemoved(trait);
                }
                traitsToRemove.Clear();
            }
        }
Example #2
0
        protected override void DrawPanelContent()
        {
            base.DrawPanelContent();

            if (Page_RandomEditor.MOD_WELL_MET)
            {
                Widgets.Label(disabledLabelRect, "RandomPlus.PanelTraits.Disabled".Translate());
                return;
            }

            float cursor = 0;

            GUI.color = Color.white;
            GUI.BeginGroup(RectScrollFrame);
            try
            {
                if (!RandomSettings.PawnFilter.Traits.Any())
                {
                    GUI.color = Style.ColorText;
                    Widgets.Label(RectScrollView.InsetBy(6, 0, 0, 0), "RandomPlus.PanelTraits.NoTraits".Translate());
                }
                GUI.color = Color.white;

                scrollView.Begin(RectScrollView);

                int index = 0;
                foreach (TraitContainer traitContainer in RandomSettings.PawnFilter.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 (traitContainer != null)
                    {
                        field.Label = $"{traitContainer.trait.LabelCap}{LabelForTraitFilter(index)} {RandomSettings.GetTraitRollChanceText(traitContainer.trait.def)}";
                        field.Tip   = traitContainer.trait.CurrentData.description;
                    }
                    else
                    {
                        field.Label = null;
                    }
                    Trait localTrait = traitContainer.trait;
                    int   localIndex = index;
                    field.ClickAction = () =>
                    {
                        Trait originalTrait = localTrait;
                        Trait selectedTrait = originalTrait;
                        ComputeDisallowedTraits(originalTrait);
                        Dialog_Options <Trait> dialog = new Dialog_Options <Trait>(ProviderTraits.Traits)
                        {
                            NameFunc = (Trait t) =>
                            {
                                return(t.LabelCap);
                            },
                            DescriptionFunc = (Trait t) =>
                            {
                                return(t.CurrentData.description);
                            },
                            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) =>
                            {
                                // filter out conflicting traits
                                return(!(disallowedTraitDefs.Contains(t.def) || disallowedTraitLabels.Contains(t.Label)));
                            },
                            CloseAction = () =>
                            {
                                RandomSettings.PawnFilter.TraitUpdated(localIndex, selectedTrait);
                            },
                            NoneSelectedFunc = () =>
                            {
                                return(selectedTrait == null);
                            },
                            SelectNoneAction = () =>
                            {
                                selectedTrait = null;
                            }
                        };
                        Find.WindowStack.Add(dialog);
                    };
                    //field.PreviousAction = () =>
                    //{
                    //    SelectPreviousTrait(index);
                    //};
                    //field.NextAction = () =>
                    //{
                    //    SelectNextTrait(index);
                    //};
                    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(traitContainer.trait);
                    }

                    //cycling required/ optional / exluded trait filter button
                    Rect traitFilterTypeRect = new Rect(field.Rect.xMax + 12, field.Rect.y + field.Rect.HalfHeight() - 6, 12, 12);
                    GUI.color = traitFilterTypeRect.Contains(Event.current.mousePosition) ?
                                Style.ColorButtonHighlight : Style.ColorButton;
                    GUI.DrawTexture(traitFilterTypeRect, Textures.TextureButtonReset);
                    if (Widgets.ButtonInvisible(traitFilterTypeRect, false))
                    {
                        SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
                        CycleTraitFilter(index);
                    }

                    index++;

                    cursor += SizeTrait.y + SizeTraitMargin.y;
                }
                cursor -= SizeTraitMargin.y;
            }
            finally
            {
                scrollView.End(cursor);

                GUI.color = Color.white;
                drawTraitPool();
                GUI.EndGroup();
            }

            // Add trait button.
            Rect addRect = new Rect(PanelRect.width - 24, 12, 16, 16);

            Style.SetGUIColorForButton(addRect);
            int  traitCount       = RandomSettings.PawnFilter.Traits.Count();
            bool addButtonEnabled = (traitCount < ProviderTraits.Traits.Count());

            if (!addButtonEnabled)
            {
                GUI.color = Style.ColorButtonDisabled;
            }
            GUI.DrawTexture(addRect, Textures.TextureButtonAdd);
            if (addButtonEnabled && Widgets.ButtonInvisible(addRect, false))
            {
                ComputeDisallowedTraits(null);
                SoundDefOf.Tick_Low.PlayOneShotOnCamera();
                Trait selectedTrait           = null;
                Dialog_Options <Trait> dialog = new Dialog_Options <Trait>(ProviderTraits.Traits)
                {
                    ConfirmButtonLabel = "RandomPlus.PanelTraits.AddDialog.AddButton".Translate(),
                    NameFunc           = (Trait t) => {
                        return($"{t.LabelCap} {RandomSettings.GetTraitRollChanceText(t.def)}");
                    },
                    DescriptionFunc = (Trait t) => {
                        return(t.CurrentData.description);
                    },
                    SelectedFunc = (Trait t) => {
                        return(selectedTrait == t);
                    },
                    SelectAction = (Trait t) => {
                        selectedTrait = t;
                    },
                    EnabledFunc = (Trait t) => {
                        return(!(disallowedTraitDefs.Contains(t.def) || disallowedTraitLabels.Contains(t.Label)));
                    },
                    CloseAction = () => {
                        if (selectedTrait != null)
                        {
                            RandomSettings.PawnFilter.AddTrait(selectedTrait);
                        }
                    }
                };
                Find.WindowStack.Add(dialog);
            }

            if (traitsToRemove.Count > 0)
            {
                foreach (var trait in traitsToRemove)
                {
                    RandomSettings.PawnFilter.TraitRemoved(trait);
                }
                traitsToRemove.Clear();
            }
        }