Skip to content

Commit

Permalink
Added a simple experience bar widget
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldiedema committed Jul 1, 2024
1 parent f7851b7 commit 3606429
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Umbra/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@
"Widget.Durability.Spiritbond": "Geistesbund",
"Widget.Durability.Popup.Equipment": "Ausrüstung (Haltbarkeit% / Geistesbund%)",
"Widget.Durability.Popup.Actions": "Aktionen",
"Widget.ExperienceBar.Name": "Erfahrungsleiste",
"Widget.ExperienceBar.Description": "Zeigt den aktuellen Prozentsatz der Erfahrungspunkte und visualisiert den Fortschritt zum nächsten Level.",
"Widget.Location.Name": "Ort",
"Widget.Location.Description": "Zeigt die aktuelle Karte und den Bereichsnamen an.",
"Widget.Location.Config.Decorate.Name": "Widget dekorieren",
Expand Down
2 changes: 2 additions & 0 deletions Umbra/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@
"Widget.Durability.Spiritbond": "Spiritbond",
"Widget.Durability.Popup.Equipment": "Equipment (Durability% / Spiritbond%)",
"Widget.Durability.Popup.Actions": "Actions",
"Widget.ExperienceBar.Name": "Experience Bar",
"Widget.ExperienceBar.Description": "Shows your current experience points percentage and visualizes the progress towards the next level.",
"Widget.Location.Name": "Location",
"Widget.Location.Description": "Displays the current map and area name.",
"Widget.Location.Config.Decorate.Name": "Decorate the widget",
Expand Down
2 changes: 2 additions & 0 deletions Umbra/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@
"Widget.Durability.Spiritbond": "Lien spirituel",
"Widget.Durability.Popup.Equipment": "Équipement (Durabilité% / Lien spirituel%)",
"Widget.Durability.Popup.Actions": "Actions",
"Widget.ExperienceBar.Name": "Barre d'expérience",
"Widget.ExperienceBar.Description": "Affiche le pourcentage de vos points d'expérience actuels et visualise la progression vers le niveau suivant.",
"Widget.Location.Name": "Emplacement",
"Widget.Location.Description": "Affiche la carte actuelle et le nom de la zone.",
"Widget.Location.Config.Decorate.Name": "Décorer le widget",
Expand Down
2 changes: 2 additions & 0 deletions Umbra/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@
"Widget.Durability.Spiritbond": "スピリットボンド",
"Widget.Durability.Popup.Equipment": "装備(耐久性% / スピリットボンド%)",
"Widget.Durability.Popup.Actions": "アクション",
"Widget.ExperienceBar.Name": "経験値バー",
"Widget.ExperienceBar.Description": "現在の経験値のパーセンテージを表示し、次のレベルへの進捗を視覚化します。",
"Widget.Location.Name": "場所",
"Widget.Location.Description": "現在の地図とエリア名を表示します。",
"Widget.Location.Config.Decorate.Name": "ウィジェットを装飾する",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Umbra | (c) 2024 by Una ____ ___ ___.
* Licensed under the terms of AGPL-3 | | \ _____ \_ |__ _______ _____
* | | // \ | __ \\_ __ \\__ \
* https://github.com/una-xiv/umbra | | /| Y Y \| \_\ \| | \/ / __ \_
* |______//__|_| /____ /|__| (____ /
* Umbra is free software: you can redistribute \/ \/ \/
* it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Umbra UI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/

using System.Collections.Generic;

namespace Umbra.Widgets;

internal partial class ExperienceBarWidget
{
protected override IEnumerable<IWidgetConfigVariable> GetConfigVariables()
{
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Umbra | (c) 2024 by Una ____ ___ ___.
* Licensed under the terms of AGPL-3 | | \ _____ \_ |__ _______ _____
* | | // \ | __ \\_ __ \\__ \
* https://github.com/una-xiv/umbra | | /| Y Y \| \_\ \| | \/ / __ \_
* |______//__|_| /____ /|__| (____ /
* Umbra is free software: you can redistribute \/ \/ \/
* it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Umbra UI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/

using Una.Drawing;

namespace Umbra.Widgets;

internal partial class ExperienceBarWidget
{
public override Node Node { get; } = new() {
Stylesheet = Stylesheet,
ClassList = ["experience-bar"],
ChildNodes = [
new() {
ClassList = ["bar"]
},
new() {
ClassList = ["label"],
},
]
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* Umbra | (c) 2024 by Una ____ ___ ___.
* Licensed under the terms of AGPL-3 | | \ _____ \_ |__ _______ _____
* | | // \ | __ \\_ __ \\__ \
* https://github.com/una-xiv/umbra | | /| Y Y \| \_\ \| | \/ / __ \_
* |______//__|_| /____ /|__| (____ /
* Umbra is free software: you can redistribute \/ \/ \/
* it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Umbra UI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/

using Una.Drawing;

namespace Umbra.Widgets;

internal partial class ExperienceBarWidget : ToolbarWidget
{
private static Stylesheet Stylesheet { get; } = new(
[
new(
".experience-bar",
new() {
Flow = Flow.Horizontal,
Anchor = Anchor.MiddleLeft,
Size = new(100, SafeHeight),
BackgroundColor = new("Widget.Background"),
StrokeColor = new("Widget.Border"),
StrokeWidth = 1,
StrokeInset = 1,
BorderRadius = 5,
IsAntialiased = false,
}
),
new(
".label",
new() {
Anchor = Anchor.TopLeft,
TextAlign = Anchor.MiddleCenter,
Color = new("Widget.Text"),
OutlineColor = new("Widget.TextOutline"),
OutlineSize = 1,
Size = new(100, SafeHeight),
TextOffset = new(0, 1)
}
),
new(
".bar",
new() {
Anchor = Anchor.MiddleLeft,
Size = new(50, SafeHeight - 8),
Margin = new(4),
BorderRadius = 4,
BackgroundColor = new("Window.AccentColor"),
IsAntialiased = false,
}
)
]
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Umbra | (c) 2024 by Una ____ ___ ___.
* Licensed under the terms of AGPL-3 | | \ _____ \_ |__ _______ _____
* | | // \ | __ \\_ __ \\__ \
* https://github.com/una-xiv/umbra | | /| Y Y \| \_\ \| | \/ / __ \_
* |______//__|_| /____ /|__| (____ /
* Umbra is free software: you can redistribute \/ \/ \/
* it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Umbra UI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/

using System.Collections.Generic;
using Umbra.Common;
using Umbra.Game;

namespace Umbra.Widgets;

[ToolbarWidget("ExperienceBar", "Widget.ExperienceBar.Name", "Widget.ExperienceBar.Description")]
internal partial class ExperienceBarWidget(
WidgetInfo info,
string? guid = null,
Dictionary<string, object>? configValues = null
) : ToolbarWidget(info, guid, configValues)
{
public override WidgetPopup? Popup => null;

private IGearsetRepository GearsetRepository { get; set; } = null!;

/// <inheritdoc/>
protected override void Initialize()
{
GearsetRepository = Framework.Service<IGearsetRepository>();
}

/// <inheritdoc/>
protected override void OnUpdate()
{
var gearset = GearsetRepository.CurrentGearset;

if (gearset == null || gearset.IsMaxLevel) {
Node.Style.IsVisible = false;
return;
}

const int maxWidth = 100 - 8;
int width = (maxWidth * gearset.JobXp / 100);

Node.Style.IsVisible = true;
Node.QuerySelector(".label")!.NodeValue = $"{gearset.JobXp}%";
Node.QuerySelector(".bar")!.Style.Size = new(width, SafeHeight - 8);
}
}

0 comments on commit 3606429

Please sign in to comment.