feat: menu overhaul
This commit is contained in:
parent
b17c7280ea
commit
f379dff516
16 changed files with 273 additions and 181 deletions
|
@ -2,24 +2,22 @@ extends Window
|
|||
class_name DragonList
|
||||
|
||||
var _library: DragonLibrary
|
||||
var _dragons: Array[DragonListEntry]
|
||||
@export var dragon_list_entry_template: PackedScene
|
||||
@export var dragon_list_pivot: Node2D
|
||||
|
||||
@onready var dragger: DraggableWindow = $CanvasLayer/Dragger
|
||||
|
||||
@export var origin_name_label: Label
|
||||
@export var dragon_name_label: Label
|
||||
|
||||
@export var hat: AnimatedSprite2D
|
||||
@export var shirt: AnimatedSprite2D
|
||||
@export var decor: AnimatedSprite2D
|
||||
@export var dragon: AnimatedSprite2D
|
||||
|
||||
@export var hat_outfits: DragonOutfit
|
||||
@export var shirt_outfits: DragonOutfit
|
||||
@export var decor_outfits: DragonOutfit
|
||||
@export var dragon_colors: DragonOutfit
|
||||
var _index_showing: int = 0
|
||||
var _pivot_start_pos: Vector2
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
dragger.on_drag.connect(_on_drag)
|
||||
_pivot_start_pos = dragon_list_pivot.position
|
||||
|
||||
|
||||
func _on_drag(offset: Vector2i):
|
||||
|
@ -28,30 +26,65 @@ func _on_drag(offset: Vector2i):
|
|||
|
||||
func set_library(library: DragonLibrary):
|
||||
_library = library
|
||||
for i in len(_library.dragons):
|
||||
_instantiate_dragon(_library.dragons[i], i)
|
||||
|
||||
_play_idle_animations()
|
||||
_show_dragon(library.dragons[0])
|
||||
|
||||
|
||||
func _instantiate_dragon(dragon: DragonProperties, offset_step: int):
|
||||
var instance: DragonListEntry = dragon_list_entry_template.instantiate()
|
||||
dragon_list_pivot.add_child(instance)
|
||||
instance.position.x += offset_step * 110
|
||||
_dragons.push_back(instance)
|
||||
|
||||
|
||||
func _show_dragon(dragon: DragonProperties):
|
||||
hat.sprite_frames = hat_outfits.get_texture(dragon.hat)
|
||||
shirt.sprite_frames = shirt_outfits.get_texture(dragon.shirt)
|
||||
decor.sprite_frames = decor_outfits.get_texture(dragon.decor)
|
||||
self.dragon.sprite_frames = dragon_colors.get_texture(dragon.color)
|
||||
_restart_animations()
|
||||
|
||||
origin_name_label.text = dragon.origin
|
||||
dragon_name_label.text = dragon.name
|
||||
|
||||
|
||||
func _restart_animations():
|
||||
hat.set_frame(0)
|
||||
hat.play('idle')
|
||||
shirt.set_frame(0)
|
||||
shirt.play('idle')
|
||||
decor.set_frame(0)
|
||||
decor.play('idle')
|
||||
dragon.set_frame(0)
|
||||
dragon.play('idle')
|
||||
|
||||
|
||||
func _on_close_pressed() -> void:
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_dragon_previous_pressed() -> void:
|
||||
if _index_showing == 0:
|
||||
return
|
||||
_index_showing -= 1
|
||||
_move_to_position(-110 * _index_showing)
|
||||
_show_dragon(_library.dragons[_index_showing])
|
||||
|
||||
|
||||
func _on_dragon_next_pressed() -> void:
|
||||
if _index_showing == len(_library.dragons) - 1:
|
||||
return
|
||||
_index_showing += 1
|
||||
_move_to_position(-110 * _index_showing)
|
||||
_show_dragon(_library.dragons[_index_showing])
|
||||
|
||||
|
||||
func _move_to_position(target_position: int):
|
||||
var tween = create_tween()
|
||||
_play_walk_animations()
|
||||
var new_pos: Vector2 = _pivot_start_pos + Vector2(target_position, 0)
|
||||
_face_direction(new_pos.x < dragon_list_pivot.position.x)
|
||||
|
||||
tween.tween_property(dragon_list_pivot, "position", new_pos, 1.0).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
|
||||
tween.tween_callback(_play_idle_animations)
|
||||
|
||||
|
||||
func _play_idle_animations():
|
||||
for dragon in _dragons:
|
||||
dragon.play_animation('idle')
|
||||
|
||||
|
||||
func _play_walk_animations():
|
||||
for dragon in _dragons:
|
||||
dragon.play_animation('walk')
|
||||
|
||||
|
||||
func _face_direction(left: bool):
|
||||
for dragon in _dragons:
|
||||
dragon.face_direction(left)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue