Skip to content

Commit

Permalink
better readability for tooltips of stats and mutations (closes #1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Nov 6, 2021
1 parent 3f37050 commit 145810b
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions ARKBreedingStats/Pedigree/PedigreeCreature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public partial class PedigreeCreature : UserControl, IPedigreeCreature
public event Action RecalculateBreedingPlan;

private readonly List<Label> _labels;
private readonly ToolTip _ttMonospaced;
private readonly ToolTip _tt;
public int comboId;
/// <summary>
Expand Down Expand Up @@ -70,18 +71,46 @@ public partial class PedigreeCreature : UserControl, IPedigreeCreature
public PedigreeCreature()
{
InitializeComponent();

_tt = new ToolTip
{
InitialDelay = 100
InitialDelay = 100,
AutoPopDelay = 15000
};
_ttMonospaced = new ToolTip
{
InitialDelay = 100,
AutoPopDelay = 15000
};
_ttMonospaced.OwnerDraw = true;
// set to monospaced font for better digit alignment
_tooltipFont = new Font("Consolas", 12);
_ttMonospaced.Draw += TtMonospacedDraw;
_ttMonospaced.Popup += TtMonospacedPopup;
_tt.SetToolTip(labelSex, "Sex");
_tt.SetToolTip(labelMutations, "Mutation-Counter");
_ttMonospaced.SetToolTip(labelMutations, "Mutation-Counter");
_labels = new List<Label> { labelHP, labelSt, labelOx, labelFo, labelWe, labelDm, labelSp, labelCr };
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
Disposed += PedigreeCreature_Disposed;
comboId = -1;
}

#region Tooltip font

private readonly Font _tooltipFont;

private void TtMonospacedPopup(object sender, PopupEventArgs e)
{
e.ToolTipSize = TextRenderer.MeasureText(_ttMonospaced.GetToolTip(e.AssociatedControl), _tooltipFont);
}

private void TtMonospacedDraw(object sender, DrawToolTipEventArgs e)
{
e.DrawBackground();
e.DrawBorder();
e.Graphics.DrawString(e.ToolTipText, _tooltipFont, Brushes.Black, 0, 0);
}

public PedigreeCreature(Creature creature, bool[] enabledColorRegions, int comboId = -1, bool displayPedigreeLink = false) : this()
{
Cursor = Cursors.Hand;
Expand All @@ -91,6 +120,8 @@ public PedigreeCreature(Creature creature, bool[] enabledColorRegions, int combo
TsMiViewInPedigree.Visible = displayPedigreeLink;
}

#endregion

/// <summary>
/// Set text of labels for stats. Only used for header control.
/// </summary>
Expand All @@ -99,14 +130,16 @@ public void SetCustomStatNames(Dictionary<string, string> customStatNames = null
for (int s = 0; s < DisplayedStatsCount; s++)
{
_labels[s].Text = Utils.StatName(DisplayedStats[s], true, customStatNames);
_tt.SetToolTip(_labels[s], Utils.StatName(DisplayedStats[s], customStatNames: customStatNames));
_ttMonospaced.SetToolTip(_labels[s], Utils.StatName(DisplayedStats[s], customStatNames: customStatNames));
}

labelMutations.Visible = true;
}

private void PedigreeCreature_Disposed(object sender, EventArgs e)
{
_ttMonospaced.RemoveAll();
_ttMonospaced.Dispose();
_tt.RemoveAll();
_tt.Dispose();
}
Expand Down Expand Up @@ -175,7 +208,9 @@ public Creature Creature
_labels[s].Text = "0";
_labels[s].BackColor = Color.WhiteSmoke;
_labels[s].ForeColor = Color.LightGray;
_tt.SetToolTip(_labels[s], Utils.StatName(si, false, _creature.Species?.statNames) + ": " + _creature.valuesBreeding[si] * (Utils.Precision(si) == 3 ? 100 : 1) + (Utils.Precision(si) == 3 ? "%" : string.Empty));
_ttMonospaced.SetToolTip(_labels[s], Utils.StatName(si, false, _creature.Species?.statNames) + ": "
+ $"{_creature.valuesBreeding[si] * (Utils.Precision(si) == 3 ? 100 : 1),7:#,0.0}"
+ (Utils.Precision(si) == 3 ? "%" : string.Empty));
}
else
{
Expand All @@ -199,7 +234,9 @@ public Creature Creature
else
_labels[s].BackColor = Utils.GetColorFromPercent((int)(_creature.levelsWild[si] * 2.5), _creature.topBreedingStats[si] ? 0.2 : 0.7);
_labels[s].ForeColor = Parent?.ForeColor ?? Color.Black; // needed so text is not transparent on overlay
_tt.SetToolTip(_labels[s], Utils.StatName(si, false, _creature.Species?.statNames) + ": " + _creature.valuesBreeding[si] * (Utils.Precision(si) == 3 ? 100 : 1) + (Utils.Precision(si) == 3 ? "%" : string.Empty));
_ttMonospaced.SetToolTip(_labels[s], Utils.StatName(si, false, _creature.Species?.statNames) + ": "
+ $"{_creature.valuesBreeding[si] * (Utils.Precision(si) == 3 ? 100 : 1),7:#,0.0}"
+ (Utils.Precision(si) == 3 ? "%" : string.Empty));
}
// fonts are strange, and this seems to work. The assigned font-object is probably only used to read out the properties and then not used anymore.
using (var font = new Font("Microsoft Sans Serif", 8.25F, (_creature.topBreedingStats?[si]).GetValueOrDefault() ? FontStyle.Bold : FontStyle.Regular, GraphicsUnit.Point, 0))
Expand All @@ -225,10 +262,11 @@ public Creature Creature
int totalMutations = _creature.Mutations;
if (totalMutations > 0)
{
labelMutations.Text = totalMutations > 9999 ? totalMutations.ToString().Substring(0, 4) + "…" : totalMutations.ToString();
var totalMutationsString = totalMutations.ToString();
labelMutations.Text = totalMutationsString.Length > 4 ? totalMutationsString.Substring(0, 4) + "…" : totalMutationsString;
labelMutations.BackColor = totalMutations < GameConstants.MutationPossibleWithLessThan ? Utils.MutationColor : Utils.MutationColorOverLimit;
_tt.SetToolTip(labelMutations,
$"Mutation-Counter: {totalMutations}\nMaternal: {_creature.mutationsMaternal}\nPaternal: {_creature.mutationsPaternal}");
_ttMonospaced.SetToolTip(labelMutations,
$"Mutation-Counter: {totalMutations,13:#,0}\nMaternal: {_creature.mutationsMaternal,21:#,0}\nPaternal: {_creature.mutationsPaternal,21:#,0}");
}
labelMutations.Visible = totalMutations > 0;
_contextMenuAvailable = true;
Expand Down

0 comments on commit 145810b

Please sign in to comment.