Skip to content

Commit

Permalink
Add tentative editor camera render layer selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Razoric480 committed Aug 16, 2020
1 parent 85f7975 commit 14ba87e
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 211 deletions.
368 changes: 161 additions & 207 deletions godot/Demos/AdvancedToonDemo.tscn

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions godot/Demos/XRay3DDemo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ material/0 = SubResource( 9 )
[node name="teeth1" parent="rat" index="3"]
material/0 = SubResource( 9 )

[node name="XRayTransform" type="RemoteTransform" parent="rat"]
remote_path = NodePath("../../XRayView/Viewport/rat")

[node name="StencilView" parent="rat" instance=ExtResource( 3 )]

[node name="body1" parent="rat/StencilView" index="0"]
Expand Down
70 changes: 70 additions & 0 deletions godot/addons/com.gdquest.editor_camera/LayerGrid.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
tool
extends Control


var value := 0xFFFFF
var hovered_index := -1
var flag_rects := []


func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
for i in flag_rects.size():
if flag_rects[i].has_point(event.position):
hovered_index = i
update()
break
if (
event is InputEventMouseButton and
event.button_index == BUTTON_LEFT and
event.pressed
):
if value & ( 1 << hovered_index):
value &= ~(1 << hovered_index)
else:
value |= (1 << hovered_index)

emit_signal("flag_changed", value)
update()


func _notification(what: int) -> void:
match what:
NOTIFICATION_DRAW:
var rect := Rect2()
rect.size = rect_size
flag_rects.clear()

var base_size := int((rect.size.y * 80 / 100) / 2)
var height := int(base_size * 2 + 1)
var vertical_offset := int((rect.size.y - height) / 2)

var color := get_color("highlight_color", "Editor")

for i in range(2):
var offset := Vector2(4, vertical_offset)
if i == 1:
offset.y += base_size + 1

offset += rect.position

for j in range(10):
var out := offset + Vector2(j * (base_size + 1), 0)
if j >= 5:
out.x += 1

var idx := i * 10 + j
var on := value & ( 1 << idx)
var rect2 := Rect2(out, Vector2(base_size, base_size))

color.a = 0.6 if on else 0.2

if idx == hovered_index:
color.a += 0.15

draw_rect(rect2, color)
flag_rects.push_back(rect2)

NOTIFICATION_MOUSE_EXIT:
hovered_index = -1
update()
16 changes: 16 additions & 0 deletions godot/addons/com.gdquest.editor_camera/RenderLayerDialog.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tool
extends WindowDialog


signal flag_changed(value)

onready var layer_grid := $CenterContainer/VBoxContainer/LayerGrid


func _on_OKButton_pressed() -> void:
emit_signal("flag_changed", layer_grid.value)
hide()


func _on_CancelButton_pressed() -> void:
hide()
59 changes: 59 additions & 0 deletions godot/addons/com.gdquest.editor_camera/SetLayerDialog.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://addons/com.gdquest.editor_camera/RenderLayerDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/com.gdquest.editor_camera/LayerGrid.gd" type="Script" id=2]

[node name="RenderLayerDialog" type="WindowDialog"]
visible = true
rect_min_size = Vector2( 320, 120 )
window_title = "Set Render Layer"
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="CenterContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}

[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
margin_left = 49.0
margin_top = 18.0
margin_right = 271.0
margin_bottom = 101.0
custom_constants/separation = 13

[node name="LayerGrid" type="Control" parent="CenterContainer/VBoxContainer"]
margin_right = 222.0
margin_bottom = 50.0
rect_min_size = Vector2( 200, 50 )
script = ExtResource( 2 )

[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer/VBoxContainer"]
margin_top = 63.0
margin_right = 222.0
margin_bottom = 83.0
grow_horizontal = 2
size_flags_horizontal = 3
custom_constants/separation = 137
__meta__ = {
"_edit_use_anchors_": false
}

[node name="OKButton" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
margin_right = 31.0
margin_bottom = 20.0
text = "OK"

[node name="CancelButton" type="Button" parent="CenterContainer/VBoxContainer/HBoxContainer"]
margin_left = 168.0
margin_right = 222.0
margin_bottom = 20.0
text = "Cancel"
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/OKButton" to="." method="_on_OKButton_pressed"]
[connection signal="pressed" from="CenterContainer/VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_CancelButton_pressed"]
7 changes: 7 additions & 0 deletions godot/addons/com.gdquest.editor_camera/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="Editor Camera Render Layers"
description=""
author="Razoric"
version=""
script="plugin.gd"
40 changes: 40 additions & 0 deletions godot/addons/com.gdquest.editor_camera/plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
tool
extends EditorPlugin


var Popup := preload("SetLayerDialog.tscn")
var popup: WindowDialog
var render_value := 0xFFFFF


func _exit_tree() -> void:
remove_tool_menu_item("Set Editor Camera Render Layer")
popup.free()


func handles(object: Object) -> bool:
if object == get_tree().edited_scene_root:
popup = Popup.instance()
add_child(popup)

popup.connect("flag_changed", self, "_on_RenderLayer_flag_changed")

set_input_event_forwarding_always_enabled()

add_tool_menu_item("Set Editor Camera Render Layer", self, "_on_set_render_layer")

return true
return false


func forward_spatial_gui_input(camera: Camera, event: InputEvent) -> bool:
camera.cull_mask = render_value
return false


func _on_set_render_layer(userdata) -> void:
popup.popup_centered()


func _on_RenderLayer_flag_changed(value: int) -> void:
render_value = value
2 changes: 1 addition & 1 deletion godot/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ window/stretch/aspect="expand"

[editor_plugins]

enabled=PoolStringArray( "gdquest.toon-controller" )
enabled=PoolStringArray( "com.gdquest.editor_camera", "gdquest.toon-controller" )

[input]

Expand Down

0 comments on commit 14ba87e

Please sign in to comment.