init
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
## Only drawing polygons is fastest
|
||||
@export var draw_fills := true
|
||||
|
||||
## Drawing strokes with cutouts requires extra compute, but still ok
|
||||
@export var draw_strokes := true
|
||||
|
||||
## Redrawing navigation is fast, but would slow down agents
|
||||
@export var draw_navigation := false
|
||||
|
||||
## Redrawing collision polygons is heavy
|
||||
@export var draw_collision := false
|
||||
|
||||
|
||||
var foobar := false
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
add_ellipse(event.position)
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
|
||||
add_clip_to_ellipses(event.position)
|
||||
|
||||
|
||||
func add_clip_to_ellipses(at_pos: Vector2):
|
||||
var ellipse : ScalableVectorShape2D = null
|
||||
for ch in get_children():
|
||||
if ch is ScalableVectorShape2D and ch.shape_type == ScalableVectorShape2D.ShapeType.ELLIPSE and ch.clipped_polygon_has_point(at_pos):
|
||||
ellipse = ch
|
||||
|
||||
if not ellipse:
|
||||
return
|
||||
|
||||
foobar = not foobar
|
||||
var rect = ScalableVectorShape2D.new()
|
||||
rect.name = "ClipRect"
|
||||
rect.update_curve_at_runtime = true
|
||||
rect.shape_type = ScalableVectorShape2D.ShapeType.RECT
|
||||
rect.position = at_pos - ellipse.position
|
||||
rect.size = Vector2(200, 40) if foobar else Vector2(40, 200)
|
||||
rect.rx = 20
|
||||
rect.ry = 20
|
||||
ellipse.add_child(rect, true)
|
||||
ellipse.add_clip_path(rect)
|
||||
|
||||
|
||||
func add_ellipse(at_pos: Vector2):
|
||||
var ellipse = ScalableVectorShape2D.new()
|
||||
# make sure it will rerender in game
|
||||
ellipse.name = "Ellipse"
|
||||
ellipse.update_curve_at_runtime = true
|
||||
ellipse.shape_type = ScalableVectorShape2D.ShapeType.ELLIPSE
|
||||
ellipse.position = at_pos
|
||||
ellipse.size = Vector2(500, 250)
|
||||
|
||||
if draw_fills:
|
||||
# assign a Polygon2D as fill
|
||||
ellipse.polygon = Polygon2D.new()
|
||||
ellipse.polygon.color = Color.WHITE
|
||||
ellipse.add_child(ellipse.polygon)
|
||||
|
||||
if draw_strokes:
|
||||
# assign a Line2D as stroke
|
||||
ellipse.line = Line2D.new()
|
||||
ellipse.stroke_color = Color.BLACK
|
||||
ellipse.add_child(ellipse.line)
|
||||
|
||||
if draw_collision:
|
||||
# assign a collision object to hold new collision polygons
|
||||
ellipse.collision_object = StaticBody2D.new()
|
||||
ellipse.add_child(ellipse.collision_object)
|
||||
|
||||
if draw_navigation:
|
||||
ellipse.navigation_region = NavigationRegion2D.new()
|
||||
ellipse.add_child(ellipse.navigation_region)
|
||||
|
||||
add_child(ellipse, true)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c8rves0r1i4up
|
||||
@@ -0,0 +1,44 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c2k8nyelxdgi3"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c8rves0r1i4up" path="res://addons/curved_lines_2d/examples/add_shapes_programmatically/click_ellipse.gd" id="1_1ehuy"]
|
||||
[ext_resource type="Script" uid="uid://dr5dl1my0r0rl" path="res://addons/curved_lines_2d/examples/add_shapes_programmatically/label.gd" id="2_a3wah"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_1ehuy"]
|
||||
font_size = 32
|
||||
outline_size = 4
|
||||
outline_color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ClickEllipse" type="Node2D" parent="."]
|
||||
script = ExtResource("1_1ehuy")
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -217.0
|
||||
offset_top = -22.5
|
||||
offset_right = 217.0
|
||||
offset_bottom = 22.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
text = "- Left click to add an ellipse -
|
||||
|
||||
- Right click to cut a hole in the ellipse -"
|
||||
label_settings = SubResource("LabelSettings_1ehuy")
|
||||
horizontal_alignment = 1
|
||||
script = ExtResource("2_a3wah")
|
||||
@@ -0,0 +1,7 @@
|
||||
extends Label
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if modulate.a > 0.0:
|
||||
modulate.a -= delta * 0.25
|
||||
else:
|
||||
queue_free()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dr5dl1my0r0rl
|
||||
Reference in New Issue
Block a user