Skip to content

Commit 6f1f1fc

Browse files
committed
Implement Hidden in C#.
1 parent f7ce55f commit 6f1f1fc

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

modules/mono/csharp_script.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ bool CSharpLanguage::handles_global_class_type(const String &p_type) const {
447447

448448
String CSharpLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path, bool *r_is_abstract, bool *r_is_tool, bool *r_is_hidden) const {
449449
String class_name;
450-
GDMonoCache::managed_callbacks.ScriptManagerBridge_GetGlobalClassName(&p_path, r_base_type, r_icon_path, r_is_abstract, r_is_tool, &class_name);
450+
GDMonoCache::managed_callbacks.ScriptManagerBridge_GetGlobalClassName(&p_path, r_base_type, r_icon_path, r_is_abstract, r_is_tool, r_is_hidden, &class_name);
451451
return class_name;
452452
}
453453

modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/GlobalClassAttribute.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ namespace Godot
88
/// Exposes the target class as a global script class to Godot Engine.
99
/// </summary>
1010
[AttributeUsage(AttributeTargets.Class)]
11-
public sealed class GlobalClassAttribute : Attribute { }
11+
public sealed class GlobalClassAttribute : Attribute
12+
{
13+
/// <summary>
14+
/// Prevent the current class from appearing in the Create Node dialog.
15+
/// </summary>
16+
public bool Hidden { get; init; }
17+
}
1218
}

modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ManagedCallbacks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public unsafe struct ManagedCallbacks
1919
public delegate* unmanaged<godot_string_name*, IntPtr, IntPtr> ScriptManagerBridge_CreateManagedForGodotObjectBinding;
2020
public delegate* unmanaged<IntPtr, IntPtr, godot_variant**, int, godot_bool> ScriptManagerBridge_CreateManagedForGodotObjectScriptInstance;
2121
public delegate* unmanaged<IntPtr, godot_string_name*, void> ScriptManagerBridge_GetScriptNativeName;
22-
public delegate* unmanaged<godot_string*, godot_string*, godot_string*, godot_bool*, godot_bool*, godot_string*, void> ScriptManagerBridge_GetGlobalClassName;
22+
public delegate* unmanaged<godot_string*, godot_string*, godot_string*, godot_bool*, godot_bool*, godot_bool*, godot_string*, void> ScriptManagerBridge_GetGlobalClassName;
2323
public delegate* unmanaged<IntPtr, IntPtr, void> ScriptManagerBridge_SetGodotObjectPtr;
2424
public delegate* unmanaged<IntPtr, godot_string_name*, godot_variant**, int, godot_bool*, void> ScriptManagerBridge_RaiseEventSignal;
2525
public delegate* unmanaged<IntPtr, IntPtr, godot_bool> ScriptManagerBridge_ScriptIsOrInherits;

modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ internal static unsafe void GetScriptNativeName(IntPtr scriptPtr, godot_string_n
199199
}
200200

201201
[UnmanagedCallersOnly]
202-
internal static unsafe void GetGlobalClassName(godot_string* scriptPath, godot_string* outBaseType, godot_string* outIconPath, godot_bool* outIsAbstract, godot_bool* outIsTool, godot_string* outClassName)
202+
internal static unsafe void GetGlobalClassName(godot_string* scriptPath, godot_string* outBaseType, godot_string* outIconPath, godot_bool* outIsAbstract, godot_bool* outIsTool, godot_bool* outHidden, godot_string* outClassName)
203203
{
204204
// This method must always return the outBaseType for every script, even if the script is
205205
// not a global class. But if the script is not a global class it must return an empty
@@ -230,6 +230,15 @@ internal static unsafe void GetGlobalClassName(godot_string* scriptPath, godot_s
230230
}
231231
}
232232

233+
if (outHidden != null)
234+
{
235+
var globalClassAttr = scriptType.GetCustomAttributes(inherit: false)
236+
.OfType<GlobalClassAttribute>()
237+
.FirstOrDefault();
238+
239+
*outHidden = (globalClassAttr?.Hidden == true).ToGodotBool();
240+
}
241+
233242
if (outBaseType != null)
234243
{
235244
bool foundGlobalBaseScript = false;

modules/mono/mono_gd/gd_mono_cache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct ManagedCallbacks {
8484
using FuncScriptManagerBridge_CreateManagedForGodotObjectBinding = GCHandleIntPtr(GD_CLR_STDCALL *)(const StringName *, Object *);
8585
using FuncScriptManagerBridge_CreateManagedForGodotObjectScriptInstance = bool(GD_CLR_STDCALL *)(const CSharpScript *, Object *, const Variant **, int32_t);
8686
using FuncScriptManagerBridge_GetScriptNativeName = void(GD_CLR_STDCALL *)(const CSharpScript *, StringName *);
87-
using FuncScriptManagerBridge_GetGlobalClassName = void(GD_CLR_STDCALL *)(const String *, String *, String *, bool *, bool *, String *);
87+
using FuncScriptManagerBridge_GetGlobalClassName = void(GD_CLR_STDCALL *)(const String *, String *, String *, bool *, bool *, bool *, String *);
8888
using FuncScriptManagerBridge_SetGodotObjectPtr = void(GD_CLR_STDCALL *)(GCHandleIntPtr, Object *);
8989
using FuncScriptManagerBridge_RaiseEventSignal = void(GD_CLR_STDCALL *)(GCHandleIntPtr, const StringName *, const Variant **, int32_t, bool *);
9090
using FuncScriptManagerBridge_ScriptIsOrInherits = bool(GD_CLR_STDCALL *)(const CSharpScript *, const CSharpScript *);

0 commit comments

Comments
 (0)