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); } } }
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 } }
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 } }