예제 #1
0
        public static void DrawFactionColorsButton(Rect rect, CompColorableTwoFaction comp, bool paintable = false)
        {
            Rect rect1 = rect.LeftHalf().LeftHalf();

            Widgets.Label(rect1, "Faction Presets: ");
            Rect rect2 = rect.LeftHalf().RightHalf();

            rect2.width *= 2;
            Rect rect3 = rect.RightHalf().RightHalf();

            Widgets.Dropdown <CompColorableTwoFaction, FactionDef>
            (
                rect2,
                comp,
                (CompColorableTwoFaction sp) => comp.FactionDef,
                new Func <CompColorableTwoFaction, IEnumerable <Widgets.DropdownMenuElement <FactionDef> > >(DrawFactionColorsButton_GenerateMenu),
                comp.FactionDef != null ? ((string)comp.FactionDef.LabelCap ?? comp.FactionDef.fixedName) : "None",
                comp.FactionDef != null ? comp.FactionDef.FactionIcon : null,
                null,
                null,
                delegate()
            {
            },
                paintable
            );
        }
예제 #2
0
        public Color mainColorFor(ShoulderPadEntry entry)
        {
            if (entry != null)
            {
                if (!entry.Options.NullOrEmpty())
                {
                    if (entry.Used.Color.HasValue)
                    {
                        //    Log.Message("mainColorFor "+ entry.shoulderPadType + " activeOption: " + entry.Used.Label + " Color: "+ entry.Used.Color.Value);
                        return(entry.Used.Color.Value);
                    }
                }
                if (entry.UseFactionColors)
                {
                    CompColorableTwoFaction colours = Colours as CompColorableTwoFaction;
                    if (colours != null)
                    {
                        if (colours.Active)
                        {
                            //   Log.Message("mainColorFor " + entry.shoulderPadType + " UseFactionColors");
                            return(colours.Color);
                        }
                    }

                    /*
                     * else
                     * {
                     *  FactionDef def = pawn?.Faction?.def;
                     *  if (entry.FactionColours(out Color color, out Color colorTwo, def))
                     *  {
                     *      if (color != Color.white)
                     *      {
                     *          return color;
                     *      }
                     *  }
                     * }
                     */
                }
                if (entry.overridePrimaryColor.HasValue)
                {
                    //    Log.Message("mainColorFor " + entry.shoulderPadType + " overridePrimaryColor");
                    return(entry.overridePrimaryColor.Value);
                }
                if (entry.UseSecondaryColorAsPrimary)
                {
                    if (entry.overrideSecondaryColor.HasValue)
                    {
                        //    Log.Message("mainColorFor " + entry.shoulderPadType + " overrideSecondaryColor");
                        return(entry.overrideSecondaryColor.Value);
                    }
                    //    Log.Message("mainColorFor " + entry.shoulderPadType + " DrawColorTwo");
                    return(this.parent.DrawColorTwo);
                }
            }
            //    Log.Message("mainColorFor " + entry.shoulderPadType + " DrawColor");
            return(this.parent.DrawColor);
        }
예제 #3
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();
        }
예제 #4
0
        public static void SetColors(this Thing t, Color newColorOne, Color?newColorTwo = null, bool setFaction = false, FactionDef factionDef = null, Graphic graphic = null, bool reportFailure = true)
        {
            ThingWithComps twc = t as ThingWithComps;

            if (twc == null)
            {
                if (reportFailure)
                {
                    Log.Error("SetColor on non-ThingWithComps " + t);
                }
                return;
            }
            t.SetColorOne(newColorOne);
            if (newColorTwo.HasValue)
            {
                t.SetColorTwo(newColorTwo.Value);
            }
            if (setFaction)
            {
                CompColorableTwoFaction comp = twc.TryGetCompFast <CompColorableTwoFaction>();
                if (comp != null && factionDef != null)
                {
                    comp.FactionDef = factionDef;
                    if (graphic != null)
                    {
                        FieldInfo subgraphic = typeof(Thing).GetField("graphicInt", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                        Traverse  traverse   = Traverse.Create(t);
                        subgraphic.SetValue(t, graphic);
                    }
                }
            }
            if (t is Apparel apparel && apparel.Wearer != null && !apparel.def.apparel.wornGraphicPath.NullOrEmpty())
            {
                apparel.Wearer.Drawer.renderer.graphics.ResolveApparelGraphics();
            }
        }
예제 #5
0
        // Token: 0x060046EB RID: 18155 RVA: 0x0017FE99 File Offset: 0x0017E099
        private static IEnumerable <Widgets.DropdownMenuElement <FactionDef> > DrawFactionColorsButton_GenerateMenu(CompColorableTwoFaction e)
        {
            if (e.FactionDef != null)
            {
                yield return(new Widgets.DropdownMenuElement <FactionDef>
                {
                    option = new FloatMenuOption("None", delegate()
                    {
                        /*
                         * Graphic graphic = e.parent.DefaultGraphic;
                         * Color color = graphic.Color;
                         * Color colorTwo = graphic.ColorTwo;
                         *
                         * graphic = graphic.GetColoredVersion(graphic.Shader, color, colorTwo);
                         * e.parent.SetColors(color, colorTwo, true, null, graphic);
                         */
                        /*
                         * e.drawer.apparel.SetColorOne(color);
                         * e.drawer.apparel.SetColorTwo(colorTwo);
                         * FieldInfo subgraphic = typeof(Thing).GetField("graphicInt", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                         * Traverse traverse = Traverse.Create(e.drawer.apparel);
                         * subgraphic.SetValue(e.drawer.apparel, graphic);
                         */
                        e.FactionDef = null;
                        Graphic graphic = e.parent.DefaultGraphic;
                        Color color = e.Color;
                        Color colorTwo = e.ColorTwo;

                        graphic = graphic.GetColoredVersion(graphic.Shader, color, colorTwo);

                        e.parent.SetColors(color, colorTwo, true, e.FactionDef, graphic);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null),
                    payload = null
                });
            }
            string key = e.Props.Key;

            using (List <FactionDef> .Enumerator enumerator = e.ColouredDefs.OrderBy(x => x.label).ToList().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    FactionDef          variant = enumerator.Current;
                    FactionDefExtension ext     = enumerator.Current.GetModExtensionFast <FactionDefExtension>();

                    if (e.FactionDef != variant && variant.defName.Contains(key))
                    {
                        if (ext == null)
                        {
                            continue;
                        }
                        if (ext.factionColor == null && ext.factionColorTwo == null && ext.factionMaskTag.NullOrEmpty() && ext.factionTextureTag.NullOrEmpty())
                        {
                            continue;
                        }
                        yield return(new Widgets.DropdownMenuElement <FactionDef>
                        {
                            option = new FloatMenuOption((string)variant.LabelCap ?? variant.fixedName, delegate()
                            {
                                /*
                                 * Graphic graphic = e.parent.Graphic;
                                 * //    graphic.path += "_" + variant.TexPath;
                                 * Color color = graphic.Color;
                                 * Color colorTwo = graphic.ColorTwo;
                                 * if (ext.factionColor != null)
                                 * {
                                 *  color = ext.factionColor.Value;
                                 * }
                                 * if (ext.factionColorTwo != null)
                                 * {
                                 *  colorTwo = ext.factionColorTwo.Value;
                                 * }
                                 * graphic = graphic.GetColoredVersion(graphic.Shader, color, colorTwo);
                                 *
                                 * e.parent.SetColors(color, colorTwo, true, variant, graphic);
                                 * Texture texture;
                                 * if (!ext.factionMaskTag.NullOrEmpty())
                                 * {
                                 *  string msk = "m_" + ext.factionMaskTag;
                                 *  texture = ContentFinder<Texture2D>.Get(graphic.path + msk, false);
                                 *  if (texture != null)
                                 *  {
                                 *      graphic.MatEast.SetTexture(ShaderPropertyIDs.MaskTex, texture);
                                 *  }
                                 *  graphic.MatEast.SetColor(ShaderPropertyIDs.ColorTwo, colorTwo);
                                 * }
                                 */

                                /*
                                 * e.drawer.apparel.SetColorOne(color);
                                 * e.drawer.apparel.SetColorTwo(colorTwo);
                                 *
                                 * FieldInfo subgraphic = typeof(Thing).GetField("graphicInt", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                                 * Traverse traverse = Traverse.Create(e.drawer.apparel);
                                 * subgraphic.SetValue(e.drawer.apparel, graphic);
                                 */
                                //    Log.Message("set active");

                                e.FactionDef = variant;
                                Graphic graphic = e.parent.DefaultGraphic;
                                Color color = e.Color;
                                Color colorTwo = e.ColorTwo;

                                graphic = graphic.GetColoredVersion(graphic.Shader, color, colorTwo);

                                e.parent.SetColors(color, colorTwo, true, e.FactionDef, graphic);
                            }, MenuOptionPriority.Default, null, null, 0f, null, null),
                            payload = variant
                        });
                    }
                }
            }
            yield break;
        }
예제 #6
0
        private static IEnumerable <Widgets.DropdownMenuElement <FactionDef> > DrawFactionColorsButton_GenerateMenu(CompColorableTwoFaction e)
        {
            if (e.FactionDef != null)
            {
                yield return(new Widgets.DropdownMenuElement <FactionDef>
                {
                    option = new FloatMenuOption("None", delegate()
                    {
                        /*
                         * Graphic graphic = e.parent.DefaultGraphic;
                         * Color color = graphic.Color;
                         * Color colorTwo = graphic.ColorTwo;
                         *
                         * graphic = graphic.GetColoredVersion(graphic.Shader, color, colorTwo);
                         * e.parent.SetColors(color, colorTwo, true, null, graphic);
                         */
                        /*
                         * e.drawer.apparel.SetColorOne(color);
                         * e.drawer.apparel.SetColorTwo(colorTwo);
                         * FieldInfo subgraphic = typeof(Thing).GetField("graphicInt", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                         * Traverse traverse = Traverse.Create(e.drawer.apparel);
                         * subgraphic.SetValue(e.drawer.apparel, graphic);
                         */
                        e.FactionDef = null;
                        Graphic graphic = e.parent.DefaultGraphic;
                        Color color = e.Color;
                        Color colorTwo = e.ColorTwo;

                        graphic = graphic.GetColoredVersion(graphic.Shader, color, colorTwo);

                        e.parent.SetColors(color, colorTwo, true, e.FactionDef, graphic);
                        if (e.parent is Apparel apparel)
                        {
                            if (apparel.Wearer != null)
                            {
                                UpdateApparelGraphicsFor(apparel.Wearer);
                            }
                        }
                    }, MenuOptionPriority.Default, null, null, 0f, null, null),
                    payload = null
                });