From d5f53572dfd7c404fd6161ab1bd453b891906744 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Sep 2024 15:44:53 +0200 Subject: [PATCH 01/36] Add support for using C# stdlib api in Visual Scripts #112 --- .../Modules/SourceCodeEditing/CodeEditingModule.cs | 13 +++++++------ Source/Editor/Surface/VisjectSurface.ContextMenu.cs | 10 +++++----- Source/Editor/Surface/VisualScriptSurface.cs | 1 - 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs b/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs index e298288a4..74af68a42 100644 --- a/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs +++ b/Source/Editor/Modules/SourceCodeEditing/CodeEditingModule.cs @@ -155,6 +155,11 @@ namespace FlaxEditor.Modules.SourceCodeEditing /// public readonly CachedTypesCollection All = new CachedAllTypesCollection(8096, ScriptType.Null, type => true, HasAssemblyValidAnyTypes); + /// + /// The all types collection from all assemblies (including C# system libraries). + /// + public readonly CachedTypesCollection AllWithStd = new CachedTypesCollection(8096, ScriptType.Null, type => true, assembly => true); + /// /// The all valid types collection for the Visual Script property types (includes basic types like int/float, structures, object references). /// @@ -574,21 +579,17 @@ namespace FlaxEditor.Modules.SourceCodeEditing private static bool HasAssemblyValidAnyTypes(Assembly assembly) { var codeBase = Utils.GetAssemblyLocation(assembly); + if (string.IsNullOrEmpty(codeBase)) + return true; #if USE_NETCORE if (assembly.ManifestModule.FullyQualifiedName == "") return false; - if (string.IsNullOrEmpty(codeBase)) - return true; - // Skip runtime related assemblies string repositoryUrl = assembly.GetCustomAttributes().FirstOrDefault(x => x.Key == "RepositoryUrl")?.Value ?? ""; if (repositoryUrl != "https://github.com/dotnet/runtime") return true; #else - if (string.IsNullOrEmpty(codeBase)) - return true; - // Skip assemblies from in-build Mono directory if (!codeBase.Contains("/Mono/lib/mono/")) return true; diff --git a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs index d086aa851..18041f314 100644 --- a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs +++ b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs @@ -140,12 +140,12 @@ namespace FlaxEditor.Surface var searchStartTime = DateTime.Now; #endif - foreach (var scriptType in Editor.Instance.CodeEditing.All.Get()) + foreach (var scriptType in Editor.Instance.CodeEditing.AllWithStd.Get()) { - if (!SurfaceUtils.IsValidVisualScriptType(scriptType)) - continue; - - _iterator(scriptType, _cache, _version); + if (SurfaceUtils.IsValidVisualScriptType(scriptType)) + { + _iterator(scriptType, _cache, _version); + } } // Add group to context menu (on a main thread) diff --git a/Source/Editor/Surface/VisualScriptSurface.cs b/Source/Editor/Surface/VisualScriptSurface.cs index e17453b0a..11ce24c64 100644 --- a/Source/Editor/Surface/VisualScriptSurface.cs +++ b/Source/Editor/Surface/VisualScriptSurface.cs @@ -17,7 +17,6 @@ using FlaxEditor.Surface.Elements; using FlaxEngine; using FlaxEngine.GUI; using FlaxEngine.Utilities; -using Object = FlaxEngine.Object; namespace FlaxEditor.Surface { From c69beae81a773dff0999617bb68b735b4757638d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Sep 2024 15:45:12 +0200 Subject: [PATCH 02/36] Add namespace to method tooltips in Visual ScriptType #112 --- Source/Editor/Surface/SurfaceUtils.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Editor/Surface/SurfaceUtils.cs b/Source/Editor/Surface/SurfaceUtils.cs index c1f966812..8f5c498d1 100644 --- a/Source/Editor/Surface/SurfaceUtils.cs +++ b/Source/Editor/Surface/SurfaceUtils.cs @@ -443,6 +443,8 @@ namespace FlaxEditor.Surface sb.Append("virtual "); sb.Append(valueType.Name); sb.Append(' '); + if (member.IsMethod) + sb.Append(member.DeclaringType.Namespace).Append('.'); sb.Append(declaringType.Name); sb.Append('.'); sb.Append(name); From 51ee3de689b3aa3aa048d570309449b9e1d33f7f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Sep 2024 16:29:14 +0200 Subject: [PATCH 03/36] Add Background Brush to the control for more styling #1898 --- Source/Engine/UI/GUI/Control.cs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs index cd7097dae..cb6e11ee0 100644 --- a/Source/Engine/UI/GUI/Control.cs +++ b/Source/Engine/UI/GUI/Control.cs @@ -81,6 +81,7 @@ namespace FlaxEngine.GUI // Style private Color _backgroundColor = Color.Transparent; + private IBrush _backgroundBrush = null; // Tooltip @@ -174,6 +175,25 @@ namespace FlaxEngine.GUI set => _backgroundColor = value; } + /// + /// Gets or sets control background brush used to fill the contents. Uses Background Color property as tint color. + /// + [EditorDisplay("Background Style"), EditorOrder(2001)] + public IBrush BackgroundBrush + { + get => _backgroundBrush; + set + { + _backgroundBrush = value; + +#if FLAX_EDITOR + // Auto-reset background color so brush is visible as it uses it for tint + if (value != null && _backgroundColor == Color.Transparent && FlaxEditor.CustomEditors.CustomEditor.IsSettingValue) + _backgroundColor = Color.White; +#endif + } + } + /// /// Gets or sets the anchor preset used by the control anchors (based on and ). /// @@ -416,9 +436,14 @@ namespace FlaxEngine.GUI public virtual void Draw() { // Paint Background - if (_backgroundColor.A > 0.0f) + var rect = new Rectangle(Float2.Zero, _bounds.Size); + if (BackgroundBrush != null) { - Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), _backgroundColor); + BackgroundBrush.Draw(rect, _backgroundColor); + } + else if (_backgroundColor.A > 0.0f) + { + Render2D.FillRectangle(rect, _backgroundColor); } } From cb67fbcbd71e32eaeecbe9579c4f651d4fe08119 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Sep 2024 19:01:18 +0200 Subject: [PATCH 04/36] Remove BackgroundBrush from Button as it's already in Control as of 51ee3de689b3aa3aa048d570309449b9e1d33f7f --- Source/Engine/UI/GUI/Common/Button.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/Button.cs b/Source/Engine/UI/GUI/Common/Button.cs index ff0b776f9..aa25e0b1b 100644 --- a/Source/Engine/UI/GUI/Common/Button.cs +++ b/Source/Engine/UI/GUI/Common/Button.cs @@ -62,12 +62,6 @@ namespace FlaxEngine.GUI [EditorDisplay("Text Style"), EditorOrder(2020)] public Color TextColor; - /// - /// Gets or sets the brush used for background drawing. - /// - [EditorDisplay("Background Style"), EditorOrder(1999), Tooltip("The brush used for background drawing."), ExpandGroups] - public IBrush BackgroundBrush { get; set; } - /// /// Gets or sets the background color when button is highlighted. /// From 49eeb7bf9a3dcb4bcf373fc5281d61ffcfab7b0a Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Sep 2024 22:37:36 +0200 Subject: [PATCH 05/36] Fix parsing forward enum declaration in scripting api --- .../Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs index 46eeeb572..37ac4f1dd 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs @@ -242,6 +242,11 @@ namespace Flax.Build.Bindings } // Forward type + if (token.Value == "enum") + { + context.Tokenizer.SkipUntil(TokenType.Identifier); + token = context.Tokenizer.CurrentToken; + } if (token.Value == "class") { context.Tokenizer.SkipUntil(TokenType.Identifier); From c5f1cdc23d294f7a220950134bdb897c855c1501 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Fri, 13 Sep 2024 23:35:25 +0200 Subject: [PATCH 06/36] add splash screen quote about docs Documentation is amazing. If ppl read it. --- Source/Editor/Windows/SplashScreen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index dfa1b4bf7..49257d281 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -135,6 +135,7 @@ const Char* SplashScreenQuotes[] = TEXT("Drum roll please"), TEXT("Good Luck Have Fun"), TEXT("GG Well Played"), + TEXT("Now with documentation."), }; SplashScreen::~SplashScreen() From 2a29b8e8078d5f8ceac2e7200ec2631388fba305 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sat, 14 Sep 2024 23:25:59 +0200 Subject: [PATCH 07/36] Fix regression in function surfaces --- .../Assets/AnimationGraphFunctionWindow.cs | 1 + .../Windows/Assets/MaterialFunctionWindow.cs | 1 + .../Assets/ParticleEmitterFunctionWindow.cs | 1 + .../Assets/VisjectFunctionSurfaceWindow.cs | 23 ++++++++++++------- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Source/Editor/Windows/Assets/AnimationGraphFunctionWindow.cs b/Source/Editor/Windows/Assets/AnimationGraphFunctionWindow.cs index 36acb0a57..5693e7b3b 100644 --- a/Source/Editor/Windows/Assets/AnimationGraphFunctionWindow.cs +++ b/Source/Editor/Windows/Assets/AnimationGraphFunctionWindow.cs @@ -32,6 +32,7 @@ namespace FlaxEditor.Windows.Assets _surface.ContextChanged += OnSurfaceContextChanged; // Toolstrip + SurfaceUtils.PerformCommonSetup(this, _toolstrip, _surface, out _saveButton, out _undoButton, out _redoButton); _toolstrip.AddSeparator(); _toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/animation/anim-graph/index.html")).LinkTooltip("See documentation to learn more"); diff --git a/Source/Editor/Windows/Assets/MaterialFunctionWindow.cs b/Source/Editor/Windows/Assets/MaterialFunctionWindow.cs index 076d2a863..fcafeadbc 100644 --- a/Source/Editor/Windows/Assets/MaterialFunctionWindow.cs +++ b/Source/Editor/Windows/Assets/MaterialFunctionWindow.cs @@ -28,6 +28,7 @@ namespace FlaxEditor.Windows.Assets }; // Toolstrip + SurfaceUtils.PerformCommonSetup(this, _toolstrip, _surface, out _saveButton, out _undoButton, out _redoButton); _toolstrip.AddSeparator(); _toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/graphics/materials/index.html")).LinkTooltip("See documentation to learn more"); } diff --git a/Source/Editor/Windows/Assets/ParticleEmitterFunctionWindow.cs b/Source/Editor/Windows/Assets/ParticleEmitterFunctionWindow.cs index e3993d445..c7869ff2c 100644 --- a/Source/Editor/Windows/Assets/ParticleEmitterFunctionWindow.cs +++ b/Source/Editor/Windows/Assets/ParticleEmitterFunctionWindow.cs @@ -28,6 +28,7 @@ namespace FlaxEditor.Windows.Assets }; // Toolstrip + SurfaceUtils.PerformCommonSetup(this, _toolstrip, _surface, out _saveButton, out _undoButton, out _redoButton); _toolstrip.AddSeparator(); _toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/particles/index.html")).LinkTooltip("See documentation to learn more"); } diff --git a/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs b/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs index 24b3e3f9b..edfe16f86 100644 --- a/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs +++ b/Source/Editor/Windows/Assets/VisjectFunctionSurfaceWindow.cs @@ -27,9 +27,21 @@ namespace FlaxEditor.Windows.Assets /// protected readonly Panel _panel; - private readonly ToolStripButton _saveButton; - private readonly ToolStripButton _undoButton; - private readonly ToolStripButton _redoButton; + /// + /// Save button. + /// + protected ToolStripButton _saveButton; + + /// + /// Undo button. + /// + protected ToolStripButton _undoButton; + + /// + /// Redo button. + /// + protected ToolStripButton _redoButton; + private bool _showWholeGraphOnLoad = true; /// @@ -61,17 +73,12 @@ namespace FlaxEditor.Windows.Assets protected VisjectFunctionSurfaceWindow(Editor editor, AssetItem item) : base(editor, item) { - var inputOptions = Editor.Options.Options.Input; - // Undo _undo = new Undo(); _undo.UndoDone += OnUndoRedo; _undo.RedoDone += OnUndoRedo; _undo.ActionDone += OnUndoRedo; - // Toolstrip - SurfaceUtils.PerformCommonSetup(this, _toolstrip, _surface, out _saveButton, out _undoButton, out _redoButton); - // Panel _panel = new Panel(ScrollBars.None) { From 6c6938aa41ef8fe2c00cc01002186c2975352d03 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Sun, 15 Sep 2024 16:03:45 +0200 Subject: [PATCH 08/36] improve editor options descriptions --- Source/Editor/Options/InterfaceOptions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index 3417f72a0..d8493a70a 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -211,10 +211,10 @@ namespace FlaxEditor.Options public bool SeparateValueAndUnit { get; set; } /// - /// Gets or sets the option to put a space between numbers and units for unit formatting. + /// Gets or sets tree line visibility. /// [DefaultValue(true)] - [EditorDisplay("Interface"), EditorOrder(320)] + [EditorDisplay("Interface"), EditorOrder(320), Tooltip("Toggles tree line visibility in places like the Scene or Content Panel.")] public bool ShowTreeLines { get; set; } = true; /// @@ -369,7 +369,7 @@ namespace FlaxEditor.Options public int NumberOfGameClientsToLaunch = 1; /// - /// Gets or sets the visject connection curvature. + /// Gets or sets the curvature of the line connecting to connected visject nodes. /// [DefaultValue(1.0f), Range(0.0f, 2.0f)] [EditorDisplay("Visject"), EditorOrder(550)] From 1fa01590799f80a2815c741167e438d8a6cda646 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 15 Sep 2024 22:59:29 +0200 Subject: [PATCH 09/36] Fix crash in editor when opening Visual Script that uses array of visual script references --- Source/Editor/CustomEditors/CustomEditorsUtil.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Editor/CustomEditors/CustomEditorsUtil.cs b/Source/Editor/CustomEditors/CustomEditorsUtil.cs index d6d2455d0..27dbdbb7b 100644 --- a/Source/Editor/CustomEditors/CustomEditorsUtil.cs +++ b/Source/Editor/CustomEditors/CustomEditorsUtil.cs @@ -72,6 +72,8 @@ namespace FlaxEditor.CustomEditors return new GenericEditor(); if (targetType.IsArray) { + if (targetType.Type == null) + return new ArrayEditor(); if (targetType.Type.GetArrayRank() != 1) return new GenericEditor(); // Not-supported multidimensional array From a367d4091348b96cad6ec84865a8ce650947ae80 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 15 Sep 2024 23:03:53 +0200 Subject: [PATCH 10/36] Add more contextual log printing on missing object/asset reference #2414 --- Source/Engine/Content/Asset.cpp | 4 +- Source/Engine/Content/Content.cpp | 3 ++ Source/Engine/Core/LogContext.cpp | 60 ++++++++++++++++++--- Source/Engine/Core/LogContext.h | 8 +-- Source/Engine/Scripting/Scripting.cpp | 6 ++- Source/Engine/Scripting/ScriptingObject.cpp | 8 ++- 6 files changed, 74 insertions(+), 15 deletions(-) diff --git a/Source/Engine/Content/Asset.cpp b/Source/Engine/Content/Asset.cpp index ddff7fc8a..b6a7be5c9 100644 --- a/Source/Engine/Content/Asset.cpp +++ b/Source/Engine/Content/Asset.cpp @@ -7,6 +7,7 @@ #include "Loading/ContentLoadingManager.h" #include "Loading/Tasks/LoadAssetTask.h" #include "Engine/Core/Log.h" +#include "Engine/Core/LogContext.h" #include "Engine/Engine/Engine.h" #include "Engine/Threading/Threading.h" #include "Engine/Profiler/ProfilerCPU.h" @@ -587,9 +588,10 @@ bool Asset::IsInternalType() const bool Asset::onLoad(LoadAssetTask* task) { - if (task->Asset.Get() != this || Platform::AtomicRead(&_loadingTask) == 0) // It may fail when task is cancelled and new one was created later (don't crash but just end with an error) + if (task->Asset.Get() != this || Platform::AtomicRead(&_loadingTask) == 0) return true; + LogContextScope logContext(GetID()); Locker.Lock(); diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index fa4517911..92e1baf7b 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -9,6 +9,7 @@ #include "Storage/JsonStorageProxy.h" #include "Factories/IAssetFactory.h" #include "Engine/Core/Log.h" +#include "Engine/Core/LogContext.h" #include "Engine/Core/Types/String.h" #include "Engine/Core/ObjectsRemovalService.h" #include "Engine/Engine/EngineService.h" @@ -970,6 +971,7 @@ Asset* Content::LoadAsync(const Guid& id, const ScriptingTypeHandle& type) if (IsAssetTypeIdInvalid(type, result->GetTypeHandle()) && !result->Is(type)) { LOG(Warning, "Different loaded asset type! Asset: \'{0}\'. Expected type: {1}", result->ToString(), type.ToString()); + LogContext::Print(LogType::Warning); return nullptr; } return result; @@ -1004,6 +1006,7 @@ Asset* Content::LoadAsync(const Guid& id, const ScriptingTypeHandle& type) if (!GetAssetInfo(id, assetInfo)) { LOG(Warning, "Invalid or missing asset ({0}, {1}).", id, type.ToString()); + LogContext::Print(LogType::Warning); LOAD_FAILED(); } #if ASSETS_LOADING_EXTRA_VERIFICATION diff --git a/Source/Engine/Core/LogContext.cpp b/Source/Engine/Core/LogContext.cpp index d4516e2d1..4264d8759 100644 --- a/Source/Engine/Core/LogContext.cpp +++ b/Source/Engine/Core/LogContext.cpp @@ -1,9 +1,15 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #include "LogContext.h" +#include "Engine/Core/Log.h" #include "Engine/Core/Types/Guid.h" #include "Engine/Core/Types/String.h" +#include "Engine/Core/Types/StringBuilder.h" #include "Engine/Core/Collections/Array.h" +#include "Engine/Scripting/Scripting.h" +#include "Engine/Scripting/Script.h" +#include "Engine/Content/Asset.h" +#include "Engine/Level/Actor.h" #include "Engine/Threading/ThreadLocal.h" struct LogContextThreadData @@ -30,7 +36,7 @@ struct LogContextThreadData Count--; } - LogContextData Peek() + LogContextData Peek() const { return Count > 0 ? Ptr[Count - 1] : LogContextData(); } @@ -38,12 +44,54 @@ struct LogContextThreadData ThreadLocal GlobalLogContexts; -String LogContext::GetInfo() +void LogContext::Print(LogType verbosity) { - LogContextData context = LogContext::Get(); - if (context.ObjectID != Guid::Empty) - return String::Format(TEXT("(Loading source was {0})"), context.ObjectID); - return String::Empty; + auto& stack = GlobalLogContexts.Get(); + if (stack.Count == 0) + return; + const StringView indentation(TEXT(" ")); + StringBuilder msg; + for (int32 index = (int32)stack.Count - 1; index >= 0; index--) + { + // Build call hierarchy via indentation + msg.Clear(); + for (uint32 i = index; i < stack.Count; i++) + msg.Append(indentation); + + LogContextData& context = stack.Ptr[index]; + if (context.ObjectID != Guid::Empty) + { + // Object reference context + msg.Append(TEXT(" Referenced by ")); + if (ScriptingObject* object = Scripting::TryFindObject(context.ObjectID)) + { + const StringAnsiView typeName(object->GetType().Fullname); + if (Asset* asset = ScriptingObject::Cast(object)) + { + msg.AppendFormat(TEXT("asset '{}' ({}, {})"), asset->GetPath(), asset->GetTypeName(), context.ObjectID); + } + else if (Actor* actor = ScriptingObject::Cast(object)) + { + msg.AppendFormat(TEXT("actor '{}' ({}, {})"), actor->GetNamePath(), String(typeName), context.ObjectID); + } + else if (Script* script = ScriptingObject::Cast