Skip to content

Commit

Permalink
fix disease tooltips (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
FluffierThanThou committed Jul 27, 2021
1 parent e614724 commit fa04cfc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
Binary file modified Assemblies/DynamicPawnTable.dll
Binary file not shown.
Binary file modified Assemblies/MedicalInfo.dll
Binary file not shown.
Binary file modified Assemblies/MedicalInfo.pdb
Binary file not shown.
79 changes: 39 additions & 40 deletions Source/MedicalInfo/ColumnWorkers/PawnColumnWorker_Diseases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,91 +14,90 @@ namespace Fluffy
{
public class PawnColumnWorker_Diseases : PawnColumnWorker
{
private static readonly MethodInfo _getTooltipMethodInfo;

static PawnColumnWorker_Diseases()
public override int Compare(Pawn a, Pawn b)
{
_getTooltipMethodInfo =
typeof( HealthCardUtility ).GetMethod( "GetTooltip", BindingFlags.NonPublic | BindingFlags.Static );
if ( _getTooltipMethodInfo == null )
throw new MissingMethodException( "HealthCardUtility.GetTooltip not found" );
return GetValueToCompareTo(a).CompareTo(GetValueToCompareTo(b));
}

public override int Compare( Pawn a, Pawn b )
{
return GetValueToCompareTo( a ).CompareTo( GetValueToCompareTo( b ) );
}

public override void DoCell( Rect rect, Pawn pawn, PawnTable table )
public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
{
var diseases = pawn.GetPotentiallyLethalHediffs();
var diseaseRect = new Rect( rect.xMin - Constants.IconSize / 2f,
rect.yMin + ( rect.height - Constants.IconSize ) / 2f,
Constants.IconSize, Constants.IconSize );
var diseaseRect = new Rect(rect.xMin - Constants.IconSize / 2f,
rect.yMin + (rect.height - Constants.IconSize) / 2f,
Constants.IconSize, Constants.IconSize);
var n = diseases.Count();
foreach ( var disease in diseases )
foreach (var disease in diseases)
{
diseaseRect.x += Constants.StatColumnMinWidth / ( n + 1 );
DrawDiseaseIndicator( diseaseRect, (CapacityUtility.DiseaseProgress) disease );
diseaseRect.x += Constants.StatColumnMinWidth / (n + 1);
DrawDiseaseIndicator(diseaseRect, (CapacityUtility.DiseaseProgress)disease);
}

TooltipHandler.TipRegion( rect, () => GetTooltip( pawn, diseases ), pawn.GetHashCode() );
TooltipHandler.TipRegion(rect, () => GetTooltip(pawn, diseases), pawn.GetHashCode());
}

private string GetTooltip( Pawn pawn, IEnumerable<Hediff> diseases )
private string GetTooltip(Pawn pawn, IEnumerable<Hediff> diseases)
{
var tip = "";
foreach ( var set in diseases.GroupBy( k => k.Part ) )
tip += GetDiseaseTooltip( pawn, set, set.Key ) + "\n\n";
foreach (var set in diseases.GroupBy(k => k.Part))
tip += GetDiseaseTooltip(pawn, set, set.Key) + "\n\n";
return tip;
}

public override void DoHeader( Rect rect, PawnTable table )
public override void DoHeader(Rect rect, PawnTable table)
{
def.headerIconSize = new Vector2( Constants.HeaderIconSize, Constants.HeaderIconSize );
base.DoHeader( rect, table );
def.headerIconSize = new Vector2(Constants.HeaderIconSize, Constants.HeaderIconSize);
base.DoHeader(rect, table);
}

public void DrawDiseaseIndicator( Rect rect, CapacityUtility.DiseaseProgress disease )
public void DrawDiseaseIndicator(Rect rect, CapacityUtility.DiseaseProgress disease)
{
// draw immunity
if ( disease.immunity > 0 )
if (disease.immunity > 0)
{
var immunityRect = rect.ContractedBy( Mathf.Lerp( rect.width / 2f, 0f, disease.immunity ) );
GUI.color = new Color( 1f, 1f, 1f, Mathf.Lerp( .5f, 1f, disease.immunity ) );
GUI.DrawTexture( immunityRect, Resources.Circle );
var immunityRect = rect.ContractedBy(Mathf.Lerp(rect.width / 2f, 0f, disease.immunity));
GUI.color = new Color(1f, 1f, 1f, Mathf.Lerp(.5f, 1f, disease.immunity));
GUI.DrawTexture(immunityRect, Resources.Circle);
}

// draw disease progress
var diseaseProgressRect = rect.ContractedBy( Mathf.Lerp( rect.width / 2f, 0f, disease.severity ) );
var diseaseProgressRect = rect.ContractedBy(Mathf.Lerp(rect.width / 2f, 0f, disease.severity));
GUI.color = disease.color;
GUI.DrawTexture( diseaseProgressRect, Resources.Circle );
GUI.DrawTexture(diseaseProgressRect, Resources.Circle);
GUI.color = Color.white;

// draw indicator
GUI.color = disease.tended ? Color.white : Color.gray;
GUI.DrawTexture( rect, Resources.DashCircle );
GUI.DrawTexture(rect, Resources.DashCircle);
}

public string GetDiseaseTooltip( Pawn pawn, IEnumerable<Hediff> diffs, BodyPartRecord part )
public string GetDiseaseTooltip(Pawn pawn, IEnumerable<Hediff> diffs, BodyPartRecord part)
{
return _getTooltipMethodInfo.Invoke( null, new object[] {diffs, pawn, part} ) as string;
var tips = diffs.Select(diff => diff.GetTooltip(pawn, false));
if (part != null)
{
return $"{part.LabelCap}:\n{string.Join("\n", tips)}";
}
else
{
return string.Join("\n", tips);
}
}

public override int GetMinWidth( PawnTable table )
public override int GetMinWidth(PawnTable table)
{
return Constants.StatColumnMinWidth;
}

public float GetValueToCompareTo( Pawn pawn )
public float GetValueToCompareTo(Pawn pawn)
{
var diseases = pawn.GetDiseases()
.Select( d => (CapacityUtility.DiseaseProgress) d )
.Select(d => (CapacityUtility.DiseaseProgress)d)
.ToList();
if ( !diseases.Any() )
if (!diseases.Any())
return -1;

return diseases.Max( d => d.severity - d.immunity );
return diseases.Max(d => d.severity - d.immunity);
}
}
}
11 changes: 10 additions & 1 deletion modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"version": {
"major": 4,
"minor": 2,
"build": 101
"build": 105
},
"author": {
"name": "Fluffy",
Expand All @@ -19,6 +19,15 @@
"url": "https://github.com/fluffy-mods/MedicalTab"
},
"changelog": [
{
"date": "2021-07-27T22:25:10.000Z",
"message": "fully move to sdk project, update refs",
"author": {
"name": "Fluffy",
"email": "fluffy.l2032@gmail.com"
},
"hash": "e614724510822a19b3b2c21aff0fee7f89398855"
},
{
"date": "2021-07-22T17:26:18.000Z",
"message": "release v4.2.99",
Expand Down

0 comments on commit fa04cfc

Please sign in to comment.