Skip to content

Commit

Permalink
Rewritten Recalculation code of the NativeStatsPanel
Browse files Browse the repository at this point in the history
Closes #93
  • Loading branch information
justalemon committed Oct 25, 2022
1 parent e3a616e commit dff6030
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
18 changes: 7 additions & 11 deletions LemonUI/Menus/NativeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,19 +853,15 @@ private void TriggerSelectedItem()
/// </summary>
private void RecalculatePanel()
{
// If the selected item has a panel
if (SelectedItem?.Panel != null)
if (SelectedItem?.Panel == null)
{
// Save the Y value of the description
float y = descriptionRect.Position.Y;
// If it has text, show it after the description instead of taking it's place
if (!string.IsNullOrWhiteSpace(descriptionText.Text))
{
y += descriptionRect.Size.Height + 10;
}
// Finally, set the position of the panel
SelectedItem.Panel.Recalculate(new PointF(descriptionRect.Position.X, y), Width);
return;
}

const int separation = 10;

PointF position = new PointF(descriptionRect.Position.X, descriptionRect.Position.Y + descriptionRect.Size.Height + separation);
SelectedItem.Panel.Recalculate(position, Width);
}
/// <summary>
/// Resets the current position of the cursor.
Expand Down
26 changes: 17 additions & 9 deletions LemonUI/Menus/NativeStatsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class NativeStatsInfo
{
#region Fields

private const float barWidth = 33;
private const float barHeight = 9;
private readonly ScaledText text = new ScaledText(PointF.Empty, string.Empty, 0.35f);
private float value = 100;
private readonly List<ScaledRectangle> backgrounds = new List<ScaledRectangle>();
Expand Down Expand Up @@ -95,12 +97,12 @@ internal void SetColor(Color background, Color foreground)
/// </summary>
private void UpdateBars()
{
SizeF @default = new SizeF(35, 9);
SizeF @default = new SizeF(barWidth, barHeight);

// FIRST BAR
if (value > 0 && value < 20)
{
foregrounds[0].Size = new SizeF(@default.Width * (value / 20), @default.Height);
foregrounds[0].Size = new SizeF(barWidth * (value / 20), barHeight);
}
else
{
Expand All @@ -110,7 +112,7 @@ private void UpdateBars()
// SECOND BAR
if (value > 20 && value < 40)
{
foregrounds[1].Size = new SizeF(@default.Width * ((value - 20) / 20), @default.Height);
foregrounds[1].Size = new SizeF(barWidth * ((value - 20) / 20), barHeight);
}
else
{
Expand All @@ -120,7 +122,7 @@ private void UpdateBars()
// THIRD BAR
if (value > 40 && value < 60)
{
foregrounds[2].Size = new SizeF(@default.Width * ((value - 40) / 20), @default.Height);
foregrounds[2].Size = new SizeF(barWidth * ((value - 40) / 20), barHeight);
}
else
{
Expand All @@ -130,7 +132,7 @@ private void UpdateBars()
// FOURTH BAR
if (value > 60 && value < 80)
{
foregrounds[3].Size = new SizeF(@default.Width * ((value - 60) / 20), @default.Height);
foregrounds[3].Size = new SizeF(barWidth * ((value - 60) / 20), barHeight);
}
else
{
Expand All @@ -140,7 +142,7 @@ private void UpdateBars()
// FIFTH BAR
if (value > 80 && value < 100)
{
foregrounds[4].Size = new SizeF(@default.Width * ((value - 80) / 20), @default.Height);
foregrounds[4].Size = new SizeF(barWidth * ((value - 80) / 20), barHeight);
}
else
{
Expand All @@ -154,13 +156,19 @@ private void UpdateBars()
/// <param name="width">The Width of the parent Stats Panel.</param>
public void Recalculate(PointF position, float width)
{
text.Position = new PointF(position.X, position.Y);
const float barOffsetTop = 11;
const float offsetLeft = 9;
const float separatorSize = 4;
const float rightMargin = 42;

text.Position = new PointF(position.X + offsetLeft, position.Y);

for (int i = 0; i < 5; i++)
{
PointF pos = new PointF(position.X + width - 234 + ((35 + 3) * i), position.Y + 10);
PointF pos = new PointF(position.X + width - rightMargin - (barWidth * (5 - i)) - (separatorSize * (5 - i)), position.Y + barOffsetTop);

backgrounds[i].Position = pos;
backgrounds[i].Size = new SizeF(35, 9);
backgrounds[i].Size = new SizeF(barWidth, barHeight);
foregrounds[i].Position = pos;
}

Expand Down
9 changes: 6 additions & 3 deletions LemonUI/Menus/NativeStatsPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using LemonUI.Elements;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -147,11 +146,15 @@ public override void Recalculate(PointF position, float width)
{
base.Recalculate(position, width);

Background.Size = new SizeF(width, (fields.Count * 38) + 9);
const float differenceTop = 7;
const float perStatSeparation = 38;

Background.Size = new SizeF(width, differenceTop + (perStatSeparation * fields.Count));

for (int i = 0; i < fields.Count; i++)
{
fields[i].Recalculate(new PointF(position.X + 9, position.Y + 9 + (38 * i)), width);
PointF fieldPosition = new PointF(position.X, position.Y + differenceTop + (perStatSeparation * i));
fields[i].Recalculate(fieldPosition, width);
}
}
/// <summary>
Expand Down

0 comments on commit dff6030

Please sign in to comment.