pulsing cursor #5
This commit is contained in:
parent
68dd73fb95
commit
503caa4430
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
shader = ExtResource( 1 )
|
shader = ExtResource( 1 )
|
||||||
shader_param/lowColor = Color( 1, 0.960784, 0, 1 )
|
shader_param/lowColor = Color( 0, 0, 0, 0 )
|
||||||
shader_param/highColor = Color( 0.921569, 0, 1, 1 )
|
shader_param/highColor = Color( 0, 0.976471, 1, 1 )
|
||||||
shader_param/t = null
|
shader_param/t = null
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=7 format=2]
|
[gd_scene load_steps=8 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://nodes/grid.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://nodes/grid.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://nodes/grid_cursor.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://nodes/grid_cursor.tscn" type="PackedScene" id=2]
|
||||||
|
@ -7,16 +7,20 @@
|
||||||
[ext_resource path="res://nodes/interaction_mode.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://nodes/interaction_mode.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://nodes/ui/build_mode_ui.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://nodes/ui/build_mode_ui.tscn" type="PackedScene" id=6]
|
||||||
|
|
||||||
|
[sub_resource type="Curve" id=1]
|
||||||
|
_data = [ Vector2( 0, 0 ), 0.0, 5.0, 0, 0, Vector2( 0.5, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), -4.0, 0.0, 0, 0 ]
|
||||||
|
|
||||||
[node name="Root" type="Node"]
|
[node name="Root" type="Node"]
|
||||||
|
|
||||||
|
[node name="Clock" parent="." instance=ExtResource( 4 )]
|
||||||
|
_autoTick = true
|
||||||
|
|
||||||
[node name="Grid" parent="." instance=ExtResource( 1 )]
|
[node name="Grid" parent="." instance=ExtResource( 1 )]
|
||||||
DiffusionCoefficient = 0.1
|
DiffusionCoefficient = 0.1
|
||||||
|
|
||||||
[node name="Cursor" parent="." instance=ExtResource( 2 )]
|
[node name="Cursor" parent="." instance=ExtResource( 2 )]
|
||||||
Grid = NodePath("../Grid")
|
Grid = NodePath("../Grid")
|
||||||
|
_pulseShape = SubResource( 1 )
|
||||||
[node name="Clock" parent="." instance=ExtResource( 4 )]
|
|
||||||
_autoTick = true
|
|
||||||
|
|
||||||
[node name="Interaction Mode" parent="." instance=ExtResource( 5 )]
|
[node name="Interaction Mode" parent="." instance=ExtResource( 5 )]
|
||||||
|
|
||||||
|
@ -31,6 +35,7 @@ anchor_bottom = 1.0
|
||||||
[connection signal="OnPauseChanged" from="Clock" to="UI/Debug" method="_on_Clock_OnPauseChanged"]
|
[connection signal="OnPauseChanged" from="Clock" to="UI/Debug" method="_on_Clock_OnPauseChanged"]
|
||||||
[connection signal="OnTick" from="Clock" to="Grid" method="_on_Clock_OnTick"]
|
[connection signal="OnTick" from="Clock" to="Grid" method="_on_Clock_OnTick"]
|
||||||
[connection signal="OnTick" from="Clock" to="UI/Debug" method="_on_Clock_OnTick"]
|
[connection signal="OnTick" from="Clock" to="UI/Debug" method="_on_Clock_OnTick"]
|
||||||
|
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="Cursor" method="_on_Interaction_Mode_OnInteractionModeChanged"]
|
||||||
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="UI/Debug" method="_on_Interaction_Mode_OnInteractionModeChanged"]
|
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="UI/Debug" method="_on_Interaction_Mode_OnInteractionModeChanged"]
|
||||||
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="UI/Build Mode" method="_on_Interaction_Mode_OnInteractionModeChanged"]
|
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="UI/Build Mode" method="_on_Interaction_Mode_OnInteractionModeChanged"]
|
||||||
[connection signal="OnExit" from="UI/Build Mode" to="Interaction Mode" method="Reset"]
|
[connection signal="OnExit" from="UI/Build Mode" to="Interaction Mode" method="Reset"]
|
||||||
|
|
|
@ -8,6 +8,17 @@ public class GridCursor : Sprite
|
||||||
private WorldGrid _grid;
|
private WorldGrid _grid;
|
||||||
private ShaderMaterial _material;
|
private ShaderMaterial _material;
|
||||||
|
|
||||||
|
#region Animation
|
||||||
|
[Export]
|
||||||
|
private Curve _pulseShape;
|
||||||
|
[Export]
|
||||||
|
private float _pulseRate = 1.0f;
|
||||||
|
private float PulsePeriod => 1.0f / _pulseRate;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private float _elapsed = 0.0f;
|
||||||
|
private bool _pulsing = false;
|
||||||
|
|
||||||
private const string T = "t";
|
private const string T = "t";
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
|
@ -48,4 +59,33 @@ public class GridCursor : Sprite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _Process(float delta)
|
||||||
|
{
|
||||||
|
_elapsed += delta * _pulseRate;
|
||||||
|
|
||||||
|
if (!_pulsing)
|
||||||
|
{
|
||||||
|
_material.SetShaderParam(T, 1f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var a = _pulseShape.Interpolate(_elapsed % 1.0f);
|
||||||
|
_material.SetShaderParam(T, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void _on_Interaction_Mode_OnInteractionModeChanged(InteractionMode.Mode oldMode, InteractionMode.Mode newMode)
|
||||||
|
{
|
||||||
|
switch (newMode)
|
||||||
|
{
|
||||||
|
case InteractionMode.Mode.SELECT:
|
||||||
|
_pulsing = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case InteractionMode.Mode.BUILD:
|
||||||
|
_pulsing = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue