Skip to content

Commit a818e5e

Browse files
committed
Merge pull request fluffy-mods#206 from maarxx/highlight_active_square
Add Option to Highlight Current Active Work Cell
2 parents df112dd + 15604d9 commit a818e5e

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

Languages/English/Keyed/Keyed-English.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<WorkTab.DisableScrollwheelTip>Disable the scrollwheel functions (when hovering over skills)</WorkTab.DisableScrollwheelTip>
3232
<WorkTab.JobTextMode>Current job column as text (requires restart)</WorkTab.JobTextMode>
3333
<WorkTab.JobTextModeTip>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.)</WorkTab.JobTextModeTip>
34+
<WorkTab.HighlightActiveWorkCells>Highlight Active Work Cells</WorkTab.HighlightActiveWorkCells>
35+
<WorkTab.HighlightActiveWorkCellsTip>Highlight the grid squares in the work tab when the pawn is actually working that job right now.</WorkTab.HighlightActiveWorkCellsTip>
3436
<WorkTab.VerticalLabels>Vertical labels</WorkTab.VerticalLabels>
3537
<WorkTab.VerticalLabelsTip>Display work labels vertically</WorkTab.VerticalLabelsTip>
3638
<WorkTab.FontFix>Fix vertical fonts</WorkTab.FontFix>

Source/Core/Settings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Settings: ModSettings {
1414
public static bool playSounds = true;
1515
public static bool TwentyFourHourMode = true;
1616
public static bool verticalLabels = true;
17+
public static bool highlightActiveWorkCells;
1718
private static string _defaultPriorityBuffer = defaultPriority.ToString();
1819

1920
// public static bool sharedFavourites = true;
@@ -54,6 +55,8 @@ public static void DoWindowContents(Rect rect) {
5455
"WorkTab.DisableScrollwheelTip".Translate());
5556
options.CheckboxLabeled("WorkTab.JobTextMode".Translate(), ref jobTextMode,
5657
"WorkTab.JobTextModeTip".Translate());
58+
options.CheckboxLabeled("WorkTab.HighlightActiveWorkCells".Translate(), ref highlightActiveWorkCells,
59+
"WorkTab.HighlightActiveWorkCellsTip".Translate());
5760
bool verticalLabelsBuffer = verticalLabels;
5861
options.CheckboxLabeled("WorkTab.VerticalLabels".Translate(), ref verticalLabelsBuffer,
5962
"WorkTab.VerticalLabelsTip".Translate());
@@ -91,6 +94,7 @@ public override void ExposeData() {
9194
Scribe_Values.Look(ref disableScrollwheel, "DisableScrollwheel");
9295
Scribe_Values.Look(ref jobTextMode, "JobTextMode");
9396
Scribe_Values.Look(ref verticalLabels, "VerticalLabels", true);
97+
Scribe_Values.Look(ref highlightActiveWorkCells, "HighlightActiveWorkCells");
9498
Scribe_Values.Look(ref _fontFix, "FontFix", true);
9599

96100
// apply font-fix on load

Source/PawnColumns/PawnColumnWorker_WorkGiver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) {
5757

5858
WorkGiverDef workgiver = WorkGiver;
5959

60+
if (Settings.highlightActiveWorkCells)
61+
{
62+
bool doingNow = (pawn.CurJob?.workGiverDef?.defName == workgiver?.defName);
63+
if (doingNow)
64+
{
65+
GUI.color = Color.white;
66+
GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.getActiveHighlightBox());
67+
}
68+
}
69+
6070
// create rect in centre of cell, slightly offsetting left to give the appearance of aligning to worktype.
6171
Vector2 pos = rect.center - (new Vector2( WorkGiverBoxSize, WorkGiverBoxSize ) / 2f);
6272
Rect box = new Rect( pos.x - 2f, pos.y, WorkGiverBoxSize, WorkGiverBoxSize );

Source/PawnColumns/PawnColumnWorker_WorkType.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table) {
8282
bool incapable = IncapableOfWholeWorkType( pawn );
8383
WorkTypeDef worktype = def.workType;
8484

85+
if (Settings.highlightActiveWorkCells)
86+
{
87+
bool doingNow = (pawn.CurJob?.workGiverDef?.workType?.defName == worktype?.defName);
88+
if (doingNow)
89+
{
90+
GUI.color = Color.white;
91+
GUI.DrawTexture(rect.ContractedBy(-2f), DrawUtilities.getActiveHighlightBox());
92+
}
93+
}
94+
8595
// create rect in centre of cell
8696
Vector2 pos = rect.center - (new Vector2( WorkTypeBoxSize, WorkTypeBoxSize ) / 2f);
8797
Rect box = new Rect( pos.x, pos.y, WorkTypeBoxSize, WorkTypeBoxSize );

Source/Utilities/DrawUtilities.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ public static void DrawWorkBoxBackground(Rect box, Pawn pawn, WorkTypeDef workty
7070
_drawWorkBoxBackgroundMethodInfo.Invoke(null, new object[] { box, pawn, worktype });
7171
}
7272

73+
private static Texture2D activeHighlightBox;
74+
public static Texture2D getActiveHighlightBox()
75+
{
76+
if (activeHighlightBox != null)
77+
{
78+
return activeHighlightBox;
79+
}
80+
Color color = Color.magenta;
81+
Texture2D startingExample = WidgetsWork.WorkBoxOverlay_PreceptWarning;
82+
int width = startingExample.width;
83+
int height = startingExample.height;
84+
Texture2D texture = new Texture2D(width, height);
85+
Color[] pixels = Enumerable.Repeat(color, width * height).ToArray();
86+
texture.SetPixels(pixels);
87+
texture.Apply();
88+
activeHighlightBox = texture;
89+
return activeHighlightBox;
90+
}
91+
7392
public static string PriorityLabel(int priority) {
7493
/**
7594
* 9 8 7 6 5 4

0 commit comments

Comments
 (0)