예제 #1
0
        protected virtual void Initialize()
        {
#if ALIEN_DEBUG
            Log.Warning("DresserDTO.initialize - start");
#endif
            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeMirrorBody))
            {
                this.originalAgeBioTicks   = this.Pawn.ageTracker.AgeBiologicalTicks;
                this.originalAgeChronTicks = this.Pawn.ageTracker.AgeChronologicalTicks;

                this.BodyTypeSelectionDto = new BodyTypeSelectionDTO(this.Pawn.story.bodyType, this.Pawn.gender);

                this.HeadTypeSelectionDto = new HeadTypeSelectionDTO(this.Pawn.story.HeadGraphicPath, this.Pawn.gender);

                this.SkinColorSliderDto = new SliderWidgetDTO(this.Pawn.story.melanin, 0, 1);

                this.GenderSelectionDto = new GenderSelectionDTO(this.Pawn.gender);
                this.GenderSelectionDto.SelectionChangeListener += delegate(object sender)
                {
                    this.BodyTypeSelectionDto.Gender  = (Gender)this.GenderSelectionDto.SelectedItem;
                    this.HairStyleSelectionDto.Gender = (Gender)this.GenderSelectionDto.SelectedItem;
                    this.HeadTypeSelectionDto.Gender  = (Gender)this.GenderSelectionDto.SelectedItem;
                };
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeMirrorHair))
            {
                this.HairStyleSelectionDto = new HairStyleSelectionDTO(this.Pawn.story.hairDef, this.Pawn.gender);

                ColorPresetsDTO hairColorPresets = IOUtil.LoadColorPresets(ColorPresetType.Hair);
                this.HairColorSelectionDto = new HairColorSelectionDTO(this.Pawn.story.hairColor, hairColorPresets);
                if (GradientHairColorUtil.IsGradientHairAvailable)
                {
                    if (!GradientHairColorUtil.GetGradientHair(this.Pawn, out bool enabled, out Color color))
                    {
                        enabled = false;
                        color   = Color.white;
                    }
                    this.GradientHairColorSelectionDto = new HairColorSelectionDTO(color, hairColorPresets, enabled);
                }
            }
        }
        protected override void Initialize()
        {
            AlienComp ac = base.Pawn.TryGetComp <AlienComp>();

            if (ac == null || !(base.Pawn.def is ThingDef_AlienRace ar))
            {
                Log.Error("Failed to get alien race for " + base.Pawn.Name.ToStringShort);
                return;
            }
            AlienSettings   raceSettings    = ar.alienRace;
            GeneralSettings generalSettings = raceSettings?.generalSettings;

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeMirrorAlienSkinColor))
            {
#if ALIEN_DEBUG
                Log.Warning("AlienDresserDTO.initialize - start");
#endif
                if (raceSettings != null)
                {
                    HairSettings hairSettings = raceSettings.hairSettings;
                    var          c            = ac.GetChannel("skin");
                    if (c != null)
                    {
                        base.AlienSkinColorPrimary = new SelectionColorWidgetDTO(c.first);
                        base.AlienSkinColorPrimary.SelectionChangeListener += this.PrimarySkinColorChange;

                        base.AlienSkinColorSecondary = new SelectionColorWidgetDTO(c.second);
                        base.AlienSkinColorPrimary.SelectionChangeListener += this.SecondarySkinColorChange;
                    }

                    if (hairSettings?.hasHair == true)
                    {
                        base.HairColorSelectionDto = new HairColorSelectionDTO(this.Pawn.story.hairColor, IOUtil.LoadColorPresets(ColorPresetType.Hair));
                        base.HairColorSelectionDto.SelectionChangeListener += this.PrimaryHairColorChange;

                        ColorPresetsDTO hairColorPresets = IOUtil.LoadColorPresets(ColorPresetType.Hair);
                        if (GradientHairColorUtil.IsGradientHairAvailable)
                        {
                            if (!GradientHairColorUtil.GetGradientHair(this.Pawn, out bool enabled, out Color color))
                            {
                                enabled = false;
                                color   = Color.white;
                            }
                            base.GradientHairColorSelectionDto = new HairColorSelectionDTO(color, hairColorPresets, enabled);
                            base.GradientHairColorSelectionDto.SelectionChangeListener += this.GradientHairColorChange;
                        }
                    }
                }
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeMirrorHair))
            {
                if (raceSettings != null)
                {
                    HairSettings hairSettings = raceSettings.hairSettings;
                    base.HasHair = hairSettings?.hasHair == true;
#if ALIEN_DEBUG
                    Log.Warning("initialize - got hair settings: HasHair = " + base.HasHair);
#endif
                    if (base.HasHair)
                    {
                        List <string> hairTags = hairSettings.hairTags;
                        if (hairTags != null)
                        {
                            IEnumerable <HairDef> hairDefs = from hair in DefDatabase <HairDef> .AllDefs
                                                             where hair.hairTags.SharesElementWith(hairTags)
                                                             select hair;
#if ALIEN_DEBUG
                            System.Text.StringBuilder sb = new System.Text.StringBuilder("Hair Defs: ");
                            foreach (HairDef d in hairDefs)
                            {
                                sb.Append(d.defName);
                                sb.Append(", ");
                            }
                            Log.Warning("initialize - " + sb.ToString());
#endif

                            /*if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeDresserHair))
                             * {
                             *  if (hairSettings != null)
                             *  {
                             *      List<string> filter = (List<string>)hairSettings.GetType().GetField("hairTags")?.GetValue(hairSettings);
                             *      base.HairStyleSelectionDto = new HairStyleSelectionDTO(this.Pawn.story.hairDef, this.Pawn.gender, filter);
                             *  }
                             * }*/
                            base.HairStyleSelectionDto = new HairStyleSelectionDTO(this.Pawn.story.hairDef, this.Pawn.gender, hairDefs);
                        }
                        else
                        {
                            base.HairStyleSelectionDto = new HairStyleSelectionDTO(this.Pawn.story.hairDef, this.Pawn.gender);
                        }
                    }
                    else
                    {
#if ALIEN_DEBUG
                        Log.Warning("initialize - remove hair editors");
#endif
                        base.EditorTypeSelectionDto.Remove(CurrentEditorEnum.ChangeMirrorHair);//, CurrentEditorEnum.ChangeDresserAlienHairColor);
#if ALIEN_DEBUG
                        Log.Warning("initialize - hair editors removed");
#endif
                    }
                }
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeMirrorBody))
            {
                var apg = generalSettings?.alienPartGenerator;
                if (apg != null)
                {
                    List <string> crownTypes = apg.aliencrowntypes;
                    if (ac.crownType != null && ac.crownType != "" &&
                        crownTypes?.Count > 1)
                    {
                        this.HeadTypeSelectionDto = new HeadTypeSelectionDTO(ac.crownType, this.Pawn.gender, crownTypes);
                    }

                    List <BodyTypeDef> alienbodytypes = apg.alienbodytypes;
                    if (alienbodytypes != null && alienbodytypes.Count > 1)
                    {
                        this.BodyTypeSelectionDto = new BodyTypeSelectionDTO(this.Pawn.story.bodyType, this.Pawn.gender, alienbodytypes);
                    }
                    else
                    {
                        Log.Warning("No alien body types found. Defaulting to human.");
                        this.BodyTypeSelectionDto = new BodyTypeSelectionDTO(this.Pawn.story.bodyType, this.Pawn.gender);
                    }
                }

                if (generalSettings.maleGenderProbability > 0f && generalSettings.maleGenderProbability < 1f)
                {
                    base.GenderSelectionDto = new GenderSelectionDTO(base.Pawn.gender);
                    base.GenderSelectionDto.SelectionChangeListener += GenderChange;
                }
#if ALIEN_DEBUG
                Log.Warning("initialize - done");
#endif
            }
        }