-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor UpgradeButton and UpgradeMenu
- Rename signals and variables - Make animations shorter: from 30 frames to ~10 frames - Make some functions and variables pseudo-private - In UpgradeMenu, store references to buttons directly instead of their count
- Loading branch information
1 parent
62911fb
commit bee5a67
Showing
3 changed files
with
54 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,52 @@ | ||
# Sets and controls the icon and label of the upgrade buttons. The tool keyword | ||
# Sets and controls the icon and _label of the upgrade buttons. The tool keyword | ||
# makes sure we can see the result in the editor. | ||
tool | ||
extends TextureButton | ||
|
||
signal on_hide_complete; | ||
signal on_show_complete; | ||
signal appeared; | ||
signal disappeared; | ||
|
||
export var texture: Texture setget set_texture | ||
export var text := "" setget set_text | ||
|
||
onready var texture_rect := $VBoxContainer/TextureRect | ||
onready var label := $VBoxContainer/Label | ||
onready var animation_player := $AnimationPlayer | ||
onready var _texture_rect := $VBoxContainer/TextureRect | ||
onready var _label := $VBoxContainer/Label | ||
onready var _animation_player := $AnimationPlayer | ||
|
||
|
||
func show_delayed(delay : float = 0) -> void: | ||
play_animation("show", delay) | ||
yield(animation_player, 'animation_finished') | ||
emit_signal("on_show_complete") | ||
func appear(delay : float = 0) -> void: | ||
_play_animation("show", delay) | ||
|
||
|
||
func hide_delayed(delay : float = 0) -> void: | ||
play_animation("hide", delay) | ||
yield(animation_player, 'animation_finished') | ||
emit_signal("on_hide_complete") | ||
func disappear(delay : float = 0) -> void: | ||
_play_animation("hide", delay) | ||
|
||
|
||
func play_animation(animation, delay) -> void: | ||
animation_player.set_assigned_animation(animation) | ||
animation_player.seek(0, true) | ||
func _play_animation(animation, delay) -> void: | ||
_animation_player.set_assigned_animation(animation) | ||
_animation_player.seek(0, true) | ||
yield(get_tree().create_timer(delay), "timeout") | ||
animation_player.play() | ||
|
||
_animation_player.play() | ||
|
||
|
||
func set_texture(value: Texture) -> void: | ||
texture = value | ||
if not texture_rect: | ||
if not _texture_rect: | ||
yield(self, "ready") | ||
texture_rect.texture = value | ||
_texture_rect.texture = value | ||
|
||
|
||
func set_text(value: String) -> void: | ||
text = value | ||
if not texture_rect: | ||
if not _texture_rect: | ||
yield(self, "ready") | ||
label.text = value | ||
label.visible = text != "" | ||
_label.text = value | ||
_label.visible = text != "" | ||
|
||
|
||
func _on_AnimationPlayer_animation_finished(anim_name: String) -> void: | ||
match anim_name: | ||
"show": | ||
emit_signal("appeared") | ||
"hide": | ||
emit_signal("disappeared") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters