Skip to content

Commit

Permalink
re-implement vertical labels as an option (default: on). Should help …
Browse files Browse the repository at this point in the history
…reduce horizontal clutter (#67).
  • Loading branch information
FluffierThanThou committed Nov 10, 2017
1 parent f196b45 commit 27ccebe
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 68 deletions.
4 changes: 2 additions & 2 deletions About/About.xml
Expand Up @@ -33,8 +33,8 @@ Bronytamin: Russian translation
Duduluu: Chinese translation
Eric Swanson: Help with time-dependent tooltips
DoctorVanGogh: Help with typos in build script
MrClon:
mercutiodesign:
MrClon: Russian translation
mercutiodesign: Optional scrollwheel usage setting

<size=24>Version</size>
This is version v0.18.0.0
Expand Down
Binary file modified Assemblies/WorkTab.dll
Binary file not shown.
6 changes: 5 additions & 1 deletion Languages/English/Keyed/Keyed-English.xml
Expand Up @@ -25,9 +25,13 @@
<WorkTab.PlaySoundsTip>Play sounds when a priority is changed?</WorkTab.PlaySoundsTip>
<WorkTab.PlayCrunch>Crunchy sounds</WorkTab.PlayCrunch>
<WorkTab.PlayCrunchTip>Play a crunchy sound when a pawn is assigned to a job they are not skilled at?</WorkTab.PlayCrunchTip>

<WorkTab.DisableScrollwheel>Disable Scrollwheel</WorkTab.DisableScrollwheel>
<WorkTab.DisableScrollwheelTip>Disable the scrollwheel functions (when hovering over skills)</WorkTab.DisableScrollwheelTip>
<WorkTab.VerticalLabels>Vertical labels</WorkTab.VerticalLabels>
<WorkTab.VerticalLabelsTip>Display work labels vertically</WorkTab.VerticalLabelsTip>
<WorkTab.FontFix>Fix vertical fonts</WorkTab.FontFix>
<WorkTab.FontFixTip>Unity (the engine RimWorld is built on) does not deal well with rotated fonts, causing a blur. This fix removes the blur, but can cause slightly odd letter positioning.</WorkTab.FontFixTip>

<!-- scheduler -->
<WorkTab.SchedulerHourTip>{0}-{1} is currently {2}\n\n{3}</WorkTab.SchedulerHourTip>
<WorkTab.Selected>selected</WorkTab.Selected>
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Expand Up @@ -26,8 +26,8 @@ Finally, there will never be an 'autolabour' mode where a mod sets priorities fo
- Duduluu: Chinese translation
- Eric Swanson: Help with time-dependent tooltips
- DoctorVanGogh: Help with typos in build script
- MrClon:
- mercutiodesign:
- MrClon: Russian translation
- mercutiodesign: Optional scrollwheel usage setting

# Think you found a bug?
Please read [this guide](http://steamcommunity.com/sharedfiles/filedetails/?id=725234314) before creating a bug report,
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Constants.cs
Expand Up @@ -15,8 +15,10 @@ public static class Constants
public const int WorkGiverWidth = 25;
public const int WorkGiverBoxSize = 20;
public const int Margin = 4;
public const int HeaderHeight = 50;
public static Dictionary<string,string> TruncationCache = new Dictionary<string, string>();
public const int HorizontalHeaderHeight = 50;
public const int VerticalHeaderHeight = 100;
public static Dictionary<string, string> TruncationCache = new Dictionary<string, string>();
public static Dictionary<string, string> VerticalTruncationCache = new Dictionary<string, string>();
public const int TimeBarHeight = 40;
public const int ExtraTopSpace = 40;
public static readonly Vector2 PriorityLabelSize = new Vector2( 160, 30 );
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/PawnPriorityTracker.cs
Expand Up @@ -83,7 +83,7 @@ public void Recache(WorkGiverDef workgiver, bool bubble = true)
var priorities = pawn.GetPriorities(workgiver);
_everScheduledWorkGiver[workgiver] = priorities.Any(p => p > 0);
_timeScheduledWorkGiver[workgiver] = priorities.Distinct().Count() > 1;
_timeScheduledWorkGiverTip[workgiver] = WorkUtilities.TimeScheduledTip(pawn, priorities, workgiver.label);
_timeScheduledWorkGiverTip[workgiver] = DrawUtilities.TimeScheduledTip(pawn, priorities, workgiver.label);

// also recache worktype
if (bubble)
Expand All @@ -103,7 +103,7 @@ public void Recache(WorkTypeDef worktype, bool bubble = true)
// recache worktype stuff
_everScheduledWorkType[worktype] = workgivers.Any(wg => _everScheduledWorkGiver[wg]);
_timeScheduledWorkType[worktype] = workgivers.Any(wg => _timeScheduledWorkGiver[wg]);
_timeScheduledWorkTypeTip[worktype] = WorkUtilities.TimeScheduledTip(pawn, priorities, worktype.gerundLabel);
_timeScheduledWorkTypeTip[worktype] = DrawUtilities.TimeScheduledTip(pawn, priorities, worktype.gerundLabel);

// is any workgiver different from the whole at any time during the day?
_partScheduledWorkType[worktype] = TimeUtilities.WholeDay
Expand Down
48 changes: 45 additions & 3 deletions Source/Core/Settings.cs
Expand Up @@ -2,6 +2,7 @@
// Settings.cs
// 2017-05-22

using System.Resources;
using UnityEngine;
using Verse;

Expand All @@ -14,20 +15,55 @@ public class Settings: ModSettings
public static bool playSounds = true;
public static bool TwentyFourHourMode = true;
public static bool disableScrollwheel = false;
public static bool verticalLabels = true;
private static bool _fontFix = true;

public Settings()
{
ApplyFontFix( _fontFix );
}

public static void ApplyFontFix( bool state )
{
Logger.Debug( state ? "Applying font fix" : "Disabling font fix" );
_fontFix = state;
Text.fontStyles[0].font.material.mainTexture.filterMode = state ? FilterMode.Point : FilterMode.Trilinear;
}

// buffers
private static string maxPriorityBuffer = maxPriority.ToString();

private static bool _fontFixBuffer = _fontFix;
private static string _maxPriorityBuffer = maxPriority.ToString();

public static void DoWindowContents( Rect rect )
{
var options = new Listing_Standard();
options.Begin(rect);
options.TextFieldNumericLabeled<int>("WorkTab.MaxPriority".Translate(), ref maxPriority, ref maxPriorityBuffer, 4, 9, "WorkTab.MaxPriorityTip".Translate(), 1 / 8f);
options.TextFieldNumericLabeled<int>("WorkTab.MaxPriority".Translate(), ref maxPriority, ref _maxPriorityBuffer, 4, 9, "WorkTab.MaxPriorityTip".Translate(), 1 / 8f);
options.CheckboxLabeled("WorkTab.24HourMode".Translate(), ref TwentyFourHourMode, "WorkTab.24HourModeTip".Translate() );
options.CheckboxLabeled("WorkTab.PlaySounds".Translate(), ref playSounds, "WorkTab.PlaySoundsTip".Translate());
playCrunch = playSounds && playCrunch; // disabling sounds also disables crunch.
options.CheckboxLabeled("WorkTab.PlayCrunch".Translate(), ref playCrunch, !playSounds, "WorkTab.PlayCrunchTip".Translate());
options.CheckboxLabeled("WorkTab.DisableScrollwheel".Translate(), ref disableScrollwheel, "WorkTab.DisableScrollwheelTip".Translate());
bool verticalLabelsBuffer = verticalLabels;
options.CheckboxLabeled( "WorkTab.VerticalLabels".Translate(), ref verticalLabelsBuffer,
"WorkTab.VerticalLabelsTip".Translate() );

// vertical labels mess up unity's font positioning, and causes anti-aliasing blur
// setting the filtermode to point removes the blur, but causes slight jitter in letter positioning.
// I still think it's the lesser of two evils...
bool _fontFixBuffer = _fontFix;
options.CheckboxLabeled("WorkTab.FontFix".Translate(), ref _fontFixBuffer, "WorkTab.FontFixTip".Translate());
_fontFixBuffer = verticalLabels && _fontFixBuffer; // disabling vertical labels makes the font fix unnecesary.

// apply any changes.
if ( _fontFixBuffer != _fontFix )
ApplyFontFix( _fontFixBuffer );
if ( verticalLabelsBuffer != verticalLabels )
{
verticalLabels = verticalLabelsBuffer;
MainTabWindow_WorkTab.Instance.Table.SetDirty();
}

options.End();
}

Expand All @@ -40,6 +76,12 @@ public override void ExposeData()
Scribe_Values.Look(ref playSounds, "PlaySounds", true);
Scribe_Values.Look(ref playCrunch, "PlayCrunch", true);
Scribe_Values.Look(ref disableScrollwheel, "DisableScrollwheel", false);
Scribe_Values.Look(ref verticalLabels, "VerticalLabels", true );
Scribe_Values.Look(ref _fontFix, "FontFix", true );

// apply font-fix on load
if ( Scribe.mode == LoadSaveMode.PostLoadInit )
ApplyFontFix( _fontFix );
}

#endregion
Expand Down
66 changes: 42 additions & 24 deletions Source/PawnColumns/PawnColumnWorker_WorkGiver.cs
Expand Up @@ -49,7 +49,7 @@ public override void DoCell( Rect rect, Pawn pawn, PawnTable table )
var incapable = !pawn.CapableOf( workgiver );

// plop in the tooltip
Func<string> tipGetter = delegate { return WorkUtilities.TipForPawnWorker( pawn, workgiver, incapable ); };
Func<string> tipGetter = delegate { return DrawUtilities.TipForPawnWorker( pawn, workgiver, incapable ); };
TooltipHandler.TipRegion( box, tipGetter, pawn.thingIDNumber ^ workgiver.workType.GetHashCode() );

// bail out if pawn can't actually do this work
Expand All @@ -76,16 +76,16 @@ protected virtual void DrawWorkGiverBoxFor( Rect box, Pawn pawn, WorkGiverDef wo
{
// draw background
GUI.color = incapable ? new Color( 1f, .3f, .3f ) : Color.white;
WorkUtilities.DrawWorkBoxBackground( box, pawn, workgiver.workType );
DrawUtilities.DrawWorkBoxBackground( box, pawn, workgiver.workType );
GUI.color = Color.white;

// draw extras
var tracker = PriorityManager.Get[pawn];
if (tracker.TimeScheduled(workgiver))
WorkUtilities.DrawTimeScheduled(box);
DrawUtilities.DrawTimeScheduled(box);

// draw priorities / checks
WorkUtilities.DrawPriority( box, pawn.GetPriority( workgiver, VisibleHour ), true );
DrawUtilities.DrawPriority( box, pawn.GetPriority( workgiver, VisibleHour ), true );
}

protected virtual void HandleInteractions( Rect rect, Pawn pawn )
Expand Down Expand Up @@ -162,14 +162,48 @@ protected override void HeaderClicked( Rect headerRect, PawnTable table )
}

public string Label => WorkGiver.label.NullOrEmpty() ? WorkGiver.gerund : WorkGiver.LabelCap;

public override void DoHeader( Rect rect, PawnTable table )
public override void DoHeader(Rect rect, PawnTable table)
{
// make sure we're at the correct font size
Text.Font = GameFont.Tiny;
Rect labelRect = rect;

if ( Settings.verticalLabels )
DrawVerticalHeader( rect, table );
else
DrawHorizontalHeader( rect, table, out labelRect );

// handle interactions (click + scroll)
HeaderInteractions(labelRect, table);

// mouseover stuff
Widgets.DrawHighlightIfMouseover(labelRect);
TooltipHandler.TipRegion(labelRect, GetHeaderTip(table));

// sort icon
if (table.SortingBy == def)
{
Texture2D sortIcon = (!table.SortingDescending) ? SortingIcon : SortingDescendingIcon;
Rect bottomRight = new Rect(rect.xMax - sortIcon.width - 1f, rect.yMax - sortIcon.height - 1f,
sortIcon.width, sortIcon.height);
GUI.DrawTexture(bottomRight, sortIcon);
}
}

public void DrawVerticalHeader( Rect rect, PawnTable table )
{
GUI.color = new Color(.8f, .8f, .8f);
Text.Anchor = TextAnchor.MiddleLeft;
DrawUtilities.VerticalLabel(rect, Label.Truncate(rect.height, VerticalTruncationCache));
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = Color.white;
}

public void DrawHorizontalHeader( Rect rect, PawnTable table, out Rect labelRect )
{
// get offset rect
var labelRect = GetLabelRect( rect );
labelRect = GetLabelRect( rect );

// draw label, slightly greyed out to contrast with work types
GUI.color = new Color( 1f, 1f, 1f, .8f );
Expand All @@ -189,22 +223,6 @@ public override void DoHeader( Rect rect, PawnTable table )
Widgets.DrawLineVertical( Mathf.FloorToInt( start.x ), start.y, length );
Widgets.DrawLineVertical( Mathf.CeilToInt( start.x ), start.y, length );
GUI.color = Color.white;

// handle interactions (click + scroll)
HeaderInteractions( labelRect, table );

// mouseover stuff
Widgets.DrawHighlightIfMouseover( labelRect );
TooltipHandler.TipRegion( labelRect, GetHeaderTip( table ) );

// sort icon
if ( table.SortingBy == def )
{
Texture2D sortIcon = ( !table.SortingDescending ) ? SortingIcon : SortingDescendingIcon;
Rect bottomRight = new Rect( rect.xMax - sortIcon.width - 1f, rect.yMax - sortIcon.height - 1f,
sortIcon.width, sortIcon.height );
GUI.DrawTexture( bottomRight, sortIcon );
}
}

public override int Compare( Pawn a, Pawn b )
Expand Down Expand Up @@ -261,7 +279,7 @@ public Vector2 LabelSize
}
}

public override int GetMinHeaderHeight( PawnTable table ) { return HeaderHeight; }
public override int GetMinHeaderHeight( PawnTable table ) { return Settings.verticalLabels ? VerticalHeaderHeight : HorizontalHeaderHeight; }

private Rect GetLabelRect( Rect headerRect )
{
Expand Down
68 changes: 43 additions & 25 deletions Source/PawnColumns/PawnColumnWorker_WorkType.cs
Expand Up @@ -47,7 +47,7 @@ public override void DoCell( Rect rect, Pawn pawn, PawnTable table )
var box = new Rect( pos.x, pos.y, WorkTypeBoxSize, WorkTypeBoxSize );

// plop in the tooltip
Func<string> tipGetter = delegate { return WorkUtilities.TipForPawnWorker( pawn, worktype, incapable ); };
Func<string> tipGetter = delegate { return DrawUtilities.TipForPawnWorker( pawn, worktype, incapable ); };
TooltipHandler.TipRegion( box, tipGetter, pawn.thingIDNumber ^ worktype.GetHashCode() );

// bail out if worktype is disabled (or pawn has no background story).
Expand All @@ -67,18 +67,18 @@ protected virtual void DrawWorkTypeBoxFor( Rect box, Pawn pawn, WorkTypeDef work
{
// draw background
GUI.color = incapable ? new Color( 1f, .3f, .3f ) : Color.white;
WorkUtilities.DrawWorkBoxBackground( box, pawn, worktype );
DrawUtilities.DrawWorkBoxBackground( box, pawn, worktype );
GUI.color = Color.white;

// draw extras
var tracker = PriorityManager.Get[pawn];
if (tracker.TimeScheduled(worktype))
WorkUtilities.DrawTimeScheduled(box);
DrawUtilities.DrawTimeScheduled(box);
if (tracker.PartScheduled(worktype))
WorkUtilities.DrawPartScheduled(box);
DrawUtilities.DrawPartScheduled(box);

// draw priorities / checks
WorkUtilities.DrawPriority( box, pawn.GetPriority( worktype, VisibleHour ) );
DrawUtilities.DrawPriority( box, pawn.GetPriority( worktype, VisibleHour ) );
}

protected virtual void HandleInteractions( Rect rect, Pawn pawn )
Expand Down Expand Up @@ -174,26 +174,12 @@ public override void DoHeader( Rect rect, PawnTable table )
{
// make sure we're at the correct font size
Text.Font = GameFont.Small;
Rect labelRect = rect;

// get offset rect
var labelRect = GetLabelRect( rect );

// draw label
Widgets.Label( labelRect, def.workType.labelShort.Truncate( labelRect.width, TruncationCache ) );

// get bottom center of label
var start = new Vector2( labelRect.center.x, labelRect.yMax );
var length = rect.yMax - start.y;

// make sure we're not at a whole pixel
if ( start.x - (int) start.x < 1e-4 )
start.x += .5f;

// draw the lines - two separate lines give a clearer edge than one 2px line...
GUI.color = new Color( 1f, 1f, 1f, 0.3f );
Widgets.DrawLineVertical( Mathf.FloorToInt( start.x ), start.y, length );
Widgets.DrawLineVertical( Mathf.CeilToInt( start.x ), start.y, length );
GUI.color = Color.white;
if ( Settings.verticalLabels )
DrawVerticalHeader( rect, table );
else
DrawHorizontalHeader( rect, table, out labelRect );

// handle interactions (click + scroll)
HeaderInteractions( labelRect, table );
Expand All @@ -212,6 +198,38 @@ public override void DoHeader( Rect rect, PawnTable table )
}
}

public void DrawVerticalHeader( Rect rect, PawnTable table )
{
GUI.color = new Color(.8f, .8f, .8f);
Text.Anchor = TextAnchor.MiddleLeft;
DrawUtilities.VerticalLabel(rect, def.workType.labelShort.Truncate(rect.height, VerticalTruncationCache));
Text.Anchor = TextAnchor.UpperLeft;
GUI.color = Color.white;
}

public void DrawHorizontalHeader( Rect rect, PawnTable table, out Rect labelRect )
{
// get offset rect
labelRect = GetLabelRect(rect);

// draw label
Widgets.Label(labelRect, def.workType.labelShort.Truncate(labelRect.width, TruncationCache));

// get bottom center of label
var start = new Vector2(labelRect.center.x, labelRect.yMax);
var length = rect.yMax - start.y;

// make sure we're not at a whole pixel
if (start.x - (int)start.x < 1e-4)
start.x += .5f;

// draw the lines - two separate lines give a clearer edge than one 2px line...
GUI.color = new Color(1f, 1f, 1f, 0.3f);
Widgets.DrawLineVertical(Mathf.FloorToInt(start.x), start.y, length);
Widgets.DrawLineVertical(Mathf.CeilToInt(start.x), start.y, length);
GUI.color = Color.white;
}

public override int Compare( Pawn a, Pawn b )
{
return GetValueToCompare( a ).CompareTo( GetValueToCompare( b ) );
Expand Down Expand Up @@ -271,7 +289,7 @@ public Vector2 LabelSize
}
}

public override int GetMinHeaderHeight( PawnTable table ) { return HeaderHeight; }
public override int GetMinHeaderHeight( PawnTable table ) { return Settings.verticalLabels ? VerticalHeaderHeight : HorizontalHeaderHeight; }

private Rect GetLabelRect( Rect headerRect )
{
Expand Down
4 changes: 2 additions & 2 deletions Source/PawnTable/MainTabWindow_WorkTab.cs
Expand Up @@ -77,8 +77,8 @@ public override void PostOpen()

public PawnTable Table
{
get { return _tableFieldInfo.GetValue(this) as PawnTable; }
private set { _tableFieldInfo.SetValue(this, value); }
get => _tableFieldInfo.GetValue(this) as PawnTable;
private set => _tableFieldInfo.SetValue(this, value);
}

public static void RebuildTable()
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("18.0.0.5")]
[assembly: AssemblyFileVersion("18.0.0.5")]
[assembly: AssemblyVersion("18.0.0.25")]
[assembly: AssemblyFileVersion("18.0.0.25")]

0 comments on commit 27ccebe

Please sign in to comment.