From a8cb1e53af33114eb21583fcfe3b5cb723c3af35 Mon Sep 17 00:00:00 2001 From: Nytra <14206961+Nytra@users.noreply.github.com> Date: Sun, 25 Aug 2024 16:39:16 +0100 Subject: [PATCH] Restore on-demand data feed template injection and make the templates look better by having consistent widths --- .../Settings/ConfigSectionSettingsItems.cs | 16 +++-- .../DataFeeds/Settings/SettingsViewData.cs | 66 +++++-------------- 2 files changed, 27 insertions(+), 55 deletions(-) diff --git a/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ConfigSectionSettingsItems.cs b/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ConfigSectionSettingsItems.cs index 1429688..8d83b79 100644 --- a/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ConfigSectionSettingsItems.cs +++ b/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ConfigSectionSettingsItems.cs @@ -27,10 +27,12 @@ internal sealed class ConfigSectionSettingsItems : DataFeedBuildingBlockMonkey? _currentParameters; public override int Priority => 400; public override IAsyncEnumerable Apply(IAsyncEnumerable current, EnumerateDataFeedParameters parameters) { + _currentParameters = parameters; var path = parameters.Path; if (path.Count is < 2 or > 3 || path[0] is not SettingsHelpers.MonkeyLoader) @@ -255,11 +257,15 @@ private static DataFeedValueField GenerateValueField(IReadOnlyList valueField.InitBase(path, groupKeys, configKey); valueField.InitSetupValue(field => field.SetupConfigKeyField(configKey)); - //var valueType = typeof(T); - //if (valueType != typeof(dummy) && (Coder.IsEnginePrimitive || valueType == typeof(Type))) - //{ - // settingsData.Mapper?.RunSynchronously(() => EnsureDataFeedValueFieldTemplate(settingsData, valueType)); - //} + var valueType = typeof(T); + if (valueType != typeof(dummy) && (Coder.IsEnginePrimitive || valueType == typeof(Type))) + { + if (_currentParameters!.DataFeed is SettingsDataFeed settingsDataFeed) + { + var settingsViewData = SettingsHelpers.GetViewData(_currentParameters!.DataFeed); + settingsViewData.Mapper?.RunSynchronously(() => settingsViewData.EnsureDataFeedValueFieldTemplate(valueType)); + } + } return valueField; } diff --git a/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/SettingsViewData.cs b/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/SettingsViewData.cs index 96541e7..1ee7a3f 100644 --- a/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/SettingsViewData.cs +++ b/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/SettingsViewData.cs @@ -72,20 +72,6 @@ internal SettingsViewData(SettingsDataFeed dataFeed) RootCategoryView = dataFeed.Slot.GetComponent(); - dataFeed.StartTask(async () => - { - while (CoroutineManager.Manager.Value is null) - { - await Task.Delay(1000); - } - foreach (var primitiveType in GetTemplateTypes()) - { - await default(NextUpdate); - EnsureDataFeedValueFieldTemplate(primitiveType); - - } - }); - var settingsListSlot = dataFeed.Slot.FindChild(s => s.Name == "Settings List", maxDepth: 2); if (settingsListSlot is null) return; @@ -111,24 +97,6 @@ internal void MoveUpFromCategory(string category) RootCategoryView.MoveUpInCategory(); } - private static IEnumerable GetTemplateTypes() - { - var nullableType = typeof(Nullable<>); - - foreach (var basePrimitive in GenericTypesAttribute.GetTypes(GenericTypesAttribute.Group.EnginePrimitivesAndEnums)) - { - if (basePrimitive.Name == nameof(dummy)) - continue; - - if (basePrimitive.IsValueType) - yield return nullableType.MakeGenericType(basePrimitive); - - yield return basePrimitive; - } - - yield return typeof(Type); - } - private void CleanupView() { if (!HasRootCategoryView) @@ -140,7 +108,10 @@ private void CleanupView() Logger.Debug(() => "Cached RootCategoryView and subscribed to events."); } - private void EnsureDataFeedValueFieldTemplate(Type typeToInject) + /// + /// Ensures a template exists for the given in this SettingsViewData's + /// + public void EnsureDataFeedValueFieldTemplate(Type typeToInject) { if (!HasMapper) { @@ -188,30 +159,24 @@ private void EnsureDataFeedValueFieldTemplate(Type typeToInject) RadiantUI_Constants.SetupEditorStyle(ui); ui.ForceNext = template.AttachComponent(); - ui.HorizontalLayout(11.78908f, 11.78908f); + ui.HorizontalLayout(11.78908f, 11.78908f).ForceExpandWidth.Value = false; + ui.PushStyle(); + ui.Style.MinWidth = 288f; var text = ui.Text("Label"); + ui.PopStyle(); + text.Size.Value = 24f; text.HorizontalAlign.Value = TextHorizontalAlignment.Left; - ui.Style.MinHeight = 32f; - - ui.Spacer(128f); - Component? component = null; - ISyncMember? member = null; - FieldInfo? fieldInfo = null; + Component component; + ISyncMember member; + FieldInfo fieldInfo; if (typeToInject == typeof(Type)) { - component = template.AttachComponent(typeof(TypeField)); - member = component.GetSyncMember("Type"); - - if (member == null) - { - Logger.Error(() => "Could not get Type sync member from attached TypeField component!"); - return; - } - + component = template.AttachComponent(); + member = ((TypeField)component).Type; fieldInfo = component.GetSyncMemberFieldInfo("Type"); } else @@ -228,9 +193,10 @@ private void EnsureDataFeedValueFieldTemplate(Type typeToInject) fieldInfo = component.GetSyncMemberFieldInfo("Value"); } + ui.PushStyle(); ui.Style.FlexibleWidth = 1f; SyncMemberEditorBuilder.Build(member, null, fieldInfo, ui, 0f); - ui.Style.FlexibleWidth = -1f; + ui.PopStyle(); var memberActions = ui.Root?.GetComponentInChildren()?.Slot; if (memberActions != null)