Exemplo n.º 1
0
        protected OptionsHair InitializeHairs(ThingDef raceDef)
        {
            AlienRace alienRace = AlienRaceProvider.GetAlienRace(raceDef);

            if (alienRace == null)
            {
                return(HumanlikeHairs);
            }
            if (!alienRace.HasHair)
            {
                return(noHair);
            }
            // If the alien race does not have a limited set of hairs, then we'll try to re-use the humanlike hair options.
            if (alienRace.HairTags == null)
            {
                // If the selection of hairs is the same and the alien race has no custom color generator, then
                // we can just re-use the humanlike hair options.
                if (alienRace.HairColors == null)
                {
                    return(HumanlikeHairs);
                }
                // If there is a custom color generator, then we make a copy of the humanlike hair options--preserving
                // the HairDef lists--but we replace the color list.
                else
                {
                    OptionsHair humanHairs           = HumanlikeHairs;
                    OptionsHair humanHairsWithColors = new OptionsHair();
                    humanHairsWithColors.MaleHairs     = humanHairs.MaleHairs;
                    humanHairsWithColors.FemaleHairs   = humanHairs.FemaleHairs;
                    humanHairsWithColors.NoGenderHairs = humanHairs.NoGenderHairs;
                    humanHairsWithColors.Colors        = alienRace.HairColors.ToList();
                    return(humanHairsWithColors);
                }
            }
            OptionsHair result = new OptionsHair();

            foreach (HairDef hairDef in DefDatabase <HairDef> .AllDefs.Where((HairDef def) => {
                foreach (var tag in def.hairTags)
                {
                    if (alienRace.HairTags.Contains(tag))
                    {
                        return(true);
                    }
                }
                return(false);
            }))
            {
                result.AddHair(hairDef);
            }

            if (alienRace.HairColors != null)
            {
                result.Colors = alienRace.HairColors.ToList();
            }

            result.Sort();
            return(result);
        }
        protected OptionsHair InitializeHumanlikeHairs()
        {
            HashSet <string> nonHumanHairTags = new HashSet <string>();
            // This was meant to remove alien race-specific hair defs from those available when customizing non-aliens.
            // However, there's no way to distinguish between hair tags that are ONLY for aliens vs. the non-alien
            // hair defs that are also allow for aliens.  This makes the logic below fail.  Instead, we'll include
            // all hair def (both alien and non-alien) in the list of available hairs for non-aliens.
            // TODO: Implement filtering in the hair selection to make it easier to find appropriate hairs when there
            // are a lot of mods that add hairs.

            /*
             * IEnumerable<ThingDef> alienRaces = DefDatabase<ThingDef>.AllDefs.Where((ThingDef def) => {
             *  return def.race != null && ProviderAlienRaces.IsAlienRace(def);
             * });
             * foreach (var alienRaceDef in alienRaces) {
             *  AlienRace alienRace = AlienRaceProvider.GetAlienRace(alienRaceDef);
             *  if (alienRace == null) {
             *      continue;
             *  }
             *  if (alienRace.HairTags != null) {
             *      foreach (var tag in alienRace.HairTags) {
             *          nonHumanHairTags.Add(tag);
             *      }
             *  }
             * }
             */
            OptionsHair result = new OptionsHair();

            foreach (HairDef hairDef in DefDatabase <HairDef> .AllDefs.Where((HairDef def) => {
                foreach (var tag in def.hairTags)
                {
                    if (nonHumanHairTags.Contains(tag))
                    {
                        return(false);
                    }
                }
                return(true);
            }))
            {
                result.AddHair(hairDef);
            }
            result.Sort();

            // Set up default hair colors
            result.Colors.Add(new Color(0.2f, 0.2f, 0.2f));
            result.Colors.Add(new Color(0.31f, 0.28f, 0.26f));
            result.Colors.Add(new Color(0.25f, 0.2f, 0.15f));
            result.Colors.Add(new Color(0.3f, 0.2f, 0.1f));
            result.Colors.Add(new Color(0.3529412f, 0.227451f, 0.1254902f));
            result.Colors.Add(new Color(0.5176471f, 0.3254902f, 0.1843137f));
            result.Colors.Add(new Color(0.7568628f, 0.572549f, 0.3333333f));
            result.Colors.Add(new Color(0.9294118f, 0.7921569f, 0.6117647f));

            return(result);
        }
Exemplo n.º 3
0
        protected OptionsHair InitializeHumanlikeHairs()
        {
            HashSet <string>       nonHumanHairTags = new HashSet <string>();
            IEnumerable <ThingDef> alienRaces       = DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => {
                return(def.race != null && ProviderAlienRaces.IsAlienRace(def));
            });

            foreach (var alienRaceDef in alienRaces)
            {
                AlienRace alienRace = AlienRaceProvider.GetAlienRace(alienRaceDef);
                if (alienRace == null)
                {
                    continue;
                }
                if (alienRace.HairTags != null)
                {
                    foreach (var tag in alienRace.HairTags)
                    {
                        nonHumanHairTags.Add(tag);
                    }
                }
            }
            OptionsHair result = new OptionsHair();

            foreach (HairDef hairDef in DefDatabase <HairDef> .AllDefs.Where((HairDef def) => {
                foreach (var tag in def.hairTags)
                {
                    if (nonHumanHairTags.Contains(tag))
                    {
                        return(false);
                    }
                }
                return(true);
            }))
            {
                result.AddHair(hairDef);
            }
            result.Sort();

            // Set up default hair colors
            result.Colors.Add(new Color(0.2f, 0.2f, 0.2f));
            result.Colors.Add(new Color(0.31f, 0.28f, 0.26f));
            result.Colors.Add(new Color(0.25f, 0.2f, 0.15f));
            result.Colors.Add(new Color(0.3f, 0.2f, 0.1f));
            result.Colors.Add(new Color(0.3529412f, 0.227451f, 0.1254902f));
            result.Colors.Add(new Color(0.5176471f, 0.3254902f, 0.1843137f));
            result.Colors.Add(new Color(0.7568628f, 0.572549f, 0.3333333f));
            result.Colors.Add(new Color(0.9294118f, 0.7921569f, 0.6117647f));

            return(result);
        }
Exemplo n.º 4
0
        private List <PawnLayer> InitializeAlienPawnLayers(ThingDef pawnDef, Gender gender, AlienRace race)
        {
            List <PawnLayer> layers = new List <PawnLayer>()
            {
                InitializeHairLayer(pawnDef, gender),
                InitializeHeadLayer(pawnDef, gender),
                InitializeBodyLayer(pawnDef, gender),
            };

            if (race.Addons != null)
            {
                OptionsHair optionsHair = PrepareCarefully.Instance.Providers.Hair.GetHairsForRace(pawnDef);
                foreach (var addon in race.Addons)
                {
                    PawnLayerAlienAddon layer = new PawnLayerAlienAddon();
                    layer.Name  = addon.Name;
                    layer.Label = addon.Name;
                    if (addon.Skin)
                    {
                        layer.Skin = true;
                    }
                    else
                    {
                        layer.Hair = true;
                        layer.ColorSelectorType = ColorSelectorType.RGB;
                        layer.ColorSwatches     = optionsHair.Colors;
                    }
                    layer.AlienAddon = addon;
                    layer.Options    = InitializeAlienAddonOptions(race, addon);
                    if (layer.Options == null || layer.Options.Count == 1)
                    {
                        continue;
                    }
                    layers.Add(layer);
                }
            }

            layers.AddRange(new PawnLayer[] {
                pantsLayer,
                bottomClothingLayer,
                middleClothingLayer,
                topClothingLayer,
                hatLayer,
                accessoryLayer
            });
            return(layers);
        }
        public List <HairDef> GetHairs(ThingDef raceDef, Gender gender)
        {
            OptionsHair hairs = GetHairsForRace(raceDef);

            return(hairs.GetHairs(gender));
        }
Exemplo n.º 6
0
        protected override void DrawPanelContent(State state)
        {
            base.DrawPanelContent(state);
            CustomPawn customPawn = state.CurrentPawn;

            string label = PawnLayers.Label(this.selectedPawnLayer);

            if (WidgetDropdown.Button(RectLayerSelector, label, true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                int layerCount = this.pawnLayerActions.Count;
                for (int i = 0; i < layerCount; i++)
                {
                    int pawnLayer = pawnLayers[i];
                    label = PawnLayers.Label(pawnLayers[i]);
                    list.Add(new FloatMenuOption(label, this.pawnLayerActions[i], MenuOptionPriority.Default, null, null, 0, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list, null, false));
            }
            GUI.DrawTexture(RectPortrait, Textures.TexturePortraitBackground);

            customPawn.UpdatePortrait();
            DrawPawn(customPawn, RectPortrait);

            GUI.color = ColorPortraitBorder;
            Widgets.DrawBox(RectPortrait, 1);
            GUI.color = Color.white;

            // Conflict alert
            if (customPawn.ApparelConflict != null)
            {
                GUI.color = Color.white;
                Rect alertRect = new Rect(RectPortrait.x + 77, RectPortrait.y + 150, 36, 32);
                GUI.DrawTexture(alertRect, Textures.TextureAlert);
                TooltipHandler.TipRegion(alertRect, customPawn.ApparelConflict);
            }

            // Draw selector field.
            Rect   fieldRect = new Rect(RectPortrait.x, RectPortrait.y + RectPortrait.height + 5, RectPortrait.width, 28);
            Action previousSelectionAction = null;
            Action nextSelectionAction     = null;
            Action clickAction             = null;

            OptionsApparel  apparelOptions = null;
            List <ThingDef> apparelList    = null;
            OptionsHair     hairOptions    = null;
            List <HairDef>  hairList       = null;

            if (this.selectedPawnLayer == PawnLayers.Hair)
            {
                hairOptions = PrepareCarefully.Instance.Providers.Hair.GetHairsForRace(customPawn);
                hairList    = hairOptions.GetHairs(customPawn.Gender);
            }
            else if (PawnLayers.IsApparelLayer(this.selectedPawnLayer))
            {
                apparelOptions = PrepareCarefully.Instance.Providers.Apparel.GetApparelForRace(customPawn);
                apparelList    = apparelOptions.GetApparel(this.selectedPawnLayer);
            }

            if (this.selectedPawnLayer == PawnLayers.HeadType)
            {
                int headTypeCount = PrepareCarefully.Instance.Providers.HeadTypes.GetHeadTypes(customPawn).Count();
                if (customPawn.HeadType != null && headTypeCount > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHead(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHead(customPawn, 1);
                    };
                }
                if (customPawn.HeadType != null && headTypeCount > 0)
                {
                    clickAction = () => {
                        ShowHeadDialog(customPawn);
                    };
                }
            }
            else if (this.selectedPawnLayer == PawnLayers.BodyType)
            {
                if (PrepareCarefully.Instance.Providers.BodyTypes.GetBodyTypesForPawn(customPawn.Pawn).Count > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextBodyType(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextBodyType(customPawn, 1);
                    };
                }
                clickAction = () => {
                    ShowBodyTypeDialog(customPawn);
                };
            }
            else if (this.selectedPawnLayer == PawnLayers.Hair)
            {
                if (hairList.Count > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHair(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextHair(customPawn, 1);
                    };
                }
                if (hairList.Count > 0)
                {
                    clickAction = () => {
                        ShowHairDialog(customPawn);
                    };
                }
            }
            else
            {
                if (apparelList.Count > 1)
                {
                    previousSelectionAction = () => {
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                        SelectNextApparel(customPawn, -1);
                    };
                    nextSelectionAction = () => {
                        SelectNextApparel(customPawn, 1);
                        SoundDefOf.TickTiny.PlayOneShotOnCamera();
                    };
                }
                if (apparelList.Count > 0)
                {
                    clickAction = () => {
                        ShowApparelDialog(customPawn, this.selectedPawnLayer);
                    };
                }
            }

            string selectorLabel = PawnLayerLabel.CapitalizeFirst();

            if (hairList != null && hairList.Count == 0)
            {
                selectorLabel = "EdB.PC.Common.NoOptionAvailable".Translate();
            }
            if (apparelList != null && apparelList.Count == 0)
            {
                selectorLabel = "EdB.PC.Common.NoOptionAvailable".Translate();
            }
            DrawFieldSelector(fieldRect, selectorLabel, previousSelectionAction, nextSelectionAction, clickAction);

            float cursorY = fieldRect.y + 34;

            // Draw stuff selector for apparel
            if (PawnLayers.IsApparelLayer(this.selectedPawnLayer))
            {
                ThingDef apparelDef = customPawn.GetSelectedApparel(selectedPawnLayer);
                if (apparelDef != null && apparelDef.MadeFromStuff)
                {
                    if (customPawn.GetSelectedStuff(selectedPawnLayer) == null)
                    {
                        Log.Error("Selected stuff for " + PawnLayers.ToApparelLayer(selectedPawnLayer) + " is null");
                    }
                    Rect stuffFieldRect = new Rect(RectPortrait.x, cursorY, RectPortrait.width, 28);
                    DrawFieldSelector(stuffFieldRect, customPawn.GetSelectedStuff(selectedPawnLayer).LabelCap,
                                      () => {
                        ThingDef selected = customPawn.GetSelectedStuff(selectedPawnLayer);
                        int index         = this.apparelStuffLookup[apparelDef].FindIndex((ThingDef d) => { return(selected == d); });
                        index--;
                        if (index < 0)
                        {
                            index = this.apparelStuffLookup[apparelDef].Count - 1;
                        }
                        customPawn.SetSelectedStuff(selectedPawnLayer, apparelStuffLookup[apparelDef][index]);
                    },
                                      () => {
                        ThingDef selected = customPawn.GetSelectedStuff(selectedPawnLayer);
                        int index         = this.apparelStuffLookup[apparelDef].FindIndex((ThingDef d) => { return(selected == d); });
                        index++;
                        if (index >= this.apparelStuffLookup[apparelDef].Count)
                        {
                            index = 0;
                        }
                        customPawn.SetSelectedStuff(selectedPawnLayer, this.apparelStuffLookup[apparelDef][index]);
                    },
                                      () => {
                        ShowApparelStuffDialog(customPawn, this.selectedPawnLayer);
                    }
                                      );

                    cursorY += stuffFieldRect.height;
                }
            }
            cursorY += 8;

            // Draw Color Selector
            if (PawnLayers.IsApparelLayer(selectedPawnLayer))
            {
                if (apparelList != null && apparelList.Count > 0)
                {
                    ThingDef def = customPawn.GetSelectedApparel(selectedPawnLayer);
                    if (def != null && def.HasComp(typeof(CompColorable)))
                    {
                        if (def.MadeFromStuff)
                        {
                            DrawColorSelector(customPawn, cursorY, null);
                        }
                        else
                        {
                            DrawColorSelector(customPawn, cursorY, def.colorGenerator);
                        }
                    }
                }
            }
            else if (selectedPawnLayer == PawnLayers.BodyType || selectedPawnLayer == PawnLayers.HeadType)
            {
                AlienRace alienRace = customPawn.AlienRace;
                if (alienRace == null || alienRace.UseMelaninLevels)
                {
                    DrawHumanlikeColorSelector(customPawn, cursorY);
                }
                else
                {
                    DrawAlienPawnColorSelector(customPawn, cursorY, alienRace.PrimaryColors, true);
                }
            }
            else if (selectedPawnLayer == PawnLayers.Hair)
            {
                if (hairList != null && hairList.Count > 0)
                {
                    DrawColorSelector(customPawn, cursorY, hairOptions.Colors, true);
                }
            }

            // Random button
            if (RectButtonRandomize.Contains(Event.current.mousePosition))
            {
                GUI.color = Style.ColorButtonHighlight;
            }
            else
            {
                GUI.color = Style.ColorButton;
            }
            GUI.DrawTexture(RectButtonRandomize, Textures.TextureButtonRandom);
            if (Widgets.ButtonInvisible(RectButtonRandomize, false))
            {
                SoundDefOf.TickLow.PlayOneShotOnCamera();
                RandomizeAppearance();
            }

            // Gender buttons.
            if (state.CurrentPawn.Pawn.RaceProps != null && state.CurrentPawn.Pawn.RaceProps.hasGenders)
            {
                bool genderFemaleSelected = state.CurrentPawn.Gender == Gender.Female;
                Style.SetGUIColorForButton(RectGenderFemale, genderFemaleSelected);
                GUI.DrawTexture(RectGenderFemale, Textures.TextureButtonGenderFemale);
                if (!genderFemaleSelected && Widgets.ButtonInvisible(RectGenderFemale, false))
                {
                    SoundDefOf.TickTiny.PlayOneShotOnCamera();
                    GenderUpdated(Gender.Female);
                }
                bool genderMaleSelected = state.CurrentPawn.Gender == Gender.Male;
                Style.SetGUIColorForButton(RectGenderMale, genderMaleSelected);
                GUI.DrawTexture(RectGenderMale, Textures.TextureButtonGenderMale);
                if (!genderMaleSelected && Widgets.ButtonInvisible(RectGenderMale, false))
                {
                    SoundDefOf.TickTiny.PlayOneShotOnCamera();
                    GenderUpdated(Gender.Male);
                }
            }
            GUI.color = Color.white;
        }