Implemented basic tool system.
This commit is contained in:
parent
9814051fc4
commit
8d028205fb
|
@ -4,4 +4,4 @@
|
|||
|
||||
[resource]
|
||||
script = ExtResource( 1 )
|
||||
aspect_ratio = Vector2( 20.169, 14.308 )
|
||||
aspect_ratio = Vector2( 16, 9 )
|
||||
|
|
|
@ -13,7 +13,3 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="Canvas" parent="." instance=ExtResource( 1 )]
|
||||
margin_left = 12.0
|
||||
margin_top = 12.0
|
||||
margin_right = -12.0
|
||||
margin_bottom = -12.0
|
||||
|
|
|
@ -6,14 +6,24 @@ signal sd_scene_changed(new_scene)
|
|||
const MainScreen = preload("res://addons/summer_day/main_screen.tscn")
|
||||
const Timeline = preload("res://addons/summer_day/tool/timeline/timeline.tscn")
|
||||
|
||||
var Canvas: SummerDayCanvas
|
||||
|
||||
var main_screen_instance: SummerDayMainScreen
|
||||
var timeline_instance: SummerDayTimeline
|
||||
|
||||
var tool_context := SummerDayToolContext.new()
|
||||
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
main_screen_instance = MainScreen.instance()
|
||||
Canvas = main_screen_instance.get_node("Canvas")
|
||||
Canvas.tool_context = tool_context
|
||||
self.connect("sd_scene_changed",
|
||||
main_screen_instance.get_node("Canvas"), "_on_SummerDay_scene_changed"
|
||||
Canvas, "_on_SummerDay_scene_changed"
|
||||
)
|
||||
self.connect("sd_scene_changed",
|
||||
tool_context, "_on_SummerDay_scene_changed"
|
||||
)
|
||||
# Add the main panel to the editor's main viewport.
|
||||
get_editor_interface().get_editor_viewport().add_child(main_screen_instance)
|
||||
|
|
|
@ -1,21 +1,30 @@
|
|||
tool
|
||||
extends Control
|
||||
extends PanelContainer
|
||||
class_name SummerDayCanvas
|
||||
|
||||
var scene: SummerDayScene
|
||||
var canvas_state := SummerDayCanvasState.new()
|
||||
var tool_pool := SummerDayCanvasToolPool.new()
|
||||
|
||||
var tool_context: SummerDayToolContext # Provided by plugin root.
|
||||
|
||||
|
||||
func _ready():
|
||||
tool_context.canvas_state = canvas_state
|
||||
canvas_state.connect("view_transform_changed",
|
||||
$BackgroundLayer/EmptyCanvasLayer, "_on_view_transform_changed")
|
||||
$Render/BackgroundLayer/EmptyCanvasLayer, "_on_view_transform_changed")
|
||||
|
||||
|
||||
func _gui_input(event):
|
||||
if event is InputEventMagnifyGesture:
|
||||
print(event.factor)
|
||||
if event is InputEventMouseButton:
|
||||
print(event.pressed)
|
||||
func _input(event):
|
||||
var allow_pass = false
|
||||
var pos = event.get("position")
|
||||
if pos == null:
|
||||
allow_pass = true
|
||||
else:
|
||||
if get_rect().has_point(get_local_mouse_position()):
|
||||
allow_pass = true
|
||||
if allow_pass:
|
||||
tool_pool.run_most_prior(event, tool_context)
|
||||
|
||||
|
||||
func _on_SummerDay_scene_changed(new_scene):
|
||||
|
@ -23,7 +32,9 @@ func _on_SummerDay_scene_changed(new_scene):
|
|||
canvas_state.update_fill_transform(scene)
|
||||
scene.connect("aspect_ratio_changed",
|
||||
self, "_on_scene_aspect_ratio_changed")
|
||||
$Label.text = str(scene) + "\n" + str(scene.aspect_ratio)
|
||||
$Render/Label.text = str(scene) + "\n" + str(scene.aspect_ratio)
|
||||
$Render/BackgroundLayer/EmptyCanvasLayer.update_size(scene)
|
||||
canvas_state.update_fill_transform(scene)
|
||||
|
||||
|
||||
func _on_Canvas_resized():
|
||||
|
@ -32,5 +43,5 @@ func _on_Canvas_resized():
|
|||
|
||||
|
||||
func _on_scene_aspect_ratio_changed(new_aspect_ratio):
|
||||
$BackgroundLayer/EmptyCanvasLayer.update_size(scene)
|
||||
$Render/BackgroundLayer/EmptyCanvasLayer.update_size(scene)
|
||||
canvas_state.update_fill_transform(scene)
|
||||
|
|
|
@ -1,76 +1,89 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://addons/summer_day/tool/canvas/canvas.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Main.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://addons/summer_day/tool/canvas/rendering/empty_canvas_layer.gd" type="Script" id=3]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=3]
|
||||
bg_color = Color( 0.180392, 0.172549, 0.203922, 1 )
|
||||
border_width_left = 1
|
||||
border_width_top = 1
|
||||
border_width_right = 1
|
||||
border_width_bottom = 1
|
||||
border_color = Color( 0.121569, 0.113725, 0.133333, 1 )
|
||||
|
||||
[sub_resource type="GDScript" id=4]
|
||||
script/source = "extends ViewportContainer
|
||||
|
||||
|
||||
func _gui_input(event):
|
||||
pass
|
||||
|
||||
func _clips_input():
|
||||
pass
|
||||
"
|
||||
|
||||
[sub_resource type="Environment" id=1]
|
||||
ambient_light_color = Color( 1, 1, 1, 1 )
|
||||
|
||||
[sub_resource type="World" id=2]
|
||||
environment = SubResource( 1 )
|
||||
|
||||
[sub_resource type="GDScript" id=3]
|
||||
script/source = "tool
|
||||
extends Control
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = \"text\"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
update()
|
||||
"
|
||||
|
||||
[node name="Canvas" type="ViewportContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
stretch = true
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="BackgroundLayer" type="Viewport" parent="."]
|
||||
size = Vector2( 1024, 600 )
|
||||
size_override_stretch = true
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
usage = 0
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="EmptyCanvasLayer" type="Polygon2D" parent="BackgroundLayer"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="RenderLayer" type="Viewport" parent="."]
|
||||
size = Vector2( 1024, 600 )
|
||||
world = SubResource( 2 )
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="Main" parent="RenderLayer" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="ForegroundLayer" type="Viewport" parent="."]
|
||||
size = Vector2( 1024, 600 )
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
usage = 0
|
||||
render_target_update_mode = 3
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
[node name="Canvas" type="PanelContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 12.0
|
||||
margin_top = 12.0
|
||||
margin_right = -12.0
|
||||
margin_bottom = -12.0
|
||||
script = SubResource( 3 )
|
||||
custom_styles/panel = SubResource( 3 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
[node name="Render" type="ViewportContainer" parent="."]
|
||||
margin_left = 1.0
|
||||
margin_top = 1.0
|
||||
margin_right = 999.0
|
||||
margin_bottom = 575.0
|
||||
stretch = true
|
||||
script = SubResource( 4 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="BackgroundLayer" type="Viewport" parent="Render"]
|
||||
size = Vector2( 998, 574 )
|
||||
size_override_stretch = true
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
usage = 0
|
||||
render_target_update_mode = 3
|
||||
gui_disable_input = true
|
||||
|
||||
[node name="EmptyCanvasLayer" type="Polygon2D" parent="Render/BackgroundLayer"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="RenderLayer" type="Viewport" parent="Render"]
|
||||
size = Vector2( 998, 574 )
|
||||
world = SubResource( 2 )
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
render_target_update_mode = 3
|
||||
gui_disable_input = true
|
||||
|
||||
[node name="Main" parent="Render/RenderLayer" instance=ExtResource( 2 )]
|
||||
|
||||
[node name="ForegroundLayer" type="Viewport" parent="Render"]
|
||||
size = Vector2( 998, 574 )
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
usage = 0
|
||||
render_target_update_mode = 3
|
||||
gui_disable_input = true
|
||||
|
||||
[node name="Label" type="Label" parent="Render"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 14.0
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ signal view_transform_changed(view_transform)
|
|||
var rect_size: Vector2
|
||||
|
||||
var fill_transform := Transform2D.IDENTITY
|
||||
var canvas_transform := Transform2D.IDENTITY
|
||||
var canvas_transform := Transform2D.IDENTITY setget _set_canvas_transform
|
||||
var view_transform := Transform2D.IDENTITY # fill_transform * canvas_transform
|
||||
|
||||
|
||||
|
@ -29,11 +29,7 @@ func update_fill_transform(scene):
|
|||
var translation = Vector2.ZERO
|
||||
if aspect_ratio <= size_ratio:
|
||||
scale = rect_size.y
|
||||
print(rect_size.y)
|
||||
translation.x = rect_size.x * 0.5 - aspect_ratio * scale * 0.5
|
||||
print(rect_size.x * 0.5)
|
||||
print(aspect_ratio * scale * 0.5)
|
||||
print(translation)
|
||||
else:
|
||||
scale = rect_size.x / aspect_ratio
|
||||
translation.y = rect_size.y * 0.5 - scale * 0.5
|
||||
|
@ -45,11 +41,14 @@ func update_fill_transform(scene):
|
|||
Vector2(0.0, scale),
|
||||
translation
|
||||
)
|
||||
print(fill_transform)
|
||||
emit_signal("fill_transform_changed", fill_transform)
|
||||
|
||||
|
||||
func _update_view_transformation(transform):
|
||||
print("DoWeReach?")
|
||||
view_transform = fill_transform * canvas_transform
|
||||
view_transform = canvas_transform * fill_transform
|
||||
emit_signal("view_transform_changed", view_transform)
|
||||
|
||||
|
||||
func _set_canvas_transform(new_canvas_transform):
|
||||
canvas_transform = new_canvas_transform
|
||||
emit_signal("canvas_transform_changed", canvas_transform)
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
extends Reference
|
||||
class_name SummerDayBaseTool
|
||||
|
||||
|
||||
func _check_if_chosen(input) -> int: # Virtual.
|
||||
return 0
|
||||
|
||||
|
||||
func _run(tool_context): # Virtual.
|
||||
pass
|
|
@ -1,4 +0,0 @@
|
|||
extends SummerDayBaseTool
|
||||
class_name SummerDayHandTool
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
extends Reference
|
||||
class_name SummerDayToolContext
|
||||
|
||||
|
||||
var edited_scene: SummerDayScene
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
|
@ -0,0 +1,16 @@
|
|||
extends SummerDayTool
|
||||
class_name SummerDayFreeTransformCanvasTool
|
||||
|
||||
|
||||
func _init():
|
||||
priority = 1
|
||||
|
||||
|
||||
func _check_for_use(event: InputEvent, tool_context: SummerDayToolContext):
|
||||
if event is InputEventScreenDrag:
|
||||
return true
|
||||
|
||||
func _run(event: InputEvent, tool_context: SummerDayToolContext):
|
||||
var transform := tool_context.canvas_state.canvas_transform
|
||||
transform = transform.translated(event.relative)
|
||||
tool_context.canvas_state.canvas_transform = transform
|
|
@ -0,0 +1,4 @@
|
|||
extends SummerDayTool
|
||||
class_name SummerDayHandCanvasTool
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
extends SummerDayToolPool
|
||||
class_name SummerDayCanvasToolPool
|
||||
|
||||
|
||||
func _init():
|
||||
persistent_tool_pool.append(
|
||||
SummerDayFreeTransformCanvasTool.new()
|
||||
)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
|
@ -0,0 +1,20 @@
|
|||
extends Reference
|
||||
class_name SummerDayTool
|
||||
|
||||
|
||||
var priority = 0
|
||||
var modifier_layer = 0
|
||||
|
||||
|
||||
func _check_for_use(
|
||||
event: InputEvent, tool_context: SummerDayToolContext
|
||||
) -> bool: # Virtual.
|
||||
return false
|
||||
|
||||
|
||||
func _run(event: InputEvent, tool_context: SummerDayToolContext): # Virtual.
|
||||
pass
|
||||
|
||||
|
||||
func get_priority_score() -> int:
|
||||
return priority * 4 + modifier_layer
|
|
@ -0,0 +1,10 @@
|
|||
extends Reference
|
||||
class_name SummerDayToolContext
|
||||
|
||||
|
||||
var edited_scene: SummerDayScene
|
||||
var canvas_state: SummerDayCanvasState
|
||||
|
||||
|
||||
func _on_SummerDay_scene_changed(new_scene):
|
||||
edited_scene = new_scene
|
|
@ -0,0 +1,20 @@
|
|||
extends Reference
|
||||
class_name SummerDayToolPool
|
||||
|
||||
var persistent_tool_pool = []
|
||||
var modifiable_tool_pool = []
|
||||
|
||||
|
||||
func run_most_prior(
|
||||
event: InputEvent, tool_context: SummerDayToolContext):
|
||||
var priority_high_score = 0
|
||||
var currently_most_prior: SummerDayTool = null
|
||||
for list in [persistent_tool_pool, modifiable_tool_pool]:
|
||||
for i in list:
|
||||
if i._check_for_use(event, tool_context):
|
||||
var priority_score = i.get_priority_score()
|
||||
if priority_score > priority_high_score:
|
||||
priority_high_score = priority_score
|
||||
currently_most_prior = i
|
||||
if currently_most_prior != null:
|
||||
currently_most_prior._run(event, tool_context)
|
|
@ -44,12 +44,7 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://Bullshit/ScriptEditTest.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "SummerDayBaseTool",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/canvas/tool_system/base_tool.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"base": "PanelContainer",
|
||||
"class": "SummerDayCanvas",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/canvas/canvas.gd"
|
||||
|
@ -59,10 +54,20 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/canvas/canvas_state.gd"
|
||||
}, {
|
||||
"base": "SummerDayBaseTool",
|
||||
"class": "SummerDayHandTool",
|
||||
"base": "SummerDayToolPool",
|
||||
"class": "SummerDayCanvasToolPool",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/canvas/tool_system/general_use/hand.gd"
|
||||
"path": "res://addons/summer_day/tool/canvas/tools/tool_pool.gd"
|
||||
}, {
|
||||
"base": "SummerDayTool",
|
||||
"class": "SummerDayFreeTransformCanvasTool",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/canvas/tools/general_use/free_transform.gd"
|
||||
}, {
|
||||
"base": "SummerDayTool",
|
||||
"class": "SummerDayHandCanvasTool",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/canvas/tools/general_use/hand.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "SummerDayMainScreen",
|
||||
|
@ -80,9 +85,19 @@ _global_script_classes=[ {
|
|||
"path": "res://addons/summer_day/tool/timeline/timeline.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "SummerDayTool",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/tool_system/base_tool.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "SummerDayToolContext",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/canvas/tool_system/tool_context.gd"
|
||||
"path": "res://addons/summer_day/tool/tool_system/tool_context.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "SummerDayToolPool",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/summer_day/tool/tool_system/tool_pool.gd"
|
||||
}, {
|
||||
"base": "OH",
|
||||
"class": "VeryWorse",
|
||||
|
@ -97,14 +112,17 @@ _global_script_class_icons={
|
|||
"PremiumTexture": "",
|
||||
"SDDisplay": "",
|
||||
"ScriptEditorTest": "",
|
||||
"SummerDayBaseTool": "",
|
||||
"SummerDayCanvas": "",
|
||||
"SummerDayCanvasState": "",
|
||||
"SummerDayHandTool": "",
|
||||
"SummerDayCanvasToolPool": "",
|
||||
"SummerDayFreeTransformCanvasTool": "",
|
||||
"SummerDayHandCanvasTool": "",
|
||||
"SummerDayMainScreen": "",
|
||||
"SummerDayScene": "",
|
||||
"SummerDayTimeline": "",
|
||||
"SummerDayTool": "",
|
||||
"SummerDayToolContext": "",
|
||||
"SummerDayToolPool": "",
|
||||
"VeryWorse": ""
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user