diff --git a/Assemblies/Outfitter.dll b/Assemblies/Outfitter.dll index 374108c..a9968fc 100644 Binary files a/Assemblies/Outfitter.dll and b/Assemblies/Outfitter.dll differ diff --git a/Source/Outfitter/HarmonyPatches.cs b/Source/Outfitter/HarmonyPatches.cs index 7ce8186..4549670 100644 --- a/Source/Outfitter/HarmonyPatches.cs +++ b/Source/Outfitter/HarmonyPatches.cs @@ -11,6 +11,7 @@ using Harmony; using Outfitter; +using Outfitter.TabPatch; using RimWorld; @@ -46,14 +47,10 @@ static HarmonyPatches() new HarmonyMethod(typeof(HarmonyPatches), nameof(UpdatePriorities))); harmony.Patch( - AccessTools.Method(typeof(ITab_Bills), "FillTab"), - new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.FillTab_Prefix)), + AccessTools.Method(typeof(BillStack), nameof(BillStack.DoListing)), + new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.DoListing)), null); - harmony.Patch( - AccessTools.Method(typeof(ITab_Bills), "TabUpdate"), - new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.TabUpdate_Prefix)), - null); // harmony.Patch( // AccessTools.Method(typeof(ThinkNode_JobGiver), nameof(ThinkNode_JobGiver.TryIssueJobPackage)), diff --git a/Source/Outfitter/ITab_Bills_Patch.cs b/Source/Outfitter/ITab_Bills_Patch.cs deleted file mode 100644 index 1e10932..0000000 --- a/Source/Outfitter/ITab_Bills_Patch.cs +++ /dev/null @@ -1,106 +0,0 @@ -namespace Outfitter -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - - using RimWorld; - - using UnityEngine; - - using Verse; - - public static class ITab_Bills_Patch - { - private static float viewHeight = 1000f; - - private static Vector2 scrollPosition = default(Vector2); - - private static readonly Vector2 WinSize = new Vector2(420f, 480f); - - private static Bill mouseoverBill; - - // RimWorld.ITab_Bills - - public static bool FillTab_Prefix() - { - Building_WorkTable selTable = (Building_WorkTable)Find.Selector.SingleSelectedThing; - - PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.BillsTab, KnowledgeAmount.FrameDisplayed); - float x = WinSize.x; - Vector2 winSize2 = WinSize; - Rect rect2 = new Rect(0f, 0f, x, winSize2.y).ContractedBy(10f); - Func> recipeOptionsMaker = delegate - { - List list = new List(); - for (int i = 0; i < selTable.def.AllRecipes.Count; i++) - { - if (selTable.def.AllRecipes[i].AvailableNow) - { - RecipeDef recipe = selTable.def.AllRecipes[i]; - list.Add( - new FloatMenuOption( - recipe.LabelCap, - delegate - { - if (!selTable.Map.mapPawns.FreeColonists.Any( - col => recipe.PawnSatisfiesSkillRequirements(col))) - { - Bill.CreateNoPawnsWithSkillDialog(recipe); - } - - Bill bill = recipe.MakeNewBill(); - selTable.billStack.AddBill(bill); - if (recipe.conceptLearned != null) - { - PlayerKnowledgeDatabase.KnowledgeDemonstrated( - recipe.conceptLearned, - KnowledgeAmount.Total); - } - - if (TutorSystem.TutorialMode) - { - TutorSystem.Notify_Event("AddBill-" + recipe.LabelCap); - } - }, - MenuOptionPriority.Default, - null, - null, - 29f, - rect => Widgets.InfoCardButton( - (float)(rect.x + 5.0), - (float)(rect.y + (rect.height - 24.0) / 2.0), - recipe))); - } - } - - if (!list.Any()) - { - list.Add( - new FloatMenuOption( - "NoneBrackets".Translate(), - null)); - } - - return list; - }; - - mouseoverBill = selTable.billStack.DoListing(rect2, recipeOptionsMaker, ref scrollPosition, ref viewHeight); - - - return false; - - } - - public static bool TabUpdate_Prefix() - { - if (mouseoverBill != null) - { - mouseoverBill.TryDrawIngredientSearchRadiusOnMap(Find.Selector.SingleSelectedThing.Position); - mouseoverBill = null; - } - return false; - } - } -} \ No newline at end of file diff --git a/Source/Outfitter/Outfitter.csproj b/Source/Outfitter/Outfitter.csproj index 04c57ce..62f7391 100644 --- a/Source/Outfitter/Outfitter.csproj +++ b/Source/Outfitter/Outfitter.csproj @@ -70,7 +70,10 @@ - + + + + diff --git a/Source/Outfitter/TabPatch/FloatMenuColonists.cs b/Source/Outfitter/TabPatch/FloatMenuColonists.cs new file mode 100644 index 0000000..6a5ba1d --- /dev/null +++ b/Source/Outfitter/TabPatch/FloatMenuColonists.cs @@ -0,0 +1,43 @@ +namespace Outfitter.TabPatch +{ + using System.Collections.Generic; + + using Harmony; + + using JetBrains.Annotations; + + using UnityEngine; + + using Verse; + + public class FloatMenuColonists : FloatMenu + { + public FloatMenuColonists([NotNull] List options, [CanBeNull] string label) + : base(options, label) + { + this.givesColonistOrders = true; + this.vanishIfMouseDistant = true; + this.closeOnClickedOutside = true; + } + + public override void DoWindowContents(Rect rect) + { + this.options.Do( + o => + { + // FloatMenuOptionSorting option = o as FloatMenuOptionSorting; + // option.Label = PathInfo.GetJobReport(option.sortBy); + o.SetSizeMode(FloatMenuSizeMode.Normal); + }); + this.windowRect = new Rect(this.windowRect.x, this.windowRect.y, this.InitialSize.x, this.InitialSize.y); + base.DoWindowContents(this.windowRect); + } + + public override void PostClose() + { + base.PostClose(); + + Tools.CloseLabelMenu(false); + } + } +} \ No newline at end of file diff --git a/Source/Outfitter/TabPatch/FloatMenuLabels.cs b/Source/Outfitter/TabPatch/FloatMenuLabels.cs new file mode 100644 index 0000000..42d9fa7 --- /dev/null +++ b/Source/Outfitter/TabPatch/FloatMenuLabels.cs @@ -0,0 +1,34 @@ +namespace Outfitter.TabPatch +{ + using System; + using System.Collections.Generic; + + using UnityEngine; + + using Verse; + + public class FloatMenuLabels : FloatMenu + { + public FloatMenuLabels(List options) + : base(options, null) + { + this.givesColonistOrders = false; + this.vanishIfMouseDistant = true; + this.closeOnClickedOutside = false; + } + } + + public class FloatMenuOptionNoClose : FloatMenuOption + { + public FloatMenuOptionNoClose(string label, Action action) + : base(label, action) + { + } + + public override bool DoGUI(Rect rect, bool colonistOrdering) + { + base.DoGUI(rect, colonistOrdering); + return false; // don't close after an item is selected + } + } +} \ No newline at end of file diff --git a/Source/Outfitter/TabPatch/ITab_Bills_Patch.cs b/Source/Outfitter/TabPatch/ITab_Bills_Patch.cs new file mode 100644 index 0000000..3deee5d --- /dev/null +++ b/Source/Outfitter/TabPatch/ITab_Bills_Patch.cs @@ -0,0 +1,67 @@ +namespace Outfitter.TabPatch +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + + using RimWorld; + + using UnityEngine; + + using Verse; + + public static class ITab_Bills_Patch + { + private static float viewHeight = 1000f; + + private static Vector2 scrollPosition = default(Vector2); + + private static readonly Vector2 WinSize = new Vector2(420f, 480f); + + private static Bill mouseoverBill; + + // RimWorld.ITab_Bills + + public static bool DoListing(BillStack __instance, ref Bill __result, Rect rect, Func> recipeOptionsMaker, ref Vector2 scrollPosition, ref float viewHeight) + { + Bill result = null; + GUI.BeginGroup(rect); + Text.Font = GameFont.Small; + if (__instance.Count < 15) + { + Rect rect2 = new Rect(0f, 0f, 150f, 29f); + if (Widgets.ButtonText(rect2, "AddBill".Translate(), true, false, true)) + { + Find.WindowStack.Add(new FloatMenu(recipeOptionsMaker())); + } + UIHighlighter.HighlightOpportunity(rect2, "AddBill"); + } + Text.Anchor = TextAnchor.UpperLeft; + GUI.color = Color.white; + Rect outRect = new Rect(0f, 35f, rect.width, (float)(rect.height - 35.0)); + Rect viewRect = new Rect(0f, 0f, (float)(outRect.width - 16.0), viewHeight); + Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect, true); + float num = 0f; + for (int i = 0; i < __instance.Count; i++) + { + Bill bill = __instance.Bills[i]; + + Rect rect3 = bill.DoInterface(0f, num, viewRect.width, i); + if (!bill.DeletedOrDereferenced && Mouse.IsOver(rect3)) + { + result = bill; + } + num = (float)(num + (rect3.height + 6.0)); + } + if (Event.current.type == EventType.Layout) + { + viewHeight = (float)(num + 60.0); + } + Widgets.EndScrollView(); + GUI.EndGroup(); + __result= result; + return false; + } + } +} \ No newline at end of file diff --git a/Source/Outfitter/TabPatch/Tools.cs b/Source/Outfitter/TabPatch/Tools.cs new file mode 100644 index 0000000..e4c4ed1 --- /dev/null +++ b/Source/Outfitter/TabPatch/Tools.cs @@ -0,0 +1,81 @@ +namespace Outfitter.TabPatch +{ + using System; + using System.Collections.Generic; + using System.Linq; + + using Harmony; + + using JetBrains.Annotations; + + using Verse; + + public static class Tools + { + public static FloatMenuLabels LabelMenu; + + private static FloatMenuColonists actionMenu; + + public static void CloseLabelMenu(bool sound) + { + if (LabelMenu != null) + { + Find.WindowStack.TryRemove(LabelMenu, sound); + LabelMenu = null; + } + } + + public static FloatMenuOption MakeMenuItemForLabel([NotNull] string label, [NotNull] List fmo) + { + // List sortByWhats = fmo.Keys.ToList(); + List options = fmo.ToList(); + string labelFixed = label; + FloatMenuOptionNoClose option = new FloatMenuOptionNoClose( + labelFixed, + () => + { + if (options.Count() == 1 && options[0].Disabled == false) + { + Action action = options[0].action; + if (action != null) + { + CloseLabelMenu(true); + action(); + } + } + else + { + int i = 0; + List actions = new List(); + fmo.Do( + menuOption => + { + FloatMenuOption floatMenuOption = + new FloatMenuOption( + menuOption.Label, + () => + { + FloatMenuOption pawnOption = + menuOption; + actionMenu.Close(); + CloseLabelMenu(true); + pawnOption.action(); + }, + (MenuOptionPriority)i++, + () => + { + // PathInfo.current = pawn; + }); + actions.Add(floatMenuOption); + }); + actionMenu = new FloatMenuColonists(actions, null); + Find.WindowStack.Add(actionMenu); + } + }) + { + Disabled = options.All(o => o.Disabled) + }; + return option; + } + } +} \ No newline at end of file