-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tentative editor camera render layer selector
- Loading branch information
1 parent
85f7975
commit 14ba87e
Showing
8 changed files
with
354 additions
and
211 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,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
16
godot/addons/com.gdquest.editor_camera/RenderLayerDialog.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
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
59
godot/addons/com.gdquest.editor_camera/SetLayerDialog.tscn
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,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"] |
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="Editor Camera Render Layers" | ||
description="" | ||
author="Razoric" | ||
version="" | ||
script="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
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 |
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