Skip to content

Commit

Permalink
Fix World Name widget always being visible
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldiedema committed Aug 13, 2024
1 parent 4add54f commit 13fee8d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 117 deletions.
10 changes: 0 additions & 10 deletions Umbra/i18n/de.json

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

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

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

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

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

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

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

10 changes: 0 additions & 10 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 @@ -30,36 +30,8 @@ protected override IEnumerable<IWidgetConfigVariable> GetConfigVariables()
I18N.Translate("Widget.WorldName.Config.HideOnHomeWorld.Description"),
false
),
new BooleanWidgetConfigVariable(
"Decorate",
I18N.Translate("Widget.WorldName.Config.Decorate.Name"),
I18N.Translate("Widget.WorldName.Config.Decorate.Description"),
true
) { Category = I18N.Translate("Widget.ConfigCategory.WidgetAppearance") },
new BooleanWidgetConfigVariable(
"ShowIcon",
I18N.Translate("Widget.WorldName.Config.ShowIcon.Name"),
I18N.Translate("Widget.WorldName.Config.ShowIcon.Description"),
true
) { Category = I18N.Translate("Widget.ConfigCategory.WidgetAppearance") },
new SelectWidgetConfigVariable(
"IconLocation",
I18N.Translate("Widget.WorldName.Config.IconLocation.Name"),
I18N.Translate("Widget.WorldName.Config.IconLocation.Description"),
"Left",
new() {
{ "Left", I18N.Translate("Widget.WorldName.Config.IconLocation.Option.Left") },
{ "Right", I18N.Translate("Widget.WorldName.Config.IconLocation.Option.Right") },
}
) { Category = I18N.Translate("Widget.ConfigCategory.WidgetAppearance") },
new IntegerWidgetConfigVariable(
"TextYOffset",
I18N.Translate("Widget.WorldName.Config.TextYOffset.Name"),
I18N.Translate("Widget.WorldName.Config.TextYOffset.Description"),
0,
-5,
5
) { Category = I18N.Translate("Widget.ConfigCategory.WidgetAppearance") },
..DefaultToolbarWidgetConfigVariables,
..SingleLabelTextOffsetVariables,
];
}
}
57 changes: 20 additions & 37 deletions Umbra/src/Toolbar/Widgets/Library/WorldName/WorldNameWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ internal partial class WorldNameWidget(
/// <inheritdoc/>
public override WidgetPopup? Popup => null;

private IPlayer? _player;
private string? _currentWorldName;
private bool? _hideOnHomeWorld;
private bool? _decorate;
private int? _textYOffset;
private bool? _showIcon;
private string? _iconLocation;
private IPlayer _player = Framework.Service<IPlayer>();

/// <inheritdoc/>
protected override void Initialize()
Expand All @@ -48,43 +42,32 @@ protected override void Initialize()
/// <inheritdoc/>
protected override void OnUpdate()
{
var hideOnHomeWorld = GetConfigValue<bool>("HideOnHomeWorld");
var decorate = GetConfigValue<bool>("Decorate");
var textYOffset = GetConfigValue<int>("TextYOffset");
var showIcon = GetConfigValue<bool>("ShowIcon");
var iconLocation = GetConfigValue<string>("IconLocation");
var hideOnHomeWorld = GetConfigValue<bool>("HideOnHomeWorld");
var decorate = GetConfigValue<bool>("Decorate");
var textYOffset = GetConfigValue<int>("TextYOffset");
var iconLocation = GetConfigValue<string>("IconLocation");
bool showIcon = GetConfigValue<string>("DisplayMode") != "TextOnly";
bool isVisible = !hideOnHomeWorld || _player.CurrentWorldName != _player.HomeWorldName;

if (hideOnHomeWorld == _hideOnHomeWorld
&& decorate == _decorate
&& textYOffset == _textYOffset
&& showIcon == _showIcon
&& iconLocation == _iconLocation
&& _currentWorldName == _player?.CurrentWorldName)
return;
Node.Style.IsVisible = isVisible;

_hideOnHomeWorld = hideOnHomeWorld;
_decorate = decorate;
_textYOffset = textYOffset;
_showIcon = showIcon;
_iconLocation = iconLocation;
_currentWorldName = _player?.CurrentWorldName;
if (isVisible) {
SeStringBuilder str = new SeStringBuilder();

Node.Style.IsVisible = !hideOnHomeWorld || _currentWorldName != _player?.HomeWorldName;
if (iconLocation == "Left" && showIcon && _player.CurrentWorldName != _player.HomeWorldName) {
str.AddIcon(BitmapFontIcon.CrossWorld);
}

SeStringBuilder str = new SeStringBuilder();
str.AddText(_player.CurrentWorldName);

if (iconLocation == "Left" && showIcon && _currentWorldName != _player?.HomeWorldName) {
str.AddIcon(BitmapFontIcon.CrossWorld);
}

str.AddText(_currentWorldName ?? "Unknown World");
if (iconLocation == "Right" && showIcon && _player.CurrentWorldName != _player.HomeWorldName) {
str.AddIcon(BitmapFontIcon.CrossWorld);
}

if (iconLocation == "Right" && showIcon && _currentWorldName != _player?.HomeWorldName) {
str.AddIcon(BitmapFontIcon.CrossWorld);
SetLabel(str.Build());
SetGhost(!decorate);
}

Node.QuerySelector("Label")!.Style.TextOffset = new(0, textYOffset + 1);
SetLabel(str.Build());
SetGhost(!decorate);
base.OnUpdate();
}
}

0 comments on commit 13fee8d

Please sign in to comment.