Skip to content

Commit

Permalink
feat: puzzle progress animation tweaks
Browse files Browse the repository at this point in the history
- waits a frame and hides the panel before toasting
- locks the puzzle_num so it's not off by one
- delays move-cursor a bit to fix alignment (yucky hard-coded number)
- adds margin and animation disable to animatedvbox
  • Loading branch information
russmatney committed Feb 23, 2024
1 parent 900604e commit de32570
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 25 deletions.
10 changes: 8 additions & 2 deletions src/Anim.gd
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,20 @@ static func puzzle_animate_outro_to_point(puzz_node):
## toast ###########################################################

static func toast(node, opts={}):
if opts.get("wait_frame", false):
node.set_visible(false)
await node.get_tree().process_frame

var screen_rect = node.get_viewport_rect()
Log.pr("screen rect", screen_rect, "node size", node.get_size())
var margin = opts.get("margin", 20)
var target_pos = screen_rect.end - node.get_size() - Vector2.ONE * margin
var initial_pos = Vector2(target_pos.x, screen_rect.size.y)
var in_t = opts.get("in_t", 0.7)
var out_t = opts.get("out_t", 0.7)
var delay_t = opts.get("delay_t", 1.0)
Log.pr("toasting the progress panel!", node, target_pos, initial_pos)

node.global_position = initial_pos
node.set_visible(true)

var t = node.create_tween()
t.tween_property(node, "global_position", target_pos, in_t)\
Expand All @@ -178,3 +181,6 @@ static func toast(node, opts={}):
t.tween_property(node, "global_position", initial_pos, out_t)\
.set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)\
.set_delay(delay_t)

if opts.get("free_node", true):
t.tween_callback(node.queue_free)
13 changes: 7 additions & 6 deletions src/puzzle/GameScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,18 @@ func on_puzzle_win():
await show_progress_jumbo()
else:
var panel = ProgressPanelScene.instantiate()
panel.disable_resize_animation()
var lock_puzz_num = puzzle_num
panel.ready.connect(func():
Log.pr("showing progress with puzzle_set", puzzle_set)
panel.render({
puzzle_set=puzzle_set,
start_puzzle_num=puzzle_num,
end_puzzle_num=puzzle_num + 1,
start_puzzle_num=lock_puzz_num,
end_puzzle_num=lock_puzz_num + 1,
}))
panel.rendered.connect(func():
# wait for panel to finish resizing
Anim.toast(panel, {wait_frame=true, in_t=0.7, out_t=0.7, delay=1.0, margin=48}))
hud.add_child.call_deferred(panel)
await panel.rendered
# TODO clean up panel afterwards
Anim.toast(panel, {in_t=0.7, out_t=0.7, delay=1.0, margin=48})

puzzle_num += 1
rebuild_puzzle()
Expand Down
1 change: 0 additions & 1 deletion src/puzzle/GameScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ script = ExtResource("1_ak4mv")
game_def_path = "res://src/puzzles/dothop-one.txt"
puzzle_theme = SubResource("Resource_hnxo3")
puzzle_set = SubResource("Resource_d5xou")
puzzle_num = 6

[node name="HUD" parent="." instance=ExtResource("3_3vrse")]

Expand Down
13 changes: 9 additions & 4 deletions src/ui/AnimatedVBoxContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class_name AnimatedVBoxContainer
@export var child_size = Vector2(200, 64)
@export var anim_duration: float = 0.3

@export var disable_animations = false

@export var margin = Vector2()

var og_size
var chs = []

Expand All @@ -13,10 +17,11 @@ func _ready():
og_size = custom_minimum_size
chs = get_children()

hide_and_animate_in()
if not disable_animations:
hide_and_animate_in()

func on_visibility_changed():
if is_visible_in_tree():
if is_visible_in_tree() and not disable_animations:
hide_and_animate_in()

func hide_and_animate_in():
Expand All @@ -30,8 +35,8 @@ func animate_opening():
set_custom_minimum_size(Vector2.ZERO)
var t = create_tween()
t.tween_property(self, "custom_minimum_size",
Vector2.RIGHT*(max(og_size.x, child_size.x))
+ (Vector2.DOWN * child_size.y * len(chs)),
(Vector2.RIGHT * (max(og_size.x, child_size.x) + margin.x))
+ (Vector2.DOWN * (child_size.y * len(chs) + margin.y)),
anim_duration).set_trans(Tween.TRANS_CUBIC)
await get_tree().create_timer(anim_duration).timeout

Expand Down
25 changes: 16 additions & 9 deletions src/ui/components/PuzzleProgressPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extends Control
@onready var puzzle_list = $%PuzzleList
@onready var panel_container = $%PuzzlePanelContainer
@onready var puzzle_set_icon = $%PuzzleSetIcon
@onready var animated_container = $%AnimatedVBoxContainer
var puzzle_set: PuzzleSet
var start_puzzle_num: int
var end_puzzle_num: int
Expand All @@ -15,14 +16,20 @@ signal rendered
## ready ############################################################

func _ready():
Log.pr("prog panel ready")
panel_container.minimum_size_changed.connect(func():
set_custom_minimum_size(panel_container.get_size())
set_size(panel_container.get_size()))
if not Engine.is_editor_hint():
panel_container.minimum_size_changed.connect(func():
set_custom_minimum_size(panel_container.get_size())
set_size(panel_container.get_size()))

if Engine.is_editor_hint():
render({puzzle_set=Store.get_puzzle_sets()[0]})

## disable animations ##################################################

func disable_resize_animation():
var cont = get_node("%AnimatedVBoxContainer")
cont.disable_animations = true

## build puzzle list ############################################################

func render(opts):
Expand All @@ -33,8 +40,6 @@ func render(opts):
Log.warn("No puzzle set found in PuzzleProgressPanel")
return

Log.pr("prog panel rendering", opts)

var ps_theme = puzzle_set.get_theme()

var start_puzzle_icon
Expand Down Expand Up @@ -65,10 +70,12 @@ func render(opts):
puzzle_set_icon.set_texture(ps_theme.get_player_icon())
puzzle_set_icon.modulate.a = 0.0

rendered.emit()

if start_puzzle_icon and end_puzzle_icon:
U.call_in(0.5, self, func(): move_puzzle_cursor(end_puzzle_icon, {from=start_puzzle_icon}))
# ugh, this hard-coded time is gross....
# needs to let the resizing and toasting run first
U.call_in(0.8, self, func(): move_puzzle_cursor(end_puzzle_icon, {from=start_puzzle_icon}))

rendered.emit()

func move_puzzle_cursor(icon, opts={}):
if opts.get("no_show", false):
Expand Down
13 changes: 10 additions & 3 deletions src/ui/components/PuzzleProgressPanel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -0.000244141
offset_top = -0.000247955
offset_right = -884.0
offset_bottom = -460.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("2_mt4fd")
Expand All @@ -21,12 +25,15 @@ layout_mode = 0
size_flags_horizontal = 3
theme = ExtResource("1_tufv2")

[node name="VBoxContainer" type="VBoxContainer" parent="PuzzlePanelContainer"]
custom_minimum_size = Vector2(200, 64)
[node name="AnimatedVBoxContainer" type="VBoxContainer" parent="PuzzlePanelContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(158, 154)
layout_mode = 2
script = ExtResource("2_6lh1w")
child_size = Vector2(64, 64)
margin = Vector2(94, 90)

[node name="PuzzleList" type="GridContainer" parent="PuzzlePanelContainer/VBoxContainer"]
[node name="PuzzleList" type="GridContainer" parent="PuzzlePanelContainer/AnimatedVBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
columns = 4
Expand Down

0 comments on commit de32570

Please sign in to comment.