Skip to content

Commit

Permalink
Update experience bar width & add 2 new colors for exp/rested
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldiedema committed Aug 10, 2024
1 parent 24490d3 commit a91dde1
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Umbra/i18n/de.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Umbra/i18n/en.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Umbra/i18n/fr.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Umbra/i18n/ja.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Umbra/i18n/zh.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ protected override IEnumerable<IWidgetConfigVariable> GetConfigVariables()
I18N.Translate("Widget.ExperienceBar.Config.ShowLevelSyncIcon.Description"),
true
) { Category = I18N.Translate("Widget.ConfigCategory.WidgetAppearance") },
new BooleanWidgetConfigVariable(
"ShowPreciseExperience",
I18N.Translate("Widget.ExperienceBar.Config.ShowPreciseExperience.Name"),
I18N.Translate("Widget.ExperienceBar.Config.ShowPreciseExperience.Description"),
true
) { Category = I18N.Translate("Widget.ConfigCategory.WidgetAppearance") },
new IntegerWidgetConfigVariable(
"WidgetWidth",
I18N.Translate("Widget.ExperienceBar.Config.WidgetWidth.Name"),
I18N.Translate("Widget.ExperienceBar.Config.WidgetWidth.Description"),
100,
25,
30,
500
) { Category = I18N.Translate("Widget.ConfigCategory.WidgetAppearance") },
new IntegerWidgetConfigVariable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal partial class ExperienceBarWidget : ToolbarWidget
Color = new("Widget.Text"),
OutlineColor = new("Widget.TextOutline"),
OutlineSize = 1,
Size = new(150, SafeHeight),
Size = new(0, SafeHeight),
TextOverflow = false,
WordWrap = false,
Padding = new(0, 4),
Expand Down Expand Up @@ -112,15 +112,14 @@ internal partial class ExperienceBarWidget : ToolbarWidget
".bar.normal",
new() {
Anchor = Anchor.MiddleLeft,
BackgroundColor = new("Window.AccentColor"),
BackgroundColor = new("Misc.ExperienceBar"),
}
),
new(
".bar.rested",
new() {
Anchor = Anchor.MiddleLeft,
BackgroundColor = new("Window.AccentColor"),
Opacity = 0.33f,
BackgroundColor = new("Misc.ExperienceBarRested"),
}
),
new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ protected override void OnUpdate()
}

SanctuaryIconNode.Style.IsVisible = GetConfigValue<bool>("ShowSanctuaryIcon") && Player.IsInSanctuary;
SyncIconNode.Style.IsVisible = GetConfigValue<bool>("ShowLevelSyncIcon") && Player.SyncedLevel > 0 && Player.SyncedLevel != Player.Level;

SyncIconNode.Style.IsVisible = GetConfigValue<bool>("ShowLevelSyncIcon")
&& Player.SyncedLevel > 0
&& Player.SyncedLevel != Player.Level;

Node.Style.IsVisible = true;
Node.Tooltip = GetTooltipText();
Expand All @@ -59,6 +62,15 @@ protected override void OnUpdate()

LeftLabelNode.Style.TextOffset = new(0, GetConfigValue<int>("TextYOffset"));
RightLabelNode.Style.TextOffset = new(0, GetConfigValue<int>("TextYOffset"));
RightLabelNode.Style.FontSize = GetConfigValue<bool>("ShowPreciseExperience") ? 11 : 13;

int fullWidth = GetConfigValue<int>("WidgetWidth")
- 12
- ((SyncIconNode.Style.IsVisible ?? true) || (SanctuaryIconNode.Style.IsVisible ?? true) ? 20 : 0);

int leftWidth = LeftLabelNode.InnerWidth;

RightLabelNode.Style.Size = new(fullWidth - (int)(leftWidth / Una.Drawing.Node.ScaleFactor) - 4, SafeHeight);

UpdateVisualBars();
}
Expand All @@ -77,6 +89,10 @@ private string GetExpString()
{
if (!GetConfigValue<bool>("ShowExperience")) return "";

if (GetConfigValue<bool>("ShowPreciseExperience")) {
return GetPreciseExperienceString();
}

var xpPercent = Player.CurrentExperience / (float)Player.TotalRequiredExperience * 100;
return $"{xpPercent:0.0}%";
}
Expand All @@ -90,10 +106,7 @@ private void UpdateVisualBars()
int maxWidth = barWidth - 8;
int normalWidth = (int)(maxWidth * (Player.CurrentExperience / (float)(Player.TotalRequiredExperience)));
uint restedXp = Math.Min(Player.RestedExperience, Player.TotalRequiredExperience);

int restedWidth = Math.Abs(
(int)(maxWidth * (restedXp / (float)(Player.TotalRequiredExperience))) - normalWidth
);
int restedWidth = Math.Min(maxWidth - normalWidth, (int)(maxWidth * (restedXp / (float)(Player.TotalRequiredExperience))));

Node.Style.Size = new(barWidth, SafeHeight);

Expand All @@ -118,14 +131,16 @@ private void UpdateVisualBars()

private string? GetTooltipText()
{
if (Player.IsMaxLevel) return null;
return Player.IsMaxLevel ? null : $"{I18N.Translate("Experience")}: {GetPreciseExperienceString()}";
}

// Add decimals to the values.
private string GetPreciseExperienceString()
{
string currentXpStr = Player.CurrentExperience.ToString("N0");
string neededXpStr = Player.TotalRequiredExperience.ToString("N0");
string restedXpStr = Player.RestedExperience.ToString("N0");
string restedStr = Player.RestedExperience > 0 ? $" - {I18N.Translate("Rested")}: {restedXpStr}" : "";

return $"{I18N.Translate("Experience")}: {currentXpStr} / {neededXpStr}{restedStr}";
return $"{currentXpStr} / {neededXpStr}{restedStr}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal partial class GearsetNode
new() {
Anchor = Anchor.TopLeft,
Size = new(0, 1),
BackgroundColor = new("Window.AccentColor"),
BackgroundColor = new("Misc.ExperienceBar"),
BorderRadius = 3,
IsAntialiased = false,
}
Expand Down
2 changes: 2 additions & 0 deletions Umbra/src/Umbra.Colors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ public static void RegisterDefaultColors()
Color.AssignByName("Role.MagicalRangedDps", 0xAF2E3069);
Color.AssignByName("Role.Crafter", 0xAFA72A5A);
Color.AssignByName("Role.Gatherer", 0xAF2C89A6);
Color.AssignByName("Misc.ExperienceBar", 0xFF4c8eb9);
Color.AssignByName("Misc.ExperienceBarRested", 0xFFb98e4c);
}

private static void OnConfigProfileChanged(string _)
Expand Down

0 comments on commit a91dde1

Please sign in to comment.