From 283ee2af6fb39601dcd8a13cad63e294ebedd8ce Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 15 Oct 2024 18:55:03 +0200 Subject: [PATCH 01/22] add debug draw clear method --- Source/Engine/Debug/DebugDraw.cpp | 4 ++++ Source/Engine/Debug/DebugDraw.h | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 2ae7756da..dccfcc206 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -2145,4 +2145,8 @@ void DebugDraw::DrawText(const StringView& text, const Transform& transform, con t.TimeLeft = duration; } +void DebugDraw::Clear(void* context) +{ + DebugDraw::UpdateContext(nullptr, MAX_float); +} #endif diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index 9c58aa727..bb5cf2e50 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -689,6 +689,12 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw /// The font size. /// The duration (in seconds). Use 0 to draw it only once. API_FUNCTION() static void DrawText(const StringView& text, const Transform& transform, const Color& color = Color::White, int32 size = 32, float duration = 0.0f); + + /// + /// Clear all debug draw displayed on sceen. + /// + /// + API_FUNCTION() static void Clear(void* context = nullptr); }; #define DEBUG_DRAW_AXIS_FROM_DIRECTION(origin, direction, size, duration, depthTest) DebugDraw::DrawAxisFromDirection(origin, direction, size, duration, depthTest); @@ -721,6 +727,7 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw #define DEBUG_DRAW_WIRE_ARC(position, orientation, radius, angle, color, duration, depthTest) DebugDraw::DrawWireArc(position, orientation, radius, angle, color, duration, depthTest) #define DEBUG_DRAW_WIRE_ARROW(position, orientation, scale, capScale, color, duration, depthTest) DebugDraw::DrawWireArrow(position, orientation, scale, capScale, color, duration, depthTest) #define DEBUG_DRAW_TEXT(text, position, color, size, duration) DebugDraw::DrawText(text, position, color, size, duration) +#define DEBUG_DRAW_CLEAR(context) DebugDraw::Clear(context) #else @@ -753,5 +760,6 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw #define DEBUG_DRAW_WIRE_ARC(position, orientation, radius, angle, color, duration, depthTest) #define DEBUG_DRAW_WIRE_ARROW(position, orientation, scale, capScale, color, duration, depthTest) #define DEBUG_DRAW_TEXT(text, position, color, size, duration) +#define DEBUG_DRAW_CLEAR(context) #endif From 98215252bde5cb7e0c6bca8f5d9ada9f57e20198 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 15 Oct 2024 22:05:16 +0200 Subject: [PATCH 02/22] add tooltip text alignment editor options --- Source/Editor/Options/InterfaceOptions.cs | 9 +++++++++ Source/Engine/UI/GUI/Tooltip.cs | 23 ++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index d8493a70a..ea3d613a0 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -217,6 +217,15 @@ namespace FlaxEditor.Options [EditorDisplay("Interface"), EditorOrder(320), Tooltip("Toggles tree line visibility in places like the Scene or Content Panel.")] public bool ShowTreeLines { get; set; } = true; + /// + /// Gets or sets tooltip text alignment. + /// + [DefaultValue(TextAlignment.Center)] + [EditorDisplay("Interface"), EditorOrder(321)] + public TextAlignment TooltipTextAlignment { get; set; } = TextAlignment.Center; + + + /// /// Gets or sets the timestamps prefix mode for output log messages. /// diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index a7f80e152..61bacb934 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -1,5 +1,7 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +using FlaxEditor; +using FlaxEditor.Options; using System; namespace FlaxEngine.GUI @@ -236,7 +238,22 @@ namespace FlaxEngine.GUI // Padding for text var textRect = GetClientArea(); - textRect.X += 5; + + float textX = 0; + switch (Editor.Instance.Options.Options.Interface.TooltipTextAlignment) + { + case TextAlignment.Near: + textX = 15; + break; + case TextAlignment.Center: + textX = 5; + break; + case TextAlignment.Far: + textX = -5; + break; + } + + textRect.X += textX; textRect.Width -= 10; // Tooltip text @@ -245,7 +262,7 @@ namespace FlaxEngine.GUI _currentText, textRect, style.Foreground, - TextAlignment.Center, + Editor.Instance.Options.Options.Interface.TooltipTextAlignment, TextAlignment.Center, TextWrapping.WrapWords ); @@ -265,7 +282,7 @@ namespace FlaxEngine.GUI { var layout = TextLayoutOptions.Default; layout.Bounds = new Rectangle(0, 0, MaxWidth, 10000000); - layout.HorizontalAlignment = TextAlignment.Center; + layout.HorizontalAlignment = TextAlignment.Near; layout.VerticalAlignment = TextAlignment.Center; layout.TextWrapping = TextWrapping.WrapWords; var items = style.FontMedium.ProcessText(_currentText, ref layout); From 7558cce6094f3a3b35df3aa5ae482e1f290d1ddb Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 15 Oct 2024 22:07:09 +0200 Subject: [PATCH 03/22] change back accidentally committed line --- Source/Engine/UI/GUI/Tooltip.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index 61bacb934..bac74b5ab 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -282,7 +282,7 @@ namespace FlaxEngine.GUI { var layout = TextLayoutOptions.Default; layout.Bounds = new Rectangle(0, 0, MaxWidth, 10000000); - layout.HorizontalAlignment = TextAlignment.Near; + layout.HorizontalAlignment = TextAlignment.Center; layout.VerticalAlignment = TextAlignment.Center; layout.TextWrapping = TextWrapping.WrapWords; var items = style.FontMedium.ProcessText(_currentText, ref layout); From 425382f7d20c793cf9046f828357614cc283c447 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 17 Oct 2024 15:03:59 +0200 Subject: [PATCH 04/22] Fix iOS game dotnet lib incorrect name --- Source/Editor/Cooker/Steps/DeployDataStep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Cooker/Steps/DeployDataStep.cpp b/Source/Editor/Cooker/Steps/DeployDataStep.cpp index 84a36e5c6..ff22247ef 100644 --- a/Source/Editor/Cooker/Steps/DeployDataStep.cpp +++ b/Source/Editor/Cooker/Steps/DeployDataStep.cpp @@ -275,7 +275,7 @@ bool DeployDataStep::Perform(CookingData& data) DEPLOY_NATIVE_FILE("libmonosgen-2.0.dylib"); DEPLOY_NATIVE_FILE("libSystem.IO.Compression.Native.dylib"); DEPLOY_NATIVE_FILE("libSystem.Native.dylib"); - DEPLOY_NATIVE_FILE("libSystem.NET.Security.Native.dylib"); + DEPLOY_NATIVE_FILE("libSystem.Net.Security.Native.dylib"); DEPLOY_NATIVE_FILE("libSystem.Security.Cryptography.Native.Apple.dylib"); break; #undef DEPLOY_NATIVE_FILE From b27ccc5f3be689e29e100fbbb35daea340a7be25 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 17 Oct 2024 18:42:39 +0200 Subject: [PATCH 05/22] condense switch statement --- Source/Engine/UI/GUI/Tooltip.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index bac74b5ab..dbd91ffef 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -239,19 +239,12 @@ namespace FlaxEngine.GUI // Padding for text var textRect = GetClientArea(); - float textX = 0; - switch (Editor.Instance.Options.Options.Interface.TooltipTextAlignment) + float textX = Editor.Instance.Options.Options.Interface.TooltipTextAlignment switch { - case TextAlignment.Near: - textX = 15; - break; - case TextAlignment.Center: - textX = 5; - break; - case TextAlignment.Far: - textX = -5; - break; - } + TextAlignment.Near => 15, + TextAlignment.Center => 5, + TextAlignment.Far => -5, + }; textRect.X += textX; textRect.Width -= 10; From fceb47f2afbaf2e62da5203927c2dc4c78d3bc5c Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 17 Oct 2024 18:47:48 +0200 Subject: [PATCH 06/22] fix context not implemented --- Source/Engine/Debug/DebugDraw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index dccfcc206..077bf9b80 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -2147,6 +2147,6 @@ void DebugDraw::DrawText(const StringView& text, const Transform& transform, con void DebugDraw::Clear(void* context) { - DebugDraw::UpdateContext(nullptr, MAX_float); + DebugDraw::UpdateContext(context, MAX_float); } #endif From 684ae5771f413fe06e8e2bc6784e6fa01eb76605 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 19 Oct 2024 01:25:23 +0300 Subject: [PATCH 07/22] Fix crash while initializing OpenAL --- Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs index b6b5fa83d..4e90c5898 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs @@ -77,7 +77,7 @@ namespace Flax.Deps.Dependencies var buildDir = Path.Combine(root, "build-" + architecture.ToString()); var solutionPath = Path.Combine(buildDir, "OpenAL.sln"); - RunCmake(root, platform, architecture, $"-B\"{buildDir}\" -DBUILD_SHARED_LIBS=OFF"); + RunCmake(root, platform, architecture, $"-B\"{buildDir}\" -DBUILD_SHARED_LIBS=OFF DCMAKE_C_FLAGS=\"/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR /EHsc\" -DCMAKE_CXX_FLAGS=\"/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR /EHsc\""); Deploy.VCEnvironment.BuildSolution(solutionPath, configuration, architecture.ToString()); var depsFolder = GetThirdPartyFolder(options, platform, architecture); foreach (var file in binariesToCopy) From a94cc64806fffc5893411d89e9ca0d018f319381 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 20 Oct 2024 23:29:36 +0200 Subject: [PATCH 08/22] Speculative fix for missing main project info in VS Code project generation --- .../VisualStudioCode/VisualStudioCodeProjectGenerator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs index 1830b8efe..88b7a8df5 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudioCode/VisualStudioCodeProjectGenerator.cs @@ -301,7 +301,8 @@ namespace Flax.Build.Projects.VisualStudioCode json.BeginArray("configurations"); { var cppProject = solution.Projects.FirstOrDefault(x => x.BaseName == solution.Name || x.Name == solution.Name); - var csharpProject = solution.Projects.FirstOrDefault(x => x.BaseName == solution.MainProject.Targets[0].Modules[0] || x.Name == solution.MainProject.Targets[0].Modules[0]); + var mainProjectModule = solution.MainProject?.Targets.Length != 0 ? solution.MainProject.Targets[0].Modules[0] : null; + var csharpProject = mainProjectModule != null ? solution.Projects.FirstOrDefault(x => x.BaseName == mainProjectModule || x.Name == mainProjectModule) : null; if (cppProject != null) { From 8ff334ae636910250ef714ed39e1933732a145f6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 21 Oct 2024 12:12:06 +0200 Subject: [PATCH 09/22] Update OpenAL on Windows #2997 --- Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.dll | 4 ++-- Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.lib | 2 +- Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.dll b/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.dll index 7ef160291..e64bb6cd7 100644 --- a/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.dll +++ b/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d4bc89abf5a72c9c3dede29d1cbe5ced923d99e99ba82b76c7b25e940e6f4f25 -size 1111552 +oid sha256:a54bca64e921d32525ed58c52ce802b4ca2c3f8a92c342296da48c55ec1ea58d +size 1112064 diff --git a/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.lib b/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.lib index 3f70d273b..ae9715a8b 100644 --- a/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.lib +++ b/Source/Platforms/Windows/Binaries/ThirdParty/x64/OpenAL32.lib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e7636bd763b099f84d2015fa89635d27d4298b2c8c38ce0335b545ae9e2b4db4 +oid sha256:6a4ac5af61abb19624dc2ae23bc16af09a062655f3eab89fedf6c0ead6cd935a size 37562 diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs index 4e90c5898..f13449192 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs @@ -77,7 +77,7 @@ namespace Flax.Deps.Dependencies var buildDir = Path.Combine(root, "build-" + architecture.ToString()); var solutionPath = Path.Combine(buildDir, "OpenAL.sln"); - RunCmake(root, platform, architecture, $"-B\"{buildDir}\" -DBUILD_SHARED_LIBS=OFF DCMAKE_C_FLAGS=\"/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR /EHsc\" -DCMAKE_CXX_FLAGS=\"/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR /EHsc\""); + RunCmake(root, platform, architecture, $"-B\"{buildDir}\" -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=\"/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR /EHsc\" -DCMAKE_CXX_FLAGS=\"/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR /EHsc\""); Deploy.VCEnvironment.BuildSolution(solutionPath, configuration, architecture.ToString()); var depsFolder = GetThirdPartyFolder(options, platform, architecture); foreach (var file in binariesToCopy) From f62c77c35ce568a9ff87111dfc0b1e28ece60d0f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 21 Oct 2024 12:37:55 +0200 Subject: [PATCH 10/22] Fix game deployment if output name contains invalid path characters #3004 --- .../Platform/Windows/WindowsPlatformTools.cpp | 5 ++-- Source/Editor/Utilities/EditorUtilities.cpp | 28 +++++++++++++++++-- Source/Editor/Utilities/EditorUtilities.h | 7 +++++ Source/Engine/Tools/ModelTool/ModelTool.cpp | 6 +--- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Source/Editor/Cooker/Platform/Windows/WindowsPlatformTools.cpp b/Source/Editor/Cooker/Platform/Windows/WindowsPlatformTools.cpp index 9d3280f4b..5259ca2df 100644 --- a/Source/Editor/Cooker/Platform/Windows/WindowsPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/Windows/WindowsPlatformTools.cpp @@ -511,11 +511,12 @@ bool WindowsPlatformTools::OnDeployBinaries(CookingData& data) // Rename app const String newName = EditorUtilities::GetOutputName(); - if (newName != StringUtils::GetFileNameWithoutExtension(files[0])) + const StringView oldName = StringUtils::GetFileNameWithoutExtension(files[0]); + if (newName != oldName) { if (FileSystem::MoveFile(data.NativeCodeOutputPath / newName + TEXT(".exe"), files[0], true)) { - data.Error(TEXT("Failed to change output executable name.")); + data.Error(String::Format(TEXT("Failed to change output executable name from '{}' to '{}'."), oldName, newName)); return true; } } diff --git a/Source/Editor/Utilities/EditorUtilities.cpp b/Source/Editor/Utilities/EditorUtilities.cpp index 0fc614af5..e3f521437 100644 --- a/Source/Editor/Utilities/EditorUtilities.cpp +++ b/Source/Editor/Utilities/EditorUtilities.cpp @@ -5,10 +5,11 @@ #include "Engine/Platform/File.h" #include "Engine/Platform/FileSystem.h" #include "Engine/Platform/CreateProcessSettings.h" -#include "Engine/Core/Log.h" #include "Engine/Graphics/Textures/TextureData.h" #include "Engine/Graphics/PixelFormatExtensions.h" #include "Engine/Tools/TextureTool/TextureTool.h" +#include "Engine/Core/Log.h" +#include "Engine/Core/Types/StringBuilder.h" #include "Engine/Core/Config/GameSettings.h" #include "Engine/Core/Config/BuildSettings.h" #include "Engine/Content/Content.h" @@ -28,6 +29,7 @@ String EditorUtilities::GetOutputName() outputName.Replace(TEXT("${COMPANY_NAME}"), *gameSettings->CompanyName, StringSearchCase::IgnoreCase); if (outputName.IsEmpty()) outputName = TEXT("FlaxGame"); + ValidatePathChars(outputName, 0); return outputName; } @@ -360,6 +362,28 @@ bool EditorUtilities::IsInvalidPathChar(Char c) return false; } +void EditorUtilities::ValidatePathChars(String& filename, char invalidCharReplacement) +{ + if (invalidCharReplacement == 0) + { + StringBuilder result; + for (int32 i = 0; i < filename.Length(); i++) + { + if (!IsInvalidPathChar(filename[i])) + result.Append(filename[i]); + } + filename = result.ToString(); + } + else + { + for (int32 i = 0; i < filename.Length(); i++) + { + if (IsInvalidPathChar(filename[i])) + filename[i] = invalidCharReplacement; + } + } +} + bool EditorUtilities::ReplaceInFiles(const String& folderPath, const Char* searchPattern, DirectorySearchOption searchOption, const String& findWhat, const String& replaceWith) { Array files; @@ -391,7 +415,7 @@ bool EditorUtilities::ReplaceInFile(const StringView& file, const Dictionarytrue if the given character cannot be used as a path because it is illegal character; otherwise, false. static bool IsInvalidPathChar(Char c); + /// + /// Validates path characters and replaces any incorrect ones. + /// + /// The input and output filename string to process. + /// The character to use for replacement for any invalid characters in the path. Use '0' to remove them. + static void ValidatePathChars(String& filename, char invalidCharReplacement = ' '); + /// /// Replaces the given text with other one in the files. /// diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index 408fcb887..91c2edc06 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -1080,11 +1080,7 @@ void TrySetupMaterialParameter(MaterialInstance* instance, Span par String GetAdditionalImportPath(const String& autoImportOutput, Array& importedFileNames, const String& name) { String filename = name; - for (int32 j = filename.Length() - 1; j >= 0; j--) - { - if (EditorUtilities::IsInvalidPathChar(filename[j])) - filename[j] = ' '; - } + EditorUtilities::ValidatePathChars(filename); if (importedFileNames.Contains(filename)) { int32 counter = 1; From 6c077a83bceab5dcd80605c15e12f77236d6235b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 21 Oct 2024 21:01:48 -0500 Subject: [PATCH 11/22] Handle C++ bracket default values for code gen to C# --- .../Flax.Build/Bindings/BindingsGenerator.CSharp.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index 06d2b9712..17c92fe44 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -153,6 +153,17 @@ namespace Flax.Build.Bindings case "false": return value; } + // Handle C++ bracket default values that are not arrays + if (value.StartsWith("{") && value.EndsWith("}") && valueType != null && !valueType.IsArray && valueType.Type != "Array") + { + value = value.Replace("{", "").Replace("}", "").Trim(); + if (string.IsNullOrEmpty(value)) + { + value = $"default({valueType.Type})"; + return value; + } + } + // Numbers if (float.TryParse(value, out _) || (value[value.Length - 1] == 'f' && float.TryParse(value.Substring(0, value.Length - 1), out _))) { From cc511453f5c4026a064d589e68708043ac3e7331 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 21 Oct 2024 21:24:59 -0500 Subject: [PATCH 12/22] Handle c# code gen when C++ field has default value with style type `type{}` --- .../Flax.Build/Bindings/BindingsGenerator.CSharp.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index 17c92fe44..9642c8b02 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -153,6 +153,17 @@ namespace Flax.Build.Bindings case "false": return value; } + // Handle float{_} style type of default values + if (valueType != null && value.StartsWith($"{valueType.Type}") && value.EndsWith("}")) + { + value = value.Replace($"{valueType.Type}", "").Replace("{", "").Replace("}", "").Trim(); + if (string.IsNullOrEmpty(value)) + { + value = $"default({valueType.Type})"; + return value; + } + } + // Handle C++ bracket default values that are not arrays if (value.StartsWith("{") && value.EndsWith("}") && valueType != null && !valueType.IsArray && valueType.Type != "Array") { From acbb5343204c1d49ef6d300c2957b3ae7b683cd7 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 21 Oct 2024 21:34:34 -0500 Subject: [PATCH 13/22] Handle ex: API_FIELD() Type FieldName {DefaultValue}; --- .../Flax.Build/Bindings/BindingsGenerator.Parsing.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs index b2a3604bb..d99fa8b92 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Parsing.cs @@ -1352,11 +1352,17 @@ namespace Flax.Build.Bindings desc.Name = ParseName(ref context); // Read ';' or default value or array size or bit-field size - token = context.Tokenizer.ExpectAnyTokens(new[] { TokenType.SemiColon, TokenType.Equal, TokenType.LeftBracket, TokenType.Colon }); + token = context.Tokenizer.ExpectAnyTokens(new[] { TokenType.SemiColon, TokenType.Equal, TokenType.LeftBracket, TokenType.LeftCurlyBrace, TokenType.Colon }); if (token.Type == TokenType.Equal) { context.Tokenizer.SkipUntil(TokenType.SemiColon, out desc.DefaultValue, false); } + // Handle ex: API_FIELD() Type FieldName {DefaultValue}; + else if (token.Type == TokenType.LeftCurlyBrace) + { + context.Tokenizer.SkipUntil(TokenType.SemiColon, out desc.DefaultValue, false); + desc.DefaultValue = '{' + desc.DefaultValue; + } else if (token.Type == TokenType.LeftBracket) { // Read the fixed array length From 3e0809ec0ad0a9c58629d5bac45d8b1190a0c4ea Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 14:16:11 +0200 Subject: [PATCH 14/22] improve delete assets confirm dialog - Improve visual spacing - Improve grammar and reduce word count - Make prompt respect asset count --- Source/Editor/Windows/ContentWindow.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index bb7c594b3..90da6735b 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -638,12 +638,14 @@ namespace FlaxEditor.Windows var toDelete = new List(items); toDelete.Sort((a, b) => a.IsFolder ? 1 : b.IsFolder ? -1 : a.Compare(b)); + string singularPlural = toDelete.Count > 1 ? "s" : ""; + string msg = toDelete.Count == 1 - ? string.Format("Are you sure to delete \'{0}\'?\nThis action cannot be undone. Files will be deleted permanently.", items[0].Path) - : string.Format("Are you sure to delete {0} selected items?\nThis action cannot be undone. Files will be deleted permanently.", items.Count); + ? string.Format("Delete \'{0}\'?\n\nThis action cannot be undone.\nFiles will be deleted permanently.", items[0].Path) + : string.Format("Delete {0} selected items?\n\nThis action cannot be undone.\nFiles will be deleted permanently.", items.Count); // Ask user - if (MessageBox.Show(msg, "Delete asset(s)", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) + if (MessageBox.Show(msg, "Delete asset" + singularPlural, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) return; // Clear navigation From 06929f70796c07ab67afd6d371a9024877490bc7 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 14:38:13 +0200 Subject: [PATCH 15/22] add getter for WheeledVehicle throttle --- Source/Engine/Physics/Actors/WheeledVehicle.cpp | 5 +++++ Source/Engine/Physics/Actors/WheeledVehicle.h | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.cpp b/Source/Engine/Physics/Actors/WheeledVehicle.cpp index 11157783e..010add151 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.cpp +++ b/Source/Engine/Physics/Actors/WheeledVehicle.cpp @@ -190,6 +190,11 @@ void WheeledVehicle::SetThrottle(float value) _throttle = Math::Clamp(value, -1.0f, 1.0f); } +float WheeledVehicle::GetThrottle() +{ + return _throttle; +} + void WheeledVehicle::SetSteering(float value) { _steering = Math::Clamp(value, -1.0f, 1.0f); diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index 16e226546..fe518a41d 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -541,6 +541,12 @@ public: /// The value (-1,1 range). When using UseReverseAsBrake it can be negative and will be used as brake and backward driving. API_FUNCTION() void SetThrottle(float value); + /// + /// Get the vehicle throttle. It is the analog accelerator pedal value in range (0,1) where 1 represents the pedal fully pressed and 0 represents the pedal in its rest state. + /// + /// The vehicle throttle. + API_FUNCTION() float GetThrottle(); + /// /// Sets the input for vehicle steering. Steer is the analog steer value in range (-1,1) where -1 represents the steering wheel at left lock and +1 represents the steering wheel at right lock. /// From 1d631e91cee384feb7e7396868e925c896105e37 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 22 Oct 2024 14:56:22 -0500 Subject: [PATCH 16/22] Disable add script item if it is not being added to a required actor. --- .../CustomEditors/Dedicated/ScriptsEditor.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs index d2aa85269..e71f9a8bc 100644 --- a/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ScriptsEditor.cs @@ -95,7 +95,21 @@ namespace FlaxEditor.CustomEditors.Dedicated var cm = new ItemsListContextMenu(180); for (int i = 0; i < scripts.Count; i++) { - cm.AddItem(new TypeSearchPopup.TypeItemView(scripts[i])); + var script = scripts[i]; + var item = new TypeSearchPopup.TypeItemView(script); + if (script.GetAttributes(false).FirstOrDefault(x => x is RequireActorAttribute) is RequireActorAttribute requireActor) + { + var actors = ScriptsEditor.ParentEditor.Values; + foreach (var a in actors) + { + if (a.GetType() != requireActor.RequiredType) + { + item.Enabled = false; + break; + } + } + } + cm.AddItem(item); } cm.TextChanged += text => { From 09c0d0d29d169f0a0cb98113c0461e1d4a0edfbb Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 22 Oct 2024 21:55:25 +0200 Subject: [PATCH 17/22] Add `Alignment` option to Vertical and Horizonal Panels #2599 --- .../Engine/UI/GUI/Panels/HorizontalPanel.cs | 18 +++++++++++++++ .../Engine/UI/GUI/Panels/PanelWithMargins.cs | 22 +++++++++++++++++++ Source/Engine/UI/GUI/Panels/VerticalPanel.cs | 18 +++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs index a25a98c86..1c8e646e3 100644 --- a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs @@ -80,6 +80,24 @@ namespace FlaxEngine.GUI size.Y = maxHeight; Size = size; } + else if (_alignment != TextAlignment.Near && hasAnyLeft) + { + // Apply layout alignment + var offset = Width - left - _margin.Right; + if (_alignment == TextAlignment.Center) + offset *= 0.5f; + for (int i = 0; i < _children.Count; i++) + { + Control c = _children[i]; + if (c.Visible) + { + if (Mathf.IsZero(c.AnchorMin.X) && Mathf.IsZero(c.AnchorMax.X)) + { + c.X += offset; + } + } + } + } } } } diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 071f0ccf2..18bd1a52d 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -30,6 +30,11 @@ namespace FlaxEngine.GUI /// protected Float2 _offset; + /// + /// The child controls alignment within layout area. + /// + protected TextAlignment _alignment = TextAlignment.Near; + /// /// Gets or sets the left margin. /// @@ -172,6 +177,23 @@ namespace FlaxEngine.GUI } } + /// + /// Gets or sets the child controls alignment within layout area. + /// + [EditorOrder(50), VisibleIf(nameof(AutoSize), true)] + public TextAlignment Alignment + { + get => _alignment; + set + { + if (_alignment != value) + { + _alignment = value; + PerformLayout(); + } + } + } + /// /// Initializes a new instance of the class. /// diff --git a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs index 9ee2a2297..aae95bd43 100644 --- a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs @@ -80,6 +80,24 @@ namespace FlaxEngine.GUI size.X = maxWidth; Size = size; } + else if (_alignment != TextAlignment.Near && hasAnyTop) + { + // Apply layout alignment + var offset = Height - top - _margin.Bottom; + if (_alignment == TextAlignment.Center) + offset *= 0.5f; + for (int i = 0; i < _children.Count; i++) + { + Control c = _children[i]; + if (c.Visible) + { + if (Mathf.IsZero(c.AnchorMin.Y) && Mathf.IsZero(c.AnchorMax.Y)) + { + c.Y += offset; + } + } + } + } } } } From 4d0ed0136960bd3a4c477c403b7420a8263ed34a Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 22 Oct 2024 16:31:08 -0500 Subject: [PATCH 18/22] Add test case for field default values --- Source/Engine/Tests/TestScripting.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Source/Engine/Tests/TestScripting.h b/Source/Engine/Tests/TestScripting.h index 19fd76351..dc05750e1 100644 --- a/Source/Engine/Tests/TestScripting.h +++ b/Source/Engine/Tests/TestScripting.h @@ -8,6 +8,35 @@ #include "Engine/Scripting/ScriptingObject.h" #include "Engine/Scripting/SerializableScriptingObject.h" +// Test default values init on fields. +API_STRUCT(NoDefault) struct TestDefaultValues +{ + DECLARE_SCRIPTING_TYPE_MINIMAL(TestDefaultValues); + + // Default value case 1 + API_FIELD() float TestFloat1 = {}; + // Default value case 2 + API_FIELD() float TestFloat2 = { }; + // Default value case 3 + API_FIELD() float TestFloat3 = {1.0f}; + // Default value case 4 + API_FIELD() float TestFloat4 = float{}; + // Default value case 5 + API_FIELD() float TestFloat5 = float{ }; + // Default value case 6 + API_FIELD() float TestFloat6 = float{1.0f}; + // Default value case 7 + API_FIELD() float TestFloat7 {}; + // Default value case 8 + API_FIELD() float TestFloat8 {1.0f}; + // Default value case 9 + API_FIELD() float TestFloat9 = 1.0f; + // Default value case 10 + API_FIELD() float TestFloat10 = 1.f; + // Default value case 11 + API_FIELD() float TestFloat11 = 1; +}; + // Test interface (name conflict with namespace) API_INTERFACE(Namespace="Foo") class FLAXENGINE_API IFoo { From dbb6cecafbc624caafd8b0fcb9829dfb5383552a Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 22 Oct 2024 23:37:47 +0200 Subject: [PATCH 19/22] Fix warning --- Source/Engine/UI/GUI/Tooltip.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index dbd91ffef..16b9abe8e 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -238,14 +238,13 @@ namespace FlaxEngine.GUI // Padding for text var textRect = GetClientArea(); - float textX = Editor.Instance.Options.Options.Interface.TooltipTextAlignment switch { TextAlignment.Near => 15, TextAlignment.Center => 5, TextAlignment.Far => -5, + _ => throw new ArgumentOutOfRangeException() }; - textRect.X += textX; textRect.Width -= 10; From b714194e3a65037287ab062c209bb98ff7d3c245 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 23:45:18 +0200 Subject: [PATCH 20/22] Make text respect asset count --- Source/Editor/Windows/ContentWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 90da6735b..6089b2e07 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -641,7 +641,7 @@ namespace FlaxEditor.Windows string singularPlural = toDelete.Count > 1 ? "s" : ""; string msg = toDelete.Count == 1 - ? string.Format("Delete \'{0}\'?\n\nThis action cannot be undone.\nFiles will be deleted permanently.", items[0].Path) + ? string.Format("Delete \'{0}\'?\n\nThis action cannot be undone.\nFile will be deleted permanently.", items[0].Path) : string.Format("Delete {0} selected items?\n\nThis action cannot be undone.\nFiles will be deleted permanently.", items.Count); // Ask user From d5895306b946d1fcc0dcf18cf1d90cf3e3f42864 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 22 Oct 2024 21:09:59 -0500 Subject: [PATCH 21/22] Add button in GameCooker window to open output build folder. --- Source/Editor/Windows/GameCookerWindow.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/Editor/Windows/GameCookerWindow.cs b/Source/Editor/Windows/GameCookerWindow.cs index 855faed63..cbe211eca 100644 --- a/Source/Editor/Windows/GameCookerWindow.cs +++ b/Source/Editor/Windows/GameCookerWindow.cs @@ -328,6 +328,19 @@ namespace FlaxEditor.Windows group.Object(new ReadOnlyValueContainer(platformObj)); + layout.Space(2); + var openOutputButton = layout.Button("Open output folder").Button; + openOutputButton.TooltipText = "Opens the defined out folder if the path exists."; + openOutputButton.Clicked += () => + { + string output = StringUtils.ConvertRelativePathToAbsolute(Globals.ProjectFolder, StringUtils.NormalizePath(proxy.PerPlatformOptions[_platform].Output)); + if (Directory.Exists(output)) + FlaxEngine.FileSystem.ShowFileExplorer(output); + else + FlaxEditor.Editor.LogWarning($"Can not open path: {output} because it does not exist."); + }; + layout.Space(2); + _buildButton = layout.Button("Build").Button; _buildButton.Clicked += OnBuildClicked; } From baa4c2c6806c555e48ab75b3e4520cb5c0c7ed10 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 22 Oct 2024 21:27:16 -0500 Subject: [PATCH 22/22] Fix tooltip having editor references. --- Source/Editor/Options/InterfaceOptions.cs | 11 +++++++++-- Source/Editor/Options/OptionsModule.cs | 2 ++ Source/Engine/UI/GUI/Tooltip.cs | 11 +++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index ea3d613a0..ca053dcab 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using FlaxEditor.GUI.Docking; using FlaxEditor.Utilities; using FlaxEngine; +using FlaxEngine.GUI; namespace FlaxEditor.Options { @@ -222,9 +223,15 @@ namespace FlaxEditor.Options /// [DefaultValue(TextAlignment.Center)] [EditorDisplay("Interface"), EditorOrder(321)] - public TextAlignment TooltipTextAlignment { get; set; } = TextAlignment.Center; - + public TextAlignment TooltipTextAlignment { get => _tooltipTextAlignment; + set + { + _tooltipTextAlignment = value; + Style.Current.SharedTooltip.HorizontalTextAlignment = value; + } + } + private TextAlignment _tooltipTextAlignment = TextAlignment.Center; /// /// Gets or sets the timestamps prefix mode for output log messages. diff --git a/Source/Editor/Options/OptionsModule.cs b/Source/Editor/Options/OptionsModule.cs index d43af963e..24dea810e 100644 --- a/Source/Editor/Options/OptionsModule.cs +++ b/Source/Editor/Options/OptionsModule.cs @@ -331,6 +331,7 @@ namespace FlaxEditor.Options SharedTooltip = new Tooltip(), }; + style.SharedTooltip.HorizontalTextAlignment = Editor.Instance.Options.Options.Interface.TooltipTextAlignment; style.DragWindow = style.BackgroundSelected * 0.7f; return style; } @@ -386,6 +387,7 @@ namespace FlaxEditor.Options SharedTooltip = new Tooltip(), }; + style.SharedTooltip.HorizontalTextAlignment = Editor.Instance.Options.Options.Interface.TooltipTextAlignment; return style; } diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index 16b9abe8e..40aae0067 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -1,7 +1,5 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. -using FlaxEditor; -using FlaxEditor.Options; using System; namespace FlaxEngine.GUI @@ -19,6 +17,11 @@ namespace FlaxEngine.GUI private string _currentText; private Window _window; + /// + /// The horizontal alignment of the text. + /// + public TextAlignment HorizontalTextAlignment = TextAlignment.Center; + /// /// Gets or sets the time in seconds that mouse have to be over the target to show the tooltip. /// @@ -238,7 +241,7 @@ namespace FlaxEngine.GUI // Padding for text var textRect = GetClientArea(); - float textX = Editor.Instance.Options.Options.Interface.TooltipTextAlignment switch + float textX = HorizontalTextAlignment switch { TextAlignment.Near => 15, TextAlignment.Center => 5, @@ -254,7 +257,7 @@ namespace FlaxEngine.GUI _currentText, textRect, style.Foreground, - Editor.Instance.Options.Options.Interface.TooltipTextAlignment, + HorizontalTextAlignment, TextAlignment.Center, TextWrapping.WrapWords );