Exemple #1
0
        protected CustomHeadType CreateGenderedAlienHeadTypeFromCrownType(string graphicsPath, string crownType, Gender gender)
        {
            CustomHeadType result = new CustomHeadType();

            result.Gender = gender;
            result.Label  = LabelFromCrownType(crownType);

            // Build the full graphics path for this head type
            string pathValue = string.Copy(graphicsPath);

            if (!pathValue.EndsWith("/"))
            {
                pathValue += "/";
            }
            if (gender == Gender.Female)
            {
                pathValue += "Female_";
            }
            else if (gender == Gender.Male)
            {
                pathValue += "Male_";
            }
            else
            {
                pathValue += "None_";
            }
            pathValue            += crownType;
            result.GraphicPath    = pathValue;
            result.CrownType      = FindCrownTypeEnumValue(crownType);
            result.AlienCrownType = crownType;
            return(result);
        }
        protected CustomHeadType CreateGenderedAlienHeadTypeFromCrownType(string graphicsPath, string crownType, Gender gender)
        {
            CustomHeadType result    = new CustomHeadType();
            string         pathValue = string.Copy(graphicsPath);

            if (!pathValue.EndsWith("/"))
            {
                pathValue += "/";
            }
            if (gender == Gender.Female)
            {
                pathValue += "Female_";
            }
            else if (gender == Gender.Male)
            {
                pathValue += "Male_";
            }
            else
            {
                pathValue += "None_";
            }
            pathValue += crownType;
            try {
                result.GraphicPath = pathValue;
                result.CrownType   = CrownType.Average;
                result.Gender      = gender;
                return(result);
            }
            catch (Exception ex) {
                Log.Warning("Prepare carefully failed to create a head type when trying to parse crown type value: " + crownType + ": " + ex.Message);
                return(null);
            }
        }
        protected OptionsHeadType InitializeHumanHeadTypes()
        {
            MethodInfo headGraphicsMethod = typeof(GraphicDatabaseHeadRecords).GetMethod("BuildDatabaseIfNecessary", BindingFlags.Static | BindingFlags.NonPublic);

            headGraphicsMethod.Invoke(null, null);
            string[] headsFolderPaths = new string[] {
                "Things/Pawn/Humanlike/Heads/Male",
                "Things/Pawn/Humanlike/Heads/Female"
            };
            OptionsHeadType result = new OptionsHeadType();

            for (int i = 0; i < headsFolderPaths.Length; i++)
            {
                string text = headsFolderPaths[i];
                IEnumerable <string> graphicsInFolder = GraphicDatabaseUtility.GraphicNamesInFolder(text);
                foreach (string current in GraphicDatabaseUtility.GraphicNamesInFolder(text))
                {
                    string         fullPath = text + "/" + current;
                    CustomHeadType headType = CreateHeadTypeFromGenderedGraphicPath(fullPath);
                    result.AddHeadType(headType);
                    pathDictionary.Add(fullPath, headType);
                }
            }
            return(result);
        }
Exemple #4
0
        public CustomHeadType FindHeadTypeForGender(CustomHeadType headType, Gender gender)
        {
            if (headType.Gender == null || headType.Gender == gender)
            {
                return(headType);
            }
            string graphicsPath               = headType.GraphicPath;
            string prefixReplacementString    = "/" + gender.ToString() + "_";
            string directoryReplacementString = "/" + gender.ToString() + "/";

            if (headType.Gender == Gender.Male)
            {
                graphicsPath = graphicsPath.Replace("/Male/", directoryReplacementString);
                graphicsPath = graphicsPath.Replace("/Male_", prefixReplacementString);
            }
            if (headType.Gender == Gender.Female)
            {
                graphicsPath = graphicsPath.Replace("/Female/", directoryReplacementString);
                graphicsPath = graphicsPath.Replace("/Female_", prefixReplacementString);
            }
            else
            {
                graphicsPath = graphicsPath.Replace("/None/", directoryReplacementString);
                graphicsPath = graphicsPath.Replace("/None_", prefixReplacementString);
            }
            CustomHeadType result = FindHeadType(graphicsPath);

            return(result != null ? result : headType);
        }
Exemple #5
0
 public void AddHeadType(CustomHeadType headType)
 {
     headTypes.Add(headType);
     pathDictionary.Add(headType.GraphicPath, headType);
     if (headType.AlternateGraphicPath != null)
     {
         pathDictionary.Add(headType.AlternateGraphicPath, headType);
     }
 }
 public void AddHeadType(CustomHeadType headType)
 {
     headTypes.Add(headType);
     //Logger.Debug(headType.ToString());
     pathDictionary.Add(headType.GraphicPath, headType);
     if (headType.AlternateGraphicPath != null)
     {
         pathDictionary.Add(headType.AlternateGraphicPath, headType);
     }
 }
Exemple #7
0
        public CustomHeadType FindHeadTypeForGender(CustomHeadType headType, Gender gender)
        {
            if (headType.Gender == null || headType.Gender == gender)
            {
                return(headType);
            }

            if (headType.AlienCrownType.NullOrEmpty())
            {
                string graphicsPath               = headType.GraphicPath;
                string prefixReplacementString    = "/" + gender.ToString() + "_";
                string directoryReplacementString = "/" + gender.ToString() + "/";
                if (headType.Gender == Gender.Male)
                {
                    graphicsPath = graphicsPath.Replace("/Male/", directoryReplacementString);
                    graphicsPath = graphicsPath.Replace("/Male_", prefixReplacementString);
                }
                if (headType.Gender == Gender.Female)
                {
                    graphicsPath = graphicsPath.Replace("/Female/", directoryReplacementString);
                    graphicsPath = graphicsPath.Replace("/Female_", prefixReplacementString);
                }
                else
                {
                    graphicsPath = graphicsPath.Replace("/None/", directoryReplacementString);
                    graphicsPath = graphicsPath.Replace("/None_", prefixReplacementString);
                }
                CustomHeadType result = FindHeadTypeByGraphicsPath(graphicsPath);
                if (result == null)
                {
                    Log.Warning("Could not find head type for gender: " + graphicsPath);
                }
                return(result != null ? result : headType);
            }
            else
            {
                Gender targetGender = gender;
                if (headType.Gender == Gender.Male)
                {
                    targetGender = Gender.Female;
                }
                if (headType.Gender == Gender.Female)
                {
                    targetGender = Gender.Male;
                }
                else
                {
                    return(headType);
                }
                var result = headTypes.Where(h => {
                    return(h.AlienCrownType == headType.AlienCrownType && h.Gender == targetGender);
                }).FirstOrDefault();
                return(result != null ? result : headType);
            }
        }
        protected OptionsHeadType InitializeAlienHeadTypes(ThingDef raceDef)
        {
            //Logger.Debug("InitializeAlienHeadTypes(" + raceDef.defName + ")");
            AlienRace       alienRace = AlienRaceProvider.GetAlienRace(raceDef);
            OptionsHeadType result    = new OptionsHeadType();

            if (alienRace == null)
            {
                Logger.Warning("Could not initialize head types for alien race, " + raceDef + ", because the race's thing definition was missing");
                return(result);
            }
            //Logger.Debug("alienRace.GraphicsPathForHeads = " + alienRace.GraphicsPathForHeads);
            if (alienRace.GraphicsPathForHeads == null)
            {
                Logger.Warning("Could not initialize head types for alien race, " + raceDef + ", because no path for head graphics was found.");
                return(result);
            }
            foreach (var crownType in alienRace.CrownTypes)
            {
                //Logger.Debug(" - " + crownType);
                if (alienRace.GenderSpecificHeads)
                {
                    CustomHeadType maleHead   = CreateGenderedAlienHeadTypeFromCrownType(alienRace.GraphicsPathForHeads, crownType, Gender.Male);
                    CustomHeadType femaleHead = CreateGenderedAlienHeadTypeFromCrownType(alienRace.GraphicsPathForHeads, crownType, Gender.Female);
                    if (maleHead != null)
                    {
                        //Logger.Debug("   - MALE: " + maleHead.GraphicPath);
                        result.AddHeadType(maleHead);
                    }
                    if (femaleHead != null)
                    {
                        //Logger.Debug("   - FEMALE: " + femaleHead.GraphicPath);
                        result.AddHeadType(femaleHead);
                    }
                }
                else
                {
                    CustomHeadType head = CreateMultiGenderAlienHeadTypeFromCrownType(alienRace.GraphicsPathForHeads, crownType);
                    if (head != null)
                    {
                        //Logger.Debug("   - MULTIGENDER: " + head.GraphicPath);
                        result.AddHeadType(head);
                    }
                }
            }
            return(result);
        }
        protected CustomHeadType CreateMultiGenderAlienHeadTypeFromCrownType(string graphicsPath, string crownType)
        {
            CustomHeadType result    = new CustomHeadType();
            string         pathValue = string.Copy(graphicsPath);

            if (!pathValue.EndsWith("/"))
            {
                pathValue += "/";
            }
            pathValue            += crownType;
            result.GraphicPath    = pathValue;
            result.Label          = LabelFromCrownType(crownType);
            result.Gender         = null;
            result.CrownType      = FindCrownTypeEnumValue(crownType);
            result.AlienCrownType = crownType;
            return(result);
        }
        protected CustomHeadType CreateHeadTypeFromGenderedGraphicPath(string graphicPath)
        {
            CustomHeadType result = new CustomHeadType();

            result.GraphicPath = graphicPath;
            string[] strArray = Path.GetFileNameWithoutExtension(graphicPath).Split('_');
            try {
                result.CrownType = (CrownType)ParseHelper.FromString(strArray[strArray.Length - 2], typeof(CrownType));
                result.Gender    = (Gender)ParseHelper.FromString(strArray[strArray.Length - 3], typeof(Gender));
            }
            catch (Exception ex) {
                Log.Warning("Parse error with head graphic at " + graphicPath + ": " + ex.Message);
                result.CrownType = CrownType.Undefined;
                result.Gender    = Gender.None;
            }
            return(result);
        }
Exemple #11
0
        protected OptionsHeadType InitializeAlienHeadTypes(ThingDef raceDef)
        {
            AlienRace       alienRace = AlienRaceProvider.GetAlienRace(raceDef);
            OptionsHeadType result    = new OptionsHeadType();

            if (alienRace == null)
            {
                Log.Warning("Prepare Carefully could not initialize head types for alien race, " + raceDef);
                return(result);
            }
            if (alienRace.GraphicsPathForHeads == null)
            {
                Log.Warning("Prepare Carefully could not initialize head types for alien race, " + raceDef + ", because no path for head graphics was found.");
                return(result);
            }
            foreach (var crownType in alienRace.CrownTypes)
            {
                if (alienRace.GenderSpecificHeads)
                {
                    CustomHeadType maleHead   = CreateGenderedAlienHeadTypeFromCrownType(alienRace.GraphicsPathForHeads, crownType, Gender.Male);
                    CustomHeadType femaleHead = CreateGenderedAlienHeadTypeFromCrownType(alienRace.GraphicsPathForHeads, crownType, Gender.Female);
                    if (maleHead != null)
                    {
                        result.AddHeadType(maleHead);
                    }
                    if (femaleHead != null)
                    {
                        result.AddHeadType(femaleHead);
                    }
                }
                else
                {
                    CustomHeadType head = CreateMultiGenderAlienHeadTypeFromCrownType(alienRace.GraphicsPathForHeads, crownType);
                    if (head != null)
                    {
                        result.AddHeadType(head);
                    }
                }
            }
            return(result);
        }
Exemple #12
0
        protected CustomHeadType CreateMultiGenderAlienHeadTypeFromCrownType(string graphicsPath, string crownType)
        {
            CustomHeadType result    = new CustomHeadType();
            string         pathValue = string.Copy(graphicsPath);

            if (!pathValue.EndsWith("/"))
            {
                pathValue += "/";
            }
            pathValue += crownType;
            try {
                result.GraphicPath = pathValue;
                string    firstPart = crownType.Split('_')[0];
                CrownType c         = (CrownType)Enum.Parse(typeof(CrownType), firstPart);
                result.Gender = null;
                return(result);
            }
            catch (Exception ex) {
                Log.Warning("Prepare carefully failed to create a head type when trying to parse crown type value: " + crownType + ": " + ex.Message);
                return(null);
            }
        }
Exemple #13
0
        protected OptionsHeadType InitializeHumanHeadTypes()
        {
            Reflection.GraphicDatabaseHeadRecords.BuildDatabaseIfNecessary();
            string[] headsFolderPaths = new string[] {
                "Things/Pawn/Humanlike/Heads/Male",
                "Things/Pawn/Humanlike/Heads/Female"
            };
            OptionsHeadType result = new OptionsHeadType();

            for (int i = 0; i < headsFolderPaths.Length; i++)
            {
                string text = headsFolderPaths[i];
                IEnumerable <string> graphicsInFolder = GraphicDatabaseUtility.GraphicNamesInFolder(text);
                foreach (string current in GraphicDatabaseUtility.GraphicNamesInFolder(text))
                {
                    string         fullPath = text + "/" + current;
                    CustomHeadType headType = CreateHumanHeadTypeFromGenderedGraphicPath(fullPath);
                    result.AddHeadType(headType);
                    pathDictionary.Add(fullPath, headType);
                }
            }
            return(result);
        }
        public CustomHeadType FindHeadTypeForGender(ThingDef race, CustomHeadType headType, Gender gender)
        {
            OptionsHeadType headTypes = GetHeadTypesForRace(race);

            return(headTypes.FindHeadTypeForGender(headType, gender));
        }
Exemple #15
0
 public void AddHeadType(CustomHeadType headType)
 {
     headTypes.Add(headType);
     pathDictionary.Add(headType.GraphicPath, headType);
 }