Skip to content

Commit

Permalink
Add 'revert to default value' buttons to CVAR settings
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldiedema committed Aug 22, 2024
1 parent 81c46a1 commit 02b0497
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
1 change: 1 addition & 0 deletions Umbra/i18n/de.json

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

1 change: 1 addition & 0 deletions Umbra/i18n/en.json

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

1 change: 1 addition & 0 deletions Umbra/i18n/fr.json

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

1 change: 1 addition & 0 deletions Umbra/i18n/ja.json

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

1 change: 1 addition & 0 deletions Umbra/i18n/zh.json

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

53 changes: 48 additions & 5 deletions Umbra/src/Windows/Library/Settings/Modules/CvarModule.Controls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* GNU Affero General Public License for more details.
*/

using System.Collections.Generic;
using Dalamud.Interface;
using Umbra.Common;
using Umbra.Windows.Components;
using Una.Drawing;
Expand All @@ -36,7 +36,7 @@ internal partial class CvarModule
node.ClassList.Add("cvar");
node.OnValueChanged += value => ConfigManager.Set(cvar.Id, value);

return node;
return CreateNode(cvar, node);
}

if (cvar.Options is not null && cvar.Options.Count > 0 && cvar.Default is string) {
Expand All @@ -51,7 +51,7 @@ internal partial class CvarModule
node.ClassList.Add("cvar");
node.OnValueChanged += value => ConfigManager.Set(cvar.Id, value);

return node;
return CreateNode(cvar, node);
}

if (cvar is { Default: int, Min: not null, Max: not null }) {
Expand All @@ -67,7 +67,7 @@ internal partial class CvarModule
node.ClassList.Add("cvar");
node.OnValueChanged += value => ConfigManager.Set(cvar.Id, value);

return node;
return CreateNode(cvar, node);
}

if (cvar is { Default: float, Min: not null, Max: not null }) {
Expand All @@ -83,9 +83,52 @@ internal partial class CvarModule
node.ClassList.Add("cvar");
node.OnValueChanged += value => ConfigManager.Set(cvar.Id, value);

return node;
return CreateNode(cvar, node);
}

return null;
}

private Node CreateNode(Cvar cvar, Node controlNode)
{
ButtonNode resetNode = new(
"Reset",
null,
FontAwesomeIcon.History,
true
) {
Style = new() {
Anchor = Anchor.TopRight,
Margin = new() { Top = -4 },
},
Tooltip = I18N.Translate("Revert")
};

Node node = new() {
ClassList = ["cvar-control-node"],
ChildNodes = [controlNode, resetNode],
Style = new() {
Flow = Flow.Horizontal,
Size = new(500, 0),
Gap = 8,
}
};

var c = cvar;

resetNode.OnClick += _ => {
ConfigManager.Set(c.Id, c.Default);

if (controlNode is CheckboxNode n) n.Value = (bool)c.Default!;
if (controlNode is SelectNode s) s.Value = (string)c.Default!;
if (controlNode is IntegerInputNode i) i.Value = (int)c.Default!;
if (controlNode is FloatInputNode f) f.Value = (float)c.Default!;
};

resetNode.BeforeDraw += _ => {
resetNode.Style.IsVisible = c.Value is not null && !c.Value.Equals(c.Default);
};

return node;
}
}
8 changes: 6 additions & 2 deletions Umbra/src/Windows/Library/Settings/Modules/CvarModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ public override void OnUpdate()

Node.QuerySelector(".cvar-header")!.Style.Size = new(size.Width - 30, 0);

foreach (var cvarNode in Node.QuerySelectorAll(".cvar-list > .cvar, .cvar-subcategory")) {
foreach (var cvarNode in Node.QuerySelectorAll(" .cvar-subcategory")) {
cvarNode.Style.Size = new(size.Width - 30, 0);
}

foreach (var cvarNode in Node.QuerySelectorAll(".cvar-subcategory > .cvar-list > .cvar")) {
foreach (var cvarNode in Node.QuerySelectorAll(".cvar-control-node")) {
cvarNode.Style.Size = new(size.Width - 45, 0);
}

foreach (var cvarNode in Node.QuerySelectorAll(".cvar")) {
cvarNode.Style.Size = new(size.Width - 80, 0);
}
}

private List<Node> GetCvarNodeList(List<Cvar> cvars)
Expand Down

0 comments on commit 02b0497

Please sign in to comment.