//ctor to populate lists.
        public MainTabWindow_Numbers()
        {
            MethodInfo statsToDraw = typeof(StatsReportUtility).GetMethod("StatsToDraw",
                                                                          BindingFlags.NonPublic | BindingFlags.Static |
                                                                          BindingFlags.InvokeMethod, null,
                                                                          new [] { typeof(Thing) }, null);

            Pawn tmpPawn = PawnGenerator.GeneratePawn(PawnKindDefOf.AncientSoldier, Faction.OfPlayerSilentFail);

            if (statsToDraw != null)
            {
                pawnHumanlikeStatDef =
                    ((IEnumerable <StatDrawEntry>)statsToDraw.Invoke(null, new[] { tmpPawn }))
                    .Concat(tmpPawn.def.SpecialDisplayStats(StatRequest.For(tmpPawn)))
                    .Where(s => s.ShouldDisplay && s.stat != null)
                    .Select(s => s.stat).OrderBy(stat => stat.LabelCap).ToList();

                tmpPawn = PawnGenerator.GeneratePawn(PawnKindDefOf.Thrumbo);

                pawnAnimalStatDef =
                    ((IEnumerable <StatDrawEntry>)statsToDraw.Invoke(null, new[] { tmpPawn }))
                    .Where(s => s.ShouldDisplay && s.stat != null)
                    .Select(s => s.stat).OrderBy(stat => stat.LabelCap).ToList();

                Corpse corpse = (Corpse)ThingMaker.MakeThing(tmpPawn.RaceProps.corpseDef);
                corpse.InnerPawn = tmpPawn;

                corpseStatDef = ((IEnumerable <StatDrawEntry>)statsToDraw.Invoke(null, new[] { corpse }))
                                .Concat(tmpPawn.def.SpecialDisplayStats(StatRequest.For(tmpPawn)))
                                .Where(s => s.ShouldDisplay && s.stat != null)
                                .Select(s => s.stat).OrderBy(stat => stat.LabelCap).ToList();
            }

            pawnHumanlikeNeedDef = DefDatabase <NeedDef> .AllDefsListForReading;
            pawnAnimalNeedDef    = tmpPawn.needs.AllNeeds.Where(x => x.def.showOnNeedList).Select(x => x.def).ToList();

            PawnTableDef defaultTable = WorldComponent_Numbers.PrimaryFilter.First().Key;

            if (Find.World.GetComponent <WorldComponent_Numbers>().sessionTable.TryGetValue(defaultTable, out List <PawnColumnDef> list))
            {
                pawnTableDef.columns = list;
            }

            settings = LoadedModManager.GetMod <Numbers>().GetSettings <Numbers_Settings>();
            UpdateFilter();
        }
Пример #2
0
        public Numbers(ModContentPack content) : base(content)
        {
            Harmony harmony = new Harmony("tallidown.rimworld.numbers");

            //Harmony.DEBUG = true;

            harmony.Patch(AccessTools.Method(typeof(DefGenerator), nameof(DefGenerator.GenerateImpliedDefs_PreResolve)),
                          postfix: new HarmonyMethod(typeof(Numbers), nameof(Columndefs)));

            harmony.Patch(AccessTools.Method(typeof(PawnColumnWorker), "HeaderClicked"),
                          prefix: new HarmonyMethod(typeof(Numbers), nameof(RightClickToRemoveHeader)));

            harmony.Patch(AccessTools.Method(typeof(PawnTable), nameof(PawnTable.PawnTableOnGUI)),
                          transpiler: new HarmonyMethod(typeof(Numbers), nameof(MakeHeadersReOrderable)));

            // HERE!!
            harmony.Patch(AccessTools.Method(typeof(PawnColumnWorker), nameof(PawnColumnWorker.DoHeader)),
                          transpiler: new HarmonyMethod(typeof(Numbers), nameof(UseWordWrapOnHeaders)));

            harmony.Patch(AccessTools.Method(typeof(PawnColumnWorker_Text), nameof(PawnColumnWorker_Text.DoCell)),
                          transpiler: new HarmonyMethod(typeof(Numbers), nameof(CentreCell)));

            harmony.Patch(AccessTools.Method(typeof(ReorderableWidget), nameof(ReorderableWidget.Reorderable)),
                          transpiler: new HarmonyMethod(typeof(Numbers), nameof(ReorderWidgetFromEventToInputTranspiler)));

            //we meet again, Fluffy.
            Type pawnColumWorkerType = GenTypes.GetTypeInAnyAssembly("WorkTab.PawnColumnWorker_WorkType");

            if (pawnColumWorkerType != null && typeof(PawnColumnWorker).IsAssignableFrom(pawnColumWorkerType))
            {
                harmony.Patch(AccessTools.Method(pawnColumWorkerType, "HeaderInteractions"),
                              prefix: new HarmonyMethod(typeof(Numbers), nameof(RightClickToRemoveHeader)));
            }

            //we meet Uuugggg again too. Credit where it's due:
            //  https://github.com/alextd/RimWorld-EnhancementPack/blob/master/Source/PawnTableHighlightSelected.cs
            harmony.Patch(AccessTools.Method(typeof(PawnColumnWorker_Label), nameof(PawnColumnWorker_Label.DoCell)),
                          postfix: new HarmonyMethod(typeof(Numbers), nameof(AddHighlightToLabel_PostFix)),
                          transpiler: new HarmonyMethod(typeof(Numbers), nameof(AddHighlightToLabel_Transpiler)));

            settings = GetSettings <Numbers_Settings>();
        }