Exemplo n.º 1
0
        /// <summary>expose data.</summary>
        public override void PostExposeData()
        {
            base.PostExposeData();
            Scribe_Values.Look(ref _customDrawSize, "customDrawSize");
            Scribe_Values.Look(ref _customPortraitDrawSize, "customPortraitDrawSize");
            Scribe_Values.Look(ref _fixedGenderPostSpawn, nameof(FixGenderPostSpawn));
            Scribe_Values.Look(ref _skinColor, "skinColor");
            Scribe_Values.Look(ref _skinColorSecond, "skinColorSecond");
            Scribe_Values.Look(ref _hairColorSecond, "hairColorSecond");
            Scribe_Values.Look(ref _crownType, "crownType");
            Scribe_Values.Look(ref _hairColor, nameof(HairColor));
            Scribe_Values.Look(ref _scanned, nameof(_scanned));
            Scribe_Defs.Look(ref _body, nameof(_body));
            Scribe_Defs.Look(ref _hairDef, nameof(_hairDef));


            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                if (_skinColor == Color.clear)
                {
                    _skinColor = PawnSkinColors.GetSkinColor(Pawn.story.melanin);
                }
                if (_body == null)
                {
                    _body = Pawn.story.bodyType;
                }
            }
        }
Exemplo n.º 2
0
        // see PawnGenerator
        private void generate_pawn()
        {
            Gender gender;

            if (Rand.Value < 0.5f)
            {
                gender = Gender.Male;
            }
            else
            {
                gender = Gender.Female;
            }

            Faction f = Faction.OfPlayer;

            float melanin = PawnSkinColors.RandomMelanin(f);

            skinColor = PawnSkinColors.GetSkinColor(melanin);
            int age = 20;

            hairColor = PawnHairColors.RandomHairColor(skinColor, age);
            hairDef   = RandomHairDefFor(gender, f.def);

            crownType = Rand.Value >= 0.5f ? CrownType.Narrow : CrownType.Average;

            headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(
                gender, skinColor, crownType).GraphicPath;

            bodyType = BodyType.Male;
        }
Exemplo n.º 3
0
        public override Color GetColor(Pawn pawn, List <string> options)
        {
            List <Pair <Color, float> > list = new List <Pair <Color, float> >();

            foreach (var option in options)
            {
                var          arg = option.Replace(" ", "");
                List <float> num = new List <float>();
                foreach (Match match in Regex.Matches(arg, @"(\d{1,}\.\d{1,}|\d{1,})"))
                {
                    num.Add(float.Parse(match.Value));
                }
                if (num.Count() != 3)
                {
                    RaceAddon.Notify("Parsing failed! => " + option, true);
                }
                Color color = PawnSkinColors.GetSkinColor(Rand.Range(num[0], num[1]));
                list.Add(new Pair <Color, float>(color, num[2]));
            }
            if (list.Count == 0)
            {
                RaceAddon.Notify("Color generation failed! => " + pawn.Name.ToStringFull, true);
                return(Color.white);
            }
            return(list.RandomElementByWeight(x => x.Second).First);
        }
Exemplo n.º 4
0
        public PawnGraphicRenderer(float melanin)
        {
            Color     skinColor = PawnSkinColors.GetSkinColor(this.melanin = melanin);
            Gender    gender    = (Rand.Value < 0.5f) ? Gender.Male : Gender.Female;
            CrownType crownType = (Rand.Value < 0.5f) ? CrownType.Average : CrownType.Narrow;
            HairDef   hairDef   = RandomHairDefFor(gender);
            Color     hairColor = PawnHairColors.RandomHairColor(skinColor, 18);

            headGraphic = GraphicDatabaseHeadRecords.GetHeadRandom(gender, skinColor, crownType, false);
            hairGraphic = GraphicDatabase.Get <Graphic_Multi>(hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, hairColor);
        }
Exemplo n.º 5
0
        // Populates color arrays from PawnSkinColors.SkinColors.  Uses an indirect method of getting the color values
        // instead of just copying the color list via reflection.  This will make it work better with mods that
        // detour the color methods in that class--as long as they detour the GetSkinDataIndexOfMelanin() method.
        public static void InitializeColors()
        {
            List <float> values = new List <float>();

            // Get the private GetSkinDataLeftIndexByWhiteness() method from the PawnSkinColors class.
            MethodInfo getSkinDataIndexOfMelaninMethod = typeof(PawnSkinColors)
                                                         .GetMethod("GetSkinDataIndexOfMelanin",
                                                                    BindingFlags.NonPublic | BindingFlags.Static, null, new[] { typeof(float) }, null);

            // Iterate all values from 0.0f to 1.0f, using increments of 0.01f, to get the left index for each value.
            // Use this technique to construct a list of all of the indexes and their values.  Once we have the list
            // of indexes and their values, we can use the GetSkinColor() method to get the actual colors.
            int currentIndex = 0;

            values.Add(0.0f);
            float f       = 0.01f;
            int   counter = 1;

            while (f < 1.0f)
            {
                // ReSharper disable once PossibleNullReferenceException
                int result = (int)getSkinDataIndexOfMelaninMethod.Invoke(null, new object[] { f });
                if (result != currentIndex)
                {
                    currentIndex = result;
                    values.Add(f);
                }
                counter++;
                double d = counter / 100.0;
                f = (float)d;
            }
            values.Add(1.0f);

            // Allocate the arrays and fill them with the correct values.
            int length = values.Count;

            Colors        = new Color[length];
            ColorValues   = new float[length];
            RoundedColors = new Color[length];
            for (int i = 0; i < length; i++)
            {
                float v     = values[i];
                Color color = PawnSkinColors.GetSkinColor(v);
                Colors[i]          = color;
                RoundedColors[i]   = color;
                RoundedColors[i].r = (float)Math.Round(color.r, 3);
                RoundedColors[i].g = (float)Math.Round(color.g, 3);
                RoundedColors[i].b = (float)Math.Round(color.b, 3);
                RoundedColors[i].a = (float)Math.Round(color.a, 3);
                ColorValues[i]     = v;
                //  Log.Message("Color added: (" + color.r + ", " + color.g + ", " + color.b + ")");
            }
        }
Exemplo n.º 6
0
        // Populates color arrays from PawnSkinColors.SkinColors.  Uses an indirect method of getting the color values
        // instead of just copying the color list via reflection.  This will make it work better with mods that
        // detour the color methods in that class--as long as they detour the GetSkinDataIndexOfMelanin() method.
        public static void InitializeColors()
        {
            List <float> values = new List <float>();

            // Iterate all values from 0.0f to 1.0f, using increments of 0.01f, to get the left index for each value.
            // Use this technique to construct a list of all of the indexes and their values.  Once we have the list
            // of indexes and their values, we can use the GetSkinColor() method to get the actual colors.
            int currentIndex = 0;

            values.Add(0.0f);
            float f       = 0.01f;
            int   counter = 1;

            while (f < 1.0f)
            {
                int result = Reflection.PawnSkinColors.GetSkinDataIndexOfMelanin(f);
                if (result != currentIndex)
                {
                    currentIndex = result;
                    values.Add(f);
                }
                counter++;
                double d = (double)counter / 100.0;
                f = (float)d;
            }
            values.Add(1.0f);

            // Allocate the arrays and fill them with the correct values.
            int length = values.Count;

            Colors        = new Color[length];
            ColorValues   = new float[length];
            RoundedColors = new Color[length];
            for (int i = 0; i < length; i++)
            {
                float v     = values[i];
                Color color = PawnSkinColors.GetSkinColor(v);
                Colors[i]          = color;
                RoundedColors[i]   = color;
                RoundedColors[i].r = (float)Math.Round(color.r, 3);
                RoundedColors[i].g = (float)Math.Round(color.g, 3);
                RoundedColors[i].b = (float)Math.Round(color.b, 3);
                RoundedColors[i].a = (float)Math.Round(color.a, 3);
                ColorValues[i]     = v;
                //Logger.Debug("Color added: (" + color.r + ", " + color.g + ", " + color.b + ")");
            }
        }
        public override void DoEditInterface(Listing_ScenEdit listing)
        {
            phase += Time.deltaTime * step;

            float t = (Mathf.Sin(phase) + 1) / 2f;

            curCol = PawnSkinColors.GetSkinColor(melanin.LerpThroughRange(t));

            Rect rect = listing.GetScenPartRect(this, RowHeight * 4 + 31f);

            Rect[] rows = rect.SplitRows(31f, 4 * RowHeight);

            Rect[] cols = rows[0].SplitCols(rows[0].width - 31f, 31f);

            Widgets.FloatRange(cols[0], listing.CurHeight.GetHashCode(), ref melanin);
            Widgets.DrawBoxSolid(cols[1].ContractedBy(4), curCol);
            FixMelaninRange();

            DoContextEditInterface(rows[1]);
        }
Exemplo n.º 8
0
        public Color SkinColor(Pawn alien, bool first = true)
        {
            AlienComp alienComp = alien.TryGetComp <AlienComp>();

            if (alienComp.skinColor == Color.clear)
            {
                alienComp.skinColor       = (this.alienskincolorgen != null ? this.alienskincolorgen.NewRandomizedColor() : PawnSkinColors.GetSkinColor(alien.story.melanin));
                alienComp.skinColorSecond = (this.alienskinsecondcolorgen != null ? this.alienskinsecondcolorgen.NewRandomizedColor() : alienComp.skinColor);
            }
            return(first ? alienComp.skinColor : alienComp.skinColorSecond);
        }
Exemplo n.º 9
0
 public override Color NewRandomizedColor() =>
 PawnSkinColors.GetSkinColor(Rand.Range(this.minMelanin, this.maxMelanin));
Exemplo n.º 10
0
 static bool Prefix(ref Color __result)
 {
     __result = PawnSkinColors.GetSkinColor(WhiteOnly.settings.melaninRange.RandomInRange * 0.01f);
     return(false);
 }
Exemplo n.º 11
0
        public Color SkinColor(Pawn alien, bool first = true)
        {
            AlienComp alienComp = alien.TryGetComp <AlienComp>();

            if (alienComp.skinColor != Color.clear)
            {
                return(first ? alienComp.skinColor : alienComp.skinColorSecond);
            }

            alienComp.skinColor       = this.alienskincolorgen?.NewRandomizedColor() ?? PawnSkinColors.GetSkinColor(melanin: alien.story.melanin);
            alienComp.skinColorSecond = this.alienskinsecondcolorgen?.NewRandomizedColor() ?? alienComp.skinColor;
            return(first ? alienComp.skinColor : alienComp.skinColorSecond);
        }