Пример #1
0
        protected virtual void Initialize()
        {
#if ALIEN_DEBUG
            Log.Warning("DresserDTO.initialize - start");
#endif
            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeDresserBody))
            {
                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.ChangeDresserHair))
            {
                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);
                }
            }
        }
Пример #2
0
        private void UpdatePawn(object sender, object value)
        {
            if (sender != null)
            {
                Pawn pawn = this.dresserDto.Pawn;

                if (sender is ApparelColorSelectionDTO)
                {
                    if (this.ApparelWithColorChange == null)
                    {
                        this.ApparelWithColorChange = new List <Apparel>();
                    }

                    ApparelColorSelectionDTO dto = (ApparelColorSelectionDTO)sender;
                    CompColorableUtility.SetColor(dto.Apparel, dto.SelectedColor, true);

                    if (!this.ApparelWithColorChange.Contains(dto.Apparel))
                    {
                        this.ApparelWithColorChange.Add(dto.Apparel);
                    }
                }
                else if (sender is ApparelLayerColorSelectionDTO)
                {
                    if (this.ApparelWithColorChange == null)
                    {
                        this.ApparelWithColorChange = new List <Apparel>();
                    }

                    ApparelLayerColorSelectionDTO dto = (ApparelLayerColorSelectionDTO)sender;

                    foreach (Apparel a in this.dresserDto.Pawn.apparel.WornApparel)
                    {
                        Color c = a.DrawColor;
                        if (a.DrawColor != c &&
                            !this.ApparelWithColorChange.Contains(a))
                        {
                            this.ApparelWithColorChange.Add(a);
                        }
                    }
                }
                else if (sender is BodyTypeSelectionDTO)
                {
                    pawn.story.bodyType = (BodyTypeDef)value;
                }
                else if (sender is GenderSelectionDTO)
                {
                    pawn.gender = (Gender)value;
                }
                else if (sender is HairColorSelectionDTO)
                {
                    if ((sender as HairColorSelectionDTO).IsGradientEnabled)
                    {
                        GradientHairColorUtil.SetGradientHair(pawn, true, (Color)value);
                    }
                    else
                    {
                        pawn.story.hairColor = (Color)value;
                    }
                }
                else if (sender is HairStyleSelectionDTO)
                {
                    pawn.story.hairDef = (HairDef)value;
                }
                else if (sender is HeadTypeSelectionDTO)
                {
                    dresserDto.SetCrownType(value);
                }
                else if (sender is SliderWidgetDTO)
                {
                    pawn.story.melanin = (float)value;
                }
            }
            rerenderPawn = true;
        }
Пример #3
0
        private void UpdatePawn(object sender, object value)
        {
            if (sender != null)
            {
                Pawn pawn = this.dresserDto.Pawn;

                if (sender is ApparelColorSelectionDTO)
                {
                    if (this.ApparelWithColorChange == null)
                    {
                        this.ApparelWithColorChange = new List <Apparel>();
                    }

                    ApparelColorSelectionDTO dto = (ApparelColorSelectionDTO)sender;
                    CompColorableUtility.SetColor(dto.Apparel, dto.SelectedColor, true);

                    if (!this.ApparelWithColorChange.Contains(dto.Apparel))
                    {
                        this.ApparelWithColorChange.Add(dto.Apparel);
                    }
                }
                else if (sender is ApparelLayerColorSelectionDTO)
                {
                    if (this.ApparelWithColorChange == null)
                    {
                        this.ApparelWithColorChange = new List <Apparel>();
                    }

                    ApparelLayerColorSelectionDTO dto = (ApparelLayerColorSelectionDTO)sender;
                    dto.PawnOutfitTracker.SetLayerColor(dto.ApparelLayerDef, dto.SelectedColor);

                    foreach (Apparel a in this.dresserDto.Pawn.apparel.WornApparel)
                    {
                        Color c = a.DrawColor;
                        dto.PawnOutfitTracker.ApplyApparelColor(a);
                        if (a.DrawColor != c &&
                            !this.ApparelWithColorChange.Contains(a))
                        {
                            this.ApparelWithColorChange.Add(a);
                        }
                    }
                }
                else if (sender is BodyTypeSelectionDTO)
                {
                    pawn.story.bodyType = (BodyTypeDef)value;
                }
                else if (sender is GenderSelectionDTO)
                {
                    pawn.gender = (Gender)value;
                }
                else if (sender is HairColorSelectionDTO)
                {
                    if ((sender as HairColorSelectionDTO).IsGradientEnabled)
                    {
                        GradientHairColorUtil.SetGradientHair(pawn, true, (Color)value);
                    }
                    else
                    {
                        pawn.story.hairColor = (Color)value;
                    }
                }
                else if (sender is HairStyleSelectionDTO)
                {
                    pawn.story.hairDef = (HairDef)value;
                }
                else if (sender is HeadTypeSelectionDTO)
                {
                    if (value.ToString().IndexOf("Narrow") >= 0 ||
                        value.ToString().IndexOf("narrow") >= 0)
                    {
                        dresserDto.Pawn.story.crownType = CrownType.Narrow;
                    }
                    else
                    {
                        dresserDto.Pawn.story.crownType = CrownType.Average;
                    }
                    typeof(Pawn_StoryTracker).GetField("headGraphicPath", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(dresserDto.Pawn.story, value);
                }
                else if (sender is SliderWidgetDTO)
                {
                    pawn.story.melanin = (float)value;
                }
            }
            rerenderPawn = true;
        }
Пример #4
0
        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.ChangeDresserAlienSkinColor))
            {
#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.ChangeDresserHair))
            {
                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.ChangeDresserHair);//, CurrentEditorEnum.ChangeDresserAlienHairColor);
#if ALIEN_DEBUG
                        Log.Warning("initialize - hair editors removed");
#endif
                    }
                }
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeDresserBody))
            {
                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
            }
        }
Пример #5
0
 private void GradientHairColorChange(object sender)
 {
     GradientHairColorUtil.SetGradientHair(base.Pawn, base.GradientHairColorSelectionDto.IsGradientEnabled, base.GradientHairColorSelectionDto.SelectedColor);
 }
        protected override void Initialize()
        {
            object raceSettings    = AlienRaceUtil.GetAlienRaceSettings(base.Pawn);
            object generalSettings = AlienRaceUtil.GetGeneralSettings(base.Pawn);
            object hairSettings    = AlienRaceUtil.GetHairSettings(base.Pawn);

            foreach (ThingComp tc in base.Pawn.GetComps <ThingComp>())
            {
#if ALIEN_DEBUG
                Log.Warning(" comp: " + tc.GetType().Namespace + "." + tc.GetType().Name);
#endif
                if (tc.GetType().Namespace.EqualsIgnoreCase("AlienRace") &&
                    tc.GetType().Name.EqualsIgnoreCase("AlienComp"))
                {
                    this.alienComp = tc;
#if ALIEN_DEBUG
                    Log.Warning("Alien Comp found!");
#endif
                    break;
                }
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeDresserAlienSkinColor))
            {
                if (PrimarySkinColorFieldInfo == null && SecondarySkinColorFieldInfo == null &&
                    PrimaryHairColorFieldInfo == null && SecondaryHairColorFieldInfo == null)
                {
                    PrimarySkinColorFieldInfo   = alienComp.GetType().GetField("skinColor");
                    SecondarySkinColorFieldInfo = alienComp.GetType().GetField("skinColorSecond");
                    SecondaryHairColorFieldInfo = alienComp.GetType().GetField("hairColorSecond");
#if ALIEN_DEBUG
                    Log.Warning("Field Info for primary skin color found: " + (PrimarySkinColorFieldInfo != null).ToString());
                    Log.Warning("Field Info for secondary skin color found: " + (SecondarySkinColorFieldInfo != null).ToString());
                    Log.Warning("Field Info for secondary hair color found: " + (SecondaryHairColorFieldInfo != null).ToString());
#endif
                }

#if ALIEN_DEBUG
                Log.Warning("AlienDresserDTO.initialize - start");
#endif
                if (this.alienComp != null)
                {
                    if (PrimarySkinColorFieldInfo != null)
                    {
                        base.AlienSkinColorPrimary = new SelectionColorWidgetDTO((Color)PrimarySkinColorFieldInfo.GetValue(this.alienComp));
                        base.AlienSkinColorPrimary.SelectionChangeListener += this.PrimarySkinColorChange;
                    }

                    if (SecondarySkinColorFieldInfo != null)
                    {
                        base.AlienSkinColorSecondary = new SelectionColorWidgetDTO((Color)SecondarySkinColorFieldInfo.GetValue(this.alienComp));
                        base.AlienSkinColorPrimary.SelectionChangeListener += this.SecondarySkinColorChange;
                    }

                    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 (SecondaryHairColorFieldInfo != null)
                     * {
                     *  base.AlienHairColorSecondary = new HairColorSelectionDTO((Color)SecondarySkinColorFieldInfo.GetValue(this.alienComp), IOUtil.LoadColorPresets(ColorPresetType.Hair));
                     *  base.AlienHairColorSecondary.SelectionChangeListener += this.SecondaryHairColorChange;
                     * }*/
                }
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeDresserHair))
            {
                if (raceSettings != null)
                {
                    base.HasHair = AlienRaceUtil.HasHair(base.Pawn);
#if ALIEN_DEBUG
                    Log.Warning("initialize - got hair settings: HasHair = " + base.HasHair);
#endif
                    if (base.HasHair)
                    {
                        List <string> hairTags = AlienRaceUtil.GetHairTags(base.Pawn);
                        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.ChangeDresserHair);//, CurrentEditorEnum.ChangeDresserAlienHairColor);
#if ALIEN_DEBUG
                        Log.Warning("initialize - hair editors removed");
#endif
                    }
                }
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeDresserBody))
            {
                float maleGenderProbability = 0.5f;
                if (AlienRaceUtil.HasMaleGenderProbability(base.Pawn))
                {
#if ALIEN_DEBUG
                    Log.Warning("initialize - generalSettings found");
#endif
                    FieldInfo fi = generalSettings.GetType().GetField("MaleGenderProbability");
                    if (fi != null)
                    {
                        maleGenderProbability = AlienRaceUtil.GetMaleGenderProbability(base.Pawn);
#if ALIEN_DEBUG
                        Log.Warning("initialize - male gender prob = " + maleGenderProbability);
#endif
                    }

                    fi = generalSettings.GetType().GetField("alienPartGenerator");
                    if (fi != null)
                    {
                        object alienPartGenerator = fi.GetValue(generalSettings);
                        if (alienPartGenerator != null)
                        {
                            fi = alienPartGenerator.GetType().GetField("aliencrowntypes");
                            if (fi != null && alienComp != null)
                            {
                                List <string> crownTypes = (List <string>)fi.GetValue(alienPartGenerator);
                                fi = alienComp.GetType().GetField("crownType");
                                if (fi != null)
                                {
                                    string crownType = (string)fi.GetValue(alienComp);
                                    if (crownTypes != null && crownType != null && crownTypes.Count > 1)
                                    {
                                        this.HeadTypeSelectionDto = new HeadTypeSelectionDTO(crownType, this.Pawn.gender, crownTypes);
                                    }
                                }
                            }

                            try
                            {
                                fi = alienPartGenerator.GetType().GetField("alienbodytypes");
                                if (fi != null)
                                {
                                    Log.Warning("Get story");
                                    Log.Warning(this.Pawn.story.bodyType.ToString());
                                    List <BodyTypeDef> alienbodytypes = (List <BodyTypeDef>)fi.GetValue(alienPartGenerator);
                                    if (alienbodytypes != null && alienbodytypes.Count > 0)
                                    {
                                        Log.Warning("Found body types");
                                        this.BodyTypeSelectionDto = new BodyTypeSelectionDTO(this.Pawn.story.bodyType, this.Pawn.gender, alienbodytypes);
                                        Log.Warning("Body Types loaded");
                                    }
                                    else
                                    {
                                        Log.Warning("No alien body types found. Defaulting to human.");
                                        this.BodyTypeSelectionDto = new BodyTypeSelectionDTO(this.Pawn.story.bodyType, this.Pawn.gender);
                                    }
                                }
                            }
                            catch
                            {
                                Log.Warning("Problem getting alien body types. Defaulting to human.");
                                this.BodyTypeSelectionDto = new BodyTypeSelectionDTO(this.Pawn.story.bodyType, this.Pawn.gender);
                            }
                        }
                    }
                }
                if (maleGenderProbability > 0f && maleGenderProbability < 1f)
                {
                    base.GenderSelectionDto = new GenderSelectionDTO(base.Pawn.gender);
                    base.GenderSelectionDto.SelectionChangeListener += GenderChange;
                }
#if ALIEN_DEBUG
                Log.Warning("initialize - done");
#endif
            }
        }