Skip to content

Commit

Permalink
Merge pull request fluffy-mods#206 from maarxx/highlight_active_square
Browse files Browse the repository at this point in the history
Add Option to Highlight Current Active Work Cell
  • Loading branch information
Doomster14 committed Nov 12, 2023
2 parents df112dd + 15604d9 commit a818e5e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Languages/English/Keyed/Keyed-English.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<WorkTab.DisableScrollwheelTip>Disable the scrollwheel functions (when hovering over skills)</WorkTab.DisableScrollwheelTip>
<WorkTab.JobTextMode>Current job column as text (requires restart)</WorkTab.JobTextMode>
<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>
<WorkTab.HighlightActiveWorkCells>Highlight Active Work Cells</WorkTab.HighlightActiveWorkCells>
<WorkTab.HighlightActiveWorkCellsTip>Highlight the grid squares in the work tab when the pawn is actually working that job right now.</WorkTab.HighlightActiveWorkCellsTip>
<WorkTab.VerticalLabels>Vertical labels</WorkTab.VerticalLabels>
<WorkTab.VerticalLabelsTip>Display work labels vertically</WorkTab.VerticalLabelsTip>
<WorkTab.FontFix>Fix vertical fonts</WorkTab.FontFix>
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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;
Expand Down Expand Up @@ -54,6 +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());
bool verticalLabelsBuffer = verticalLabels;
options.CheckboxLabeled("WorkTab.VerticalLabels".Translate(), ref verticalLabelsBuffer,
"WorkTab.VerticalLabelsTip".Translate());
Expand Down Expand Up @@ -91,6 +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 _fontFix, "FontFix", true);

// apply font-fix on load
Expand Down
10 changes: 10 additions & 0 deletions Source/PawnColumns/PawnColumnWorker_WorkGiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 10 additions & 0 deletions Source/PawnColumns/PawnColumnWorker_WorkType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
19 changes: 19 additions & 0 deletions Source/Utilities/DrawUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a818e5e

Please sign in to comment.