예제 #1
0
        // RimWorld.CharacterCardUtility
        public void DrawCard(Rect rect, ThingWithComps selectedThing, CompColorableTwoFaction Colorable)
        {
            GUI.BeginGroup(rect);

            if (Colorable != null && Colorable.Props != null)
            {
                var ts    = Text.CalcSize(selectedThing.def.LabelCap).x;
                var y     = rect.y;
                var rect2 = new Rect(rect.width / 2 - ts + SpacingOffset, y, rect.width, HeaderSize);
                //    y += rect2.height;
                Text.Font = GameFont.Small;
                Widgets.ListSeparator(ref y, rect2.width, "Colours: ");
                if (!Colorable.Props.Key.NullOrEmpty())
                {
                    List <FactionDef> factions = new List <FactionDef>();
                    for (int i = 0; i < DefDatabase <FactionDef> .AllDefsListForReading.Count; i++)
                    {
                        FactionDef          f         = DefDatabase <FactionDef> .AllDefsListForReading[i];
                        FactionDefExtension extension = f.GetModExtensionFast <FactionDefExtension>();
                        if (f.defName.Contains(Colorable.Props.Key) && extension != null)
                        {
                            if (extension.factionColor.HasValue)
                            {
                                factions.Add(f);
                            }
                        }
                    }
                    if (!factions.NullOrEmpty())
                    {
                        var rect3 = new Rect(0f, y, rect.width, 20f);
                        DrawFactionColorsButton(rect3, Colorable, false);
                        y += rect2.height;
                    }
                    if (!factions.NullOrEmpty())
                    {
                        var rect3  = new Rect(0f, y, rect.width, 20f);
                        var rect3R = rect3.RightHalf();
                        var rect3L = rect3.LeftHalf();

                        y += rect2.height;
                    }
                }
            }
            GUI.EndGroup();
        }
예제 #2
0
        public void UpdateGraphic()
        {
            if (Drawer?.pawn == null)
            {
                Graphic = null;
                return;
            }
            if (apparel.Wearer == null)
            {
                if (Drawer != null)
                {
                    Drawer.pawn = null;
                }
                Graphic = null;
                return;
            }
            if (Drawer.pawn != apparel.Wearer)
            {
                //    Log.Message("Old Wearer: "+ Drawer.pawn + "new Wearer: "+ apparel.Wearer);
                Drawer.pawn = apparel.Wearer;
            }
            Pawn   pawn   = Drawer.pawn;
            Shader shader = this.Shader;
            string path   = padTexPath;

            if (UseFactionTextures || UseVariableTextures)
            {
                bool notPlayer = pawn.Faction != null && (pawn.Faction != Faction.OfPlayer);
                if (notPlayer)
                {
                    FactionDefExtension ext = pawn.Faction.def.HasModExtension <FactionDefExtension>() ? pawn.Faction.def.GetModExtensionFast <FactionDefExtension>() : null;
                    bool factionTextures    = UseFactionTextures && ext?.factionTextureTag != null;
                    if (factionTextures)
                    {
                        //    Log.Message("using factionTextureTag " + ext.factionTextureTag);
                        for (int i = 0; i < Options.Count; i++)
                        {
                            if (Options[i].TexPath == ext.factionTextureTag)
                            {
                                Used = Options[i];
                                //    Log.Message("Found faction VariantTexture " + VariantTextures.Options[i].texPath);
                                break;
                            }
                        }
                    }
                    else
                    {
                        bool foundVar = false;
                        if (!Options.NullOrEmpty())
                        {
                            for (int i = 0; i < Options.Count; i++)
                            {
                                if (pawn.kindDef.apparelTags.Contains(Options[i].TexPath))
                                {
                                    Used     = Options[i];
                                    foundVar = true;
                                    //    Log.Message("Found KindDef VariantTexture " + VariantTextures.Options[i].texPath);
                                    break;
                                }
                            }
                            if (!foundVar)
                            {
                                Used = Options.RandomElement();
                            }
                        }
                    }
                }
                else
                {
                    if (UseFactionTextures)
                    {
                        //    Log.Message("UseFactionTextures");
                        //    CompColorableTwoFaction FC = Drawer.Colours as CompColorableTwoFaction;
                        if (Drawer.Colours is CompColorableTwoFaction FC)
                        {
                            //    Log.Message("FC != null");
                            if (FC.FactionDef != null)
                            {
                                //        Log.Message("FactionDef = " + FC.FactionDef.LabelCap);
                                FactionDefExtension e = FC.Extension;
                                if (e != null)
                                {
                                    //   Log.Message("FactionDefExtension != null");
                                    if (!Options.NullOrEmpty())
                                    {
                                        //    Log.Message("Options: " + Options.Count);
                                        for (int i = 0; i < Options.Count; i++)
                                        {
                                            //    Log.Message("checking " + e.factionTextureTag + " Vs " + Options[i].TexPath + " = " + (Options[i].TexPath == e.factionTextureTag));
                                            if (Options[i].TexPath == e.factionTextureTag)
                                            {
                                                Used = Options[i];
                                                //        Log.Message("Found faction VariantTexture " + Options[i].TexPath);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            //    Log.Message("FC == null");
                            List <FactionDef> factions = DefDatabase <FactionDef> .AllDefsListForReading;
                            //    Log.Message("UpdateGraphic() 4 1 B 1 1 B 2 factions: "+ factions.Count);
                            for (int i = 0; i < factions.Count; i++)
                            {
                                //    Log.Message("UpdateGraphic() 4 1 B 1 1 B 2 faction: " + i);
                                FactionDef f = factions[i];

                                //    Log.Message("UpdateGraphic() 4 1 B 1 1 B 2 faction: " + f);
                                FactionDefExtension e = f.HasModExtension <FactionDefExtension>() ? f.GetModExtensionFast <FactionDefExtension>() : null;
                                //    Log.Message("UpdateGraphic() 4 1 B 1 1 B 2 faction: " + (e == null));
                                if (e == null)
                                {
                                    //    Log.Message("e == null");
                                    continue;
                                }
                                if (e.factionTextureTag.NullOrEmpty())
                                {
                                    //    Log.Message("factionTextureTag == null");
                                    continue;
                                }

                                if (!Options.NullOrEmpty())
                                {
                                    //    Log.Message("UpdateGraphic() 4 1 B 1 1 A 1 1 1");
                                    //    Log.Message("Options: " + Options.Count);
                                    for (int ii = 0; ii < Options.Count; ii++)
                                    {
                                        //    Log.Message("checking " + e.factionTextureTag + " Vs " + Options[i].TexPath + " = " + (Options[i].TexPath == e.factionTextureTag));
                                        if (Options[ii].TexPath == e.factionTextureTag)
                                        {
                                            faction = f;
                                            //        Log.Message("Found faction VariantTexture " + Options[i].TexPath);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                path = padTexPath + "/" + Used.TexPath;
            }

            string body    = bodyTypeString(pawn.story.bodyType);
            string testRot = "_";

            if (CheckPauldronRotation(Rot4.South))
            {
                testRot += "south";
            }
            else
            if (CheckPauldronRotation(Rot4.North))
            {
                testRot += "north";
            }
            else
            if (CheckPauldronRotation(Rot4.East))
            {
                testRot += "east";
            }
            else
            if (CheckPauldronRotation(Rot4.West))
            {
                testRot += "west";
            }
            else
            {
                testRot = "";
            }
            string    testpath = path + body + testRot;
            Texture2D tex      = ContentFinder <Texture2D> .Get(testpath, false);

            Graphic graphic;

            if (tex == null)
            {
                this.UpdateProps();
                path = padTexPath;
                if (UseFactionTextures || UseVariableTextures)
                {
                    path = padTexPath + "/" + this.DefaultOption.TexPath;
                }
            }
            path += body;
            Color color    = Drawer.mainColorFor(this);
            Color colorTwo = Drawer.secondaryColorFor(this);

            graphic = GraphicDatabase.Get <Graphic_Multi>(path, shader, size, color, colorTwo);
            if (Drawer.Colours is CompColorableTwoFaction factionColors)
            {
                Texture texture;
                if (factionColors.ActiveFaction)
                {
                    if (!factionColors.Extension.factionMaskTag.NullOrEmpty())
                    {
                        string msk = "m_" + factionColors.Extension.factionMaskTag;
                        texture = ContentFinder <Texture2D> .Get(graphic.path + "_east" + msk, false);

                        if (texture != null)
                        {
                            graphic.MatEast.SetTexture(ShaderPropertyIDs.MaskTex, texture);
                        }
                        graphic.MatEast.SetColor(ShaderPropertyIDs.ColorTwo, colorTwo);

                        texture = ContentFinder <Texture2D> .Get(graphic.path + "_west" + msk, false);

                        if (texture != null)
                        {
                            graphic.MatWest.SetTexture(ShaderPropertyIDs.MaskTex, texture);
                        }
                        graphic.MatWest.SetColor(ShaderPropertyIDs.ColorTwo, colorTwo);

                        texture = ContentFinder <Texture2D> .Get(graphic.path + "_south" + msk, false);

                        if (texture != null)
                        {
                            graphic.MatSouth.SetTexture(ShaderPropertyIDs.MaskTex, texture);
                        }
                        graphic.MatSouth.SetColor(ShaderPropertyIDs.ColorTwo, colorTwo);

                        texture = ContentFinder <Texture2D> .Get(graphic.path + "_north" + msk, false);

                        if (texture != null)
                        {
                            graphic.MatNorth.SetTexture(ShaderPropertyIDs.MaskTex, texture);
                        }
                        graphic.MatNorth.SetColor(ShaderPropertyIDs.ColorTwo, colorTwo);
                    }
                }
            }
            //    Log.Message(this.Label + " " + graphic.path + " Shader: " + graphic.Shader.name + "Colour: " + graphic.Color + " Colour: " + graphic.ColorTwo);

            /*
             * if (!this.Drawer.apparel.def.apparel.wornGraphicPath.NullOrEmpty())
             * {
             *  SetApparelColours();
             * }
             */
            Graphic = graphic;
        }