connections
This commit is contained in:
23
addons/linepath2d/icon.svg
Normal file
23
addons/linepath2d/icon.svg
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Made by Claudio Z. 2024 (cloudofoz) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#8DA5F3;}
|
||||
</style>
|
||||
<g>
|
||||
<g>
|
||||
<path class="st0" d="M2.9,1.2c1.9,0,3.8,0,5.7,0.3c1,0.1,1.9,0.3,3,0.7c0.5,0.2,1,0.4,1.7,1c0.3,0.3,0.7,0.8,0.6,1.6
|
||||
c-0.1,0.8-0.6,1.1-0.9,1.4l0,0c-0.1,0.1-0.2,0.1-0.3,0.2C11,6.8,9.4,7.4,8,8.1c-1.5,0.7-2.9,1.6-3.8,2.7c-0.2,0.3-0.4,0.6-0.5,0.9
|
||||
c0,0.1-0.1,0.3-0.1,0.4l0,0c0,0,0-0.1,0-0.1c0-0.1,0-0.1-0.1-0.2c0-0.1-0.1-0.1-0.1-0.1c0,0,0,0,0.1,0.1C4,12,4.9,12.1,5.7,12.1
|
||||
c1.6,0.1,3.3-0.1,5-0.4c0.3-0.1,0.6,0.1,0.6,0.4c0.1,0.3-0.1,0.5-0.4,0.6c-1.7,0.5-3.4,0.8-5.2,0.8c-0.9,0-1.8,0-2.8-0.3
|
||||
c-0.1,0-0.3-0.1-0.5-0.2c-0.1-0.1-0.2-0.1-0.3-0.3C2,12.6,2,12.5,2,12.4c0-0.1,0-0.1,0-0.2l0-0.1c0-0.4,0.1-0.6,0.1-0.9
|
||||
c0.2-0.5,0.4-1,0.7-1.4C3.9,8.2,5.5,7.2,7,6.3c1.6-0.9,3.2-1.6,4.8-2.3l-0.3,0.2c0,0-0.1,0-0.1,0.3c0,0.3,0.1,0.4,0.1,0.4
|
||||
c-0.1-0.1-0.4-0.2-0.8-0.3C10,4.4,9.1,4.2,8.3,4.2C6.5,4.1,4.8,4.1,3,4.2l0,0C2.1,4.3,1.4,3.7,1.4,2.9C1.3,2,1.9,1.3,2.9,1.2
|
||||
C2.8,1.3,2.8,1.2,2.9,1.2z"/>
|
||||
<g>
|
||||
<polygon class="st0" points="11,15.4 15,10.5 8.8,9.5 "/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
43
addons/linepath2d/icon.svg.import
Normal file
43
addons/linepath2d/icon.svg.import
Normal file
@@ -0,0 +1,43 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c0qiq6063dp2k"
|
||||
path="res://.godot/imported/icon.svg-b9b36016f8243188eed518770c277664.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/linepath2d/icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-b9b36016f8243188eed518770c277664.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
248
addons/linepath2d/linepath2d.gd
Normal file
248
addons/linepath2d/linepath2d.gd
Normal file
@@ -0,0 +1,248 @@
|
||||
# Copyright (C) 2024 Claudio Z. (cloudofoz)
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
@tool
|
||||
extends Path2D
|
||||
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
# CONSTANTS
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
# Enable the creation of a default curve when this class is instantiated
|
||||
const LP_CREATE_DEFAULT_CURVE = true
|
||||
|
||||
# Enable the creation of a default curve width profile when this class is instatiated
|
||||
const LP_CREATE_DEFAULT_PROFILE = true
|
||||
|
||||
# Size in pixels of the default curve
|
||||
const LP_DEFAULT_CURVE_SIZE = 400
|
||||
|
||||
# Size in pixels of the default curve width
|
||||
const LP_DEFAULT_CURVE_WIDTH = 25
|
||||
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
# PRIVATE VARIABLES
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
var lp_line: Line2D = null
|
||||
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
# PUBLIC VARIABLES
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
@export_category("LinePath2D")
|
||||
|
||||
## Sets the Path2D 'Curve2D' resource
|
||||
##
|
||||
## Note: Please, use this variable to change the curve and not the original Path2D property
|
||||
## Reason: It's not currently possible to override the parent setter:
|
||||
## 'Path2D.set_curve(value)'.
|
||||
## Reference: https://github.com/godotengine/godot-proposals/issues/8045
|
||||
@export var _curve: Curve2D = null:
|
||||
set(value):
|
||||
if(curve && curve.changed.is_connected(lp_build_line)):
|
||||
curve.changed.disconnect(lp_build_line)
|
||||
curve = value
|
||||
if(curve):
|
||||
curve.changed.connect(lp_build_line)
|
||||
lp_build_line()
|
||||
get:
|
||||
return curve
|
||||
|
||||
## Sets the width of the curve
|
||||
@export var width: float = LP_DEFAULT_CURVE_WIDTH:
|
||||
set(value):
|
||||
if(!lp_line): return
|
||||
lp_line.width = value
|
||||
#lp_line.draw.emit()
|
||||
get:
|
||||
return lp_line.width if lp_line else LP_DEFAULT_CURVE_WIDTH
|
||||
|
||||
## Use this [Curve] to modify the line width profile
|
||||
@export var width_profile: Curve:
|
||||
set(value):
|
||||
if(!lp_line): return
|
||||
lp_line.width_curve = value
|
||||
#lp_line.draw.emit()
|
||||
get:
|
||||
return lp_line.width_curve if lp_line else null
|
||||
|
||||
|
||||
@export_group("Fill", "fill_")
|
||||
|
||||
## Default path color
|
||||
@export var fill_default_color: Color = Color.WHITE:
|
||||
set(value):
|
||||
if(lp_line): lp_line.default_color = value
|
||||
get:
|
||||
return lp_line.default_color if lp_line else Color.WHITE
|
||||
|
||||
## Fill the path with a gradient
|
||||
@export var fill_gradient: Gradient = null:
|
||||
set(value):
|
||||
if(lp_line): lp_line.gradient = value
|
||||
get:
|
||||
return lp_line.gradient if lp_line else null
|
||||
|
||||
## Fill the path with a texture
|
||||
@export var fill_texture: Texture2D = null:
|
||||
set(value):
|
||||
if(lp_line): lp_line.texture = value
|
||||
get:
|
||||
return lp_line.texture if lp_line else null
|
||||
|
||||
## Change the texture fill mode
|
||||
@export_enum("None: 0", "Tile: 1", "Stretch: 2")
|
||||
var fill_texture_mode: int = Line2D.LINE_TEXTURE_NONE:
|
||||
set(value):
|
||||
if(lp_line): lp_line.texture_mode = value
|
||||
get:
|
||||
return lp_line.texture_mode if lp_line else Line2D.LINE_TEXTURE_NONE
|
||||
|
||||
## Sets the material (CanvasMaterial2D or ShaderMaterial)
|
||||
#@export var fill_material: Material = null:
|
||||
#set(value):
|
||||
#if(!lp_line): return
|
||||
#if(!(value is CanvasItemMaterial) && !(value is ShaderMaterial)):
|
||||
#lp_line.material = null
|
||||
#return
|
||||
#lp_line.material = value
|
||||
#get:
|
||||
#return lp_line.material if lp_line else null
|
||||
|
||||
|
||||
@export_group("Capping", "cap_")
|
||||
|
||||
## The style of connection between segments of the polyline
|
||||
@export_enum("Sharp: 0", "Bevel: 1", "Round: 2")
|
||||
var cap_joint_mode: int = Line2D.LINE_JOINT_SHARP:
|
||||
set(value):
|
||||
if(lp_line): lp_line.joint_mode = value
|
||||
get:
|
||||
return lp_line.joint_mode if lp_line else 0
|
||||
|
||||
## The style of the beginning of the polyline
|
||||
@export_enum("None: 0", "Box: 1", "Round: 1")
|
||||
var cap_begin_cap: int = Line2D.LINE_CAP_NONE:
|
||||
set(value):
|
||||
if(lp_line): lp_line.begin_cap_mode = value
|
||||
get:
|
||||
return lp_line.begin_cap_mode if lp_line else Line2D.LINE_CAP_NONE
|
||||
|
||||
## The style of the ending of the polyline
|
||||
@export_enum("None: 0", "Box: 1", "Round: 1")
|
||||
var cap_end_cap: int = Line2D.LINE_CAP_NONE:
|
||||
set(value):
|
||||
if(lp_line): lp_line.end_cap_mode = value
|
||||
get:
|
||||
return lp_line.end_cap_mode if lp_line else Line2D.LINE_CAP_NONE
|
||||
|
||||
## If true and the polyline has more than two segments,
|
||||
## the first and the last point will be connected by a segment
|
||||
@export var cap_close_curve: bool = false:
|
||||
set(value):
|
||||
if(lp_line): lp_line.closed = value
|
||||
get:
|
||||
return lp_line.closed if lp_line else false
|
||||
|
||||
|
||||
@export_group("Border", "border_")
|
||||
|
||||
## Determines the miter limit of the polyline
|
||||
@export var border_sharp_limit: float = 2.0:
|
||||
set(value):
|
||||
if(lp_line): lp_line.sharp_limit = value
|
||||
get:
|
||||
return lp_line.sharp_limit if lp_line else 2.0
|
||||
|
||||
## The smoothness of the rounded joints and caps
|
||||
@export var border_round_precision: int = 8:
|
||||
set(value):
|
||||
if(lp_line): lp_line.round_precision = value
|
||||
get:
|
||||
return lp_line.round_precision if lp_line else 8
|
||||
|
||||
## If true the polyline border will be antialiased
|
||||
## Note: Antialiased polylines are not accelerated by batching
|
||||
@export var border_antialiased: bool = false:
|
||||
set(value):
|
||||
if(lp_line): lp_line.antialiased = value
|
||||
get:
|
||||
return lp_line.antialiased if lp_line else false
|
||||
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
# VIRTUAL METHODS
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
func _init() -> void:
|
||||
if(!lp_line):
|
||||
lp_line = Line2D.new()
|
||||
|
||||
func _ready() -> void:
|
||||
lp_clear_duplicated_internal_children()
|
||||
lp_line.set_meta("__lp2d_internal__", true)
|
||||
add_child(lp_line)
|
||||
if(!curve || curve.point_count < 2):
|
||||
curve = lp_create_default_curve(LP_DEFAULT_CURVE_SIZE)
|
||||
if(!lp_line.width_curve):
|
||||
lp_line.width_curve = lp_create_default_profile(LP_DEFAULT_CURVE_WIDTH)
|
||||
lp_build_line()
|
||||
if(curve && !curve.changed.is_connected(lp_build_line)):
|
||||
curve.changed.connect(lp_build_line)
|
||||
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
# PRIVATE METHODS
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
func lp_create_default_curve(size:int) -> Curve2D:
|
||||
if(!LP_CREATE_DEFAULT_CURVE): return null
|
||||
var c = Curve2D.new()
|
||||
c.add_point(Vector2.ZERO, Vector2.ZERO, Vector2(size,0))
|
||||
c.add_point(Vector2(size,size), Vector2(-size,0), Vector2.ZERO)
|
||||
return c
|
||||
|
||||
func lp_create_default_profile(size:float) -> Curve:
|
||||
if(!LP_CREATE_DEFAULT_PROFILE): return null
|
||||
var c = Curve.new()
|
||||
c.add_point(Vector2.ZERO)
|
||||
c.add_point(Vector2(0.5,1))
|
||||
c.add_point(Vector2(1.0, 0))
|
||||
return c
|
||||
|
||||
func lp_build_line() -> void:
|
||||
if(!lp_line):
|
||||
return
|
||||
if(!curve || curve.point_count < 2):
|
||||
lp_line.clear_points()
|
||||
return
|
||||
lp_line.points = curve.get_baked_points()
|
||||
|
||||
func lp_clear_duplicated_internal_children():
|
||||
for c in get_children():
|
||||
if(c.get_meta("__lp2d_internal__", false)):
|
||||
c.queue_free()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
# KNOWN BUGS/LIMITATIONS:
|
||||
#
|
||||
# *) Changing the 'Path2D.curve' in the editor will result in an unexpected behaviour
|
||||
# TO-FIX: Overriding the default setter 'Path2D.set_curve(value)', it's not currently possible.
|
||||
# PROPOSAL: https://github.com/godotengine/godot-proposals/issues/8045
|
||||
1
addons/linepath2d/linepath2d.gd.uid
Normal file
1
addons/linepath2d/linepath2d.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b7ni0w4diekq4
|
||||
7
addons/linepath2d/plugin.cfg
Normal file
7
addons/linepath2d/plugin.cfg
Normal file
@@ -0,0 +1,7 @@
|
||||
[plugin]
|
||||
|
||||
name="LinePath2D"
|
||||
description="This simple Godot addon brings the 'Line2D' drawing capabilities to 'Path2D' curves."
|
||||
author="cloudofoz"
|
||||
version="0.10"
|
||||
script="plugin.gd"
|
||||
31
addons/linepath2d/plugin.gd
Normal file
31
addons/linepath2d/plugin.gd
Normal file
@@ -0,0 +1,31 @@
|
||||
# Copyright (C) 2024 Claudio Z. (cloudofoz)
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
|
||||
func _enter_tree() -> void:
|
||||
## This simple addon brings the 'Line2D' drawing capabilities to 'Path2D' curves.
|
||||
add_custom_type("LinePath2D", "Path2D", preload("linepath2d.gd"), preload("icon.svg"))
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
remove_custom_type("LinePath2D")
|
||||
1
addons/linepath2d/plugin.gd.uid
Normal file
1
addons/linepath2d/plugin.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://or7xl32s36qq
|
||||
Reference in New Issue
Block a user