/*
         * public static bool DebugSameColorAsWhat(this Color colorA, Color colorB)
         * {
         *  bool sameR = Math.Abs(colorA.r - colorB.r) < 0.01;
         *  bool sameG = Math.Abs(colorA.g - colorB.g) < 0.01;
         *  bool sameB = Math.Abs(colorA.b - colorB.b) < 0.01;
         *  bool sameA = Math.Abs(colorA.a - colorB.a) < 0.01;
         *
         *  Log.Warning(
         *      " ColorA:" + colorA +
         *      " ColorB:" + colorB +
         *      " R:" + sameR +
         *      " G:" + sameG+
         *      " B:" + sameB +
         *      " A:" + sameA
         *  );
         *
         *  return sameR && sameG && sameB && sameA;
         * }
         */

        public static Color PickAlienColor(this AlienPartGenerator.AlienComp a, string channelName, int channelNum)
        {
            return(channelNum == 1 ?
                   a.GetChannel(channelName).first :
                   (channelNum == 2 ? a.GetChannel(channelName).second : Color.white)
                   );
        }
Esempio n. 2
0
        public static AlienPartGenerator.AlienComp GetAlien(Pawn pawn = null)
        {
            AlienPartGenerator.AlienComp alienComp = null;
            alienComp = pawn?.TryGetComp <AlienPartGenerator.AlienComp>();

            return(alienComp);
        }
Esempio n. 3
0
 /// <summary>
 /// Gets the color of the skin.
 /// </summary>
 /// <param name="alienComp">The alien comp.</param>
 /// <param name="first">if set to <c>true</c> [first].</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">alienComp</exception>
 public static Color?GetSkinColor([NotNull] this AlienPartGenerator.AlienComp alienComp, bool first = true)
 {
     if (alienComp == null)
     {
         throw new ArgumentNullException(nameof(alienComp));
     }
     AlienPartGenerator.ExposableValueTuple <Color, Color> tuple = alienComp.ColorChannels.TryGetValue("skin");
     return(first ? tuple?.first : tuple?.second);
 }
Esempio n. 4
0
 /// <summary>
 /// Sets the color of the skin.
 /// </summary>
 /// <param name="alienComp">The alien comp.</param>
 /// <param name="first">The first.</param>
 /// <param name="second">The second.</param>
 /// <exception cref="ArgumentNullException">alienComp</exception>
 public static void SetSkinColor([NotNull] this AlienPartGenerator.AlienComp alienComp, Color first, Color?second = null)
 {
     if (alienComp == null)
     {
         throw new ArgumentNullException(nameof(alienComp));
     }
     alienComp.ColorChannels["skin"].first = first;
     if (second != null)
     {
         alienComp.ColorChannels["skin"].second = second.Value;
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Sets the color of the hair.
        /// </summary>
        /// <param name="alienComp">The alien comp.</param>
        /// <param name="first">The first.</param>
        /// <param name="second">The second.</param>
        /// <exception cref="ArgumentNullException">alienComp</exception>
        public static void SetHairColor([NotNull] this AlienPartGenerator.AlienComp alienComp, Color first, Color?second = null)
        {
            if (alienComp == null)
            {
                throw new ArgumentNullException(nameof(alienComp));
            }
            var tuple = alienComp.ColorChannels["hair"];

            tuple.first = first;
            if (second != null)
            {
                tuple.second = second.Value;
            }
        }
Esempio n. 6
0
        public static void SetAlienCrownType(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
        {
            if (!(comp.Pawn.IsAlien() && newPawn.IsAlien()))
            {
                return;
            }

            AlienPartGenerator.AlienComp templateAlien = comp.Pawn.TryGetComp <AlienPartGenerator.AlienComp>();
            AlienPartGenerator.AlienComp copyAlien     = newPawn?.TryGetComp <AlienPartGenerator.AlienComp>();

            if (templateAlien == null || copyAlien == null)
            {
                return;
            }

            copyAlien.crownType = templateAlien.crownType;
        }
Esempio n. 7
0
        public static void SetAlienSkinColor(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
        {
            /*
             * if (!(comp.Pawn.IsAlien() || newPawn.IsAlien()))
             *  return;
             */
            AlienPartGenerator.AlienComp templateAlien = comp.Pawn.TryGetComp <AlienPartGenerator.AlienComp>();
            AlienPartGenerator.AlienComp copyAlien     = newPawn?.TryGetComp <AlienPartGenerator.AlienComp>();

            if (templateAlien == null || copyAlien == null)
            {
                return;
            }

            Color skinColor1 = templateAlien.GetChannel("skin").first;
            Color skinColor2 = templateAlien.GetChannel("skin").second;

            copyAlien.GetChannel("skin").first  = skinColor1;
            copyAlien.GetChannel("skin").second = skinColor2;
        }
        public static List <ThingSettings> ThingSettingsWithColor(this HediffComp_RandySpawnUponDeath comp)
        {
            string debugStr =
                comp.MyDebug ?
                comp.Pawn.LabelShort + " ThingSettingsWithColor -" :
                "";

            if (comp.MyDebug)
            {
                Log.Warning(debugStr + " creating thing list with color");
            }

            if (!comp.HasColorCondition || !comp.Pawn.IsAlien())
            {
                if (comp.MyDebug)
                {
                    Log.Warning(debugStr + "Found no color condition or pawn is not alien");
                }
                return(null);
            }

            AlienPartGenerator.AlienComp alienComp = Tools.GetAlien(comp.Pawn);
            if (alienComp == null)
            {
                if (comp.MyDebug)
                {
                    Log.Warning(debugStr + "Found no AlienPartGenerator.AlienComp");
                }
                return(null);
            }

            if (comp.MyDebug)
            {
                Log.Warning(
                    debugStr + "colors=>" +
                    " skin.first:" + alienComp.GetChannel("skin").first +
                    " skin.second:" + alienComp.GetChannel("skin").second
                    );
            }

            List <ThingSettings> debugList = comp.FullOptionList.Where(
                t =>
                t.IsThingSpawner && t.HasColorCondition
                ).ToList();

            if (comp.MyDebug)
            {
                Log.Warning("Option num:" + debugList.Count);
            }

            Color PawnColor = alienComp.GetChannel("skin").first;

            //Color PawnColor = PickAlienColor(alienComp, t.colorCondition.channelName, t.colorCondition.channelNum)

            foreach (ThingSettings TS in debugList)
            {
                if (comp.MyDebug)
                {
                    Log.Warning(
                        " TS.Def: " + TS.thingToSpawn.defName +
                        "; TS.color: " + TS.thingToSpawn.PickStuffColor() +
                        "; P.color: " + PawnColor +
                        "; equals: " + PawnColor.SameColorAs(TS.thingToSpawn.PickStuffColor())
                        //"; equals what:" + PawnColor.SameColorAsWhat(TS.thingToSpawn.graphicData.color),
                        );
                }
            }



            List <ThingSettings> answer = new List <ThingSettings>();

            answer = comp.FullOptionList.Where(
                t =>
                t.IsThingSpawner && t.HasColorCondition &&
                PawnColor.SameColorAs(t.thingToSpawn.PickStuffColor())

                /*
                 * PickAlienColor(alienComp, t.colorCondition.channelName, t.colorCondition.channelNum).SameColorAs(t.thingToSpawn.graphicData.color)
                 */
                ).ToList();

            if (comp.MyDebug)
            {
                Log.Warning(debugStr + "Found " + answer.Count + " things with color");
            }

            return(answer);
        }
        protected void DrawColorSelector(Rect crect, List <Color> colors, bool allowAnyColor)
        {
            Color currentColor = this.NewHairColor;
            Rect  rect         = new Rect(SwatchPosition.x, crect.y + 5f, SwatchSize.x, SwatchSize.y);

            if (colors != null)
            {
                foreach (Color color in colors)
                {
                    bool selected = (color == currentColor);
                    if (selected)
                    {
                        Rect selectionRect = new Rect(rect.x - 2, rect.y - 2, SwatchSize.x + 4, SwatchSize.y + 4);
                        GUI.color = ColorSwatchSelection;
                        GUI.DrawTexture(selectionRect, BaseContent.WhiteTex);
                    }

                    Rect borderRect = new Rect(rect.x - 1, rect.y - 1, SwatchSize.x + 2, SwatchSize.y + 2);
                    GUI.color = ColorSwatchBorder;
                    GUI.DrawTexture(borderRect, BaseContent.WhiteTex);

                    GUI.color = color;
                    GUI.DrawTexture(rect, BaseContent.WhiteTex);

                    if (!selected)
                    {
                        if (Widgets.ButtonInvisible(rect, false))
                        {
                            this.NewHairColor = (color);
                            currentColor      = color;

                            if (this.useSkincolorForHair)
                            {
                                AlienPartGenerator.AlienComp comp = Pawn.TryGetComp <AlienPartGenerator.AlienComp>();
                                comp.skinColor = currentColor;
                            }

                            this.RerenderPawn = true;
                        }
                    }

                    rect.x += SwatchSpacing.x;
                    if (rect.x >= SwatchLimit - SwatchSize.x)
                    {
                        rect.y += SwatchSpacing.y;
                        rect.x  = SwatchPosition.x;
                    }
                }
            }

            GUI.color = Color.white;
            if (!allowAnyColor)
            {
                return;
            }

            if (rect.x != SwatchPosition.x)
            {
                rect.x  = SwatchPosition.x;
                rect.y += SwatchSpacing.y;
            }

            rect.y     += 4;
            rect.width  = 49;
            rect.height = 49;
            GUI.color   = ColorSwatchBorder;
            GUI.DrawTexture(rect, BaseContent.WhiteTex);
            GUI.color = currentColor;
            GUI.DrawTexture(rect.ContractedBy(1), BaseContent.WhiteTex);

            GUI.color = Color.red;
            float originalR = currentColor.r;
            float originalG = currentColor.g;
            float originalB = currentColor.b;
            float r         = GUI.HorizontalSlider(new Rect(rect.x + 56, rect.y - 1, 136, 16), currentColor.r, 0, 1);

            GUI.color = Color.green;
            float g = GUI.HorizontalSlider(new Rect(rect.x + 56, rect.y + 19, 136, 16), currentColor.g, 0, 1);

            GUI.color = Color.blue;
            float b = GUI.HorizontalSlider(new Rect(rect.x + 56, rect.y + 39, 136, 16), currentColor.b, 0, 1);

            if (!this.CloseEnough(r, originalR) || !this.CloseEnough(g, originalG) || !this.CloseEnough(b, originalB))
            {
                this.NewHairColor = (new Color(r, g, b));
                if (this.useSkincolorForHair)
                {
                    AlienPartGenerator.AlienComp comp = Pawn.TryGetComp <AlienPartGenerator.AlienComp>();
                    comp.skinColor = this.NewHairColor;
                }

                this.RerenderPawn = true;
            }

            GUI.color = Color.white;
        }
Esempio n. 10
0
        /*
         * public static float DrawSize(float original, bool portrait, Pawn pawn, AlienRace.AlienPartGenerator.BodyAddon addon)
         * {
         *  float result = original;
         *  LinkedBodyAddon linked = addon as LinkedBodyAddon;
         *  if (linked != null && linked.linkLifeStageDrawSize)
         *  {
         *      ThingDef_AlienRace thingDef_AlienRace = pawn.def as ThingDef_AlienRace;
         *      GraphicPaths paths = thingDef_AlienRace.alienRace.graphicPaths.GetCurrentGraphicPath(pawn.ageTracker.CurLifeStage);
         *      Vector2 v = linked.alignWithHead ? (portrait? paths.customPortraitHeadDrawSize : paths.customHeadDrawSize) : (portrait ? paths.customPortraitDrawSize : paths.customDrawSize);
         *      result *= (v.x + v.y) / 2f;
         *      //    Log.Message("DrawSize result: " + result);
         *  }
         *
         *  return result;
         * }
         */
        public static Vector2 DrawSize(Vector2 original, bool portrait, AlienRace.AlienPartGenerator.BodyAddon addon, AlienPartGenerator.AlienComp alienComp)
        {
            if (addon is LinkedBodyAddon linked && linked.linkLifeStageDrawSize)
            {
                // ThingDef_AlienRace thingDef_AlienRace = pawn.def as ThingDef_AlienRace;
                // AlienPartGenerator.AlienComp alienComp = pawn.GetComp<AlienPartGenerator.AlienComp>();
                return(((portrait && addon.drawSizePortrait != Vector2.zero) ? addon.drawSizePortrait : addon.drawSize) * (addon.scaleWithPawnDrawsize ? (linked.alignWithHead ? alienComp.customHeadDrawSize : alienComp.customDrawSize) : Vector2.one) * 1.5f);
            }

            return(original);
        }
Esempio n. 11
0
        //public static bool DrawAddons_Prefix(bool portrait, Pawn pawn, Vector3 vector, Quaternion quat, Rot4 rotation)
        //{
        //    if (pawn.ageTracker.CurLifeStageIndex < AgeStage.Child)
        //    { return false; }
        //    return true;
        //}

        public static bool DrawAddons_Prefix(bool portrait, Pawn pawn, Vector3 vector, Quaternion quat, Rot4 rotation)
        {
            if (!(pawn.def is ThingDef_AlienRace alienProps))
            {
                return(false);
            }

            // don't make addon for baby & toddler
            if (pawn.ageTracker.CurLifeStageIndex < AgeStage.Child)
            {
                return(false);
            }

            List <AlienPartGenerator.BodyAddon> addons = alienProps.alienRace.generalSettings.alienPartGenerator.bodyAddons;

            AlienPartGenerator.AlienComp alienComp = pawn.GetComp <AlienPartGenerator.AlienComp>();
            for (int i = 0; i < addons.Count; i++)
            {
                AlienPartGenerator.BodyAddon ba = addons[index : i];

                if (!ba.CanDrawAddon(pawn: pawn))
                {
                    continue;
                }

                AlienPartGenerator.RotationOffset offset = rotation == Rot4.South ?
                                                           ba.offsets.south :
                                                           rotation == Rot4.North ?
                                                           ba.offsets.north :
                                                           rotation == Rot4.East ?
                                                           ba.offsets.east :
                                                           ba.offsets.west;

                Vector2 bodyOffset = (portrait ? offset?.portraitBodyTypes ?? offset?.bodyTypes : offset?.bodyTypes)?.FirstOrDefault(predicate: to => to.bodyType == pawn.story.bodyType)
                                     ?.offset ?? Vector2.zero;
                Vector2 crownOffset = (portrait ? offset?.portraitCrownTypes ?? offset?.crownTypes : offset?.crownTypes)?.FirstOrDefault(predicate: to => to.crownType == alienComp.crownType)
                                      ?.offset ?? Vector2.zero;

                //Defaults for tails
                //south 0.42f, -0.3f, -0.22f
                //north     0f,  0.3f, -0.55f
                //east -0.42f, -0.3f, -0.22f

                float moffsetX = 0.42f;
                float moffsetZ = -0.22f;
                float moffsetY = ba.inFrontOfBody ? 0.3f + ba.layerOffset : -0.3f - ba.layerOffset;
                float num      = ba.angle;

                if (rotation == Rot4.North)
                {
                    moffsetX = 0f;
                    moffsetY = !ba.inFrontOfBody ? -0.3f - ba.layerOffset : 0.3f + ba.layerOffset;
                    moffsetZ = -0.55f;
                    num      = 0;
                }

                moffsetX += bodyOffset.x + crownOffset.x;
                moffsetZ += bodyOffset.y + crownOffset.y;

                if (rotation == Rot4.East)
                {
                    moffsetX = -moffsetX;
                    num      = -num; //Angle
                }

                Vector3 offsetVector = new Vector3(x: moffsetX, y: moffsetY, z: moffsetZ);

                Material dmat    = alienComp.addonGraphics[index : i].MatAt(rot : rotation);
                Vector3  rootloc = vector;

                // adjust tail scale
                if (pawn.ageTracker.CurLifeStageIndex == AgeStage.Child && !ba.inFrontOfBody)
                {
                    const float TextureScaleX  = 1.225f;
                    const float TextureScaleY  = 1.225f;
                    const float TextureOffsetX = -0.09f;
                    const float TextureOffsetY = 0f;
                    const float dVectorOffsetX = 0.16f;
                    const float dVectorOffsetY = 0f;
                    const float dVectorOffsetZ = 0.32f;
                    Material    xmat           = new Material(dmat);

                    //float TextureScaleX = CnP_Settings.option_debug_scale_X;
                    //float TextureScaleY = CnP_Settings.option_debug_scale_Y;
                    //float TextureOffsetX = CnP_Settings.option_debug_offset_X;
                    //float TextureOffsetY = CnP_Settings.option_debug_offset_Y;
                    //float dVectorOffsetX = 0.16f;  // CnP_Settings.option_debug_loc_X;
                    //float dVectorOffsetY = 0f;   // CnP_Settings.option_debug_loc_Y;
                    //float dVectorOffsetZ = 0.32f;   // CnP_Settings.option_debug_loc_Z;

                    if (rotation == Rot4.East)
                    {
                        offsetVector.x += dVectorOffsetX;
                    }
                    if (rotation == Rot4.West)
                    {
                        offsetVector.x -= dVectorOffsetX;
                    }

                    offsetVector.y += dVectorOffsetY;
                    offsetVector.z += dVectorOffsetZ;

                    xmat.mainTextureScale  = new Vector2(TextureScaleX, TextureScaleY);
                    xmat.mainTextureOffset = new Vector2(TextureOffsetX, TextureOffsetY);
                    dmat = xmat;
                }
                //////////////////////////////////////////////////////////////////////////////////////////////////

                GenDraw.DrawMeshNowOrLater(mesh: alienComp.addonGraphics[index: i].MeshAt(rot: rotation), loc: rootloc + offsetVector.RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: quat)) * 2f * 57.29578f),
                                           quat: Quaternion.AngleAxis(angle: num, axis: Vector3.up) * quat, mat: dmat, drawNow: portrait);
            }
            return(false);
        }
Esempio n. 12
0
        // closed match in RGB space
        public static Color ClosestColor(Pawn pawn, bool complementary = false, bool myDebug = false)
        {
            AlienPartGenerator.AlienComp alienComp = Tools.GetAlien(pawn);

            Color pColor;

            if (alienComp == null)
            {
                pColor = pawn.DrawColor;
            }
            else
            {
                pColor = alienComp.GetChannel("skin").first;
                Tools.Warn(pawn.LabelShort + " is alien, color=" + pColor, myDebug);
            }


            Color answer = Color.blue;

            float purpleDiff, blueDiff, cyanDiff, greenDiff, yellowDiff, orangeDiff, redDiff;
            float minVal = 1000f;

            //1 0 1
            purpleDiff = (
                Math.Abs(pColor.r - MyGfx.Purple.r) +
                Math.Abs(pColor.g - MyGfx.Purple.g) / 4 +
                Math.Abs(pColor.b - MyGfx.Purple.b)
                );
            // 0 0 1
            blueDiff = (
                Math.Abs(pColor.r - MyGfx.Blue.r) / 2 +
                Math.Abs(pColor.g - MyGfx.Blue.g) / 2 +
                Math.Abs(pColor.b - MyGfx.Blue.b)
                );
            // 0 1 1
            cyanDiff = (
                Math.Abs(pColor.r - MyGfx.Cyan.r) / 4 +
                Math.Abs(pColor.g - MyGfx.Cyan.g) +
                Math.Abs(pColor.b - MyGfx.Cyan.b)
                );

            // 0 1 0
            greenDiff = (
                Math.Abs(pColor.r - MyGfx.Green.r) / 2 +
                Math.Abs(pColor.g - MyGfx.Green.g) +
                Math.Abs(pColor.b - MyGfx.Green.b) / 2
                );
            // 1 1 0
            yellowDiff = (
                Math.Abs(pColor.r - MyGfx.Yellow.r) +
                Math.Abs(pColor.g - MyGfx.Yellow.g) +
                Math.Abs(pColor.b - MyGfx.Yellow.b) / 4
                );
            // 1 .6 0
            orangeDiff = (
                Math.Abs(pColor.r - MyGfx.Orange.r) +
                Math.Abs(pColor.g - MyGfx.Orange.g) / 1.6f +
                Math.Abs(pColor.b - MyGfx.Orange.b) / 2.5f
                );
            // 1 0 0
            redDiff = (
                Math.Abs(pColor.r - MyGfx.Red.r) +
                Math.Abs(pColor.g - MyGfx.Red.g) / 2 +
                Math.Abs(pColor.b - MyGfx.Red.b) / 2
                );


            Tools.Warn(
                pawn.LabelShort + "'s pColor: " + pColor
                , myDebug
                );
            Tools.Warn(
                "purpleDiff: " + purpleDiff +
                "; blueDiff: " + blueDiff +
                "; cyanDiff: " + cyanDiff +
                "; greenDiff: " + greenDiff +
                "; yellowDiff: " + yellowDiff +
                "; orangeDiff: " + orangeDiff +
                "; redDiff: " + redDiff
                , myDebug
                );


            if (purpleDiff < minVal)
            {
                minVal = purpleDiff;
                answer = MyGfx.Purple;
            }
            if (blueDiff < minVal)
            {
                minVal = blueDiff;
                answer = MyGfx.Blue;
            }
            if (cyanDiff < minVal)
            {
                minVal = cyanDiff;
                answer = MyGfx.Blue;
            }
            if (greenDiff < minVal)
            {
                minVal = greenDiff;
                answer = MyGfx.Green;
            }
            if (yellowDiff < minVal)
            {
                minVal = yellowDiff;
                answer = MyGfx.Yellow;
            }
            if (orangeDiff < minVal)
            {
                minVal = orangeDiff;
                answer = MyGfx.Orange;
            }
            if (redDiff < minVal)
            {
                minVal = redDiff;
                answer = MyGfx.Red;
            }

            if (complementary)
            {
                if (answer == MyGfx.Purple)
                {
                    answer = MyGfx.Yellow;
                }
                else if ((answer == MyGfx.Blue) || (answer == MyGfx.Cyan))
                {
                    answer = MyGfx.Orange;
                }
                else if (answer == MyGfx.Green)
                {
                    answer = MyGfx.Red;
                }
                else if (answer == MyGfx.Yellow)
                {
                    answer = MyGfx.Purple;
                }
                else if (answer == MyGfx.Orange)
                {
                    answer = MyGfx.Blue;
                }
                else if (answer == MyGfx.Red)
                {
                    answer = MyGfx.Green;
                }
            }

            Tools.Warn((complementary)?"complementary":"closest" + " Color=" + answer, myDebug);

            return(answer);
        }