Skip to content

Commit

Permalink
add: custom DemoData resources and thumbnail texture ratio fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gtibo committed Feb 21, 2023
1 parent 4646a94 commit aace8be
Show file tree
Hide file tree
Showing 29 changed files with 345 additions and 23 deletions.
8 changes: 6 additions & 2 deletions main/menu_scene_selector/card/card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ var zoomed_in = 1.15
signal pressed

func _ready():
connect("resized", _on_resized)
connect("resized", _set_pivot)
connect("mouse_entered", _set_focus.bind(true))
connect("mouse_exited", _set_focus.bind(false))
connect("focus_entered", _set_focus.bind(true))
connect("focus_exited", _set_focus.bind(false))
_set_pivot()

func _gui_input(event):
if event is InputEventMouseButton:
Expand Down Expand Up @@ -55,6 +56,9 @@ func _set_focus(state : bool):
func set_title(value : String):
title.text = value

func set_thumbnail(value : Texture2D):
thumbnail.texture = value
thumbnail.set_texture_ratio()

func _on_resized():
func _set_pivot():
pivot_offset = size / 2.0
3 changes: 2 additions & 1 deletion main/menu_scene_selector/card/card.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ shader_type canvas_item;
uniform float zoom = 1.0;
uniform float radius = 0.25;
uniform vec2 ratio = vec2(1.0, 1.0);
uniform vec2 texture_ratio = vec2(1.0, 1.0);

uniform vec3 gradient_color : source_color = vec3(1.0);
uniform float gradient_opacity = 0.0;
Expand All @@ -14,7 +15,7 @@ void fragment() {
float mask = smoothstep(0.005, -0.0025, d);

float normalized_zoom = (1.0 + 1.0 - zoom);
COLOR.rgb = texture(TEXTURE, (UV - 0.5) * normalized_zoom * ratio + 0.5).rgb;
COLOR.rgb = texture(TEXTURE, (UV - 0.5) * normalized_zoom * texture_ratio * ratio + 0.5).rgb;
COLOR.rgb = mix(COLOR.rgb, gradient_color, step(-0.025, d) * gradient_opacity);
COLOR.a *= mask;
}
1 change: 1 addition & 0 deletions main/menu_scene_selector/card/card.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ shader = ExtResource("1_goa7o")
shader_parameter/zoom = 1.0
shader_parameter/radius = 0.1
shader_parameter/ratio = Vector2(1, 1)
shader_parameter/texture_ratio = Vector2(1, 1)
shader_parameter/gradient_color = Color(1, 1, 1, 1)
shader_parameter/gradient_opacity = 0.0

Expand Down
6 changes: 5 additions & 1 deletion main/menu_scene_selector/card/thumbnail.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func _set_current_gradient_opacity(value : float):
current_gradient_opacity = value
var t = create_tween().set_ease(Tween.EASE_OUT)
t.tween_property(material, "shader_parameter/gradient_opacity", current_gradient_opacity, 0.1)

func _set_ratio():
material.set("shader_parameter/ratio", Vector2(size.x/size.y, 1.0))

func set_texture_ratio():
var s = texture.get_size()
material.set("shader_parameter/texture_ratio", Vector2(s.y/s.x, 1.0))
5 changes: 3 additions & 2 deletions main/menu_scene_selector/card_selector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ func focus_current_card() -> void:
grid.get_child(active_card_index).grab_focus()


func create_card(card_title: String) -> void:
func create_card(card_title: String, thumbnail : Texture2D) -> void:
var card = card_scene.instantiate()
grid.add_child(card)
card.set_title(card_title)
card.set_thumbnail(thumbnail)
card.focused = false
var card_index = grid.get_child_count() - 1
card.pressed.connect(_set_active_card_index.bind(card_index))
Expand All @@ -40,7 +41,7 @@ func create_card(card_title: String) -> void:
_check_arrow()


func _set_active_card_index(card_index : int):
func _set_active_card_index(card_index : int):
grid.get_child(active_card_index).active = false
grid.get_child(card_index).active = true
active_card_index = card_index
Expand Down
19 changes: 3 additions & 16 deletions main/ui_scene_selector.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
extends Node

const DEMOS := [
{"path": "res://2d_clipping/2d_clipping.tscn", "name": "2D Clipping"},
{"path": "res://3d_physics_nodes/3d_physics_nodes.tscn", "name": "3D Physics Nodes"},
{"path": "res://animation_retargeting/animation_retargeting.tscn", "name": "Animation Retargeting"},
{"path": "res://cutout_character/cutout_character.tscn", "name": "Cutout Character"},
{"path": "res://interior-diorama/interior_diorama.tscn", "name": "Interior Diorama"},
{"path": "res://outdoor_environment/outdoor_environment.tscn", "name": "Outdoor Environment"},
{"path": "res://theme_variations/theme_variations.tscn", "name": "Theme Variations"},
{"path": "res://tilemap/tilemap_based_level.tscn", "name": "Tilemap Level"},
{"path": "res://tweens/tween_demo.tscn", "name": "Tween Demo"},
{"path": "res://ui_flexbox/flow_container_demo.tscn", "name": "Flow Container"}
]

@export var DEMOS : Array[Resource]
@onready var main_menu : CanvasLayer = %MainMenu
@onready var scene_tree := get_tree()

Expand All @@ -27,14 +15,14 @@ func _ready() -> void:
main_menu.card_selector.card_selected.connect(_on_entry_pressed)

for demo in DEMOS:
main_menu.card_selector.create_card(demo["name"])
main_menu.card_selector.create_card(demo["title"], demo["thumbnail"])
main_menu.card_selector.grid.get_child(0).grab_focus()


func _on_entry_pressed(demo_id: int) -> void:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
_cached_mouse_mode = Input.MOUSE_MODE_VISIBLE
scene_tree.change_scene_to_file(DEMOS[demo_id]["path"])
scene_tree.change_scene_to_file(DEMOS[demo_id]["scene_path"])
_current_scene_index = demo_id
resume()

Expand All @@ -45,7 +33,6 @@ func _input(event: InputEvent) -> void:
return
if not main_menu._is_open:
pause()
main_menu.card_selector.focus_current_card()
else:
resume()
if event.is_action_pressed("menu_quit"):
Expand Down
11 changes: 10 additions & 1 deletion main/ui_scene_selector.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
[gd_scene load_steps=3 format=3 uid="uid://d4mjp57jai7ya"]
[gd_scene load_steps=10 format=3 uid="uid://d4mjp57jai7ya"]

[ext_resource type="Script" path="res://main/ui_scene_selector.gd" id="1_x13la"]
[ext_resource type="Resource" uid="uid://brsu33cswdnyg" path="res://resources/demo_data/data/2d_clipping.tres" id="2_2d0ry"]
[ext_resource type="PackedScene" uid="uid://q0elnm5woxkb" path="res://main/menu_scene_selector/main_menu.tscn" id="2_aoh2w"]
[ext_resource type="Resource" uid="uid://bj4ymd0ci8ub2" path="res://resources/demo_data/data/animation_retargeting.tres" id="3_q5lkc"]
[ext_resource type="Resource" uid="uid://dmi6uuh3lmhhe" path="res://resources/demo_data/data/ball_pool.tres" id="4_46ofe"]
[ext_resource type="Resource" uid="uid://ds2qi4qsnpacn" path="res://resources/demo_data/data/canvas_group.tres" id="5_fwpk7"]
[ext_resource type="Resource" uid="uid://7ymumgpqy2ss" path="res://resources/demo_data/data/heightmap.tres" id="6_6blfo"]
[ext_resource type="Resource" uid="uid://bnggfxwnp0uo" path="res://resources/demo_data/data/multilingual.tres" id="7_1ca3p"]
[ext_resource type="Resource" uid="uid://drht6iicmq1hw" path="res://resources/demo_data/data/voxelgi.tres" id="8_uakx5"]

[node name="UISceneSelector" type="Node"]
script = ExtResource("1_x13la")
DEMOS = Array[Resource]([ExtResource("2_2d0ry"), ExtResource("3_q5lkc"), ExtResource("4_46ofe"), ExtResource("5_fwpk7"), ExtResource("6_6blfo"), ExtResource("7_1ca3p"), ExtResource("8_uakx5")])

[node name="MainMenu" parent="." instance=ExtResource("2_aoh2w")]
unique_name_in_owner = true
layer = 10
10 changes: 10 additions & 0 deletions resources/demo_data/data/2d_clipping.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="DemoData" load_steps=3 format=3 uid="uid://brsu33cswdnyg"]

[ext_resource type="Script" path="res://resources/demo_data/demo_data_builder.gd" id="1_bhqcp"]
[ext_resource type="Texture2D" uid="uid://174o3rsb6mok" path="res://resources/demo_data/thumbnails/2d_clipping_thumbnail.png" id="2_q81bn"]

[resource]
script = ExtResource("1_bhqcp")
title = "2D clipping"
thumbnail = ExtResource("2_q81bn")
scene_path = "res://2d_clipping/2d_clipping_background.tscn"
10 changes: 10 additions & 0 deletions resources/demo_data/data/animation_retargeting.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="DemoData" load_steps=3 format=3 uid="uid://bj4ymd0ci8ub2"]

[ext_resource type="Script" path="res://resources/demo_data/demo_data_builder.gd" id="1_f33nh"]
[ext_resource type="Texture2D" uid="uid://bsmoimtxixl01" path="res://resources/demo_data/thumbnails/animation_retargeting_thumbnail.png" id="2_bbn5d"]

[resource]
script = ExtResource("1_f33nh")
title = "Animation Retargeting"
thumbnail = ExtResource("2_bbn5d")
scene_path = "res://animation_retargeting/animation_retargeting.tscn"
10 changes: 10 additions & 0 deletions resources/demo_data/data/ball_pool.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="DemoData" load_steps=3 format=3 uid="uid://dmi6uuh3lmhhe"]

[ext_resource type="Script" path="res://resources/demo_data/demo_data_builder.gd" id="1_ggau4"]
[ext_resource type="Texture2D" uid="uid://bc0rxlnuspcln" path="res://resources/demo_data/thumbnails/ball_pool_thumbnail.png" id="2_5x3bx"]

[resource]
script = ExtResource("1_ggau4")
title = "Ball Pool"
thumbnail = ExtResource("2_5x3bx")
scene_path = "res://3d_balls_pool/3d_balls_pool.tscn"
10 changes: 10 additions & 0 deletions resources/demo_data/data/canvas_group.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="DemoData" load_steps=3 format=3 uid="uid://ds2qi4qsnpacn"]

[ext_resource type="Script" path="res://resources/demo_data/demo_data_builder.gd" id="1_t7ybg"]
[ext_resource type="Texture2D" uid="uid://bf6lgckyosgxo" path="res://resources/demo_data/thumbnails/canvas_group_thumbnail.png" id="2_yblpk"]

[resource]
script = ExtResource("1_t7ybg")
title = "Canvas Group"
thumbnail = ExtResource("2_yblpk")
scene_path = "res://cutout_character/cutout_character.tscn"
10 changes: 10 additions & 0 deletions resources/demo_data/data/heightmap.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="DemoData" load_steps=3 format=3 uid="uid://7ymumgpqy2ss"]

[ext_resource type="Script" path="res://resources/demo_data/demo_data_builder.gd" id="1_af66d"]
[ext_resource type="Texture2D" uid="uid://be1alsrbqb4o3" path="res://resources/demo_data/thumbnails/heightmap_thumbnail.png" id="2_t4kjs"]

[resource]
script = ExtResource("1_af66d")
title = "Heightmap"
thumbnail = ExtResource("2_t4kjs")
scene_path = "res://heightmap_physics/heightmap_physics.tscn"
10 changes: 10 additions & 0 deletions resources/demo_data/data/multilingual.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="DemoData" load_steps=3 format=3 uid="uid://bnggfxwnp0uo"]

[ext_resource type="Script" path="res://resources/demo_data/demo_data_builder.gd" id="1_xshkg"]
[ext_resource type="Texture2D" uid="uid://buo8o3melhgm3" path="res://resources/demo_data/thumbnails/multilingual_thumbnail.png" id="2_2qqrx"]

[resource]
script = ExtResource("1_xshkg")
title = "Multilingual"
thumbnail = ExtResource("2_2qqrx")
scene_path = "res://dialogue_tree/dialogue_tree_ui.tscn"
10 changes: 10 additions & 0 deletions resources/demo_data/data/voxelgi.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="DemoData" load_steps=3 format=3 uid="uid://drht6iicmq1hw"]

[ext_resource type="Script" path="res://resources/demo_data/demo_data_builder.gd" id="1_1dblf"]
[ext_resource type="Texture2D" uid="uid://dx05efr2wg5a0" path="res://resources/demo_data/thumbnails/voxelgi_thumbnail.png" id="2_1w8u8"]

[resource]
script = ExtResource("1_1dblf")
title = "VoxelGI"
thumbnail = ExtResource("2_1w8u8")
scene_path = "res://interior-diorama/interior_diorama.tscn"
6 changes: 6 additions & 0 deletions resources/demo_data/demo_data_builder.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends Resource
class_name DemoData

@export var title : String = ""
@export var thumbnail : Texture2D
@export_file var scene_path
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions resources/demo_data/thumbnails/2d_clipping_thumbnail.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://174o3rsb6mok"
path="res://.godot/imported/2d_clipping_thumbnail.png-bd5dc4068eb9c039d09236bdde7e0bae.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/demo_data/thumbnails/2d_clipping_thumbnail.png"
dest_files=["res://.godot/imported/2d_clipping_thumbnail.png-bd5dc4068eb9c039d09236bdde7e0bae.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bsmoimtxixl01"
path="res://.godot/imported/animation_retargeting_thumbnail.png-41734efa9271a18f2a8296175b3b86b5.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/demo_data/thumbnails/animation_retargeting_thumbnail.png"
dest_files=["res://.godot/imported/animation_retargeting_thumbnail.png-41734efa9271a18f2a8296175b3b86b5.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions resources/demo_data/thumbnails/ball_pool_thumbnail.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bc0rxlnuspcln"
path="res://.godot/imported/ball_pool_thumbnail.png-cf8fc0ee8db759a6054496cad6f87c3a.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/demo_data/thumbnails/ball_pool_thumbnail.png"
dest_files=["res://.godot/imported/ball_pool_thumbnail.png-cf8fc0ee8db759a6054496cad6f87c3a.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions resources/demo_data/thumbnails/canvas_group_thumbnail.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bf6lgckyosgxo"
path="res://.godot/imported/canvas_group_thumbnail.png-42249f4d79d5e4ef6ec88daa268b5fe4.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/demo_data/thumbnails/canvas_group_thumbnail.png"
dest_files=["res://.godot/imported/canvas_group_thumbnail.png-42249f4d79d5e4ef6ec88daa268b5fe4.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aace8be

Please sign in to comment.