From 3a77eb7a3d1a77a99bdb97e065bc37f81249c509 Mon Sep 17 00:00:00 2001 From: Nordup Date: Sun, 24 Mar 2024 05:56:49 +0400 Subject: [PATCH] WorldCanvas scalable animation --- project/scenes/menu_body/world.tscn | 81 ++++++++++++------------ project/scripts/sandbox/render_result.gd | 4 +- project/scripts/ui/world/world_canvas.gd | 24 +++++++ 3 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 project/scripts/ui/world/world_canvas.gd diff --git a/project/scenes/menu_body/world.tscn b/project/scenes/menu_body/world.tscn index c43d1f5..bff515f 100644 --- a/project/scenes/menu_body/world.tscn +++ b/project/scenes/menu_body/world.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=3 uid="uid://kywrsqro3d5i"] +[gd_scene load_steps=24 format=3 uid="uid://kywrsqro3d5i"] [ext_resource type="Script" path="res://scripts/loading/gate_loader.gd" id="1_uxhy6"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_q7cvi"] @@ -10,6 +10,7 @@ [ext_resource type="Script" path="res://scripts/sandbox/input_sync.gd" id="8_1blsi"] [ext_resource type="Resource" uid="uid://bo6qgr210aamc" path="res://resources/sandbox_env.tres" id="8_a6dvr"] [ext_resource type="Resource" uid="uid://crjhix0osmtnf" path="res://resources/ui_events.res" id="9_ir58h"] +[ext_resource type="Script" path="res://scripts/ui/world/world_canvas.gd" id="9_ncfxj"] [ext_resource type="Script" path="res://scripts/sandbox/command_sync.gd" id="10_cqo55"] [ext_resource type="Script" path="res://scripts/ui/world/world_ui.gd" id="12_jdwjt"] [ext_resource type="Script" path="res://scripts/ui/world/gate_info.gd" id="14_8hca5"] @@ -79,32 +80,32 @@ tracks/3/keys = { tracks/4/type = "value" tracks/4/imported = false tracks/4/enabled = true -tracks/4/path = NodePath("HBoxContainer/WorldCanvas:custom_minimum_size") +tracks/4/path = NodePath("HBoxContainer/WorldCanvas/RenderResult/HideOnPress:disabled") tracks/4/interp = 1 tracks/4/loop_wrap = true tracks/4/keys = { "times": PackedFloat32Array(0), "transitions": PackedFloat32Array(1), -"update": 0, -"values": [Vector2(1300, 0)] +"update": 1, +"values": [false] } tracks/5/type = "value" tracks/5/imported = false tracks/5/enabled = true -tracks/5/path = NodePath("HBoxContainer/WorldCanvas/RenderResult/HideOnPress:disabled") +tracks/5/path = NodePath("HBoxContainer/WorldCanvas:interpolate") tracks/5/interp = 1 tracks/5/loop_wrap = true tracks/5/keys = { "times": PackedFloat32Array(0), "transitions": PackedFloat32Array(1), -"update": 1, -"values": [false] +"update": 0, +"values": [0.0] } [sub_resource type="Animation" id="Animation_tper3"] resource_name = "fullscreen" length = 0.25 -step = 0.0166667 +step = 0.05 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true @@ -156,27 +157,27 @@ tracks/3/keys = { tracks/4/type = "value" tracks/4/imported = false tracks/4/enabled = true -tracks/4/path = NodePath("HBoxContainer/WorldCanvas:custom_minimum_size") -tracks/4/interp = 2 +tracks/4/path = NodePath("HBoxContainer/WorldCanvas/RenderResult/HideOnPress:disabled") +tracks/4/interp = 1 tracks/4/loop_wrap = true tracks/4/keys = { -"times": PackedFloat32Array(0.1, 0.25), -"transitions": PackedFloat32Array(1, 1.07177), -"update": 0, -"values": [Vector2(1300, 0), Vector2(1920, 0)] -} -tracks/5/type = "value" -tracks/5/imported = false -tracks/5/enabled = true -tracks/5/path = NodePath("HBoxContainer/WorldCanvas/RenderResult/HideOnPress:disabled") -tracks/5/interp = 1 -tracks/5/loop_wrap = true -tracks/5/keys = { "times": PackedFloat32Array(0), "transitions": PackedFloat32Array(1), "update": 1, "values": [true] } +tracks/5/type = "value" +tracks/5/imported = false +tracks/5/enabled = true +tracks/5/path = NodePath("HBoxContainer/WorldCanvas:interpolate") +tracks/5/interp = 2 +tracks/5/loop_wrap = true +tracks/5/keys = { +"times": PackedFloat32Array(0.1, 0.25), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [0.0, 1.0] +} [sub_resource type="Animation" id="Animation_77flb"] resource_name = "initial" @@ -233,27 +234,27 @@ tracks/3/keys = { tracks/4/type = "value" tracks/4/imported = false tracks/4/enabled = true -tracks/4/path = NodePath("HBoxContainer/WorldCanvas:custom_minimum_size") -tracks/4/interp = 2 +tracks/4/path = NodePath("HBoxContainer/WorldCanvas/RenderResult/HideOnPress:disabled") +tracks/4/interp = 1 tracks/4/loop_wrap = true tracks/4/keys = { -"times": PackedFloat32Array(0, 0.15), -"transitions": PackedFloat32Array(1.07177, 1), -"update": 0, -"values": [Vector2(1920, 0), Vector2(1300, 0)] -} -tracks/5/type = "value" -tracks/5/imported = false -tracks/5/enabled = true -tracks/5/path = NodePath("HBoxContainer/WorldCanvas/RenderResult/HideOnPress:disabled") -tracks/5/interp = 1 -tracks/5/loop_wrap = true -tracks/5/keys = { "times": PackedFloat32Array(0), "transitions": PackedFloat32Array(1), "update": 1, "values": [false] } +tracks/5/type = "value" +tracks/5/imported = false +tracks/5/enabled = true +tracks/5/path = NodePath("HBoxContainer/WorldCanvas:interpolate") +tracks/5/interp = 1 +tracks/5/loop_wrap = true +tracks/5/keys = { +"times": PackedFloat32Array(0, 0.15), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [1.0, 0.0] +} [sub_resource type="AnimationLibrary" id="AnimationLibrary_sld6k"] _data = { @@ -299,10 +300,12 @@ grow_horizontal = 2 grow_vertical = 2 theme_override_constants/separation = 0 -[node name="WorldCanvas" type="Control" parent="HBoxContainer"] +[node name="WorldCanvas" type="Control" parent="HBoxContainer" node_paths=PackedStringArray("render_result")] custom_minimum_size = Vector2(1300, 0) layout_mode = 2 size_flags_horizontal = 0 +script = ExtResource("9_ncfxj") +render_result = NodePath("RenderResult") [node name="RenderResult" type="TextureRect" parent="HBoxContainer/WorldCanvas"] layout_mode = 1 @@ -310,8 +313,8 @@ anchors_preset = 14 anchor_top = 0.5 anchor_right = 1.0 anchor_bottom = 0.5 -offset_top = -365.625 -offset_bottom = 365.625 +offset_top = -409.625 +offset_bottom = 409.681 grow_horizontal = 2 grow_vertical = 2 texture = ExtResource("7_52jgh") diff --git a/project/scripts/sandbox/render_result.gd b/project/scripts/sandbox/render_result.gd index 52fcd78..349829d 100644 --- a/project/scripts/sandbox/render_result.gd +++ b/project/scripts/sandbox/render_result.gd @@ -9,8 +9,8 @@ var rd: RenderingDevice var ext_texure: ExternalTexture var texture_rid: RID -@onready var width = get_viewport().size.x -@onready var height = get_viewport().size.y +@onready var width: int = get_viewport().size.x +@onready var height: int = get_viewport().size.y func _ready() -> void: diff --git a/project/scripts/ui/world/world_canvas.gd b/project/scripts/ui/world/world_canvas.gd new file mode 100644 index 0000000..f2cd9a1 --- /dev/null +++ b/project/scripts/ui/world/world_canvas.gd @@ -0,0 +1,24 @@ +extends Control + +@export var render_result: RenderResult +@export var interpolate: float: + set(value): + interpolate = value + animate(value) + +var initial: int = 1300 +var full_screen: int = 1920 + + +func _ready() -> void: + var viewport_width = ProjectSettings.get_setting("display/window/size/viewport_width", 1152) + var scale_width = float(custom_minimum_size.x) / viewport_width + + full_screen = render_result.width + initial = int(full_screen * scale_width) + custom_minimum_size.x = initial + Debug.logclr("WorldCanvas initial: %d full_screen: %d" % [initial, full_screen], Color.DIM_GRAY) + + +func animate(value: float) -> void: + custom_minimum_size.x = lerp(initial, full_screen, value)