From d498bdbb01c58d14349ce04a542db7669db2437c Mon Sep 17 00:00:00 2001 From: angelolocritani <67960642+angelolocritani@users.noreply.github.com> Date: Mon, 16 Aug 2021 19:38:01 +0200 Subject: [PATCH 01/17] Update FavouriteManager.cs Fluffy.WorkTab.NoStoredFavourites was not translated --- Source/Favourites/FavouriteManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Favourites/FavouriteManager.cs b/Source/Favourites/FavouriteManager.cs index ae256d9..f3890e9 100644 --- a/Source/Favourites/FavouriteManager.cs +++ b/Source/Favourites/FavouriteManager.cs @@ -179,7 +179,7 @@ private static void LoadFavouriteFloatMenu(Pawn pawn) .ToList(); if (options.Count == 0) { - options.Add(new FloatMenuOption("Fluffy.WorkTab.NoStoredFavourites", null)); + options.Add(new FloatMenuOption("Fluffy.WorkTab.NoStoredFavourites".Translate(), null)); } Find.WindowStack.Add(new FloatMenu(options)); } @@ -191,4 +191,4 @@ public override void ExposeData() Scribe_Collections.Look(ref _favourites, "FavouriteAssignments", LookMode.Reference, LookMode.Reference); } } -} \ No newline at end of file +} From 289579385fee91ffb446b5c7083c0d36e67d7c95 Mon Sep 17 00:00:00 2001 From: angelolocritani <67960642+angelolocritani@users.noreply.github.com> Date: Tue, 17 Aug 2021 11:13:12 +0200 Subject: [PATCH 02/17] Default priority (+ tip) setting now transletable Update Keyed-English.xml --- Languages/English/Keyed/Keyed-English.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Languages/English/Keyed/Keyed-English.xml b/Languages/English/Keyed/Keyed-English.xml index 1d18a97..0def170 100644 --- a/Languages/English/Keyed/Keyed-English.xml +++ b/Languages/English/Keyed/Keyed-English.xml @@ -21,6 +21,8 @@ Should times be shown in 12h (e.g. noon, 9p.m.) or 24h (e.g. 12:00, 21:00) mode? Levels of priority How many levels of priority should we use? (Limited to between 4 and 9) + Default priority + Which level of priority is assigned by default? Sounds Play sounds when a priority is changed? Crunchy sounds @@ -77,4 +79,4 @@ Very low priority Lowest priority - \ No newline at end of file + From 777f1abd8c9eca57f8f68e7ed63846f493ed05e2 Mon Sep 17 00:00:00 2001 From: Sineme Date: Wed, 28 Dec 2022 16:15:16 +0100 Subject: [PATCH 03/17] Fix horizontal scroll area fixes #157, #159 and #164 The scroll area was using cachedSize for its output rectangle capping it at the screen width. As the "Work"-tab window is not as wide as the screen, ouput rectangle was too wide when there were many work types. To fix this the PawnTable was extended with the property methods void set_OutRect(this PawnTable, Rect) and Rect get_OutRect() 'fake adding' a new property that can be used to set and get the "Work"-tab window dimension instead of relying on the screen size. MainTabWindow_WorkTab.DoWindowContents calls set_OutRect with the window dimension PawnTable_PawnTableOnGUI.PawnTableOnGUI calls get_OutRect to clamp the output rectangle properly I think ideally PawnTable.PawnTableOnGUI's parameter would be Rect window instead of Vector2 position in the future. --- Source/Extensions/PawnTable_Extensions.cs | 35 +++++++++++++++++++ .../PawnTable/PawnTable_PawnTableOnGUI.cs | 7 +++- Source/PawnTable/MainTabWindow_WorkTab.cs | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Source/Extensions/PawnTable_Extensions.cs diff --git a/Source/Extensions/PawnTable_Extensions.cs b/Source/Extensions/PawnTable_Extensions.cs new file mode 100644 index 0000000..5d94289 --- /dev/null +++ b/Source/Extensions/PawnTable_Extensions.cs @@ -0,0 +1,35 @@ +using RimWorld; +using RimWorld.BaseGen; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace WorkTab.Extensions { + internal static class PawnTable_Extensions { + private static ConditionalWeakTable> outRectDictionary=new ConditionalWeakTable>(); + /// + /// Sets the rectangle the is drawn in. + /// + /// The being extended. + /// The rectangle the will be drawn in. + internal static void set_OutRect(this PawnTable pawnTable, Rect outRect) { + var value = outRectDictionary.GetValue( + pawnTable, + a => new StrongBox(outRect) + ); + value.Value = outRect; + } + /// + /// Gets the rectangle the will be drawn in. + /// + /// The being extended. + /// The rectangle the will be drawn in. + internal static Rect get_OutRect(this PawnTable pawnTable) { + return outRectDictionary.GetOrCreateValue(pawnTable).Value; + } + } +} diff --git a/Source/HarmonyPatches/PawnTable/PawnTable_PawnTableOnGUI.cs b/Source/HarmonyPatches/PawnTable/PawnTable_PawnTableOnGUI.cs index 28462f6..3c0d8bd 100644 --- a/Source/HarmonyPatches/PawnTable/PawnTable_PawnTableOnGUI.cs +++ b/Source/HarmonyPatches/PawnTable/PawnTable_PawnTableOnGUI.cs @@ -8,6 +8,7 @@ using RimWorld; using UnityEngine; using Verse; +using WorkTab.Extensions; namespace WorkTab { [HarmonyPatch(typeof(PawnTable), nameof(PawnTable.PawnTableOnGUI))] @@ -79,7 +80,11 @@ public static bool Prefix(PawnTable __instance, // Instead, we want to limit outRect to the available view area, so a horizontal scrollbar can appear. float labelWidth = cachedColumnWidths[0]; var labelCol = columns[0]; - float outWidth = Mathf.Min( cachedSize.x - labelWidth, UI.screenWidth - (standardWindowMargin * 2f) ); + // ideally this method would be called with a Rect outRect + // indicating the window it is being drawn in instead + // of a Vector2 position + var outRect = __instance.get_OutRect(); + float outWidth = outRect.width - labelWidth; float viewWidth = cachedSize.x - labelWidth - 16f; Rect labelHeaderRect = new Rect( diff --git a/Source/PawnTable/MainTabWindow_WorkTab.cs b/Source/PawnTable/MainTabWindow_WorkTab.cs index 4e1bf05..f4c8009 100644 --- a/Source/PawnTable/MainTabWindow_WorkTab.cs +++ b/Source/PawnTable/MainTabWindow_WorkTab.cs @@ -10,6 +10,7 @@ using RimWorld.Planet; using UnityEngine; using Verse; +using WorkTab.Extensions; using static WorkTab.Constants; using static WorkTab.InteractionUtilities; using static WorkTab.Resources; @@ -122,6 +123,7 @@ public static void SelectWholeDay() { } public override void DoWindowContents(Rect rect) { + Instance.Table.set_OutRect(rect); if (_columnsChanged) { RebuildTable(); } From 35c142624cd5d73311c4525cd92aa913a613eef8 Mon Sep 17 00:00:00 2001 From: maarxx Date: Fri, 10 Feb 2023 16:58:09 -0500 Subject: [PATCH 04/17] Respect "Disable Scrollwheel" on Checkbox WorkTypes --- Source/PawnColumns/PawnColumnWorker_WorkType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/PawnColumns/PawnColumnWorker_WorkType.cs b/Source/PawnColumns/PawnColumnWorker_WorkType.cs index d1d2524..51512f5 100644 --- a/Source/PawnColumns/PawnColumnWorker_WorkType.cs +++ b/Source/PawnColumns/PawnColumnWorker_WorkType.cs @@ -381,7 +381,7 @@ private void HandleInteractionsDetailed(Rect rect, Pawn pawn) { } private void HandleInteractionsToggle(Rect rect, Pawn pawn) { - if ((Event.current.type == EventType.MouseDown || Event.current.type == EventType.ScrollWheel) + if ((Event.current.type == EventType.MouseDown || (Event.current.type == EventType.ScrollWheel && !Settings.disableScrollwheel)) && Mouse.IsOver(rect)) { // track priority so we can play appropriate sounds bool active = pawn.GetPriority( def.workType, VisibleHour ) > 0; From 631992c323ed69b2d6d0d12d7bcbf5c63b740624 Mon Sep 17 00:00:00 2001 From: maarxx Date: Fri, 10 Feb 2023 18:23:36 -0500 Subject: [PATCH 05/17] Replace Job Icon Column with Job Text Column --- Defs/PawnColumnDefs.xml | 8 +++++ Source/Core/Constants.cs | 1 + ...enerator_GenerateImpliedDefs_PreResolve.cs | 6 +++- .../PawnColumns/PawnColumnWorker_JobText.cs | 33 +++++++++++++++++++ Source/Utilities/DefOf.cs | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Source/PawnColumns/PawnColumnWorker_JobText.cs diff --git a/Defs/PawnColumnDefs.xml b/Defs/PawnColumnDefs.xml index 4dd4668..3af3e8f 100644 --- a/Defs/PawnColumnDefs.xml +++ b/Defs/PawnColumnDefs.xml @@ -19,6 +19,14 @@ (16,16) + + JobText + WorkTab.PawnColumnWorker_JobText + true + + Current job + + CopyPasteDetailedWorkPriorities WorkTab.PawnColumnWorker_CopyPasteDetailedWorkPriorities diff --git a/Source/Core/Constants.cs b/Source/Core/Constants.cs index e89c628..4eeef82 100644 --- a/Source/Core/Constants.cs +++ b/Source/Core/Constants.cs @@ -12,6 +12,7 @@ public static class Constants { public const float MinTimeBarLabelSpacing = 50f; public const int TimeBarHeight = 40; public const int VerticalHeaderHeight = 100; + public const int JobTextWidth = 150; public const int WorkGiverBoxSize = 20; public const int WorkGiverWidth = 25; public const int WorkTypeBoxSize = 25; diff --git a/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs b/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs index 89b93a4..4bb4bb7 100644 --- a/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs +++ b/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs @@ -24,7 +24,11 @@ private static void Postfix() { // insert mood and job columns before first work column name int firstWorkindex = workTable.columns.FindIndex(d => d.workerClass == typeof(PawnColumnWorker_WorkPriority)); - workTable.columns.Insert(firstWorkindex, PawnColumnDefOf.Job); + if (true) { + workTable.columns.Insert(firstWorkindex, PawnColumnDefOf.JobText); + } else { + workTable.columns.Insert(firstWorkindex, PawnColumnDefOf.Job); + } workTable.columns.Insert(firstWorkindex + 1, PawnColumnDefOf.Mood); // go over PawnColumnDefs and replace all PawnColumnWorker_WorkPriority diff --git a/Source/PawnColumns/PawnColumnWorker_JobText.cs b/Source/PawnColumns/PawnColumnWorker_JobText.cs new file mode 100644 index 0000000..263df17 --- /dev/null +++ b/Source/PawnColumns/PawnColumnWorker_JobText.cs @@ -0,0 +1,33 @@ +// Copyright Karel Kroeze, 2020-2021. +// WorkTab/WorkTab/PawnColumnWorker_WorkTabLabel.cs + +using RimWorld; +using Verse; +using static WorkTab.Constants; + +namespace WorkTab { + public class PawnColumnWorker_JobText : PawnColumnWorker_Text { + public override int GetMinWidth(PawnTable table) + { + return JobTextWidth; + } + private string GetJobString(Pawn pawn) + { + return pawn.jobs?.curDriver?.GetReport() ?? ""; + } + protected override string GetTextFor(Pawn pawn) { + return GetJobString(pawn); + } + protected override string GetTip(Pawn pawn) { + return GetJobString(pawn); + } + public string GetValueToCompare(Pawn pawn) + { + return GetJobString(pawn); + } + public override int Compare(Pawn a, Pawn b) + { + return GetValueToCompare(a).CompareTo(GetValueToCompare(b)); + } + } +} diff --git a/Source/Utilities/DefOf.cs b/Source/Utilities/DefOf.cs index c643126..7792ab5 100644 --- a/Source/Utilities/DefOf.cs +++ b/Source/Utilities/DefOf.cs @@ -14,6 +14,7 @@ public static class PawnColumnDefOf { [MayRequireIdeology] public static PawnColumnDef Guest; [MayRequireIdeology] public static PawnColumnDef Ideo; public static PawnColumnDef Job; + public static PawnColumnDef JobText; public static PawnColumnDef LabelShortWithIcon; public static PawnColumnDef Mood; public static PawnColumnDef WorkTabLabel; From 28a5a420a163e000a1754f3bec4ac88306391b9d Mon Sep 17 00:00:00 2001 From: maarxx Date: Fri, 10 Feb 2023 18:43:18 -0500 Subject: [PATCH 06/17] Make Mod Setting for Job Text Column (Icon vs Text) --- Source/Core/Settings.cs | 4 ++++ .../DefGenerator_GenerateImpliedDefs_PreResolve.cs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Core/Settings.cs b/Source/Core/Settings.cs index f0cb3cc..938fd33 100644 --- a/Source/Core/Settings.cs +++ b/Source/Core/Settings.cs @@ -8,6 +8,7 @@ namespace WorkTab { public class Settings: ModSettings { public static int defaultPriority = 3; public static bool disableScrollwheel; + public static bool jobTextMode = false; public static int maxPriority = 9; public static bool playCrunch = true; public static bool playSounds = true; @@ -51,6 +52,8 @@ public static void DoWindowContents(Rect rect) { "WorkTab.PlayCrunchTip".Translate()); options.CheckboxLabeled("WorkTab.DisableScrollwheel".Translate(), ref disableScrollwheel, "WorkTab.DisableScrollwheelTip".Translate()); + options.CheckboxLabeled("WorkTab.JobTextMode".Translate(), ref jobTextMode, + "WorkTab.JobTextModeTip".Translate()); bool verticalLabelsBuffer = verticalLabels; options.CheckboxLabeled("WorkTab.VerticalLabels".Translate(), ref verticalLabelsBuffer, "WorkTab.VerticalLabelsTip".Translate()); @@ -86,6 +89,7 @@ public override void ExposeData() { Scribe_Values.Look(ref playSounds, "PlaySounds", true); Scribe_Values.Look(ref playCrunch, "PlayCrunch", true); Scribe_Values.Look(ref disableScrollwheel, "DisableScrollwheel"); + Scribe_Values.Look(ref jobTextMode, "JobTextMode"); Scribe_Values.Look(ref verticalLabels, "VerticalLabels", true); Scribe_Values.Look(ref _fontFix, "FontFix", true); diff --git a/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs b/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs index 4bb4bb7..9333c15 100644 --- a/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs +++ b/Source/HarmonyPatches/DefGenerator_GenerateImpliedDefs_PreResolve.cs @@ -24,7 +24,7 @@ private static void Postfix() { // insert mood and job columns before first work column name int firstWorkindex = workTable.columns.FindIndex(d => d.workerClass == typeof(PawnColumnWorker_WorkPriority)); - if (true) { + if (Settings.jobTextMode) { workTable.columns.Insert(firstWorkindex, PawnColumnDefOf.JobText); } else { workTable.columns.Insert(firstWorkindex, PawnColumnDefOf.Job); From 11d2ce8f4d196479b1facdd482b85a304db1f580 Mon Sep 17 00:00:00 2001 From: maarxx Date: Fri, 10 Feb 2023 18:56:34 -0500 Subject: [PATCH 07/17] Localize Mod Setting for Job Text Column --- Languages/English/Keyed/Keyed-English.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Languages/English/Keyed/Keyed-English.xml b/Languages/English/Keyed/Keyed-English.xml index 1d18a97..6ac6062 100644 --- a/Languages/English/Keyed/Keyed-English.xml +++ b/Languages/English/Keyed/Keyed-English.xml @@ -27,6 +27,8 @@ Play a crunchy sound when a pawn is assigned to a job they are not skilled at? Disable Scrollwheel Disable the scrollwheel functions (when hovering over skills) + Current job column as text (requires restart) + Render the current job column as a text column with the whole job, instead of just an icon.\n\n(Due to a technical limitation, you must restart the game after enabling this option.) Vertical labels Display work labels vertically Fix vertical fonts From 15604d9e882a2fe46c202be5a580331c9bc0f335 Mon Sep 17 00:00:00 2001 From: maarxx Date: Mon, 13 Feb 2023 18:58:05 -0500 Subject: [PATCH 08/17] Add Option to Highlight Current Active Work Cell --- Languages/English/Keyed/Keyed-English.xml | 2 ++ Source/Core/Settings.cs | 4 ++++ .../PawnColumns/PawnColumnWorker_WorkGiver.cs | 10 ++++++++++ .../PawnColumns/PawnColumnWorker_WorkType.cs | 10 ++++++++++ Source/Utilities/DrawUtilities.cs | 19 +++++++++++++++++++ 5 files changed, 45 insertions(+) diff --git a/Languages/English/Keyed/Keyed-English.xml b/Languages/English/Keyed/Keyed-English.xml index 1d18a97..42e612b 100644 --- a/Languages/English/Keyed/Keyed-English.xml +++ b/Languages/English/Keyed/Keyed-English.xml @@ -27,6 +27,8 @@ Play a crunchy sound when a pawn is assigned to a job they are not skilled at? Disable Scrollwheel Disable the scrollwheel functions (when hovering over skills) + Highlight Active Work Cells + Highlight the grid squares in the work tab when the pawn is actually working that job right now. Vertical labels Display work labels vertically Fix vertical fonts diff --git a/Source/Core/Settings.cs b/Source/Core/Settings.cs index f0cb3cc..44855dc 100644 --- a/Source/Core/Settings.cs +++ b/Source/Core/Settings.cs @@ -13,6 +13,7 @@ public class Settings: ModSettings { public static bool playSounds = true; public static bool TwentyFourHourMode = true; public static bool verticalLabels = true; + public static bool highlightActiveWorkCells; private static string _defaultPriorityBuffer = defaultPriority.ToString(); // public static bool sharedFavourites = true; @@ -51,6 +52,8 @@ public static void DoWindowContents(Rect rect) { "WorkTab.PlayCrunchTip".Translate()); options.CheckboxLabeled("WorkTab.DisableScrollwheel".Translate(), ref disableScrollwheel, "WorkTab.DisableScrollwheelTip".Translate()); + options.CheckboxLabeled("WorkTab.HighlightActiveWorkCells".Translate(), ref highlightActiveWorkCells, + "WorkTab.HighlightActiveWorkCellsTip".Translate()); bool verticalLabelsBuffer = verticalLabels; options.CheckboxLabeled("WorkTab.VerticalLabels".Translate(), ref verticalLabelsBuffer, "WorkTab.VerticalLabelsTip".Translate()); @@ -87,6 +90,7 @@ public override void ExposeData() { Scribe_Values.Look(ref playCrunch, "PlayCrunch", true); Scribe_Values.Look(ref disableScrollwheel, "DisableScrollwheel"); Scribe_Values.Look(ref verticalLabels, "VerticalLabels", true); + Scribe_Values.Look(ref highlightActiveWorkCells, "HighlightActiveWorkCells"); Scribe_Values.Look(ref _fontFix, "FontFix", true); // apply font-fix on load diff --git a/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs b/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs index f8dd1c1..6b0b9f6 100644 --- a/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs +++ b/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs @@ -57,6 +57,16 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) { WorkGiverDef workgiver = WorkGiver; + if (Settings.highlightActiveWorkCells) + { + bool doingNow = (pawn.CurJob?.workGiverDef?.defName == workgiver?.defName); + if (doingNow) + { + GUI.color = Color.white; + GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.getActiveHighlightBox()); + } + } + // create rect in centre of cell, slightly offsetting left to give the appearance of aligning to worktype. Vector2 pos = rect.center - (new Vector2( WorkGiverBoxSize, WorkGiverBoxSize ) / 2f); Rect box = new Rect( pos.x - 2f, pos.y, WorkGiverBoxSize, WorkGiverBoxSize ); diff --git a/Source/PawnColumns/PawnColumnWorker_WorkType.cs b/Source/PawnColumns/PawnColumnWorker_WorkType.cs index d1d2524..3356ba1 100644 --- a/Source/PawnColumns/PawnColumnWorker_WorkType.cs +++ b/Source/PawnColumns/PawnColumnWorker_WorkType.cs @@ -82,6 +82,16 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) { bool incapable = IncapableOfWholeWorkType( pawn ); WorkTypeDef worktype = def.workType; + if (Settings.highlightActiveWorkCells) + { + bool doingNow = (pawn.CurJob?.workGiverDef?.workType?.defName == worktype?.defName); + if (doingNow) + { + GUI.color = Color.white; + GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.getActiveHighlightBox()); + } + } + // create rect in centre of cell Vector2 pos = rect.center - (new Vector2( WorkTypeBoxSize, WorkTypeBoxSize ) / 2f); Rect box = new Rect( pos.x, pos.y, WorkTypeBoxSize, WorkTypeBoxSize ); diff --git a/Source/Utilities/DrawUtilities.cs b/Source/Utilities/DrawUtilities.cs index 6cd3d2b..7ae1e30 100644 --- a/Source/Utilities/DrawUtilities.cs +++ b/Source/Utilities/DrawUtilities.cs @@ -70,6 +70,25 @@ public static void DrawWorkBoxBackground(Rect box, Pawn pawn, WorkTypeDef workty _drawWorkBoxBackgroundMethodInfo.Invoke(null, new object[] { box, pawn, worktype }); } + private static Texture2D activeHighlightBox; + public static Texture2D getActiveHighlightBox() + { + if (activeHighlightBox != null) + { + return activeHighlightBox; + } + Color color = Color.magenta; + Texture2D startingExample = WidgetsWork.WorkBoxOverlay_PreceptWarning; + int width = startingExample.width; + int height = startingExample.height; + Texture2D texture = new Texture2D(width, height); + Color[] pixels = Enumerable.Repeat(color, width * height).ToArray(); + texture.SetPixels(pixels); + texture.Apply(); + activeHighlightBox = texture; + return activeHighlightBox; + } + public static string PriorityLabel(int priority) { /** * 9 8 7 6 5 4 From c2b1a428de3934c2bc3264fa3a0042eeee3982d8 Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:39:23 +0300 Subject: [PATCH 09/17] Fix: Priorities reset after save-load. PriorityManager class was relying on Scribe methods in ExposeData() for clearing out old priorities data. But ExposeData() is not called when a new game is started or a game is loaded which was saved without the mod active. So, new data was added to the old one. If a non-modded save was loaded twice, pawn priorities lists were doubled, with the latest list being active. When the game was subsequently saved and loaded, all data was saved, but only the oldest copy of priorities was restored. Other copies yielded an error: Exception in LookDictionary(label=Priorities): System.InvalidOperationException: Tried to add different values for the same key. Attempts to load priorities data of non-existent pawns, inherited from other games, resulted in a probably harmless error: Could not resolve reference to object with loadID Thing_Human# Now, all static members of PriorityManager are initialized by constructor. --- Source/Priorities/PriorityManager.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Priorities/PriorityManager.cs b/Source/Priorities/PriorityManager.cs index 79d6046..fd43f4e 100644 --- a/Source/Priorities/PriorityManager.cs +++ b/Source/Priorities/PriorityManager.cs @@ -16,11 +16,15 @@ public class PriorityManager: GameComponent { private List pawnPriorityTrackersScribe; private List pawnsScribe; + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "RimWorld requires a constructor with parameter")] public PriorityManager(Game game) : this() { } public PriorityManager() { _instance = this; + _nextId = 0; + _showScheduler = false; + priorities = new Dictionary(); } public static PriorityManager Get { @@ -90,7 +94,7 @@ public override void ExposeData() { List pawns = priorities.Keys.ToList(); foreach (Pawn pawn in pawns) { if (pawn?.Destroyed ?? true) // null or destroyed -{ + { priorities.Remove(pawn); } } From 3fde93d36d3473de7f3406a9448f3abc2e8bd8d2 Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Sun, 12 Nov 2023 00:20:15 +0300 Subject: [PATCH 10/17] Removed unused project DynamicPawnTable. --- Source/WorkTab.sln | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Source/WorkTab.sln b/Source/WorkTab.sln index 0d621db..68f5132 100644 --- a/Source/WorkTab.sln +++ b/Source/WorkTab.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkTab", "WorkTab.csproj", "{5C909B0F-E82A-46B1-AE39-E56285B236A2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicPawnTable", "..\..\..\TOOLS\DynamicPawnTable\DynamicPawnTable\DynamicPawnTable.csproj", "{E93B85A6-EEFF-4BDE-A6F4-CCE6D3487F9A}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluffyUI", "..\..\..\TOOLS\FluffyUI\FluffyUI\FluffyUI.csproj", "{3E905175-2540-4C06-B4C6-F955836C0451}" EndProject Global @@ -19,10 +17,6 @@ Global {5C909B0F-E82A-46B1-AE39-E56285B236A2}.Debug|Any CPU.Build.0 = Debug|Any CPU {5C909B0F-E82A-46B1-AE39-E56285B236A2}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C909B0F-E82A-46B1-AE39-E56285B236A2}.Release|Any CPU.Build.0 = Release|Any CPU - {E93B85A6-EEFF-4BDE-A6F4-CCE6D3487F9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E93B85A6-EEFF-4BDE-A6F4-CCE6D3487F9A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E93B85A6-EEFF-4BDE-A6F4-CCE6D3487F9A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E93B85A6-EEFF-4BDE-A6F4-CCE6D3487F9A}.Release|Any CPU.Build.0 = Release|Any CPU {3E905175-2540-4C06-B4C6-F955836C0451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3E905175-2540-4C06-B4C6-F955836C0451}.Debug|Any CPU.Build.0 = Debug|Any CPU {3E905175-2540-4C06-B4C6-F955836C0451}.Release|Any CPU.ActiveCfg = Release|Any CPU From 45b467dbf1e52636d179f818571a45611648debd Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Sun, 12 Nov 2023 19:21:12 +0300 Subject: [PATCH 11/17] Fix warning: DrawUtilities probably needs a StaticConstructorOnStartup attribute Fix warning in the game's log: Type DrawUtilities probably needs a StaticConstructorOnStartup attribute, because it has a field activeHighlightBox of type Texture2D. All assets must be loaded in the main thread. --- Source/Utilities/DrawUtilities.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Utilities/DrawUtilities.cs b/Source/Utilities/DrawUtilities.cs index 7ae1e30..c9f497b 100644 --- a/Source/Utilities/DrawUtilities.cs +++ b/Source/Utilities/DrawUtilities.cs @@ -11,6 +11,7 @@ using Verse; namespace WorkTab { + [StaticConstructorOnStartup] public static class DrawUtilities { private static MethodInfo _drawWorkBoxBackgroundMethodInfo; From 0c87f48d98b2896dee139c116c2ceee6d81b4b96 Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Sun, 12 Nov 2023 19:34:01 +0300 Subject: [PATCH 12/17] Fix: Naming rule violation. --- Source/PawnColumns/PawnColumnWorker_WorkGiver.cs | 2 +- Source/PawnColumns/PawnColumnWorker_WorkType.cs | 2 +- Source/Utilities/DrawUtilities.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs b/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs index 6b0b9f6..110ab00 100644 --- a/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs +++ b/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs @@ -63,7 +63,7 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) { if (doingNow) { GUI.color = Color.white; - GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.getActiveHighlightBox()); + GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.GetActiveHighlightBox()); } } diff --git a/Source/PawnColumns/PawnColumnWorker_WorkType.cs b/Source/PawnColumns/PawnColumnWorker_WorkType.cs index 079c8bd..1f82299 100644 --- a/Source/PawnColumns/PawnColumnWorker_WorkType.cs +++ b/Source/PawnColumns/PawnColumnWorker_WorkType.cs @@ -88,7 +88,7 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) { if (doingNow) { GUI.color = Color.white; - GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.getActiveHighlightBox()); + GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.GetActiveHighlightBox()); } } diff --git a/Source/Utilities/DrawUtilities.cs b/Source/Utilities/DrawUtilities.cs index c9f497b..ce463ee 100644 --- a/Source/Utilities/DrawUtilities.cs +++ b/Source/Utilities/DrawUtilities.cs @@ -72,7 +72,7 @@ public static void DrawWorkBoxBackground(Rect box, Pawn pawn, WorkTypeDef workty } private static Texture2D activeHighlightBox; - public static Texture2D getActiveHighlightBox() + public static Texture2D GetActiveHighlightBox() { if (activeHighlightBox != null) { From 21ca9474d8f4c488337a25cbed5e5ab4c3a5f48f Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Sun, 12 Nov 2023 20:31:07 +0300 Subject: [PATCH 13/17] Fix: active job frame is too bright. --- Source/Utilities/DrawUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Utilities/DrawUtilities.cs b/Source/Utilities/DrawUtilities.cs index ce463ee..c12aaff 100644 --- a/Source/Utilities/DrawUtilities.cs +++ b/Source/Utilities/DrawUtilities.cs @@ -78,7 +78,7 @@ public static Texture2D GetActiveHighlightBox() { return activeHighlightBox; } - Color color = Color.magenta; + Color color = Color.Lerp(Color.black, Color.magenta, 0.7f); Texture2D startingExample = WidgetsWork.WorkBoxOverlay_PreceptWarning; int width = startingExample.width; int height = startingExample.height; From 29fa35abc39cc3db3565dc8e9901bd138c80e342 Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Sun, 12 Nov 2023 20:31:33 +0300 Subject: [PATCH 14/17] Fix wording in tooltips: increase/increment/decrease/decrement priorities => raise/lower --- Languages/English/Keyed/Keyed-English.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Languages/English/Keyed/Keyed-English.xml b/Languages/English/Keyed/Keyed-English.xml index d150f4c..817a0ab 100644 --- a/Languages/English/Keyed/Keyed-English.xml +++ b/Languages/English/Keyed/Keyed-English.xml @@ -11,7 +11,7 @@ Click to collapse all priorities\nCtrl-click headers to toggle expanding individual priorities - Shift + left-click or scroll up to increase priorities\nShift + right click or scroll down to decrease priorities + Shift + left-click or scroll up to raise priorities\nShift + right click or scroll down to lower priorities Shift + left-click or scroll up to toggle priorities on\nShift + right click or scroll down to toggle priorities off Ctrl + click to expand list of detailed priorities Ctrl + click to collapse list of detailed priorities @@ -54,7 +54,7 @@ {0} is assigned to {1} - Click to jump to\nShift-left-click or scroll up to increment priorities\nShift-right-click or scroll down to decrement priorities + Click to jump to\nShift-left-click or scroll up to raise priorities\nShift-right-click or scroll down to lower priorities Create new favourite From cb9c657d501c9bc99cc5df382ef3f7cd1a0482d3 Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Sun, 12 Nov 2023 22:43:29 +0300 Subject: [PATCH 15/17] Enable HighlightCurrentJobCell by default. Also, change names and labels for being consistent: ActiveWorkCells => CurrentJobCell. Minor clean-up. --- Languages/English/Keyed/Keyed-English.xml | 6 ++--- Source/Core/Settings.cs | 26 +++++++++---------- .../PawnColumns/PawnColumnWorker_WorkGiver.cs | 4 +-- .../PawnColumns/PawnColumnWorker_WorkType.cs | 4 +-- Source/Utilities/DrawUtilities.cs | 12 ++++----- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Languages/English/Keyed/Keyed-English.xml b/Languages/English/Keyed/Keyed-English.xml index 817a0ab..7767f41 100644 --- a/Languages/English/Keyed/Keyed-English.xml +++ b/Languages/English/Keyed/Keyed-English.xml @@ -30,9 +30,9 @@ Disable Scrollwheel Disable the scrollwheel functions (when hovering over skills) Current job column as text (requires restart) - Render the current job column as a text column with the whole job, instead of just an icon.\n\n(Due to a technical limitation, you must restart the game after enabling this option.) - Highlight Active Work Cells - Highlight the grid squares in the work tab when the pawn is actually working that job right now. + Render the current job column as a text description of current activity.\nWhen disabled, an icon is displayed.\n\n(Due to a technical limitation, you must restart the game after changing this option.) + Highlight current job cell + Highlight the grid square in the work tab when the pawn is actually working that job right now. Vertical labels Display work labels vertically Fix vertical fonts diff --git a/Source/Core/Settings.cs b/Source/Core/Settings.cs index 42738d7..53d70c6 100644 --- a/Source/Core/Settings.cs +++ b/Source/Core/Settings.cs @@ -6,15 +6,15 @@ namespace WorkTab { public class Settings: ModSettings { - public static int defaultPriority = 3; - public static bool disableScrollwheel; - public static bool jobTextMode = false; - public static int maxPriority = 9; - public static bool playCrunch = true; - public static bool playSounds = true; - public static bool TwentyFourHourMode = true; - public static bool verticalLabels = true; - public static bool highlightActiveWorkCells; + public static int maxPriority = 9; + public static int defaultPriority = 3; + public static bool TwentyFourHourMode = true; + public static bool playSounds = true; + public static bool playCrunch = true; + public static bool disableScrollwheel = false; + public static bool jobTextMode = false; + public static bool highlightCurrentJobCell = true; + public static bool verticalLabels = true; private static string _defaultPriorityBuffer = defaultPriority.ToString(); // public static bool sharedFavourites = true; @@ -55,8 +55,8 @@ public static void DoWindowContents(Rect rect) { "WorkTab.DisableScrollwheelTip".Translate()); options.CheckboxLabeled("WorkTab.JobTextMode".Translate(), ref jobTextMode, "WorkTab.JobTextModeTip".Translate()); - options.CheckboxLabeled("WorkTab.HighlightActiveWorkCells".Translate(), ref highlightActiveWorkCells, - "WorkTab.HighlightActiveWorkCellsTip".Translate()); + options.CheckboxLabeled("WorkTab.HighlightCurrentJobCell".Translate(), ref highlightCurrentJobCell, + "WorkTab.HighlightCurrentJobCellTip".Translate()); bool verticalLabelsBuffer = verticalLabels; options.CheckboxLabeled("WorkTab.VerticalLabels".Translate(), ref verticalLabelsBuffer, "WorkTab.VerticalLabelsTip".Translate()); @@ -70,7 +70,7 @@ public static void DoWindowContents(Rect rect) { options.CheckboxLabeled("WorkTab.FontFix".Translate(), ref _fontFixBuffer, "WorkTab.FontFixTip".Translate()); _fontFixBuffer = - verticalLabels && _fontFixBuffer; // disabling vertical labels makes the font fix unnecesary. + verticalLabels && _fontFixBuffer; // disabling vertical labels makes the font fix unnecessary. // apply any changes. if (_fontFixBuffer != _fontFix) { @@ -94,7 +94,7 @@ public override void ExposeData() { Scribe_Values.Look(ref disableScrollwheel, "DisableScrollwheel"); Scribe_Values.Look(ref jobTextMode, "JobTextMode"); Scribe_Values.Look(ref verticalLabels, "VerticalLabels", true); - Scribe_Values.Look(ref highlightActiveWorkCells, "HighlightActiveWorkCells"); + Scribe_Values.Look(ref highlightCurrentJobCell, "HighlightCurrentJobCell", true); Scribe_Values.Look(ref _fontFix, "FontFix", true); // apply font-fix on load diff --git a/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs b/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs index 110ab00..e6c3082 100644 --- a/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs +++ b/Source/PawnColumns/PawnColumnWorker_WorkGiver.cs @@ -57,13 +57,13 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) { WorkGiverDef workgiver = WorkGiver; - if (Settings.highlightActiveWorkCells) + if (Settings.highlightCurrentJobCell) { bool doingNow = (pawn.CurJob?.workGiverDef?.defName == workgiver?.defName); if (doingNow) { GUI.color = Color.white; - GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.GetActiveHighlightBox()); + GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.GetCurrentJobHighlightBox()); } } diff --git a/Source/PawnColumns/PawnColumnWorker_WorkType.cs b/Source/PawnColumns/PawnColumnWorker_WorkType.cs index 1f82299..196d86b 100644 --- a/Source/PawnColumns/PawnColumnWorker_WorkType.cs +++ b/Source/PawnColumns/PawnColumnWorker_WorkType.cs @@ -82,13 +82,13 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) { bool incapable = IncapableOfWholeWorkType( pawn ); WorkTypeDef worktype = def.workType; - if (Settings.highlightActiveWorkCells) + if (Settings.highlightCurrentJobCell) { bool doingNow = (pawn.CurJob?.workGiverDef?.workType?.defName == worktype?.defName); if (doingNow) { GUI.color = Color.white; - GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.GetActiveHighlightBox()); + GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.GetCurrentJobHighlightBox()); } } diff --git a/Source/Utilities/DrawUtilities.cs b/Source/Utilities/DrawUtilities.cs index c12aaff..d8ba890 100644 --- a/Source/Utilities/DrawUtilities.cs +++ b/Source/Utilities/DrawUtilities.cs @@ -71,12 +71,12 @@ public static void DrawWorkBoxBackground(Rect box, Pawn pawn, WorkTypeDef workty _drawWorkBoxBackgroundMethodInfo.Invoke(null, new object[] { box, pawn, worktype }); } - private static Texture2D activeHighlightBox; - public static Texture2D GetActiveHighlightBox() + private static Texture2D currentJobHighlightBox; + public static Texture2D GetCurrentJobHighlightBox() { - if (activeHighlightBox != null) + if (currentJobHighlightBox != null) { - return activeHighlightBox; + return currentJobHighlightBox; } Color color = Color.Lerp(Color.black, Color.magenta, 0.7f); Texture2D startingExample = WidgetsWork.WorkBoxOverlay_PreceptWarning; @@ -86,8 +86,8 @@ public static Texture2D GetActiveHighlightBox() Color[] pixels = Enumerable.Repeat(color, width * height).ToArray(); texture.SetPixels(pixels); texture.Apply(); - activeHighlightBox = texture; - return activeHighlightBox; + currentJobHighlightBox = texture; + return currentJobHighlightBox; } public static string PriorityLabel(int priority) { From 59dc4fe4662ceef86f289a25e10a4060c9b4b717 Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Mon, 13 Nov 2023 23:37:06 +0300 Subject: [PATCH 16/17] Fix: Numeric settings are reset after restarting the game. --- Source/Core/Settings.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Source/Core/Settings.cs b/Source/Core/Settings.cs index 53d70c6..2ee0a8e 100644 --- a/Source/Core/Settings.cs +++ b/Source/Core/Settings.cs @@ -15,13 +15,8 @@ public class Settings: ModSettings { public static bool jobTextMode = false; public static bool highlightCurrentJobCell = true; public static bool verticalLabels = true; - private static string _defaultPriorityBuffer = defaultPriority.ToString(); - - // public static bool sharedFavourites = true; private static bool _fontFix = true; - - // buffers - private static string _maxPriorityBuffer = maxPriority.ToString(); + // public static bool sharedFavourites = true; public Settings() { ApplyFontFix(_fontFix); @@ -39,10 +34,12 @@ public static void ApplyFontFix(bool state) { public static void DoWindowContents(Rect rect) { Listing_Standard options = new Listing_Standard(); options.Begin(rect); - options.TextFieldNumericLabeled("WorkTab.MaxPriority".Translate(), ref maxPriority, ref _maxPriorityBuffer, + string maxPriorityBuffer = null; + options.TextFieldNumericLabeled("WorkTab.MaxPriority".Translate(), ref maxPriority, ref maxPriorityBuffer, 4, 9, "WorkTab.MaxPriorityTip".Translate(), 1 / 8f); + string defaultPriorityBuffer = null; options.TextFieldNumericLabeled("WorkTab.DefaultPriority".Translate(), ref defaultPriority, - ref _defaultPriorityBuffer, 1, 9, "WorkTab.DefaultPriorityTip".Translate(), + ref defaultPriorityBuffer, 1, 9, "WorkTab.DefaultPriorityTip".Translate(), 1 / 8f); options.CheckboxLabeled("WorkTab.24HourMode".Translate(), ref TwentyFourHourMode, "WorkTab.24HourModeTip".Translate()); From 82ec47af79e28db1fefada23e9278ef151a65e31 Mon Sep 17 00:00:00 2001 From: Doomster14 <146005125+Doomster14@users.noreply.github.com> Date: Wed, 15 Nov 2023 00:17:22 +0300 Subject: [PATCH 17/17] Fix the last fix: Numeric settings are hard to edit. --- Source/Core/Settings.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Core/Settings.cs b/Source/Core/Settings.cs index 2ee0a8e..c96ba70 100644 --- a/Source/Core/Settings.cs +++ b/Source/Core/Settings.cs @@ -1,4 +1,4 @@ -// Settings.cs +// Settings.cs // Copyright Karel Kroeze, 2020-2020 using UnityEngine; @@ -18,6 +18,11 @@ public class Settings: ModSettings { private static bool _fontFix = true; // public static bool sharedFavourites = true; + // Buffers will be initialized with current settings as soon as + // DoWindowContents() → Listing_Standard.TextFieldNumericLabeled() → Widgets.TextFieldNumeric() will be called. + private static string maxPriorityBuffer = null; + private static string defaultPriorityBuffer = null; + public Settings() { ApplyFontFix(_fontFix); } @@ -34,10 +39,8 @@ public static void ApplyFontFix(bool state) { public static void DoWindowContents(Rect rect) { Listing_Standard options = new Listing_Standard(); options.Begin(rect); - string maxPriorityBuffer = null; options.TextFieldNumericLabeled("WorkTab.MaxPriority".Translate(), ref maxPriority, ref maxPriorityBuffer, 4, 9, "WorkTab.MaxPriorityTip".Translate(), 1 / 8f); - string defaultPriorityBuffer = null; options.TextFieldNumericLabeled("WorkTab.DefaultPriority".Translate(), ref defaultPriority, ref defaultPriorityBuffer, 1, 9, "WorkTab.DefaultPriorityTip".Translate(), 1 / 8f);