-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from goostengine/grid-layer
- Loading branch information
Showing
7 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class_name GridLayer, "icon_grid_layer.svg" extends CanvasLayer | ||
tool | ||
|
||
# This class allows to display infinite grid at run-time, similarly to how | ||
# editor displays grid with snapping is enabled in canvas editor. | ||
# For example, when using Camera2D, the grid's origin offset and scale are | ||
# going to be updated automatically. | ||
|
||
func _init(): | ||
# Do not show grid on top, since we have transparent grid by default. | ||
layer = -1 | ||
|
||
|
||
func _ready(): | ||
if not Engine.editor_hint: | ||
return | ||
|
||
# Instantiate a default GridRect with transparent background. | ||
var grid = GridRect.new() | ||
add_child(grid) | ||
if get_parent(): | ||
if get_parent().filename: | ||
grid.owner = get_parent() | ||
else: | ||
grid.owner = get_parent().owner | ||
|
||
grid.origin_axes_visible = true | ||
|
||
grid.anchor_right = 1.0 | ||
grid.anchor_bottom = 1.0 | ||
grid.margin_right = 0.0 | ||
grid.margin_bottom = 0.0 | ||
|
||
var bc = Color() | ||
bc.a = 0.0 # Transparent by default. | ||
grid.set("custom_colors/background", bc) | ||
# Use default colors from GraphEdit. | ||
grid.set("custom_colors/line_cell", grid.get_color("grid_minor", "GraphEdit")) | ||
grid.set("custom_colors/line_division", grid.get_color("grid_major", "GraphEdit")) | ||
|
||
|
||
func _process(_delta): | ||
for idx in get_child_count(): | ||
var grid = get_child(idx) | ||
if not grid is GridRect: | ||
continue | ||
|
||
grid.origin_offset = get_viewport().canvas_transform.origin | ||
grid.origin_scale = get_viewport().canvas_transform.get_scale() | ||
|
||
|
||
func _get_configuration_warning(): | ||
if not has_grid(): | ||
return "GridLayer must have at least one GridRect added as a child." | ||
return "" | ||
|
||
|
||
func has_grid(): | ||
for idx in get_child_count(): | ||
if get_child(idx) is GridRect: | ||
return true | ||
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tool | ||
extends EditorPlugin |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/icon_grid_layer.svg-4d36d2a91fa21a54de7ea7a412dae37f.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/grid_layer/icon_grid_layer.svg" | ||
dest_files=[ "res://.import/icon_grid_layer.svg-4d36d2a91fa21a54de7ea7a412dae37f.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[plugin] | ||
|
||
name="GridLayer" | ||
description="Display infinite grid at run-time" | ||
author="Goost" | ||
version="0.1" | ||
script="grid_layer_plugin.gd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters