khanat-client/scenes/interfaces/creatures_menu/creatures_menu_ui.gd

56 lines
1.7 KiB
GDScript

extends Control
signal new_pressed( slot )
signal cancel_pressed
signal select_pressed( creature_filename )
var slots_number = 0
var slots = {}
func _ready():
var files = []
var directory = Directory.new()
if directory.dir_exists( "user://creatures/" ):
directory.open( "user://creatures/" )
directory.list_dir_begin()
while true:
var file = directory.get_next()
if file == "":
break
elif not file.begins_with( "." ) and not directory.current_is_dir():
files.append( file )
directory.list_dir_end()
for file in files:
var creature_box = preload( "res://scenes/interfaces/creatures_menu/creature_box.tscn" ).instance()
creature_box.get_node( "label" ).text = file
creature_box.slot = slots_number
creature_box.creature_filename = file
creature_box.connect( "select_pressed", self, "_on_creature_box_select_pressed" )
creature_box.connect( "delete_pressed", self, "_on_creature_box_delete_pressed" )
$screen_box/scroll_container/v_box_container/creatures_box.add_child( creature_box )
slots[ slots_number ] = creature_box
slots_number += 1
#var creature = Creatures.Ra_old2.new()
var creature = Data.new()
Config.msg_debug( "File:" + file )
creature.load( file )
creature_box.get_node( "label" ).text = creature.get_data("pseudonym", "No name")
func _on_new_pressed():
emit_signal( "new_pressed", slots_number )
func _on_cancel_pressed():
emit_signal( "cancel_pressed" )
func _on_creature_box_select_pressed( slot ):
emit_signal( "select_pressed", slots[ slot ].creature_filename )
func _on_creature_box_delete_pressed( slot ):
if slots[ slot ].creature_filename:
var dir = Directory.new()
dir.remove( "user://creatures/" + slots[ slot ].creature_filename )
slots[ slot ].queue_free()