Пример #1
0
        public static DresserDTO Create(Pawn pawn, Job job, CurrentEditorEnum selectedEditor)
        {
            List <CurrentEditorEnum> editors = Building_ChangeMirror.SupportedEditors;

            if (AlienRaceUtil.IsAlien(pawn))
            {
                List <CurrentEditorEnum> alienEditors = new List <CurrentEditorEnum>(editors.Count + 2);
                foreach (CurrentEditorEnum ed in editors)
                {
                    alienEditors.Add(ed);
                    if (ed == CurrentEditorEnum.ChangeMirrorBody)
                    {
                        alienEditors.Add(CurrentEditorEnum.ChangeMirrorAlienSkinColor);
                    }

                    /*else if (ed == CurrentEditorEnum.ChangeDresserHair)
                     * {
                     *  alienEditors.Add(CurrentEditorEnum.ChangeDresserAlienHairColor);
                     * }*/
                }
                editors = alienEditors;
                return(new AlienDresserDTO(pawn, selectedEditor, editors));
            }

            return(new DresserDTO(pawn, selectedEditor, editors));
        }
Пример #2
0
        public static DresserDTO Create(Pawn pawn, Job job, CurrentEditorEnum selectedEditor)
        {
            bool isAlien = AlienRaceUtil.IsAlien(pawn);
            IEnumerable <CurrentEditorEnum> editors;

            if (job.targetA.Thing is Building_ChangeMirror)
            {
                editors = Building_ChangeMirror.GetSupportedEditors(isAlien);
            }
            else
            {
                editors = Building_ChangeMirror.GetSupportedEditors(isAlien);
            }

            if (isAlien)
            {
                return(new AlienDresserDTO(pawn, selectedEditor, editors));
            }
            return(new DresserDTO(pawn, selectedEditor, editors));
        }
Пример #3
0
        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.ChangeMirrorAlienSkinColor))
            {
                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;

                    /*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.ChangeMirrorHair))
            {
                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.ChangeMirrorHair);//, CurrentEditorEnum.ChangeDresserAlienHairColor);
#if ALIEN_DEBUG
                        Log.Warning("initialize - hair editors removed");
#endif
                    }
                }
            }

            if (this.EditorTypeSelectionDto.Contains(CurrentEditorEnum.ChangeMirrorBody))
            {
                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);
                                    }
                                }
                            }

                            fi = alienPartGenerator.GetType().GetField("alienbodytypes");
                            if (fi != null)
                            {
                                List <BodyTypeDef> alienbodytypes = (List <BodyTypeDef>)fi.GetValue(alienPartGenerator);
                                if (alienbodytypes != null)
                                {
                                    this.BodyTypeSelectionDto = new BodyTypeSelectionDTO(this.Pawn.story.bodyType, this.Pawn.gender, alienbodytypes);
                                }
                            }
                        }
                    }
                }
                if (maleGenderProbability > 0f && maleGenderProbability < 1f)
                {
                    base.GenderSelectionDto = new GenderSelectionDTO(base.Pawn.gender);
                    base.GenderSelectionDto.SelectionChangeListener += GenderChange;
                }
#if ALIEN_DEBUG
                Log.Warning("initialize - done");
#endif
            }
        }