diff --git a/RokojoriPlugin.cs b/RokojoriPlugin.cs index 594fb22..ad84a82 100644 --- a/RokojoriPlugin.cs +++ b/RokojoriPlugin.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Globalization; using System; using System.Data; +using Rokojori.Tools; namespace Rokojori { @@ -17,9 +18,9 @@ namespace Rokojori #else [Tool] public partial class RokojoriPlugin: EditorPlugin - { GizmoDrawerPlugin gizmoDrawerPlugin = new GizmoDrawerPlugin(); + GodotEditorInspectorTools inspectorTools = new GodotEditorInspectorTools(); public static readonly string path = "res://addons/rokojori_action_library"; @@ -123,6 +124,8 @@ namespace Rokojori AddNode3DGizmoPlugin( gizmoDrawerPlugin ); + inspectorTools.rokojoriPlugin = this; + inspectorTools.AddPlugins(); // var pePackedScene = GD.Load( ProblemsExplorerPath ); // if ( pePackedScene != null ) @@ -157,6 +160,9 @@ namespace Rokojori } RemoveNode3DGizmoPlugin( gizmoDrawerPlugin ); + + inspectorTools.rokojoriPlugin = this; + inspectorTools.RemovePlugins(); } bool wasDisposed = true; diff --git a/Runtime/Shading/Library/Noise.gdshaderinc b/Runtime/Shading/Library/Noise.gdshaderinc index ef7b6e8..8164aca 100644 --- a/Runtime/Shading/Library/Noise.gdshaderinc +++ b/Runtime/Shading/Library/Noise.gdshaderinc @@ -263,3 +263,14 @@ bool ditherDiscard( float ditherFadeValue, vec4 _FRAGCOORD ) vec3 magic = vec3( 0.06711056, 0.00583715, 52.9829189 ); return ditherFadeValue < 0.001 || ditherFadeValue < fract( magic.z * fract( dot( _FRAGCOORD.xy, magic.xy ) ) ); } + + +bool perlinDiscard( float ditherFadeValue, vec2 _FRAGCOORD, float fadeBlend ) +{ + + float scale = mapClamped( ditherFadeValue, 1.0, 1.0 - fadeBlend, 0.0, 1.0 ); + + float offset = perlin( _FRAGCOORD ) * scale; + + return ( ditherFadeValue + offset ) < 1.0; +} \ No newline at end of file diff --git a/Runtime/Shading/Shaders/Effects/Scanner/ScannerBase.gdshaderinc b/Runtime/Shading/Shaders/Effects/Scanner/ScannerBase.gdshaderinc index f8ecc0c..ee5cfdc 100644 --- a/Runtime/Shading/Shaders/Effects/Scanner/ScannerBase.gdshaderinc +++ b/Runtime/Shading/Shaders/Effects/Scanner/ScannerBase.gdshaderinc @@ -6,6 +6,7 @@ #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc" uniform vec4 albedo : source_color; +uniform float multiplyAlbedoByAlpha:hint_range(0,1) = 0; uniform float driver:hint_range(0,1) = 0; @@ -78,6 +79,11 @@ void fragment() float noise2 = perlin3D( relativeWorldVertex * noiseScale2 + ( noiseScroll2 + noiseScrollFromScanDirection2 * normalizedScanDir )* TIME ); noise2 = mix( 1, noise2, noiseAmount2 ); - ALBEDO = albedo.rgb * scanColor.rgb; - ALPHA = clamp01( albedo.a * scanColor.a * noise * noise2 ); + float alphaValue = clamp01( albedo.a * scanColor.a * noise * noise2 ); + + float alphaMultiply = mix( 1.0, alphaValue, multiplyAlbedoByAlpha ); + ALBEDO = albedo.rgb * scanColor.rgb * alphaMultiply; + + ALPHA = alphaValue; + } diff --git a/Runtime/Shading/Shaders/Effects/Scanner/ScannerVisualShader.tres b/Runtime/Shading/Shaders/Effects/Scanner/ScannerVisualShader.tres new file mode 100644 index 0000000..9a6c46d --- /dev/null +++ b/Runtime/Shading/Shaders/Effects/Scanner/ScannerVisualShader.tres @@ -0,0 +1,24 @@ +[gd_resource type="VisualShader" load_steps=2 format=3 uid="uid://cfpq68lhdwdmq"] + +[sub_resource type="VisualShaderNodeGlobalExpression" id="VisualShaderNodeGlobalExpression_gj0vb"] +size = Vector2(360, 160) +expression = "#include \"res://addons/rokojori_action_library/Runtime/Shading/Shaders/Effects/Scanner/ScannerBase.gdshaderinc\"" + +[resource] +code = "shader_type spatial; +render_mode blend_premul_alpha, depth_draw_never, depth_test_default, cull_back, diffuse_lambert, specular_schlick_ggx, unshaded; + + + +// GlobalExpression:0 + #include \"res://addons/rokojori_action_library/Runtime/Shading/Shaders/Effects/Scanner/ScannerBase.gdshaderinc\" +" +modes/blend = 4 +modes/depth_draw = 2 +flags/unshaded = true +nodes/vertex/2/node = SubResource("VisualShaderNodeGlobalExpression_gj0vb") +nodes/vertex/2/position = Vector2(-140, 60) +nodes/vertex/2/size = Vector2(360, 160) +nodes/vertex/2/input_ports = "" +nodes/vertex/2/output_ports = "" +nodes/vertex/2/expression = "#include \"res://addons/rokojori_action_library/Runtime/Shading/Shaders/Effects/Scanner/ScannerBase.gdshaderinc\"" diff --git a/Runtime/VFX/FlashVFX/FlashVFX.cs b/Runtime/VFX/FlashVFX/FlashVFX.cs index c10ef59..0ba5e88 100644 --- a/Runtime/VFX/FlashVFX/FlashVFX.cs +++ b/Runtime/VFX/FlashVFX/FlashVFX.cs @@ -10,6 +10,12 @@ namespace Rokojori [Export] public FlashPreset preset; + [Export, ReadOnly] + public string test = "3"; + + [Export, NamedArray ] + public FlareLayer[] layers = []; + [Export] public Node[] targets; diff --git a/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Pink Mana Charge Flash.tres b/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Pink Mana Charge Flash.tres index bc53891..64a3580 100644 --- a/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Pink Mana Charge Flash.tres +++ b/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Pink Mana Charge Flash.tres @@ -48,6 +48,7 @@ gradient = SubResource("Gradient_ad8tv") render_priority = 0 shader = ExtResource("4_gli2s") shader_parameter/albedo = Color(4.2130003, 4.2130003, 4.2130003, 1) +shader_parameter/multiplyAlbedoByAlpha = 0.0 shader_parameter/driver = 0.0 shader_parameter/position = Vector3(0, 0, 0) shader_parameter/direction = Vector3(0, 1, 0) diff --git a/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Rainbow Star Boost Flash.tres b/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Rainbow Star Boost Flash.tres index 65bdeab..4e37746 100644 --- a/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Rainbow Star Boost Flash.tres +++ b/Runtime/VFX/FlashVFX/FlashVFXPresets/Scanner/Rainbow Star Boost Flash.tres @@ -44,6 +44,7 @@ use_hdr = true render_priority = 0 shader = ExtResource("4_uu110") shader_parameter/albedo = Color(4.2130003, 4.2130003, 4.2130003, 1) +shader_parameter/multiplyAlbedoByAlpha = 0.0 shader_parameter/driver = 0.0 shader_parameter/position = Vector3(0, 0, 0) shader_parameter/direction = Vector3(0, 1, 0) diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttribute.cs b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttribute.cs new file mode 100644 index 0000000..da28438 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttribute.cs @@ -0,0 +1,7 @@ +using System; +namespace Rokojori; + +public class InfoAttribute : Attribute +{ + +} \ No newline at end of file diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttribute.cs.uid b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttribute.cs.uid new file mode 100644 index 0000000..ce50deb --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttribute.cs.uid @@ -0,0 +1 @@ +uid://umduhx2b15in diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttributeDrawer.cs b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttributeDrawer.cs new file mode 100644 index 0000000..5a0f5e6 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttributeDrawer.cs @@ -0,0 +1,20 @@ +using System; +using Godot; + + +namespace Rokojori.Tools; + + +#if TOOLS +public partial class InfoAttributeDrawer : GodotEditorAttributeDrawer +{ + protected override Control GetPropertyEditor( + Variant.Type type, string name, PropertyHint hintType, string hintString, + PropertyUsageFlags usageFlags, bool wide, object value + ) + { + return new Label() { Text = $"{ value.ToString() ?? "" }" }; + } + +} +#endif \ No newline at end of file diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttributeDrawer.cs.uid b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttributeDrawer.cs.uid new file mode 100644 index 0000000..fd1e2ec --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/Info/InfoAttributeDrawer.cs.uid @@ -0,0 +1 @@ +uid://cxgt07gnemhdw diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttribute.cs b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttribute.cs new file mode 100644 index 0000000..8040f70 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttribute.cs @@ -0,0 +1,7 @@ +using System; +namespace Rokojori; + +public class NamedArrayAttribute : Attribute +{ + +} \ No newline at end of file diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttribute.cs.uid b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttribute.cs.uid new file mode 100644 index 0000000..b4ff552 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttribute.cs.uid @@ -0,0 +1 @@ +uid://co7psqyxy1up7 diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttributeDrawer.cs b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttributeDrawer.cs new file mode 100644 index 0000000..a25d525 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttributeDrawer.cs @@ -0,0 +1,117 @@ +using System; +using Godot; +using System.Collections.Generic; + +namespace Rokojori.Tools; + + +#if TOOLS + + +[Tool] + +public partial class NamedArrayEditor:EditorProperty +{ + VBoxContainer _container; + List _values = []; + bool _updating = false; + Type _arrayItemType; + + public NamedArrayEditor( Type arrayItemType ) + { + _container = new VBoxContainer(); + _arrayItemType = arrayItemType; + AddChild( _container ); + AddFocusable( _container ); + } + + + public override void _UpdateProperty() + { + _container.DestroyChildren(); + + var value = GetEditedObject().Get( GetEditedProperty() ).AsGodotArray(); + + _updating = true; + + for ( int i = 0; i < value.Count; i++ ) + { + var hbox = new HBoxContainer(); + + var label = new Label(); + label.Text = ( i + 1 ) + ":"; + hbox.AddChild( label ); + + var item = value[ i ]; + var editor = EditorInspector.InstantiatePropertyEditor( + (GodotObject) item, item.VariantType, + "", PropertyHint.None, "", + (uint) PropertyUsageFlags.Editor, false + ); + + editor.UpdateProperty(); + hbox.AddChild( editor ); + + _container.AddChild( hbox ); + + } + + var button = new Button(); + button.Text = "+"; + + button.Pressed += ()=> + { + var array = GetEditedObject().Get( GetEditedProperty() ).AsGodotArray(); + + // array.Add( Variant.From<( null ) ); + }; + + _container.AddChild( button ); + + + _updating = false; + } + + // Variant CreateDefaultValue( Type type ) + // { + // if ( typeof( int ) == type ) + // { + // return 0; + // } + + // if ( typeof( float ) == type ) + // { + // return 0f; + // } + + // if ( typeof( bool ) == type ) + // { + // return false; + // } + + // if ( typeof( string ) == type ) + // { + // return ""; + // } + + + // } + +} + + +public partial class NamedArrayAttributeDrawer : GodotEditorAttributeDrawer +{ + protected override Control GetPropertyEditor( + Variant.Type type, string name, PropertyHint hintType, string hintString, + PropertyUsageFlags usageFlags, bool wide, object value + ) + { + var itemType = ReflectionHelper.GetDataMemberInfo( godotObject, name ).GetType().GetElementType(); + return new NamedArrayEditor( itemType ); + // var typeName = value == null ? "null" : value.GetType().Name; + // return new Label() { Text = typeName }; + } + +} +#endif \ No newline at end of file diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttributeDrawer.cs.uid b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttributeDrawer.cs.uid new file mode 100644 index 0000000..ff5e762 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/NamedArray/NamedArrayAttributeDrawer.cs.uid @@ -0,0 +1 @@ +uid://b8buka2dlp53x diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttribute.cs b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttribute.cs new file mode 100644 index 0000000..a4975fe --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttribute.cs @@ -0,0 +1,7 @@ +using System; +namespace Rokojori; + +public class ReadOnlyAttribute : Attribute +{ + +} \ No newline at end of file diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttribute.cs.uid b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttribute.cs.uid new file mode 100644 index 0000000..c79850b --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttribute.cs.uid @@ -0,0 +1 @@ +uid://e44nnts2vx27 diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttributeDrawer.cs b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttributeDrawer.cs new file mode 100644 index 0000000..857a753 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttributeDrawer.cs @@ -0,0 +1,20 @@ +using System; +using Godot; + + +namespace Rokojori.Tools; + + +#if TOOLS +public partial class ReadOnlyAttributeDrawer : GodotEditorAttributeDrawer +{ + protected override Control GetPropertyEditor( + Variant.Type type, string name, PropertyHint hintType, string hintString, + PropertyUsageFlags usageFlags, bool wide, object value + ) + { + return new Label() { Text = $"{name}: { value.ToString() ?? "null" }" }; + } + +} +#endif \ No newline at end of file diff --git a/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttributeDrawer.cs.uid b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttributeDrawer.cs.uid new file mode 100644 index 0000000..096d759 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/AttributeDrawers/ReadOnly/ReadOnlyAttributeDrawer.cs.uid @@ -0,0 +1 @@ +uid://cfpqhdrn3rcjb diff --git a/Tools/godot-editor-inspector-tools/GodotEditorAttributeDrawer.cs b/Tools/godot-editor-inspector-tools/GodotEditorAttributeDrawer.cs index 8c856d6..9238204 100644 --- a/Tools/godot-editor-inspector-tools/GodotEditorAttributeDrawer.cs +++ b/Tools/godot-editor-inspector-tools/GodotEditorAttributeDrawer.cs @@ -18,8 +18,14 @@ public abstract partial class GodotEditorAttributeDrawer : GodotEditorInspect if ( GetValueOfMemberWithAttribute( obj, name, typeof(A), out object value ) ) { - var control = GetPropertyEditor( type, name, hintType, hintString, usageFlags, wide, value ); - AddPropertyEditor( name, control ); + var editor = GetPropertyEditor( type, name, hintType, hintString, usageFlags, wide, value ); + + if ( editor == null ) + { + return base._ParseProperty( obj, type, name, hintType, hintString, usageFlags, wide ); + } + + AddPropertyEditor( name, editor ); return true; } @@ -27,6 +33,7 @@ public abstract partial class GodotEditorAttributeDrawer : GodotEditorInspect return base._ParseProperty( obj, type, name, hintType, hintString, usageFlags, wide ); } + protected abstract Control GetPropertyEditor( Variant.Type type, string name, PropertyHint hintType, string hintString, PropertyUsageFlags usageFlags, bool wide, object value diff --git a/Tools/godot-editor-inspector-tools/GodotEditorInspectorTools.cs b/Tools/godot-editor-inspector-tools/GodotEditorInspectorTools.cs new file mode 100644 index 0000000..9780a27 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/GodotEditorInspectorTools.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using Godot; +using System.Linq; + +namespace Rokojori.Tools; + +public class GodotEditorInspectorTools +{ + List registeredPlugins = []; + public RokojoriPlugin rokojoriPlugin; + + public void AddPlugins() + { + registeredPlugins = new List(); + + // var plugins = GetGodotEditorInspectorPluginsInAssembly(); + + List plugins = + [ + new InfoAttributeDrawer(), + new ReadOnlyAttributeDrawer(), + + new NamedArrayAttributeDrawer() + ]; + + plugins.ForEach( + p => + { + try + { + rokojoriPlugin.AddInspectorPlugin( p ); + RJLog.Log( $"Registered inspector for: {p.GetType().FullName}" ); + } + catch ( Exception e ) + { + RJLog.Error( $"Error adding inspector automatically: {p.GetType().Name}. Skipping. {e}"); + return; + } + + registeredPlugins.Add( p ); + } + ); + } + + + + public void RemovePlugins() + { + registeredPlugins.ForEach( rokojoriPlugin.RemoveInspectorPlugin ); + } + + static bool IsSubclassOfGeneric( Type type, Type genericBaseType ) + { + var it = type.BaseType; + + while ( it != null ) + { + if ( it.IsGenericType && it.GetGenericTypeDefinition() == genericBaseType ) + { + return true; + } + + it = it.BaseType; + } + + return false; + } + + List GetGodotEditorInspectorPluginsInAssembly() + { + var results = new List(); + var baseType = typeof( GodotEditorInspector<> ); + + foreach ( var assembly in AppDomain.CurrentDomain.GetAssemblies() ) + { + try + { + var types = assembly.GetTypes().Where( t => t.IsClass && ! t.IsAbstract && IsSubclassOfGeneric( t, baseType ) ); + + foreach ( var type in types ) + { + try + { + if ( Activator.CreateInstance( type ) is EditorInspectorPlugin pluginInstance ) + { + results.Add(pluginInstance); + } + } + catch ( Exception e ) + { + RJLog.Error( $"Unable creating instance of type {type.Name}. {e.Message}" ); + } + } + } + catch ( ReflectionTypeLoadException e ) + { + RJLog.Error( $"Unable to load types from assembly: {assembly.FullName}. {e.Message} "); + } + } + + return results; + } +} \ No newline at end of file diff --git a/Tools/godot-editor-inspector-tools/GodotEditorInspectorTools.cs.uid b/Tools/godot-editor-inspector-tools/GodotEditorInspectorTools.cs.uid new file mode 100644 index 0000000..1b68db8 --- /dev/null +++ b/Tools/godot-editor-inspector-tools/GodotEditorInspectorTools.cs.uid @@ -0,0 +1 @@ +uid://bfq4t4jyytoft