From e6aea97f1b41d74d18e4c514966aab3b1c3bc5ea Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 12 Jun 2020 02:27:21 +0300 Subject: [PATCH] The world_2d of the preview viewports is no longer the same as the main viewport's A "CanvasPreview" Node2D has been added to every preview viewport, where it draws the current frame. This solves #205. --- src/Autoload/Global.gd | 2 ++ src/Canvas.gd | 2 ++ src/UI/CanvasPreview.gd | 13 ++++++++++++ src/UI/CanvasPreview.tscn | 6 ++++++ src/UI/SecondViewport.gd | 6 ------ src/UI/TransparentChecker.tscn | 17 ++++++++++++++++ src/UI/UI.tscn | 36 ++++++++++++++-------------------- 7 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 src/UI/CanvasPreview.gd create mode 100644 src/UI/CanvasPreview.tscn delete mode 100644 src/UI/SecondViewport.gd create mode 100644 src/UI/TransparentChecker.tscn diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 999acaacc..0559aa6f7 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -133,6 +133,7 @@ var canvas : Canvas var tabs : Tabs var main_viewport : ViewportContainer var second_viewport : ViewportContainer +var small_preview_viewport : ViewportContainer var camera : Camera2D var camera2 : Camera2D var camera_preview : Camera2D @@ -251,6 +252,7 @@ func _ready() -> void: tabs = find_node_by_name(root, "Tabs") main_viewport = find_node_by_name(root, "ViewportContainer") second_viewport = find_node_by_name(root, "ViewportContainer2") + small_preview_viewport = find_node_by_name(root, "PreviewViewportContainer") camera = find_node_by_name(main_viewport, "Camera2D") camera2 = find_node_by_name(root, "Camera2D2") camera_preview = find_node_by_name(root, "CameraPreview") diff --git a/src/Canvas.gd b/src/Canvas.gd index 84dd37131..c62b0a8aa 100644 --- a/src/Canvas.gd +++ b/src/Canvas.gd @@ -27,6 +27,8 @@ func _ready() -> void: func _draw() -> void: + Global.second_viewport.get_child(0).get_node("CanvasPreview").update() + Global.small_preview_viewport.get_child(0).get_node("CanvasPreview").update() var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels var size : Vector2 = Global.current_project.size if Global.onion_skinning: diff --git a/src/UI/CanvasPreview.gd b/src/UI/CanvasPreview.gd new file mode 100644 index 000000000..e4a4c97af --- /dev/null +++ b/src/UI/CanvasPreview.gd @@ -0,0 +1,13 @@ +extends Node2D + + +func _draw() -> void: + var current_project : Project = Global.current_project + var frame : int = current_project.current_frame + var current_cels : Array = current_project.frames[frame].cels + + # Draw current frame layers + for i in range(current_cels.size()): + var modulate_color := Color(1, 1, 1, current_cels[i].opacity) + if current_project.layers[i].visible: # if it's visible + draw_texture(current_cels[i].image_texture, Vector2.ZERO, modulate_color) diff --git a/src/UI/CanvasPreview.tscn b/src/UI/CanvasPreview.tscn new file mode 100644 index 000000000..700d8ef5e --- /dev/null +++ b/src/UI/CanvasPreview.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://src/UI/CanvasPreview.gd" type="Script" id=1] + +[node name="CanvasPreview" type="Node2D"] +script = ExtResource( 1 ) diff --git a/src/UI/SecondViewport.gd b/src/UI/SecondViewport.gd deleted file mode 100644 index bc6123ace..000000000 --- a/src/UI/SecondViewport.gd +++ /dev/null @@ -1,6 +0,0 @@ -extends Viewport - - -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - world_2d = Global.canvas.get_parent().world_2d diff --git a/src/UI/TransparentChecker.tscn b/src/UI/TransparentChecker.tscn new file mode 100644 index 000000000..9b01ef466 --- /dev/null +++ b/src/UI/TransparentChecker.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/Shaders/TransparentChecker.shader" type="Shader" id=1] +[ext_resource path="res://src/UI/TransparentChecker.gd" type="Script" id=2] + +[sub_resource type="ShaderMaterial" id=1] +shader = ExtResource( 1 ) +shader_param/size = 10.0 +shader_param/color1 = Color( 0.7, 0.7, 0.7, 1 ) +shader_param/color2 = Color( 1, 1, 1, 1 ) + +[node name="TransparentChecker" type="ColorRect"] +material = SubResource( 1 ) +margin_right = 40.0 +margin_bottom = 40.0 +mouse_filter = 2 +script = ExtResource( 2 ) diff --git a/src/UI/UI.tscn b/src/UI/UI.tscn index fd0611930..e376f260c 100644 --- a/src/UI/UI.tscn +++ b/src/UI/UI.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=25 format=2] +[gd_scene load_steps=23 format=2] [ext_resource path="res://src/UI/ToolButtons.gd" type="Script" id=1] -[ext_resource path="res://src/UI/SecondViewport.gd" type="Script" id=2] +[ext_resource path="res://src/UI/CanvasPreview.tscn" type="PackedScene" id=2] [ext_resource path="res://src/UI/Tabs.gd" type="Script" id=3] [ext_resource path="res://src/UI/Rulers/VerticalRuler.gd" type="Script" id=4] +[ext_resource path="res://src/UI/TransparentChecker.tscn" type="PackedScene" id=5] [ext_resource path="res://src/UI/Rulers/HorizontalRuler.gd" type="Script" id=6] [ext_resource path="res://src/CameraMovement.gd" type="Script" id=7] [ext_resource path="res://src/SelectionRectangle.gd" type="Script" id=8] @@ -14,21 +15,13 @@ [ext_resource path="res://assets/graphics/dark_themes/tools/eraser_r.png" type="Texture" id=13] [ext_resource path="res://assets/graphics/dark_themes/tools/pencil_l.png" type="Texture" id=14] [ext_resource path="res://assets/graphics/dark_themes/tools/lightendarken.png" type="Texture" id=15] -[ext_resource path="res://src/Shaders/TransparentChecker.shader" type="Shader" id=16] [ext_resource path="res://src/UI/ColorAndToolOptions.tscn" type="PackedScene" id=17] [ext_resource path="res://src/UI/Timeline/AnimationTimeline.tscn" type="PackedScene" id=18] [ext_resource path="res://src/Canvas.tscn" type="PackedScene" id=19] [ext_resource path="res://src/Palette/PalettePanelContainer.tscn" type="PackedScene" id=20] [ext_resource path="res://assets/graphics/dark_themes/tools/zoom.png" type="Texture" id=21] -[ext_resource path="res://src/UI/TransparentChecker.gd" type="Script" id=22] [ext_resource path="res://src/UI/ViewportContainer.gd" type="Script" id=23] -[sub_resource type="ShaderMaterial" id=1] -shader = ExtResource( 16 ) -shader_param/size = 10.0 -shader_param/color1 = Color( 0.7, 0.7, 0.7, 1 ) -shader_param/color2 = Color( 1, 1, 1, 1 ) - [sub_resource type="StyleBoxFlat" id=2] bg_color = Color( 0.0627451, 0.0627451, 0.0627451, 1 ) expand_margin_top = 6.0 @@ -284,12 +277,7 @@ handle_input_locally = false usage = 0 render_target_update_mode = 3 -[node name="TransparentChecker" type="ColorRect" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/ViewportContainer/Viewport"] -material = SubResource( 1 ) -margin_right = 40.0 -margin_bottom = 40.0 -mouse_filter = 2 -script = ExtResource( 22 ) +[node name="TransparentChecker" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/ViewportContainer/Viewport" instance=ExtResource( 5 )] [node name="Canvas" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportandVerticalRuler/ViewportContainer/Viewport" instance=ExtResource( 19 )] @@ -319,7 +307,10 @@ script = ExtResource( 23 ) size = Vector2( 0, 426 ) handle_input_locally = false render_target_update_mode = 3 -script = ExtResource( 2 ) + +[node name="TransparentChecker" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportContainer2/Viewport" instance=ExtResource( 5 )] + +[node name="CanvasPreview" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportContainer2/Viewport" instance=ExtResource( 2 )] [node name="Camera2D2" type="Camera2D" parent="CanvasAndTimeline/ViewportAndRulers/HSplitContainer/ViewportContainer2/Viewport"] current = true @@ -353,21 +344,24 @@ margin_right = 322.0 margin_bottom = 164.0 size_flags_horizontal = 4 -[node name="CanvasPreview" type="ViewportContainer" parent="RightPanel/PreviewAndPalettes/PanelContainer"] +[node name="PreviewViewportContainer" type="ViewportContainer" parent="RightPanel/PreviewAndPalettes/PanelContainer"] margin_left = 7.0 margin_top = 7.0 margin_right = 307.0 margin_bottom = 157.0 rect_min_size = Vector2( 0, 150 ) -[node name="Viewport" type="Viewport" parent="RightPanel/PreviewAndPalettes/PanelContainer/CanvasPreview"] +[node name="Viewport" type="Viewport" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer"] size = Vector2( 300, 150 ) transparent_bg = true handle_input_locally = false render_target_update_mode = 3 -script = ExtResource( 2 ) -[node name="CameraPreview" type="Camera2D" parent="RightPanel/PreviewAndPalettes/PanelContainer/CanvasPreview/Viewport"] +[node name="TransparentChecker" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer/Viewport" instance=ExtResource( 5 )] + +[node name="CanvasPreview" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer/Viewport" instance=ExtResource( 2 )] + +[node name="CameraPreview" type="Camera2D" parent="RightPanel/PreviewAndPalettes/PanelContainer/PreviewViewportContainer/Viewport"] offset = Vector2( 32, 32 ) current = true zoom = Vector2( 0.15, 0.15 )