Пример #1
0
        public override void DrawWornExtras()
        {
            base.DrawWornExtras();
            if (!Pauldrons.NullOrEmpty())
            {
                PawnRenderFlags flags      = Wearer.Drawer.renderer.GetDefaultRenderFlags(Wearer);
                Quaternion      quat       = Quaternion.AngleAxis(0, Vector3.up);
                Vector3         vector     = Wearer.Drawer.renderer.GetBodyPos(Wearer.DrawPos, out bool renderBody);
                Rot4            headfacing = Wearer.Rotation;
                Rot4            bodyFacing = Wearer.Rotation;
                bool            portrait   = flags.FlagSet(PawnRenderFlags.Portrait);
                Vector2         size       = (portrait ? MeshPool.humanlikeBodySet.MeshAt(bodyFacing).bounds.size : Wearer.Drawer.renderer.graphics.nakedGraphic.MeshAt(bodyFacing).bounds.size);
                if (AdeptusIntergrationUtility.enabled_AlienRaces)
                {
                    PawnRenderUtility.AlienRacesPatch(Wearer, bodyFacing, out size, portrait);
                }
                else
                {
                    size = new Vector2(1.5f, 1.5f);
                }
                foreach (CompPauldronDrawer Pauldron in Pauldrons)
                {
                    Vector3 center = vector + (quat * Pauldron.GetOffsetFor(bodyFacing, false));
                    if (Pauldron.activeEntries.NullOrEmpty())
                    {
                        Pauldron.Initialize();
                    }
                    foreach (ShoulderPadEntry entry in Pauldron.activeEntries)
                    {
                        //    entry.Drawer = Pauldron;
                        if (entry.apparel == null)
                        {
                            entry.apparel = this;
                        }
                        if (entry.Drawer == null)
                        {
                            Log.Warning("Warning! Drawer null");
                        }
                        if (!entry.ForceDynamicDraw)
                        {
                            continue;
                        }

                        if (entry.ShouldDrawEntry(flags, bodyFacing, size, renderBody, out Graphic pauldronMat, out Mesh pauldronMesh, out Vector3 offset))
                        {
                            if (Pauldron.onHead || renderBody)
                            {
                                Vector3 drawAt = Wearer.Drawer.DrawPos + (quat * Pauldron.GetOffsetFor(bodyFacing, false));

                                /*
                                 * drawAt.y += 0.009687258f;
                                 * drawAt.y += 0.022166021f;
                                 * drawAt.y += 0.028957527f;
                                 * drawAt.y += 0.97f;
                                 */
                                GenDraw.DrawMeshNowOrLater
                                (
                                    // pauldronMesh,
                                    PawnRenderUtility.GetPawnMesh(portrait, Wearer, entry.Props.flipWest && bodyFacing == Rot4.West ? bodyFacing.Opposite : bodyFacing, !Pauldron.onHead),
                                    drawAt + (quat * offset),
                                    quat,
                                    PawnRenderUtility.OverrideMaterialIfNeeded(pauldronMat.MatAt(bodyFacing), Wearer),
                                    flags.FlagSet(PawnRenderFlags.DrawNow)
                                );
                            }
                        }
                    }
                }
            }
            if (!Extras.NullOrEmpty())
            {
                PawnRenderFlags flags      = Wearer.Drawer.renderer.GetDefaultRenderFlags(Wearer);
                Quaternion      quat       = Quaternion.AngleAxis(0, Vector3.up);
                Vector3         vector     = Wearer.DrawPos;
                Rot4            headfacing = Wearer.Rotation;
                Rot4            bodyFacing = Wearer.Rotation;
                bool            portrait   = flags.FlagSet(PawnRenderFlags.Portrait);
                Vector2         size       = (portrait ? MeshPool.humanlikeBodySet.MeshAt(bodyFacing).bounds.size : Wearer.Drawer.renderer.graphics.nakedGraphic.MeshAt(bodyFacing).bounds.size);
                if (AdeptusIntergrationUtility.enabled_AlienRaces)
                {
                    PawnRenderUtility.AlienRacesPatch(Wearer, bodyFacing, out size, portrait);
                }
                else
                {
                    size = new Vector2(1.5f, 1.5f);
                }
                foreach (CompApparelExtraPartDrawer ExtraDrawer in Extras)
                {
                    Vector3 drawAt = Wearer.DrawPos;
                    if (!ExtraDrawer.Props.ExtrasEntries.NullOrEmpty())
                    {
                        bool onHead = ExtraDrawer.onHead || ExtraDrawer.ExtraPartEntry.OnHead || ExtraDrawer.Props.onHead;
                        Rot4 facing = onHead ? headfacing : bodyFacing;
                        if (!ExtraDrawer.ExtraPartEntry.DynamicDraw)
                        {
                            continue;
                        }
                        if (ExtraDrawer.ShouldDrawExtra(Wearer, this, facing, out Material extraMat))
                        {
                            if (onHead || !PawnRenderFlagsExtension.FlagSet(flags, PawnRenderFlags.Invisible))
                            {
                                if (onHead)
                                {
                                    Vector3 v = vector + quat * Wearer.Drawer.renderer.BaseHeadOffsetAt(headfacing);
                                    drawAt = v + quat * new Vector3(ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).x *size.x, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).y, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).z *size.y);
                                }
                                else
                                {
                                    drawAt = vector + (quat * new Vector3(ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).x *size.x, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).y, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).z *size.y));
                                }

                                /*
                                 * GenDraw.DrawMeshNowOrLater
                                 *  (
                                 *      // pauldronMesh,
                                 *      PawnRenderUtility.GetPawnMesh(portrait, Wearer, facing, !onHead),
                                 *      drawAt,
                                 *      quat,
                                 *      PawnRenderUtility.OverrideMaterialIfNeeded(extraMat, Wearer),
                                 *      ExtraDrawer.ExtraPartEntry.animateExtra
                                 *  );
                                 */
                                Graphics.DrawMesh(
                                    PawnRenderUtility.GetPawnMesh(portrait, Wearer, facing, !onHead),
                                    drawAt,
                                    quat,
                                    PawnRenderUtility.OverrideMaterialIfNeeded(extraMat, Wearer),
                                    0);
                            }
                            //    vector.y += CompApparelExtaDrawer.MinClippingDistance;
                        }
                    }
                }
            }

            if (!Shields.NullOrEmpty())
            {
                foreach (var item in Shields)
                {
                    item.DrawShield();
                }
            }
        }
        public static void DrawAddons(ref PawnRenderFlags flags, Vector3 vector, Pawn pawn, Quaternion quat, Rot4 bodyFacing, Mesh mesh, Rot4 headfacing, bool renderBody)
        {
            if (!pawn.RaceProps.Humanlike || PawnRenderFlagsExtension.FlagSet(flags, (PawnRenderFlags)4))
            {
                return;
            }

            /*
             * //    Log.Message(string.Concat(new string[]
             * {
             *  "DRAWING EXTRAS FOR: " + pawn.NameFullColored + " | " + flags.ToString() + " | ",
             *  (!pawn.RaceProps.Humanlike || PawnRenderFlagsExtension.FlagSet(flags, (PawnRenderFlags)4)).ToString(),
             *  " | ",
             *  PawnRenderFlagsExtension.FlagSet(flags, (PawnRenderFlags)4).ToString(),
             *  " | ",
             *  (!pawn.RaceProps.Humanlike).ToString()
             * }));
             */
            //    Log.Message("DrawAddons "+ flags.ToString());
            if (flags.FlagSet(PawnRenderFlags.Invisible))
            {
                //    Log.Message("PawnRenderFlags.Invisible");
                return;
            }
            bool    portrait    = flags.FlagSet(PawnRenderFlags.Portrait);
            Vector2 defaultSize = mesh?.bounds.size ?? (portrait ? MeshPool.humanlikeBodySet.MeshAt(bodyFacing).bounds.size : pawn.Drawer.renderer.graphics.nakedGraphic.MeshAt(bodyFacing).bounds.size);
            Vector2 size        = mesh?.bounds.size ?? (portrait ? MeshPool.humanlikeBodySet.MeshAt(bodyFacing).bounds.size : pawn.Drawer.renderer.graphics.nakedGraphic.MeshAt(bodyFacing).bounds.size);

            if (pawn.RaceProps.Humanlike)
            {
                if (pawn.apparel != null && pawn.apparel.WornApparelCount > 0)
                {
                    //    Log.Message("DrawAddons for "+ pawn.apparel.WornApparelCount+" apparel");
                    if (AdeptusIntergrationUtility.enabled_AlienRaces)
                    {
                        PawnRenderUtility.AlienRacesPatch(pawn, bodyFacing, out size, portrait);
                    }
                    else
                    {
                        size = new Vector2(1.5f, 1.5f);
                    }

                    List <Apparel> worn = pawn.apparel.WornApparel;
                    for (int wa = 0; wa < worn.Count; wa++)
                    {
                        Apparel apparel = worn[wa];
                        if (apparel is ApparelComposite composite)
                        {
                            //     Log.Message("composite");
                            if (!composite.Pauldrons.NullOrEmpty() && AMAMod.settings.AllowPauldronDrawer)
                            {
                                for (int i = 0; i < composite.Pauldrons.Count; i++)
                                {
                                    CompPauldronDrawer Pauldron = composite.Pauldrons[i] as CompPauldronDrawer;
                                    if (Pauldron != null)
                                    {
                                        Vector3 center = vector + (quat * Pauldron.GetOffsetFor(bodyFacing, false));
                                        if (Pauldron.activeEntries.NullOrEmpty())
                                        {
                                            Pauldron.Initialize();
                                        }
                                        foreach (ShoulderPadEntry entry in Pauldron.activeEntries)
                                        {
                                            //    entry.Drawer = Pauldron;
                                            if (entry.apparel == null)
                                            {
                                                entry.apparel = apparel;
                                            }
                                            if (entry.Drawer == null)
                                            {
                                                Log.Warning("Warning! Drawer null");
                                            }

                                            /*
                                             * if (entry.ForceDynamicDraw)
                                             * {
                                             *  continue;
                                             * }
                                             */
                                            if (entry.ShouldDrawEntry(flags, bodyFacing, size, renderBody, out Graphic pauldronMat, out Mesh pauldronMesh, out Vector3 offset))
                                            {
                                                if (Pauldron.onHead || renderBody)
                                                {
                                                    GenDraw.DrawMeshNowOrLater
                                                    (
                                                        // pauldronMesh,
                                                        PawnRenderUtility.GetPawnMesh(portrait, pawn, entry.Props.flipWest && bodyFacing == Rot4.West ? bodyFacing.Opposite : bodyFacing, !Pauldron.onHead),
                                                        center + (quat * offset),
                                                        quat,
                                                        PawnRenderUtility.OverrideMaterialIfNeeded(pauldronMat.MatAt(bodyFacing), pawn),
                                                        flags.FlagSet(PawnRenderFlags.DrawNow)
                                                    );
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (!composite.Extras.NullOrEmpty() && AMAMod.settings.AllowExtraPartDrawer)
                            {
                                for (int i = 0; i < composite.Extras.Count; i++)
                                {
                                    CompApparelExtraPartDrawer ExtraDrawer = composite.Extras[i];
                                    if (ExtraDrawer != null)
                                    {
                                        if (ExtraDrawer.hidesHead)
                                        {
                                            flags |= PawnRenderFlags.HeadStump;
                                        }
                                        Vector3 drawAt = vector;
                                        if (!ExtraDrawer.Props.ExtrasEntries.NullOrEmpty())
                                        {
                                            bool onHead = ExtraDrawer.onHead || ExtraDrawer.ExtraPartEntry.OnHead || ExtraDrawer.Props.onHead;
                                            Rot4 facing = onHead ? headfacing : bodyFacing;
                                            if (ExtraDrawer.ExtraPartEntry.DynamicDraw)
                                            {
                                                continue;
                                            }
                                            if (ExtraDrawer.ShouldDrawExtra(pawn, apparel, facing, out Material extraMat))
                                            {
                                                if (onHead || renderBody)
                                                {
                                                    if (onHead)
                                                    {
                                                        Vector3 v = vector + quat * pawn.Drawer.renderer.BaseHeadOffsetAt(headfacing);
                                                        drawAt = v + quat * new Vector3(ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).x *size.x, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).y, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).z *size.y);
                                                    }
                                                    else
                                                    {
                                                        drawAt = vector + (quat * new Vector3(ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).x *size.x, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).y, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).z *size.y));
                                                    }
                                                    GenDraw.DrawMeshNowOrLater
                                                    (
                                                        // pauldronMesh,
                                                        PawnRenderUtility.GetPawnMesh(portrait, pawn, facing, !onHead),
                                                        drawAt,
                                                        quat,
                                                        PawnRenderUtility.OverrideMaterialIfNeeded(extraMat, pawn),
                                                        flags.FlagSet(PawnRenderFlags.DrawNow) || ExtraDrawer.ExtraPartEntry.DynamicDraw
                                                    );
                                                }
                                                //    vector.y += CompApparelExtaDrawer.MinClippingDistance;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            //    Log.Message("noncomposite");
                            for (int i = 0; i < apparel.AllComps.Count; i++)
                            {
                                if (AMAMod.settings.AllowPauldronDrawer)
                                {
                                    CompPauldronDrawer Pauldron = apparel.AllComps[i] as CompPauldronDrawer;
                                    if (Pauldron != null)
                                    {
                                        //    Log.Message("Pauldron");
                                        Vector3 center = vector + (quat * Pauldron.GetOffsetFor(bodyFacing, false));
                                        if (Pauldron.activeEntries.NullOrEmpty())
                                        {
                                            Pauldron.Initialize();
                                        }
                                        foreach (ShoulderPadEntry entry in Pauldron.activeEntries)
                                        {
                                            //    entry.Drawer = Pauldron;
                                            if (entry.apparel == null)
                                            {
                                                entry.apparel = apparel;
                                            }
                                            if (entry.Drawer == null)
                                            {
                                                Log.Warning("Warning! Drawer null");
                                            }
                                            if (entry.ForceDynamicDraw)
                                            {
                                                continue;
                                            }
                                            if (entry.ShouldDrawEntry(flags, bodyFacing, size, renderBody, out Graphic pauldronMat, out Mesh pauldronMesh, out Vector3 offset))
                                            {
                                                if (Pauldron.onHead || renderBody && pauldronMat != null)
                                                {
                                                    //    Log.Message("Pauldron DrawMeshNowOrLater " + !flags.FlagSet(PawnRenderFlags.Cache));
                                                    GenDraw.DrawMeshNowOrLater
                                                    (
                                                        // pauldronMesh,
                                                        PawnRenderUtility.GetPawnMesh(portrait, pawn, entry.Props.flipWest && bodyFacing == Rot4.West ? bodyFacing.Opposite : bodyFacing, !Pauldron.onHead),
                                                        center + (quat * offset),
                                                        quat,
                                                        PawnRenderUtility.OverrideMaterialIfNeeded(pauldronMat.MatAt(bodyFacing), pawn),
                                                        flags.FlagSet(PawnRenderFlags.DrawNow)
                                                    );
                                                }
                                            }
                                        }
                                    }
                                }
                                if (AMAMod.settings.AllowExtraPartDrawer)
                                {
                                    CompApparelExtraPartDrawer ExtraDrawer = apparel.AllComps[i] as CompApparelExtraPartDrawer;
                                    if (ExtraDrawer != null)
                                    {
                                        //    Log.Message("ExtraDrawer");
                                        Vector3 drawAt = vector;
                                        if (!ExtraDrawer.Props.ExtrasEntries.NullOrEmpty())
                                        {
                                            bool onHead = ExtraDrawer.onHead || ExtraDrawer.ExtraPartEntry.OnHead || ExtraDrawer.Props.onHead;
                                            Rot4 facing = onHead ? headfacing : bodyFacing;
                                            if (ExtraDrawer.ExtraPartEntry.DynamicDraw)
                                            {
                                                continue;
                                            }
                                            if (ExtraDrawer.ShouldDrawExtra(pawn, apparel, facing, out Material extraMat))
                                            {
                                                if (onHead || renderBody)
                                                {
                                                    if (onHead)
                                                    {
                                                        Vector3 v = vector + quat * pawn.Drawer.renderer.BaseHeadOffsetAt(headfacing);
                                                        drawAt = v + quat * new Vector3(ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).x *size.x, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).y, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).z *size.y);
                                                    }
                                                    else
                                                    {
                                                        drawAt = vector + (quat * new Vector3(ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).x *size.x, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).y, ExtraDrawer.GetOffset(bodyFacing, ExtraDrawer.ExtraPartEntry).z *size.y));
                                                    }
                                                    //    Log.Message("ExtraDrawer DrawMeshNowOrLater "+ !flags.FlagSet(PawnRenderFlags.Cache));
                                                    GenDraw.DrawMeshNowOrLater
                                                    (
                                                        // pauldronMesh,
                                                        PawnRenderUtility.GetPawnMesh(portrait, pawn, facing, !onHead),
                                                        drawAt,
                                                        quat,
                                                        PawnRenderUtility.OverrideMaterialIfNeeded(extraMat, pawn),
                                                        flags.FlagSet(PawnRenderFlags.DrawNow) || ExtraDrawer.ExtraPartEntry.DynamicDraw
                                                    );
                                                }
                                                //    vector.y += CompApparelExtaDrawer.MinClippingDistance;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (!pawn.Dead && AMAMod.settings.AllowHediffPartDrawer)
            {
                Vector3 drawAt = vector;
                for (int i = 0; i < AdeptusHediffUtility.GraphicHediffs.Count; i++)
                {
                    if (pawn.health.hediffSet.GetFirstHediffOfDef(AdeptusHediffUtility.GraphicHediffs[i]) is HediffWithComps hediff)
                    {
                        if (hediff.TryGetCompFast <HediffComp_DrawImplant_AdMech>() is HediffComp_DrawImplant_AdMech drawer)
                        {
                            Material material = null;
                            if (drawer.implantDrawProps.implantDrawerType != ImplantDrawerType.Head)
                            {
                                drawAt.y += 0.005f;
                                if (bodyFacing == Rot4.South && drawer.implantDrawProps.implantDrawerType == ImplantDrawerType.Backpack)
                                {
                                    drawAt.y -= 0.3f;
                                }
                                material = drawer.ImplantMaterial(pawn, bodyFacing);
                                //    GenDraw.DrawMeshNowOrLater(mesh, drawAt, quat, material, portrait);
                            }
                            else
                            {
                                if (!pawn.Downed && !pawn.Dead && drawer.implantDrawProps.useHeadOffset)
                                {
                                    drawAt = vector + pawn.Drawer.renderer.BaseHeadOffsetAt(headfacing);
                                }
                                else
                                {
                                    if ((pawn.Downed || pawn.Dead) && drawer.implantDrawProps.useHeadOffset)
                                    {
                                        drawAt.y = vector.y + pawn.Drawer.renderer.BaseHeadOffsetAt(headfacing).y;
                                    }
                                }
                                drawAt.y += 0.005f;
                                material  = drawer.ImplantMaterial(pawn, headfacing);
                                //    GenDraw.DrawMeshNowOrLater(mesh, drawAt, quat, material, portrait);
                            }

                            if (material != null)
                            {
                                //    GenDraw.DrawMeshNowOrLater(mesh, drawAt , quat, material, portrait);

                                material = PawnRenderUtility.OverrideMaterialIfNeeded(material, pawn);
                                //                                                                                        Angle calculation to not pick the shortest, taken from Quaternion.Angle and modified
                                GenDraw.DrawMeshNowOrLater(mesh: mesh, loc: drawAt + drawer.offsetVector().RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: quat)) * 2f * 57.29578f),
                                                           quat: quat, mat: material, drawNow: flags.FlagSet(PawnRenderFlags.DrawNow));

                                drawAt.y += HediffComp_DrawImplant_AdMech.MinClippingDistance;
                            }
                        }
                    }
                }

                /*
                 * for (int hd = 0; hd < pawn.health.hediffSet.hediffs.Count; hd++)
                 * {
                 *  Vector3 drawAt = vector;
                 *  HediffWithComps hediff = pawn.health.hediffSet.hediffs[hd] as HediffWithComps;
                 *  if (hediff != null)
                 *  {
                 *      for (int i = 0; i < hediff.comps.Count; i++)
                 *      {
                 *          HediffComp_DrawImplant_AdMech drawer = hediff.comps[i] as HediffComp_DrawImplant_AdMech;
                 *          if (drawer != null)
                 *          {
                 *              Material material = null;
                 *              if (drawer.implantDrawProps.implantDrawerType != ImplantDrawerType.Head)
                 *              {
                 *                  drawAt.y += 0.005f;
                 *                  if (bodyFacing == Rot4.South && drawer.implantDrawProps.implantDrawerType == ImplantDrawerType.Backpack)
                 *                  {
                 *                      drawAt.y -= 0.3f;
                 *                  }
                 *                  material = drawer.ImplantMaterial(pawn, bodyFacing);
                 *                  //    GenDraw.DrawMeshNowOrLater(mesh, drawAt, quat, material, portrait);
                 *              }
                 *              else
                 *              {
                 *                  if (!pawn.Downed && !pawn.Dead && drawer.implantDrawProps.useHeadOffset)
                 *                  {
                 *                      drawAt = vector + pawn.Drawer.renderer.BaseHeadOffsetAt(headfacing);
                 *                  }
                 *                  else
                 *                  {
                 *                      if (pawn.Downed || pawn.Dead && drawer.implantDrawProps.useHeadOffset)
                 *                      {
                 *                          drawAt.y = vector.y + pawn.Drawer.renderer.BaseHeadOffsetAt(headfacing).y;
                 *                      }
                 *                  }
                 *                  drawAt.y += 0.005f;
                 *                  material = drawer.ImplantMaterial(pawn, headfacing);
                 *                  //    GenDraw.DrawMeshNowOrLater(mesh, drawAt, quat, material, portrait);
                 *              }
                 *
                 *              if (material != null)
                 *              {
                 *                  //    GenDraw.DrawMeshNowOrLater(mesh, drawAt , quat, material, portrait);
                 *
                 *                  material = OverrideMaterialIfNeeded(material, pawn);
                 *                  //                                                                                        Angle calculation to not pick the shortest, taken from Quaternion.Angle and modified
                 *                  GenDraw.DrawMeshNowOrLater(mesh: mesh, loc: drawAt + drawer.offsetVector().RotatedBy(angle: Mathf.Acos(f: Quaternion.Dot(a: Quaternion.identity, b: quat)) * 2f * 57.29578f),
                 *                      quat: quat, mat: material, drawNow: portrait);
                 *
                 *                  drawAt.y += HediffComp_DrawImplant_AdMech.MinClippingDistance;
                 *              }
                 *          }
                 *          HediffComp_Shield _Shield;
                 *          if ((_Shield = hediff.comps[i] as HediffComp_Shield) != null)
                 *          {
                 *              _Shield.DrawWornExtras();
                 *          }
                 *      }
                 *  }
                 * }
                 */
            }
        }