-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple experience bar widget
- Loading branch information
1 parent
f7851b7
commit 3606429
Showing
8 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Umbra/src/Toolbar/Widgets/Library/ExperienceBar/ExperienceBarWidget.Config.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Umbra/src/Toolbar/Widgets/Library/ExperienceBar/ExperienceBarWidget.Nodes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}, | ||
] | ||
}; | ||
} |
64 changes: 64 additions & 0 deletions
64
Umbra/src/Toolbar/Widgets/Library/ExperienceBar/ExperienceBarWidget.Stylesheet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
) | ||
] | ||
); | ||
} |
57 changes: 57 additions & 0 deletions
57
Umbra/src/Toolbar/Widgets/Library/ExperienceBar/ExperienceBarWidget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |